func,Py_GetRecursionLimit,3.2,,
func,Py_GetVersion,3.2,,
data,Py_HasFileSystemDefaultEncoding,3.2,,
+func,Py_IS_TYPE,3.15,,
func,Py_IncRef,3.2,,
func,Py_Initialize,3.2,,
func,Py_InitializeEx,3.2,,
macro,Py_RELATIVE_OFFSET,3.12,,
func,Py_ReprEnter,3.2,,
func,Py_ReprLeave,3.2,,
+func,Py_SET_SIZE,3.15,,
+func,Py_SIZE,3.15,,
func,Py_SetProgramName,3.2,,
func,Py_SetPythonHome,3.2,,
func,Py_SetRecursionLimit,3.2,,
# endif
};
#else
- Py_ssize_t ob_refcnt;
+ Py_ssize_t ob_refcnt; // part of stable ABI; do not change
#endif
_Py_ALIGNED_DEF(_PyObject_MIN_ALIGNMENT, char) _aligner;
};
- PyTypeObject *ob_type;
+ PyTypeObject *ob_type; // part of stable ABI; do not change
};
#else
// Objects that are not owned by any thread use a thread id (tid) of zero.
#ifndef _Py_OPAQUE_PYOBJECT
struct PyVarObject {
PyObject ob_base;
- Py_ssize_t ob_size; /* Number of items in variable part */
+ Py_ssize_t ob_size; // Number of items in variable part. Part of stable ABI
};
#endif
typedef struct PyVarObject PyVarObject;
}
#endif
-// Py_TYPE() implementation for the stable ABI
+PyAPI_DATA(PyTypeObject) PyLong_Type;
+PyAPI_DATA(PyTypeObject) PyBool_Type;
+
+/* Definitions for the stable ABI */
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 14)
PyAPI_FUNC(PyTypeObject*) Py_TYPE(PyObject *ob);
+#endif
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15)
+PyAPI_FUNC(Py_ssize_t) Py_SIZE(PyObject *ob);
+PyAPI_FUNC(int) Py_IS_TYPE(PyObject *ob, PyTypeObject *type);
+PyAPI_FUNC(void) Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size);
+#endif
+
+#ifndef _Py_OPAQUE_PYOBJECT
-#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030e0000
- // Stable ABI implements Py_TYPE() as a function call
- // on limited C API version 3.14 and newer.
+static inline void
+Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
+{
+ ob->ob_type = type;
+}
+
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 11)
+// Non-limited API & limited API 3.11 & below: use static inline functions and
+// use _PyObject_CAST so that users don't need their own casts
+# define Py_TYPE(ob) _Py_TYPE_impl(_PyObject_CAST(ob))
+# define Py_SIZE(ob) _Py_SIZE_impl(_PyObject_CAST(ob))
+# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl(_PyObject_CAST(ob), (type))
+# define Py_SET_SIZE(ob, size) _Py_SET_SIZE_impl(_PyVarObject_CAST(ob), (size))
+# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
+#elif Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15)
+// Limited API 3.11-3.14: use static inline functions, without casts
+# define Py_SIZE(ob) _Py_SIZE_impl(ob)
+# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl((ob), (type))
+# define Py_SET_SIZE(ob, size) _Py_SET_SIZE_impl((ob), (size))
+# if Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14)
+// Py_TYPE() is static inline only on Limited API 3.13 and below
+# define Py_TYPE(ob) _Py_TYPE_impl(ob)
+# endif
#else
- static inline PyTypeObject* _Py_TYPE(PyObject *ob)
- {
- return ob->ob_type;
- }
- #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
- # define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST(ob))
- #else
- # define Py_TYPE(ob) _Py_TYPE(ob)
- #endif
+// Limited API 3.15+: use function calls
#endif
-PyAPI_DATA(PyTypeObject) PyLong_Type;
-PyAPI_DATA(PyTypeObject) PyBool_Type;
+static inline
+PyTypeObject* _Py_TYPE_impl(PyObject *ob)
+{
+ return ob->ob_type;
+}
-#ifndef _Py_OPAQUE_PYOBJECT
// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
-static inline Py_ssize_t Py_SIZE(PyObject *ob) {
+static inline Py_ssize_t
+_Py_SIZE_impl(PyObject *ob)
+{
assert(Py_TYPE(ob) != &PyLong_Type);
assert(Py_TYPE(ob) != &PyBool_Type);
return _PyVarObject_CAST(ob)->ob_size;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
-#endif
-#endif // !defined(_Py_OPAQUE_PYOBJECT)
-static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
+static inline int
+_Py_IS_TYPE_impl(PyObject *ob, PyTypeObject *type)
+{
return Py_TYPE(ob) == type;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
-#endif
-
-#ifndef _Py_OPAQUE_PYOBJECT
-static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
- ob->ob_type = type;
-}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
-#endif
-
-static inline void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
+static inline void
+_Py_SET_SIZE_impl(PyVarObject *ob, Py_ssize_t size)
+{
assert(Py_TYPE(_PyObject_CAST(ob)) != &PyLong_Type);
assert(Py_TYPE(_PyObject_CAST(ob)) != &PyBool_Type);
#ifdef Py_GIL_DISABLED
ob->ob_size = size;
#endif
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define Py_SET_SIZE(ob, size) Py_SET_SIZE(_PyVarObject_CAST(ob), (size))
-#endif
+
#endif // !defined(_Py_OPAQUE_PYOBJECT)