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("I", "foo"); struct.pack("L", "foo") should fail #45118
Comments
The following code prints out "I L" when run with python 2.5 and current SVN trunk (if you silence the DeprecationWarnings): """ for c in "bBhHiIlLqQdf":
try:
struct.pack(c, "foo bar")
except struct.error:
pass
else:
print c
""" It works correctly (prints nothing) in Python 2.4. |
Cannot confirm for trunk. |
While the behavior cannot be reproduced in the trunk, in can be $ python -W ignore
Python 2.6.1 (r261:67515, Dec 6 2008, 16:42:21)
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.pack('L', 'foobar')
'\x00\x00\x00\x00'
>>> struct.pack('I', 'foobar')
'\x00\x00\x00\x00'
>>> struct.pack('i', 'foobar')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: required argument is not an integer
>>> |
It looks as though this was sort-of fixed sometime between 2.6.1 and Python 2.6.2+ (release26-maint:71755, Apr 19 2009, 22:06:02)
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.pack('L', 'not an integer')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for &: 'str' and 'long' That error message suggests that there's something nasty happening |
Mark, Virgil: Thanks for correcting my wrong assessment! The lucky TypeError comes from rev 68120. It looks like that error message in trunk is due to a "PyNumber_And(v, |
Thanks for the patch, Daniel! It certainly fixes the problem. I was At the moment it's not clear exactly what types should be accepted by I propose doing a little bit of rewriting so that (1) all attempted conversions of a PyObject to a C integer (2) If PY_STRUCT_FLOAT_COERCE is defined, instances of float or Does this seem reasonable? |
Here's a patch that does some general cleanup of the object->integer |
Strange TypeError message fixed in r73858: those pack operations now raise |
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: