Re: patch for 2.1.55 pre-1 minix/sysv/affs

Manong Dibos (jwalther@citytel.net)
Fri, 12 Sep 1997 14:56:57 +0000 ( )


This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

---187955613-2032249575-874076217=:785
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Fri, 12 Sep 1997, Linus Torvalds wrote:
> Sure. We'd also be about 500 times slower.
>
> Exception handling is _complex_. That translates into slow.

Ok, I agree the full fledged, regular OO exception handling (where
exceptions involve allocating "objects" and passing them up hierarchies to
find the right handlers) can be slow.

However, for the quick and dirty usage of exceptions (the most used I
think), Ive come up with these simple C macro's. Would anyone care to
check them out?

I believe they involve almost no performance hit over the conventional
nested if()'s......

To use the code, just #include "exceptions.h"

--- exceptions.h ---

/* exceptions.h -- Macros to emulate exception handling in C
*
* September 11, 1997
* by Jonathan Walther jwalther@citytel.net
*
* Datatypes:
* an "exception" is actually an int.
* each thread gets one "int" dedicated to hold exception values called
* "e"
* Mappings between an integer value and what it "means" when thrown as
* an exception can vary between try{} statements. So that the ints
* you throw make sense, use #define's to give the int a meaning.
*
* Usage:
*
* #define FOO_ERR 3
*
* try
* // code
* if (foo) throw(FOO_ERR);
* // more code
* endtry
* catch(FOO_ERR)
* // handle it
* catch(BAR_ERR)
* // if it had been thrown, this would handle it
* finally
* // do this no matter what
* endcatching
*
* try, endtry, and endcatching are mandatory. The other clauses may be
* omitted.
*
* in the catch and finally clauses, more than one statement must be put
* in braces. eg,
*
* catch(FOO_ERR) blah(); endcatching // correct
* catch(FOO_ERR) blah(); bing(); endcatching // not correct
* catch(FOO_ERR) { blah(); bing(); } endcatching // correct
*
* Final note: Whenever you invoke "try", e is modified. If you wish to
* preserve the value, stash it in another variable.
*/

#define try e = 0; do {
#define throw(x) { e = x; break; }
#define endtry } while(0); if (e){ if (0) {}
#define catch(x) else if ( e == x )
#define finally } {
#define endcatching }

int e;

--- end of exceptions.h ---

---187955613-2032249575-874076217=:785
Content-Type: TEXT/plain; name="exceptions.h"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.3.96.970912145657.785B@citytelprct53.citytel.net>
Content-Description:

LyogZXhjZXB0aW9ucy5oIC0tIE1hY3JvcyB0byBlbXVsYXRlIGV4Y2VwdGlv
biBoYW5kbGluZyBpbiBDDQogKg0KICogU2VwdGVtYmVyIDExLCAxOTk3DQog
KiBieSBKb25hdGhhbiBXYWx0aGVyICBqd2FsdGhlckBjaXR5dGVsLm5ldA0K
ICoNCiAqIERhdGF0eXBlczoNCiAqICBhbiAiZXhjZXB0aW9uIiBpcyBhY3R1
YWxseSBhbiBpbnQuDQogKiAgZWFjaCB0aHJlYWQgZ2V0cyBvbmUgImludCIg
ZGVkaWNhdGVkIHRvIGhvbGRpbmcgZXhjZXB0aW9uIHZhbHVlcyBjYWxsZWQg
ImUiDQogKiAgTWFwcGluZ3MgYmV0d2VlbiBhbiBpbnRlZ2VyIHZhbHVlIGFu
ZCB3aGF0IGl0ICJtZWFucyIgd2hlbiB0aHJvd24gYXMgYW4NCiAqICAgIGV4
Y2VwdGlvbiBjYW4gdmFyeSBiZXR3ZWVuIHRyeXt9IHN0YXRlbWVudHMuICBT
byB0aGF0IHRoZSBpbnRzIHlvdSB0aHJvdw0KICogICAgbWFrZSBzZW5zZSwg
dXNlICNkZWZpbmUncyB0byBnaXZlIHRoZSBpbnQgYSBtZWFuaW5nLg0KICoN
CiAqIFVzYWdlOg0KICoNCiAqICAjZGVmaW5lIEZPT19FUlIgMw0KICoNCiAq
ICB0cnkNCiAqICAgIC8vIGNvZGUNCiAqICAgIGlmIChmb28pIHRocm93KEZP
T19FUlIpOw0KICogICAgLy8gbW9yZSBjb2RlDQogKiAgZW5kdHJ5DQogKiAg
Y2F0Y2goRk9PX0VSUikNCiAqICAgIC8vIGhhbmRsZSBpdA0KICogIGZpbmFs
bHkNCiAqICAgIC8vIGRvIHRoaXMgbm8gbWF0dGVyIHdoYXQNCiAqIC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