Skip to content

Commit aee27c9

Browse files
committed
Update for _Py_OPAQUE_PYOBJECT
- Don't expose the "real" functions for old Limited API - Move implementations below defines so that they pick up the right Py_TYPE definition
1 parent eebcc12 commit aee27c9

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

Include/object.h

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,44 @@ PyAPI_DATA(PyTypeObject) PyLong_Type;
269269
PyAPI_DATA(PyTypeObject) PyBool_Type;
270270

271271
/* Definitions for the stable ABI */
272+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 14)
272273
PyAPI_FUNC(PyTypeObject*) Py_TYPE(PyObject *ob);
274+
#endif
275+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15)
273276
PyAPI_FUNC(Py_ssize_t) Py_SIZE(PyObject *ob);
274277
PyAPI_FUNC(int) Py_IS_TYPE(PyObject *ob, PyTypeObject *type);
275278
PyAPI_FUNC(void) Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size);
279+
#endif
276280

277281
#ifndef _Py_OPAQUE_PYOBJECT
278282

283+
static inline void
284+
Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
285+
{
286+
ob->ob_type = type;
287+
}
288+
289+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 11)
290+
// Non-limited API & limited API 3.11 & below: use static inline functions and
291+
// use _PyObject_CAST so that users don't need their own casts
292+
# define Py_TYPE(ob) _Py_TYPE_impl(_PyObject_CAST(ob))
293+
# define Py_SIZE(ob) _Py_SIZE_impl(_PyObject_CAST(ob))
294+
# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl(_PyObject_CAST(ob), (type))
295+
# define Py_SET_SIZE(ob, size) _Py_SET_SIZE_impl(_PyVarObject_CAST(ob), (size))
296+
# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
297+
#elif Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15)
298+
// Limited API 3.11-3.14: use static inline functions, without casts
299+
# define Py_SIZE(ob) _Py_SIZE_impl(ob)
300+
# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl((ob), (type))
301+
# define Py_SET_SIZE(ob, size) _Py_SET_SIZE_impl((ob), (size))
302+
# if Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14)
303+
// Py_TYPE() is static inline only on Limited API 3.13 and below
304+
# define Py_TYPE(ob) _Py_TYPE_impl(ob)
305+
# endif
306+
#else
307+
// Limited API 3.15+: use function calls
308+
#endif
309+
279310
static inline
280311
PyTypeObject* _Py_TYPE_impl(PyObject *ob)
281312
{
@@ -309,33 +340,6 @@ _Py_SET_SIZE_impl(PyVarObject *ob, Py_ssize_t size)
309340
#endif
310341
}
311342

312-
static inline void
313-
Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
314-
{
315-
ob->ob_type = type;
316-
}
317-
318-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 11)
319-
// Non-limited API & limited API 3.11 & below: use static inline functions and
320-
// use _PyObject_CAST so that users don't need their own casts
321-
# define Py_TYPE(ob) _Py_TYPE_impl(_PyObject_CAST(ob))
322-
# define Py_SIZE(ob) _Py_SIZE_impl(_PyObject_CAST(ob))
323-
# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl(_PyObject_CAST(ob), (type))
324-
# define Py_SET_SIZE(ob, size) _Py_SET_SIZE_impl(_PyVarObject_CAST(ob), (size))
325-
# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
326-
#elif Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15)
327-
// Limited API 3.11-3.14: use static inline functions, without casts
328-
# define Py_SIZE(ob) _Py_SIZE_impl(ob)
329-
# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl((ob), (type))
330-
# define Py_SET_SIZE(ob, size) _Py_SET_SIZE_impl((ob), (size))
331-
# if Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14)
332-
// Py_TYPE() is static inline only on Limited API 3.13 and below
333-
# define Py_TYPE(ob) _Py_TYPE_impl(ob)
334-
# endif
335-
#else
336-
// Limited API 3.15+: use function calls
337-
#endif
338-
339343
#endif // !defined(_Py_OPAQUE_PYOBJECT)
340344

341345

0 commit comments

Comments
 (0)