public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Edgar Toernig <froese@gmx.de>
To: Dan Aloni <da-x@gmx.net>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] [PATCH] C exceptions in kernel
Date: Sat, 23 Feb 2002 04:37:27 +0100	[thread overview]
Message-ID: <3C770E77.5C7111B1@gmx.de> (raw)
In-Reply-To: <1014412325.1074.36.camel@callisto.yi.org>

[-- Attachment #1: Type: text/plain, Size: 226 bytes --]

Dan Aloni wrote:
> 
> The attached patch implements C exceptions in the kernel,

Bad idea ...

> which *don't* depend on special support from the compiler.

... which can be implemented in simple ANSI-C.  See below.

Ciao, ET.

[-- Attachment #2: try-n-catch.c --]
[-- Type: text/plain, Size: 889 bytes --]

#include <setjmp.h>

struct _catch
{
    struct _catch *next;
    jmp_buf buf;
};

static struct _catch _catch_top[1];
struct _catch *_catch = _catch_top;

#define throw()				\
    do {				\
	_catch = _catch->next;		\
	longjmp(_catch->buf, 1);	\
    } while (0)


#define try				\
    if (setjmp(_catch->buf) == 0) {	\
	struct _catch _catch_new[1];	\
	_catch_new->next = _catch;	\
	_catch = _catch_new;

#define catch \
	_catch = _catch->next;		\
    } else


/**** example below ****/

#include <stdio.h>

int a = 1;

void
foo(int x)
{
    a=2;
    if (x & 1)
	throw();
}

int
main(int argc, char **argv)
{
    int i;

    for (i = 0; i < 10; ++i)
    {
	a=i;
	try
	{
	    try foo(i); catch
	    {
		printf("2: caught at %d (a=%d)\n", i, a);
		if ((i&3)==1)
		    throw();
	    }
	}
	catch
	{
	    printf("1: caught at %d (a=%d)\n", i, a);
	}
	printf("a=%d\n", a);
    }
    return 0;
}


  parent reply	other threads:[~2002-02-23  4:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-22 21:12 [RFC] [PATCH] C exceptions in kernel Dan Aloni
2002-02-22 21:28 ` Davide Libenzi
2002-02-22 22:10 ` Richard B. Johnson
2002-02-22 22:34 ` David B. Stevens
2002-02-22 22:48   ` Davide Libenzi
2002-02-23  3:37 ` Edgar Toernig [this message]
     [not found] ` <mailman.1014437101.26721.linux-kernel2news@redhat.com>
2002-02-23 10:11   ` Pete Zaitcev
2002-02-23 12:26     ` Keith Owens
2002-02-23 12:50       ` Pete Zaitcev
2002-02-23 23:07         ` Jes Sorensen
2002-02-23 23:40           ` Keith Owens
2002-02-24  1:02             ` Jes Sorensen
2002-02-24 23:45               ` Richard Gooch
2002-02-23 23:50         ` Bill Huey
2002-02-24  1:31           ` Davide Libenzi
2002-02-24  2:55             ` Bill Huey
2002-02-23 15:13 ` Felix von Leitner
2002-02-23 15:21 ` bert hubert
2002-02-23 16:05   ` Dan Aloni
2002-02-23 16:22     ` Larry McVoy
2002-02-23 17:00       ` Dan Aloni
2002-02-23 17:52         ` Francois Romieu
2002-02-23 17:07       ` bert hubert
2002-02-23 17:47   ` Alexander Viro
2002-02-23 18:21     ` bert hubert
2002-02-23 18:31       ` Larry McVoy
2002-02-23 18:38         ` bert hubert
2002-02-23 19:12           ` Kurt Ferreira
2002-02-23 23:05       ` Jes Sorensen

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

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

  git send-email \
    --in-reply-to=3C770E77.5C7111B1@gmx.de \
    --to=froese@gmx.de \
    --cc=da-x@gmx.net \
    --cc=linux-kernel@vger.kernel.org \
    /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