[PyQt] SIP problem with compiled functions (or anything that is not a function or method)

Phil Thompson phil at riverbankcomputing.com
Sun Feb 19 14:02:07 GMT 2012


On Sun, 19 Feb 2012 13:42:58 +0100, Kay Hayen <kayhayen at gmx.de> wrote:
> Hello,
> 
> I have previously raised the problem, but this time I have a solution as

> well.
> 
>          /*
>           * Emulate the behaviour of a descriptor to make sure we return

> a bound
>           * method.
>           */
>          if (PyMethod_Check(reimp))
>          {
>              /* It's already a method but make sure it is bound. */
>              if (PyMethod_GET_SELF(reimp) != NULL)
>              {
>                  Py_INCREF(reimp);
>              }
>              else
>              {
> #if PY_MAJOR_VERSION >= 3
>                  reimp = PyMethod_New(PyMethod_GET_FUNCTION(reimp),
>                          (PyObject *)sipSelf);
> #else
>                  reimp = PyMethod_New(PyMethod_GET_FUNCTION(reimp),
>                          (PyObject *)sipSelf,
PyMethod_GET_CLASS(reimp));
> #endif
>              }
>          }
>          else if (PyFunction_Check(reimp))
>          {
> #if PY_MAJOR_VERSION >= 3
>              reimp = PyMethod_New(reimp, (PyObject *)sipSelf);
> #else
>              reimp = PyMethod_New(reimp, (PyObject *)sipSelf, cls);
> #endif
>          }
>          else
>          {
>              /*
>               * We don't know what it is so just return and assume that
an
>               * appropriate exception will be raised later on.
>               */
>              Py_INCREF(reimp);
>          }
> 
> 
> Now I don't know the rationale for making an emulation. But if I add 
> this before the else:
> 
>          else if (Py_TYPE(reimp)->tp_descr_get)
>          {
>              reimp = Py_TYPE(reimp)->tp_descr_get(reimp, (PyObject 
> *)sipSelf, cls);
>          }
> 
> it just asks whatever object it is to bind itself to the given object 
> and class. Can you please consider this change? It makes PyQt work with 
> Nuitka out of the box.

Seems to be a safe enough change - applied.

Phil


More information about the PyQt mailing list