Skip to content

Commit 5eccfab

Browse files
committed
More refactoring for free-threading
1 parent c24f24f commit 5eccfab

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

Include/internal/pycore_object.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ extern "C" {
99
#endif
1010

1111
#include <stdbool.h>
12-
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
1312
#include "pycore_emscripten_trampoline.h" // _PyCFunction_TrampolineCall()
13+
#include "pycore_object_deferred.h" // _PyObject_HasDeferredRefcount
1414
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_STORE_PTR_RELAXED
1515
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1616
#include "pycore_typeobject.h" // _PyStaticType_GetState()
@@ -539,20 +539,6 @@ _Py_TryIncrefCompare(PyObject **src, PyObject *op)
539539
return 1;
540540
}
541541

542-
static inline int
543-
_Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, _PyStackRef *out)
544-
{
545-
if (_PyObject_HasDeferredRefcount(op)) {
546-
*out = (_PyStackRef){ .bits = (intptr_t)op | Py_TAG_DEFERRED };
547-
return 1;
548-
}
549-
if (_Py_TryIncrefCompare(src, op)) {
550-
*out = PyStackRef_FromPyObjectSteal(op);
551-
return 1;
552-
}
553-
return 0;
554-
}
555-
556542
/* Loads and increfs an object from ptr, which may contain a NULL value.
557543
Safe with concurrent (atomic) updates to ptr.
558544
NOTE: The writer must set maybe-weakref on the stored object! */

Include/internal/pycore_stackref.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern "C" {
1414
#endif
1515

1616
#include "pycore_object_deferred.h"
17+
#include "pycore_object.h"
1718

1819
#include <stddef.h>
1920
#include <stdbool.h>
@@ -639,6 +640,24 @@ PyStackRef_FunctionCheck(_PyStackRef stackref)
639640
return PyFunction_Check(PyStackRef_AsPyObjectBorrow(stackref));
640641
}
641642

643+
#ifdef Py_GIL_DISABLED
644+
645+
static inline int
646+
_Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, _PyStackRef *out)
647+
{
648+
if (_PyObject_HasDeferredRefcount(op)) {
649+
*out = (_PyStackRef){ .bits = (intptr_t)op | Py_TAG_DEFERRED };
650+
return 1;
651+
}
652+
if (_Py_TryIncrefCompare(src, op)) {
653+
*out = PyStackRef_FromPyObjectSteal(op);
654+
return 1;
655+
}
656+
return 0;
657+
}
658+
659+
#endif
660+
642661
#ifdef __cplusplus
643662
}
644663
#endif

Objects/listobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "pycore_long.h" // _PyLong_DigitCount
1313
#include "pycore_modsupport.h" // _PyArg_NoKwnames()
1414
#include "pycore_object.h" // _PyObject_GC_TRACK(), _PyDebugAllocatorStats()
15+
#include "pycore_stackref.h" // _Py_TryIncrefCompareStackRef()
1516
#include "pycore_tuple.h" // _PyTuple_FromArray()
1617
#include "pycore_typeobject.h" // _Py_TYPE_VERSION_LIST
1718
#include "pycore_setobject.h" // _PySet_NextEntry()

Python/bytecodes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "pycore_long.h" // _PyLong_ExactDealloc()
3030
#include "pycore_setobject.h" // _PySet_NextEntry()
3131
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
32+
#include "pycore_stackref.h"
3233
#include "pycore_tuple.h" // _PyTuple_ITEMS()
3334
#include "pycore_typeobject.h" // _PySuper_Lookup()
3435

Python/specialize.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "pycore_dict.h" // DICT_KEYS_UNICODE
99
#include "pycore_frame.h" // FRAME_SPECIALS_SIZE
1010
#include "pycore_function.h" // _PyFunction_GetVersionForCurrentState()
11+
#include "pycore_list.h" // _PyListIterObject
1112
#include "pycore_long.h" // _PyLong_IsNonNegativeCompact()
1213
#include "pycore_moduleobject.h"
1314
#include "pycore_object.h"

0 commit comments

Comments
 (0)