[pypy-issue] Issue #2342: [cpyext] unable to set tp_as_* function if NULL when PyType_Ready called (pypy/pypy)

Amaury Forgeot d'Arc amauryfa at gmail.com
Mon Jul 11 03:58:02 EDT 2016

2016-07-10 16:39 GMT+02:00 mattip <issues-reply at bitbucket.org>:

> New issue 2342: [cpyext] unable to set tp_as_* function if NULL when
> PyType_Ready called
> https://bitbucket.org/pypy/pypy/issues/2342/cpyext-unable-to-set-tp_as_-function-if
> mattip:
> numpy sets tp_as_number slots for scalars when importing umath, which
> happens way after PyType_Ready is called on the scalar types. Since the
> various tp_as_number.* functions are NULL when PyType_Ready is called, no
> wrapper function is created in add_operators, and the later
> pto.tp_as_number assignment has no effect. This is the actual problem
> underlying issue #.

This looks wrong to me, even from a CPython perspective. Are the __add__
methods and others correctly filled?

> I have created a branch override-tp_as-methods and a test in that branch,
> but it is not clear to me what the strategy to resolve this should be. Two
> options, niether good::
> - somehow create stub functions for each tp_as_* slot, wrapping the
> original type's function, beign careful not to create recursive calls
> - add a PyPy only C_API function like PyType_Refresh(pto) that would
> re-assign the tp_as_* slots
> Any other ideas?

If nneeded, the existing PyType_Modified() seems a perfect fit for this

def PyType_Modified(space, w_obj):
    """Invalidate the internal lookup cache for the type and all of its
    subtypes.  This function must be called after any manual
    modification of the attributes or base classes of the type.

> _______________________________________________
> pypy-issue mailing list
> pypy-issue at python.org
> https://mail.python.org/mailman/listinfo/pypy-issue

Amaury Forgeot d'Arc

More information about the pypy-issue mailing list