[C++-sig] Incref / Decref Question

Michael Wieher michael.wieher at gmail.com
Tue May 27 19:17:30 CEST 2008


OK.  Same problem for the last week.  Not boost-related but rather
Python Extension / C C++ fundamental issue.
Please tell me if this looks OK or if its terribly, terribly stupid.

mainfile.cpp
----------------------------------------------------------------------------------
myClass instanceOfMyClass;               //----global data structure,
accessible to all functions

PyObject * function() {
    modifies, initliaizes, mallocs, etc. "instanceOfMyClass"
}

---------------------------------------------------------------------------------

That is the entire program.

It executes fine, if I call it from within python.py script, but if I
load the library.so into python interpreter >>> on exit, the
interpreter seg-faults.
Python 2.4.3 (#1, Mar 14 2007, 18:51:08)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymem
>>> pymem.initData()
0
>>>
Segmentation fault

(checking log-files I can be sure that all functionality is OK, and it
is executing correctly)

this is being run on a CentOS platform.
on Ubuntu, there is no seg-fault, and all else  is the same.

However, when Valgrind reviews the library (on both CentOS and Ubuntu)
I get the same message:
$>valgrind ./pymem.so
==5844== Process terminating with default action of signal 11 (SIGSEGV)
==5844==  Bad permissions for mapped region at address 0x38156080
==5844==    at 0x1: (within /home/michael/proj/pydata/src/pymem.so)

Now, I see this as a memory-address issue, which seems ridiculous to
me, since the library.so is compiled with -fPIC, thus removing it from
conflicting memory issues.

So, my logical conclusion is that somehow, when this global-instance
is modified, a reference-count is either incremented or decremented
incorrectly, and that when the python interpreter exits, it seg-faults
because it is either trying to clean up something that does not exist,
or thinking something doesn't exist when it does.

Any tips or ideas how to further debug this?



More information about the Cplusplus-sig mailing list