From f36359b30ecc68ee445dc33611532597a8b0df44 Mon Sep 17 00:00:00 2001 From: cherierm Date: Mon, 25 Sep 2006 16:17:59 +0000 Subject: [PATCH] Declare all variables at the begining for ANSI C standard compatibility. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2807 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/config.c | 2 +- src/xbt/dict.c | 42 +++++++++++++++++++++++++++++++----------- src/xbt/dict_cursor.c | 13 ++++++++++--- src/xbt/dict_multi.c | 34 +++++++++++++++++++++++++++++----- src/xbt/mallocator.c | 18 +++++++++++++----- 5 files changed, 84 insertions(+), 25 deletions(-) diff --git a/src/xbt/config.c b/src/xbt/config.c index def06a9978..99559a76f0 100644 --- a/src/xbt/config.c +++ b/src/xbt/config.c @@ -662,7 +662,7 @@ xbt_cfg_set_int(xbt_cfg_t cfg,const char*name, int val) { xbt_dynar_set(variable->content,0,&val); } else { - if (variable->max && xbt_dynar_length(variable->content) == variable->max) + if (variable->max && xbt_dynar_length(variable->content) == (unsigned long)variable->max) THROW3(mismatch_error,0, "Cannot add value %d to the config element %s since it's already full (size=%d)", val,name,variable->max); diff --git a/src/xbt/dict.c b/src/xbt/dict.c index 227347b76a..84c45869eb 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -169,10 +169,12 @@ void xbt_dict_set_ext(xbt_dict_t dict, int key_len, void *data, void_f_pvoid_t *free_ctn) { - xbt_assert(dict); - unsigned int hash_code = xbt_dict_hash_ext(key,key_len) % dict->table_size; + unsigned int hash_code; xbt_dictelm_t current, previous = NULL; + xbt_assert(dict); + + hash_code = xbt_dict_hash_ext(key,key_len) % dict->table_size; current = dict->table[hash_code]; while (current != NULL && @@ -237,11 +239,15 @@ void xbt_dict_set(xbt_dict_t dict, void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len) { - xbt_assert(dict); - unsigned int hash_code = xbt_dict_hash_ext(key,key_len) % dict->table_size; + + unsigned int hash_code; xbt_dictelm_t current; + xbt_assert(dict); + + hash_code = xbt_dict_hash_ext(key,key_len) % dict->table_size; + current = dict->table[hash_code]; while (current != NULL && (key_len != current->key_len || strncmp(key, current->key, key_len))) { @@ -268,11 +274,15 @@ void *xbt_dict_get_ext(xbt_dict_t dict, */ void *xbt_dict_get(xbt_dict_t dict, const char *key) { - xbt_assert(dict); - unsigned int hash_code = xbt_dict_hash(key) % dict->table_size; + + unsigned int hash_code ; xbt_dictelm_t current; + xbt_assert(dict); + + hash_code = xbt_dict_hash(key) % dict->table_size; + current = dict->table[hash_code]; while (current != NULL && (strcmp(key, current->key))) { current = current->next; @@ -316,11 +326,15 @@ void *xbt_dict_get_or_null(xbt_dict_t dict, void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len) { - xbt_assert(dict); - unsigned int hash_code = xbt_dict_hash_ext(key,key_len) % dict->table_size; + + unsigned int hash_code ; xbt_dictelm_t current, previous = NULL; + xbt_assert(dict); + + hash_code = xbt_dict_hash_ext(key,key_len) % dict->table_size; + current = dict->table[hash_code]; while (current != NULL && (key_len != current->key_len || strncmp(key, current->key, key_len))) { @@ -364,10 +378,12 @@ void xbt_dict_remove(xbt_dict_t dict, * \param dict the dict */ void xbt_dict_reset(xbt_dict_t dict) { - xbt_assert(dict); + int i; xbt_dictelm_t current, previous = NULL; + + xbt_assert(dict); if (dict->count == 0) return; @@ -399,9 +415,13 @@ int xbt_dict_length(xbt_dict_t dict) { * Add an already mallocated element to a dictionary. */ void xbt_dict_add_element(xbt_dict_t dict, xbt_dictelm_t element) { - xbt_assert(dict); - int hashcode = xbt_dict_hash_ext(element->key,element->key_len) % dict->table_size; + + int hashcode; + + xbt_assert(dict); + + hashcode = xbt_dict_hash_ext(element->key,element->key_len) % dict->table_size; element->next = dict->table[hashcode]; dict->table[hashcode] = element; } diff --git a/src/xbt/dict_cursor.c b/src/xbt/dict_cursor.c index 1110af7516..65411180a7 100644 --- a/src/xbt/dict_cursor.c +++ b/src/xbt/dict_cursor.c @@ -103,11 +103,16 @@ void xbt_dict_cursor_first(const xbt_dict_t dict, * \brief Move to the next element. */ void xbt_dict_cursor_step(xbt_dict_cursor_t cursor) { + + + xbt_dictelm_t current ; + int line; + DEBUG0("xbt_dict_cursor_step"); xbt_assert(cursor); - xbt_dictelm_t current = cursor->current; - int line = cursor->line; + current = cursor->current; + line = cursor->line; if (cursor->dict != NULL) { @@ -137,10 +142,12 @@ void xbt_dict_cursor_step(xbt_dict_cursor_t cursor) { int xbt_dict_cursor_get_or_free(xbt_dict_cursor_t *cursor, char **key, void **data) { - DEBUG0("xbt_dict_get_or_free"); xbt_dictelm_t current; + DEBUG0("xbt_dict_get_or_free"); + + if (!cursor || !(*cursor)) return FALSE; diff --git a/src/xbt/dict_multi.c b/src/xbt/dict_multi.c index 90ff8bf31d..62c999b291 100644 --- a/src/xbt/dict_multi.c +++ b/src/xbt/dict_multi.c @@ -97,13 +97,37 @@ xbt_multidict_set(xbt_dict_t mdict, xbt_dynar_push(lens,&thislen); } - TRY { - xbt_multidict_set_ext(mdict, keys, lens, data, free_ctn); - } CLEANUP { - xbt_dynar_free(&lens); - } CATCH(e) { + /*TRY + { + xbt_multidict_set_ext(mdict, keys, lens, data, free_ctn); + } + CLEANUP + { + xbt_dynar_free(&lens); + } + CATCH(e) + { RETHROW; + }*/ + + TRY + { + xbt_multidict_set_ext(mdict, keys, lens, data, free_ctn); + } + CLEANUP + { + xbt_dynar_free(&lens); } + CATCH(e) + { + RETHROW; + } + + + + + + } /** \brief Insert \e data under all the keys contained in \e keys, providing their sizes in \e lens. diff --git a/src/xbt/mallocator.c b/src/xbt/mallocator.c index 01f303f307..5f161967da 100644 --- a/src/xbt/mallocator.c +++ b/src/xbt/mallocator.c @@ -31,10 +31,14 @@ xbt_mallocator_t xbt_mallocator_new(int size, pvoid_f_void_t new_f, void_f_pvoid_t free_f, void_f_pvoid_t reset_f) { + + + xbt_mallocator_t m; + xbt_assert0(size > 0, "size must be positive"); - xbt_assert0(new_f != NULL && free_f != NULL && reset_f != NULL, - "invalid parameter"); - xbt_mallocator_t m = xbt_new0(s_xbt_mallocator_t, 1); + xbt_assert0(new_f != NULL && free_f != NULL && reset_f != NULL,"invalid parameter"); + + m = xbt_new0(s_xbt_mallocator_t, 1); m->objects = xbt_new0(void*, size); m->max_size = size; @@ -55,9 +59,11 @@ xbt_mallocator_t xbt_mallocator_new(int size, * \see xbt_mallocator_new() */ void xbt_mallocator_free(xbt_mallocator_t m) { - xbt_assert0(m != NULL, "Invalid parameter"); int i; + xbt_assert0(m != NULL, "Invalid parameter"); + + for (i = 0; i < m->current_size; i++) { m->free_f(m->objects[i]); } @@ -82,9 +88,11 @@ void xbt_mallocator_free(xbt_mallocator_t m) { * \see xbt_mallocator_release() */ void *xbt_mallocator_get(xbt_mallocator_t m) { + +void *object; xbt_assert0(m != NULL, "Invalid parameter"); - void *object; + if (m->current_size > 0) { /* there is at least an available object */ object = m->objects[--m->current_size]; -- 2.20.1