Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make sure that the code still compiles with the freaking paranoid gcc warning options...
[simgrid.git] / src / gras / DataDesc / ddt_create.c
index ea98f36..6caa963 100644 (file)
@@ -10,6 +10,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "xbt/misc.h" /* min()/max() */
+#include "xbt/ex.h"
 #include "gras/DataDesc/datadesc_private.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions");
@@ -39,7 +40,7 @@ static gras_datadesc_type_t gras_ddt_new(const char *name) {
 
   res->name = (char*)strdup(name);
   res->name_len = strlen(name);
-  res->flags = 0;
+  res->cycle = 0;
       
   xbt_set_add(gras_datadesc_set_local,
               (xbt_set_elm_t)res,&gras_ddt_freev);
@@ -48,31 +49,37 @@ static gras_datadesc_type_t gras_ddt_new(const char *name) {
 }
 
 /**
- * This returns NULL when no type of this name can be found
+ * This returns NULL no type of this name can be found instead of throwing exceptions which would complicate the GRAS_DEFINE_TYPE macro
  */
 gras_datadesc_type_t gras_datadesc_by_name(const char *name) {
-
-  gras_datadesc_type_t type;
-
-  XBT_IN1("(%s)",name);
-  if (xbt_set_get_by_name(gras_datadesc_set_local,
-                          name,(xbt_set_elm_t*)&type) == no_error) {
-    XBT_OUT;
-    return type;
-  } else { 
-    XBT_OUT;
-    return NULL;
+  xbt_ex_t e;
+  gras_datadesc_type_t res = NULL;
+  TRY {
+    res = (gras_datadesc_type_t)xbt_set_get_by_name(gras_datadesc_set_local,name);
+  } CATCH(e) {
+    if (e.category != not_found_error)
+      RETHROW;
+    xbt_ex_free(e);
+    res = NULL;
   }
+  return res;
 }
 
 /**
- * Retrieve a type from its code
+ * Retrieve a type from its code (or NULL if not found)
  */
-xbt_error_t gras_datadesc_by_id(long int              code,
-                                gras_datadesc_type_t *type) {
-  XBT_IN;
-  return xbt_set_get_by_id(gras_datadesc_set_local,
-                           code,(xbt_set_elm_t*)type);
+gras_datadesc_type_t gras_datadesc_by_id(long int code) {
+  xbt_ex_t e;
+  gras_datadesc_type_t res=NULL;
+  TRY {
+    res = (gras_datadesc_type_t)xbt_set_get_by_id(gras_datadesc_set_local,code);
+  } CATCH(e) {
+    if (e.category != not_found_error)
+      RETHROW;
+    xbt_ex_free(e);
+    res = NULL;
+  }
+  return res;
 }
 
 /**
@@ -97,7 +104,7 @@ gras_datadesc_type_t
                 "Redefinition of type %s does not match", name);
     VERB1("Discarding redefinition of %s",name);
     return res;
-  }
+  } 
   res = gras_ddt_new(name);
 
   for (arch = 0; arch < gras_arch_count; arch ++) {
@@ -247,7 +254,7 @@ gras_datadesc_struct_close(gras_datadesc_type_t struct_type) {
  */
 void
 gras_datadesc_cycle_set(gras_datadesc_type_t ddt) {
-  ddt->flags |= gras_datadesc_flag_cycle;
+  ddt->cycle = 1;
 }
 
 /**
@@ -259,7 +266,7 @@ gras_datadesc_cycle_set(gras_datadesc_type_t ddt) {
  */
 void
 gras_datadesc_cycle_unset(gras_datadesc_type_t ddt) {
-  ddt->flags &= ~(gras_datadesc_flag_cycle);
+  ddt->cycle = 0;
 }
 
 /** \brief Declare a new union description */
@@ -403,6 +410,7 @@ gras_datadesc_type_t
 
   XBT_IN1("(%s)",name);
   res = gras_datadesc_by_name(name);
+
   if (res) {
     xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
                 "Redefinition of type %s does not match", name);
@@ -619,12 +627,12 @@ gras_datadesc_dynar(gras_datadesc_type_t elm_t,
   return res;
 }
 
-xbt_error_t
+
+gras_datadesc_type_t
 gras_datadesc_import_nws(const char           *name,
                         const DataDescriptor *desc,
-                        unsigned long         howmany,
-              /* OUT */ gras_datadesc_type_t *dst) {
-  RAISE_UNIMPLEMENTED;
+                        unsigned long         howmany) {
+  THROW_UNIMPLEMENTED;
 }
 
 /**