Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/_py_helper.h @ 559:bb160a1e67d7
A simple helper include file with some conveniente functions.
Also some "backports" from later Python versions.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 06 Jan 2022 18:50:09 +0100 |
| parents | |
| children | 81238ea2dbe3 |
comparison
equal
deleted
inserted
replaced
| 558:7a3c311991d7 | 559:bb160a1e67d7 |
|---|---|
| 1 /* -*- coding: utf-8 -*- */ | |
| 2 /* | |
| 3 * Some Python helper for C. | |
| 4 * | |
| 5 * Also contains some interesting backports from later Python versions. | |
| 6 * | |
| 7 * :Copyright: (c) 2021, Franz Glasner. All rights reserved. | |
| 8 * :License: BSD-3-Clause. See LICENSE.txt for details. | |
| 9 */ | |
| 10 | |
| 11 #if !defined(_PY_HELPER_H_d9df407295df4884a88e56699f6c6d8d) | |
| 12 #define _PY_HELPER_H_d9df407295df4884a88e56699f6c6d8d | |
| 13 | |
| 14 #if PY_VERSION_HEX < 0x030A0000 | |
| 15 | |
| 16 static inline | |
| 17 PyObject * | |
| 18 Py_NewRef(PyObject *obj) | |
| 19 { | |
| 20 Py_INCREF(obj); | |
| 21 return obj; | |
| 22 } | |
| 23 | |
| 24 | |
| 25 static inline | |
| 26 PyObject * | |
| 27 Py_XNewRef(PyObject *obj) | |
| 28 { | |
| 29 Py_XINCREF(obj); | |
| 30 return obj; | |
| 31 } | |
| 32 | |
| 33 #endif /* PY_VERSION_HEX < 0x030A0000 */ | |
| 34 | |
| 35 | |
| 36 static inline | |
| 37 void | |
| 38 py_clear_ref(PyObject **obj) | |
| 39 { | |
| 40 PyObject *tmp; | |
| 41 | |
| 42 if ((tmp = *obj) != NULL) { | |
| 43 *obj = NULL; | |
| 44 Py_DECREF(tmp); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 | |
| 49 /* | |
| 50 * NOTE: This implementation is valid for CPython only! | |
| 51 */ | |
| 52 static inline | |
| 53 int | |
| 54 py_object_is(PyObject *obj1, PyObject *obj2) | |
| 55 { | |
| 56 return (obj1 == obj2); | |
| 57 } | |
| 58 | |
| 59 | |
| 60 /* | |
| 61 * NOTE: This implementation is valid for CPython only! | |
| 62 */ | |
| 63 static inline | |
| 64 int | |
| 65 py_object_isnot(PyObject *obj1, PyObject *obj2) | |
| 66 { | |
| 67 return (obj1 != obj2); | |
| 68 } | |
| 69 | |
| 70 #endif |
