Skip to content

Commit cbe0c15

Browse files
committed
Rename GraalPy-speficic PyDescrObject functions
1 parent 6d0174e commit cbe0c15

File tree

12 files changed

+50
-49
lines changed

12 files changed

+50
-49
lines changed

graalpython/com.oracle.graal.python.cext/include/cpython/descrobject.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2023, Oracle and/or its affiliates.
1+
/* Copyright (c) 2023, 2025, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2023 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -37,8 +37,8 @@ typedef struct {
3737

3838
#define PyDescr_COMMON PyDescrObject d_common
3939

40-
#define PyDescr_TYPE(x) PyDescrObject_GetType((PyObject*)(x))
41-
#define PyDescr_NAME(x) PyDescrObject_GetName((PyObject*)(x))
40+
#define PyDescr_TYPE(x) GraalPyDescrObject_GetType((PyObject*)(x))
41+
#define PyDescr_NAME(x) GraalPyDescrObject_GetName((PyObject*)(x))
4242

4343
typedef struct {
4444
PyDescr_COMMON;
@@ -67,3 +67,12 @@ PyAPI_DATA(PyTypeObject) _PyMethodWrapper_Type;
6767
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
6868
struct wrapperbase *, void *);
6969
PyAPI_FUNC(int) PyDescr_IsData(PyObject *);
70+
71+
// GraalPy public API to replace struct accessors
72+
PyAPI_FUNC(PyMethodDef*) GraalPyMethodDescrObject_GetMethod(PyObject*);
73+
PyAPI_FUNC(PyTypeObject*) GraalPyDescrObject_GetType(PyObject*);
74+
PyAPI_FUNC(PyObject*) GraalPyDescrObject_GetName(PyObject*);
75+
// Deprecated aliases kept for current versions of Cython
76+
// Remove in 27.0
77+
#define PyDescrObject_GetType GraalPyDescrObject_GetType
78+
#define PyMethodDescrObject_GetMethod GraalPyMethodDescrObject_GetMethod

graalpython/com.oracle.graal.python.cext/include/descrobject.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2024, Oracle and/or its affiliates.
1+
/* Copyright (c) 2018, 2025, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2020 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -93,11 +93,6 @@ struct PyMemberDef {
9393
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, PyMemberDef *);
9494
PyAPI_FUNC(int) PyMember_SetOne(char *, PyMemberDef *, PyObject *);
9595

96-
// GraalPy-specific
97-
PyAPI_FUNC(PyMethodDef*) PyMethodDescrObject_GetMethod(PyObject*);
98-
PyAPI_FUNC(PyTypeObject*) PyDescrObject_GetType(PyObject*);
99-
PyAPI_FUNC(PyObject*) PyDescrObject_GetName(PyObject*);
100-
10196
#ifndef Py_LIMITED_API
10297
# define Py_CPYTHON_DESCROBJECT_H
10398
# include "cpython/descrobject.h"

graalpython/com.oracle.graal.python.cext/src/descrobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ PyObject* PyDescr_NewGetSet(PyTypeObject *type, PyGetSetDef *getset) {
6363
}
6464

6565

66-
PyMethodDef* PyMethodDescrObject_GetMethod(PyObject* descr) {
66+
PyMethodDef* GraalPyMethodDescrObject_GetMethod(PyObject* descr) {
6767
return GraalPyPrivate_GET_PyMethodDescrObject_d_method(descr);
6868
}
6969

70-
PyTypeObject* PyDescrObject_GetType(PyObject* descr) {
70+
PyTypeObject* GraalPyDescrObject_GetType(PyObject* descr) {
7171
return GraalPyPrivate_GET_PyDescrObject_d_type(descr);
7272
}
7373

74-
PyObject* PyDescrObject_GetName(PyObject* descr) {
74+
PyObject* GraalPyDescrObject_GetName(PyObject* descr) {
7575
return GraalPyPrivate_GET_PyDescrObject_d_name(descr);
7676
}
7777

graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/CApiBuiltinsProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,12 +746,12 @@ private static Path resolvePath(Path path) {
746746
private static final String[] ADDITIONAL = new String[]{
747747
/*
748748
* These PySlice builtins are deprecated and scheduled for removal once we no
749-
* longer support old versions of Cython that use them. Grep all patches before
749+
* longer support versions of Cython that use them. Grep all patches before
750750
* removing
751751
*/
752752
"PySlice_Start", "PySlice_Step", "PySlice_Stop",
753-
"PyDescrObject_GetName", "PyDescrObject_GetType", "PyInterpreterState_GetIDFromThreadState",
754-
"PyMethodDescrObject_GetMethod", "PyObject_GetDoc", "PyObject_SetDoc", "_PyFrame_SetLineNumber",
753+
"PyInterpreterState_GetIDFromThreadState",
754+
"PyObject_GetDoc", "PyObject_SetDoc", "_PyFrame_SetLineNumber",
755755
"PyCode_GetName",
756756
"PyCode_GetFileName", "_PyArray_Resize", "_PyArray_Data",
757757
"_PyErr_Occurred", "_PyNamespace_New", "_Py_GetErrorHandler",

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_descr.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -75,7 +75,7 @@ def test_new_classmethod(self):
7575
assert tester.from_param(123) == TestNewClassMethod
7676

