Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
315 changes: 315 additions & 0 deletions graalpython/lib-graalpython/patches/cython-3.2.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py
index 3726a72..ed46b9b 100644
--- a/Cython/Build/Dependencies.py
+++ b/Cython/Build/Dependencies.py
@@ -1077,6 +1077,11 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
else:
dep_timestamp, dep = deps.newest_dependency(source)
priority = 2 - (dep in deps.immediate_dependencies(source))
+ # GraalPy change: force recythonize if not cythonized by our patched version
+ if os.path.exists(c_file):
+ with open(c_file, 'rb') as f:
+ if not b'graalpy' in f.read(100):
+ c_timestamp = -1
if force or c_timestamp < dep_timestamp:
if not quiet and not force:
if source == dep:
@@ -1130,6 +1135,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
for i, task in enumerate(to_compile, 1)
]

+ nthreads = 0 # GraalVM: we don't want to spawn
+
if N <= 1:
nthreads = 0
try:
diff --git a/Cython/Compiler/Version.py b/Cython/Compiler/Version.py
index 5ae2a4e..951aacc 100644
--- a/Cython/Compiler/Version.py
+++ b/Cython/Compiler/Version.py
@@ -5,4 +5,4 @@ from .. import __version__ as version

# For 'generated by' header line in C files.

-watermark = str(version)
+watermark = f'{version}-graalpy'
diff --git a/Cython/Includes/cpython/array.pxd b/Cython/Includes/cpython/array.pxd
index 2221ade..f46d197 100644
--- a/Cython/Includes/cpython/array.pxd
+++ b/Cython/Includes/cpython/array.pxd
@@ -100,15 +100,18 @@ cdef extern from *: # Hard-coded utility code hack.

cdef:
Py_ssize_t ob_size
- arraydescr* ob_descr # struct arraydescr *ob_descr;
+
+ @property
+ cdef inline arraydescr* ob_descr(self) noexcept nogil:
+ return __Pyx_PyArray_Descr(self)

@property
cdef inline __data_union data(self) noexcept nogil:
return __Pyx_PyArray_Data(self)

array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr)
-
__data_union __Pyx_PyArray_Data(array self) noexcept nogil
+ arraydescr* __Pyx_PyArray_Descr(array self) noexcept nogil
# fast resize/realloc
# not suitable for small increments; reallocation 'to the point'
int resize(array self, Py_ssize_t n) except -1
@@ -120,15 +123,18 @@ cdef inline array clone(array template, Py_ssize_t length, bint zero):
""" fast creation of a new array, given a template array.
type will be same as template.
if zero is true, new array will be initialized with zeroes."""
- cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
+ cdef arraydescr* descr = template.ob_descr
+ cdef array op = newarrayobject(Py_TYPE(template), length, descr)
if zero and op is not None:
- memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
+ memset(op.data.as_chars, 0, <size_t> length * descr.itemsize)
return op

cdef inline array copy(array self):
""" make a copy of an array. """
- cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
- memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
+ cdef Py_ssize_t length = Py_SIZE(self)
+ cdef arraydescr* descr = self.ob_descr
+ cdef array op = newarrayobject(Py_TYPE(self), length, descr)
+ memcpy(op.data.as_chars, self.data.as_chars, <size_t> length * descr.itemsize)
return op

cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:
@@ -149,4 +155,4 @@ cdef inline int extend(array self, array other) except -1:

cdef inline void zero(array self) noexcept:
""" set all elements of array to zero. """
- memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
+ memset(self.data.as_chars, 0, <size_t> Py_SIZE(self) * self.ob_descr.itemsize)
diff --git a/Cython/Utility/CythonFunction.c b/Cython/Utility/CythonFunction.c
index 38e2f1c..7a4e223 100644
--- a/Cython/Utility/CythonFunction.c
+++ b/Cython/Utility/CythonFunction.c
@@ -87,6 +87,22 @@ typedef struct {
PyObject *func_is_coroutine;
} __pyx_CyFunctionObject;

