Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/_py_helper.h @ 562:f75c5b13a1d7
FIX: Memory-leak
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 06 Jan 2022 20:13:10 +0100 |
| parents | 81238ea2dbe3 |
| children | 2c211934d4b0 |
comparison
equal
deleted
inserted
replaced
| 561:c51f484387ee | 562:f75c5b13a1d7 |
|---|---|
| 100 } | 100 } |
| 101 | 101 |
| 102 | 102 |
| 103 /* | 103 /* |
| 104 * Transfer from a borrowed reference to an owned one and clear the source. | 104 * Transfer from a borrowed reference to an owned one and clear the source. |
| 105 * Also safely clear the destination before. | 105 * Also clear the destination before. |
| 106 */ | 106 */ |
| 107 static inline | 107 static inline |
| 108 void | 108 void |
| 109 py_transfer_borrowed(PyObject **dest, PyObject **src) | 109 py_transfer_borrowed(PyObject **dest, PyObject **src) |
| 110 { | 110 { |
| 111 Py_DECREF(*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. | |
| 120 */ | |
| 121 static inline | |
| 122 void | |
| 123 py_x_transfer_borrowed(PyObject **dest, PyObject **src) | |
| 124 { | |
| 111 Py_XDECREF(*dest); | 125 Py_XDECREF(*dest); |
| 112 *dest = Py_NewRef(*src); | 126 *dest = Py_NewRef(*src); |
| 127 *src = NULL; | |
| 128 } | |
| 129 | |
| 130 | |
| 131 /* | |
| 132 * Transfer from a borrowed reference to an owned one and clear the source. | |
| 133 * Also clear the destination before. The source object may be NULL. | |
| 134 */ | |
| 135 static inline | |
| 136 void | |
| 137 py_transfer_x_borrowed(PyObject **dest, PyObject **src) | |
| 138 { | |
| 139 Py_DECREF(*dest); | |
| 140 *dest = Py_XNewRef(*src); | |
| 113 *src = NULL; | 141 *src = NULL; |
| 114 } | 142 } |
| 115 | 143 |
| 116 | 144 |
| 117 /* | 145 /* |
| 118 * Transfer from a borrowed reference to an owned one and clear the source. | 146 * 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. | 147 * Also safely clear the destination before. The source object may be NULL. |
| 120 */ | 148 */ |
| 121 static inline | 149 static inline |
| 122 void | 150 void |
| 123 py_transfer_x_borrowed(PyObject **dest, PyObject **src) | 151 py_x_transfer_x_borrowed(PyObject **dest, PyObject **src) |
| 124 { | 152 { |
| 125 Py_XDECREF(*dest); | 153 Py_XDECREF(*dest); |
| 126 *dest = Py_XNewRef(*src); | 154 *dest = Py_XNewRef(*src); |
| 155 *src = NULL; | |
| 156 } | |
| 157 | |
| 158 | |
| 159 /* | |
| 160 * Transfer ownership from a owned reference to an owned one and clear the | |
| 161 * source. | |
| 162 * Also clear the destination before. | |
| 163 */ | |
| 164 static inline | |
| 165 void | |
| 166 py_transfer_owned(PyObject **dest, PyObject **src) | |
| 167 { | |
| 168 Py_DECREF(*dest); | |
| 169 *dest = *src; | |
| 127 *src = NULL; | 170 *src = NULL; |
| 128 } | 171 } |
| 129 | 172 |
| 130 | 173 |
| 131 /* | 174 /* |
| 133 * source. | 176 * source. |
| 134 * Also safely clear the destination before. | 177 * Also safely clear the destination before. |
| 135 */ | 178 */ |
| 136 static inline | 179 static inline |
| 137 void | 180 void |
| 138 py_transfer_owned(PyObject **dest, PyObject **src) | 181 py_x_transfer_owned(PyObject **dest, PyObject **src) |
| 139 { | 182 { |
| 140 Py_XDECREF(*dest); | 183 Py_XDECREF(*dest); |
| 141 *dest = *src; | 184 *dest = *src; |
| 142 *src = NULL; | 185 *src = NULL; |
| 143 } | 186 } |
