|
52 | 52 | # error "ceval.c must be build with Py_BUILD_CORE define for best performance"
|
53 | 53 | #endif
|
54 | 54 |
|
55 |
| -#if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_GIL_DISABLED) |
| 55 | +#if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) |
56 | 56 | // GH-89279: The MSVC compiler does not inline these static inline functions
|
57 | 57 | // in PGO build in _PyEval_EvalFrameDefault(), because this function is over
|
58 | 58 | // the limit of PGO, and that limit cannot be configured.
|
59 | 59 | // Define them as macros to make sure that they are always inlined by the
|
60 | 60 | // preprocessor.
|
61 |
| -// TODO: implement Py_DECREF macro for Py_GIL_DISABLED |
| 61 | + |
| 62 | +#undef Py_IS_TYPE |
| 63 | +#define Py_IS_TYPE(ob, type) \ |
| 64 | + (_PyObject_CAST(ob)->ob_type == (type)) |
| 65 | + |
| 66 | +#undef Py_XDECREF |
| 67 | +#define Py_XDECREF(arg) \ |
| 68 | + do { \ |
| 69 | + PyObject *xop = _PyObject_CAST(arg); \ |
| 70 | + if (xop != NULL) { \ |
| 71 | + Py_DECREF(xop); \ |
| 72 | + } \ |
| 73 | + } while (0) |
| 74 | + |
| 75 | +#ifndef Py_GIL_DISABLED |
62 | 76 |
|
63 | 77 | #undef Py_DECREF
|
64 | 78 | #define Py_DECREF(arg) \
|
|
74 | 88 | } \
|
75 | 89 | } while (0)
|
76 | 90 |
|
77 |
| -#undef Py_XDECREF |
78 |
| -#define Py_XDECREF(arg) \ |
79 |
| - do { \ |
80 |
| - PyObject *xop = _PyObject_CAST(arg); \ |
81 |
| - if (xop != NULL) { \ |
82 |
| - Py_DECREF(xop); \ |
83 |
| - } \ |
84 |
| - } while (0) |
85 |
| - |
86 |
| -#undef Py_IS_TYPE |
87 |
| -#define Py_IS_TYPE(ob, type) \ |
88 |
| - (_PyObject_CAST(ob)->ob_type == (type)) |
89 |
| - |
90 | 91 | #undef _Py_DECREF_SPECIALIZED
|
91 | 92 | #define _Py_DECREF_SPECIALIZED(arg, dealloc) \
|
92 | 93 | do { \
|
|
100 | 101 | d(op); \
|
101 | 102 | } \
|
102 | 103 | } while (0)
|
| 104 | + |
| 105 | +#else // Py_GIL_DISABLED |
| 106 | + |
| 107 | +#undef Py_DECREF |
| 108 | +#define Py_DECREF(arg) \ |
| 109 | + do { \ |
| 110 | + PyObject *op = _PyObject_CAST(arg); \ |
| 111 | + uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local); \ |
| 112 | + if (local == _Py_IMMORTAL_REFCNT_LOCAL) { \ |
| 113 | + break; \ |
| 114 | + } \ |
| 115 | + _Py_DECREF_STAT_INC(); \ |
| 116 | + if (_Py_IsOwnedByCurrentThread(op)) { \ |
| 117 | + local--; \ |
| 118 | + _Py_atomic_store_uint32_relaxed(&op->ob_ref_local, local); \ |
| 119 | + if (local == 0) { \ |
| 120 | + _Py_MergeZeroLocalRefcount(op); \ |
| 121 | + } \ |
| 122 | + } \ |
| 123 | + else { \ |
| 124 | + _Py_DecRefShared(op); \ |
| 125 | + } \ |
| 126 | + } while (0) |
| 127 | + |
| 128 | +#undef _Py_DECREF_SPECIALIZED |
| 129 | +#define _Py_DECREF_SPECIALIZED(arg, dealloc) Py_DECREF(arg) |
| 130 | + |
| 131 | +#endif |
103 | 132 | #endif
|
104 | 133 |
|
105 | 134 |
|
|
0 commit comments