From 2aed3ec87bf48c6043965c82ae1a85e2fb583ff9 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 22 Apr 2018 19:32:34 +0200 Subject: pypy: avoid calling tp_init, doesn't work with PyPy Calling tp_init under PyPy does not call the Python level __init__. Filed under https://bitbucket.org/pypy/pypy/issues/2806 Just use PyObject_CallMethod() to call __init__ instead. It works just as well and there is no perf difference from a quick test. --- gi/gimodule.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gi/gimodule.c b/gi/gimodule.c index a3984dad..e46af02c 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -1030,7 +1030,7 @@ pygobject__g_instance_init(GTypeInstance *instance, gpointer g_class) { GObject *object = (GObject *) instance; - PyObject *wrapper, *args, *kwargs; + PyObject *wrapper, *result; PyGILState_STATE state; wrapper = g_object_get_qdata(object, pygobject_wrapper_key); @@ -1057,18 +1057,16 @@ pygobject__g_instance_init(GTypeInstance *instance, * so we don't destroy the wrapper. The next call to pygobject_new_full * will take the ref */ pygobject_ref_float ((PyGObject *) wrapper); - args = PyTuple_New(0); - kwargs = PyDict_New(); - if (Py_TYPE(wrapper)->tp_init(wrapper, args, kwargs)) - PyErr_Print(); - Py_DECREF(args); - Py_DECREF(kwargs); + result = PyObject_CallMethod (wrapper, "__init__", NULL); + if (result == NULL) + PyErr_Print (); + else + Py_DECREF (result); } /* XXX: used for Gtk.Template */ if (PyObject_HasAttrString (wrapper, "__dontuse_ginstance_init__")) { - PyObject *result; result = PyObject_CallMethod (wrapper, "__dontuse_ginstance_init__", NULL); if (result == NULL) PyErr_Print (); -- cgit v1.2.1