[Python-3000] MemoryError oddities

Georg Brandl g.brandl at gmx.net
Mon Jul 21 20:26:54 CEST 2008


In a debug-build 3k, do this (32-bit machine):

Python 3.0b2+ (py3k:65171M, Jul 21 2008, 20:08:20)
[GCC 4.2.4 (Gentoo 4.2.4 p1.0)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> "a"*1000000000
instinstTraceback (most recent call last):
   File "<stdin>", line 1, in <module>
MemoryError
[41296 refs]
 >>> "a"*1000000000
inst[1]    21400 segmentation fault  ./python

Here, something fishy is probably going on in the unicode free list.
Compare with 2.6:

Python 2.6b2+ (trunk:65131:65163M, Jul 21 2008, 19:58:07)
[GCC 4.2.4 (Gentoo 4.2.4 p1.0)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> u"a"*1000000000
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
MemoryError
[34330 refs]
 >>> u"a"*1000000000
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
MemoryError
[34332 refs]

Still, the refcount seems to leak.

Also:

 >>> b"a"*sys.maxsize
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
MemoryError
[41297 refs]
 >>> b"a"*sys.maxsize
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<stdin>", line 1, in <module>
MemoryError
[41317 refs]
 >>> b"a"*sys.maxsize
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<stdin>", line 1, in <module>
   File "<stdin>", line 1, in <module>
MemoryError
[41337 refs]

This probably has to do with the fact that this MemoryError is a prebuilt
instance.

Finally:

 >>> "a"*sys.maxsize
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
OverflowError: repeated string is too long
[41379 refs]

Nothing wrong here, but the exception is a different one.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-3000 mailing list