Skip to content

Commit 0bed09e

Browse files
committed
Add patch for numpy 2
1 parent fbe3af9 commit 0bed09e

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

graalpython/lib-graalpython/patches/numpy/metadata.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[[rules]]
2+
version = '>= 2.0.0rc1, < 2.1'
3+
patch = 'numpy-2.0.0.patch'
4+
dist-type = 'sdist'
5+
ignore-rule-on-llvm = true
6+
17
[[rules]]
28
version = '== 1.26.4'
39
patch = 'numpy-1.26.4.patch'
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
diff --git a/numpy/_core/include/numpy/ndarrayobject.h b/numpy/_core/include/numpy/ndarrayobject.h
2+
index 0462625..3625e34 100644
3+
--- a/numpy/_core/include/numpy/ndarrayobject.h
4+
+++ b/numpy/_core/include/numpy/ndarrayobject.h
5+
@@ -220,7 +220,7 @@ NPY_TITLE_KEY_check(PyObject *key, PyObject *value)
6+
if (key == title) {
7+
return 1;
8+
}
9+
-#ifdef PYPY_VERSION
10+
+#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
11+
/*
12+
* On PyPy, dictionary keys do not always preserve object identity.
13+
* Fall back to comparison by value.
14+
diff --git a/numpy/_core/src/multiarray/compiled_base.c b/numpy/_core/src/multiarray/compiled_base.c
15+
index 7913b18..9463852 100644
16+
--- a/numpy/_core/src/multiarray/compiled_base.c
17+
+++ b/numpy/_core/src/multiarray/compiled_base.c
18+
@@ -1407,6 +1407,7 @@ fail:
19+
NPY_NO_EXPORT PyObject *
20+
arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *const *args, Py_ssize_t len_args)
21+
{
22+
+#if 0 // GraalPy change
23+
PyObject *obj;
24+
PyObject *str;
25+
const char *docstr;
26+
@@ -1518,6 +1519,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *const *args, Py_ssize_t
27+
}
28+
29+
#undef _ADDDOC
30+
+#endif // GraalPy change
31+
32+
Py_RETURN_NONE;
33+
}
34+
diff --git a/numpy/_core/src/multiarray/shape.c b/numpy/_core/src/multiarray/shape.c
35+
index ede7a61..21ae17b 100644
36+
--- a/numpy/_core/src/multiarray/shape.c
37+
+++ b/numpy/_core/src/multiarray/shape.c
38+
@@ -105,6 +105,11 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,
39+
"cannot resize an array with refcheck=True on PyPy.\n"
40+
"Use the np.resize function or refcheck=False");
41+
return NULL;
42+
+#elif defined(GRAALVM_PYTHON)
43+
+ PyErr_SetString(PyExc_ValueError,
44+
+ "cannot resize an array with refcheck=True on GraalPy.\n"
45+
+ "Use the np.resize function or refcheck=False");
46+
+ return NULL;
47+
#else
48+
refcnt = Py_REFCNT(self);
49+
#endif /* PYPY_VERSION */
50+
diff --git a/numpy/_core/src/multiarray/stringdtype/dtype.c b/numpy/_core/src/multiarray/stringdtype/dtype.c
51+
index b94ab7e..6148268 100644
52+
--- a/numpy/_core/src/multiarray/stringdtype/dtype.c
53+
+++ b/numpy/_core/src/multiarray/stringdtype/dtype.c
54+
@@ -817,7 +817,7 @@ init_string_dtype(void)
55+
};
56+
57+
/* Loaded dynamically, so needs to be set here: */
58+
- Py_TYPE(((PyObject *)&PyArray_StringDType)) = &PyArrayDTypeMeta_Type;
59+
+ Py_SET_TYPE(((PyObject *)&PyArray_StringDType), &PyArrayDTypeMeta_Type);
60+
((PyTypeObject *)&PyArray_StringDType)->tp_base = &PyArrayDescr_Type;
61+
if (PyType_Ready((PyTypeObject *)&PyArray_StringDType) < 0) {
62+
return -1;
63+
diff --git a/numpy/_core/src/multiarray/temp_elide.c b/numpy/_core/src/multiarray/temp_elide.c
64+
index 2890406..353a657 100644
65+
--- a/numpy/_core/src/multiarray/temp_elide.c
66+
+++ b/numpy/_core/src/multiarray/temp_elide.c
67+
@@ -58,7 +58,7 @@
68+
* supported too by using the appropriate Windows APIs.
69+
*/
70+
71+
-#if defined HAVE_BACKTRACE && defined HAVE_DLFCN_H && ! defined PYPY_VERSION
72+
+#if defined HAVE_BACKTRACE && defined HAVE_DLFCN_H && ! defined PYPY_VERSION && !defined(GRAALVM_PYTHON)
73+
74+
#include <feature_detection_misc.h>
75+
76+
diff --git a/numpy/_core/src/npymath/ieee754.c.src b/numpy/_core/src/npymath/ieee754.c.src
77+
index 8fccc9a..3bb9cf0 100644
78+
--- a/numpy/_core/src/npymath/ieee754.c.src
79+
+++ b/numpy/_core/src/npymath/ieee754.c.src
80+
@@ -362,6 +362,11 @@ int npy_get_floatstatus_barrier(char* param)
81+
* By using a volatile, the compiler cannot reorder this call
82+
*/
83+
if (param != NULL) {
84+
+ // GraalPy change: the pointer needs to be dereferenced to establish
85+
+ // a data dependency to to ensure the compiler won't reorder the call
86+
+ if (points_to_py_handle_space(param)) {
87+
+ param = (char*)pointer_to_stub(param);
88+
+ }
89+
volatile char NPY_UNUSED(c) = *(char*)param;
90+
}
91+
92+
diff --git a/numpy/_core/src/npymath/ieee754.cpp b/numpy/_core/src/npymath/ieee754.cpp
93+
index 1c59bf3..519fabc 100644
94+
--- a/numpy/_core/src/npymath/ieee754.cpp
95+
+++ b/numpy/_core/src/npymath/ieee754.cpp
96+
@@ -428,6 +428,11 @@ npy_get_floatstatus_barrier(char *param)
97+
* By using a volatile, the compiler cannot reorder this call
98+
*/
99+
if (param != NULL) {
100+
+ // GraalPy change: the pointer needs to be dereferenced to establish
101+
+ // a data dependency to to ensure the compiler won't reorder the call
102+
+ if (points_to_py_handle_space(param)) {
103+
+ param = (char*)pointer_to_stub(param);
104+
+ }
105+
volatile char NPY_UNUSED(c) = *(char *)param;
106+
}
107+
108+
diff --git a/vendored-meson/meson/mesonbuild/utils/universal.py b/vendored-meson/meson/mesonbuild/utils/universal.py
109+
index 1694912..a555fe3 100644
110+
--- a/vendored-meson/meson/mesonbuild/utils/universal.py
111+
+++ b/vendored-meson/meson/mesonbuild/utils/universal.py
112+
@@ -727,6 +727,7 @@ def windows_detect_native_arch() -> str:
113+
"""
114+
if sys.platform != 'win32':
115+
return ''
116+
+ return 'amd64' # Workaround for GraalPy bug on Windows with kernel32.GetCurrentProcess()
117+
try:
118+
import ctypes
119+
process_arch = ctypes.c_ushort()

mx.graalpython/mx_graalpython.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,7 @@ def _python_checkpatchfiles():
21192119
'numpy-1.23.2.patch',
21202120
'numpy-1.23.5.patch',
21212121
'numpy-1.26.4.patch',
2122+
'numpy-2.0.0.patch',
21222123
# libcst is MIT
21232124
'libcst-1.0.1.patch',
21242125
# Empty license field, skip it. It's MIT

0 commit comments

Comments
 (0)