[lkml]   [2002]   [Feb]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [RFC] [PATCH] C exceptions in kernel
On Sat, Feb 23, 2002 at 06:05:48PM +0200, Dan Aloni wrote:
> But, it CAN be used in *local* driver call branches. Writing a new
> driver? have a lot of local nested calls? Hate goto's? You can use
> exceptions.

Is this really anything other than syntactic sugar? Maybe it's different
in drivers, but I find myself doing the following in user space all the time

#define unless(x) if (!(x)) /* perl/BCPL corrupted me */

char *foo = 0, *bar = 0;
int locked = 0;
int rc = -1;

if (bad args or something) {
out: if (foo) free(foo);
if (bar) free(bar);
if (locked) unlock();
return (rc);

unless (locked = get_the_lock()) goto out;
unless (foo = allocate_foo()) goto out;
unless (bar = allocate_bar()) goto out;

more code....

rc = 0;
goto out;

It seems ugly at first but it has some nice attributes:

a) all the cleanup is in one place, for both the error path and the
non-error path. I could put it at the bottom, I like it at the
top because that's where I tend to have the list of things needed
to be cleaned.

b) all the error cases are branches, the normal path is straightline.

c) it's as dense as I can make it.

So how would you do the same thing with exceptions?
Larry McVoy lm at
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:24    [W:0.089 / U:0.096 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site