Mercurial > hgrepos > Python > libs > ConfigMix
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/configmix/_py_helper.h Thu Jan 06 18:50:09 2022 +0100 @@ -0,0 +1,70 @@ +/* -*- coding: utf-8 -*- */ +/* + * Some Python helper for C. + * + * Also contains some interesting backports from later Python versions. + * + * :Copyright: (c) 2021, Franz Glasner. All rights reserved. + * :License: BSD-3-Clause. See LICENSE.txt for details. + */ + +#if !defined(_PY_HELPER_H_d9df407295df4884a88e56699f6c6d8d) +#define _PY_HELPER_H_d9df407295df4884a88e56699f6c6d8d + +#if PY_VERSION_HEX < 0x030A0000 + +static inline +PyObject * +Py_NewRef(PyObject *obj) +{ + Py_INCREF(obj); + return obj; +} + + +static inline +PyObject * +Py_XNewRef(PyObject *obj) +{ + Py_XINCREF(obj); + return obj; +} + +#endif /* PY_VERSION_HEX < 0x030A0000 */ + + +static inline +void +py_clear_ref(PyObject **obj) +{ + PyObject *tmp; + + if ((tmp = *obj) != NULL) { + *obj = NULL; + Py_DECREF(tmp); + } +} + + +/* + * NOTE: This implementation is valid for CPython only! + */ +static inline +int +py_object_is(PyObject *obj1, PyObject *obj2) +{ + return (obj1 == obj2); +} + + +/* + * NOTE: This implementation is valid for CPython only! + */ +static inline +int +py_object_isnot(PyObject *obj1, PyObject *obj2) +{ + return (obj1 != obj2); +} + +#endif
