return (PyObject*)myPyType; ...segmentation fault!

E

elho

I called a own python type 'PyType' with a c function and returned it
into my python programm - there it fault.
It is said that the object has a NULL-Pointer when I try to debug it?

Here are the importent snips from my code:


// == test.py =========================================================
..
:
myNewPyType = PyMyExtention.GetValue ("xxx")
# printings for testing
print "...back to python... test.py"
print "pp\t ...PyMyType.PyMyObject:", type(tySdlXml)
//===================================================================/


// == PyMyExtention.c =================================================
..
:
static PyObject* wrap_GetValue (PyObject* self, PyObject* args)
{
char* pchXXX;
if (!PyArg_ParseTuple(args, "s", &pchXXX))
{
return 0;
}

long llong = CFunktion::CallMe(pchXXX);

// returning Python-Objekt
PyObject *pyType = PyMyObject_NewC (llong);
cout << "cc ..." << ((PyMyType*)pyType)->lAttribute << endl;
cout << "\t ...proof object-valid pointer?" << (void*)pyType << endl;
return (PyObject*)pyType;
}
..
:
//===================================================================/


// == PyMyExtention.c =================================================
..
:
typedef struct {
PyObject_HEAD
long lAttribute;
} PyMyObject;

static PyObject* PyMyObject_NewC (long lAttribute)
{
PySDLXMLNode *self;
PySDLXMLNode *type;

self = new PySDLXMLNode;
self->lAttribute = lAttribute;

return (PyObject*)self;
}

static PyMethodDef PyMyObject_methods[] = {
{"PyMyObject_NewC", (PyCFunction)PyMyObject_NewC, METH_NOARGS,
"Create PyMyObject_NewC from C-Code"},
{NULL} /* Sentinel */
};

:

static PyTypeObject PySDLXMLNodeType = {
PyObject_HEAD_INIT(NULL)
:
};
//===================================================================/


// ::: output ::::::::::::::::::::::::::::::::::::::::::::::::::::

cc ...135603272
t ...proof object-valid pointer?: 0x8165940
....back to python... test.py
Segmentation fault

//===================================================================/


....you see: It returns to python but over there the object is something
bad. So what is wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top