[PYTHON MATRIX-SIG] C API questions
Konrad Hinsen
hinsen@ibs.ibs.fr
Tue, 5 Nov 96 19:45:02 +0100
> The one part about this discussion I didn't follow was the part about trying
> to make sure Python does not keep a reference to your compiled object. That
> is probably impossible what with traceback stacks and all. Or maybe I didn't
> get it.
But the traceback stack does not keep its references forever, I hope.
Is there maybe a way to force it to give up a certain reference?
> If you do use PyArray_FromDimsAndData you should just follow the normal
> Python rules for reference counting in your extensions and since the count
> started out at 1 it will never get deleted. But if the pointer points to
> something that might not be there later, this is the wrong Python object to
> model it, IMHO.
But what other choice do I have? I want to define a general C-level
interface to some of my code, which might actually be Python code.
So I must construct a C wrapper around the Python functions. But a
C function can't make any assumptions about the existence of its
actual parameters after it returns. It might look like:
double *x = malloc(n*sizeof(double));
do_some_calculation(x, n);
free(x);
with
void do_some_calculation(double *x, int n)
{
PyArrayObject *a = PyArray_FromDimsAndData(.., x, n, ..);
/* call Python function working on a */
}
In that case I must make sure that no access to the memory pointed
to by x can occur after my C wrapper exits.
Konrad.
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire | Tel.: +33-76.88.99.28
Institut de Biologie Structurale | Fax: +33-76.88.54.94
41, av. des Martyrs | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France | Nederlands/Francais
-------------------------------------------------------------------------------
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================