Show More
@@ -0,0 +1,278 b'' | |||||
|
1 | // Header file providing new functions of the Python C API to old Python | |||
|
2 | // versions. | |||
|
3 | // | |||
|
4 | // File distributed under the MIT license. | |||
|
5 | // | |||
|
6 | // Homepage: | |||
|
7 | // https://github.com/pythoncapi/pythoncapi_compat | |||
|
8 | // | |||
|
9 | // Latest version: | |||
|
10 | // https://raw.githubusercontent.com/pythoncapi/pythoncapi_compat/master/pythoncapi_compat.h | |||
|
11 | ||||
|
12 | #ifndef PYTHONCAPI_COMPAT | |||
|
13 | #define PYTHONCAPI_COMPAT | |||
|
14 | ||||
|
15 | #ifdef __cplusplus | |||
|
16 | extern "C" { | |||
|
17 | #endif | |||
|
18 | ||||
|
19 | #include <Python.h> | |||
|
20 | #include "frameobject.h" // PyFrameObject, PyFrame_GetBack() | |||
|
21 | ||||
|
22 | ||||
|
23 | // Cast argument to PyObject* type. | |||
|
24 | #ifndef _PyObject_CAST | |||
|
25 | # define _PyObject_CAST(op) ((PyObject*)(op)) | |||
|
26 | #endif | |||
|
27 | ||||
|
28 | ||||
|
29 | // bpo-42262 added Py_NewRef() to Python 3.10.0a3 | |||
|
30 | #if PY_VERSION_HEX < 0x030a00A3 && !defined(Py_NewRef) | |||
|
31 | static inline PyObject* _Py_NewRef(PyObject *obj) | |||
|
32 | { | |||
|
33 | Py_INCREF(obj); | |||
|
34 | return obj; | |||
|
35 | } | |||
|
36 | #define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj)) | |||
|
37 | #endif | |||
|
38 | ||||
|
39 | ||||
|
40 | // bpo-42262 added Py_XNewRef() to Python 3.10.0a3 | |||
|
41 | #if PY_VERSION_HEX < 0x030a00A3 && !defined(Py_XNewRef) | |||
|
42 | static inline PyObject* _Py_XNewRef(PyObject *obj) | |||
|
43 | { | |||
|
44 | Py_XINCREF(obj); | |||
|
45 | return obj; | |||
|
46 | } | |||
|
47 | #define Py_XNewRef(obj) _Py_XNewRef(_PyObject_CAST(obj)) | |||
|
48 | #endif | |||
|
49 | ||||
|
50 | ||||
|
51 | // bpo-39573 added Py_SET_REFCNT() to Python 3.9.0a4 | |||
|
52 | #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_REFCNT) | |||
|
53 | static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) | |||
|
54 | { | |||
|
55 | ob->ob_refcnt = refcnt; | |||
|
56 | } | |||
|
57 | #define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT((PyObject*)(ob), refcnt) | |||
|
58 | #endif | |||
|
59 | ||||
|
60 | ||||
|
61 | // bpo-39573 added Py_SET_TYPE() to Python 3.9.0a4 | |||
|
62 | #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE) | |||
|
63 | static inline void | |||
|
64 | _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) | |||
|
65 | { | |||
|
66 | ob->ob_type = type; | |||
|
67 | } | |||
|
68 | #define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type) | |||
|
69 | #endif | |||
|
70 | ||||
|
71 | ||||
|
72 | // bpo-39573 added Py_SET_SIZE() to Python 3.9.0a4 | |||
|
73 | #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE) | |||
|
74 | static inline void | |||
|
75 | _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) | |||
|
76 | { | |||
|
77 | ob->ob_size = size; | |||
|
78 | } | |||
|
79 | #define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size) | |||
|
80 | #endif | |||
|
81 | ||||
|
82 | ||||
|
83 | // bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1 | |||
|
84 | #if PY_VERSION_HEX < 0x030900B1 | |||
|
85 | static inline PyCodeObject* | |||
|
86 | PyFrame_GetCode(PyFrameObject *frame) | |||
|
87 | { | |||
|
88 | PyCodeObject *code; | |||
|
89 | assert(frame != NULL); | |||
|
90 | code = frame->f_code; | |||
|
91 | assert(code != NULL); | |||
|
92 | Py_INCREF(code); | |||
|
93 | return code; | |||
|
94 | } | |||
|
95 | #endif | |||
|
96 | ||||
|
97 | static inline PyCodeObject* | |||
|
98 | _PyFrame_GetCodeBorrow(PyFrameObject *frame) | |||
|
99 | { | |||
|
100 | PyCodeObject *code = PyFrame_GetCode(frame); | |||
|
101 | Py_DECREF(code); | |||
|
102 | return code; // borrowed reference | |||
|
103 | } | |||
|
104 | ||||
|
105 | ||||
|
106 | // bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1 | |||
|
107 | #if PY_VERSION_HEX < 0x030900B1 | |||
|
108 | static inline PyFrameObject* | |||
|
109 | PyFrame_GetBack(PyFrameObject *frame) | |||
|
110 | { | |||
|
111 | PyFrameObject *back; | |||
|
112 | assert(frame != NULL); | |||
|
113 | back = frame->f_back; | |||
|
114 | Py_XINCREF(back); | |||
|
115 | return back; | |||
|
116 | } | |||
|
117 | #endif | |||
|
118 | ||||
|
119 | static inline PyFrameObject* | |||
|
120 | _PyFrame_GetBackBorrow(PyFrameObject *frame) | |||
|
121 | { | |||
|
122 | PyFrameObject *back = PyFrame_GetBack(frame); | |||
|
123 | Py_XDECREF(back); | |||
|
124 | return back; // borrowed reference | |||
|
125 | } | |||
|
126 | ||||
|
127 | ||||
|
128 | // bpo-39947 added PyThreadState_GetInterpreter() to Python 3.9.0a5 | |||
|
129 | #if PY_VERSION_HEX < 0x030900A5 | |||
|
130 | static inline PyInterpreterState * | |||
|
131 | PyThreadState_GetInterpreter(PyThreadState *tstate) | |||
|
132 | { | |||
|
133 | assert(tstate != NULL); | |||
|
134 | return tstate->interp; | |||
|
135 | } | |||
|
136 | #endif | |||
|
137 | ||||
|
138 | ||||
|
139 | // bpo-40429 added PyThreadState_GetFrame() to Python 3.9.0b1 | |||
|
140 | #if PY_VERSION_HEX < 0x030900B1 | |||
|
141 | static inline PyFrameObject* | |||
|
142 | PyThreadState_GetFrame(PyThreadState *tstate) | |||
|
143 | { | |||
|
144 | PyFrameObject *frame; | |||
|
145 | assert(tstate != NULL); | |||
|
146 | frame = tstate->frame; | |||
|
147 | Py_XINCREF(frame); | |||
|
148 | return frame; | |||
|
149 | } | |||
|
150 | #endif | |||
|
151 | ||||
|
152 | static inline PyFrameObject* | |||
|
153 | _PyThreadState_GetFrameBorrow(PyThreadState *tstate) | |||
|
154 | { | |||
|
155 | PyFrameObject *frame = PyThreadState_GetFrame(tstate); | |||
|
156 | Py_XDECREF(frame); | |||
|
157 | return frame; // borrowed reference | |||
|
158 | } | |||
|
159 | ||||
|
160 | ||||
|
161 | // bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a5 | |||
|
162 | #if PY_VERSION_HEX < 0x030900A5 | |||
|
163 | static inline PyInterpreterState * | |||
|
164 | PyInterpreterState_Get(void) | |||
|
165 | { | |||
|
166 | PyThreadState *tstate; | |||
|
167 | PyInterpreterState *interp; | |||
|
168 | ||||
|
169 | tstate = PyThreadState_GET(); | |||
|
170 | if (tstate == NULL) { | |||
|
171 | Py_FatalError("GIL released (tstate is NULL)"); | |||
|
172 | } | |||
|
173 | interp = tstate->interp; | |||
|
174 | if (interp == NULL) { | |||
|
175 | Py_FatalError("no current interpreter"); | |||
|
176 | } | |||
|
177 | return interp; | |||
|
178 | } | |||
|
179 | #endif | |||
|
180 | ||||
|
181 | ||||
|
182 | // bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a6 | |||
|
183 | #if 0x030700A1 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x030900A6 | |||
|
184 | static inline uint64_t | |||
|
185 | PyThreadState_GetID(PyThreadState *tstate) | |||
|
186 | { | |||
|
187 | assert(tstate != NULL); | |||
|
188 | return tstate->id; | |||
|
189 | } | |||
|
190 | #endif | |||
|
191 | ||||
|
192 | ||||
|
193 | // bpo-37194 added PyObject_CallNoArgs() to Python 3.9.0a1 | |||
|
194 | #if PY_VERSION_HEX < 0x030900A1 | |||
|
195 | static inline PyObject* | |||
|
196 | PyObject_CallNoArgs(PyObject *func) | |||
|
197 | { | |||
|
198 | return PyObject_CallFunctionObjArgs(func, NULL); | |||
|
199 | } | |||
|
200 | #endif | |||
|
201 | ||||
|
202 | ||||
|
203 | // bpo-39245 made PyObject_CallOneArg() public (previously called | |||
|
204 | // _PyObject_CallOneArg) in Python 3.9.0a4 | |||
|
205 | #if PY_VERSION_HEX < 0x030900A4 | |||
|
206 | static inline PyObject* | |||
|
207 | PyObject_CallOneArg(PyObject *func, PyObject *arg) | |||
|
208 | { | |||
|
209 | return PyObject_CallFunctionObjArgs(func, arg, NULL); | |||
|
210 | } | |||
|
211 | #endif | |||
|
212 | ||||
|
213 | ||||
|
214 | // bpo-40024 added PyModule_AddType() to Python 3.9.0a5 | |||
|
215 | #if PY_VERSION_HEX < 0x030900A5 | |||
|
216 | static inline int | |||
|
217 | PyModule_AddType(PyObject *module, PyTypeObject *type) | |||
|
218 | { | |||
|
219 | const char *name, *dot; | |||
|
220 | ||||
|
221 | if (PyType_Ready(type) < 0) { | |||
|
222 | return -1; | |||
|
223 | } | |||
|
224 | ||||
|
225 | // inline _PyType_Name() | |||
|
226 | name = type->tp_name; | |||
|
227 | assert(name != NULL); | |||
|
228 | dot = strrchr(name, '.'); | |||
|
229 | if (dot != NULL) { | |||
|
230 | name = dot + 1; | |||
|
231 | } | |||
|
232 | ||||
|
233 | Py_INCREF(type); | |||
|
234 | if (PyModule_AddObject(module, name, (PyObject *)type) < 0) { | |||
|
235 | Py_DECREF(type); | |||
|
236 | return -1; | |||
|
237 | } | |||
|
238 | ||||
|
239 | return 0; | |||
|
240 | } | |||
|
241 | #endif | |||
|
242 | ||||
|
243 | ||||
|
244 | // bpo-40241 added PyObject_GC_IsTracked() to Python 3.9.0a6. | |||
|
245 | // bpo-4688 added _PyObject_GC_IS_TRACKED() to Python 2.7.0a2. | |||
|
246 | #if PY_VERSION_HEX < 0x030900A6 | |||
|
247 | static inline int | |||
|
248 | PyObject_GC_IsTracked(PyObject* obj) | |||
|
249 | { | |||
|
250 | return (PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj)); | |||
|
251 | } | |||
|
252 | #endif | |||
|
253 | ||||
|
254 | // bpo-40241 added PyObject_GC_IsFinalized() to Python 3.9.0a6. | |||
|
255 | // bpo-18112 added _PyGCHead_FINALIZED() to Python 3.4.0 final. | |||
|
256 | #if PY_VERSION_HEX < 0x030900A6 && PY_VERSION_HEX >= 0x030400F0 | |||
|
257 | static inline int | |||
|
258 | PyObject_GC_IsFinalized(PyObject *obj) | |||
|
259 | { | |||
|
260 | return (PyObject_IS_GC(obj) && _PyGCHead_FINALIZED((PyGC_Head *)(obj)-1)); | |||
|
261 | } | |||
|
262 | #endif | |||
|
263 | ||||
|
264 | ||||
|
265 | // bpo-39573 added Py_IS_TYPE() to Python 3.9.0a4 | |||
|
266 | #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_IS_TYPE) | |||
|
267 | static inline int | |||
|
268 | _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { | |||
|
269 | return ob->ob_type == type; | |||
|
270 | } | |||
|
271 | #define Py_IS_TYPE(ob, type) _Py_IS_TYPE((const PyObject*)(ob), type) | |||
|
272 | #endif | |||
|
273 | ||||
|
274 | ||||
|
275 | #ifdef __cplusplus | |||
|
276 | } | |||
|
277 | #endif | |||
|
278 | #endif // PYTHONCAPI_COMPAT |
@@ -0,0 +1,278 b'' | |||||
|
1 | // Header file providing new functions of the Python C API to old Python | |||
|
2 | // versions. | |||
|
3 | // | |||
|
4 | // File distributed under the MIT license. | |||
|
5 | // | |||
|
6 | // Homepage: | |||
|
7 | // https://github.com/pythoncapi/pythoncapi_compat | |||
|
8 | // | |||
|
9 | // Latest version: | |||
|
10 | // https://raw.githubusercontent.com/pythoncapi/pythoncapi_compat/master/pythoncapi_compat.h | |||
|
11 | ||||
|
12 | #ifndef PYTHONCAPI_COMPAT | |||
|
13 | #define PYTHONCAPI_COMPAT | |||
|
14 | ||||
|
15 | #ifdef __cplusplus | |||
|
16 | extern "C" { | |||
|
17 | #endif | |||
|
18 | ||||
|
19 | #include <Python.h> | |||
|
20 | #include "frameobject.h" // PyFrameObject, PyFrame_GetBack() | |||
|
21 | ||||
|
22 | ||||
|
23 | // Cast argument to PyObject* type. | |||
|
24 | #ifndef _PyObject_CAST | |||
|
25 | # define _PyObject_CAST(op) ((PyObject*)(op)) | |||
|
26 | #endif | |||
|
27 | ||||
|
28 | ||||
|
29 | // bpo-42262 added Py_NewRef() to Python 3.10.0a3 | |||
|
30 | #if PY_VERSION_HEX < 0x030a00A3 && !defined(Py_NewRef) | |||
|
31 | static inline PyObject* _Py_NewRef(PyObject *obj) | |||
|
32 | { | |||
|
33 | Py_INCREF(obj); | |||
|
34 | return obj; | |||
|
35 | } | |||
|
36 | #define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj)) | |||
|
37 | #endif | |||
|
38 | ||||
|
39 | ||||
|
40 | // bpo-42262 added Py_XNewRef() to Python 3.10.0a3 | |||
|
41 | #if PY_VERSION_HEX < 0x030a00A3 && !defined(Py_XNewRef) | |||
|
42 | static inline PyObject* _Py_XNewRef(PyObject *obj) | |||
|
43 | { | |||
|
44 | Py_XINCREF(obj); | |||
|
45 | return obj; | |||
|
46 | } | |||
|
47 | #define Py_XNewRef(obj) _Py_XNewRef(_PyObject_CAST(obj)) | |||
|
48 | #endif | |||
|
49 | ||||
|
50 | ||||
|
51 | // bpo-39573 added Py_SET_REFCNT() to Python 3.9.0a4 | |||
|
52 | #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_REFCNT) | |||
|
53 | static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) | |||
|
54 | { | |||
|
55 | ob->ob_refcnt = refcnt; | |||
|
56 | } | |||
|
57 | #define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT((PyObject*)(ob), refcnt) | |||
|
58 | #endif | |||
|
59 | ||||
|
60 | ||||
|
61 | // bpo-39573 added Py_SET_TYPE() to Python 3.9.0a4 | |||
|
62 | #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE) | |||
|
63 | static inline void | |||
|
64 | _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) | |||
|
65 | { | |||
|
66 | ob->ob_type = type; | |||
|
67 | } | |||
|
68 | #define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type) | |||
|
69 | #endif | |||
|
70 | ||||
|
71 | ||||
|
72 | // bpo-39573 added Py_SET_SIZE() to Python 3.9.0a4 | |||
|
73 | #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE) | |||
|
74 | static inline void | |||
|
75 | _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) | |||
|
76 | { | |||
|
77 | ob->ob_size = size; | |||
|
78 | } | |||
|
79 | #define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size) | |||
|
80 | #endif | |||
|
81 | ||||
|
82 | ||||
|
83 | // bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1 | |||
|
84 | #if PY_VERSION_HEX < 0x030900B1 | |||
|
85 | static inline PyCodeObject* | |||
|
86 | PyFrame_GetCode(PyFrameObject *frame) | |||
|
87 | { | |||
|
88 | PyCodeObject *code; | |||
|
89 | assert(frame != NULL); | |||
|
90 | code = frame->f_code; | |||
|
91 | assert(code != NULL); | |||
|
92 | Py_INCREF(code); | |||
|
93 | return code; | |||
|
94 | } | |||
|
95 | #endif | |||
|
96 | ||||
|
97 | static inline PyCodeObject* | |||
|
98 | _PyFrame_GetCodeBorrow(PyFrameObject *frame) | |||
|
99 | { | |||
|
100 | PyCodeObject *code = PyFrame_GetCode(frame); | |||
|
101 | Py_DECREF(code); | |||
|
102 | return code; // borrowed reference | |||
|
103 | } | |||
|
104 | ||||
|
105 | ||||
|
106 | // bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1 | |||
|
107 | #if PY_VERSION_HEX < 0x030900B1 | |||
|
108 | static inline PyFrameObject* | |||
|
109 | PyFrame_GetBack(PyFrameObject *frame) | |||
|
110 | { | |||
|
111 | PyFrameObject *back; | |||
|
112 | assert(frame != NULL); | |||
|
113 | back = frame->f_back; | |||
|
114 | Py_XINCREF(back); | |||
|
115 | return back; | |||
|
116 | } | |||
|
117 | #endif | |||
|
118 | ||||
|
119 | static inline PyFrameObject* | |||
|
120 | _PyFrame_GetBackBorrow(PyFrameObject *frame) | |||
|
121 | { | |||
|
122 | PyFrameObject *back = PyFrame_GetBack(frame); | |||
|
123 | Py_XDECREF(back); | |||
|
124 | return back; // borrowed reference | |||
|
125 | } | |||
|
126 | ||||
|
127 | ||||
|
128 | // bpo-39947 added PyThreadState_GetInterpreter() to Python 3.9.0a5 | |||
|
129 | #if PY_VERSION_HEX < 0x030900A5 | |||
|
130 | static inline PyInterpreterState * | |||
|
131 | PyThreadState_GetInterpreter(PyThreadState *tstate) | |||
|
132 | { | |||
|
133 | assert(tstate != NULL); | |||
|
134 | return tstate->interp; | |||
|
135 | } | |||
|
136 | #endif | |||
|
137 | ||||
|
138 | ||||
|
139 | // bpo-40429 added PyThreadState_GetFrame() to Python 3.9.0b1 | |||
|
140 | #if PY_VERSION_HEX < 0x030900B1 | |||
|
141 | static inline PyFrameObject* | |||
|
142 | PyThreadState_GetFrame(PyThreadState *tstate) | |||
|
143 | { | |||
|
144 | PyFrameObject *frame; | |||
|
145 | assert(tstate != NULL); | |||
|
146 | frame = tstate->frame; | |||
|
147 | Py_XINCREF(frame); | |||
|
148 | return frame; | |||
|
149 | } | |||
|
150 | #endif | |||
|
151 | ||||
|
152 | static inline PyFrameObject* | |||
|
153 | _PyThreadState_GetFrameBorrow(PyThreadState *tstate) | |||
|
154 | { | |||
|
155 | PyFrameObject *frame = PyThreadState_GetFrame(tstate); | |||
|
156 | Py_XDECREF(frame); | |||
|
157 | return frame; // borrowed reference | |||
|
158 | } | |||
|
159 | ||||
|
160 | ||||
|
161 | // bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a5 | |||
|
162 | #if PY_VERSION_HEX < 0x030900A5 | |||
|
163 | static inline PyInterpreterState * | |||
|
164 | PyInterpreterState_Get(void) | |||
|
165 | { | |||
|
166 | PyThreadState *tstate; | |||
|
167 | PyInterpreterState *interp; | |||
|
168 | ||||
|
169 | tstate = PyThreadState_GET(); | |||
|
170 | if (tstate == NULL) { | |||
|
171 | Py_FatalError("GIL released (tstate is NULL)"); | |||
|
172 | } | |||
|
173 | interp = tstate->interp; | |||
|
174 | if (interp == NULL) { | |||
|
175 | Py_FatalError("no current interpreter"); | |||
|
176 | } | |||
|
177 | return interp; | |||
|
178 | } | |||
|
179 | #endif | |||
|
180 | ||||
|
181 | ||||
|
182 | // bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a6 | |||
|
183 | #if 0x030700A1 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x030900A6 | |||
|
184 | static inline uint64_t | |||
|
185 | PyThreadState_GetID(PyThreadState *tstate) | |||
|
186 | { | |||
|
187 | assert(tstate != NULL); | |||
|
188 | return tstate->id; | |||
|
189 | } | |||
|
190 | #endif | |||
|
191 | ||||
|
192 | ||||
|
193 | // bpo-37194 added PyObject_CallNoArgs() to Python 3.9.0a1 | |||
|
194 | #if PY_VERSION_HEX < 0x030900A1 | |||
|
195 | static inline PyObject* | |||
|
196 | PyObject_CallNoArgs(PyObject *func) | |||
|
197 | { | |||
|
198 | return PyObject_CallFunctionObjArgs(func, NULL); | |||
|
199 | } | |||
|
200 | #endif | |||
|
201 | ||||
|
202 | ||||
|
203 | // bpo-39245 made PyObject_CallOneArg() public (previously called | |||
|
204 | // _PyObject_CallOneArg) in Python 3.9.0a4 | |||
|
205 | #if PY_VERSION_HEX < 0x030900A4 | |||
|
206 | static inline PyObject* | |||
|
207 | PyObject_CallOneArg(PyObject *func, PyObject *arg) | |||
|
208 | { | |||
|
209 | return PyObject_CallFunctionObjArgs(func, arg, NULL); | |||
|
210 | } | |||
|
211 | #endif | |||
|
212 | ||||
|
213 | ||||
|
214 | // bpo-40024 added PyModule_AddType() to Python 3.9.0a5 | |||
|
215 | #if PY_VERSION_HEX < 0x030900A5 | |||
|
216 | static inline int | |||
|
217 | PyModule_AddType(PyObject *module, PyTypeObject *type) | |||
|
218 | { | |||
|
219 | const char *name, *dot; | |||
|
220 | ||||
|
221 | if (PyType_Ready(type) < 0) { | |||
|
222 | return -1; | |||
|
223 | } | |||
|
224 | ||||
|
225 | // inline _PyType_Name() | |||
|
226 | name = type->tp_name; | |||
|
227 | assert(name != NULL); | |||
|
228 | dot = strrchr(name, '.'); | |||
|
229 | if (dot != NULL) { | |||
|
230 | name = dot + 1; | |||
|
231 | } | |||
|
232 | ||||
|
233 | Py_INCREF(type); | |||
|
234 | if (PyModule_AddObject(module, name, (PyObject *)type) < 0) { | |||
|
235 | Py_DECREF(type); | |||
|
236 | return -1; | |||
|
237 | } | |||
|
238 | ||||
|
239 | return 0; | |||
|
240 | } | |||
|
241 | #endif | |||
|
242 | ||||
|
243 | ||||
|
244 | // bpo-40241 added PyObject_GC_IsTracked() to Python 3.9.0a6. | |||
|
245 | // bpo-4688 added _PyObject_GC_IS_TRACKED() to Python 2.7.0a2. | |||
|
246 | #if PY_VERSION_HEX < 0x030900A6 | |||
|
247 | static inline int | |||
|
248 | PyObject_GC_IsTracked(PyObject* obj) | |||
|
249 | { | |||
|
250 | return (PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj)); | |||
|
251 | } | |||
|
252 | #endif | |||
|
253 | ||||
|
254 | // bpo-40241 added PyObject_GC_IsFinalized() to Python 3.9.0a6. | |||
|
255 | // bpo-18112 added _PyGCHead_FINALIZED() to Python 3.4.0 final. | |||
|
256 | #if PY_VERSION_HEX < 0x030900A6 && PY_VERSION_HEX >= 0x030400F0 | |||
|
257 | static inline int | |||
|
258 | PyObject_GC_IsFinalized(PyObject *obj) | |||
|
259 | { | |||
|
260 | return (PyObject_IS_GC(obj) && _PyGCHead_FINALIZED((PyGC_Head *)(obj)-1)); | |||
|
261 | } | |||
|
262 | #endif | |||
|
263 | ||||
|
264 | ||||
|
265 | // bpo-39573 added Py_IS_TYPE() to Python 3.9.0a4 | |||
|
266 | #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_IS_TYPE) | |||
|
267 | static inline int | |||
|
268 | _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { | |||
|
269 | return ob->ob_type == type; | |||
|
270 | } | |||
|
271 | #define Py_IS_TYPE(ob, type) _Py_IS_TYPE((const PyObject*)(ob), type) | |||
|
272 | #endif | |||
|
273 | ||||
|
274 | ||||
|
275 | #ifdef __cplusplus | |||
|
276 | } | |||
|
277 | #endif | |||
|
278 | #endif // PYTHONCAPI_COMPAT |
@@ -9,3 +9,4 b' contrib/python-zstandard/**.h' | |||||
9 | hgext/fsmonitor/pywatchman/**.c |
|
9 | hgext/fsmonitor/pywatchman/**.c | |
10 | mercurial/thirdparty/**.c |
|
10 | mercurial/thirdparty/**.c | |
11 | mercurial/thirdparty/**.h |
|
11 | mercurial/thirdparty/**.h | |
|
12 | mercurial/pythoncapi_compat.h |
@@ -758,7 +758,7 b' PyTypeObject ZstdBufferWithSegmentsColle' | |||||
758 | }; |
|
758 | }; | |
759 |
|
759 | |||
760 | void bufferutil_module_init(PyObject* mod) { |
|
760 | void bufferutil_module_init(PyObject* mod) { | |
761 |
Py_TYPE(&ZstdBufferWithSegmentsType |
|
761 | Py_SET_TYPE(&ZstdBufferWithSegmentsType, &PyType_Type); | |
762 | if (PyType_Ready(&ZstdBufferWithSegmentsType) < 0) { |
|
762 | if (PyType_Ready(&ZstdBufferWithSegmentsType) < 0) { | |
763 | return; |
|
763 | return; | |
764 | } |
|
764 | } | |
@@ -766,7 +766,7 b' void bufferutil_module_init(PyObject* mo' | |||||
766 | Py_INCREF(&ZstdBufferWithSegmentsType); |
|
766 | Py_INCREF(&ZstdBufferWithSegmentsType); | |
767 | PyModule_AddObject(mod, "BufferWithSegments", (PyObject*)&ZstdBufferWithSegmentsType); |
|
767 | PyModule_AddObject(mod, "BufferWithSegments", (PyObject*)&ZstdBufferWithSegmentsType); | |
768 |
|
768 | |||
769 |
Py_TYPE(&ZstdBufferSegmentsType |
|
769 | Py_SET_TYPE(&ZstdBufferSegmentsType, &PyType_Type); | |
770 | if (PyType_Ready(&ZstdBufferSegmentsType) < 0) { |
|
770 | if (PyType_Ready(&ZstdBufferSegmentsType) < 0) { | |
771 | return; |
|
771 | return; | |
772 | } |
|
772 | } | |
@@ -774,7 +774,7 b' void bufferutil_module_init(PyObject* mo' | |||||
774 | Py_INCREF(&ZstdBufferSegmentsType); |
|
774 | Py_INCREF(&ZstdBufferSegmentsType); | |
775 | PyModule_AddObject(mod, "BufferSegments", (PyObject*)&ZstdBufferSegmentsType); |
|
775 | PyModule_AddObject(mod, "BufferSegments", (PyObject*)&ZstdBufferSegmentsType); | |
776 |
|
776 | |||
777 |
Py_TYPE(&ZstdBufferSegmentType |
|
777 | Py_SET_TYPE(&ZstdBufferSegmentType, &PyType_Type); | |
778 | if (PyType_Ready(&ZstdBufferSegmentType) < 0) { |
|
778 | if (PyType_Ready(&ZstdBufferSegmentType) < 0) { | |
779 | return; |
|
779 | return; | |
780 | } |
|
780 | } | |
@@ -782,7 +782,7 b' void bufferutil_module_init(PyObject* mo' | |||||
782 | Py_INCREF(&ZstdBufferSegmentType); |
|
782 | Py_INCREF(&ZstdBufferSegmentType); | |
783 | PyModule_AddObject(mod, "BufferSegment", (PyObject*)&ZstdBufferSegmentType); |
|
783 | PyModule_AddObject(mod, "BufferSegment", (PyObject*)&ZstdBufferSegmentType); | |
784 |
|
784 | |||
785 |
Py_TYPE(&ZstdBufferWithSegmentsCollectionType |
|
785 | Py_SET_TYPE(&ZstdBufferWithSegmentsCollectionType, &PyType_Type); | |
786 | if (PyType_Ready(&ZstdBufferWithSegmentsCollectionType) < 0) { |
|
786 | if (PyType_Ready(&ZstdBufferWithSegmentsCollectionType) < 0) { | |
787 | return; |
|
787 | return; | |
788 | } |
|
788 | } |
@@ -348,12 +348,12 b' PyTypeObject ZstdCompressionChunkerType ' | |||||
348 | }; |
|
348 | }; | |
349 |
|
349 | |||
350 | void compressionchunker_module_init(PyObject* module) { |
|
350 | void compressionchunker_module_init(PyObject* module) { | |
351 |
Py_TYPE(&ZstdCompressionChunkerIteratorType |
|
351 | Py_SET_TYPE(&ZstdCompressionChunkerIteratorType, &PyType_Type); | |
352 | if (PyType_Ready(&ZstdCompressionChunkerIteratorType) < 0) { |
|
352 | if (PyType_Ready(&ZstdCompressionChunkerIteratorType) < 0) { | |
353 | return; |
|
353 | return; | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 |
Py_TYPE(&ZstdCompressionChunkerType |
|
356 | Py_SET_TYPE(&ZstdCompressionChunkerType, &PyType_Type); | |
357 | if (PyType_Ready(&ZstdCompressionChunkerType) < 0) { |
|
357 | if (PyType_Ready(&ZstdCompressionChunkerType) < 0) { | |
358 | return; |
|
358 | return; | |
359 | } |
|
359 | } |
@@ -400,7 +400,7 b' PyTypeObject ZstdCompressionDictType = {' | |||||
400 | }; |
|
400 | }; | |
401 |
|
401 | |||
402 | void compressiondict_module_init(PyObject* mod) { |
|
402 | void compressiondict_module_init(PyObject* mod) { | |
403 |
Py_TYPE(&ZstdCompressionDictType |
|
403 | Py_SET_TYPE(&ZstdCompressionDictType, &PyType_Type); | |
404 | if (PyType_Ready(&ZstdCompressionDictType) < 0) { |
|
404 | if (PyType_Ready(&ZstdCompressionDictType) < 0) { | |
405 | return; |
|
405 | return; | |
406 | } |
|
406 | } |
@@ -556,7 +556,7 b' PyTypeObject ZstdCompressionParametersTy' | |||||
556 | }; |
|
556 | }; | |
557 |
|
557 | |||
558 | void compressionparams_module_init(PyObject* mod) { |
|
558 | void compressionparams_module_init(PyObject* mod) { | |
559 |
Py_TYPE(&ZstdCompressionParametersType |
|
559 | Py_SET_TYPE(&ZstdCompressionParametersType, &PyType_Type); | |
560 | if (PyType_Ready(&ZstdCompressionParametersType) < 0) { |
|
560 | if (PyType_Ready(&ZstdCompressionParametersType) < 0) { | |
561 | return; |
|
561 | return; | |
562 | } |
|
562 | } |
@@ -811,7 +811,7 b' PyTypeObject ZstdCompressionReaderType =' | |||||
811 | void compressionreader_module_init(PyObject* mod) { |
|
811 | void compressionreader_module_init(PyObject* mod) { | |
812 | /* TODO make reader a sub-class of io.RawIOBase */ |
|
812 | /* TODO make reader a sub-class of io.RawIOBase */ | |
813 |
|
813 | |||
814 |
Py_TYPE(&ZstdCompressionReaderType |
|
814 | Py_SET_TYPE(&ZstdCompressionReaderType, &PyType_Type); | |
815 | if (PyType_Ready(&ZstdCompressionReaderType) < 0) { |
|
815 | if (PyType_Ready(&ZstdCompressionReaderType) < 0) { | |
816 | return; |
|
816 | return; | |
817 | } |
|
817 | } |
@@ -365,7 +365,7 b' PyTypeObject ZstdCompressionWriterType =' | |||||
365 | }; |
|
365 | }; | |
366 |
|
366 | |||
367 | void compressionwriter_module_init(PyObject* mod) { |
|
367 | void compressionwriter_module_init(PyObject* mod) { | |
368 |
Py_TYPE(&ZstdCompressionWriterType |
|
368 | Py_SET_TYPE(&ZstdCompressionWriterType, &PyType_Type); | |
369 | if (PyType_Ready(&ZstdCompressionWriterType) < 0) { |
|
369 | if (PyType_Ready(&ZstdCompressionWriterType) < 0) { | |
370 | return; |
|
370 | return; | |
371 | } |
|
371 | } |
@@ -249,7 +249,7 b' PyTypeObject ZstdCompressionObjType = {' | |||||
249 | }; |
|
249 | }; | |
250 |
|
250 | |||
251 | void compressobj_module_init(PyObject* module) { |
|
251 | void compressobj_module_init(PyObject* module) { | |
252 |
Py_TYPE(&ZstdCompressionObjType |
|
252 | Py_SET_TYPE(&ZstdCompressionObjType, &PyType_Type); | |
253 | if (PyType_Ready(&ZstdCompressionObjType) < 0) { |
|
253 | if (PyType_Ready(&ZstdCompressionObjType) < 0) { | |
254 | return; |
|
254 | return; | |
255 | } |
|
255 | } |
@@ -619,7 +619,7 b' static PyObject* ZstdCompressor_compress' | |||||
619 | goto finally; |
|
619 | goto finally; | |
620 | } |
|
620 | } | |
621 |
|
621 | |||
622 |
Py_SIZE(output |
|
622 | Py_SET_SIZE(output, outBuffer.pos); | |
623 |
|
623 | |||
624 | finally: |
|
624 | finally: | |
625 | PyBuffer_Release(&source); |
|
625 | PyBuffer_Release(&source); | |
@@ -1659,7 +1659,7 b' PyTypeObject ZstdCompressorType = {' | |||||
1659 | }; |
|
1659 | }; | |
1660 |
|
1660 | |||
1661 | void compressor_module_init(PyObject* mod) { |
|
1661 | void compressor_module_init(PyObject* mod) { | |
1662 |
Py_TYPE(&ZstdCompressorType |
|
1662 | Py_SET_TYPE(&ZstdCompressorType, &PyType_Type); | |
1663 | if (PyType_Ready(&ZstdCompressorType) < 0) { |
|
1663 | if (PyType_Ready(&ZstdCompressorType) < 0) { | |
1664 | return; |
|
1664 | return; | |
1665 | } |
|
1665 | } |
@@ -228,7 +228,7 b' PyTypeObject ZstdCompressorIteratorType ' | |||||
228 | }; |
|
228 | }; | |
229 |
|
229 | |||
230 | void compressoriterator_module_init(PyObject* mod) { |
|
230 | void compressoriterator_module_init(PyObject* mod) { | |
231 |
Py_TYPE(&ZstdCompressorIteratorType |
|
231 | Py_SET_TYPE(&ZstdCompressorIteratorType, &PyType_Type); | |
232 | if (PyType_Ready(&ZstdCompressorIteratorType) < 0) { |
|
232 | if (PyType_Ready(&ZstdCompressorIteratorType) < 0) { | |
233 | return; |
|
233 | return; | |
234 | } |
|
234 | } |
@@ -774,7 +774,7 b' PyTypeObject ZstdDecompressionReaderType' | |||||
774 | void decompressionreader_module_init(PyObject* mod) { |
|
774 | void decompressionreader_module_init(PyObject* mod) { | |
775 | /* TODO make reader a sub-class of io.RawIOBase */ |
|
775 | /* TODO make reader a sub-class of io.RawIOBase */ | |
776 |
|
776 | |||
777 |
Py_TYPE(&ZstdDecompressionReaderType |
|
777 | Py_SET_TYPE(&ZstdDecompressionReaderType, &PyType_Type); | |
778 | if (PyType_Ready(&ZstdDecompressionReaderType) < 0) { |
|
778 | if (PyType_Ready(&ZstdDecompressionReaderType) < 0) { | |
779 | return; |
|
779 | return; | |
780 | } |
|
780 | } |
@@ -288,7 +288,7 b' PyTypeObject ZstdDecompressionWriterType' | |||||
288 | }; |
|
288 | }; | |
289 |
|
289 | |||
290 | void decompressionwriter_module_init(PyObject* mod) { |
|
290 | void decompressionwriter_module_init(PyObject* mod) { | |
291 |
Py_TYPE(&ZstdDecompressionWriterType |
|
291 | Py_SET_TYPE(&ZstdDecompressionWriterType, &PyType_Type); | |
292 | if (PyType_Ready(&ZstdDecompressionWriterType) < 0) { |
|
292 | if (PyType_Ready(&ZstdDecompressionWriterType) < 0) { | |
293 | return; |
|
293 | return; | |
294 | } |
|
294 | } |
@@ -195,7 +195,7 b' PyTypeObject ZstdDecompressionObjType = ' | |||||
195 | }; |
|
195 | }; | |
196 |
|
196 | |||
197 | void decompressobj_module_init(PyObject* module) { |
|
197 | void decompressobj_module_init(PyObject* module) { | |
198 |
Py_TYPE(&ZstdDecompressionObjType |
|
198 | Py_SET_TYPE(&ZstdDecompressionObjType, &PyType_Type); | |
199 | if (PyType_Ready(&ZstdDecompressionObjType) < 0) { |
|
199 | if (PyType_Ready(&ZstdDecompressionObjType) < 0) { | |
200 | return; |
|
200 | return; | |
201 | } |
|
201 | } |
@@ -1811,7 +1811,7 b' PyTypeObject ZstdDecompressorType = {' | |||||
1811 | }; |
|
1811 | }; | |
1812 |
|
1812 | |||
1813 | void decompressor_module_init(PyObject* mod) { |
|
1813 | void decompressor_module_init(PyObject* mod) { | |
1814 |
Py_TYPE(&ZstdDecompressorType |
|
1814 | Py_SET_TYPE(&ZstdDecompressorType, &PyType_Type); | |
1815 | if (PyType_Ready(&ZstdDecompressorType) < 0) { |
|
1815 | if (PyType_Ready(&ZstdDecompressorType) < 0) { | |
1816 | return; |
|
1816 | return; | |
1817 | } |
|
1817 | } |
@@ -242,7 +242,7 b' PyTypeObject ZstdDecompressorIteratorTyp' | |||||
242 | }; |
|
242 | }; | |
243 |
|
243 | |||
244 | void decompressoriterator_module_init(PyObject* mod) { |
|
244 | void decompressoriterator_module_init(PyObject* mod) { | |
245 |
Py_TYPE(&ZstdDecompressorIteratorType |
|
245 | Py_SET_TYPE(&ZstdDecompressorIteratorType, &PyType_Type); | |
246 | if (PyType_Ready(&ZstdDecompressorIteratorType) < 0) { |
|
246 | if (PyType_Ready(&ZstdDecompressorIteratorType) < 0) { | |
247 | return; |
|
247 | return; | |
248 | } |
|
248 | } |
@@ -128,7 +128,7 b' PyTypeObject FrameParametersType = {' | |||||
128 | }; |
|
128 | }; | |
129 |
|
129 | |||
130 | void frameparams_module_init(PyObject* mod) { |
|
130 | void frameparams_module_init(PyObject* mod) { | |
131 |
Py_TYPE(&FrameParametersType |
|
131 | Py_SET_TYPE(&FrameParametersType, &PyType_Type); | |
132 | if (PyType_Ready(&FrameParametersType) < 0) { |
|
132 | if (PyType_Ready(&FrameParametersType) < 0) { | |
133 | return; |
|
133 | return; | |
134 | } |
|
134 | } |
@@ -9,6 +9,7 b'' | |||||
9 | #define PY_SSIZE_T_CLEAN |
|
9 | #define PY_SSIZE_T_CLEAN | |
10 | #include <Python.h> |
|
10 | #include <Python.h> | |
11 | #include "structmember.h" |
|
11 | #include "structmember.h" | |
|
12 | #include <pythoncapi_compat.h> | |||
12 |
|
13 | |||
13 | #define ZSTD_STATIC_LINKING_ONLY |
|
14 | #define ZSTD_STATIC_LINKING_ONLY | |
14 | #define ZDICT_STATIC_LINKING_ONLY |
|
15 | #define ZDICT_STATIC_LINKING_ONLY |
@@ -119,7 +119,7 b' static PyObject *listdir_stat_new(PyType' | |||||
119 |
|
119 | |||
120 | static void listdir_stat_dealloc(PyObject *o) |
|
120 | static void listdir_stat_dealloc(PyObject *o) | |
121 | { |
|
121 | { | |
122 |
o |
|
122 | Py_TYPE(o)->tp_free(o); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | static PyObject *listdir_stat_getitem(PyObject *self, PyObject *key) |
|
125 | static PyObject *listdir_stat_getitem(PyObject *self, PyObject *key) |
@@ -21,6 +21,7 b'' | |||||
21 | #include <ctype.h> |
|
21 | #include <ctype.h> | |
22 | #include <stdlib.h> |
|
22 | #include <stdlib.h> | |
23 | #include <string.h> |
|
23 | #include <string.h> | |
|
24 | #include "pythoncapi_compat.h" | |||
24 |
|
25 | |||
25 | #include "util.h" |
|
26 | #include "util.h" | |
26 |
|
27 | |||
@@ -678,7 +679,7 b' static PyObject *hashmangle(const char *' | |||||
678 | } |
|
679 | } | |
679 |
|
680 | |||
680 | assert(PyBytes_Check(ret)); |
|
681 | assert(PyBytes_Check(ret)); | |
681 |
Py_SIZE(ret |
|
682 | Py_SET_SIZE(ret, destlen); | |
682 |
|
683 | |||
683 | return ret; |
|
684 | return ret; | |
684 | } |
|
685 | } |
@@ -11,6 +11,7 b' New errors are not allowed. Warnings are' | |||||
11 | > -X contrib/python-zstandard \ |
|
11 | > -X contrib/python-zstandard \ | |
12 | > -X hgext/fsmonitor/pywatchman \ |
|
12 | > -X hgext/fsmonitor/pywatchman \ | |
13 | > -X mercurial/thirdparty \ |
|
13 | > -X mercurial/thirdparty \ | |
|
14 | > -X mercurial/pythoncapi_compat.h \ | |||
14 | > | sed 's-\\-/-g' | "$check_code" --warnings --per-file=0 - || false |
|
15 | > | sed 's-\\-/-g' | "$check_code" --warnings --per-file=0 - || false | |
15 | Skipping contrib/automation/hgautomation/__init__.py it has no-che?k-code (glob) |
|
16 | Skipping contrib/automation/hgautomation/__init__.py it has no-che?k-code (glob) | |
16 | Skipping contrib/automation/hgautomation/aws.py it has no-che?k-code (glob) |
|
17 | Skipping contrib/automation/hgautomation/aws.py it has no-che?k-code (glob) |
General Comments 0
You need to be logged in to leave comments.
Login now