pygobject_new segfault

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

pygobject_new segfault

Manne Tallmarken
Helly guys,

I am trying to run a simple test program, however, it segfaults:

#include <stdio.h>
#include <gtk/gtk.h>
#include <pygobject.h>

int main(int argc, char **argv)
{
    gdk_init(&argc, &argv);
   
    GtkWidget *test = gtk_button_new();

    PyObject *p = pygobject_new ((GObject *) test);

    printf("%p\n", p);

    return 0;
}

$ gcc -std=c99 -Wall `pkg-config --cflags --libs gtk+-2.0` -I/usr/include/python2.7 -I/usr/include/pygtk-2.0 -o debug debug.c && ./debug
zsh: segmentation fault  ./debug

If I remove the line containing pygobject_new it works. What am I doing wrong?

$ uname -a
Linux helix 3.0.0-1-amd64 #1 SMP Sat Aug 27 16:21:11 UTC 2011 x86_64 GNU/Linux

$ cat /etc/issue
Debian GNU/Linux wheezy/sid

$ dpkg -l python2.7-dev|grep python                
ii  python2.7-dev                         2.7.3~rc2-2.1                   Header files and a static library for Python (v2.7)

$ dpkg -l python-gobject-2-dev|grep python
ii  python-gobject-2-dev                  2.28.6-10                    development headers for the static GObject Python bindings

Best regards,
Manne Tallmarken
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Reply | Threaded
Open this post in threaded view
|

Re: pygobject_new segfault

Hrvoje Niksic-2
You need to call pygobject_init(-1, -1, -1) before using pygobject.  You
also need to call Py_Initialize().  Also, since you're using gtk, and
not just gdk, you should call gtk_init().

With the first three lines of main() changed to:

     gdk_init(&argc, &argv);
     Py_Initialize();
     pygobject_init(-1, -1, -1);

and with -lpython2.7 added to the compilation line, the test program no
longer segfaults on startup.
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/