Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use homogeneous dictionaries whenever possible.
[simgrid.git] / src / gras / DataDesc / cbps.c
index 0bae0a2..cfb2b2a 100644 (file)
@@ -32,7 +32,7 @@ gras_cbps_t gras_cbps_new(void)
   res = xbt_new(s_gras_cbps_t, 1);
 
   res->lints = xbt_dynar_new(sizeof(int), NULL);
-  res->space = xbt_dict_new();
+  res->space = xbt_dict_new_homogeneous(NULL);
   /* no leak, the content is freed manually on block_end */
   res->frames = xbt_dynar_new(sizeof(xbt_dynar_t), NULL);
   res->globals = xbt_dynar_new(sizeof(char *), NULL);
@@ -87,13 +87,14 @@ gras_cbps_v_push(gras_cbps_t ps,
 
   TRY {
     varstack = xbt_dict_get(ps->space, name);
-  } CATCH(e) {
+  }
+  CATCH(e) {
     if (e.category != mismatch_error)
       RETHROW;
 
     XBT_DEBUG("Create a new variable stack for '%s' into the space", name);
     varstack = xbt_dynar_new(sizeof(gras_cbps_elm_t *), NULL);
-    xbt_dict_set(ps->space, varname, (void **) varstack, NULL);
+    xbt_dict_set(ps->space, name, (void **) varstack, NULL);
     xbt_ex_free(e);
     /* leaking, you think? only if you do not close all the openned blocks ;) */
   }
@@ -128,16 +129,17 @@ gras_cbps_v_pop(gras_cbps_t ps,
   XBT_DEBUG("pop(%s)", name);
   TRY {
     varstack = xbt_dict_get(ps->space, name);
-  } CATCH(e) {
+  }
+  CATCH(e) {
     if (e.category != mismatch_error)
       RETHROW;
 
     xbt_ex_free(e);
-    THROW1(not_found_error, 1, "Asked to pop the non-existant %s", name);
+    THROWF(not_found_error, 1, "Asked to pop the non-existant %s", name);
   }
   xbt_dynar_pop(varstack, &var);
 
-  if (!xbt_dynar_length(varstack)) {
+  if (xbt_dynar_is_empty(varstack)) {
     XBT_DEBUG("Last incarnation of %s poped. Kill it", name);
     xbt_dict_remove(ps->space, name);
     xbt_dynar_free(&varstack);
@@ -262,7 +264,7 @@ void gras_cbps_block_end(gras_cbps_t ps)
   unsigned int cursor = 0;
   char *name = NULL;
 
-  xbt_assert0(xbt_dynar_length(ps->frames),
+  xbt_assert(xbt_dynar_length(ps->frames),
               "More block_end than block_begin");
   xbt_dynar_pop(ps->frames, &frame);
 
@@ -275,13 +277,12 @@ void gras_cbps_block_end(gras_cbps_t ps)
     varstack = xbt_dict_get(ps->space, name);
     xbt_dynar_pop(varstack, &var);
 
-    if (!xbt_dynar_length(varstack)) {
+    if (xbt_dynar_is_empty(varstack)) {
       xbt_dict_remove(ps->space, name);
       xbt_dynar_free_container(&varstack);      /*already empty, save a test ;) */
     }
 
-    if (var->data)
-      free(var->data);
+    free(var->data);
     free(var);
     free(name);
   }
@@ -302,7 +303,7 @@ int gras_cbps_i_pop(gras_cbps_t ps)
 {
   int ret;
 
-  xbt_assert0(xbt_dynar_length(ps->lints) > 0,
+  xbt_assert(!xbt_dynar_is_empty(ps->lints),
               "gras_cbps_i_pop: no value to pop");
   ret = xbt_dynar_pop_as(ps->lints, int);
   XBT_DEBUG("pop %d as a size", ret);