didier deshommes wrote:
> On Thu, Sep 4, 2008 at 9:21 AM, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>> didier deshommes wrote:
>> Would you have a code example that shows your problem?
>
> Here's the simplest example I could compile:
> {{{
> cdef class T:
> cdef int i
> #cdef c_struct
> def __cinit__(self):
> cdef char char_name = '2'
> cdef int int_name
> cdef bint bint_name
> print 1
>
> }}}
>
> Looking at the generated cpp file, around the corresponding __cinit__,
> I see char_name, (mangled as pyx_v_char_name), but no sign of mangled
> versions of int_name or bint_name. The cpp file also shows which lines
> are being executed and seems to be skipping lines where variables are
> declared.
Right.. this is resource acquisition on initialization? Unfortunately
the C++ support of Cython is probably too weak for that (I'm assuming
that using a global cdef variable won't really work either for your
usecase, otherwise just do that).
What you can do is create a header file like this:
#define setup_func_context() MyInitializerClass __var
i.e. turn it into a call using a macro, and then call that function from
Cython:
cdef extern from "myheader.h":
void setup_func_context()
cdef class T:
def __cinit__(self):
setup_func_context()
.... do stuff ...
Of course it is rather obscure as that function call makes something
happen when you exit the function as well, but it should work. You can
always make modifications (pass in the variable name to use, create
accessor macros to get hold of the variable etc.) to make it work for you.
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev