[Cython] Generated C++ code incompatible with Clang

Hannes Röst hroest_nospam2333 at quantentunnel.de
Fri Apr 12 17:04:01 CEST 2013


Dear mailing list

In the process of developing a rather large Cython project where we wrap the
scientific OpenMS library (http://sourceforge.net/projects/open-ms/) using
Cython, we have come across an issue with the C++ code that is generated by
Cython. The issue is that Cython generates C++ that is not compatible with the
Clang compiler.

I hope this is the correct mailing list to report this issue since it seems to
be a bug in Cython and not in Clang (after some discussion we have concluded
that Clang is most likely correct in rejecting the generated code). Since we do
not have access to the issue tracker, we hoped posting our issue here would
clear up matters.

The issue occurs with the following minimal testcase:

from libcpp.vector cimport vector as libcpp_vector
from cython.operator cimport dereference as deref, preincrement as inc

cdef class TestClass:

    cdef libcpp_vector[float] inst

    def __iter__(self):
        it = self.inst.begin()
        while it != self.inst.end():
            yield deref(it)
            inc(it)

When compiled with Cython to C++, it generates C++ that cannot be compiled with
Clang (however it seems that gcc and MSVS accept the code). It seems that the
same issue with Clang was already discussed here:
https://bugzilla.mozilla.org/show_bug.cgi?id=623303 and the conclusion was that
Clang is correct in reporting the code as erroneous.

In the above case, the invalid C++ code that gets generated is:

  p->__pyx_v_it.std::vector<float>::iterator::~iterator();

The correct code for the above case would probably be (this is just a
suggestion, it compiles with gcc and clang on our machines and our tests run
through with it):

  typedef std::vector<float>::iterator _it;
  p->__pyx_v_it.~_it();


We have tested it with the 0.18 release as well as the newest 0.19b2 build from
github (58131b68dc033fc7ca269d875a2aab2b4e9646a2) and the results were the
same.

Thanks,

Hannes Röst




-- 
Hannes Röst
Institute of Molecular Systems Biology
ETH Zürich Hönggerberg HPT C75
Wolfgang-Pauli Strasse 16
CH-8093 Zürich (Switzerland)

phone: 0041 44 633 3945
fax: 0041 44 633 10 51
e-mail: roest at imsb.biol.ethz.ch


More information about the cython-devel mailing list