[cable] generated python wrapper signals EXC_BAD_ACCESS on MacOSX

Kaben Nanlohy k_cable.public.kitware.com at random.poofygoof.com
Mon Feb 9 17:28:08 EST 2004


Hi;

I hope that others have used CableSwig on Apple's Panther, and can share
some advice with me : I'm struggling with the 'Module' example (at
Utilities/CableSwig/Testing/Module beneath the Insight root) wrapped for
python with CableSwig/Python2.3(fink).

(Early warning and apology : I hope that I'm giving sufficient
information below, but I'm probably giving too much.)

I'm not using or building the example within the Insight project -- I've
copied the example as a test case into my own project (which builds
happily using CMake), where the example builds without problems. Here is
what I see when I try to use the imported module:


$ python2.3         
Python 2.3.3 (#1, Dec 29 2003, 09:45:44) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from TestModule import *
>>> dir()
['__builtins__', '__doc__', '__file__', '__name__', 'bar', 'barPtr', 'foo', 'fooPtr', 'types']
>>> b=bar()
Bus error
$ 


Running python2.3 from gdb (this may not be a good way to debug -- I am no
python expert), I see:


>>> b=bar()

Program received signal EXC_BAD_ACCESS, Could not access memory.
PyErr_Occurred () at Python/errors.c:81
81      Python/errors.c: No such file or directory.
        in Python/errors.c
(gdb) bt           
#0  PyErr_Occurred () at Python/errors.c:81
#1  0x013497f4 in PyObject_Call (func=0x1442af0, arg=0x0, kw=0x13497f4) at Objects/abstract.c:1756
#2  0x013b2358 in PyEval_CallObjectWithKeywords (func=0x614cb0, arg=0x706030, kw=0x0) at Python/ceval.c:3346
#3  0x005516b0 in SWIG_NewPointerObj (ptr=0x0, type=0x0, own=0) at /Users/kaben/Projects/software/avida/branch.kaben/build/cableswig_example/SwigRuntime/swigrunPython.cc:589
#4  0x005204c8 in _wrap_new_bar__SWIG_1(_object*, _object*) (self=0x0, args=0x31e030) at /Users/kaben/Projects/software/avida/branch.kaben/build/cableswig_example/Module/barPython.cc:760
#5  0x005205a4 in _wrap_new_bar(_object*, _object*) (self=0x0, args=0x31e030) at /Users/kaben/Projects/software/avida/branch.kaben/build/cableswig_example/Module/barPython.cc:778
#6  0x0002235c in PyObject_Call (func=0x1442af0, arg=0x0, kw=0x13497f4) at Objects/abstract.c:1755
.
.
.
#30 0x000039d4 in start ()


The problem seems to begin in the CableSwig-generated function
SWIG_NewPointerObj() in cableswig_example/SwigRuntime/swigrunPython.cc, where
the relevant lines read:


     /* Create a new pointer object */
565: SWIGRUNTIME(PyObject *)
     SWIG_NewPointerObj(void *ptr, swig_type_info *type, int own) {
       PyObject *robj;
       if (!ptr) {
         Py_INCREF(Py_None);
570:     return Py_None;
       } 
     #ifdef SWIG_COBJECT_TYPES
       robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, (char *) type->name, NULL);                                                     #else
575:   {
         char result[1024];
         char *r = result;
         *(r++) = '_'; 
         r = SWIG_PackData(r,&ptr,sizeof(void *));
580:     strcpy(r,type->name);
         robj = PyString_FromString(result);
       }
     #endif
       if (!robj || (robj == Py_None)) return robj;
585:   if (type->clientdata) {
         PyObject *inst;
         PyObject *args = Py_BuildValue((char*)"(O)", robj);
         Py_DECREF(robj);
         inst = PyObject_CallObject((PyObject *) type->clientdata, args);
590:     Py_DECREF(args);
         if (inst) {
           if (own) {
             PyObject *n = PyInt_FromLong(1);
             PyObject_SetAttrString(inst,(char*)"thisown",n);
595:         Py_DECREF(n);
           }
           robj = inst;
         }
       } 
600:   return robj;
     } 


During a break at the pertinent line 589 I find:


Breakpoint 1, SWIG_NewPointerObj (ptr=0x613de0, type=0x528054, own=1) at /Users/kaben/Projects/software/avida/branch.kaben/build/cableswig_example/SwigRuntime/swigrunPython.cc:589
589         inst = PyObject_CallObject((PyObject *) type->clientdata, args);
(gdb) p type       
$1 = (swig_type_info *) 0x528054
(gdb) p type->clientdata
$2 = (void *) 0x614bc0
(gdb) p args
$3 = (PyObject *) 0x706030
(gdb) p *args
$4 = {
  ob_refcnt = 1, 
  ob_type = 0x1432d88
}
(gdb) p *args->ob_type
$5 = {
  ob_refcnt = 1, 
  ob_type = 0x1433140, 
  ob_size = 0, 
  tp_name = 0x141e024 "tuple", 
  tp_basicsize = 12, 
  tp_itemsize = 4, 
  tp_dealloc = 0x13848f0 <tupledealloc>, 
  tp_print = 0x1384a60 <tupleprint>, 
  tp_getattr = 0, 
  tp_setattr = 0, 
  tp_compare = 0, 
  tp_repr = 0x1384b24 <tuplerepr>, 
  tp_as_number = 0x0, 
  tp_as_sequence = 0x1432d34, 
  tp_as_mapping = 0x1432d7c, 
  tp_hash = 0x1384ce0 <tuplehash>, 
  tp_call = 0, 
  tp_str = 0, 
  tp_getattro = 0x1377e78 <PyObject_GenericGetAttr>, 
  tp_setattro = 0, 
  tp_as_buffer = 0x0, 
  tp_flags = 17899, 
  tp_doc = 0x1432c9c "tuple() -> an empty tuple\ntuple(sequence) -> tuple initialized from sequence's items\n\nIf the argument is a tuple, the return value is the same object.", 
  tp_traverse = 0x13851c8 <tupletraverse>, 
  tp_clear = 0, 
  tp_richcompare = 0x1385240 <tuplerichcompare>, 
  tp_weaklistoffset = 0, 
  tp_iter = 0x138583c <tuple_iter>, 
  tp_iternext = 0, 
  tp_methods = 0x1432d5c, 
  tp_members = 0x0, 
  tp_getset = 0x0, 
  tp_base = 0x0, 
  tp_dict = 0x0, 
  tp_descr_get = 0, 
  tp_descr_set = 0, 
  tp_dictoffset = 0, 
  tp_init = 0, 
  tp_alloc = 0, 
  tp_new = 0x1385460 <tuple_new>, 
  tp_free = 0x13f1a28 <PyObject_GC_Del>, 
  tp_is_gc = 0, 
  tp_bases = 0x0, 
  tp_mro = 0x0, 
  tp_cache = 0x0, 
  tp_subclasses = 0x0, 
  tp_weaklist = 0x0, 
  tp_del = 0
}


Thus on this side of PyObject_CallObject(), the variables 'type' and
'args' seem to have valid data. I suppose that PyObject_CallObject is a
macro to PyEval_CallObjectWithKeywords, but I'm not sure. In any case,
on the far side of PyEval_CallObjectWithKeywords() something has been
clobbered.

Since this is the limit of my knowledge, I thought I'd seek help before
I start researching the innards of Python and CableSwig.

I should note that the same thing happens when I try to instantiate my
own hello-world example wrapping, but that, when I use cswig in
swig-compatible mode to wrap my hello-world, instantiation works fine.

***

Okay. I hope you aren't overloaded by the length of this email. Any
thoughts / help are appreciated.


-- Kaben




More information about the cable mailing list