Repository navigation
BUG: Fix PyType_FastSubclass() check for numpy.int_ and Py3k inheritance - #3526
Conversation
|
The tp_flags change sounds correct, but the py3 issue is a doc bug -- On Tue, Jul 16, 2013 at 2:40 PM, Yury V. Zaytsev
|
|
Hi @njsmith, Thank you very much for your review! I will then drop the second part (Py3k support) and add a doc patch that contains your comment. This is great, because my changes trigger a testsuite segfault on Py3k which I'm not sure of how to approach :-/ Do you have any ideas on how to properly test that or it would be fine the way it is? I guess I could add a test which checks whether --Yury. |
|
Hi @njsmith, I've updated my patch and Travis seems to be happy now. Python 3 behavior is unchanged, Python 2 is still as illustrated in the first post (i.e. now fast-path checks should work). Thanks! |
|
After a productive discussion with @seberg on the IRC, I have managed to come up with a test, which seems to work. Let me know if there is anything else that I can do. |
|
Otherwise looks good to me. |
|
Hi @njsmith, Thank you for your valuable comments. I have changed the docstring to a comment in the test, and implemented your suggestions for the documentation patch. I have left the addendum, however, because I think that it's useful to have the reason explained under the table. Nevertheless, if you maintain that it should be removed altogether, I will do so. Thanks again! |
|
Ping! |
|
@njsmith Any remaining problems with this? |
|
Can't really check while traveling, but I think its probably good. If you
|
There was a problem hiding this comment.
First line in multiline comment should be blank
/*
* start here
*/
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
|
Hi Charles, Thanks, I've fixed it and rebased to latest master... Z. |
|
Let's give it a shot. Thanks. |
BUG: Fix PyType_FastSubclass() check for numpy.int_ and Py3k inheritance

Quote from the documentation at http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html :
However, presently, the code deviates from this document in two ways:
numpy.int_type, the correcttp_flagsare not set, which means that if one uses specialized fast-path Python C-API macroPyInt_Checkon its instances to check whether the object is a subclass of a Python builtin, the result will be different (False) as compared toPyObject_TypeCheck(True).This results in a different behavior of seemingly the same logic run through the Python interpreter using its MRO facilities and hand-written or generated modules, using optimized C-API calls directly.
SINGLE_INHERITmacros, which means thatnumpy.int_is not a subclass ofintunder Py3k at all.My patch fixes these two issues by (a) introducing new macro
DUAL_INHERIT_INT, which expands toDUAL_INHERIT(XXX, Long, XXX)under Py3k andDUAL_INHERIT(XXX, Int, XXX)otherwise and (b) settingtp_flagscorrectly from within this macro.In order to test my changes, you will need the following minimal Cython program that generates code using optimized C-API calls:
Test output on the x86_64 machine:
Python 2.7, without patch
Python 2.7, with patch
Thank you for considering my bugfix for inclusion in NumPy,
--Yury.