Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue1741130] struct.pack("I", "foo"); struct.pack("L", "foo") should fail

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jul 4, 2009, 2:30 AM

Post #1 of 3 (144 views)
Permalink
[issue1741130] struct.pack("I", "foo"); struct.pack("L", "foo") should fail

Mark Dickinson <dickinsm[at]gmail.com> added the comment:

Thanks for the patch, Daniel! It certainly fixes the problem. I was
planning something a little more drastic, though---I think the struct
module could do with a bit of a cleanup in this area.

At the moment it's not clear exactly what types should be accepted by
struct.pack with an integer format. Just ints and longs (and their
subclases)? Anything implementing an __index__ method? Anything
implementing an __int__ method (e.g., Decimal instances)?

I propose doing a little bit of rewriting so that

(1) all attempted conversions of a PyObject to a C integer
go through PyNumber_Index; thus anything with an __index__
method can be packed.

(2) If PY_STRUCT_FLOAT_COERCE is defined, instances of float or
subclasses of float (i.e., everything that passes PyFloat_Check)
are also accepted, for backwards compatibility.

Does this seem reasonable?

----------

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue1741130>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2009, 2:48 PM

Post #2 of 3 (122 views)
Permalink
[issue1741130] struct.pack("I", "foo"); struct.pack("L", "foo") should fail [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> added the comment:

Here's a patch that does some general cleanup of the object->integer
helper functions in the struct module; in the process, it fixes this
bug. With this patch, all conversions from a PyObject to a C integer go
through get_pylong, so they're all treated the same way. Currently
(i.e., without the patch) there's a lack of consistency in the way the
various integer codes are handled---some codes emit a warning for float
conversions and some ('q', 'Q') don't; some codes will happily convert
a Decimal instance, and others won't. Some codes produce this strange
'unsupported operand types' message and some don't, etc.

----------
versions: +Python 2.7 -Python 2.6
Added file: http://bugs.python.org/file14451/issue1741130.patch

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue1741130>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 5, 2009, 3:08 AM

Post #3 of 3 (117 views)
Permalink
[issue1741130] struct.pack("I", "foo"); struct.pack("L", "foo") should fail [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> added the comment:

Strange TypeError message fixed in r73858: those pack operations now raise
struct.error, like they do for all other integer codes.

----------
resolution: -> fixed
stage: patch review -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue1741130>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.