unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Prototype for C++-compatible Guile Exceptions.
@ 2015-07-14 18:07 Taahir Ahmed
  2015-07-14 18:07 ` [PATCH 1/3] Support C++ source files, use -fexceptions Taahir Ahmed
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Taahir Ahmed @ 2015-07-14 18:07 UTC (permalink / raw)
  To: guile-devel

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.




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-09-06 23:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-14 18:07 Prototype for C++-compatible Guile Exceptions Taahir Ahmed
2015-07-14 18:07 ` [PATCH 1/3] Support C++ source files, use -fexceptions Taahir Ahmed
2015-07-14 18:07 ` [PATCH 2/3] Add C++ extern "C" guards to internal headers Taahir Ahmed
2015-07-14 19:36   ` Andreas Rottmann
2015-07-16  0:22     ` Taahir Ahmed
2015-07-16 18:55       ` Andreas Rottmann
2015-07-15  3:40 ` [PATCH 3/3] Implement Guile exceptions with C++ exceptions Taahir Ahmed
2015-08-10  3:26 ` Prototype for C++-compatible Guile Exceptions Taahir Ahmed
2015-09-04  8:06 ` Mark H Weaver
2015-09-06 23:01   ` Taahir Ahmed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).