+#if !CYTHON_COMPILING_IN_LIMITED_API
+#if CYTHON_COMPILING_IN_GRAAL
+#define __Pyx_CyFunction_GetMethodDef(cyfunc) GraalPyCFunction_GetMethodDef((PyObject*)(cyfunc))
+#define __Pyx_CyFunction_SetMethodDef(cyfunc, ml) GraalPyCFunction_SetMethodDef((PyObject*)(cyfunc), ml)
+#define __Pyx_CyFunction_GetModule(cyfunc) GraalPyCFunction_GetModule((PyObject*)(cyfunc))
+#define __Pyx_CyFunction_SetModule(cyfunc, module) GraalPyCFunction_SetModule((PyObject*)(cyfunc), module)
+#define __Pyx_CyFunction_GetDoc(cyfunc) GraalPyCFunction_GetDoc((PyObject*)(cyfunc))
+#else
+#define __Pyx_CyFunction_GetMethodDef(cyfunc) (((PyCFunctionObject*)(cyfunc))->m_ml)
+#define __Pyx_CyFunction_SetMethodDef(cyfunc, ml) (((PyCFunctionObject*)(cyfunc))->m_ml = (ml))
+#define __Pyx_CyFunction_GetModule(cyfunc) (((PyCFunctionObject*)(cyfunc))->m_module)
+#define __Pyx_CyFunction_SetModule(cyfunc, module) (((PyCFunctionObject*)(cyfunc))->m_module = (module))
+#define __Pyx_CyFunction_GetDoc(cyfunc) (__Pyx_CyFunction_GetMethodDef(cyfunc)->ml_doc)
+#endif
+#endif
+
#undef __Pyx_CyOrPyCFunction_Check
#define __Pyx_CyFunction_Check(obj) __Pyx_TypeCheck(obj, CGLOBAL(__pyx_CyFunctionType))
#define __Pyx_CyOrPyCFunction_Check(obj) __Pyx_TypeCheck2(obj, CGLOBAL(__pyx_CyFunctionType), &PyCFunction_Type)
@@ -192,8 +208,8 @@ __Pyx_CyFunction_get_doc_locked(__pyx_CyFunctionObject *op)
op->func_doc = PyObject_GetAttrString(op->func, "__doc__");
if (unlikely(!op->func_doc)) return NULL;
#else
- if (((PyCFunctionObject*)op)->m_ml->ml_doc) {
- op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc);
+ if (__Pyx_CyFunction_GetDoc(op)) {
+ op->func_doc = PyUnicode_FromString(__Pyx_CyFunction_GetDoc(op));
if (unlikely(op->func_doc == NULL))
return NULL;
} else {
@@ -238,7 +254,7 @@ __Pyx_CyFunction_get_name_locked(__pyx_CyFunctionObject *op)
#if CYTHON_COMPILING_IN_LIMITED_API
op->func_name = PyObject_GetAttrString(op->func, "__name__");
#else
- op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name);
+ op->func_name = PyUnicode_InternFromString(__Pyx_CyFunction_GetMethodDef(op)->ml_name);
#endif /* CYTHON_COMPILING_IN_LIMITED_API */
if (unlikely(op->func_name == NULL))
return NULL;
@@ -588,7 +604,7 @@ static void __Pyx_CyFunction_raise_argument_count_error(__pyx_CyFunctionObject *
py_name, message, size);
Py_DECREF(py_name);
#else
- const char* name = ((PyCFunctionObject*)func)->m_ml->ml_name;
+ const char* name = __Pyx_CyFunction_GetMethodDef(func)->ml_name;
PyErr_Format(PyExc_TypeError,
"%.200s() %s (%" CYTHON_FORMAT_SSIZE_T "d given)",
name, message, size);
@@ -604,7 +620,7 @@ static void __Pyx_CyFunction_raise_type_error(__pyx_CyFunctionObject *func, cons
py_name, message);
Py_DECREF(py_name);
#else
- const char* name = ((PyCFunctionObject*)func)->m_ml->ml_name;
+ const char* name = __Pyx_CyFunction_GetMethodDef(func)->ml_name;
PyErr_Format(PyExc_TypeError,
"%.200s() %s",
name, message);
@@ -719,14 +735,14 @@ static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *
op->flags = flags;
__Pyx_CyFunction_weakreflist(op) = NULL;
#if !CYTHON_COMPILING_IN_LIMITED_API
- cf->m_ml = ml;
+ __Pyx_CyFunction_SetMethodDef(cf, ml);
cf->m_self = (PyObject *) op;
#endif
Py_XINCREF(closure);
op->func_closure = closure;
#if !CYTHON_COMPILING_IN_LIMITED_API
Py_XINCREF(module);
- cf->m_module = module;
+ __Pyx_CyFunction_SetModule(cf, module);
#endif
#if PY_VERSION_HEX < 0x030C0000 || CYTHON_COMPILING_IN_LIMITED_API
op->func_dict = NULL;
@@ -786,8 +802,10 @@ __Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
#if CYTHON_COMPILING_IN_LIMITED_API
Py_CLEAR(m->func);
#else
+#if !CYTHON_COMPILING_IN_GRAAL
Py_CLEAR(((PyCFunctionObject*)m)->m_module);
#endif
+#endif
#if PY_VERSION_HEX < 0x030C0000 || CYTHON_COMPILING_IN_LIMITED_API
Py_CLEAR(m->func_dict);
#elif PY_VERSION_HEX < 0x030d0000
@@ -843,8 +861,10 @@ static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit,
#if CYTHON_COMPILING_IN_LIMITED_API
Py_VISIT(m->func);
#else
+#if !CYTHON_COMPILING_IN_GRAAL
Py_VISIT(((PyCFunctionObject*)m)->m_module);
#endif
+#endif
#if PY_VERSION_HEX < 0x030C0000 || CYTHON_COMPILING_IN_LIMITED_API
Py_VISIT(m->func_dict);
#else
@@ -898,8 +918,8 @@ static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, Py
if (unlikely(flags < 0)) return NULL;
#else
PyCFunctionObject* f = (PyCFunctionObject*)func;
- PyCFunction meth = f->m_ml->ml_meth;
- int flags = f->m_ml->ml_flags;
+ PyCFunction meth = __Pyx_CyFunction_GetMethodDef(f)->ml_meth;
+ int flags = __Pyx_CyFunction_GetMethodDef(f)->ml_flags;
#endif
Py_ssize_t size;

@@ -1062,7 +1082,7 @@ static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *c
PyCFunction meth = PyCFunction_GetFunction(cyfunc->func);
if (unlikely(!meth)) return NULL;
#else
- PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth;
+ PyCFunction meth = __Pyx_CyFunction_GetMethodDef(cyfunc)->ml_meth;
#endif

switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) {
@@ -1101,7 +1121,7 @@ static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const
PyCFunction meth = PyCFunction_GetFunction(cyfunc->func);
if (unlikely(!meth)) return NULL;
#else
- PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth;
+ PyCFunction meth = __Pyx_CyFunction_GetMethodDef(cyfunc)->ml_meth;
#endif

switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) {
@@ -1140,7 +1160,7 @@ static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func,
PyCFunction meth = PyCFunction_GetFunction(cyfunc->func);
if (unlikely(!meth)) return NULL;
#else
- PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth;
+ PyCFunction meth = __Pyx_CyFunction_GetMethodDef(cyfunc)->ml_meth;
#endif

switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) {
@@ -1175,7 +1195,7 @@ static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject
PyCFunction meth = PyCFunction_GetFunction(cyfunc->func);
if (unlikely(!meth)) return NULL;
#else
- PyCFunction meth = ((PyCFunctionObject*)cyfunc)->m_ml->ml_meth;
+ PyCFunction meth = __Pyx_CyFunction_GetMethodDef(cyfunc)->ml_meth;
#endif
switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) {
case 1:
@@ -1435,14 +1455,14 @@ __pyx_FusedFunction_descr_get_locked(__pyx_FusedFunctionObject *func, PyObject *
module = __Pyx_CyFunction_get_module((__pyx_CyFunctionObject *) func, NULL);
if ((unlikely(!module))) return NULL;
#else
- module = ((PyCFunctionObject *) func)->m_module;
+ module = __Pyx_CyFunction_GetModule(func);
#endif

meth = (__pyx_FusedFunctionObject *) __pyx_FusedFunction_New(
#if CYTHON_COMPILING_IN_LIMITED_API
func->ml,
#else
- ((PyCFunctionObject *) func)->m_ml,
+ __Pyx_CyFunction_GetMethodDef(func),
#endif
((__pyx_CyFunctionObject *) func)->flags,
((__pyx_CyFunctionObject *) func)->func_qualname,
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index ddaffbd..c8e7962 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -96,9 +96,11 @@
#undef CYTHON_FAST_GIL
#define CYTHON_FAST_GIL 0
#undef CYTHON_METH_FASTCALL
- #define CYTHON_METH_FASTCALL 0
+ #define CYTHON_METH_FASTCALL 1
#undef CYTHON_FAST_PYCALL
- #define CYTHON_FAST_PYCALL 0
+ #define CYTHON_FAST_PYCALL 1
+ #undef CYTHON_FAST_PYCCALL
+ #define CYTHON_FAST_PYCCALL 1
#ifndef CYTHON_PEP487_INIT_SUBCLASS
#define CYTHON_PEP487_INIT_SUBCLASS 1
#endif
diff --git a/Cython/Utility/arrayarray.h b/Cython/Utility/arrayarray.h
index bc6da7b..6bf0559 100644
--- a/Cython/Utility/arrayarray.h
+++ b/Cython/Utility/arrayarray.h
@@ -69,10 +69,27 @@ struct arrayobject {
int ob_exports; /* Number of exported buffers */
};

+#if CYTHON_COMPILING_IN_GRAAL && defined(GRAALPY_VERSION_NUM) && GRAALPY_VERSION_NUM >= 0x190304a0
+#define __PYX_USE_GRAALPY_ARRAY_API 1
+#else
+#define __PYX_USE_GRAALPY_ARRAY_API 0
+#endif
+
+static CYTHON_INLINE struct arraydescr *__Pyx_PyArray_Descr(arrayobject *self) {
+#if __PYX_USE_GRAALPY_ARRAY_API
+ return (struct arraydescr *)GraalPyArray_GetDescriptor((PyObject*)self);
+#else
+ return self->ob_descr;
+#endif
+}
+
#ifndef NO_NEWARRAY_INLINE
// fast creation of a new array
static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t size,
struct arraydescr *descr) {
+#if __PYX_USE_GRAALPY_ARRAY_API
+ return GraalPyArray_New((PyObject*)type, size, (GraalPyArray_Descriptor*)descr);
+#else
arrayobject *op;
size_t nbytes;

@@ -105,6 +122,7 @@ static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t si
}
}
return (PyObject *) op;
+#endif
}
#else
PyObject* newarrayobject(PyTypeObject *type, Py_ssize_t size,
Loading
Loading