I believe you are right, it seems a bug, I'v experienced this in the
past, and there and used this fixes
cdef class myTest
def __add__(myTest self, other): # note declaration: myTest self
return self.thisPtr.add(other)
You should go on with this, It should even work when this get fixed
(in the case this is actually a bug and I'm not missing somethig)
So rename your 'plus' and 'call' to standard __add__ and __call__ with
the declaration trick above, and all should just work.
Regards,
On 5/9/08, Jan Strube <[EMAIL PROTECTED]> wrote:
>
> Hi List,
> sorry for the crosspost, I have also asked the question here
> https://answers.launchpad.net/cython/+question/31930, but
> probably the list is a better place to ask.
>
>
> In the new version of Cython I am excited to report that overloading
> operators seems to work just fine. This is great, because in the high energy
> physics community, people think it's a good idea to abuse the () operator
> for iterators to mean next (among other nonsense).
>
> So I have a short class in C++, the code is below, and as posted, everything
> works fine.
> However, when I try to change "def add(self)" to "def __add__(self)" in
> myTest I get complaints of the sort
>
> File "test.py", line 37, in <module>
> print test + 3
> File "stdMatrix.pyx", line 67, in stdMatrix.myTest.__add__
> (stdMatrix.cpp:452)
> return self.thisPtr.add(<int>other)
> AttributeError: 'stdMatrix.myTest' object has no attribute 'thisPtr'
>
> I find this quite surprising, and could use some enlightenment. I can easily
> enough work around this, but this is a bug, no?
>
> Thanks for cython and best of luck on your sprint.
> Best,
> Jan
>
> ------------ class_operators.cc ---------------
> class TEST
> {
> public:
> int x;
> TEST(int y) {x=y;}
> int operator() () {x = 17; return x;}
> int operator+(int y) {return x+y;}
> int minimize() {return 25;}
> };
> ----------------------------------------------------------
>
> ------stdMatrix.pyx----------------------------------------
> cdef extern from "class_operators.cc":
> ctypedef struct monkey "TEST":
> int x
> int (*minimize)()
> int add "operator+"(int y)
> int call "operator()"()
> monkey* new_Test "new TEST"(int y)
> void del_Test "delete"(monkey* x)
>
> cdef class myTest:
> cdef monkey *thisPtr
> def __cinit__(self, int y):
> self.thisPtr = new_Test(y)
> def __dealloc__(self):
> del_Test(self.thisPtr)
> def min(self):
> return self.thisPtr.minimize()
> def plus(self, other):
> return self.thisPtr.add(other)
> def call(self):
> return self.thisPtr.call()
> --------------------------------------------------------------------
>
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
>
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev