Hallo.
I am working on python bindings for the SDIF library (sdif stands for
sound description interchange format) via Cython.
I am creating a class in cython which should wrap a C-struct called
SdifMatrixDataT. Instances of this class can be created either
internally in Cython or in Python. When creating them in Cython I would
like to have either a constructor or a class method, so that I can write
code like
cdef SdifMatrixDataT *m = SdifFReadMatrixData(sdif_file)
return Matrix(m)
where Matrix should be:
cdef class Matrix:
cdef SdifMatrixDataT *this
def __cinit__(self, SdifMatrixDataT *matrix):
self.this = matrix
but Cython does not allow that, complaining that it cannot convert m to
a python object. It does not allow also for cdefs methods to be
classmethods or staticmethods.
The only way around was to create a c function outside of this class to
instantiate the Matrix:
cdef Matrix Matrix_new(SdifMatrixDataT *matrix):
cdef Matrix m = Matrix()
m.this = matrix
return m
This works but it is not so elegant.
Am I overseeing something obvious or is there no other way around this?
best,
eduardo
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev