@@ -54,11 +54,11 @@ whose size is determined when the object is allocated.
5454
5555/* Py_DEBUG implies Py_REF_DEBUG. */
5656#if defined(Py_DEBUG ) && !defined(Py_REF_DEBUG )
57- #define Py_REF_DEBUG
57+ # define Py_REF_DEBUG
5858#endif
5959
60- #if defined(Py_LIMITED_API ) && defined(Py_REF_DEBUG )
61- #error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG
60+ #if defined(Py_LIMITED_API ) && defined(Py_TRACE_REFS )
61+ # error Py_LIMITED_API is incompatible with Py_TRACE_REFS
6262#endif
6363
6464/* PyTypeObject structure is defined in cpython/object.h.
@@ -74,8 +74,8 @@ typedef struct _typeobject PyTypeObject;
7474#define _PyObject_EXTRA_INIT 0, 0,
7575
7676#else
77- #define _PyObject_HEAD_EXTRA
78- #define _PyObject_EXTRA_INIT
77+ # define _PyObject_HEAD_EXTRA
78+ # define _PyObject_EXTRA_INIT
7979#endif
8080
8181/* PyObject_HEAD defines the initial segment of every PyObject. */
@@ -427,21 +427,46 @@ PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno,
427427
428428PyAPI_FUNC (void ) _Py_Dealloc (PyObject * );
429429
430+ /*
431+ These are provided as conveniences to Python runtime embedders, so that
432+ they can have object code that is not dependent on Python compilation flags.
433+ */
434+ PyAPI_FUNC (void ) Py_IncRef (PyObject * );
435+ PyAPI_FUNC (void ) Py_DecRef (PyObject * );
436+
437+ // Similar to Py_IncRef() and Py_DecRef() but the argument must be non-NULL.
438+ // Private functions used by Py_INCREF() and Py_DECREF().
439+ PyAPI_FUNC (void ) _Py_IncRef (PyObject * );
440+ PyAPI_FUNC (void ) _Py_DecRef (PyObject * );
441+
430442static inline void _Py_INCREF (PyObject * op )
431443{
444+ #if defined(Py_REF_DEBUG ) && defined(Py_LIMITED_API ) && Py_LIMITED_API + 0 >= 0x030A0000
445+ // Stable ABI for Python 3.10 built in debug mode.
446+ _Py_IncRef (op );
447+ #else
448+ // Non-limited C API and limited C API for Python 3.9 and older access
449+ // directly PyObject.ob_refcnt.
432450#ifdef Py_REF_DEBUG
433451 _Py_RefTotal ++ ;
434452#endif
435453 op -> ob_refcnt ++ ;
454+ #endif
436455}
437456#define Py_INCREF (op ) _Py_INCREF(_PyObject_CAST(op))
438457
439458static inline void _Py_DECREF (
440- #ifdef Py_REF_DEBUG
459+ #if defined( Py_REF_DEBUG ) && !( defined ( Py_LIMITED_API ) && Py_LIMITED_API + 0 >= 0x030A0000 )
441460 const char * filename , int lineno ,
442461#endif
443462 PyObject * op )
444463{
464+ #if defined(Py_REF_DEBUG ) && defined(Py_LIMITED_API ) && Py_LIMITED_API + 0 >= 0x030A0000
465+ // Stable ABI for Python 3.10 built in debug mode.
466+ _Py_DecRef (op );
467+ #else
468+ // Non-limited C API and limited C API for Python 3.9 and older access
469+ // directly PyObject.ob_refcnt.
445470#ifdef Py_REF_DEBUG
446471 _Py_RefTotal -- ;
447472#endif
@@ -455,8 +480,9 @@ static inline void _Py_DECREF(
455480 else {
456481 _Py_Dealloc (op );
457482 }
483+ #endif
458484}
459- #ifdef Py_REF_DEBUG
485+ #if defined( Py_REF_DEBUG ) && !(defined( Py_LIMITED_API ) && Py_LIMITED_API + 0 >= 0x030A0000 )
460486# define Py_DECREF (op ) _Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
461487#else
462488# define Py_DECREF (op ) _Py_DECREF(_PyObject_CAST(op))
@@ -525,13 +551,6 @@ static inline void _Py_XDECREF(PyObject *op)
525551
526552#define Py_XDECREF (op ) _Py_XDECREF(_PyObject_CAST(op))
527553
528- /*
529- These are provided as conveniences to Python runtime embedders, so that
530- they can have object code that is not dependent on Python compilation flags.
531- */
532- PyAPI_FUNC (void ) Py_IncRef (PyObject * );
533- PyAPI_FUNC (void ) Py_DecRef (PyObject * );
534-
535554// Create a new strong reference to an object:
536555// increment the reference count of the object and return the object.
537556PyAPI_FUNC (PyObject * ) Py_NewRef (PyObject * obj );
0 commit comments