Title: uClibc C++ exceptions issue
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: alllexx, eric.smith, r.david.murray
Priority: normal Keywords:

Created on 2015-01-28 15:49 by alllexx, last changed 2015-01-29 11:30 by alllexx. This issue is now closed.

File name Uploaded Description Edit
module.cpp alllexx, 2015-01-28 15:49 C++ exception test module
Messages (5)
msg234899 - (view) Author: Alex Potapenko (alllexx) Date: 2015-01-28 15:49
I run Python on an arm-brcm-linux-uclibcgnueabi router. Python was cross-compiled using hndtools-arm-linux-2.6.36-uclibc-4.5.3 toolchain. While trying to use deluge, I realised that there's something wrong with handling C++ exceptions in C++ extension modules: they're not being caught at all. I tested whether C++ exception handling works on my system in general, and concluded it does work fine. I then wrote a simple C++ extension module with a try-catch block in the init function, that has a "throw 1" in the try section and a "catch (...)" section (see module.cpp), and I got "terminate called after throwing an instance of 'int'" when trying to load the module. Tested this with Python 2.7.9 and 3.4.2, however I had similar issues with other versions, such as 2.7.3 and 2.6.9.

I'm not sure whether this is a Python issue, or a specific build issue, but I'm stuck here and any help is greatly appreciated!
msg234902 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-01-28 16:36
For a problem like this you should post to the python-list mailing list.  In addition to the bug tracker not being a place to get help, you are actually more likely to find people who can help you on python-list. We don't actually deal with C++ extensions while developing Python itself so other python users are more likely to have experience in this area.

If you do manage to identify a python bug (which seems unlikely, there are certainly other people successfully using C++ with Python) you can come back and reopen this issue.
msg234906 - (view) Author: Alex Potapenko (alllexx) Date: 2015-01-28 18:16
Thank you for your reply, David! I will come back and reopen if I do identify a python bug.
msg234932 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-01-29 00:59
I agree with David that this isn't the right venue.

That said, the likely problem is that Python's main() is written in C, not C++, so some needed runtime support for exceptions is not getting initialized.
msg234962 - (view) Author: Alex Potapenko (alllexx) Date: 2015-01-29 11:24
Thank you for giving me a hint, Eric! Even though you weren't 100% right, your got me thinking in the right direction, and I found out in the end that I have to explicitly link python with libgcc_s on build time. Now everything works fine. This looks like a uClibc issue, and it should be noted somewhere for others who might encounter similar problems, I suppose.
Date User Action Args
2015-01-29 11:30:20alllexxsettitle: armv7l C++ exceptions issue -> uClibc C++ exceptions issue
2015-01-29 11:24:58alllexxsetmessages: + msg234962
2015-01-29 00:59:28eric.smithsetresolution: not a bug

messages: + msg234932
nosy: + eric.smith
2015-01-28 18:16:14alllexxsetmessages: + msg234906
2015-01-28 16:36:15r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg234902

stage: resolved
2015-01-28 15:49:05alllexxcreate