A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Avoid the temporary malloc in xbt_dynar_to_array.
[simgrid.git]
/
src
/
xbt
/
set.c
diff --git
a/src/xbt/set.c
b/src/xbt/set.c
index
2577b25
..
9158305
100644
(file)
--- a/
src/xbt/set.c
+++ b/
src/xbt/set.c
@@
-57,7
+57,7
@@
void xbt_set_free(xbt_set_t * set)
static int _xbt_set_get_id(xbt_set_t set)
{
int id;
static int _xbt_set_get_id(xbt_set_t set)
{
int id;
- if (
xbt_dynar_length(set->available_ids) > 0
) {
+ if (
!xbt_dynar_is_empty(set->available_ids)
) {
/* if there are some available ids */
xbt_dynar_pop(set->available_ids, &id);
} else {
/* if there are some available ids */
xbt_dynar_pop(set->available_ids, &id);
} else {
@@
-71,7
+71,7
@@
static int _xbt_set_get_id(xbt_set_t set)
*
* \param set set to populate
* \param elm element to add.
*
* \param set set to populate
* \param elm element to add.
- * \param free_func
How to add
the data
+ * \param free_func
how to free
the data
*
* elm->name must be set;
* if elm->name_len <= 0, it is recomputed. If >0, it's used as is;
*
* elm->name must be set;
* if elm->name_len <= 0, it is recomputed. If >0, it's used as is;
@@
-229,7
+229,7
@@
xbt_set_elm_t xbt_set_get_by_id(xbt_set_t set, int id)
res = xbt_dynar_get_as(set->dynar, id, xbt_set_elm_t);
if (res == NULL) {
res = xbt_dynar_get_as(set->dynar, id, xbt_set_elm_t);
if (res == NULL) {
- THROW
1
(not_found_error, 0, "Invalid id: %d", id);
+ THROW
F
(not_found_error, 0, "Invalid id: %d", id);
}
XBT_DEBUG("Lookup type of id %d (of %lu): %s",
id, xbt_dynar_length(set->dynar), res->name);
}
XBT_DEBUG("Lookup type of id %d (of %lu): %s",
id, xbt_dynar_length(set->dynar), res->name);
@@
-264,7
+264,7
@@
void xbt_set_cursor_first(xbt_set_t set, xbt_set_cursor_t * cursor)
if (!*cursor) {
XBT_DEBUG("Create the cursor on first use");
*cursor = xbt_new(s_xbt_set_cursor_t, 1);
if (!*cursor) {
XBT_DEBUG("Create the cursor on first use");
*cursor = xbt_new(s_xbt_set_cursor_t, 1);
- xbt_assert
0
(*cursor,
+ xbt_assert(*cursor,
"Malloc error during the creation of the cursor");
}
(*cursor)->set = set;
"Malloc error during the creation of the cursor");
}
(*cursor)->set = set;
@@
-383,10
+383,10
@@
static void search_name(xbt_set_t head, const char *key)
xbt_test_log(" Found %s (under ID %d)\n",
elm ? elm->data : "(null)", elm ? elm->ID : -1);
if (strcmp(key, elm->name))
xbt_test_log(" Found %s (under ID %d)\n",
elm ? elm->data : "(null)", elm ? elm->ID : -1);
if (strcmp(key, elm->name))
- THROW
2
(mismatch_error, 0, "The key (%s) is not the one expected (%s)",
+ THROW
F
(mismatch_error, 0, "The key (%s) is not the one expected (%s)",
key, elm->name);
if (strcmp(elm->name, elm->data))
key, elm->name);
if (strcmp(elm->name, elm->data))
- THROW
2
(mismatch_error, 0, "The name (%s) != data (%s)", key,
+ THROW
F
(mismatch_error, 0, "The name (%s) != data (%s)", key,
elm->name);
fflush(stdout);
}
elm->name);
fflush(stdout);
}
@@
-400,13
+400,13
@@
static void search_id(xbt_set_t head, int id, const char *key)
xbt_test_log("Found %s (data %s)",
elm ? elm->name : "(null)", elm ? elm->data : "(null)");
if (id != elm->ID)
xbt_test_log("Found %s (data %s)",
elm ? elm->name : "(null)", elm ? elm->data : "(null)");
if (id != elm->ID)
- THROW
2
(mismatch_error, 0,
+ THROW
F
(mismatch_error, 0,
"The found ID (%d) is not the one expected (%d)", elm->ID, id);
if (strcmp(key, elm->name))
"The found ID (%d) is not the one expected (%d)", elm->ID, id);
if (strcmp(key, elm->name))
- THROW
2
(mismatch_error, 0, "The key (%s) is not the one expected (%s)",
+ THROW
F
(mismatch_error, 0, "The key (%s) is not the one expected (%s)",
elm->name, key);
if (strcmp(elm->name, elm->data))
elm->name, key);
if (strcmp(elm->name, elm->data))
- THROW
2
(mismatch_error, 0, "The name (%s) != data (%s)",
+ THROW
F
(mismatch_error, 0, "The name (%s) != data (%s)",
elm->name, elm->data);
}
elm->name, elm->data);
}
@@
-432,9
+432,10
@@
static void search_not_found(xbt_set_t set, const char *data)
xbt_test_add("Search %s (expected not to be found)", data);
TRY {
xbt_set_get_by_name(set, data);
xbt_test_add("Search %s (expected not to be found)", data);
TRY {
xbt_set_get_by_name(set, data);
- THROW
1
(unknown_error, 0,
+ THROW
F
(unknown_error, 0,
"Found something which shouldn't be there (%s)", data);
"Found something which shouldn't be there (%s)", data);
- } CATCH(e) {
+ }
+ CATCH(e) {
if (e.category != not_found_error)
xbt_test_exception(e);
xbt_ex_free(e);
if (e.category != not_found_error)
xbt_test_exception(e);
xbt_ex_free(e);