[Pyrex] Problem with the declaration of variable/struct containing
references to functions
Fabien Cromières
fabien.cromieres at gmail.com
Mon Sep 19 19:45:59 CEST 2005
Hello everybody.
I have been using the great tool that is pyrex for a couple of month
and I appear to have come across a limitation/bug of pyrex (or maybe
it is me that doesn't understand something).
I will be grateful if somebody is kind enough and knowledgeable enough
to tell me if it is a problem with pyrex or with me .
Basically, here is what I want to do (and don't manage to):
I would like to define a struct object that contains a field that
contains a reference to a function returning a python object.
For example, the C declaration would be something like:
typedef struct {
char c;
PyObject *(*fonc)(int,int);
} Container
(the struct container has one field containing a reference to a
function that takes two int as parameters and return a Python object)
But, when I want to declare this structure in a pyrex module, no
matter what syntax I try, it doesn't work:
Let us suppose I do:
ctypedef Container:
char c
PyObject *(*fonc)(int,int)
cdef f(int i, int j):
return [i,j]
cdef Container cont
cont.fonc=f
Then I get an error saying pyrex can't convert type PyObject *((int ))
to type PyObject (*(*)(int,int))
with :
ctypedef Container:
char c
fonc(int,int)
the fonc field is silently ignored (it doesn't appear in equivalent
struct of the generated c file) and i get an error when I do
cont.fonc=f
I also tried syntax such as
object fonc(int,int)
(*fonc)(int,int)
(PyObject *)(*fonc)(int,int)
PyObject (*fonc)(int,int)
but pyrex complains each time.
Thank you for your help.
With regards,
Fabien Crom
PS:sorry for the half message I sent a couple of minutes ago.
More information about the Pyrex
mailing list