Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Interface revolution: do not try to survive to malloc failure
[simgrid.git] / src / gras / DataDesc / ddt_exchange.c
index f4f98f2..05df6ce 100644 (file)
@@ -28,14 +28,14 @@ const char *gras_datadesc_cat_names[9] = {
 
 static gras_datadesc_type_t *int_type = NULL;
 static gras_datadesc_type_t *pointer_type = NULL;    
-static inline gras_error_t gras_dd_send_int(gras_socket_t *sock,             int  i);
-static inline gras_error_t gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i);
+static _GRAS_INLINE gras_error_t gras_dd_send_int(gras_socket_t *sock,             int  i);
+static _GRAS_INLINE gras_error_t gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i);
 
-static inline gras_error_t
+static _GRAS_INLINE gras_error_t
 gras_dd_alloc_ref(gras_dict_t *refs,  long int     size,
                  char       **r_ref, long int     r_len,
                  char       **l_ref);
-static inline int 
+static _GRAS_INLINE int 
 gras_dd_is_r_null(char **r_ptr, long int length);
 
 static gras_error_t 
@@ -56,7 +56,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
                       int                   subsize);
 
 
-static inline gras_error_t
+static _GRAS_INLINE gras_error_t
 gras_dd_send_int(gras_socket_t *sock,int i) {
 
   if (!int_type) {
@@ -68,7 +68,7 @@ gras_dd_send_int(gras_socket_t *sock,int i) {
   return gras_trp_chunk_send(sock, (char*)&i, int_type->size[GRAS_THISARCH]);
 }
 
-static inline gras_error_t
+static _GRAS_INLINE gras_error_t
 gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i) {
   gras_error_t errcode;
 
@@ -83,8 +83,7 @@ gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i) {
       TRY(gras_dd_convert_elm(int_type,1,r_arch, i,i));
   } else {
     void *ptr = gras_malloc(int_type->size[r_arch]);
-    if (!ptr)
-       RAISE_MALLOC;
+
     TRY(gras_trp_chunk_recv(sock, (char*)ptr, int_type->size[r_arch]));
     if (r_arch != GRAS_THISARCH)
       TRY(gras_dd_convert_elm(int_type,1,r_arch, ptr,i));
@@ -100,7 +99,7 @@ gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i) {
  *       of 'length' bytes set to 0.
  * FIXME: Check in configure?
  */
-static inline int 
+static _GRAS_INLINE int 
 gras_dd_is_r_null(char **r_ptr, long int length) {
   int i;
 
@@ -113,7 +112,7 @@ gras_dd_is_r_null(char **r_ptr, long int length) {
   return 1;
 }
 
-static inline gras_error_t
+static _GRAS_INLINE gras_error_t
 gras_dd_alloc_ref(gras_dict_t *refs,
                  long int     size,
                  char       **r_ref,
@@ -122,20 +121,17 @@ gras_dd_alloc_ref(gras_dict_t *refs,
   char *l_data = NULL;
 
   gras_assert1(size>0,"Cannot allocate %ld bytes!", size);
-  if (! (l_data = gras_malloc((size_t)size)) )
-    RAISE_MALLOC;
+  l_data = gras_malloc((size_t)size);
 
   *l_ref = l_data;
-  DEBUG2("l_data=%p, &l_data=%p",l_data,&l_data);
+  DEBUG2("l_data=%p, &l_data=%p",(void*)l_data,(void*)&l_data);
 
   DEBUG3("alloc_ref: r_ref=%p; *r_ref=%p, r_len=%ld",
-        r_ref, r_ref?*r_ref:NULL, r_len);
+        (void*)r_ref, (void*)(r_ref?*r_ref:NULL), r_len);
 #ifdef DETECT_CYCLE
   if (r_ref && !gras_dd_is_r_null( r_ref, r_len)) {
     gras_error_t errcode;
     void *ptr = gras_malloc(sizeof(void *));
-    if (!ptr)
-      RAISE_MALLOC;
 
     memcpy(ptr,l_ref, sizeof(void *));
 
@@ -208,14 +204,14 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t *d1,
 
   if (d1->send != d2->send) {
     DEBUG4("ddt_cmp: %s->send=%p  !=  %s->send=%p",
-          d1->name,d1->send, d2->name,d2->send);
-    return d1->send > d2->send ? 1 : -1;
+          d1->name,(void*)d1->send, d2->name,(void*)d2->send);
+    return 1; /* ISO C forbids ordered comparisons of pointers to functions */
   }
 
   if (d1->recv != d2->recv) {
     DEBUG4("ddt_cmp: %s->recv=%p  !=  %s->recv=%p",
-          d1->name,d1->recv, d2->name,d2->recv);
-    return d1->recv > d2->recv ? 1 : -1;
+          d1->name,(void*)d1->recv, d2->name,(void*)d2->recv);
+    return 1; /* ISO C forbids ordered comparisons of pointers to functions */
   }
 
   switch (d1->category_code) {
@@ -253,7 +249,7 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t *d1,
     
   case e_gras_datadesc_type_cat_union:
     if (d1->category.union_data.selector != d2->category.union_data.selector) 
-      return d1->category.union_data.selector > d2->category.union_data.selector ? 1 : -1;
+      return 1;  /* ISO C forbids ordered comparisons of pointers to functions */
     
     if (gras_dynar_length(d1->category.union_data.fields) != 
        gras_dynar_length(d2->category.union_data.fields))
@@ -276,7 +272,7 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t *d1,
     
   case e_gras_datadesc_type_cat_ref:
     if (d1->category.ref_data.selector != d2->category.ref_data.selector) 
-      return d1->category.ref_data.selector > d2->category.ref_data.selector ? 1 : -1;
+      return 1; /* ISO C forbids ordered comparisons of pointers to functions */
     
     if (d1->category.ref_data.type != d2->category.ref_data.type) 
       return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1;
@@ -290,7 +286,7 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t *d1,
       return d1->category.array_data.fixed_size > d2->category.array_data.fixed_size ? 1 : -1;
     
     if (d1->category.array_data.dynamic_size != d2->category.array_data.dynamic_size) 
-      return d1->category.array_data.dynamic_size > d2->category.array_data.dynamic_size ? 1 : -1;
+      return 1; /* ISO C forbids ordered comparisons of pointers to functions */
     
     break;
     
@@ -442,12 +438,12 @@ gras_datadesc_send_rec(gras_socket_t        *sock,
     }
     errcode = gras_dict_get_ext(refs,(char*)ref, sizeof(void*), &dummy);
     if (errcode == mismatch_error) {
-      VERB1("Sending data referenced at %p", *ref);
+      VERB1("Sending data referenced at %p", (void*)*ref);
       TRY(gras_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL));
       TRY(gras_datadesc_send_rec(sock,state,refs, sub_type, *ref));
       
     } else if (errcode == no_error) {
-      VERB1("Not sending data referenced at %p (already done)", *ref);
+      VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
     } else {
       return errcode;
     }
@@ -465,7 +461,7 @@ gras_datadesc_send_rec(gras_socket_t        *sock,
     
     /* determine and send the element count */
     count = array_data.fixed_size;
-    if (count <= 0) {
+    if (count == 0) {
       count = array_data.dynamic_size(state,data);
       gras_assert1(count >=0,
                   "Invalid (negative) array size for type %s",type->name);
@@ -509,8 +505,8 @@ gras_error_t gras_datadesc_send(gras_socket_t *sock,
   gras_cbps_t *state = NULL;
   gras_dict_t    *refs; /* all references already sent */
  
-  TRY(gras_dict_new(&refs));
-  TRY(gras_cbps_new(&state));
+  gras_dict_new(&refs);
+  state = gras_cbps_new();
 
   errcode = gras_datadesc_send_rec(sock,state,refs,type,(char*)src);
 
@@ -547,7 +543,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
   int                   cpt;
   gras_datadesc_type_t *sub_type;
 
-  VERB2("Recv a %s @%p", type->name, l_data);
+  VERB2("Recv a %s @%p", type->name, (void*)l_data);
   gras_assert(l_data);
 
   switch (type->category_code) {
@@ -558,8 +554,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
        TRY(gras_dd_convert_elm(type,1,r_arch, l_data,l_data));
     } else {
       void *ptr = gras_malloc(type->size[r_arch]);
-      if (!ptr)
-        RAISE_MALLOC;
+
       TRY(gras_trp_chunk_recv(sock, (char*)ptr, type->size[r_arch]));
       if (r_arch != GRAS_THISARCH)
        TRY(gras_dd_convert_elm(type,1,r_arch, ptr,l_data));
@@ -642,8 +637,8 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
       gras_assert(pointer_type);
     }
 
-    if (! (r_ref = gras_malloc(pointer_type->size[r_arch])) )
-      RAISE_MALLOC;
+    r_ref = gras_malloc(pointer_type->size[r_arch]);
+
     TRY(gras_trp_chunk_recv(sock, (char*)r_ref,
                            pointer_type->size[r_arch]));
 
@@ -661,7 +656,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
 
 
     if (errcode == mismatch_error) {
-      int subsubcount = -1;
+      int subsubcount = 0;
       void *l_referenced=NULL;
 
       VERB2("Receiving a ref to '%s', remotely @%p",
@@ -673,7 +668,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
        gras_datadesc_type_t *subsub_type;
 
        subsubcount = array_data.fixed_size;
-       if (subsubcount < 0)
+       if (subsubcount == 0)
          TRY(gras_dd_recv_int(sock, r_arch, &subsubcount));
 
        subsub_type = array_data.type;
@@ -718,13 +713,13 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
     array_data = type->category.array_data;
     /* determine element count locally, or from caller, or from peer */
     count = array_data.fixed_size;
-    if (count <= 0)
+    if (count == 0)
       count = subsize;
-    if (count < 0)
+    if (count == 0)
       TRY(gras_dd_recv_int(sock, r_arch, &count));
-    if (count < 0)
+    if (count == 0)
       RAISE1(mismatch_error,
-            "Invalid (negative) array size for type %s",type->name);
+            "Invalid (=0) array size for type %s",type->name);
 
     /* receive the content */
     sub_type = array_data.type;
@@ -738,8 +733,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
          TRY(gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data));
       } else {
        ptr = gras_malloc(sub_type->aligned_size[r_arch] * count);
-       if (!ptr)
-          RAISE_MALLOC;
+
        TRY(gras_trp_chunk_recv(sock, (char*)ptr, 
                                sub_type->size[r_arch] * count));
        if (r_arch != GRAS_THISARCH)
@@ -788,8 +782,8 @@ gras_datadesc_recv(gras_socket_t *sock,
   gras_cbps_t *state = NULL; /* callback persistent state */
   gras_dict_t    *refs;         /* all references already sent */
 
-  TRY(gras_dict_new(&refs));
-  TRY(gras_cbps_new(&state));
+  gras_dict_new(&refs);
+  state = gras_cbps_new();
 
   errcode = gras_datadesc_recv_rec(sock, state, refs, type, 
                                   r_arch, NULL, 0,