Haoyu Bai | 1 Jul 13:40 2010
Picon

Re: [Cython] Some c++ bugs

On Thu, Jul 1, 2010 at 6:09 PM, toki doki <tokidokix@...> wrote:
> Hi,
>
> I have been trying to use cython-devel with c++ and ran into the
> following bugs (that seem to be unreported as far as I can say from a
> quick glance at Trac).
>
> First, and most annoying: in spite of what is written in the docs
> (http://wiki.cython.org/WrappingCPlusPlus), nested c++ class
> declarations seem to be unsupported. Thus, the following snippet
> (taken from the doc) for wrapping std::vector does not work and raise
> a syntax error:
>
> cdef extern from "<vector>" namespace "std":
>    cdef cppclass vector[T]:
>        cdef cppclass iterator:
>            T operator*()
>            iterator operator++()
>        vector()
>        void push_back(T&)
>        T& operator[](int)
>        iterator begin()
>        iterator end()
>

Refer to Cython/Includes/libcpp/vector.pxd for a example of nested class:

cdef extern from "<vector>" namespace "std":
    cdef cppclass vector[T]:
        cppclass iterator:
(Continue reading)

Dag Sverre Seljebotn | 1 Jul 14:43 2010
Picon
Picon

Re: [Cython] Some c++ bugs

Haoyu Bai wrote:
> On Thu, Jul 1, 2010 at 6:09 PM, toki doki <tokidokix@...> wrote:
>   
>> Hi,
>>
>> I have been trying to use cython-devel with c++ and ran into the
>> following bugs (that seem to be unreported as far as I can say from a
>> quick glance at Trac).
>>
>> First, and most annoying: in spite of what is written in the docs
>> (http://wiki.cython.org/WrappingCPlusPlus), nested c++ class
>> declarations seem to be unsupported. Thus, the following snippet
>> (taken from the doc) for wrapping std::vector does not work and raise
>> a syntax error:
>>
>> cdef extern from "<vector>" namespace "std":
>>    cdef cppclass vector[T]:
>>        cdef cppclass iterator:
>>            T operator*()
>>            iterator operator++()
>>        vector()
>>        void push_back(T&)
>>        T& operator[](int)
>>        iterator begin()
>>        iterator end()
>>
>>     
>
> Refer to Cython/Includes/libcpp/vector.pxd for a example of nested class:
>
(Continue reading)

Haoyu Bai | 1 Jul 15:15 2010
Picon

Re: [Cython] Some c++ bugs

On Thu, Jul 1, 2010 at 8:43 PM, Dag Sverre Seljebotn
<dagss <at> student.matnat.uio.no> wrote:
> Haoyu Bai wrote:
>> On Thu, Jul 1, 2010 at 6:09 PM, toki doki <tokidokix <at> gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I have been trying to use cython-devel with c++ and ran into the
>>> following bugs (that seem to be unreported as far as I can say from a
>>> quick glance at Trac).
>>>
>>> First, and most annoying: in spite of what is written in the docs
>>> (http://wiki.cython.org/WrappingCPlusPlus), nested c++ class
>>> declarations seem to be unsupported. Thus, the following snippet
>>> (taken from the doc) for wrapping std::vector does not work and raise
>>> a syntax error:
>>>
>>> cdef extern from "<vector>" namespace "std":
>>>    cdef cppclass vector[T]:
>>>        cdef cppclass iterator:
>>>            T operator*()
>>>            iterator operator++()
>>>        vector()
>>>        void push_back(T&)
>>>        T& operator[](int)
>>>        iterator begin()
>>>        iterator end()
>>>
>>>
>>
(Continue reading)

Haoyu Bai | 1 Jul 16:38 2010
Picon

Re: [Cython] Some c++ bugs

On Thu, Jul 1, 2010 at 9:15 PM, Haoyu Bai <baihaoyu <at> gmail.com> wrote:
> On Thu, Jul 1, 2010 at 8:43 PM, Dag Sverre Seljebotn
> <dagss <at> student.matnat.uio.no> wrote:
>> Haoyu Bai wrote:
>>> On Thu, Jul 1, 2010 at 6:09 PM, toki doki <tokidokix <at> gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I have been trying to use cython-devel with c++ and ran into the
>>>> following bugs (that seem to be unreported as far as I can say from a
>>>> quick glance at Trac).
>>>>
>>>> First, and most annoying: in spite of what is written in the docs
>>>> (http://wiki.cython.org/WrappingCPlusPlus), nested c++ class
>>>> declarations seem to be unsupported. Thus, the following snippet
>>>> (taken from the doc) for wrapping std::vector does not work and raise
>>>> a syntax error:
>>>>
>>>> cdef extern from "<vector>" namespace "std":
>>>>    cdef cppclass vector[T]:
>>>>        cdef cppclass iterator:
>>>>            T operator*()
>>>>            iterator operator++()
>>>>        vector()
>>>>        void push_back(T&)
>>>>        T& operator[](int)
>>>>        iterator begin()
>>>>        iterator end()
>>>>
>>>>
(Continue reading)

toki doki | 2 Jul 09:40 2010
Picon

Re: [Cython] Some c++ bugs

> Refer to Cython/Includes/libcpp/vector.pxd for a example of nested class:
>
> cdef extern from "<vector>" namespace "std":
>    cdef cppclass vector[T]:
>        cppclass iterator:
>            T& operator*()
>            iterator operator++()
>            iterator operator--()
>            bint operator==(iterator)
>            bint operator!=(iterator)
>        ...

Thanks!! That solve my problem. It was only a "documentation bug".
Then, the page "http://wiki.cython.org/WrappingCPlusPlus" needs a
couple of updates:

1- Remove the cdef in front of "cppclass iterator" in the example of
the section "Templates".
2- A note on how nested class are declared without a cdef should be added.

I asked for an access to the wiki and trac. If I am granted access, I
can do these modifications. But if somebody who has already access
want to do it before, please do so :-) .

>
> For your second issue, I have a patch that let you do "cdef cppclass
> VectOfInt(vector[int]): pass" (which is also not supported by
> cython-devel yet), which would get the same effect as ctypedef. See
> the attached file. The patch is not thoroughly tested yet. Feel free
> to take it and improve it if you are interested.
(Continue reading)


Gmane