[Python-Dev] GC and ExtensionClass

skip@pobox.com (Skip Montanaro) skip@pobox.com (Skip Montanaro)
Fri, 11 May 2001 15:41:30 -0500


Has anyone investigated interactions between ExtensionClass objects and GC?
I've encountered segfaults with 2.1 in certain situations when using the
latest PyGtk stuff.  The gdb traceback (appended) sort of suggests the two
intersect somewhere.  PyGtk provides a Python interface to the Gtk widget
get using ExtensionClasses.  Any ideas how I should approach the problem?  I
don't know either piece of code at all and the code that generates the
segfault isn't particularly small, not to mention which it uses the bleeding
edge Gtk stuff (which I doubt anyone on this list will have installed) and a
version of ExtensionClass patched by James Henstridge, the PyGtk author.

Here's what I know:

    1. Disabling gc gets rid of the segfault
    2. I only see the problem with importing a specific module that
       subclasses the GtkTextView widget from the Python command line.  If I
       run it as a script from the shell prompt, I get no segfault.
    3. If I first import the gtk module, then import my module, I get no
       segfault. 
    4. Most changes I make to the module causing the problem cause the
       problemm to disappear.

All told, all this really tells me is I'm probably dealing with a
malloc/free problem of some sort.

Neil and/or Jim (and/or anyone else willing to look into this problem), I
can give you access to my development machine via ssh if you think that
would help debug the problem.

Skip

#0  0x0807163d in visit_decref (op=0x4034ece0, data=0x0)
    at ../Modules/gcmodule.c:153
#1  0x08096dc6 in tupletraverse (o=0x8290d6c, visit=0x8071630 <visit_decref>, 
    arg=0x0) at ../Objects/tupleobject.c:366
#2  0x08071672 in subtract_refs (containers=0x80b8ac0)
    at ../Modules/gcmodule.c:167
#3  0x08071abf in collect (young=0x80b8ac0, old=0x80b8acc)
    at ../Modules/gcmodule.c:379
#4  0x08071d53 in collect_generations () at ../Modules/gcmodule.c:484
#5  0x08071db7 in _PyGC_Insert (op=0x82ea9c4) at ../Modules/gcmodule.c:507
#6  0x0808d743 in PyDict_New () at ../Objects/dictobject.c:149
#7  0x401ef977 in getBaseDictionary (type=0x4034d320) at ExtensionClass.c:1244
#8  0x401f0979 in initializeBaseExtensionClass (self=0x4034d320)
    at ExtensionClass.c:1485
#9  0x401f6774 in export_subclassed_type (dict=0x82d33a4, 
    name=0x40337c55 "GtkTreeViewColumn", typ=0x4034d320, bases=0x82ea9a4)
    at ExtensionClass.c:3410
#10 0x4022a360 in pygobject_register_class (dict=0x82d33a4, 
    class_name=0x40337c55 "GtkTreeViewColumn", 
    get_type=0x404c4080 <gtk_tree_view_column_get_type>, ec=0x4034d320, 
    bases=0x82ea9a4) at gobjectmodule.c:202
#11 0x4032fd7e in pygtk_register_classes (d=0x82d33a4) at gtk.c:30071
#12 0x402f0ed0 in init_gtk () at gtkmodule.c:98
#13 0x0806927c in _PyImport_LoadDynamicModule (name=0xbfffcd00 "gtk._gtk", 
    pathname=0xbfffc870 "/usr/local/lib/python2.1/site-packages/gtk/_gtkmodule.so", fp=0x82ab6e0) at ../Python/importdl.c:52
#14 0x08067780 in load_module (name=0xbfffcd00 "gtk._gtk", fp=0x82ab6e0, 
    buf=0xbfffc870 "/usr/local/lib/python2.1/site-packages/gtk/_gtkmodule.so", 
    type=3) at ../Python/import.c:1296
#15 0x080683eb in import_submodule (mod=0x82963bc, subname=0xbfffcd04 "_gtk", 
    fullname=0xbfffcd00 "gtk._gtk") at ../Python/import.c:1815
