Skip to content

Commit 3ad7e37

Browse files
committed
Rebase numpy patches on autopatch_capi changes
1 parent 831d643 commit 3ad7e37

File tree

3 files changed

+28
-297
lines changed

3 files changed

+28
-297
lines changed

graalpython/lib-graalpython/patches/numpy/numpy-1.23.2.patch

Lines changed: 12 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -121,157 +121,22 @@ index af53d78..1fcd6d3 100644
121121
return NULL;
122122
}
123123
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c
124-
index 2b82aca..7260b1b 100644
124+
index 66e79b0..771ce75 100644
125125
--- a/numpy/core/src/multiarray/compiled_base.c
126126
+++ b/numpy/core/src/multiarray/compiled_base.c
127-
@@ -1414,78 +1414,78 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
127+
@@ -1414,6 +1414,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
128128
return NULL;
129129
}
130130

131-
-#define _ADDDOC(doc, name) \
132-
- if (!(doc)) { \
133-
- doc = docstr; \
134-
- Py_INCREF(str); /* hold on to string (leaks reference) */ \
135-
- } \
136-
- else if (strcmp(doc, docstr) != 0) { \
137-
- PyErr_Format(PyExc_RuntimeError, "%s method %s", name, msg); \
138-
- return NULL; \
139-
- }
140-
-
141-
- if (Py_TYPE(obj) == &PyCFunction_Type) {
142-
- PyCFunctionObject *new = (PyCFunctionObject *)obj;
143-
- _ADDDOC(PyObject_GetDoc((PyObject*)(new)), new->m_ml->ml_name);
144-
- }
145-
- else if (PyObject_TypeCheck(obj, &PyType_Type)) {
146-
- /*
147-
- * We add it to both `tp_doc` and `__doc__` here. Note that in theory
148-
- * `tp_doc` extracts the signature line, but we currently do not use
149-
- * it. It may make sense to only add it as `__doc__` and
150-
- * `__text_signature__` to the dict in the future.
151-
- * The dictionary path is only necessary for heaptypes (currently not
152-
- * used) and metaclasses.
153-
- * If `__doc__` as stored in `tp_dict` is None, we assume this was
154-
- * filled in by `PyType_Ready()` and should also be replaced.
155-
- */
156-
- PyTypeObject *new = (PyTypeObject *)obj;
157-
- _ADDDOC(new->tp_doc, new->tp_name);
158-
- if (new->tp_dict != NULL && PyDict_CheckExact(new->tp_dict) &&
159-
- PyDict_GetItemString(new->tp_dict, "__doc__") == Py_None) {
160-
- /* Warning: Modifying `tp_dict` is not generally safe! */
161-
- if (PyDict_SetItemString(new->tp_dict, "__doc__", str) < 0) {
162-
- return NULL;
163-
- }
164-
- }
165-
- }
166-
- else if (Py_TYPE(obj) == &PyMemberDescr_Type) {
167-
- PyMemberDescrObject *new = (PyMemberDescrObject *)obj;
168-
- _ADDDOC(new->d_member->doc, new->d_member->name);
169-
- }
170-
- else if (Py_TYPE(obj) == &PyGetSetDescr_Type) {
171-
- PyGetSetDescrObject *new = (PyGetSetDescrObject *)obj;
172-
- _ADDDOC(new->d_getset->doc, new->d_getset->name);
173-
- }
174-
- else if (Py_TYPE(obj) == &PyMethodDescr_Type) {
175-
- PyMethodDescrObject *new = (PyMethodDescrObject *)obj;
176-
- _ADDDOC(new->d_method->ml_doc, new->d_method->ml_name);
177-
- }
178-
- else {
179-
- PyObject *doc_attr;
180-
-
181-
- doc_attr = PyObject_GetAttrString(obj, "__doc__");
182-
- if (doc_attr != NULL && doc_attr != Py_None &&
183-
- (PyUnicode_Compare(doc_attr, str) != 0)) {
184-
- Py_DECREF(doc_attr);
185-
- if (PyErr_Occurred()) {
186-
- /* error during PyUnicode_Compare */
187-
- return NULL;
188-
- }
189-
- PyErr_Format(PyExc_RuntimeError, "object %s", msg);
190-
- return NULL;
191-
- }
192-
- Py_XDECREF(doc_attr);
193-
-
194-
- if (PyObject_SetAttrString(obj, "__doc__", str) < 0) {
195-
- PyErr_SetString(PyExc_TypeError,
196-
- "Cannot set a docstring for that object");
197-
- return NULL;
198-
- }
199-
- Py_RETURN_NONE;
200-
- }
201-
-
202-
-#undef _ADDDOC
203-
+// #define _ADDDOC(doc, name) \
204-
+// if (!(doc)) { \
205-
+// doc = docstr; \
206-
+// Py_INCREF(str); /* hold on to string (leaks reference) */ \
207-
+// } \
208-
+// else if (strcmp(doc, docstr) != 0) { \
209-
+// PyErr_Format(PyExc_RuntimeError, "%s method %s", name, msg); \
210-
+// return NULL; \
211-
+// }
212-
+//
213-
+// if (Py_TYPE(obj) == &PyCFunction_Type) {
214-
+// PyCFunctionObject *new = (PyCFunctionObject *)obj;
215-
+// _ADDDOC(PyObject_GetDoc((PyObject*)(new)), new->m_ml->ml_name);
216-
+// }
217-
+// else if (PyObject_TypeCheck(obj, &PyType_Type)) {
218-
+// /*
219-
+// * We add it to both `tp_doc` and `__doc__` here. Note that in theory
220-
+// * `tp_doc` extracts the signature line, but we currently do not use
221-
+// * it. It may make sense to only add it as `__doc__` and
222-
+// * `__text_signature__` to the dict in the future.
223-
+// * The dictionary path is only necessary for heaptypes (currently not
224-
+// * used) and metaclasses.
225-
+// * If `__doc__` as stored in `tp_dict` is None, we assume this was
226-
+// * filled in by `PyType_Ready()` and should also be replaced.
227-
+// */
228-
+// PyTypeObject *new = (PyTypeObject *)obj;
229-
+// _ADDDOC(new->tp_doc, new->tp_name);
230-
+// if (new->tp_dict != NULL && PyDict_CheckExact(new->tp_dict) &&
231-
+// PyDict_GetItemString(new->tp_dict, "__doc__") == Py_None) {
232-
+// /* Warning: Modifying `tp_dict` is not generally safe! */
233-
+// if (PyDict_SetItemString(new->tp_dict, "__doc__", str) < 0) {
234-
+// return NULL;
235-
+// }
236-
+// }
237-
+// }
238-
+// else if (Py_TYPE(obj) == &PyMemberDescr_Type) {
239-
+// PyMemberDescrObject *new = (PyMemberDescrObject *)obj;
240-
+// _ADDDOC(new->d_member->doc, new->d_member->name);
241-
+// }
242-
+// else if (Py_TYPE(obj) == &PyGetSetDescr_Type) {
243-
+// PyGetSetDescrObject *new = (PyGetSetDescrObject *)obj;
244-
+// _ADDDOC(new->d_getset->doc, new->d_getset->name);
245-
+// }
246-
+// else if (Py_TYPE(obj) == &PyMethodDescr_Type) {
247-
+// PyMethodDescrObject *new = (PyMethodDescrObject *)obj;
248-
+// _ADDDOC(new->d_method->ml_doc, new->d_method->ml_name);
249-
+// }
250-
+// else {
251-
+// PyObject *doc_attr;
252-
+//
253-
+// doc_attr = PyObject_GetAttrString(obj, "__doc__");
254-
+// if (doc_attr != NULL && doc_attr != Py_None &&
255-
+// (PyUnicode_Compare(doc_attr, str) != 0)) {
256-
+// Py_DECREF(doc_attr);
257-
+// if (PyErr_Occurred()) {
258-
+// /* error during PyUnicode_Compare */
259-
+// return NULL;
260-
+// }
261-
+// PyErr_Format(PyExc_RuntimeError, "object %s", msg);
262-
+// return NULL;
263-
+// }
264-
+// Py_XDECREF(doc_attr);
265-
+//
266-
+// if (PyObject_SetAttrString(obj, "__doc__", str) < 0) {
267-
+// PyErr_SetString(PyExc_TypeError,
268-
+// "Cannot set a docstring for that object");
269-
+// return NULL;
270-
+// }
271-
+// Py_RETURN_NONE;
272-
+// }
273-
+//
274-
+// #undef _ADDDOC
131+
+#if 0 // GraalPy change
132+
#define _ADDDOC(doc, name) \
133+
if (!(doc)) { \
134+
doc = docstr; \
135+
@@ -1486,6 +1487,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
136+
}
137+
138+
#undef _ADDDOC
139+
+#endif // GraalPy change
275140

276141
Py_RETURN_NONE;
277142
}
@@ -293,7 +158,7 @@ index f959162..2ef579b 100644
293158
return ret;
294159
}
295160
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
296-
index 161dca1..bedca0c 100644
161+
index c68a0a2..a833c4f 100644
297162
--- a/numpy/core/src/multiarray/methods.c
298163
+++ b/numpy/core/src/multiarray/methods.c
299164
@@ -1095,7 +1095,6 @@ any_array_ufunc_overrides(PyObject *args, PyObject *kwds)

graalpython/lib-graalpython/patches/numpy/numpy-1.23.5.patch

Lines changed: 15 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ index af9e2df..042d854 100644
246246
acc += lane * _NpyHASH_XXPRIME_2;
247247
acc = _NpyHASH_XXROTATE(acc);
248248
diff --git a/numpy/core/src/common/ufunc_override.c b/numpy/core/src/common/ufunc_override.c
249-
index 4fb4d4b..a721a60 100644
249+
index 4fb4d4b..571aae5 100644
250250
--- a/numpy/core/src/common/ufunc_override.c
251251
+++ b/numpy/core/src/common/ufunc_override.c
252252
@@ -79,13 +79,12 @@ PyUFunc_HasOverride(PyObject * obj)
@@ -403,162 +403,28 @@ index af53d78..f42c8fc 100644
403403
return NULL;
404404
}
405405
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c
406-
index 5853e06..fc7aedd 100644
406+
index 66e79b0..8a3076a 100644
407407
--- a/numpy/core/src/multiarray/compiled_base.c
408408
+++ b/numpy/core/src/multiarray/compiled_base.c
409-
@@ -1414,78 +1414,78 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
409+
@@ -1414,6 +1414,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
410410
return NULL;
411411
}
412412

