memory violation error

Silvio Arcangeli sarcangeli at
Fri Sep 14 11:16:07 CEST 2001

It's not a problem of references to Python objects.
The only arguments it takes are a string and a CObject (containing the 
pointer for the CORBA connection, and it's a good pointer, since it's used 
by all the other functions of the API I'm embedding in Python), and they 
are referenced in the arguments tuple, so I don't think I need to take 
ownership of such references.
Anyway, to be sure the problem was not "mine" I made a test function that 
does just the following:

static PyObject * test (PyObject *unused1, PyObject *unused2){
         if (connection ok){
                 CORBAFunction(connection, other constant and valid 
parameters); // this one causes the problem
         return Py_BuildValue("s", "Ok");

This one doesn't even refer any python object, and does not take any argument.
This same code is working fine if I build it as a C application, but called 
from Python it raises a memory violation error (that is not raised if I 
comment out the line calling the CORBA function). The memory violation 
error is raised when my function is returning, not when the CORBA function 
is called.
I don't have access to the code of the CORBA function: I described this 
problem to the programmer who wrote it, but for them it's correct, since 
when tested in a C application it's working (and actually it returns all 
the correct values, and the connection is still valid after it returns).
So I was trying to understand if for example there could be some memory 
leak inside the function that does not cause a crash in a C application, 
but makes my Python extension crash. I don't have a deep knowledge of how 
Python allocates and deallocates memory when executing C functions, would 
it be possible?


At 09:57 AM 9/13/01 -0400, you wrote:
> > When I call it from Python it raises a memory violation error. I'm quite
> > sure that this problem it's caused by the API function, since if I comment
> > out the line that calls it in the extension module the error is not raised.
> > (The code of the function in the extension module is bug free for sure, it
> > doesn't do anything else than calling PyArg_ParseTuple, the API function
> > and then Py_BuildVaule.)
> > The strange thing is  that the API function seems to work fine in C, the
> > results are just the expected ones, and if I run the same code in a C
> > application no such error happens. The memory violation error happens only
> > when the function in the extension module is returning to the interpreter.
> > What could be the cause?
>Well, I'm guessing blind here, but I'd say it's because you borrow a reference
>in the C-side and forget to increment its reference count, and in the
>Python-side the reference disappers and so your C code is using an invalid
>memory location.

More information about the Python-list mailing list