[pypy-issue] Issue #2334: wrong function called for slot in cpyext + numpy (pypy/pypy)
issues-reply at bitbucket.org
Tue Jun 28 01:49:42 EDT 2016
New issue 2334: wrong function called for slot in cpyext + numpy
Upstream numpy assigned `int_multiply` to the `np_multiply` slot of numpy.int32, and `gentype_multiply` to the `np_multipy` slot of numpy.int32 's tp_base type (and other places as well).
In **cpython**, when I call either `import numpy as np; np.int32(2) * [1, 2, 3]` or `import numpy as np; [1, 2, 3] * np.int32(2)`, it calls into `int_multiply`, in **pypy** it calls `gentype_multiply` which then calls `array_multiply`. When I stop in gdb at those functions, in both pypy and cpython the correct binary function is being used (the np.int32 is the expected right or left argument) and the its ob_type shows int_multiply as val->ob_type->tp_as_number->tp_multiply.
I added a test to test_arraymodule.py to default in f0b680130986 that shows, at least in this simple case, that the binop_mul_impl resolution is working as advertised, I suspect the problem is in the creation of the PyPy w_type from numpy.int32 in PyType_Ready. I tried adding a base class with a different np_multiply slot to the array.c that is tested by test_arraymodule, but the test still worked correctly.
To reproduces the error, it is enough to::
- build/install numpy with debug info,
- run `gdb --args <pypy/cpython> -c "import numpy as np; np.int(2) * [1, 2, 3]"`,
- set breakpoints at int_multiply and array_multiply
To compile numpy with debug info, cd into a clone of numpy and `rm -rf build; CFLAGS='-g -O0' <pypy or cpython> setup.py install`
How can I reproduce this error untranslated?
More information about the pypy-issue