New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
struct.pack() + numpy int raises SystemError #46516
Comments
struct.pack() raises SystemError when fed a numpy integer in some cases. Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> import numpy
>>> i = numpy.int16(1)
>>> struct.pack(">B", i)
__main__:1: DeprecationWarning: struct integer overflow masking is
deprecated
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/struct.
py", line 63, in pack
return o.pack(*args)
SystemError: /Users/ronald/r252/Objects/longobject.c:322: bad argument
to internal function
>>> struct.pack(">H", i)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/struct.
py", line 63, in pack
return o.pack(*args)
SystemError: /Users/ronald/r252/Objects/longobject.c:322: bad argument
to internal function
>>> struct.pack(">h", i)
'\x00\x01'
>>> struct.pack(">b", i)
'\x01'
>>> struct.pack("B", i)
'\x01'
>>> struct.pack("h", i)
'\x01\x00'
>>> numpy.__version__
'1.0.4'
>>> |
on ubuntu 8.04, Python 2.7a0 (trunk:69044) and numpy 1.2.1
signed char b 'int16' . <. >. 'uint32' . <. >. |
in 2.7 svn _struct.c
np_ubyte calls get_long b/lp_uint call get_wrapped_ulong which calls
#define PyInt_Check(op) \
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS) but ob_type is set to BASE flags INT_SUBCLASS i snot set. |
Including Py_TPFLAGS_INT_SUBCLASS in numpy's BASEFLAGS cures this. |
Ok, so Python has to improve its C-API documentation, and numpy to fix |
FYI Py_TPFLAGS_INT_SUBCLASS already not used in Python 3.x. |
As noted in bpo-5476, I've submitted a pull request for NumPy: ttps://github.com/numpy/numpy/pull/3526 . I hope that this fixes this problem too: on Py2, I've added Py_TPFLAGS_INT_SUBCLASS, on Py3, NumPy doesn't inherit from int anymore, because it's not a fixed-width integer type. I guess it makes sense to close this bug now. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: