X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b9be88949e6d656a862b588e8b050bd5cc71f6d9..eb5b6b0c3c4d9a38bb205b2c8bc9aeeba8674a25:/src/xbt/lib.c diff --git a/src/xbt/lib.c b/src/xbt/lib.c index 9929a072f1..7fa4bc7caa 100644 --- a/src/xbt/lib.c +++ b/src/xbt/lib.c @@ -1,6 +1,6 @@ /* lib - a generic library, variation over dictionary */ -/* Copyright (c) 2011. The SimGrid Team. +/* Copyright (c) 2011, 2013-2014. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -80,25 +80,28 @@ void xbt_lib_unset(xbt_lib_t lib, const char *key, int level, int invoke_callbac } void *obj = elts[level]; - if (!obj) { XBT_WARN("no key %s at level %d", key, level); - } else { - XBT_DEBUG("Remove %p of key %s at level %d", obj, key, level); - if (invoke_callback) - lib->free_f[level](obj); - elts[level] = NULL; + return; } + XBT_DEBUG("Remove %p of key %s at level %d", obj, key, level); + elts[level] = NULL; + /* check if there still remains any elements of this key */ + int empty = 1; int i; - for (i = 0; i < lib->levels; i++) { + for (i = 0; i < lib->levels && empty; i++) { if (elts[i] != NULL) - return; + empty = 0; + } + if (empty) { + /* there is no element at any level, so delete the key */ + xbt_dict_remove(lib->dict, key); } - /* there is no element at any level, so delete the key */ - xbt_dict_remove(lib->dict, key); + if (invoke_callback) + lib->free_f[level](obj); } void *xbt_lib_get_or_null(xbt_lib_t lib, const char *key, int level)