From a85b69a00898360e6237607a90a263570ad4b3ba Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 25 Dec 2007 16:47:26 +0000 Subject: [PATCH] silc_stack_alloc automatically aligns the stack size. --- CHANGES.RUNTIME | 5 +++++ TODO | 2 +- lib/silcutil/silcfsm.c | 10 +++++----- lib/silcutil/silcstack.c | 3 +++ lib/silcutil/silcstack.h | 3 +-- lib/silcutil/tests/test_silcstack.c | 2 +- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGES.RUNTIME b/CHANGES.RUNTIME index 4c2cef64..ff6ebd8a 100644 --- a/CHANGES.RUNTIME +++ b/CHANGES.RUNTIME @@ -1,3 +1,8 @@ +Tue Dec 25 18:44:27 EET 2007 Pekka Riikonen + + * 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 * Added silc_getopt to lib/silcutil/silcgetopt.[ch]. diff --git a/TODO b/TODO index 8fbf2c34..fd6156b4 100644 --- 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. diff --git a/lib/silcutil/silcfsm.c b/lib/silcutil/silcfsm.c index 3cef6d96..4ff23bab 100644 --- a/lib/silcutil/silcfsm.c +++ b/lib/silcutil/silcfsm.c @@ -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; diff --git a/lib/silcutil/silcstack.c b/lib/silcutil/silcstack.c index 88286d83..79f63d2f 100644 --- a/lib/silcutil/silcstack.c +++ b/lib/silcutil/silcstack.c @@ -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). */ diff --git a/lib/silcutil/silcstack.h b/lib/silcutil/silcstack.h index 88032aa8..c4415a17 100644 --- a/lib/silcutil/silcstack.h +++ b/lib/silcutil/silcstack.h @@ -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 diff --git a/lib/silcutil/tests/test_silcstack.c b/lib/silcutil/tests/test_silcstack.c index 4b905385..34b6fc3f 100644 --- a/lib/silcutil/tests/test_silcstack.c +++ b/lib/silcutil/tests/test_silcstack.c @@ -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)); -- 2.24.0