7777
def test_new_descr(self):
78-
C = CPyExtType("C_",
78+
C = CPyExtType("C_",
7979
'''
8080
PyTypeObject A_Type = {
8181
PyVarObject_HEAD_INIT(NULL, 0)
@@ -91,7 +91,7 @@ def test_new_descr(self):
9191
}
9292
9393
static PyMethodDef foo_method = {
94-
"foo", foo, METH_O
94+
"foo", foo, METH_O
9595
};
9696
9797
static PyObject* B_new(PyTypeObject* type, PyObject* a, PyObject* b) {
@@ -166,11 +166,11 @@ def test_new_descr(self):
166166
B_Type.tp_base = &PyType_Type;
167167
if (PyType_Ready(&B_Type) < 0)
168168
return NULL;
169-
170-
Py_SET_TYPE(&C_Type, &B_Type);
169+
170+
Py_SET_TYPE(&C_Type, &B_Type);
171171
C_Type.tp_base = &A_Type;''',
172172
)
173-
173+
174174
class bar(C):
175175
pass
176176
assert bar().foo(None) is None
@@ -306,8 +306,8 @@ class TestDescr(CPyExtTestCase):
306306
if (PyObject_TypeCheck(method, (PyTypeObject *)methoddescr_type)) {
307307
PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
308308
#ifdef GRAALVM_PYTHON
309-
PyTypeObject *d_type = PyDescrObject_GetType(method);
310-
PyObject *class_method = PyDescr_NewClassMethod(d_type, PyMethodDescrObject_GetMethod(method));
309+
PyTypeObject *d_type = GraalPyDescrObject_GetType(method);
310+
PyObject *class_method = PyDescr_NewClassMethod(d_type, GraalPyMethodDescrObject_GetMethod(method));
311311
#else
312312
PyTypeObject *d_type = descr->d_common.d_type;
313313
PyObject *class_method = PyDescr_NewClassMethod(d_type, descr->d_method);

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def test_PyMethodDef(self):
575575
#define GraalPyCFunction_SetMethodDef(OBJ, VAL) (((PyCFunctionObject*) (OBJ))->m_ml = (VAL))
576576
#define GraalPyCFunction_GetModule(OBJ) (((PyCFunctionObject*) (OBJ))->m_module)
577577
#define GraalPyCFunction_SetModule(OBJ, VAL) (((PyCFunctionObject*) (OBJ))->m_module = (VAL))
578-
#define PyMethodDescrObject_GetMethod(OBJ) (((PyMethodDescrObject *) (OBJ))->d_method)
578+
#define GraalPyMethodDescrObject_GetMethod(OBJ) (((PyMethodDescrObject *) (OBJ))->d_method)
579579
#endif
580580
581581
static PyObject *native_meth_noargs(PyObject *self, PyObject *dummy) {
@@ -704,7 +704,7 @@ def test_PyMethodDef(self):
704704
PyErr_SetString(PyExc_TypeError, "<callable> is not a PyMethodDescrObject (i.e. method_descriptor)");
705705
return NULL;
706706
}
707-
PyMethodDef *def = PyMethodDescrObject_GetMethod(callable);
707+
PyMethodDef *def = GraalPyMethodDescrObject_GetMethod(callable);
708708
// returns a borrowed ref
709709
return _call_PyCFunction(def, callable_self, callable_args, callable_kwargs);
710710
}
@@ -756,7 +756,7 @@ def test_PyMethodDef(self):
756756
if (PyCFunction_Check(callable)) {
757757
def = GraalPyCFunction_GetMethodDef(callable);
758758
} else if (PyObject_TypeCheck(callable, &PyMethodDescr_Type)) {
759-
def = PyMethodDescrObject_GetMethod(callable);
759+
def = GraalPyMethodDescrObject_GetMethod(callable);
760760
} else {
761761
PyErr_SetString(PyExc_TypeError, "<callable> is not a PyCFunction (i.e. builtin_method_or_function) "
762762
"nor a PyMethodDescrObject (i.e. method_descriptor)");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ public final class CApiFunction {
242242
@CApiBuiltin(name = "PyComplex_ImagAsDouble", ret = ArgDescriptor.Double, args = {PyObject}, call = CImpl)
243243
@CApiBuiltin(name = "PyComplex_RealAsDouble", ret = ArgDescriptor.Double, args = {PyObject}, call = CImpl)
244244
@CApiBuiltin(name = "PyContextVar_Get", ret = Int, args = {PyObject, PyObject, PyObjectPtr}, call = CImpl)
245-
@CApiBuiltin(name = "PyDescrObject_GetName", ret = PyObject, args = {PyObject}, call = CImpl)
246-
@CApiBuiltin(name = "PyDescrObject_GetType", ret = PyTypeObject, args = {PyObject}, call = CImpl)
247245
@CApiBuiltin(name = "PyDescr_IsData", ret = Int, args = {PyObject}, call = CImpl)
248246
@CApiBuiltin(name = "PyDescr_NewClassMethod", ret = PyObject, args = {PyTypeObject, PyMethodDef}, call = CImpl)
249247
@CApiBuiltin(name = "PyDescr_NewGetSet", ret = PyObject, args = {PyTypeObject, PyGetSetDef}, call = CImpl)
@@ -356,7 +354,6 @@ public final class CApiFunction {
356354
@CApiBuiltin(name = "PyMem_Realloc", ret = Pointer, args = {Pointer, SIZE_T}, call = CImpl)
357355
@CApiBuiltin(name = "PyMemoryView_FromBuffer", ret = PyObject, args = {CONST_PY_BUFFER_PTR}, call = CImpl)
358356
@CApiBuiltin(name = "PyMemoryView_FromMemory", ret = PyObject, args = {CHAR_PTR, Py_ssize_t, Int}, call = CImpl)
359-
@CApiBuiltin(name = "PyMethodDescrObject_GetMethod", ret = PyMethodDef, args = {PyObject}, call = CImpl)
360357
@CApiBuiltin(name = "PyMethod_Function", ret = PyObject, args = {PyObject}, call = CImpl)
361358
@CApiBuiltin(name = "PyMethod_Self", ret = PyObject, args = {PyObject}, call = CImpl)
362359
@CApiBuiltin(name = "PyModuleDef_Init", ret = PyObject, args = {PYMODULEDEF_PTR}, call = CImpl)

graalpython/lib-graalpython/patches/Cython-0.29.32.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ index b2c67dc..ad80ca4 100644
219219
PyTypeObject *d_type = descr->d_type;
220220
#else
221221
- PyTypeObject *d_type = descr->d_common.d_type;
222-
+ PyTypeObject *d_type = PyDescrObject_GetType(method);
222+
+ PyTypeObject *d_type = GraalPyDescrObject_GetType(method);
223223
#endif
224224
- return PyDescr_NewClassMethod(d_type, descr->d_method);
225-
+ return PyDescr_NewClassMethod(d_type, PyMethodDescrObject_GetMethod(method));
225+
+ return PyDescr_NewClassMethod(d_type, GraalPyMethodDescrObject_GetMethod(method));
226226
}
227227
#endif
228228
else if (PyMethod_Check(method)) {
@@ -320,8 +320,8 @@ index 6e7153c..6d766a1 100644
320320
PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
321321
- target->func = descr->d_method->ml_meth;
322322
- target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
323-
+ target->func = PyMethodDescrObject_GetMethod(method)->ml_meth;
324-
+ target->flag = PyMethodDescrObject_GetMethod(method)->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
323+
+ target->func = GraalPyMethodDescrObject_GetMethod(method)->ml_meth;
324+
+ target->flag = GraalPyMethodDescrObject_GetMethod(method)->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
325325
}
326326
#endif
327327
return 0;

graalpython/lib-graalpython/patches/Cython-0.29.37.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ index 93f577f..5dac1d7 100644
237237
PyTypeObject *d_type = descr->d_type;
238238
#else
239239
- PyTypeObject *d_type = descr->d_common.d_type;
240-
+ PyTypeObject *d_type = PyDescrObject_GetType(method);
240+
+ PyTypeObject *d_type = GraalPyDescrObject_GetType(method);
241241
#endif
242242
- return PyDescr_NewClassMethod(d_type, descr->d_method);
243-
+ return PyDescr_NewClassMethod(d_type, PyMethodDescrObject_GetMethod(method));
243+
+ return PyDescr_NewClassMethod(d_type, GraalPyMethodDescrObject_GetMethod(method));
244244
}
245245
#endif
246246
else if (PyMethod_Check(method)) {
@@ -338,8 +338,8 @@ index 5c4d9e1..4cdd29a 100644
338338
PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
339339
- target->func = descr->d_method->ml_meth;
340340
- target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
341-
+ target->func = PyMethodDescrObject_GetMethod(method)->ml_meth;
342-
+ target->flag = PyMethodDescrObject_GetMethod(method)->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
341+
+ target->func = GraalPyMethodDescrObject_GetMethod(method)->ml_meth;
342+
+ target->flag = GraalPyMethodDescrObject_GetMethod(method)->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
343343
}
344344
#endif
345345
return 0;

graalpython/lib-graalpython/patches/Cython-3.0.10.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ index 3ea60f5..18d1842 100644
214214
PyTypeObject *d_type = descr->d_type;
215215
#else
216216
- PyTypeObject *d_type = descr->d_common.d_type;
217-
+ PyTypeObject *d_type = PyDescrObject_GetType(method);
217+
+ PyTypeObject *d_type = GraalPyDescrObject_GetType(method);
218218
#endif
219219
- return PyDescr_NewClassMethod(d_type, descr->d_method);
220-
+ return PyDescr_NewClassMethod(d_type, PyMethodDescrObject_GetMethod(method));
220+
+ return PyDescr_NewClassMethod(d_type, GraalPyMethodDescrObject_GetMethod(method));
221221
}
222222
#endif
223223
else if (PyMethod_Check(method)) {
@@ -275,8 +275,8 @@ index 1021edf..6139fd2 100644
275275
PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
276276
- target->func = descr->d_method->ml_meth;
277277
- target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
278-
+ target->func = PyMethodDescrObject_GetMethod(method)->ml_meth;
279-
+ target->flag = PyMethodDescrObject_GetMethod(method)->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
278+
+ target->func = GraalPyMethodDescrObject_GetMethod(method)->ml_meth;
279+
+ target->flag = GraalPyMethodDescrObject_GetMethod(method)->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
280280
} else
281281
#endif
282282
// bound classmethods need special treatment

0 commit comments

Comments
 (0)