I'm posting these patches to feel out the likelihood of this approach to C++ exception compatibility ever getting adopted into Guile. They still need some work in terms of function documentation, and one test failure.
---------------------------------------------------------------------- Currently, the use of libguile functions from C++ is fraught with danger. C++ destructors are not triggered by guile exceptions, and the dynwind mechanism is ill-suited for application to C++ data structures (in particular, STL structures). In my experience, writing a C++ function that takes data from guile code in a truly safe manner roughly doubles the required amount of code, because of the generally-required pattern: // ... // Some code to check that a SCM really is an int. int dummy = scm_to_int(my_scm); // Below this point, no guile exceptions may be thrown. // Now, we can create a std::vector, or what-have-you, and put our // int into it. std::vector<int> my_vector; my_vector.push_back(scm_to_int(my_scm)); // ... This sequence of patches addresses this shortcoming by using hidden C++ exceptions to perform the stack unwinding when a guile exception is thrown, so that the pre-checking demonstrated above is not needed. # How is this implemented? This sequence of patches does four things: - Enables autotools C++ support. - Adds -fexceptions to the compiler command line to enable C++ exceptions to traverse C stack frames. - Adds extern "C" guards to the internal libguile headers. - Adds a single C++ source file to libguile that contains set/longjmp workalikes for prompt and exception handling. Prompt and exception-related uses of set/longjmp are replaced with these functions. (This is the third patch, and the real meat of the work). # What are the downsides of this prototype implementation? The use of -fexceptions and a C++ source file limit the choice of compiler. GCC, Clang, and ICC should be fine. I have no idea about some of the more esoteric compilers. On most platforms, -fexceptions entails some space overhead. In my testing, libguile gets bumped from 4.8 MiB to about 5 MiB. The last two test cases in test-out-of-memory ("the kicker" and "ouch") fail. I'm still investigating the root cause. All other tests pass.