[Cython] C++ STL iteration bugs

Stefan Behnel stefan_ml at behnel.de
Sun Aug 12 08:58:56 CEST 2012


Robert Bradshaw, 12.08.2012 07:12:
> On Sat, Aug 11, 2012 at 10:03 PM, Robert Bradshaw wrote:
>> On Sat, Aug 11, 2012 at 1:19 PM, Stefan Behnel wrote:
>>> I ran into a couple of problems with the new C++ STL integration, just
>>> dumping them here for now.
>>>
>>> Failure to compile iteration over pointer to C++ vector, apparently a type
>>> inference bug:
>>>
>>> https://github.com/cython/cython/commit/edd10c3b33afcac8f471ac6d6664e29f2d985d21
> 
> Well, the problem is that you're trying to iterate over a
> vector[int]*, and iteration over pointers already has a meaning.

Ah, sure.

> Given v of type vector[int]*, it would be nice to support both iteration
> over v[a:b] and v (element-wise over the pointed-to vector), but I
> don't think this is a bug per se.

Right. However, I don't think iterating over a bare (non-char*) pointer
will ever get a meaning, so implementing this by (basically) dereferencing
the pointer should be ok.

On a somewhat related note, it would be nice to support

    for x in iter(c_ptr, end_value):
        ...

That would mostly be a generalisation of the special "ends with c'\0'"
special case of char* iteration, i.e. that would become equivalent to

    iter(char_ptr, c'\0')


> (There is similar ugliness with
> operator overloading, e.g. given "cdef CppClass* x" should "x + 1"
> increments the pointer rather than operator+.)

Hmm, right. That's less ugly though, because the pointer increment actually
makes sense.

Stefan



More information about the cython-devel mailing list