silc_stack_alloc automatically aligns the stack size.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 25 Dec 2007 16:47:26 +0000 (16:47 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 25 Dec 2007 16:47:26 +0000 (16:47 +0000)
CHANGES.RUNTIME
TODO
lib/silcutil/silcfsm.c
lib/silcutil/silcstack.c
lib/silcutil/silcstack.h
lib/silcutil/tests/test_silcstack.c

index 4c2cef6413d20edbb7915359dd9f75e21d2216fd..ff6ebd8a0e261608dbbab00d7fd9985667b60426 100644 (file)
@@ -1,3 +1,8 @@
+Tue Dec 25 18:44:27 EET 2007  Pekka Riikonen <priikone@silcnet.org>
+
+       * silc_stack_alloc now automatically aligns the requested
+         stack size.  Affected files are lib/silcutil/silcstack.[ch].
+
 Tue Dec 25 13:53:07 EET 2007  Pekka Riikonen <priikone@silcnet.org>
 
        * Added silc_getopt to lib/silcutil/silcgetopt.[ch].
diff --git a/TODO b/TODO
index 8fbf2c34e1f9e2788f83ba68f05f78cd31002b87..fd6156b4ccd834bed26fbf47a3f60039cebdc696 100644 (file)
--- a/TODO
+++ b/TODO
@@ -203,7 +203,7 @@ Runtime library, lib/silcutil/
    allocation possibility. (***DONE)
 
  o silc_stack_alloc shouldn't require multiple by 8 size argument, it
-   should figure it out itself.
+   should figure it out itself. (***DONE)
 
  o silc_malloc et. al. to respect --with-alignment.
 
index 3cef6d969506a8f374feb54fdcb5e3a89029b0cf..4ff23bab02fdb2b8eb60678629e136c9c3e5c28e 100644 (file)
@@ -108,7 +108,7 @@ void silc_fsm_thread_init(SilcFSMThread thread,
   SILC_LOG_DEBUG(("Initializing new thread %p (%s)",
                  thread, real_thread ? "real" : "FSM"));
 
-  SILC_ASSERT(!fsm->thread);
+  SILC_VERIFY(!fsm->thread);
 
   thread->fsm_context = thread_context;
   thread->state_context = NULL;
@@ -317,7 +317,7 @@ void silc_fsm_finish(void *fsm)
 {
   SilcFSM f = fsm;
 
-  SILC_ASSERT(!f->finished);
+  SILC_VERIFY(!f->finished);
 
   f->started = FALSE;
   f->finished = TRUE;
@@ -356,7 +356,7 @@ SilcSchedule silc_fsm_get_schedule(void *fsm)
 
 SilcFSM silc_fsm_get_machine(SilcFSMThread thread)
 {
-  SILC_ASSERT(thread->thread);
+  SILC_VERIFY(thread->thread);
   return (SilcFSM)thread->u.t.fsm;
 }
 
@@ -406,7 +406,7 @@ SilcBool silc_fsm_thread_wait(void *fsm, void *thread)
 {
   SilcFSM t = thread;
 
-  SILC_ASSERT(t->thread);
+  SILC_VERIFY(t->thread);
 
   t->u.t.event = silc_fsm_event_alloc(t->u.t.fsm);
   if (!t->u.t.event)
@@ -517,7 +517,7 @@ SilcFSMEvent silc_fsm_event_alloc(SilcFSM fsm)
 void silc_fsm_event_init(SilcFSMEvent event, SilcFSM fsm)
 {
   SILC_LOG_DEBUG(("Initializing event %p", event));
-  SILC_ASSERT(!fsm->thread);
+  SILC_VERIFY(!fsm->thread);
   memset(event, 0, sizeof(*event));
   event->fsm = fsm;
   event->refcnt = 0;
index 88286d83c505ddfaa3e69eb5b7b72bc009631051..79f63d2fc8552242223be51cadbccb5c69d7ff40 100644 (file)
@@ -177,6 +177,9 @@ SilcStack silc_stack_alloc(SilcUInt32 stack_size, SilcStack parent)
   if (stack_size < SILC_STACK_DEFAULT_SIZE)
     stack_size = SILC_STACK_DEFAULT_SIZE;
 
+  /* Align by 8 */
+  stack_size += ((-stack_size) % 8);
+
   if (parent) {
     /* Get stack from parent.  The stack itself is allocated from the
        parent (but does not consume parent's own stack). */
index 88032aa81eb7f97c56fe1b9656d1b7c2f329df32..c4415a17c15978d385ebddeb8ba70cce903ae372 100644 (file)
@@ -125,8 +125,7 @@ typedef void (*SilcStackOomHandler)(SilcStack stack, void *context);
  *    allocation by various routines.  Returns the pointer to the stack
  *    that must be freed with silc_stack_free function when it is not
  *    needed anymore.  If the `stack_size' is zero (0) by default a
- *    1 kilobyte (1024 bytes) stack is allocated.  If the `stack_size'
- *    is non-zero the byte value must be multiple by 8.
+ *    1 kilobyte (1024 bytes) stack is allocated.
  *
  *    If `parent' is non-NULL the created stack is a child of the `parent'
  *    stack.  All of childs the memory is allocated from the `parent' and
index 4b905385744a881edfde57a8c34c3e348840b401..34b6fc3fead140a024985a44912668bea998d2cd 100644 (file)
@@ -94,7 +94,7 @@ int main(int argc, char **argv)
   silc_stack_stats(stack);
 
   SILC_LOG_DEBUG(("Creating child stack"));
-  child = silc_stack_alloc(8192, stack);
+  child = silc_stack_alloc(8190, stack);
   if (!child)
     goto err;
   SILC_LOG_DEBUG(("Pushing %d times", NUM_ALLS / 2));