413-
-#define _ADDDOC(doc, name) \
414-
- if (!(doc)) { \
415-
- doc = docstr; \
416-
- Py_INCREF(str); /* hold on to string (leaks reference) */ \
417-
- } \
418-
- else if (strcmp(doc, docstr) != 0) { \
419-
- PyErr_Format(PyExc_RuntimeError, "%s method %s", name, msg); \
420-
- return NULL; \
421-
- }
422-
-
423-
- if (Py_TYPE(obj) == &PyCFunction_Type) {
424-
- PyCFunctionObject *new = (PyCFunctionObject *)obj;
425-
- _ADDDOC(PyObject_GetDoc((PyObject*)(new)), new->m_ml->ml_name);
426-
- }
427-
- else if (PyObject_TypeCheck(obj, &PyType_Type)) {
428-
- /*
429-
- * We add it to both `tp_doc` and `__doc__` here. Note that in theory
430-
- * `tp_doc` extracts the signature line, but we currently do not use
431-
- * it. It may make sense to only add it as `__doc__` and
432-
- * `__text_signature__` to the dict in the future.
433-
- * The dictionary path is only necessary for heaptypes (currently not
434-
- * used) and metaclasses.
435-
- * If `__doc__` as stored in `tp_dict` is None, we assume this was
436-
- * filled in by `PyType_Ready()` and should also be replaced.
437-
- */
438-
- PyTypeObject *new = (PyTypeObject *)obj;
439-
- _ADDDOC(new->tp_doc, new->tp_name);
440-
- if (new->tp_dict != NULL && PyDict_CheckExact(new->tp_dict) &&
441-
- PyDict_GetItemString(new->tp_dict, "__doc__") == Py_None) {
442-
- /* Warning: Modifying `tp_dict` is not generally safe! */
443-
- if (PyDict_SetItemString(new->tp_dict, "__doc__", str) < 0) {
444-
- return NULL;
445-
- }
446-
- }
447-
- }
448-
- else if (Py_TYPE(obj) == &PyMemberDescr_Type) {
449-
- PyMemberDescrObject *new = (PyMemberDescrObject *)obj;
450-
- _ADDDOC(new->d_member->doc, new->d_member->name);
451-
- }
452-
- else if (Py_TYPE(obj) == &PyGetSetDescr_Type) {
453-
- PyGetSetDescrObject *new = (PyGetSetDescrObject *)obj;
454-
- _ADDDOC(new->d_getset->doc, new->d_getset->name);
455-
- }
456-
- else if (Py_TYPE(obj) == &PyMethodDescr_Type) {
457-
- PyMethodDescrObject *new = (PyMethodDescrObject *)obj;
458-
- _ADDDOC(new->d_method->ml_doc, new->d_method->ml_name);
459-
- }
460-
- else {
461-
- PyObject *doc_attr;
462-
-
463-
- doc_attr = PyObject_GetAttrString(obj, "__doc__");
464-
- if (doc_attr != NULL && doc_attr != Py_None &&
465-
- (PyUnicode_Compare(doc_attr, str) != 0)) {
466-
- Py_DECREF(doc_attr);
467-
- if (PyErr_Occurred()) {
468-
- /* error during PyUnicode_Compare */
469-
- return NULL;
470-
- }
471-
- PyErr_Format(PyExc_RuntimeError, "object %s", msg);
472-
- return NULL;
473-
- }
474-
- Py_XDECREF(doc_attr);
475-
-
476-
- if (PyObject_SetAttrString(obj, "__doc__", str) < 0) {
477-
- PyErr_SetString(PyExc_TypeError,
478-
- "Cannot set a docstring for that object");
479-
- return NULL;
480-
- }
481-
- Py_RETURN_NONE;
482-
- }
483-
-
484-
-#undef _ADDDOC
485-
+// #define _ADDDOC(doc, name) \
486-
+// if (!(doc)) { \
487-
+// doc = docstr; \
488-
+// Py_INCREF(str); /* hold on to string (leaks reference) */ \
489-
+// } \
490-
+// else if (strcmp(doc, docstr) != 0) { \
491-
+// PyErr_Format(PyExc_RuntimeError, "%s method %s", name, msg); \
492-
+// return NULL; \
493-
+// }
494-
+
495-
+// if (Py_TYPE(obj) == &PyCFunction_Type) {
496-
+// PyCFunctionObject *new = (PyCFunctionObject *)obj;
497-
+// _ADDDOC(PyObject_GetDoc((PyObject*)(new)), new->m_ml->ml_name);
498-
+// }
499-
+// else if (PyObject_TypeCheck(obj, &PyType_Type)) {
500-
+// /*
501-
+// * We add it to both `tp_doc` and `__doc__` here. Note that in theory
502-
+// * `tp_doc` extracts the signature line, but we currently do not use
503-
+// * it. It may make sense to only add it as `__doc__` and
504-
+// * `__text_signature__` to the dict in the future.
505-
+// * The dictionary path is only necessary for heaptypes (currently not
506-
+// * used) and metaclasses.
507-
+// * If `__doc__` as stored in `tp_dict` is None, we assume this was
508-
+// * filled in by `PyType_Ready()` and should also be replaced.
509-
+// */
510-
+// PyTypeObject *new = (PyTypeObject *)obj;
511-
+// _ADDDOC(new->tp_doc, new->tp_name);
512-
+// if (new->tp_dict != NULL && PyDict_CheckExact(new->tp_dict) &&
513-
+// PyDict_GetItemString(new->tp_dict, "__doc__") == Py_None) {
514-
+// /* Warning: Modifying `tp_dict` is not generally safe! */
515-
+// if (PyDict_SetItemString(new->tp_dict, "__doc__", str) < 0) {
516-
+// return NULL;
517-
+// }
518-
+// }
519-
+// }
520-
+// else if (Py_TYPE(obj) == &PyMemberDescr_Type) {
521-
+// PyMemberDescrObject *new = (PyMemberDescrObject *)obj;
522-
+// _ADDDOC(new->d_member->doc, new->d_member->name);
523-
+// }
524-
+// else if (Py_TYPE(obj) == &PyGetSetDescr_Type) {
525-
+// PyGetSetDescrObject *new = (PyGetSetDescrObject *)obj;
526-
+// _ADDDOC(new->d_getset->doc, new->d_getset->name);
527-
+// }
528-
+// else if (Py_TYPE(obj) == &PyMethodDescr_Type) {
529-
+// PyMethodDescrObject *new = (PyMethodDescrObject *)obj;
530-
+// _ADDDOC(new->d_method->ml_doc, new->d_method->ml_name);
531-
+// }
532-
+// else {
533-
+// PyObject *doc_attr;
534-
+
535-
+// doc_attr = PyObject_GetAttrString(obj, "__doc__");
536-
+// if (doc_attr != NULL && doc_attr != Py_None &&
537-
+// (PyUnicode_Compare(doc_attr, str) != 0)) {
538-
+// Py_DECREF(doc_attr);
539-
+// if (PyErr_Occurred()) {
540-
+// /* error during PyUnicode_Compare */
541-
+// return NULL;
542-
+// }
543-
+// PyErr_Format(PyExc_RuntimeError, "object %s", msg);
544-
+// return NULL;
545-
+// }
546-
+// Py_XDECREF(doc_attr);
547-
+
548-
+// if (PyObject_SetAttrString(obj, "__doc__", str) < 0) {
549-
+// PyErr_SetString(PyExc_TypeError,
550-
+// "Cannot set a docstring for that object");
551-
+// return NULL;
552-
+// }
553-
+// Py_RETURN_NONE;
554-
+// }
555-
+
556-
+// #undef _ADDDOC
413+
+#if 0 // GraalPy change
414+
#define _ADDDOC(doc, name) \
415+
if (!(doc)) { \
416+
doc = docstr; \
417+
@@ -1486,7 +1487,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
418+
}
557419

