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