Skip to content

Commit 9bdcd49

Browse files
committed
Fix: PyCFunction_NewEx did not wrap 'self'.
1 parent be44900 commit 9bdcd49

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PyObject* PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module) {
5050
polyglot_from_string((const char*)(ml->ml_name), SRC_CS),
5151
pytruffle_decorate_function(native_to_java(ml->ml_meth), native_to_java_exported),
5252
get_method_flags_wrapper(ml->ml_flags),
53-
self,
53+
native_to_java(self),
5454
native_to_java(module),
55-
ml->ml_doc ? polyglot_from_string(ml->ml_doc, SRC_CS) : Py_None));
55+
ml->ml_doc ? polyglot_from_string(ml->ml_doc, SRC_CS) : native_to_java(Py_None)));
5656
}

‎graalpython/lib-graalpython/python_cext.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def AddFunction(primary, tpDict, name, cfunc, wrapper, doc, isclass=False, issta
939939
owner = to_java_type(primary)
940940
if isinstance(owner, moduletype):
941941
# module case, we create the bound function-or-method
942-
func = PyCFunction_NewEx(name, cfunc, wrapper, owner, owner.__name__, doc)
942+
func = _PyCFunction_NewEx(name, cfunc, wrapper, owner, owner.__name__, to_java(doc))
943943
object.__setattr__(owner, name, func)
944944
else:
945945
func = CreateFunction(name, cfunc, wrapper, owner)
@@ -960,11 +960,15 @@ def __init__(self, *args, **kwargs):
960960

961961

962962
def PyCFunction_NewEx(name, cfunc, wrapper, self, module, doc):
963+
return _PyCFunction_NewEx(name, cfunc, wrapper, to_java(self), to_java(module), to_java(doc))
964+
965+
966+
def _PyCFunction_NewEx(name, cfunc, wrapper, self, module, doc):
963967
func = CreateFunction(name, cfunc, wrapper)
964968
PyTruffle_SetAttr(func, "__name__", name)
965-
PyTruffle_SetAttr(func, "__doc__", to_java(doc))
969+
PyTruffle_SetAttr(func, "__doc__", doc)
966970
method = PyTruffle_BuiltinMethod(self, func)
967-
PyTruffle_SetAttr(method, "__module__", to_java(module))
971+
PyTruffle_SetAttr(method, "__module__", module)
968972
return method
969973

970974

0 commit comments

Comments
 (0)