Author meador.inge
Recipients mark.dickinson, meador.inge, skrah
Date 2011-09-16.15:03:51
SpamBayes Score 4.4742e-14
Marked as misclassified No
Message-id <CAK1QooqQuM8CnW++zTjQmGYxFR4Oe2qWAA285rC__oOP-F2YDw@mail.gmail.com>
In-reply-to <20110916125702.GA17500@sleipnir.bytereef.org>
Content
> I specifically meant the 'P' format. As far as I can see, PyLong_AsVoidPtr()
> never allowed __int__(), but now index objects can be packed as pointers.
> It isn't a big deal, I just have to know for features/pep-3118.
>
> To illustrate, this is python2.5.0; INT is an object with an __int__() method:
>
> '\x07\x00\x00\x00\x00\x00\x00\x00'
>>>> struct.pack('P', INT(7))
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "/home/stefan/hg/r25/Lib/struct.py", line 63, in pack
>    return o.pack(*args)
> struct.error: cannot convert argument to long

Huh, that's interesting.  It doesn't allow 'unsigned long' packs either (2.6.7):

Python 2.6.7+ (unknown, Sep 16 2011, 09:53:25)
[GCC 4.6.0 20110603 (Red Hat 4.6.0-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> class IDX(object):
...     def __init__(self, value):
...         self.value = value
...     def __int__(self):
...          return self.value
...
>>> for code in ['l', 'L', 'P']:
...    try:
...       struct.pack(code, IDX(9))
...    except Exception as e:
...       print "pack('%s'): %s" % (code, e)
...
'\t\x00\x00\x00'
pack('L'): unsupported operand type(s) for &: 'IDX' and 'long'
pack('P'): cannot convert argument to long

The behavior around '__int__' in previous versions seems somewhat accidental.
History
Date User Action Args
2011-09-16 15:03:51meador.ingesetrecipients: + meador.inge, mark.dickinson, skrah
2011-09-16 15:03:51meador.ingelinkissue12974 messages
2011-09-16 15:03:51meador.ingecreate