unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Dirk Herrmann <dirk@dirk-herrmanns-seiten.de>
Cc: guile-devel@gnu.org, Neil Jerram <neil@ossau.uklinux.net>
Subject: Re: Stack unwinding for C code
Date: Fri, 02 Jan 2004 12:45:12 +0100	[thread overview]
Message-ID: <3FF559C8.2040702@dirk-herrmanns-seiten.de> (raw)
In-Reply-To: <87brppkft6.fsf@zagadka.ping.de>

Marius Vollmer wrote:

>I see.  Hmm.  I have no ideas (yet) about what to do about
>SCM_DEFER_INTS, etc.  But you are right, we should have a plan for
>bringing all things that are related to the dynamic context together.
>So what about separating the API further: there would be only
>scm_begin_frame and an additional function scm_prevent_rewind (or
>scm_prevent_reentry?) could be used like
>
>    scm_begin_frame ();
>    scm_prevent_rewind ();
>    ...
>    scm_end_frame ();
>
I like this style of interface for its simplicity. But, I am somewhat 
confused since in your proposal below you don't suggest this style of 
interface, but instead describe scm_begin_frame as receiving an 
additional argument with flags. I wouldn't prefer any of the two 
solutions, but I am currently not sure what you actually suggest - 
especially since in the example given below you don't pass any argument 
to scm_begin_frame.

>Sometimes, it is necessary to perform cleanups when the unwinding
>happens.  Frequently, dynamically allocated temporary data structures
>need to be deallocated, for example.
>
If this document was to be reused in the documentation later, we should 
given an example here.

>- C Function: void scm_begin_frame (int flags)
>
>  Starts a new frame and makes it the 'current' one.  FLAGS determines
>  the default behavior of the frame.  For normal frames, use 0.  This
>  will result in a frame that can not be reentered with a captured
>  continuation.  See below.
>
>  The frame is ended either implicitly when a non-local exit happens,
>  or explicitly with scm_end_frame.
>
If this style of API is used (that is, passing a 'flags' argument to 
scm_begin_frame instead of having separate functions like 
scm_prevent_rewind and similar), then I suggest to use an enumeration 
type with all possible flags instead of an int type. This improves both 
type safety and readability of the code using scm_begin_frame. The same 
applies to the 'explicit' argument to scm_on_unwind and scm_on_rewind.

>- C Function: void scm_on_unwind (void (*func)(void *), void *data,
>                                  int explicit)
>
>  Arranges for FUNC to be called with DATA as its arguments when the
>  current frame ends implicitly.  If EXPLICIT is non-zero, FUNC is
>  also called when the frame ends explicitly.
>
It is a nice coincidence that 'free' matches the void (*func) (void *) 
signature, especially since free will probably be one of the most 
frequently used functions with scm_on_unwind. fclose, however, does not 
match and is another candidate that may be commonly used. Unfortunately 
it wouldn't be standard conforming to just cast fclose to match the 
signature. I suggest that (in addition to the generic scm_on_unwind) for 
a limited set of common functions we provide specialized 
scm_on_unwind_xxx functions, like:

scm_on_unwind_free (void *data, int explicit); // could simply be 
#defined to scm_on_unwind
scm_on_unwind_fclose (FILE* fp, int explicit); // on some architectures 
this may also safely be #defined to scm_on_unwind
// maybe there are other typical cleanup functions...

Then, scm_on_unwind_free could either simply be #defined to 
scm_on_unwind, or - if it brings some performance and code size benefit 
to avoid passing the additional argument - provided as a special 
implementation. On some architectures it may also be an option to just 
#define scm_on_unwind_fclose to scm_on_unwind.

Best regards
Dirk Herrmann



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  reply	other threads:[~2004-01-02 11:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-26 21:36 Stack unwinding for C code Marius Vollmer
2003-12-27  9:53 ` tomas
2003-12-27 12:11 ` Neil Jerram
2003-12-27 17:37   ` Marius Vollmer
2003-12-28  2:25     ` Tom Lord
2003-12-29 22:12       ` Marius Vollmer
2003-12-29 23:25     ` Neil Jerram
2003-12-31  0:10       ` Marius Vollmer
2004-01-02 11:45         ` Dirk Herrmann [this message]
2004-01-02 17:38           ` Marius Vollmer
2004-01-03 22:08             ` Marius Vollmer
2004-01-10 11:45             ` Dirk Herrmann
2004-01-11  1:23               ` Marius Vollmer
2004-01-06 18:37         ` Paul Jarc
2004-01-07 20:27           ` Marius Vollmer
2004-01-13 17:24         ` Rob Browning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3FF559C8.2040702@dirk-herrmanns-seiten.de \
    --to=dirk@dirk-herrmanns-seiten.de \
    --cc=guile-devel@gnu.org \
    --cc=neil@ossau.uklinux.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).