Fix indent (Use 4spaces) and modelines info

svn path=/trunk/; revision=54967
This commit is contained in:
Alexis La Goutte 2014-01-26 18:24:45 +00:00
parent c6022b3b85
commit ea227de9e2
2 changed files with 148 additions and 122 deletions

View File

@ -43,7 +43,7 @@
#include "exceptions.h"
#endif
#define XCEPT_BUFFER_SIZE 1024
#define XCEPT_BUFFER_SIZE 1024
#ifdef KAZLIB_POSIX_THREADS
@ -90,23 +90,23 @@ int except_init(void)
assert (init_counter < INT_MAX);
if (init_counter++ == 0) {
int top_ok = (pthread_key_create(&top_key, 0) == 0);
int uh_ok = (pthread_key_create(&uh_key, 0) == 0);
int alloc_ok = (pthread_key_create(&alloc_key, 0) == 0);
int dealloc_ok = (pthread_key_create(&dealloc_key, 0) == 0);
int top_ok = (pthread_key_create(&top_key, 0) == 0);
int uh_ok = (pthread_key_create(&uh_key, 0) == 0);
int alloc_ok = (pthread_key_create(&alloc_key, 0) == 0);
int dealloc_ok = (pthread_key_create(&dealloc_key, 0) == 0);
if (!top_ok || !uh_ok || !alloc_ok || !dealloc_ok) {
retval = 0;
init_counter = 0;
if (top_ok)
pthread_key_delete(top_key);
if (uh_ok)
pthread_key_delete(uh_key);
if (alloc_ok)
pthread_key_delete(alloc_key);
if (dealloc_ok)
pthread_key_delete(dealloc_key);
}
if (!top_ok || !uh_ok || !alloc_ok || !dealloc_ok) {
retval = 0;
init_counter = 0;
if (top_ok)
pthread_key_delete(top_key);
if (uh_ok)
pthread_key_delete(uh_key);
if (alloc_ok)
pthread_key_delete(alloc_key);
if (dealloc_ok)
pthread_key_delete(dealloc_key);
}
}
pthread_mutex_unlock(&init_mtx);
@ -121,16 +121,16 @@ void except_deinit(void)
assert (init_counter > 0);
if (--init_counter == 0) {
pthread_key_delete(top_key);
pthread_key_delete(uh_key);
pthread_key_delete(alloc_key);
pthread_key_delete(dealloc_key);
pthread_key_delete(top_key);
pthread_key_delete(uh_key);
pthread_key_delete(alloc_key);
pthread_key_delete(dealloc_key);
}
pthread_mutex_unlock(&init_mtx);
}
#else /* no thread support */
#else /* no thread support */
static int init_counter;
static void unhandled_catcher(except_t *);
@ -175,9 +175,9 @@ void except_deinit(void)
static int match(const volatile except_id_t *thrown, const except_id_t *caught)
{
int group_match = (caught->except_group == XCEPT_GROUP_ANY ||
caught->except_group == thrown->except_group);
caught->except_group == thrown->except_group);
int code_match = (caught->except_code == XCEPT_CODE_ANY ||
caught->except_code == thrown->except_code);
caught->except_code == thrown->except_code);
return group_match && code_match;
}
@ -187,31 +187,31 @@ G_GNUC_NORETURN WS_MSVC_NORETURN static void do_throw(except_t *except)
struct except_stacknode *top;
assert (except->except_id.except_group != 0 &&
except->except_id.except_code != 0);
except->except_id.except_code != 0);
for (top = get_top(); top != 0; top = top->except_down) {
if (top->except_type == XCEPT_CLEANUP) {
top->except_info.except_cleanup->except_func(top->except_info.except_cleanup->except_context);
} else {
struct except_catch *catcher = top->except_info.except_catcher;
const except_id_t *pi = catcher->except_id;
size_t i;
if (top->except_type == XCEPT_CLEANUP) {
top->except_info.except_cleanup->except_func(top->except_info.except_cleanup->except_context);
} else {
struct except_catch *catcher = top->except_info.except_catcher;
const except_id_t *pi = catcher->except_id;
size_t i;
assert (top->except_type == XCEPT_CATCHER);
except_free(catcher->except_obj.except_dyndata);
assert (top->except_type == XCEPT_CATCHER);
except_free(catcher->except_obj.except_dyndata);
for (i = 0; i < catcher->except_size; pi++, i++) {
if (match(&except->except_id, pi)) {
catcher->except_obj = *except;
set_top(top);
longjmp(catcher->except_jmp, 1);
}
}
}
for (i = 0; i < catcher->except_size; pi++, i++) {
if (match(&except->except_id, pi)) {
catcher->except_obj = *except;
set_top(top);
longjmp(catcher->except_jmp, 1);
}
}
}
}
set_top(top);
get_catcher()(except); /* unhandled exception */
get_catcher()(except); /* unhandled exception */
abort();
}
@ -219,12 +219,12 @@ static void unhandled_catcher(except_t *except)
{
if (except->except_message == NULL) {
fprintf(stderr, "Unhandled exception (group=%ld, code=%ld)\n",
except->except_id.except_group,
except->except_id.except_code);
except->except_id.except_group,
except->except_id.except_code);
} else {
fprintf(stderr, "Unhandled exception (\"%s\", group=%ld, code=%ld)\n",
except->except_message, except->except_id.except_group,
except->except_id.except_code);
except->except_message, except->except_id.except_group,
except->except_id.except_code);
}
abort();
}
@ -236,7 +236,7 @@ static void stack_push(struct except_stacknode *node)
}
void except_setup_clean(struct except_stacknode *esn,
struct except_cleanup *ecl, void (*cleanf)(void *), void *context)
struct except_cleanup *ecl, void (*cleanf)(void *), void *context)
{
esn->except_type = XCEPT_CLEANUP;
ecl->except_func = cleanf;
@ -246,7 +246,7 @@ void except_setup_clean(struct except_stacknode *esn,
}
void except_setup_try(struct except_stacknode *esn,
struct except_catch *ech, const except_id_t id[], size_t size)
struct except_catch *ech, const except_id_t id[], size_t size)
{
ech->except_id = id;
ech->except_size = size;
@ -369,7 +369,7 @@ void *except_alloc(size_t size)
void *ptr = get_alloc()(size);
if (ptr == 0)
except_throw(XCEPT_BAD_ALLOC, 0, "out of memory");
except_throw(XCEPT_BAD_ALLOC, 0, "out of memory");
return ptr;
}
@ -395,7 +395,7 @@ static void bottom_level(void)
fgets(buf, sizeof buf, stdin);
if (buf[0] >= 0 && toupper(buf[0]) == 'Y')
except_throw(1, 1, "nasty exception");
except_throw(1, 1, "nasty exception");
}
static void top_level(void)
@ -418,33 +418,33 @@ int main(int argc, char **argv)
/* outer */
except_try_push(catch, 2, &ex);
if (!ex) {
/* inner */
except_try_push(catch, 2, &ex);
if (!ex) {
top_level();
} else {
/* inner catch */
msg = except_message(ex);
if (msg == NULL) {
printf("caught exception (inner): s=%ld, c=%ld\n",
except_group(ex), except_code(ex));
} else {
printf("caught exception (inner): \"%s\", s=%ld, c=%ld\n",
msg, except_group(ex), except_code(ex));
}
except_rethrow(ex);
}
except_try_pop();
/* inner */
except_try_push(catch, 2, &ex);
if (!ex) {
top_level();
} else {
/* inner catch */
msg = except_message(ex);
if (msg == NULL) {
printf("caught exception (inner): s=%ld, c=%ld\n",
except_group(ex), except_code(ex));
} else {
printf("caught exception (inner): \"%s\", s=%ld, c=%ld\n",
msg, except_group(ex), except_code(ex));
}
except_rethrow(ex);
}
except_try_pop();
} else {
/* outer catch */
msg = except_message(ex);
if (msg == NULL) {
printf("caught exception (outer): s=%ld, c=%ld\n",
except_group(ex), except_code(ex));
} else {
printf("caught exception (outer): \"%s\", s=%ld, c=%ld\n",
except_message(ex), except_group(ex), except_code(ex));
}
/* outer catch */
msg = except_message(ex);
if (msg == NULL) {
printf("caught exception (outer): s=%ld, c=%ld\n",
except_group(ex), except_code(ex));
} else {
printf("caught exception (outer): \"%s\", s=%ld, c=%ld\n",
except_message(ex), except_group(ex), except_code(ex));
}
}
except_try_pop();
except_throw(99, 99, "exception in main");
@ -453,3 +453,16 @@ int main(int argc, char **argv)
#endif
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -38,8 +38,8 @@
#include <assert.h>
#include "ws_symbol_export.h"
#define XCEPT_GROUP_ANY 0
#define XCEPT_CODE_ANY 0
#define XCEPT_GROUP_ANY 0
#define XCEPT_CODE_ANY 0
#define XCEPT_BAD_ALLOC 1
#ifdef __cplusplus
@ -79,16 +79,16 @@ struct except_stacknode {
struct except_stacknode *except_down;
enum except_stacktype except_type;
union {
struct except_catch *except_catcher;
struct except_cleanup *except_cleanup;
struct except_catch *except_catcher;
struct except_cleanup *except_cleanup;
} except_info;
};
/* private functions made external so they can be used in macros */
extern void except_setup_clean(struct except_stacknode *,
struct except_cleanup *, void (*)(void *), void *);
struct except_cleanup *, void (*)(void *), void *);
WS_DLL_PUBLIC void except_setup_try(struct except_stacknode *,
struct except_catch *, const except_id_t [], size_t);
struct except_catch *, const except_id_t [], size_t);
WS_DLL_PUBLIC struct except_stacknode *except_pop(void);
/* public interface functions */
@ -125,61 +125,74 @@ WS_DLL_PUBLIC void except_free(void *);
* void except_try_pop(void);
*/
#define except_cleanup_push(F, C) \
{ \
struct except_stacknode except_sn; \
struct except_cleanup except_cl; \
except_setup_clean(&except_sn, &except_cl, F, C)
#define except_cleanup_push(F, C) \
{ \
struct except_stacknode except_sn; \
struct except_cleanup except_cl; \
except_setup_clean(&except_sn, &except_cl, F, C)
#define except_cleanup_pop(E) \
except_pop(); \
if (E) \
except_cl.except_func(except_cl.except_context); \
#define except_cleanup_pop(E) \
except_pop(); \
if (E) \
except_cl.except_func(except_cl.except_context); \
}
#define except_checked_cleanup_pop(F, E) \
except_pop(); \
assert (except_cl.except_func == (F)); \
if (E) \
except_cl.except_func(except_cl.except_context); \
#define except_checked_cleanup_pop(F, E) \
except_pop(); \
assert (except_cl.except_func == (F)); \
if (E) \
except_cl.except_func(except_cl.except_context); \
}
/* --- Variants to allow nesting of except_cleanup_push w/o "shadowing" variables */
#define except_cleanup_push_pfx(pfx, F, C) \
{ \
struct except_stacknode pfx##_except_sn; \
struct except_cleanup pfx##_except_cl; \
except_setup_clean(&pfx##_except_sn, &pfx##_except_cl, F, C)
#define except_cleanup_push_pfx(pfx, F, C) \
{ \
struct except_stacknode pfx##_except_sn; \
struct except_cleanup pfx##_except_cl; \
except_setup_clean(&pfx##_except_sn, &pfx##_except_cl, F, C)
#define except_cleanup_pop_pfx(pfx, E) \
except_pop(); \
if (E) \
pfx##_except_cl.except_func(pfx##_except_cl.except_context);\
#define except_cleanup_pop_pfx(pfx, E) \
except_pop(); \
if (E) \
pfx##_except_cl.except_func(pfx##_except_cl.except_context);\
}
#define except_checked_cleanup_pop_pfx(pfx, F, E) \
except_pop(); \
assert (pfx##_except_cl.except_func == (F)); \
if (E) \
pfx##_except_cl.except_func(pfx##_except_cl.except_context);\
#define except_checked_cleanup_pop_pfx(pfx, F, E) \
except_pop(); \
assert (pfx##_except_cl.except_func == (F)); \
if (E) \
pfx##_except_cl.except_func(pfx##_except_cl.except_context);\
}
/* ---------- */
#define except_try_push(ID, NUM, PPE) \
{ \
struct except_stacknode except_sn; \
struct except_catch except_ch; \
except_setup_try(&except_sn, &except_ch, ID, NUM); \
if (setjmp(except_ch.except_jmp)) \
*(PPE) = &except_ch.except_obj; \
else \
*(PPE) = 0
#define except_try_push(ID, NUM, PPE) \
{ \
struct except_stacknode except_sn; \
struct except_catch except_ch; \
except_setup_try(&except_sn, &except_ch, ID, NUM); \
if (setjmp(except_ch.except_jmp)) \
*(PPE) = &except_ch.except_obj; \
else \
*(PPE) = 0
#define except_try_pop() \
except_free(except_ch.except_obj.except_dyndata); \
except_pop(); \
#define except_try_pop() \
except_free(except_ch.except_obj.except_dyndata); \
except_pop(); \
}
#endif /* XCEPT_H */
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/