|
62 | 62 |
|
63 | 63 | #include <feature_detection_misc.h> |
64 | 64 |
|
65 | | -#if PY_VERSION_HEX >= 0x030E00A7 && !defined(PYPY_VERSION) |
66 | | -#define Py_BUILD_CORE |
67 | | -#include "internal/pycore_frame.h" |
68 | | -#include "internal/pycore_interpframe.h" |
69 | | -#undef Py_BUILD_CORE |
70 | | -#endif |
71 | | - |
72 | 65 | /* 1 prints elided operations, 2 prints stacktraces */ |
73 | 66 | #define NPY_ELIDE_DEBUG 0 |
74 | 67 | #define NPY_MAX_STACKSIZE 10 |
@@ -119,33 +112,11 @@ find_addr(void * addresses[], npy_intp naddr, void * addr) |
119 | 112 | static int |
120 | 113 | check_unique_temporary(PyObject *lhs) |
121 | 114 | { |
122 | | -#if PY_VERSION_HEX >= 0x030E00A7 && !defined(PYPY_VERSION) |
123 | | - // In Python 3.14.0a7 and later, a reference count of one doesn't guarantee |
124 | | - // that an object is a unique temporary variable. We scan the top of the |
125 | | - // interpreter stack to check if the object exists as an "owned" reference |
126 | | - // in the temporary stack. |
127 | | - PyFrameObject *frame = PyEval_GetFrame(); |
128 | | - if (frame == NULL) { |
129 | | - return 0; |
130 | | - } |
131 | | - _PyInterpreterFrame *f = frame->f_frame; |
132 | | - _PyStackRef *base = _PyFrame_Stackbase(f); |
133 | | - _PyStackRef *stackpointer = f->stackpointer; |
134 | | - int found_once = 0; |
135 | | - while (stackpointer > base) { |
136 | | - stackpointer--; |
137 | | - PyObject *obj = PyStackRef_AsPyObjectBorrow(*stackpointer); |
138 | | - if (obj == lhs) { |
139 | | - if (!found_once && PyStackRef_IsHeapSafe(*stackpointer)) { |
140 | | - found_once = 1; |
141 | | - } |
142 | | - else { |
143 | | - return 0; |
144 | | - } |
145 | | - } |
146 | | - return found_once; |
147 | | - } |
148 | | - return 0; |
| 115 | +#if PY_VERSION_HEX == 0x030E00A7 && !defined(PYPY_VERSION) |
| 116 | +#error "NumPy is broken on CPython 3.14.0a7, please update to a newer version" |
| 117 | +#elif PY_VERSION_HEX >= 0x030E00B1 && !defined(PYPY_VERSION) |
| 118 | + // see https://github.com/python/cpython/issues/133164 |
| 119 | + return PyUnstable_Object_IsUniqueReferencedTemporary(lhs); |
149 | 120 | #else |
150 | 121 | return 1; |
151 | 122 | #endif |
|
0 commit comments