#16 0x08067f6a in load_next (mod=0x82963bc, altmod=0x80bf3cc, 
    p_name=0xbfffd130, buf=0xbfffcd00 "gtk._gtk", p_buflen=0xbfffccfc)
    at ../Python/import.c:1671
#17 0x08067bcc in import_module_ex (name=0x0, globals=0x8295f1c, 
    locals=0x8295f1c, fromlist=0x8296864) at ../Python/import.c:1522
#18 0x08067d23 in PyImport_ImportModuleEx (name=0x8290aac "_gtk", 
    globals=0x8295f1c, locals=0x8295f1c, fromlist=0x8296864)
    at ../Python/import.c:1563
#19 0x0809f4b9 in builtin___import__ (self=0x0, args=0x8291124)
    at ../Python/bltinmodule.c:31
#20 0x080591e3 in call_cfunction (func=0x80cdcf0, arg=0x8291124, kw=0x0)
    at ../Python/ceval.c:2838
#21 0x080590d5 in call_object (func=0x80cdcf0, arg=0x8291124, kw=0x0)
    at ../Python/ceval.c:2801
#22 0x08058f9c in PyEval_CallObjectWithKeywords (func=0x80cdcf0, 
    arg=0x8291124, kw=0x0) at ../Python/ceval.c:2734
#23 0x08057764 in eval_code2 (co=0x82910d0, globals=0x8295f1c, 
    locals=0x8295f1c, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, 
    defcount=0, closure=0x0) at ../Python/ceval.c:1820
#24 0x08055085 in PyEval_EvalCode (co=0x82910d0, globals=0x8295f1c, 
    locals=0x8295f1c) at ../Python/ceval.c:346
#25 0x08066a86 in PyImport_ExecCodeModuleEx (name=0xbfffe0b0 "gtk", 
    co=0x82910d0, 
    pathname=0xbfffd340 "/usr/local/lib/python2.1/site-packages/gtk/__init__.pyc") at ../Python/import.c:490
#26 0x08066fc7 in load_source_module (name=0xbfffe0b0 "gtk", 
    pathname=0xbfffd7b0 "/usr/local/lib/python2.1/site-packages/gtk/__init__.py", fp=0x80d1a20) at ../Python/import.c:754
#27 0x0806775e in load_module (name=0xbfffe0b0 "gtk", fp=0x80d1a20, 
    buf=0xbfffd7b0 "/usr/local/lib/python2.1/site-packages/gtk/__init__.py", 
    type=1) at ../Python/import.c:1287
#28 0x08067129 in load_package (name=0xbfffe0b0 "gtk", 
    pathname=0xbfffdc20 "/usr/local/lib/python2.1/site-packages/gtk")
    at ../Python/import.c:811
#29 0x08067791 in load_module (name=0xbfffe0b0 "gtk", fp=0x0, 
    buf=0xbfffdc20 "/usr/local/lib/python2.1/site-packages/gtk", type=5)
    at ../Python/import.c:1310
#30 0x080683eb in import_submodule (mod=0x80bf3cc, subname=0xbfffe0b0 "gtk", 
    fullname=0xbfffe0b0 "gtk") at ../Python/import.c:1815
#31 0x08067f6a in load_next (mod=0x80bf3cc, altmod=0x80bf3cc, 
    p_name=0xbfffe4e0, buf=0xbfffe0b0 "gtk", p_buflen=0xbfffe0ac)
    at ../Python/import.c:1671
#32 0x08067bcc in import_module_ex (name=0x0, globals=0x828c3fc, 
    locals=0x828c3fc, fromlist=0x80bf3cc) at ../Python/import.c:1522
#33 0x08067d23 in PyImport_ImportModuleEx (name=0x811556c "gtk", 
    globals=0x828c3fc, locals=0x828c3fc, fromlist=0x80bf3cc)
    at ../Python/import.c:1563
#34 0x0809f4b9 in builtin___import__ (self=0x0, args=0x829651c)
    at ../Python/bltinmodule.c:31
#35 0x080591e3 in call_cfunction (func=0x80cdcf0, arg=0x829651c, kw=0x0)
    at ../Python/ceval.c:2838
#36 0x080590d5 in call_object (func=0x80cdcf0, arg=0x829651c, kw=0x0)
    at ../Python/ceval.c:2801
