Author: Pekka Riikonen <priikone@silcnet.org>
- 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
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;
{
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;
{
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;
{
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;
{
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;
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;
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;
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;
thread, real_thread ? "real" : "FSM"));
#if defined(SILC_DEBUG)
- assert(!fsm->thread);
+ SILC_ASSERT(!fsm->thread);
#endif /* SILC_DEBUG */
thread->fsm_context = thread_context;
#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)
SilcFSM silc_fsm_get_machine(SilcFSMThread thread)
{
- assert(thread->thread);
+ SILC_ASSERT(thread->thread);
return (SilcFSM)thread->u.t.fsm;
}
SilcFSM t = thread;
#if defined(SILC_DEBUG)
- assert(t->thread);
+ SILC_ASSERT(t->thread);
#endif /* SILC_DEBUG */
if (t->finished)
/* 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;
{
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;
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));
Author: Pekka Riikonen <priikone@silcnet.org>
- 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
#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
* 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
*
* 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
* 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);
*
* 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);