Hi,

It seems there is a problem when attempting to access C members of an
extension type in special methods, such as __mul__ :

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
cdef extern from "btQuaternion.h":
    cdef cppclass btQuaternion:
        btQuaternion(float, float, float, float)
        btQuaternion operator*(float)
        float x()
        float y()
        float z()
        float w()


cdef class Quaternion:

    cdef btQuaternion *wrapped

    def __init__(self, x, y, z, w):
        self.wrapped = new btQuaternion(x, y, z, w)

    def __dealloc__(self):
        del self.wrapped

    def __mul__(self, float other):
        return from_c_obj(self.wrapped[0] * other) # Cannot convert
                                                   # Python object to
                                                   # 'btQuaternion'


cdef from_c_obj(btQuaternion quat):
    """
    Construct a Quaternion instance from its C++ counterpart.
    """
    return Quaternion(quat.x(), quat.y(), quat.z(), quat.w())
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

Changing this code to something like :

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
    def __mul(self, float other):
        return from_c_obj(self.wrapped[0] * other)

    def __mul__(self, float other):
        return self.__mul(other)
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

Gives no error, and the code works as expected (all of this was tested
on the latest dev branch).

Cheers,
-- 
Lup
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to