#37 0x08058f9c in PyEval_CallObjectWithKeywords (func=0x80cdcf0, 
    arg=0x829651c, kw=0x0) at ../Python/ceval.c:2734
#38 0x08057764 in eval_code2 (co=0x82968b8, globals=0x828c3fc, 
    locals=0x828c3fc, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, 
    defcount=0, closure=0x0) at ../Python/ceval.c:1820
#39 0x08055085 in PyEval_EvalCode (co=0x82968b8, globals=0x828c3fc, 
    locals=0x828c3fc) at ../Python/ceval.c:346
#40 0x08066a86 in PyImport_ExecCodeModuleEx (name=0xbfffeff0 "seg", 
    co=0x82968b8, pathname=0xbfffe6f0 "seg.pyc") at ../Python/import.c:490
#41 0x08066fc7 in load_source_module (name=0xbfffeff0 "seg", 
    pathname=0xbfffeb60 "seg.py", fp=0x820cd60) at ../Python/import.c:754
#42 0x0806775e in load_module (name=0xbfffeff0 "seg", fp=0x820cd60, 
    buf=0xbfffeb60 "seg.py", type=1) at ../Python/import.c:1287
#43 0x080683eb in import_submodule (mod=0x80bf3cc, subname=0xbfffeff0 "seg", 
    fullname=0xbfffeff0 "seg") at ../Python/import.c:1815
#44 0x08067f6a in load_next (mod=0x80bf3cc, altmod=0x80bf3cc, 
    p_name=0xbffff420, buf=0xbfffeff0 "seg", p_buflen=0xbfffefec)
    at ../Python/import.c:1671
#45 0x08067bcc in import_module_ex (name=0x0, globals=0x80d21e4, 
    locals=0x80d21e4, fromlist=0x80bf3cc) at ../Python/import.c:1522
#46 0x08067d23 in PyImport_ImportModuleEx (name=0x828c61c "seg", 
    globals=0x80d21e4, locals=0x80d21e4, fromlist=0x80bf3cc)
    at ../Python/import.c:1563
#47 0x0809f4b9 in builtin___import__ (self=0x0, args=0x80e7bc4)
    at ../Python/bltinmodule.c:31
#48 0x080591e3 in call_cfunction (func=0x80cdcf0, arg=0x80e7bc4, kw=0x0)
    at ../Python/ceval.c:2838
#49 0x080590d5 in call_object (func=0x80cdcf0, arg=0x80e7bc4, kw=0x0)
    at ../Python/ceval.c:2801
#50 0x08058f9c in PyEval_CallObjectWithKeywords (func=0x80cdcf0, 
    arg=0x80e7bc4, kw=0x0) at ../Python/ceval.c:2734
#51 0x08057764 in eval_code2 (co=0x8115908, globals=0x80d21e4, 
    locals=0x80d21e4, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, 
    defcount=0, closure=0x0) at ../Python/ceval.c:1820
#52 0x08055085 in PyEval_EvalCode (co=0x8115908, globals=0x80d21e4, 
    locals=0x80d21e4) at ../Python/ceval.c:346
#53 0x0806da1f in run_node (n=0x8115558, filename=0x80a496d "<stdin>", 
    globals=0x80d21e4, locals=0x80d21e4, flags=0xbffff708)
    at ../Python/pythonrun.c:1045
#54 0x0806cb2a in PyRun_InteractiveOneFlags (fp=0x4018e620, 
    filename=0x80a496d "<stdin>", flags=0xbffff708)
    at ../Python/pythonrun.c:570
#55 0x0806c98c in PyRun_InteractiveLoopFlags (fp=0x4018e620, 
    filename=0x80a496d "<stdin>", flags=0xbffff708)
    at ../Python/pythonrun.c:510
#56 0x0806c85a in PyRun_AnyFileExFlags (fp=0x4018e620, 
    filename=0x80a496d "<stdin>", closeit=0, flags=0xbffff708)
    at ../Python/pythonrun.c:473
#57 0x08051fae in Py_Main (argc=1, argv=0xbffff78c) at ../Modules/main.c:320
#58 0x400831f0 in __libc_start_main () from /lib/libc.so.6