Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/_py_helper.h @ 560:81238ea2dbe3
Implement and use more helper functions.
Improve comments.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 06 Jan 2022 19:37:03 +0100 |
| parents | bb160a1e67d7 |
| children | f75c5b13a1d7 |
comparison
equal
deleted
inserted
replaced
| 559:bb160a1e67d7 | 560:81238ea2dbe3 |
|---|---|
| 11 #if !defined(_PY_HELPER_H_d9df407295df4884a88e56699f6c6d8d) | 11 #if !defined(_PY_HELPER_H_d9df407295df4884a88e56699f6c6d8d) |
| 12 #define _PY_HELPER_H_d9df407295df4884a88e56699f6c6d8d | 12 #define _PY_HELPER_H_d9df407295df4884a88e56699f6c6d8d |
| 13 | 13 |
| 14 #if PY_VERSION_HEX < 0x030A0000 | 14 #if PY_VERSION_HEX < 0x030A0000 |
| 15 | 15 |
| 16 /* | |
| 17 * Return a new owned reference to an object | |
| 18 */ | |
| 16 static inline | 19 static inline |
| 17 PyObject * | 20 PyObject * |
| 18 Py_NewRef(PyObject *obj) | 21 Py_NewRef(PyObject *obj) |
| 19 { | 22 { |
| 20 Py_INCREF(obj); | 23 Py_INCREF(obj); |
| 21 return obj; | 24 return obj; |
| 22 } | 25 } |
| 23 | 26 |
| 24 | 27 |
| 28 /* | |
| 29 * Return a new owned reference to an object when the input can be NULL | |
| 30 */ | |
| 25 static inline | 31 static inline |
| 26 PyObject * | 32 PyObject * |
| 27 Py_XNewRef(PyObject *obj) | 33 Py_XNewRef(PyObject *obj) |
| 28 { | 34 { |
| 29 Py_XINCREF(obj); | 35 Py_XINCREF(obj); |
| 65 py_object_isnot(PyObject *obj1, PyObject *obj2) | 71 py_object_isnot(PyObject *obj1, PyObject *obj2) |
| 66 { | 72 { |
| 67 return (obj1 != obj2); | 73 return (obj1 != obj2); |
| 68 } | 74 } |
| 69 | 75 |
| 76 | |
| 77 /** | |
| 78 * Copy from source to destination and make an owned reference. | |
| 79 * Also safely clear the destination before. | |
| 80 */ | |
| 81 static inline | |
| 82 void | |
| 83 py_assign(PyObject **dest, PyObject *src) | |
| 84 { | |
| 85 Py_XDECREF(*dest); | |
| 86 *dest = Py_NewRef(src); | |
| 87 } | |
| 88 | |
| 89 | |
| 90 /** | |
| 91 * Copy from source to destination and make an owned reference. | |
| 92 * Also safely clear the destination before. The source object may be NULL. | |
| 93 */ | |
| 94 static inline | |
| 95 void | |
| 96 py_assign_x(PyObject **dest, PyObject *src) | |
| 97 { | |
| 98 Py_XDECREF(*dest); | |
| 99 *dest = Py_XNewRef(src); | |
| 100 } | |
| 101 | |
| 102 | |
| 103 /* | |
| 104 * Transfer from a borrowed reference to an owned one and clear the source. | |
| 105 * Also safely clear the destination before. | |
| 106 */ | |
| 107 static inline | |
| 108 void | |
| 109 py_transfer_borrowed(PyObject **dest, PyObject **src) | |
| 110 { | |
| 111 Py_XDECREF(*dest); | |
| 112 *dest = Py_NewRef(*src); | |
| 113 *src = NULL; | |
| 114 } | |
| 115 | |
| 116 | |
| 117 /* | |
| 118 * Transfer from a borrowed reference to an owned one and clear the source. | |
| 119 * Also safely clear the destination before. The source object may be NULL. | |
| 120 */ | |
| 121 static inline | |
| 122 void | |
| 123 py_transfer_x_borrowed(PyObject **dest, PyObject **src) | |
| 124 { | |
| 125 Py_XDECREF(*dest); | |
| 126 *dest = Py_XNewRef(*src); | |
| 127 *src = NULL; | |
| 128 } | |
| 129 | |
| 130 | |
| 131 /* | |
| 132 * Transfer ownership from a owned reference to an owned one and clear the | |
| 133 * source. | |
| 134 * Also safely clear the destination before. | |
| 135 */ | |
| 136 static inline | |
| 137 void | |
| 138 py_transfer_owned(PyObject **dest, PyObject **src) | |
| 139 { | |
| 140 Py_XDECREF(*dest); | |
| 141 *dest = *src; | |
| 142 *src = NULL; | |
| 143 } | |
| 144 | |
| 145 | |
| 70 #endif | 146 #endif |
