467,074 Members | 939 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

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

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?
Sep 30 '05 #1
  • viewed: 1052
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by jeko | last post: by
2 posts views Thread by Rolf Wester | last post: by
5 posts views Thread by Fra-it | last post: by
1 post views Thread by Kirill Simonov | last post: by
27 posts views Thread by Paminu | last post: by
4 posts views Thread by Luke Miller | last post: by
6 posts views Thread by DanielJohnson | last post: by
8 posts views Thread by Andrea | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.