|
8 | 8 | */
|
9 | 9 |
|
10 | 10 | #include "nb_internals.h"
|
| 11 | +#include "nb_ft.h" |
11 | 12 |
|
12 | 13 | #if defined(_MSC_VER)
|
13 | 14 | # pragma warning(disable: 4706) // assignment within conditional expression
|
@@ -40,62 +41,6 @@ static PyObject **nb_weaklist_ptr(PyObject *self) {
|
40 | 41 | return weaklistoffset ? (PyObject **) ((uint8_t *) self + weaklistoffset) : nullptr;
|
41 | 42 | }
|
42 | 43 |
|
43 |
| -static void nb_enable_try_inc_ref(PyObject *obj) noexcept { |
44 |
| -#if 0 && defined(Py_GIL_DISABLED) && PY_VERSION_HEX >= 0x030E00A5 |
45 |
| - PyUnstable_EnableTryIncRef(obj); |
46 |
| -#elif defined(Py_GIL_DISABLED) |
47 |
| - // Since this is called during object construction, we know that we have |
48 |
| - // the only reference to the object and can use a non-atomic write. |
49 |
| - assert(obj->ob_ref_shared == 0); |
50 |
| - obj->ob_ref_shared = _Py_REF_MAYBE_WEAKREF; |
51 |
| -#else |
52 |
| - (void) obj; |
53 |
| -#endif |
54 |
| -} |
55 |
| - |
56 |
| -static bool nb_try_inc_ref(PyObject *obj) noexcept { |
57 |
| -#if 0 && defined(Py_GIL_DISABLED) && PY_VERSION_HEX >= 0x030E00A5 |
58 |
| - return PyUnstable_TryIncRef(obj); |
59 |
| -#elif defined(Py_GIL_DISABLED) |
60 |
| - // See https://github.com/python/cpython/blob/d05140f9f77d7dfc753dd1e5ac3a5962aaa03eff/Include/internal/pycore_object.h#L761 |
61 |
| - uint32_t local = _Py_atomic_load_uint32_relaxed(&obj->ob_ref_local); |
62 |
| - local += 1; |
63 |
| - if (local == 0) { |
64 |
| - // immortal |
65 |
| - return true; |
66 |
| - } |
67 |
| - if (_Py_IsOwnedByCurrentThread(obj)) { |
68 |
| - _Py_atomic_store_uint32_relaxed(&obj->ob_ref_local, local); |
69 |
| -#ifdef Py_REF_DEBUG |
70 |
| - _Py_INCREF_IncRefTotal(); |
71 |
| -#endif |
72 |
| - return true; |
73 |
| - } |
74 |
| - Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&obj->ob_ref_shared); |
75 |
| - for (;;) { |
76 |
| - // If the shared refcount is zero and the object is either merged |
77 |
| - // or may not have weak references, then we cannot incref it. |
78 |
| - if (shared == 0 || shared == _Py_REF_MERGED) { |
79 |
| - return false; |
80 |
| - } |
81 |
| - |
82 |
| - if (_Py_atomic_compare_exchange_ssize( |
83 |
| - &obj->ob_ref_shared, &shared, shared + (1 << _Py_REF_SHARED_SHIFT))) { |
84 |
| -#ifdef Py_REF_DEBUG |
85 |
| - _Py_INCREF_IncRefTotal(); |
86 |
| -#endif |
87 |
| - return true; |
88 |
| - } |
89 |
| - } |
90 |
| -#else |
91 |
| - if (Py_REFCNT(obj) > 0) { |
92 |
| - Py_INCREF(obj); |
93 |
| - return true; |
94 |
| - } |
95 |
| - return false; |
96 |
| -#endif |
97 |
| -} |
98 |
| - |
99 | 44 | static PyGetSetDef inst_getset[] = {
|
100 | 45 | { "__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict, nullptr, nullptr },
|
101 | 46 | { nullptr, nullptr, nullptr, nullptr, nullptr }
|
@@ -945,7 +890,7 @@ static PyTypeObject *nb_type_tp(size_t supplement) noexcept {
|
945 | 890 | tp = (PyTypeObject *) nb_type_from_metaclass(
|
946 | 891 | internals_->nb_meta, internals_->nb_module, &spec);
|
947 | 892 |
|
948 |
| - maybe_make_immortal((PyObject *) tp); |
| 893 | + make_immortal((PyObject *) tp); |
949 | 894 |
|
950 | 895 | handle(tp).attr("__module__") = "nanobind";
|
951 | 896 |
|
@@ -1369,7 +1314,7 @@ PyObject *nb_type_new(const type_init_data *t) noexcept {
|
1369 | 1314 |
|
1370 | 1315 | Py_DECREF(metaclass);
|
1371 | 1316 |
|
1372 |
| - maybe_make_immortal(result); |
| 1317 | + make_immortal(result); |
1373 | 1318 |
|
1374 | 1319 | type_data *to = nb_type_data((PyTypeObject *) result);
|
1375 | 1320 |
|
|
0 commit comments