420+
#undef _ADDDOC
421+
-
422+
+#endif // GraalPy change
558423
Py_RETURN_NONE;
559424
}
425+
560426
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c
561-
index f959162..2ef579b 100644
427+
index f959162..daf83f1 100644
562428
--- a/numpy/core/src/multiarray/iterators.c
563429
+++ b/numpy/core/src/multiarray/iterators.c
564430
@@ -1400,7 +1400,11 @@ arraymultiter_new(PyTypeObject *NPY_UNUSED(subtype), PyObject *args,
@@ -575,7 +441,7 @@ index f959162..2ef579b 100644
575441
return ret;
576442
}
577443
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
578-
index 3e8c78d..60eacfb 100644
444+
index 28fe643..46f540b 100644
579445
--- a/numpy/core/src/multiarray/methods.c
580446
+++ b/numpy/core/src/multiarray/methods.c
581447
@@ -1095,7 +1095,6 @@ any_array_ufunc_overrides(PyObject *args, PyObject *kwds)

graalpython/lib-graalpython/patches/numpy/numpy-1.26.4.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ index d4b73eb..af90a68 100644
1212
* On PyPy, dictionary keys do not always preserve object identity.
1313
* Fall back to comparison by value.
1414
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c
15-
index 63cb6be..dc423fe 100644
15+
index 0842477..4e3647f 100644
1616
--- a/numpy/core/src/multiarray/compiled_base.c
1717
+++ b/numpy/core/src/multiarray/compiled_base.c
1818
@@ -1406,6 +1406,7 @@ fail:

0 commit comments

Comments
 (0)