[Python-Dev] test warnings for "%x"%id(foo) on 2.3 branch

Anthony Baxter anthony at interlink.com.au
Wed Nov 5 06:23:16 EST 2003

>>> Martin v. =?iso-8859-15?q?L=F6wis?= wrote
> What system is this on? I find it surprising that the id is < 0: on a
> 32-bit machine, this should only happen if you allocate more than 2GB.

Redhat 10 beta3 (Fedora). I'm not entirely sure why it's generating these.
Using current CVS python (although it also complains when building a 2.3.2
on this platform, but a 2.3.2 compiled on RH9 is fine.

Python 2.3.2+ (#1, Nov  5 2003, 00:54:02) 
[GCC 3.3.1 20030930 (Red Hat Linux 3.3.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> id('sdkjhfdkfhsdkjfhsdkjfhdskf')

It seems most things have a very large id now:

>>> class a: pass
>>> print a()
<__main__.a instance at 0xbf6dad4c>
>>> print a()
<__main__.a instance at 0xbf6dac2c>
>>> print a()
<__main__.a instance at 0xbf6dad0c>
>>> print a()
<__main__.a instance at 0xbf6dabcc>

I wonder if it's some sort of "randomly jumble around the address space to
prevent stack-smashing" thing? I seem to recall something about Position
Independant Execution in the release notes. This version of RH will be the 
one released in the next week or so.

> I'd reformulate them as 
> "%x" % (id(o) & 0xffffffffL)
> Of course, you have to replace 0xffffffffL with (unsigned)-1 of the
> system (i.e. 2l*sys.maxint+1). 

Hm. "%x" % (id(o) & 2L*sys.maxint+1)

is considerably less obvious that "%x"%id(o)

> I wonder whether creating a function
> sys.unsigned(id(o))
> would be appropriate, which returns its arguments for positive
> numbers, and PyLong_FromUnsignedLong((unsigned)arg) otherwise.

Possibly. I'm going to have to make the above patch to the 23 branch 
in any case - warnings from the standard test suite are bad. Would a 
different % format code be another option?


Anthony Baxter     <anthony at interlink.com.au>   
It's never too late to have a happy childhood.

More information about the Python-Dev mailing list