2

I am running OSX Lion and trying to import the python module for goocanvas, using python2.7.

I managed to successfully compile pygoocanvas-0.14.1, but when I try to import goocanvas through the python2.7 console, I get a segfault. After some debugging, I'm led to this code:

DL_EXPORT (void)
initgoocanvas (void)
{
    PyObject *m, *d;
    fprintf(stderr,"init<< \n");

//    Pycairo_IMPORT; // XXX removed, it expands to the line below, anyways
    Pycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import("cairo", "CAPI"); // ADDED XXX

    fprintf(stderr,"after import<< \n");
    if (Pycairo_CAPI == NULL) {
        return;
    }

I discovered that the segfault happens when the C++ code of the goocanvas python module tries to import the "cairo" library through PyCObject_Import("cairo", "CAPI"). However, if I try to import the cairo module directly through the python2.7 console via import cairo, it works.

How should I proceed? I have a blind seg fault and no idea on why it happens. Remembering that I managed to compile the python goocanvas module, but it segfaults upon trying to import it on python.

Jason Sundram
  • 12,225
  • 19
  • 71
  • 86
FernandoH
  • 855
  • 1
  • 9
  • 17

1 Answers1

1

What kind of console are you using? I think gtk/glib has some hooks to enable running the main loop concurrently with the REPL. This means that threads are in use, which may cause crashes if glib.threads_init() was not called.

IMHO this is broken by design, because by just importing glib or any g* module a sane Python program that uses any threads will suddenly start to segfault. Supporting threading should be the default.

In our case, the crash was caused by the logging system of glib which was forwarded to Python without holding the GIL.

Bluehorn
  • 2,956
  • 2
  • 22
  • 29