Embedding: Creating / Deleting CObjects?!

Bjoern Giesler un4e at rz.uni-karlsruhe.de
Tue Jul 20 17:18:03 EDT 1999


Hi,

I'm truly baffled. I'm trying to define a backend for my embedded Python
system, and the corresponding C routines seem to work, but the program
crashes somewhere in the Python library routines, dances the Fandango all
over my internal object representation, and whatnot. 

I'm posting a couple of fragments of my code, just so that somebody can tell
me whether this is the canonical way of handling things (this side of Python
is not exactly well documented...) 

/* Content destructor function */
static void
PLPythonDestructor(proplist_t obj)
{
  PLRelease(obj);
}

/* CObject Creator */
static PyObject *
PLPythonNewInstance(PyObject *self, PyObject *args)
{
  proplist_t plClassName, plArgs;
  instance_t instance;
  char *className;
  PyObject *pyArgs, *retval;

  printf("NewInstanceVar\n");

  if(!PyArg_ParseTuple(args, "sO", &className, &pyArgs))
    return NULL;

  plArgs = PLPy2PLObject(pyArgs); /* NULL is OK here */
  plClassName = PLMakeString(className);
  instance = PLObjectNewInstance(plClassName, plArgs); /* [My own braindead
							  class system.
							  Works, though.] */
  if(plClassName)
    PLRelease(plClassName);
  if(plArgs)
    PLRelease(plArgs);

  if(!instance)
    {
      PyErr_SetString(PyExc_RuntimeError, "Couldn't create new instance");
      return NULL;
    }
  retval = PyCObject_FromVoidPtr((void *)instance,
				 PLPythonDestructor);
  Py_INCREF(retval);
  return retval;
}

/* CObject Destructor */
static PyObject *
PLPythonDeleteInstance(PyObject *self, PyObject *args)
{
  instance_t instance;
  PyObject *instanceObject;

  printf("DeleteInstance\n");

  if(!PyArg_ParseTuple(args, "O", &instanceObject))
    return NULL;

  /*
  instance = (instance_t) PyCObject_AsVoidPtr(instanceObject);
  PLObjectDeleteInstance(instance);
  */

  Py_XDECREF(instanceObject);
  return Py_None;
}

If anything about the above code remains unclear, please ask. I WANT to get
this stuff to work!

TIA,
		--Bjoern
-- 
--------------------------------/\--One OS to rule them all---Windows NT-----
Bjoern Giesler                 /  \  One OS to find them           
<un4e at rz.uni-karlsruhe.de>    / <> \  One OS to bring them all    
-----------------------------/______\--And in the Darkness bind them---------
    Thank you for your time, worship the Antichrist, and have a nice day.




More information about the Python-list mailing list