Setting a C-structure from Python

Benoit Dupire bdupire at seatech.fau.edu
Sat Jul 8 23:52:44 EDT 2000


I think I find out where the bug was.
Thanks Armin !

Why this C extension didn't work ?

>
>  static PyObject * test_setstruct(PyObject * self, PyObject * args) {
>  PyObject * string_from_python;
>
>  if (!PyArg_ParseTuple(args,"S",&string_from_python)) return NULL;
>
>  example= (examplestruct *) PyString_AsString(string_from_python);
> Py_DECREF(string_from_python);
>  print_struct();
>
>  Py_INCREF(Py_None);
>  return Py_None;
>  }

Simply because the  "example"  pointer  points to memory owned by
string_from_python
it point to internal data which is actually part of the string object.
When I "decref "   string_from_python, its reference counter becomes 0, and
the string object is deleted.
So  "example" points to something wrong in memory.


thank you again
Benoit.






More information about the Python-list mailing list