@@ -172,6 +172,7 @@ check by comparing the reference count field to the immortality reference count.
172172 */
173173struct _object {
174174 _PyObject_HEAD_EXTRA
175+
175176#if (defined(__GNUC__ ) || defined(__clang__ )) \
176177 && !(defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L )
177178 // On C99 and older, anonymous union is a GCC and clang extension
@@ -210,28 +211,22 @@ typedef struct {
210211
211212// Test if the 'x' object is the 'y' object, the same as "x is y" in Python.
212213PyAPI_FUNC (int ) Py_Is (PyObject * x , PyObject * y );
213- #if 0 // GraalPy change
214- #define Py_Is (x , y ) ((x) == (y))
215- #endif // GraalPy change
214+ // GraalPy change: call function
215+ #define Py_Is (x , y ) (Py_Is(x, y))
216216
217-
218- PyAPI_FUNC (Py_ssize_t ) GraalPyPrivate_REFCNT (PyObject * ob );
219- static inline Py_ssize_t Py_REFCNT (PyObject * ob ) {
220- return GraalPyPrivate_REFCNT (ob );
221- }
217+ // GraalPy change: backported declaration from CPython 3.14
218+ // Py_REFCNT() implementation for the stable ABI
219+ PyAPI_FUNC (Py_ssize_t ) Py_REFCNT (PyObject * ob );
222220#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
223221# define Py_REFCNT (ob ) Py_REFCNT(_PyObject_CAST(ob))
224222#endif
225223
226224
225+ // GraalPy public API, mainly for non-C languages that can't use macros
226+ PyAPI_FUNC (PyTypeObject * ) GraalPy_TYPE (PyObject * ob );
227227// bpo-39573: The Py_SET_TYPE() function must be used to set an object type.
228- PyAPI_FUNC (PyTypeObject * ) GraalPyPrivate_TYPE (PyObject * ob );
229228static inline PyTypeObject * Py_TYPE (PyObject * ob ) {
230- #if defined(GRAALVM_PYTHON ) && defined(NDEBUG )
231- return (pointer_to_stub (ob )-> ob_type );
232- #else
233- return GraalPyPrivate_TYPE (ob );
234- #endif
229+ return GraalPy_TYPE (ob );
235230}
236231#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
237232# define Py_TYPE (ob ) Py_TYPE(_PyObject_CAST(ob))
@@ -240,12 +235,13 @@ static inline PyTypeObject* Py_TYPE(PyObject *ob) {
240235PyAPI_DATA (PyTypeObject ) PyLong_Type ;
241236PyAPI_DATA (PyTypeObject ) PyBool_Type ;
242237
238+ // GraalPy public API, mainly for non-C languages that can't use macros
239+ PyAPI_FUNC (Py_ssize_t ) GraalPy_SIZE (PyObject * ob );
243240// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
244- PyAPI_FUNC (Py_ssize_t ) GraalPyPrivate_SIZE (PyObject * ob );
245241static inline Py_ssize_t Py_SIZE (PyObject * ob ) {
246242 assert (Py_TYPE (ob ) != & PyLong_Type );
247243 assert (Py_TYPE (ob ) != & PyBool_Type );
248- return GraalPyPrivate_SIZE (ob );
244+ return GraalPy_SIZE (ob );
249245}
250246#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
251247# define Py_SIZE (ob ) Py_SIZE(_PyObject_CAST(ob))
@@ -273,22 +269,19 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
273269#endif
274270
275271
276- PyAPI_FUNC (void ) GraalPyPrivate_SET_REFCNT (PyObject * ob , Py_ssize_t refcnt );
272+ // GraalPy change: backported declaration from 3.14
273+ // Py_SET_REFCNT() implementation for stable ABI
274+ PyAPI_FUNC (void ) _Py_SetRefcnt (PyObject * ob , Py_ssize_t refcnt );
275+
277276static inline void Py_SET_REFCNT (PyObject * ob , Py_ssize_t refcnt ) {
278- // This immortal check is for code that is unaware of immortal objects.
279- // The runtime tracks these objects and we should avoid as much
280- // as possible having extensions inadvertently change the refcnt
281- // of an immortalized object.
282- if (_Py_IsImmortal (ob )) {
283- return ;
284- }
285- GraalPyPrivate_SET_REFCNT (ob , refcnt );
277+ _Py_SetRefcnt (ob , refcnt );
286278}
287279#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
288280# define Py_SET_REFCNT (ob , refcnt ) Py_SET_REFCNT(_PyObject_CAST(ob), (refcnt))
289281#endif
290282
291283
284+ // GraalPy public API, mainly for non-C languages that can't use macros
292285PyAPI_FUNC (void ) GraalPy_SET_TYPE (PyObject * ob , PyTypeObject * type );
293286static inline void Py_SET_TYPE (PyObject * ob , PyTypeObject * type ) {
294287 GraalPy_SET_TYPE (ob , type );
@@ -297,7 +290,7 @@ static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
297290# define Py_SET_TYPE (ob , type ) Py_SET_TYPE(_PyObject_CAST(ob), type)
298291#endif
299292
300-
293+ // GraalPy public API, mainly for non-C languages that can't use macros
301294PyAPI_FUNC (void ) GraalPy_SET_SIZE (PyVarObject * ob , Py_ssize_t size );
302295static inline void Py_SET_SIZE (PyVarObject * ob , Py_ssize_t size ) {
303296 GraalPy_SET_SIZE (ob , size );
0 commit comments