Stefan Behnel | 8 Jul 2012 12:33
Picon
Favicon

[Cython] errors in C++ tests

Hi,

I'm seeing C++ compiler errors errors in the C++ tests.

https://sage.math.washington.edu:8091/hudson/job/cython-devel-tests/BACKEND=cpp,PYVERSION=py3k/491/testReport/

"""
cpp_operators.cpp: In function ‘void __Pyx_CppExn2PyErr()’:
cpp_operators.cpp:442: error: expected unqualified-id before ‘&’ token
cpp_operators.cpp:442: error: expected `)' before ‘&’ token
"""

The failing code line is this:

"""
  } catch (const std::bad_alloc& exn) {
"""

That line looks ok to me. It started failing after I enabled C++ error
handling for default constructors, which then lead to the above function
being generated into the module code.

Does anyone know what to make of this?

Stefan
_______________________________________________
cython-devel mailing list
cython-devel <at> python.org
http://mail.python.org/mailman/listinfo/cython-devel
(Continue reading)

Lars Buitinck | 8 Jul 2012 20:38
Picon
Picon
Favicon

Re: [Cython] errors in C++ tests

2012/7/8 Stefan Behnel <stefan_ml <at> behnel.de>:
> """
> cpp_operators.cpp: In function ‘void __Pyx_CppExn2PyErr()’:
> cpp_operators.cpp:442: error: expected unqualified-id before ‘&’ token
> cpp_operators.cpp:442: error: expected `)' before ‘&’ token
> """
>
> The failing code line is this:
>
> """
>   } catch (const std::bad_alloc& exn) {
> """

Could you check whether the header <new> is included? It should be to
get the definition of bad_alloc.

--

-- 
Lars Buitinck
Scientific programmer, ILPS
University of Amsterdam
_______________________________________________
cython-devel mailing list
cython-devel <at> python.org
http://mail.python.org/mailman/listinfo/cython-devel
Stefan Behnel | 8 Jul 2012 20:54
Picon
Favicon

Re: [Cython] errors in C++ tests

Lars Buitinck, 08.07.2012 20:38:
> 2012/7/8 Stefan Behnel:
>> """
>> cpp_operators.cpp: In function ‘void __Pyx_CppExn2PyErr()’:
>> cpp_operators.cpp:442: error: expected unqualified-id before ‘&’ token
>> cpp_operators.cpp:442: error: expected `)' before ‘&’ token
>> """
>>
>> The failing code line is this:
>>
>> """
>>   } catch (const std::bad_alloc& exn) {
>> """
> 
> Could you check whether the header <new> is included? It should be to
> get the definition of bad_alloc.

Ah, yes. I'm sure that's it. Are there any side-effects in that header
file, or would it be ok to always include it in C++ mode when the above
exception conversion function is used?

Stefan
_______________________________________________
cython-devel mailing list
cython-devel <at> python.org
http://mail.python.org/mailman/listinfo/cython-devel
Stefan Behnel | 8 Jul 2012 21:18
Picon
Favicon

Re: [Cython] errors in C++ tests

Stefan Behnel, 08.07.2012 20:54:
> Lars Buitinck, 08.07.2012 20:38:
>> 2012/7/8 Stefan Behnel:
>>> """
>>> cpp_operators.cpp: In function ‘void __Pyx_CppExn2PyErr()’:
>>> cpp_operators.cpp:442: error: expected unqualified-id before ‘&’ token
>>> cpp_operators.cpp:442: error: expected `)' before ‘&’ token
>>> """
>>>
>>> The failing code line is this:
>>>
>>> """
>>>   } catch (const std::bad_alloc& exn) {
>>> """
>>
>> Could you check whether the header <new> is included? It should be to
>> get the definition of bad_alloc.
> 
> Ah, yes. I'm sure that's it.

... 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:

"""
#include <new>
#include <typeinfo>
#include <stdexcept>
#include <iostream>

(Continue reading)

Lars Buitinck | 8 Jul 2012 22:24
Picon
Picon
Favicon

Re: [Cython] errors in C++ tests

2012/7/8 Stefan Behnel <stefan_ml@...>:
> ... 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.

--

-- 
Lars Buitinck
Scientific programmer, ILPS
University of Amsterdam
(Continue reading)

Stefan Behnel | 8 Jul 2012 22:41
Picon
Favicon

Re: [Cython] errors in C++ tests

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
(Continue reading)

Lars Buitinck | 8 Jul 2012 23:48
Picon
Picon
Favicon

Re: [Cython] errors in C++ tests

2012/7/8 Stefan Behnel <stefan_ml@...>:
> 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.

I'm not really familiar with Cython internals; I just extended
Compiler/Nodes.py that previously added only <stdexcept>. I observed
that this leads to the headers being included once, at the top of the
file, which seemed like the clean solution.

Multiple inclusion of C++ standard headers should be completely safe,
but I don't know whether the C++ standard says anything about
including standard headers in the middle of a module.

--

-- 
Lars Buitinck
Scientific programmer, ILPS
University of Amsterdam

Gmane