File tree Expand file tree Collapse file tree 3 files changed +20
-11
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +20
-11
lines changed
Original file line number Diff line number Diff line change @@ -135,15 +135,20 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
135
135
_Py_INCREF_IMMORTAL_STAT_INC ();
136
136
return ;
137
137
}
138
- #ifdef Py_REF_DEBUG
139
- _Py_AddRefTotal (_PyThreadState_GET (), n );
140
- #endif
141
- #if !defined(Py_GIL_DISABLED )
142
- #if SIZEOF_VOID_P > 4
143
- op -> ob_refcnt += (PY_UINT32_T )n ;
144
- #else
145
- op -> ob_refcnt += n ;
146
- #endif
138
+ #ifndef Py_GIL_DISABLED
139
+ Py_ssize_t refcnt = _Py_REFCNT (op );
140
+ Py_ssize_t new_refcnt = refcnt + n ;
141
+ if (new_refcnt >= (Py_ssize_t )_Py_IMMORTAL_MINIMUM_REFCNT ) {
142
+ new_refcnt = _Py_IMMORTAL_INITIAL_REFCNT ;
143
+ }
144
+ # if SIZEOF_VOID_P > 4
145
+ op -> ob_refcnt = (PY_UINT32_T )new_refcnt ;
146
+ # else
147
+ op -> ob_refcnt = new_refcnt ;
148
+ # endif
149
+ # ifdef Py_REF_DEBUG
150
+ _Py_AddRefTotal (_PyThreadState_GET (), new_refcnt - refcnt );
151
+ # endif
147
152
#else
148
153
if (_Py_IsOwnedByCurrentThread (op )) {
149
154
uint32_t local = op -> ob_ref_local ;
@@ -160,6 +165,9 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
160
165
else {
161
166
_Py_atomic_add_ssize (& op -> ob_ref_shared , (n << _Py_REF_SHARED_SHIFT ));
162
167
}
168
+ # ifdef Py_REF_DEBUG
169
+ _Py_AddRefTotal (_PyThreadState_GET (), n );
170
+ # endif
163
171
#endif
164
172
// Although the ref count was increased by `n` (which may be greater than 1)
165
173
// it is only a single increment (i.e. addition) operation, so only 1 refcnt
Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ beyond the refcount limit. Immortality checks for reference count decreases will
42
42
be done by checking the bit sign flag in the lower 32 bits.
43
43
44
44
*/
45
- #define _Py_IMMORTAL_INITIAL_REFCNT (3UL << 30)
45
+ #define _Py_IMMORTAL_INITIAL_REFCNT (3ULL << 30)
46
+ #define _Py_IMMORTAL_MINIMUM_REFCNT (1ULL << 31)
46
47
#define _Py_STATIC_FLAG_BITS ((Py_ssize_t)(_Py_STATICALLY_ALLOCATED_FLAG | _Py_IMMORTAL_FLAGS))
47
48
#define _Py_STATIC_IMMORTAL_INITIAL_REFCNT (((Py_ssize_t)_Py_IMMORTAL_INITIAL_REFCNT) | (_Py_STATIC_FLAG_BITS << 48))
48
49
Original file line number Diff line number Diff line change @@ -15982,7 +15982,7 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
15982
15982
case SSTATE_INTERNED_MORTAL :
15983
15983
// Restore 2 references held by the interned dict; these will
15984
15984
// be decref'd by clear_interned_dict's PyDict_Clear.
15985
- Py_SET_REFCNT (s , Py_REFCNT ( s ) + 2 );
15985
+ _Py_RefcntAdd (s , 2 );
15986
15986
#ifdef Py_REF_DEBUG
15987
15987
/* let's be pedantic with the ref total */
15988
15988
_Py_IncRefTotal (_PyThreadState_GET ());
You can’t perform that action at this time.
0 commit comments