From: Pekka Riikonen Date: Wed, 1 Nov 2006 17:50:01 +0000 (+0000) Subject: Added SILC_ASSERT. X-Git-Tag: silc.client.1.1.beta1~226 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=d8a2e1ec2b995b6e9142e687e0ed5907f87f5145 Added SILC_ASSERT. --- diff --git a/lib/silcutil/silcasync.c b/lib/silcutil/silcasync.c index 3e7294d7..216e30af 100644 --- a/lib/silcutil/silcasync.c +++ b/lib/silcutil/silcasync.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2005 Pekka Riikonen + Copyright (C) 2005, 2006 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -87,7 +87,7 @@ SilcBool silc_async_init(SilcAsyncOperation op, SilcAsyncOperationPause pause_cb, void *context) { - assert(abort_cb); + SILC_ASSERT(abort_cb); op->abort_cb = abort_cb; op->pause_cb = pause_cb; op->context = context; diff --git a/lib/silcutil/silcbuffer.h b/lib/silcutil/silcbuffer.h index 5356b3b2..78d99df2 100644 --- a/lib/silcutil/silcbuffer.h +++ b/lib/silcutil/silcbuffer.h @@ -409,7 +409,7 @@ unsigned char *silc_buffer_pull(SilcBuffer sb, SilcUInt32 len) { unsigned char *old_data = sb->data; #if defined(SILC_DEBUG) - assert(len <= silc_buffer_len(sb)); + SILC_ASSERT(len <= silc_buffer_len(sb)); #else if (len > silc_buffer_len(sb)) return NULL; @@ -453,7 +453,7 @@ unsigned char *silc_buffer_push(SilcBuffer sb, SilcUInt32 len) { unsigned char *old_data = sb->data; #if defined(SILC_DEBUG) - assert((sb->data - len) >= sb->head); + SILC_ASSERT((sb->data - len) >= sb->head); #else if ((sb->data - len) < sb->head) return NULL; @@ -497,7 +497,7 @@ unsigned char *silc_buffer_pull_tail(SilcBuffer sb, SilcUInt32 len) { unsigned char *old_tail = sb->tail; #if defined(SILC_DEBUG) - assert(len <= silc_buffer_taillen(sb)); + SILC_ASSERT(len <= silc_buffer_taillen(sb)); #else if (len > silc_buffer_taillen(sb)) return NULL; @@ -541,7 +541,7 @@ unsigned char *silc_buffer_push_tail(SilcBuffer sb, SilcUInt32 len) { unsigned char *old_tail = sb->tail; #if defined(SILC_DEBUG) - assert((sb->tail - len) >= sb->data); + SILC_ASSERT((sb->tail - len) >= sb->data); #else if ((sb->tail - len) < sb->data) return NULL; @@ -582,7 +582,7 @@ unsigned char *silc_buffer_put_head(SilcBuffer sb, SilcUInt32 len) { #if defined(SILC_DEBUG) - assert(len <= silc_buffer_headlen(sb)); + SILC_ASSERT(len <= silc_buffer_headlen(sb)); #else if (len > silc_buffer_headlen(sb)) return NULL; @@ -622,7 +622,7 @@ unsigned char *silc_buffer_put(SilcBuffer sb, SilcUInt32 len) { #if defined(SILC_DEBUG) - assert(len <= silc_buffer_len(sb)); + SILC_ASSERT(len <= silc_buffer_len(sb)); #else if (len > silc_buffer_len(sb)) return NULL; @@ -662,7 +662,7 @@ unsigned char *silc_buffer_put_tail(SilcBuffer sb, SilcUInt32 len) { #if defined(SILC_DEBUG) - assert(len <= silc_buffer_taillen(sb)); + SILC_ASSERT(len <= silc_buffer_taillen(sb)); #else if (len > silc_buffer_taillen(sb)) return NULL; diff --git a/lib/silcutil/silcfsm.c b/lib/silcutil/silcfsm.c index f2fb362d..2c95ccd1 100644 --- a/lib/silcutil/silcfsm.c +++ b/lib/silcutil/silcfsm.c @@ -106,7 +106,7 @@ void silc_fsm_thread_init(SilcFSMThread thread, thread, real_thread ? "real" : "FSM")); #if defined(SILC_DEBUG) - assert(!fsm->thread); + SILC_ASSERT(!fsm->thread); #endif /* SILC_DEBUG */ thread->fsm_context = thread_context; @@ -138,11 +138,11 @@ SILC_TASK_CALLBACK(silc_fsm_free_final) #if defined(SILC_DEBUG) /* We must be finished */ - assert(f->finished); + SILC_ASSERT(f->finished); /* Machine must not have active threads */ if (!f->thread && f->u.m.threads) - assert(f->u.m.threads == 0); + SILC_ASSERT(f->u.m.threads == 0); #endif /* SILC_DEBUG */ if (!f->thread && f->u.m.lock) @@ -277,7 +277,7 @@ SilcSchedule silc_fsm_get_schedule(void *fsm) SilcFSM silc_fsm_get_machine(SilcFSMThread thread) { - assert(thread->thread); + SILC_ASSERT(thread->thread); return (SilcFSM)thread->u.t.fsm; } @@ -320,7 +320,7 @@ SilcBool silc_fsm_thread_wait(void *fsm, void *thread) SilcFSM t = thread; #if defined(SILC_DEBUG) - assert(t->thread); + SILC_ASSERT(t->thread); #endif /* SILC_DEBUG */ if (t->finished) @@ -364,7 +364,7 @@ SILC_TASK_CALLBACK(silc_fsm_run) /* Finish the state machine */ SILC_LOG_DEBUG(("State finish %p", fsm)); #if defined(SILC_DEBUG) - assert(!fsm->finished); + SILC_ASSERT(!fsm->finished); #endif /* SILC_DEBUG */ fsm->finished = TRUE; @@ -451,7 +451,7 @@ void silc_fsm_sema_init(SilcFSMSema sema, SilcFSM fsm, SilcUInt32 value) { SILC_LOG_DEBUG(("Initializing semaphore %p", sema)); #if defined(SILC_DEBUG) - assert(!fsm->thread); + SILC_ASSERT(!fsm->thread); #endif /* SILC_DEBUG */ memset(sema, 0, sizeof(*sema)); sema->fsm = fsm; @@ -500,7 +500,7 @@ SilcUInt32 silc_fsm_sema_wait(SilcFSMSema sema, void *fsm) SilcFSM entry; silc_list_start(sema->waiters); while ((entry = silc_list_get(sema->waiters)) != SILC_LIST_END) - assert(entry != fsm); + SILC_ASSERT(entry != fsm); #endif /* SILC_DEBUG */ SILC_LOG_DEBUG(("Waiting for semaphore %p", sema)); diff --git a/lib/silcutil/silclog.h b/lib/silcutil/silclog.h index acf6ed33..0b12a2a4 100644 --- a/lib/silcutil/silclog.h +++ b/lib/silcutil/silclog.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2005 Pekka Riikonen + Copyright (C) 1997 - 2006 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -285,6 +285,27 @@ typedef SilcBool (*SilcLogHexdumpCb)(char *file, char *function, int line, #endif /* SILC_DEBUG */ /***/ +/****d* silcutil/SilcLogAPI/SILC_ASSERT + * + * NAME + * + * #define SILC_ASSERT(experssion) + * + * DESCRIPTION + * + * Assert macro that prints error message to stderr and calls abort() + * if the `expression' is is false (ie. compares equal to zero). If + * SILC_DEBUG is not defined this macro as no effect. + * + * SOURCE + */ +#if defined(SILC_DEBUG) +#define SILC_ASSERT(expr) assert((expr)); +#else +#define SILC_ASSERT(expr) do { } while(0) +#endif /* SILC_DEBUG */ +/***/ + /* Prototypes */ /****f* silcutil/SilcLogAPI/silc_log_set_file @@ -308,8 +329,8 @@ typedef SilcBool (*SilcLogHexdumpCb)(char *file, char *function, int line, * save HD activity. * ***/ -SilcBool silc_log_set_file(SilcLogType type, char *filename, SilcUInt32 maxsize, - SilcSchedule scheduler); +SilcBool silc_log_set_file(SilcLogType type, char *filename, + SilcUInt32 maxsize, SilcSchedule scheduler); /****f* silcutil/SilcLogAPI/silc_log_get_file * diff --git a/lib/silcutil/silcmemory.h b/lib/silcutil/silcmemory.h index 65286de3..7bd7bef6 100644 --- a/lib/silcutil/silcmemory.h +++ b/lib/silcutil/silcmemory.h @@ -25,9 +25,6 @@ * applications use these functions when they need to allocate, manipulate * and free memory. * - * Currently all allocation routines assert() that the memory was allocated - * successfully. Hence, if memory allocation fails it is fatal error. - * ***/ #ifndef SILCMEMORY_H @@ -46,7 +43,8 @@ * DESCRIPTION * * Allocates memory of `size' bytes and returns pointer to the allocated - * memory area. Free the memory by calling silc_free. + * memory area. Free the memory by calling silc_free. Returns NULL on + * error. * ***/ void *silc_malloc(size_t size); @@ -61,7 +59,8 @@ void *silc_malloc(size_t size); * * Allocates memory of for an array of `items' elements of `size' bytes * and returns pointer to the allocated memory area. The memory area is - * also zeroed. Free the memory by calling silc_free. + * also zeroed. Free the memory by calling silc_free. Returns NULL on + * error. * ***/ void *silc_calloc(size_t items, size_t size);