trouble when calling with FFI

Help
2008-02-03
2013-06-13
  • Andrew Straw

    Andrew Straw - 2008-02-03

    Hi, I am trying to use BuGLe with pyglet, a Python-based games library. (pyglet uses ctypes to access OpenGL. ctypes is a python extension that uses libffi - "Foreign Function Interface" - to allow pure-Python code to call into shared libraries.) Anyhow, I get a segfault when trying to run in this scenario. Unfortunately, I don't have the time at the moment to dig deeper, but here's a printout from my console. I hope this is useful in debugging the issue (this is with version 20080123).

    astraw@h2:~/other-peoples-src/pyglet/pyglet-1.0/examples$ BUGLE_CHAIN=trace LD_PRELOAD=libbugle.so gdb /home/astraw/py2.5-linux-x86_64/bin/python
    GNU gdb 6.6-debian
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu"...
    (no debugging symbols found)
    Using host libthread_db library "/lib/libthread_db.so.1".
    (gdb) run opengl.py
    Starting program: /home/astraw/py2.5-linux-x86_64/bin/python opengl.py
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    [Thread debugging using libthread_db enabled]
    [New Thread 47411590986992 (LWP 28500)]
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    ---Type <return> to continue, or q <return> to quit---
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 47411590986992 (LWP 28500)]
    0x00002b1edc2b1b20 in bugle_count_glx_attributes () from /usr/lib/libbugle.so
    (gdb) bt
    #0  0x00002b1edc2b1b20 in bugle_count_glx_attributes () from /usr/lib/libbugle.so
    #1  0x00002b1edc2c2b7c in budgie_call_parameter_dump () from /usr/lib/libbugle.so
    #2  0x00002b1edc2c2c8d in budgie_dump_any_call () from /usr/lib/libbugle.so
    #3  0x00002b1edc2c0729 in bugle_log_callback () from /usr/lib/libbugle.so
    #4  0x00002aaaaf267196 in ?? () from /usr/lib/bugle/trace.so
    #5  0x00002b1edc2b8cb4 in ?? () from /usr/lib/libbugle.so
    #6  0x00002b1edc2c87a2 in glXCreateWindow () from /usr/lib/libbugle.so
    #7  0x00002aaaaf986b2c in ffi_call_unix64 () from /usr/lib/python2.5/lib-dynload/_ctypes.so
    #8  0x00002aaaaf9869b5 in ffi_call () from /usr/lib/python2.5/lib-dynload/_ctypes.so
    #9  0x00002aaaaf981e7a in _CallProc (pProc=0x2b1edc2c86f0 <glXCreateWindow>, argtuple=<value optimized out>, flags=<value optimized out>, argtypes=0xe2c3c0, restype=0x8cc360, checker=0x0)
        at /build/buildd/python2.5-2.5.1/Modules/_ctypes/callproc.c:668
    #10 0x00002aaaaf97ba40 in CFuncPtr_call (self=0xe2d500, inargs=0x4, kwds=0x0) at /build/buildd/python2.5-2.5.1/Modules/_ctypes/_ctypes.c:3362
    #11 0x0000000000417e53 in PyObject_Call ()
    #12 0x0000000000483f12 in PyEval_EvalFrameEx ()
    #13 0x0000000000488c3e in PyEval_EvalFrameEx ()
    #14 0x0000000000488c3e in PyEval_EvalFrameEx ()
    #15 0x0000000000489d60 in PyEval_EvalCodeEx ()
    #16 0x00000000004d431c in ?? ()
    #17 0x0000000000417e53 in PyObject_Call ()
    #18 0x0000000000486997 in PyEval_EvalFrameEx ()
    #19 0x0000000000489d60 in PyEval_EvalCodeEx ()
    #20 0x00000000004d431c in ?? ()
    #21 0x0000000000417e53 in PyObject_Call ()
    #22 0x000000000041e5ed in ?? ()
    #23 0x0000000000417e53 in PyObject_Call ()
    #24 0x000000000045a3b8 in ?? ()
    #25 0x000000000045d2b2 in ?? ()
    #26 0x0000000000417e53 in PyObject_Call ()
    #27 0x0000000000483f12 in PyEval_EvalFrameEx ()
    #28 0x0000000000489d60 in PyEval_EvalCodeEx ()
    #29 0x0000000000489da2 in PyEval_EvalCode ()
    #30 0x00000000004ab4fe in PyRun_FileExFlags ()
    #31 0x00000000004ab790 in PyRun_SimpleFileExFlags ()
    #32 0x0000000000414725 in Py_Main ()
    #33 0x00002b1edce52b44 in __libc_start_main () from /lib/libc.so.6
    #34 0x0000000000413c69 in _start ()
    (gdb)

     
    • Bruce Merry

      Bruce Merry - 2008-02-04

      Thanks. I've just started a new job today, so it'll be this weekend at the very earliest that I can look at this, and possibly not even then. I've seen a similar bug before, and the problem is generally that bugle doesn't find the terminating None (that's an X None == 0, not a Python None) in the list of attributes passed to glX. That could be the callers fault (passing an incorrectly terminated list), or it could be that my passing code is whacked (been a while since I messed with that, so I can't remember if that list is just a list of pairs or if it needs some interpretation to avoid walking off the end).

      If you do find out more (should be easy enough to step through bugle_glx_count_attributes and examine the parameters) let me know.

       
    • Bruce Merry

      Bruce Merry - 2008-02-09

      Hi

      I've had a look at the spec and found a few bugs in my code. Try the patch below and let me know if it helps (the patch to ChangeLog might not apply, but that's hardly important).

      Bruce

      Index: bc/glx.bc

      --- bc/glx.bc    (revision 537)
      +++ bc/glx.bc    (revision 538)
      @@ -7,7 +7,7 @@
      TYPE PARAMETER glXQueryExtension -1 TYPE_5XBool
      TYPE PARAMETER glXQueryVersion -1 TYPE_5XBool

      -LENGTH PARAMETER glXChooseVisual 2 bugle_count_glx_attributes($$)
      +LENGTH PARAMETER glXChooseVisual 2 bugle_count_glXChooseVisual_attributes($$)
      LENGTH PARAMETER glXCreate(Window|Pixmap) 3 bugle_count_glx_attributes($$)
      LENGTH PARAMETER glXCreatePbuffer 2 bugle_count_glx_attributes($$)
      LENGTH PARAMETER glXGetFBConfigs -1 ($$ ? *$2 : 0)
      Index: src/gldump.c
      ===================================================================
      --- src/gldump.c    (revision 537)
      +++ src/gldump.c    (revision 538)
      @@ -559,6 +559,28 @@
      int bugle_count_glx_attributes(const int *attr)
      {
           int i = 0;
      +    if (!attr) return 0;
           while (attr[i]) i += 2;
           return i + 1;
      }
      +
      +int bugle_count_glXChooseVisual_attributes(const int *attr)
      +{
      +    int i = 0;
      +    if (!attr) return 0;
      +    while (attr[i])
      +    {
      +        switch (attr[i])
      +        {
      +        case GLX_USE_GL:
      +        case GLX_RGBA:
      +        case GLX_DOUBLEBUFFER:
      +        case GLX_STEREO:
      +            i++;
      +            break;
      +        default:
      +            i += 2;
      +        }
      +    }
      +    return i + 1;
      +}
      Index: include/bugle/gldump.h
      ===================================================================
      --- include/bugle/gldump.h    (revision 537)
      +++ include/bugle/gldump.h    (revision 538)
      @@ -72,4 +72,10 @@
        * by None.
        */
      int bugle_count_glx_attributes(const int *attr);
      +
      +/* Similar, but for glXChooseVisual for which boolean attributes are not
      + * followed by a value.
      + */
      +int bugle_count_glXChooseVisual_attributes(const int *attr);
      +
      #endif /* !BUGLE_SRC_GLDUMP_H */
      Index: ChangeLog
      ===================================================================
      --- ChangeLog    (revision 537)
      +++ ChangeLog    (revision 538)
      @@ -1,5 +1,6 @@
      * Fix BUGLE_GL_HAS_EXTENSION_GROUP
      * Make PBO test run with a larger choice of extensions
      +* Fix crash when tracing glXChooseVisual

      0.0.20080123
      ------------

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks