From a1bad7b84b3725d9ee4b542da9de8b85fa698e76 Mon Sep 17 00:00:00 2001 From: mquinson Date: Sun, 7 Aug 2005 14:09:29 +0000 Subject: [PATCH] Some more xbt_error_t eradication; change mismatch_error to not_found_error where appropriate git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1600 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/config.c | 51 ++++++++++++++++++++-------------------- src/xbt/dict.c | 10 ++++---- src/xbt/dict_elm.c | 53 ++++++++++++++++++------------------------ src/xbt/dict_multi.c | 33 ++++++++++++++------------ src/xbt/dict_private.h | 10 ++++---- src/xbt/ex.c | 17 +++++++------- src/xbt/log.c | 38 +++++++++++++++++------------- src/xbt/set.c | 2 +- src/xbt/sysdep.c | 1 - 9 files changed, 108 insertions(+), 107 deletions(-) diff --git a/src/xbt/config.c b/src/xbt/config.c index 81c8fb4d17..f2d57d0669 100644 --- a/src/xbt/config.c +++ b/src/xbt/config.c @@ -214,7 +214,7 @@ xbt_cfg_register(xbt_cfg_t cfg, TRY { res = xbt_dict_get((xbt_dict_t)cfg,name); } CATCH(e) { - if (e.category == mismatch_error) { + if (e.category == not_found_error) { found = 1; xbt_ex_free(e); } else { @@ -265,11 +265,12 @@ xbt_cfg_register(xbt_cfg_t cfg, * @arg name the name of the elem to be freed * * Note that it removes both the description and the actual content. + * Throws not_found when no such element exists. */ -xbt_error_t +void xbt_cfg_unregister(xbt_cfg_t cfg,const char *name) { - return xbt_dict_remove((xbt_dict_t)cfg,name); + xbt_dict_remove((xbt_dict_t)cfg,name); } /** @@ -397,10 +398,10 @@ static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, TRY { res = xbt_dict_get((xbt_dict_t)cfg,name); } CATCH(e) { - if (e.category == mismatch_error) { - THROW1(mismatch_error,0, - "No registered variable '%s' in this config set",name); + if (e.category == not_found_error) { xbt_ex_free(e); + THROW1(not_found_error,0, + "No registered variable '%s' in this config set",name); } RETHROW; } @@ -431,10 +432,10 @@ xbt_cfg_get_type(xbt_cfg_t cfg, const char *name) { TRY { variable = xbt_dict_get((xbt_dict_t)cfg,name); } CATCH(e) { - if (e.category == mismatch_error) { - THROW1(mismatch_error,0, - "Can't get the type of '%s' since this variable does not exist",name); + if (e.category == not_found_error) { xbt_ex_free(e); + THROW1(not_found_error,0, + "Can't get the type of '%s' since this variable does not exist",name); } RETHROW; } @@ -465,9 +466,9 @@ xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa) { TRY { type = xbt_cfg_get_type(cfg,name); } CATCH(e) { - if (e.category == mismatch_error) { + if (e.category == not_found_error) { xbt_ex_free(e); - THROW1(mismatch_error,0,"Can't set the property '%s' since it's not registered",name); + THROW1(not_found_error,0,"Can't set the property '%s' since it's not registered",name); } RETHROW; } @@ -602,9 +603,9 @@ xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options) { variable = xbt_dict_get((xbt_dict_t)cfg,name); } CATCH(e) { free(optionlist_cpy); - if (e.category == mismatch_error) { + if (e.category == not_found_error) { xbt_ex_free(e); - THROW1(mismatch_error,0,"No registrated variable corresponding to '%s'.",name); + THROW1(not_found_error,0,"No registrated variable corresponding to '%s'.",name); } RETHROW; } @@ -839,7 +840,7 @@ void xbt_cfg_rm_int(xbt_cfg_t cfg,const char*name, int val) { } } - THROW2(mismatch_error,0, + THROW2(not_found_error,0, "Can't remove the value %d of config element %s: value not found.",val,name); } @@ -871,7 +872,7 @@ void xbt_cfg_rm_double(xbt_cfg_t cfg,const char*name, double val) { } } - THROW2(mismatch_error,0, + THROW2(not_found_error,0, "Can't remove the value %f of config element %s: value not found.",val,name); } @@ -903,7 +904,7 @@ xbt_cfg_rm_string(xbt_cfg_t cfg,const char*name, const char *val) { } } - THROW2(mismatch_error,0, + THROW2(not_found_error,0, "Can't remove the value %s of config element %s: value not found.",val,name); } @@ -936,7 +937,7 @@ xbt_cfg_rm_host(xbt_cfg_t cfg,const char*name, const char *host,int port) { } } - THROW3(mismatch_error,0, + THROW3(not_found_error,0, "Can't remove the value %s:%d of config element %s: value not found.", host,port,name); } @@ -972,12 +973,12 @@ xbt_cfg_empty(xbt_cfg_t cfg,const char*name) { TRY { variable = xbt_dict_get((xbt_dict_t)cfg,name); } CATCH(e) { - if (e.category == mismatch_error) { - xbt_ex_free(e); - THROW1(mismatch_error,0, - "Can't empty '%s' since this config element does not exist", name); - } - RETHROW; + if (e.category != not_found_error) + RETHROW; + + xbt_ex_free(e); + THROW1(not_found_error,0, + "Can't empty '%s' since this config element does not exist", name); } if (variable) { @@ -1115,9 +1116,9 @@ xbt_dynar_t xbt_cfg_get_dynar (xbt_cfg_t cfg, const char *name) { TRY { variable = xbt_dict_get((xbt_dict_t)cfg,name); } CATCH(e) { - if (e.category == mismatch_error) { + if (e.category == not_found_error) { xbt_ex_free(e); - THROW1(mismatch_error,0, + THROW1(not_found_error,0, "No registered variable %s in this config set",name); } RETHROW; diff --git a/src/xbt/dict.c b/src/xbt/dict.c index 5dcb9e69f9..b10cab7431 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -146,7 +146,7 @@ xbt_dict_get_or_null(xbt_dict_t dict, TRY { res = xbt_dictelm_get(dict->head, key); } CATCH(e) { - if (e.category != mismatch_error) + if (e.category != not_found_error) RETHROW; xbt_ex_free(e); res=NULL; @@ -165,13 +165,13 @@ xbt_dict_get_or_null(xbt_dict_t dict, * * Remove the entry associated with the given \a key */ -xbt_error_t +void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len) { xbt_assert(dict); - return xbt_dictelm_remove_ext(dict->head, key, key_len); + xbt_dictelm_remove_ext(dict->head, key, key_len); } /** @@ -182,13 +182,13 @@ xbt_dict_remove_ext(xbt_dict_t dict, * * Remove the entry associated with the given \a key */ -xbt_error_t +void xbt_dict_remove(xbt_dict_t dict, const char *key) { if (!dict) THROW1(arg_error,0,"Asked to remove key %s from NULL dict",key); - return xbt_dictelm_remove(dict->head, key); + xbt_dictelm_remove(dict->head, key); } diff --git a/src/xbt/dict_elm.c b/src/xbt/dict_elm.c index 89874931d9..69ce028799 100644 --- a/src/xbt/dict_elm.c +++ b/src/xbt/dict_elm.c @@ -54,10 +54,10 @@ static void * _xbt_dictelm_get_rec(s_xbt_dictelm_t *head, const char *key, int key_len, int offset); -static xbt_error_t _xbt_dictelm_remove_rec(s_xbt_dictelm_t *head, - const char *key, - int key_len, - int offset); +static void _xbt_dictelm_remove_rec(s_xbt_dictelm_t *head, + const char *key, + int key_len, + int offset); static _XBT_INLINE void @@ -642,9 +642,8 @@ xbt_dictelm_set(s_xbt_dictelm_t **pp_head, * @key: the key to find data * @offset: offset on the key * @data: the data that we are looking for - * @Returns: xbt_error * - * Search the given @key. mismatch_error when not found. + * Search the given @key. Throws not_found_error when not found. */ static void * @@ -672,7 +671,7 @@ _xbt_dictelm_get_rec(s_xbt_dictelm_t *p_head, switch (match) { case 0: /* no child have a common prefix */ - THROW1(mismatch_error,0,"key '%s' not found",key); + THROW1(not_found_error,0,"key '%s' not found",key); case 1: /* A child have exactly this key => Got it */ { @@ -691,10 +690,10 @@ _xbt_dictelm_get_rec(s_xbt_dictelm_t *p_head, } case 3: /* The key is a prefix of the child => not found */ - THROW1(mismatch_error,0,"key %s not found",key); + THROW1(not_found_error,0,"key %s not found",key); case 4: /* A child share a common prefix with this key => not found */ - THROW1(mismatch_error,0,"key %s not found",key); + THROW1(not_found_error,0,"key %s not found",key); default: THROW_IMPOSSIBLE; @@ -708,9 +707,8 @@ _xbt_dictelm_get_rec(s_xbt_dictelm_t *p_head, * @head: the head of the dict * @key: the key to find data * @data: the data that we are looking for - * @Returns: xbt_error * - * Search the given @key. mismatch_error when not found. + * Search the given @key. Throws not_found_error when not found. */ void * xbt_dictelm_get_ext(s_xbt_dictelm_t *p_head, @@ -718,7 +716,7 @@ xbt_dictelm_get_ext(s_xbt_dictelm_t *p_head, int key_len) { /* there is no head, go to hell */ if (!p_head) - THROW1(mismatch_error,0,"Key '%s' not found in dict",key); + THROW2(not_found_error,0,"Key '%*s' not found in dict",key_len,key); return _xbt_dictelm_get_rec(p_head, key, key_len, 0); } @@ -729,9 +727,8 @@ xbt_dictelm_get_ext(s_xbt_dictelm_t *p_head, * @head: the head of the dict * @key: the key to find data * @data: the data that we are looking for - * @Returns: xbt_error * - * Search the given @key. mismatch_error when not found. + * Search the given @key. Throws not_found_error when not found. */ void * xbt_dictelm_get(s_xbt_dictelm_t *p_head, @@ -800,16 +797,14 @@ _collapse_if_need(xbt_dictelm_t head, * @head: the head of the dict * @key: the key of the data to be removed * @offset: offset on the key - * @Returns: xbt_error_t * - * Remove the entry associated with the given @key + * Remove the entry associated with the given @key. Throws not_found_error. */ -xbt_error_t +void _xbt_dictelm_remove_rec(xbt_dictelm_t head, const char *key, int key_len, int offset) { - xbt_error_t errcode = no_error; /* there is no key to search, we did enough recursion => kill current */ if (offset >= key_len) { @@ -829,7 +824,7 @@ _xbt_dictelm_remove_rec(xbt_dictelm_t head, head->key_len = 0; /* killme. Cleanup done one step higher in recursion */ } - return errcode; + return; } else { int match = 0; @@ -853,7 +848,7 @@ _xbt_dictelm_remove_rec(xbt_dictelm_t head, _xbt_dictelm_remove_rec(p_child, key, key_len, offset); _collapse_if_need(head, pos, old_offset); - return no_error; + return; } @@ -861,8 +856,7 @@ _xbt_dictelm_remove_rec(xbt_dictelm_t head, case 3: /* The key is a prefix of the child => not found */ case 4: /* A child share a common prefix with this key => not found */ - return mismatch_error; - + THROW2(not_found_error,0,"Unable to remove key '%*s': not found",key_len,key); default: THROW_IMPOSSIBLE; @@ -876,11 +870,10 @@ _xbt_dictelm_remove_rec(xbt_dictelm_t head, * * @head: the head of the dict * @key: the key of the data to be removed - * @Returns: xbt_error_t * - * Remove the entry associated with the given @key + * Remove the entry associated with the given @key. Throws not_found_err */ -xbt_error_t +void xbt_dictelm_remove_ext(xbt_dictelm_t head, const char *key, int key_len) { @@ -888,7 +881,7 @@ xbt_dictelm_remove_ext(xbt_dictelm_t head, if (!head) THROW1(arg_error,0,"Asked to remove key %s from NULL dict",key); - return _xbt_dictelm_remove_rec(head, key, key_len, 0); + _xbt_dictelm_remove_rec(head, key, key_len, 0); } /** @@ -896,14 +889,13 @@ xbt_dictelm_remove_ext(xbt_dictelm_t head, * * @head: the head of the dict * @key: the key of the data to be removed - * @Returns: xbt_error_t * - * Remove the entry associated with the given @key + * Throws not_found when applicable */ -xbt_error_t +void xbt_dictelm_remove(xbt_dictelm_t head, const char *key) { - return _xbt_dictelm_remove_rec(head, key, strlen(key),0); + _xbt_dictelm_remove_rec(head, key, strlen(key),0); } /*----[ _xbt_dict_dump_rec ]------------------------------------------------*/ @@ -981,7 +973,6 @@ _xbt_dictelm_dump_rec(xbt_dictelm_t head, * * @head: the head of the dict * @output: a function to dump each data in the tree - * @Returns: xbt_error_t * * Ouputs the content of the structure. (for debuging purpose). @ouput is a * function to output the data. If NULL, data won't be displayed. diff --git a/src/xbt/dict_multi.c b/src/xbt/dict_multi.c index 6db40206ca..89000e56c1 100644 --- a/src/xbt/dict_multi.c +++ b/src/xbt/dict_multi.c @@ -58,14 +58,13 @@ xbt_multidict_set_ext(xbt_dict_t mdict, TRY { nextlevel = xbt_dict_get_ext(thislevel, thiskey, thislen); } CATCH(e) { - if (e.category == arg_error || e.category == mismatch_error) { - /* make sure the dict of next level exists */ - nextlevel=xbt_dict_new(); - VERB1("Create a dict (%p)",nextlevel); - xbt_dict_set_ext(thislevel, thiskey, thislen, nextlevel, &_free_dict); - } else { + if (e.category != not_found_error) RETHROW; - } + + /* make sure the dict of next level exists */ + nextlevel=xbt_dict_new(); + VERB1("Create a dict (%p)",nextlevel); + xbt_dict_set_ext(thislevel, thiskey, thislen, nextlevel, &_free_dict); } } @@ -182,7 +181,7 @@ xbt_multidict_get(xbt_dict_t mdict, xbt_dynar_t keys) { * Removing a non-existant key is ok. */ -xbt_error_t +void xbt_multidict_remove_ext(xbt_dict_t mdict, xbt_dynar_t keys, xbt_dynar_t lens) { xbt_dict_t thislevel,nextlevel=NULL; int i; @@ -217,13 +216,13 @@ xbt_multidict_remove_ext(xbt_dict_t mdict, xbt_dynar_t keys, xbt_dynar_t lens) { xbt_dynar_get_cpy(keys, i, &thiskey); xbt_dynar_get_cpy(lens, i, &thislen); - return xbt_dict_remove_ext(thislevel, thiskey, thislen); + xbt_dict_remove_ext(thislevel, thiskey, thislen); } -xbt_error_t +void xbt_multidict_remove(xbt_dict_t mdict, xbt_dynar_t keys) { - xbt_error_t errcode; + xbt_ex_t e; xbt_dynar_t lens = xbt_dynar_new(sizeof(unsigned long int),NULL); int i; @@ -232,8 +231,12 @@ xbt_multidict_remove(xbt_dict_t mdict, xbt_dynar_t keys) { unsigned long int thislen = strlen(thiskey); xbt_dynar_push(lens,&thislen); } - - errcode = xbt_multidict_remove_ext(mdict, keys, lens); - xbt_dynar_free(&lens); - return errcode; + + TRY { + xbt_multidict_remove_ext(mdict, keys, lens); + } CLEANUP { + xbt_dynar_free(&lens); + } CATCH(e) { + RETHROW; + } } diff --git a/src/xbt/dict_private.h b/src/xbt/dict_private.h index e48877cef3..1a8a9f547d 100644 --- a/src/xbt/dict_private.h +++ b/src/xbt/dict_private.h @@ -55,11 +55,11 @@ void* xbt_dictelm_get_ext (s_xbt_dictelm_t *p_head, const char *key, int key_len); -xbt_error_t xbt_dictelm_remove (s_xbt_dictelm_t *p_head, - const char *key); -xbt_error_t xbt_dictelm_remove_ext(s_xbt_dictelm_t *p_head, - const char *key, - int key_len); +void xbt_dictelm_remove (s_xbt_dictelm_t *p_head, + const char *key); +void xbt_dictelm_remove_ext(s_xbt_dictelm_t *p_head, + const char *key, + int key_len); void xbt_dictelm_dump (s_xbt_dictelm_t *p_head, void_f_pvoid_t *output); diff --git a/src/xbt/ex.c b/src/xbt/ex.c index 1f0c064e4a..f56a69ef85 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -76,13 +76,14 @@ void xbt_ex_free(xbt_ex_t e) { /** \brief returns a short name for the given exception category */ const char * xbt_ex_catname(xbt_errcat_t cat) { switch (cat) { - case unknown_error: return "unknown_err"; - case arg_error: return "invalid_arg"; - case mismatch_error: return "mismatch"; - case system_error: return "system_err"; - case network_error: return "network_err"; - case timeout_error: return "timeout"; - case thread_error: return "thread_err"; - default: return "INVALID_ERR"; + case unknown_error: return "unknown_err"; + case arg_error: return "invalid_arg"; + case mismatch_error: return "mismatch"; + case not_found_error: return "not found"; + case system_error: return "system_err"; + case network_error: return "network_err"; + case timeout_error: return "timeout"; + case thread_error: return "thread_err"; + default: return "INVALID_ERR"; } } diff --git a/src/xbt/log.c b/src/xbt/log.c index ee613d911d..9345c63d4b 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -9,16 +9,17 @@ #include -#include "gras_config.h" /* to get a working stdarg.h */ #include #include /* snprintf */ +#include /* snprintf */ +#include "gras_config.h" /* to get a working stdarg.h */ #include "xbt_modinter.h" #include "xbt/misc.h" +#include "xbt/ex.h" #include "xbt/sysdep.h" #include "xbt/log.h" -#include "xbt/error.h" #include "xbt/dynar.h" /** \addtogroup XBT_log @@ -484,21 +485,16 @@ static void _xbt_log_parse_setting(const char* control_string, DEBUG1("This is for cat '%s'", set->catname); } -static xbt_error_t _xbt_log_cat_searchsub(xbt_log_category_t cat,char *name, - /*OUT*/xbt_log_category_t*whereto) { - xbt_error_t errcode; +static xbt_log_category_t _xbt_log_cat_searchsub(xbt_log_category_t cat,char *name) { xbt_log_category_t child; if (!strcmp(cat->name,name)) { - *whereto=cat; - return no_error; + return cat; } for(child=cat->firstChild ; child != NULL; child = child->nextSibling) { - errcode=_xbt_log_cat_searchsub(child,name,whereto); - if (errcode==no_error) - return no_error; + return _xbt_log_cat_searchsub(child,name); } - return old_mismatch_error; + THROW0(not_found_error,0,"No such category"); } static void _cleanup_double_spaces(char *s) { @@ -552,7 +548,6 @@ static void _cleanup_double_spaces(char *s) { * logging command! Typically, this is done from main(). */ void xbt_log_control_set(const char* control_string) { - xbt_error_t errcode; xbt_log_setting_t set; char *cs; char *p; @@ -572,6 +567,8 @@ void xbt_log_control_set(const char* control_string) { while (!done) { xbt_log_category_t cat; + int found; + xbt_ex_t e; p=strrchr(cs,' '); if (p) { @@ -582,15 +579,24 @@ void xbt_log_control_set(const char* control_string) { done = 1; } _xbt_log_parse_setting(p,set); - - errcode = _xbt_log_cat_searchsub(&_XBT_LOGV(root),set->catname,&cat); - if (errcode == old_mismatch_error) { + + TRY { + cat = _xbt_log_cat_searchsub(&_XBT_LOGV(root),set->catname); + found = 1; + } CATCH(e) { + if (e.category != not_found_error) + RETHROW; + xbt_ex_free(e); + found = 0; + DEBUG0("Store for further application"); DEBUG1("push %p to the settings",(void*)set); xbt_dynar_push(xbt_log_settings,&set); /* malloc in advance the next slot */ set = xbt_new(s_xbt_log_setting_t,1); - } else { + } + + if (found) { DEBUG0("Apply directly"); free(set->catname); xbt_log_threshold_set(cat,set->thresh); diff --git a/src/xbt/set.c b/src/xbt/set.c index f4bc0e11cc..e00677a860 100644 --- a/src/xbt/set.c +++ b/src/xbt/set.c @@ -72,7 +72,7 @@ void xbt_set_add (xbt_set_t set, found_in_dict = xbt_dict_get_ext (set->dict, elm->name, elm->name_len); } CATCH(e) { - if (e.category != mismatch_error) + if (e.category != not_found_error) RETHROW; found = 0; elm->ID = xbt_dynar_length( set->dynar ); diff --git a/src/xbt/sysdep.c b/src/xbt/sysdep.c index 6d86b28dca..0c347504db 100644 --- a/src/xbt/sysdep.c +++ b/src/xbt/sysdep.c @@ -12,7 +12,6 @@ #include "xbt/sysdep.h" #include "xbt/xbt_portability.h" /* private */ #include "xbt/log.h" -#include "xbt/error.h" #include "portable.h" -- 2.20.1