Ondrej Certik, 17.02.2009 05:26:
> I have the following class:
>
> cdef class H1Space:
>
> def __init__(self, Mesh m, H1Shapeset s):
> self.thisptr = new_H1Space(m.thisptr, s.thisptr)
>
> and it is initialized from 2 other classes. Sometimes however, I would
> like to initialize it directly from a C++ instance of c_H1Space, e.g.
> I would like to create the H1Space class *without* calling it's
> constructor and just set the self.thisptr object to the C++ instance.
>
> Currently I am using the following code and everything works for me:
>
> cdef H1Space H1Space_from_c_H1Space(c_H1Space *h):
> cdef H1Space n
> n =<H1Space>PY_NEW(H1Space)
> n.thisptr = h
> return n
>
> But it uses the PY_NEW macro:
>
> #define PY_NEW(zzz_type) \
> (((PyTypeObject*)(zzz_type))->tp_new((PyTypeObject*)(zzz_type),
> global_empty_tuple, NULL))
>
> and global_empty_tuple() that I had to initialize, etc. I copied this
> from Sage. Is there some better way to do the above, so that I don't
> have to include the special macro above and the corresponding .h and
> .c files in my project?
This should work with the latest Cython:
cdef H1Space n = H1Space.__new__(H1Space)
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev