'throw' annotation support

Bug #779961 reported by Kirill Lapshin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PyBindGen
Fix Released
Undecided
Unassigned

Bug Description

Opening bug per https://answers.launchpad.net/pybindgen/+question/156727. Quick recap:

- Suppose you have a function or method without exception specification (throw (blah) stanza) in C++ declaration.
- According to C++ spec it may throw anything, however PBG doesn't translate C++ exceptions out of a box, and exception escaping such function to Python ends up in terminate()
- Adding 'throw' annotation in pre_scan_hook yields a warning that annotation has no effect, and indeed it doesn't.

Therefore please consider

1. Implementing support for 'throw' annotation
2. Translating std::exception on C++ method/function lacking exception specification.

I believe 1 is genuine missing functionality, and 2 is more of a 'nice to have', as it doesn't address exceptions not inherited from std::exception, but in practice it is a common case, as many projects adopt a binary view of the world -- function either throws and then has no specification or doesn't and then has "throw()" specification, furthermore majority uses exceptions inherited from std::exception anyway, so supporting this case will make it "just work" for many people out of the box.

Related branches

Revision history for this message
Gustavo Carneiro (gjc) wrote :

Regarding 2, I am not sure is a good idea. There is surely some runtime overhead when always catching exceptions in every wrapped function/method. At most, I am willing to add it as an option that is disabled by default.

Gustavo Carneiro (gjc)
Changed in pybindgen:
status: New → Fix Committed
Revision history for this message
Kirill Lapshin (kirill-lapshin) wrote :

Thanks a lot for quick response and fix. There might be some problems with it though -- I'm not 100% sure as I can't get trunk version (proxy issues) so testing with 0.15.0 plus patch from rev 786 atm. With this setup generated code fails to compile with "‘retval’ was not declared in this scope" error. Basically what happens is retval variable declared inside try block and used later on outside try block when it is already out of scope. I'll try it with trunk version tomorrow.

Revision history for this message
Kirill Lapshin (kirill-lapshin) wrote :

I believe I've reconstructed trunk from 0.15 + all patches and can confirm an error above. I'll open another bug as it seems to be unrelated to annotations.

Gustavo Carneiro (gjc)
Changed in pybindgen:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.