--- ex.pod 2002/04/02 17:54:09 1.25
+++ ex.pod 2003/01/06 15:31:24 1.26
@@ -1,8 +1,8 @@
##
-## OSSP ex - Exception Handling Library
-## Copyright (c) 2002 Ralf S. Engelschall <rse@engelschall.com>
-## Copyright (c) 2002 The OSSP Project <http://www.ossp.org/>
-## Copyright (c) 2002 Cable & Wireless Deutschland <http://www.cw.com/de/>
+## OSSP ex - Exception Handling
+## Copyright (c) 2002-2003 Ralf S. Engelschall <rse@engelschall.com>
+## Copyright (c) 2002-2003 The OSSP Project <http://www.ossp.org/>
+## Copyright (c) 2002-2003 Cable & Wireless Deutschland <http://www.cw.com/de/>
##
## This file is part of OSSP ex, an exception library
## which can be found at http://www.ossp.org/pkg/lib/ex/.
@@ -63,7 +63,7 @@
B<OSSP ex> is a small B<ISO-C++> style exception handling library for
use in the B<ISO-C> language. It allows you to use the paradigm of
throwing and catching exceptions in order to reduce the amount of error
-handling code without making your program less robust.
+handling code without making your program less robust.
This is achieved by directly transferring exceptional return codes (and
the program control flow) from the location where the exception is
@@ -124,7 +124,7 @@
this is just a numerical return code. In the complex case this can be a
pointer to an arbitrary complex data structure describing the exception.
-=item C<char *>I<ex_file>
+=item C<char *>I<ex_file>
This is the file name of the B<ISO-C> source where the B<ex_throw> call
was performed. It is provided as an additional information about the
@@ -162,7 +162,7 @@
flow in case an exception is thrown is: I<BLOCK1> (up to the statement
where the exception is thrown only), optionally followed by I<BLOCK2>,
followed by I<BLOCK3>.
-
+
The B<ex_try>, B<ex_cleanup> and B<ex_catch> cannot be used separately,
they work only in combination because they form a language clause
as a whole. In contrast to B<ISO-C++> there is only one B<ex_catch>
@@ -253,7 +253,7 @@
This is a boolean flag which can be checked inside the dynamic scope
of an B<ex_try> clause to test whether the current scope is exception
-catching.
+catching.
=item B<ex_deferred>
@@ -387,7 +387,7 @@
/* BAD EXAMPLE */
ex_try {
char *cp1, *cp2, cp3;
-
+
cp1 = mallocex(SMALLAMOUNT);
globalcontext->first = cp1;
cp2 = mallocex(TOOBIG);
@@ -475,17 +475,17 @@
}
clean {
/*04*/ printf("cp3=%s", cp3 == NULL /*02*/ ? "" : cp3);
- if (cp3 != NULL)
+ if (cp3 != NULL)
free(cp3);
- if (cp2 != NULL)
+ if (cp2 != NULL)
free(cp2);
- /*05 cp1 was given away */
- }
- catch(ex) {
- /*05 global context untouched */
- rethrow;
- }
- }
+ /*05 cp1 was given away */
+ }
+ catch(ex) {
+ /*05 global context untouched */
+ rethrow;
+ }
+ }
An alternative fixed version could also be:
@@ -500,16 +500,16 @@
/*05 keep responsibility*/
cp2 = mallocex(TOOBIG);
cp3 = mallocex(SMALLAMOUNT);
- strcpy(cp1, "foo");
+ strcpy(cp1, "foo");
strcpy(cp2, "bar");
}
clean {
/*04*/ printf("cp3=%s", cp3 == NULL /*02*/ ? "" : cp3);
- if (cp3 != NULL)
+ if (cp3 != NULL)
free(cp3);
- if (cp2 != NULL)
+ if (cp2 != NULL)
free(cp2);
- if (cp1 != NULL)
+ if (cp1 != NULL)
free(cp1);
}
catch(ex) {
@@ -588,59 +588,59 @@
free(data);
return;
}
-
+
/* callback: context fetching */
static ex_ctx_t *pthread_ex_ctx(void)
{
return (ex_ctx_t *)pthread_getspecific(pthread_ex_ctx_key);
}
-
+
/* callback: termination */
static void pthread_ex_terminate(ex_t *e)
{
pthread_exit(e->ex_value);
}
-
+
/* pthread init */
int pthread_init_ex(void)
{
int rc;
-
+
/* additionally create thread data key and override OSSP ex callbacks */
pthread_key_create(&pthread_ex_ctx_key, pthread_ex_ctx_destroy);
__ex_ctx = pthread_ex_ctx;
__ex_terminate = pthread_ex_terminate;
-
+
return rc;
}
-
+
/* internal thread entry wrapper information */
typedef struct {
void *(*entry)(void *);
void *arg;
} pthread_create_ex_t;
-
+
/* internal thread entry wrapper */
static void *pthread_create_wrapper(void *arg)
{
pthread_create_ex_t *wrapper;
ex_ctx_t *ex_ctx;
-
+
/* create per-thread exception context */
wrapper = (pthread_create_ex_t *)arg;
ex_ctx = (ex_ctx_t *)malloc(sizeof(ex_ctx_t));
EX_CTX_INITIALIZE(ex_ctx);
pthread_setspecific(pthread_ex_ctx_key, ex_ctx);
-
+
/* perform original operation */
return wrapper->entry(wrapper->arg);
}
-
+
/* pthread_create() wrapper */
int pthread_create_ex(pthread_t *thread, const pthread_attr_t *attr, void *(*entry)(void *), void *arg)
{
pthread_create_ex_t wrapper;
-
+
/* spawn thread but execute start function through wrapper */
wrapper.entry = entry;
wrapper.arg = arg;
@@ -761,7 +761,7 @@
#include "foo.h"
const char foo_id[] = "foo 1.0";
-
+
#ifdef WITH_EX
#include "ex.h"
#define FOO_RC(rv) \
|