@@ -56,6 +56,24 @@ _PyObject_CheckConsistency(PyObject *op, int check_content)
56
56
#ifdef Py_REF_DEBUG
57
57
Py_ssize_t _Py_RefTotal ;
58
58
59
+ static inline void
60
+ reftotal_increment (void )
61
+ {
62
+ _Py_RefTotal ++ ;
63
+ }
64
+
65
+ static inline void
66
+ reftotal_decrement (void )
67
+ {
68
+ _Py_RefTotal -- ;
69
+ }
70
+
71
+ void
72
+ _Py_AddRefTotal (Py_ssize_t n )
73
+ {
74
+ _Py_RefTotal += n ;
75
+ }
76
+
59
77
Py_ssize_t
60
78
_Py_GetRefTotal (void )
61
79
{
@@ -121,6 +139,32 @@ _Py_NegativeRefcount(const char *filename, int lineno, PyObject *op)
121
139
filename , lineno , __func__ );
122
140
}
123
141
142
+ /* This is exposed strictly for use in Py_INCREF(). */
143
+ PyAPI_FUNC (void )
144
+ _Py_IncRefTotal_DO_NOT_USE_THIS (void )
145
+ {
146
+ reftotal_increment ();
147
+ }
148
+
149
+ /* This is exposed strictly for use in Py_DECREF(). */
150
+ PyAPI_FUNC (void )
151
+ _Py_DecRefTotal_DO_NOT_USE_THIS (void )
152
+ {
153
+ reftotal_decrement ();
154
+ }
155
+
156
+ void
157
+ _Py_IncRefTotal (void )
158
+ {
159
+ reftotal_increment ();
160
+ }
161
+
162
+ void
163
+ _Py_DecRefTotal (void )
164
+ {
165
+ reftotal_decrement ();
166
+ }
167
+
124
168
#endif /* Py_REF_DEBUG */
125
169
126
170
void
@@ -138,12 +182,18 @@ Py_DecRef(PyObject *o)
138
182
void
139
183
_Py_IncRef (PyObject * o )
140
184
{
185
+ #ifdef Py_REF_DEBUG
186
+ reftotal_increment ();
187
+ #endif
141
188
Py_INCREF (o );
142
189
}
143
190
144
191
void
145
192
_Py_DecRef (PyObject * o )
146
193
{
194
+ #ifdef Py_REF_DEBUG
195
+ reftotal_decrement ();
196
+ #endif
147
197
Py_DECREF (o );
148
198
}
149
199
@@ -238,17 +288,12 @@ PyObject_CallFinalizerFromDealloc(PyObject *self)
238
288
/* tp_finalize resurrected it! Make it look like the original Py_DECREF
239
289
* never happened. */
240
290
Py_ssize_t refcnt = Py_REFCNT (self );
241
- _Py_NewReference (self );
291
+ _Py_NewReferenceNoTotal (self );
242
292
Py_SET_REFCNT (self , refcnt );
243
293
244
294
_PyObject_ASSERT (self ,
245
295
(!_PyType_IS_GC (Py_TYPE (self ))
246
296
|| _PyObject_GC_IS_TRACKED (self )));
247
- /* If Py_REF_DEBUG macro is defined, _Py_NewReference() increased
248
- _Py_RefTotal, so we need to undo that. */
249
- #ifdef Py_REF_DEBUG
250
- _Py_RefTotal -- ;
251
- #endif
252
297
return -1 ;
253
298
}
254
299
@@ -2010,21 +2055,33 @@ _PyTypes_FiniTypes(PyInterpreterState *interp)
2010
2055
}
2011
2056
2012
2057
2013
- void
2014
- _Py_NewReference (PyObject * op )
2058
+ static inline void
2059
+ new_reference (PyObject * op )
2015
2060
{
2016
2061
if (_PyRuntime .tracemalloc .config .tracing ) {
2017
2062
_PyTraceMalloc_NewReference (op );
2018
2063
}
2019
- #ifdef Py_REF_DEBUG
2020
- _Py_RefTotal ++ ;
2021
- #endif
2022
2064
Py_SET_REFCNT (op , 1 );
2023
2065
#ifdef Py_TRACE_REFS
2024
2066
_Py_AddToAllObjects (op , 1 );
2025
2067
#endif
2026
2068
}
2027
2069
2070
+ void
2071
+ _Py_NewReference (PyObject * op )
2072
+ {
2073
+ #ifdef Py_REF_DEBUG
2074
+ reftotal_increment ();
2075
+ #endif
2076
+ new_reference (op );
2077
+ }
2078
+
2079
+ void
2080
+ _Py_NewReferenceNoTotal (PyObject * op )
2081
+ {
2082
+ new_reference (op );
2083
+ }
2084
+
2028
2085
2029
2086
#ifdef Py_TRACE_REFS
2030
2087
void
0 commit comments