On Apr 27, 2009, at 7:35 PM, Danilo Freitas wrote:

> 2009/4/27 Robert Bradshaw <[email protected]>:
>> On Apr 27, 2009, at 6:08 PM, Greg Ewing wrote:
>>
>>> Robert Bradshaw wrote:
>>>
>>>> That's because x[0] was always the same thing as (*x), even if a  
>>>> bit
>>>> uglier. I'm not not as enthusiastic about it now (though not yet  
>>>> for
>>>> sure set against it either...)
>>>
>>> The reason for not having a * operator in Pyrex was to
>>> avoid possible ambiguities when parsing arguments to
>>> function calls (since Python already assigns a meaning
>>> to prefix * in that context).
>>>
>>> If you want to introduce a * operator you'll have to
>>> deal with that somehow.
>>
>> Nice to know the original reasoning. Well, that's another strike
>> against it, and in this case "two strikes you're out" is enough  
>> for me.
>>
> So, we should really use deref()?

Yes, I think so.

We could declare

cdef extern from "foo.h":
     cclass Foo:  # or whatever else we come up with here
         Foo __add__(Foo, Foo)
         Foo __add__(Foo, int)
         int __dereference__(Foo)
         Foo __increment__(Foo)
         ...

This would indicate that Foo supports addition with other Foos and  
ints, incrementing, and that cython.deref(Foo) is an int. The magic  
cython.deref method would see if a __dereference__ method is  
declared, and if not would allow the default behavior for pointer  
types, otherwise raising an error. An actual (*x) would be emitted in  
the code. Likewise with increment/decrement.

- Robert


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

Reply via email to