[Cython] errors in C++ tests

Stefan Behnel stefan_ml at behnel.de
Sun Jul 8 22:41:13 CEST 2012

Lars Buitinck, 08.07.2012 22:24:
> 2012/7/8 Stefan Behnel:
>> ... and there also were some more headers missing, so basically, this
>> feature never worked. Great. Here's the complete implementation with the
>> four header files that I had to add at the top:
> I'm pretty sure that at some point, it worked. I implemented this in
> 6291a2 and the five prior commits, but I did add the appropriate
> headers to Cython/Compiler/Nodes.py.
> There is a unit test for this feature in tests/run/cpp_exceptions.pyx;
> that file includes a header that in turn includes <ios>, <new> and
> <stdexcept>, but not <typeinfo> because it doesn't need that to raise
> the exception. (It would be more reliable if the test where refactored
> into C++ modules so that the headers need not be indirectly included.)
>> #include <iostream>
> Actually, you'll want to include <ios> where std::ios_base is
> declared. <iostream> is a much "heavier" header.
>> Does it make sense to always include these four headers, or should we try
>> to handle the exceptions conditionally?
> As I said, this should already have been done by
> Cython/Compiler/Nodes.py. I'm not sure what's going wrong.

Ah, I see it now. Those only work for user declared functions. This problem
arises for the default construction, i.e. the undeclared no-args
constructor that Cython creates automatically. We didn't previously
propagate exceptions for it, so the feature did work and I only broke it by
fixing the default constructor. Thanks for clearing this up.

Any reason why the env.add_include_file() calls would be better than the
header inclusion that I implemented right before the function? It's inside
of the #ifndef block now. After all, they are only needed by that function,
and when users override it by redefining the name from the outside, they do
not need to get included. If users include them themselves, they'll be
included twice - so what.


More information about the cython-devel mailing list