@@ -54,11 +54,11 @@ whose size is determined when the object is allocated.
54
54
55
55
/* Py_DEBUG implies Py_REF_DEBUG. */
56
56
#if defined(Py_DEBUG ) && !defined(Py_REF_DEBUG )
57
- #define Py_REF_DEBUG
57
+ # define Py_REF_DEBUG
58
58
#endif
59
59
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
62
62
#endif
63
63
64
64
/* PyTypeObject structure is defined in cpython/object.h.
@@ -74,8 +74,8 @@ typedef struct _typeobject PyTypeObject;
74
74
#define _PyObject_EXTRA_INIT 0, 0,
75
75
76
76
#else
77
- #define _PyObject_HEAD_EXTRA
78
- #define _PyObject_EXTRA_INIT
77
+ # define _PyObject_HEAD_EXTRA
78
+ # define _PyObject_EXTRA_INIT
79
79
#endif
80
80
81
81
/* PyObject_HEAD defines the initial segment of every PyObject. */
@@ -427,21 +427,46 @@ PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno,
427
427
428
428
PyAPI_FUNC (void ) _Py_Dealloc (PyObject * );
429
429
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
+
430
442
static inline void _Py_INCREF (PyObject * op )
431
443
{
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.
432
450
#ifdef Py_REF_DEBUG
433
451
_Py_RefTotal ++ ;
434
452
#endif
435
453
op -> ob_refcnt ++ ;
454
+ #endif
436
455
}
437
456
#define Py_INCREF (op ) _Py_INCREF(_PyObject_CAST(op))
438
457
439
458
static inline void _Py_DECREF (
440
- #ifdef Py_REF_DEBUG
459
+ #if defined( Py_REF_DEBUG ) && !( defined ( Py_LIMITED_API ) && Py_LIMITED_API + 0 >= 0x030A0000 )
441
460
const char * filename , int lineno ,
442
461
#endif
443
462
PyObject * op )
444
463
{
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.
445
470
#ifdef Py_REF_DEBUG
446
471
_Py_RefTotal -- ;
447
472
#endif
@@ -455,8 +480,9 @@ static inline void _Py_DECREF(
455
480
else {
456
481
_Py_Dealloc (op );
457
482
}
483
+ #endif
458
484
}
459
- #ifdef Py_REF_DEBUG
485
+ #if defined( Py_REF_DEBUG ) && !(defined( Py_LIMITED_API ) && Py_LIMITED_API + 0 >= 0x030A0000 )
460
486
# define Py_DECREF (op ) _Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
461
487
#else
462
488
# define Py_DECREF (op ) _Py_DECREF(_PyObject_CAST(op))
@@ -525,13 +551,6 @@ static inline void _Py_XDECREF(PyObject *op)
525
551
526
552
#define Py_XDECREF (op ) _Py_XDECREF(_PyObject_CAST(op))
527
553
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
-
535
554
// Create a new strong reference to an object:
536
555
// increment the reference count of the object and return the object.
537
556
PyAPI_FUNC (PyObject * ) Py_NewRef (PyObject * obj );
0 commit comments