@@ -56,6 +56,11 @@ whose size is determined when the object is allocated.
56
56
# define Py_REF_DEBUG
57
57
#endif
58
58
59
+ #if defined(_Py_OPAQUE_PYOBJECT ) && !defined(Py_LIMITED_API )
60
+ # error "_Py_OPAQUE_PYOBJECT only makes sense with Py_LIMITED_API"
61
+ #endif
62
+
63
+ #ifndef _Py_OPAQUE_PYOBJECT
59
64
/* PyObject_HEAD defines the initial segment of every PyObject. */
60
65
#define PyObject_HEAD PyObject ob_base;
61
66
@@ -99,6 +104,8 @@ whose size is determined when the object is allocated.
99
104
* not necessarily a byte count.
100
105
*/
101
106
#define PyObject_VAR_HEAD PyVarObject ob_base;
107
+ #endif // !defined(_Py_OPAQUE_PYOBJECT)
108
+
102
109
#define Py_INVALID_SIZE (Py_ssize_t)-1
103
110
104
111
/* PyObjects are given a minimum alignment so that the least significant bits
@@ -112,7 +119,9 @@ whose size is determined when the object is allocated.
112
119
* by hand. Similarly every pointer to a variable-size Python object can,
113
120
* in addition, be cast to PyVarObject*.
114
121
*/
115
- #ifndef Py_GIL_DISABLED
122
+ #ifdef _Py_OPAQUE_PYOBJECT
123
+ /* PyObject is opaque */
124
+ #elif !defined(Py_GIL_DISABLED )
116
125
struct _object {
117
126
#if (defined(__GNUC__ ) || defined(__clang__ )) \
118
127
&& !(defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L )
@@ -168,15 +177,18 @@ struct _object {
168
177
Py_ssize_t ob_ref_shared ; // shared (atomic) reference count
169
178
PyTypeObject * ob_type ;
170
179
};
171
- #endif
180
+ #endif // !defined(_Py_OPAQUE_PYOBJECT)
172
181
173
182
/* Cast argument to PyObject* type. */
174
183
#define _PyObject_CAST (op ) _Py_CAST(PyObject*, (op))
175
184
176
- typedef struct {
185
+ #ifndef _Py_OPAQUE_PYOBJECT
186
+ struct PyVarObject {
177
187
PyObject ob_base ;
178
188
Py_ssize_t ob_size ; /* Number of items in variable part */
179
- } PyVarObject ;
189
+ };
190
+ #endif
191
+ typedef struct PyVarObject PyVarObject ;
180
192
181
193
/* Cast argument to PyVarObject* type. */
182
194
#define _PyVarObject_CAST (op ) _Py_CAST(PyVarObject*, (op))
@@ -286,6 +298,7 @@ PyAPI_FUNC(PyTypeObject*) Py_TYPE(PyObject *ob);
286
298
PyAPI_DATA (PyTypeObject ) PyLong_Type ;
287
299
PyAPI_DATA (PyTypeObject ) PyBool_Type ;
288
300
301
+ #ifndef _Py_OPAQUE_PYOBJECT
289
302
// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
290
303
static inline Py_ssize_t Py_SIZE (PyObject * ob ) {
291
304
assert (Py_TYPE (ob ) != & PyLong_Type );
@@ -295,6 +308,7 @@ static inline Py_ssize_t Py_SIZE(PyObject *ob) {
295
308
#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
296
309
# define Py_SIZE (ob ) Py_SIZE(_PyObject_CAST(ob))
297
310
#endif
311
+ #endif // !defined(_Py_OPAQUE_PYOBJECT)
298
312
299
313
static inline int Py_IS_TYPE (PyObject * ob , PyTypeObject * type ) {
300
314
return Py_TYPE (ob ) == type ;
@@ -304,6 +318,7 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
304
318
#endif
305
319
306
320
321
+ #ifndef _Py_OPAQUE_PYOBJECT
307
322
static inline void Py_SET_TYPE (PyObject * ob , PyTypeObject * type ) {
308
323
ob -> ob_type = type ;
309
324
}
@@ -323,6 +338,7 @@ static inline void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
323
338
#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
324
339
# define Py_SET_SIZE (ob , size ) Py_SET_SIZE(_PyVarObject_CAST(ob), (size))
325
340
#endif
341
+ #endif // !defined(_Py_OPAQUE_PYOBJECT)
326
342
327
343
328
344
/*
0 commit comments