Python 2.2 __slots__ Bug?

Glyph Lefkowitz glyph at twistedmatrix.com
Wed Jun 26 07:03:23 EDT 2002


I'm sorry if this is a known issue.  I couldn't get through to the bugtracker
at sourceforge.net; it's abysmally slow and I stopped waiting for the search to
run after about 15 minutes.  Searches on google yielded nothing similar for
'python __slots__ bug'.

I think I have discovered a weird bug in the Python interpreter.  Under
Python2.2, when I run this script:

    class foo(object):
        def __init__(self, n):
            self.n = n
        __slots__ = ['n']

    o = None
    for i in xrange(43550):
        o = foo(o)
    del o
    o = None
    print "I'm fine."
    for i in xrange(43551):
        o = foo(o)
    del o
    print "I'm dead."

I get "I'm fine" and then a segmentation fault.  This only happens when
__slots__ is defined on a new-style class.  Seriously, i'm not making those
numbers up -- reliably, 43551 objects will crash the interpreter; fewer will
not.

I don't know the code here, but I'm willing to bet Python is smashing the stack
because PyType_GenericAlloc() is recursive.  I get a stacktrace from gdb that
looks like this:

    #0  0x100a3fc4 in PyDict_New ()
    #1  0x100244e8 in _PyType_Lookup ()
    #2  0x100249d4 in _PyObject_SlotCompare ()
    #3  0x1001a3d4 in PyType_GenericAlloc ()
    #4  0x1001a4fc in PyType_GenericAlloc ()
    #5  0x1001a5b8 in PyType_GenericAlloc ()
    #6  0x1001a5b8 in PyType_GenericAlloc ()
    #7  0x1001a5b8 in PyType_GenericAlloc ()
    #8  0x1001a5b8 in PyType_GenericAlloc ()
    #9  0x1001a5b8 in PyType_GenericAlloc ()
    #10 0x1001a5b8 in PyType_GenericAlloc ()
    #11 0x1001a5b8 in PyType_GenericAlloc ()
    #12 0x1001a5b8 in PyType_GenericAlloc ()
    #13 0x1001a5b8 in PyType_GenericAlloc ()
    #14 0x1001a5b8 in PyType_GenericAlloc ()

... and so on, and so on, for longer than I had the patience to page through.
(I did get to about #400, though.)

Version Information:

    % python2.2
    Python 2.2.1 (#1, May  4 2002, 11:33:48) 
    [GCC 2.95.4 20011002 (Debian prerelease)] on linux2

And since those arguments to xrange() above look like some weird magic to me,
this may also be useful to know:

    % free
                 total       used       free     shared    buffers     cached
    Mem:        253968     146192     107776          0       8008      59184
    -/+ buffers/cache:      79000     174968
    Swap:       262136       3168     258968

    % uname -a
    Linux zelda 2.4.18 #1 SMP Fri Apr 26 19:18:50 CDT 2002 ppc unknown

Is there any in-development code I should try running?

-- 
 |    <`'>    |  Glyph Lefkowitz: Traveling Sorcerer   |
 |   < _/ >   |  Lead Developer,  the Twisted project  |
 |  < ___/ >  |      http://www.twistedmatrix.com      |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20020626/1fc4389b/attachment.sig>


More information about the Python-list mailing list