|
| 1 | +diff --git a/Cython/Includes/cpython/array.pxd b/Cython/Includes/cpython/array.pxd |
| 2 | +index b5e8880..d420401 100644 |
| 3 | +--- a/Cython/Includes/cpython/array.pxd |
| 4 | ++++ b/Cython/Includes/cpython/array.pxd |
| 5 | +@@ -99,7 +99,10 @@ cdef extern from *: # Hard-coded utility code hack. |
| 6 | + cdef: |
| 7 | + Py_ssize_t ob_size |
| 8 | + arraydescr* ob_descr # struct arraydescr *ob_descr; |
| 9 | +- __data_union data |
| 10 | ++ |
| 11 | ++ @property |
| 12 | ++ cdef inline __data_union data(self) nogil: |
| 13 | ++ return __Pyx_PyArray_Data(self) |
| 14 | + |
| 15 | + def __getbuffer__(self, Py_buffer* info, int flags): |
| 16 | + # This implementation of getbuffer is geared towards Cython |
| 17 | +@@ -131,6 +134,7 @@ cdef extern from *: # Hard-coded utility code hack. |
| 18 | + |
| 19 | + array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr) |
| 20 | + |
| 21 | ++ __data_union __Pyx_PyArray_Data(array self) nogil |
| 22 | + # fast resize/realloc |
| 23 | + # not suitable for small increments; reallocation 'to the point' |
| 24 | + int resize(array self, Py_ssize_t n) except -1 |
| 25 | +diff --git a/Cython/Includes/cpython/datetime.pxd b/Cython/Includes/cpython/datetime.pxd |
| 26 | +index da988dc..b8c822e 100644 |
| 27 | +--- a/Cython/Includes/cpython/datetime.pxd |
| 28 | ++++ b/Cython/Includes/cpython/datetime.pxd |
| 29 | +@@ -373,15 +373,15 @@ cdef inline int datetime_fold(object o) noexcept: |
| 30 | + |
| 31 | + # Get days of timedelta |
| 32 | + cdef inline int timedelta_days(object o) noexcept: |
| 33 | +- return (<PyDateTime_Delta*>o).days |
| 34 | ++ return PyDateTime_DELTA_GET_DAYS(o) |
| 35 | + |
| 36 | + # Get seconds of timedelta |
| 37 | + cdef inline int timedelta_seconds(object o) noexcept: |
| 38 | +- return (<PyDateTime_Delta*>o).seconds |
| 39 | ++ return PyDateTime_DELTA_GET_SECONDS(o) |
| 40 | + |
| 41 | + # Get microseconds of timedelta |
| 42 | + cdef inline int timedelta_microseconds(object o) noexcept: |
| 43 | +- return (<PyDateTime_Delta*>o).microseconds |
| 44 | ++ return PyDateTime_DELTA_GET_MICROSECONDS(o) |
| 45 | + |
| 46 | + cdef inline double total_seconds(timedelta obj) noexcept: |
| 47 | + # Mirrors the "timedelta.total_seconds()" method. |
| 48 | +diff --git a/Cython/Utility/Builtins.c b/Cython/Utility/Builtins.c |
| 49 | +index 15ba067..fdef8e5 100644 |
| 50 | +--- a/Cython/Utility/Builtins.c |
| 51 | ++++ b/Cython/Utility/Builtins.c |
| 52 | +@@ -764,8 +764,13 @@ static {{out_type}} __Pyx_PyMemoryView_Get_{{name}}(PyObject *obj) { |
| 53 | + #define __Pyx_PySlice_Start(o) PyObject_GetAttr(o, PYIDENT("start")) |
| 54 | + #define __Pyx_PySlice_Stop(o) PyObject_GetAttr(o, PYIDENT("stop")) |
| 55 | + #define __Pyx_PySlice_Step(o) PyObject_GetAttr(o, PYIDENT("step")) |
| 56 | +-#elif CYTHON_COMPILING_IN_GRAAL |
| 57 | ++#elif CYTHON_COMPILING_IN_GRAAL && defined(GRAALPY_VERSION_NUM) && GRAALPY_VERSION_NUM > 0x19000000 |
| 58 | + // Graal defines it's own accessor functions |
| 59 | ++#define __Pyx_PySlice_Start(o) GraalPySlice_Start(o) |
| 60 | ++#define __Pyx_PySlice_Stop(o) GraalPySlice_Stop(o) |
| 61 | ++#define __Pyx_PySlice_Step(o) GraalPySlice_Step(o) |
| 62 | ++#elif CYTHON_COMPILING_IN_GRAAL |
| 63 | ++// Remove when GraalPy 24 goes EOL |
| 64 | + #define __Pyx_PySlice_Start(o) __Pyx_NewRef(PySlice_Start((PySliceObject*)o)) |
| 65 | + #define __Pyx_PySlice_Stop(o) __Pyx_NewRef(PySlice_Stop((PySliceObject*)o)) |
| 66 | + #define __Pyx_PySlice_Step(o) __Pyx_NewRef(PySlice_Step((PySliceObject*)o)) |
| 67 | +diff --git a/Cython/Utility/CythonFunction.c b/Cython/Utility/CythonFunction.c |
| 68 | +index 685d287..1b27dd5 100644 |
| 69 | +--- a/Cython/Utility/CythonFunction.c |
| 70 | ++++ b/Cython/Utility/CythonFunction.c |
| 71 | +@@ -1755,8 +1755,12 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) { |
| 72 | + "This is most likely a classmethod in a cdef class method with binding=False. " |
| 73 | + "Try setting 'binding' to True.", |
| 74 | + method); |
| 75 | +-#elif CYTHON_COMPILING_IN_GRAAL |
| 76 | ++#elif CYTHON_COMPILING_IN_GRAAL && defined(GRAALPY_VERSION_NUM) && GRAALPY_VERSION_NUM > 0x19000000 |
| 77 | + // cdef classes |
| 78 | ++ PyTypeObject *d_type = GraalPyDescrObject_GetType(method); |
| 79 | ++ return PyDescr_NewClassMethod(d_type, GraalPyMethodDescrObject_GetMethod(method)); |
| 80 | ++#elif CYTHON_COMPILING_IN_GRAAL |
| 81 | ++ // Remove when GraalPy 24 goes EOL |
| 82 | + PyTypeObject *d_type = PyDescrObject_GetType(method); |
| 83 | + return PyDescr_NewClassMethod(d_type, PyMethodDescrObject_GetMethod(method)); |
| 84 | + #else |
| 85 | +diff --git a/Cython/Utility/Exceptions.c b/Cython/Utility/Exceptions.c |
| 86 | +index 165a7ef..d88e279 100644 |
| 87 | +--- a/Cython/Utility/Exceptions.c |
| 88 | ++++ b/Cython/Utility/Exceptions.c |
| 89 | +@@ -13,7 +13,7 @@ if (likely(__Pyx_init_assertions_enabled() == 0)); else |
| 90 | + |
| 91 | + /////////////// AssertionsEnabled.proto /////////////// |
| 92 | + |
| 93 | +-#if CYTHON_COMPILING_IN_LIMITED_API || (CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030C0000) |
| 94 | ++#if CYTHON_COMPILING_IN_LIMITED_API || PY_VERSION_HEX >= 0x030C0000 |
| 95 | + // Py_OptimizeFlag is deprecated in Py3.12+ and not available in the Limited API. |
| 96 | + static int __pyx_assertions_enabled_flag; |
| 97 | + #define __pyx_assertions_enabled() (__pyx_assertions_enabled_flag) |
| 98 | +diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c |
| 99 | +index 6e29634..11f423e 100644 |
| 100 | +--- a/Cython/Utility/ModuleSetupCode.c |
| 101 | ++++ b/Cython/Utility/ModuleSetupCode.c |
| 102 | +@@ -81,7 +81,7 @@ |
| 103 | + #undef CYTHON_AVOID_BORROWED_REFS |
| 104 | + #define CYTHON_AVOID_BORROWED_REFS 1 |
| 105 | + #undef CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS |
| 106 | +- #define CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS 1 |
| 107 | ++ #define CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS 0 |
| 108 | + #undef CYTHON_ASSUME_SAFE_MACROS |
| 109 | + #define CYTHON_ASSUME_SAFE_MACROS 0 |
| 110 | + #undef CYTHON_ASSUME_SAFE_SIZE |
| 111 | +@@ -860,7 +860,11 @@ static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void (*cfunc)(vo |
| 112 | + #if CYTHON_COMPILING_IN_LIMITED_API |
| 113 | + // __Pyx_PyCode_HasFreeVars isn't easily emulated in the limited API (but isn't really necessary) |
| 114 | + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) |
| 115 | ++#elif CYTHON_COMPILING_IN_GRAAL && defined(GRAALPY_VERSION_NUM) && GRAALPY_VERSION_NUM > 0x19000000 |
| 116 | ++ #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) |
| 117 | ++ #define __Pyx_PyFrame_SetLineNumber(frame, lineno) GraalPyFrame_SetLineNumber((frame), (lineno)) |
| 118 | + #elif CYTHON_COMPILING_IN_GRAAL |
| 119 | ++ // Remove when GraalPy 24 goes EOL |
| 120 | + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) |
| 121 | + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) _PyFrame_SetLineNumber((frame), (lineno)) |
| 122 | + #else |
| 123 | +@@ -1592,7 +1596,9 @@ static PY_INT64_T __Pyx_GetCurrentInterpreterId(void) { |
| 124 | + #if !CYTHON_USE_MODULE_STATE |
| 125 | + static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { |
| 126 | + static PY_INT64_T main_interpreter_id = -1; |
| 127 | +-#if CYTHON_COMPILING_IN_GRAAL |
| 128 | ++#if CYTHON_COMPILING_IN_GRAAL && defined(GRAALPY_VERSION_NUM) && GRAALPY_VERSION_NUM > 0x19000000 |
| 129 | ++ PY_INT64_T current_id = GraalPyInterpreterState_GetIDFromThreadState(PyThreadState_Get()); |
| 130 | ++#elif CYTHON_COMPILING_IN_GRAAL |
| 131 | + PY_INT64_T current_id = PyInterpreterState_GetIDFromThreadState(PyThreadState_Get()); |
| 132 | + #elif CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX >= 0x03090000 |
| 133 | + PY_INT64_T current_id = PyInterpreterState_GetID(PyInterpreterState_Get()); |
| 134 | +diff --git a/Cython/Utility/arrayarray.h b/Cython/Utility/arrayarray.h |
| 135 | +index d410e66..e006a20 100644 |
| 136 | +--- a/Cython/Utility/arrayarray.h |
| 137 | ++++ b/Cython/Utility/arrayarray.h |
| 138 | +@@ -30,33 +30,34 @@ typedef struct arraydescr { |
| 139 | + char *formats; |
| 140 | + } arraydescr; |
| 141 | + |
| 142 | ++typedef union { |
| 143 | ++ char *ob_item; |
| 144 | ++ float *as_floats; |
| 145 | ++ double *as_doubles; |
| 146 | ++ int *as_ints; |
| 147 | ++ unsigned int *as_uints; |
| 148 | ++ unsigned char *as_uchars; |
| 149 | ++ signed char *as_schars; |
| 150 | ++ char *as_chars; |
| 151 | ++ unsigned long *as_ulongs; |
| 152 | ++ long *as_longs; |
| 153 | ++ unsigned long long *as_ulonglongs; |
| 154 | ++ long long *as_longlongs; |
| 155 | ++ short *as_shorts; |
| 156 | ++ unsigned short *as_ushorts; |
| 157 | ++ // Don't use Py_UNICODE ourselves in the union. This avoids deprecation warnings |
| 158 | ++ // for anyone who uses array.array but doesn't use this field. |
| 159 | ++ #if PY_VERSION_HEX >= 0x030d0000 |
| 160 | ++ Py_DEPRECATED(3.13) |
| 161 | ++ #endif |
| 162 | ++ wchar_t *as_pyunicodes; |
| 163 | ++ void *as_voidptr; |
| 164 | ++} __data_union; |
| 165 | + |
| 166 | + struct arrayobject { |
| 167 | + PyObject_HEAD |
| 168 | + Py_ssize_t ob_size; |
| 169 | +- union { |
| 170 | +- char *ob_item; |
| 171 | +- float *as_floats; |
| 172 | +- double *as_doubles; |
| 173 | +- int *as_ints; |
| 174 | +- unsigned int *as_uints; |
| 175 | +- unsigned char *as_uchars; |
| 176 | +- signed char *as_schars; |
| 177 | +- char *as_chars; |
| 178 | +- unsigned long *as_ulongs; |
| 179 | +- long *as_longs; |
| 180 | +- unsigned long long *as_ulonglongs; |
| 181 | +- long long *as_longlongs; |
| 182 | +- short *as_shorts; |
| 183 | +- unsigned short *as_ushorts; |
| 184 | +- // Don't use Py_UNICODE ourselves in the union. This avoids deprecation warnings |
| 185 | +- // for anyone who uses array.array but doesn't use this field. |
| 186 | +- #if PY_VERSION_HEX >= 0x030d0000 |
| 187 | +- Py_DEPRECATED(3.13) |
| 188 | +- #endif |
| 189 | +- wchar_t *as_pyunicodes; |
| 190 | +- void *as_voidptr; |
| 191 | +- } data; |
| 192 | ++ __data_union data; |
| 193 | + Py_ssize_t allocated; |
| 194 | + struct arraydescr *ob_descr; |
| 195 | + PyObject *weakreflist; /* List of weak references */ |
| 196 | +@@ -105,9 +106,20 @@ PyObject* newarrayobject(PyTypeObject *type, Py_ssize_t size, |
| 197 | + struct arraydescr *descr); |
| 198 | + #endif /* ifndef NO_NEWARRAY_INLINE */ |
| 199 | + |
| 200 | ++static CYTHON_INLINE __data_union __Pyx_PyArray_Data(arrayobject *self) { |
| 201 | ++#if !CYTHON_COMPILING_IN_GRAAL |
| 202 | ++ return self->data; |
| 203 | ++#else |
| 204 | ++ __data_union data; |
| 205 | ++ data.ob_item = GraalPyArray_Data((PyObject*)self); |
| 206 | ++ return data; |
| 207 | ++#endif |
| 208 | ++} |
| 209 | ++ |
| 210 | + // fast resize (reallocation to the point) |
| 211 | + // not designed for filing small increments (but for fast opaque array apps) |
| 212 | + static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) { |
| 213 | ++#if !CYTHON_COMPILING_IN_GRAAL |
| 214 | + void *items = (void*) self->data.ob_item; |
| 215 | + PyMem_Resize(items, char, (size_t)(n * self->ob_descr->itemsize)); |
| 216 | + if (items == NULL) { |
| 217 | +@@ -118,10 +130,14 @@ static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) { |
| 218 | + __Pyx_SET_SIZE(self, n); |
| 219 | + self->allocated = n; |
| 220 | + return 0; |
| 221 | ++#else |
| 222 | ++ return GraalPyArray_Resize((PyObject*)self, n); |
| 223 | ++#endif |
| 224 | + } |
| 225 | + |
| 226 | + // suitable for small increments; over allocation 50% ; |
| 227 | + static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) { |
| 228 | ++#if !CYTHON_COMPILING_IN_GRAAL |
| 229 | + void *items = (void*) self->data.ob_item; |
| 230 | + Py_ssize_t newsize; |
| 231 | + if (n < self->allocated && n*4 > self->allocated) { |
| 232 | +@@ -142,6 +158,9 @@ static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) { |
| 233 | + __Pyx_SET_SIZE(self, n); |
| 234 | + self->allocated = newsize; |
| 235 | + return 0; |
| 236 | ++#else |
| 237 | ++ return GraalPyArray_Resize((PyObject*)self, n); |
| 238 | ++#endif |
| 239 | + } |
| 240 | + |
| 241 | + #endif |
0 commit comments