Skip to content

Commit f2e6384

Browse files
committed
Add functions to access some PyCFunction fields
1 parent bc36981 commit f2e6384

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ typedef struct {
3232
PyCFunctionObject func;
3333
PyTypeObject *mm_class; /* Class that defines this method */
3434
} PyCMethodObject;
35+
36+
/*
37+
* XXX These functions are GraalPy-only. We need them to replace field access in our patches.
38+
* Currently used by (at least) cffi patch.
39+
*/
40+
PyAPI_FUNC(PyObject*) _PyCFunction_GetModule(PyObject* a);
41+
PyAPI_FUNC(PyMethodDef*) _PyCFunction_GetMethodDef(PyObject* a);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ PyTypeObject * PyCFunction_GetClass(PyObject *func) {
8787
PyMethodDef* def = PyCFunctionObject_m_ml(func);
8888
return PyMethodDef_ml_flags(def) & METH_METHOD ? PyCMethodObject_mm_class(func) : NULL;
8989
}
90+
91+
PyObject* _PyCFunction_GetModule(PyObject *func) {
92+
return PyCFunctionObject_m_module(func);
93+
}
94+
95+
PyMethodDef* _PyCFunction_GetMethodDef(PyObject *func) {
96+
return PyCFunctionObject_m_ml(func);
97+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public static boolean assertBuiltins(Object capiLibrary) {
541541
"PyMethodDescrObject_GetMethod", "PyObject_GetDoc", "PyObject_SetDoc", "PySlice_Start", "PySlice_Step", "PySlice_Stop", "_PyASCIIObject_LENGTH", "_PyASCIIObject_STATE_ASCII",
542542
"_PyASCIIObject_STATE_COMPACT", "_PyASCIIObject_STATE_KIND", "_PyASCIIObject_STATE_READY", "_PyASCIIObject_WSTR", "_PyByteArray_Start", "_PyEval_SetCoroutineOriginTrackingDepth",
543543
"_PyFrame_SetLineNumber", "_PyMemoryView_GetBuffer", "_PySequence_Fast_ITEMS", "_PySequence_ITEM", "_PyUnicodeObject_DATA", "_PyUnicode_get_wstr_length", "_Py_REFCNT",
544-
"_Py_SET_REFCNT", "_Py_SET_SIZE", "_Py_SET_TYPE", "_Py_SIZE", "_Py_TYPE", "_PyTuple_SET_ITEM"};
544+
"_Py_SET_REFCNT", "_Py_SET_SIZE", "_Py_SET_TYPE", "_Py_SIZE", "_Py_TYPE", "_PyTuple_SET_ITEM", "_PyCFunction_GetModule", "_PyCFunction_GetMethodDef"};
545545

546546
/**
547547
* Check the list of implemented and unimplemented builtins against the list of CPython exported

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ public final class CApiFunction {
484484
@CApiBuiltin(name = "PyCFunction_GetFlags", ret = Int, args = {PyObject}, call = PolyglotImpl)
485485
@CApiBuiltin(name = "PyCFunction_GetFunction", ret = PY_C_FUNCTION, args = {PyObject}, call = PolyglotImpl)
486486
@CApiBuiltin(name = "PyCFunction_GetSelf", ret = PyObject, args = {PyObject}, call = PolyglotImpl)
487+
@CApiBuiltin(name = "_PyCFunction_GetModule", ret = PyObject, args = {PyObject}, call = PolyglotImpl)
488+
@CApiBuiltin(name = "_PyCFunction_GetMethodDef", ret = PyMethodDef, args = {PyObject}, call = PolyglotImpl)
487489
@CApiBuiltin(name = "PyCFunction_New", ret = PyObject, args = {PyMethodDef, PyObject}, call = PolyglotImpl)
488490
@CApiBuiltin(name = "PyCFunction_NewEx", ret = PyObject, args = {PyMethodDef, PyObject, PyObject}, call = PolyglotImpl)
489491
@CApiBuiltin(name = "PyCMethod_New", ret = PyObject, args = {PyMethodDef, PyObject, PyObject, PyTypeObject}, call = PolyglotImpl)

0 commit comments

Comments
 (0)