Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
- Reduce the number of system headers loaded, overload some more system
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 9 Sep 2004 14:16:25 +0000 (14:16 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 9 Sep 2004 14:16:25 +0000 (14:16 +0000)
    calls (such as malloc to cast the result of the system one, and work
    properly on AIX)
  - Fix and reintroduce the config support

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@402 48e7efb5-ca39-0410-a469-dd3cf9ba447f

49 files changed:
ChangeLog
examples/ping/ping.c
include/Makefile.am
include/xbt.h
include/xbt/dynar.h
include/xbt/error.h
include/xbt/log.h
src/Makefile.am
src/gras/DataDesc/cbps.c
src/gras/DataDesc/datadesc.c
src/gras/DataDesc/datadesc_private.h
src/gras/DataDesc/ddt_convert.c
src/gras/DataDesc/ddt_create.c
src/gras/DataDesc/ddt_exchange.c
src/gras/DataDesc/ddt_parse.c
src/gras/DataDesc/ddt_parse.yy.c
src/gras/Msg/msg.c
src/gras/RL/gras_rl.c
src/gras/Transport/transport.c
src/gras/Transport/transport_plugin_buf.c
src/gras/Transport/transport_plugin_file.c
src/gras/Transport/transport_plugin_sg.c
src/gras/Transport/transport_plugin_tcp.c
src/gras/Virtu/process.c
src/gras/Virtu/rl_process.c
src/gras/Virtu/sg_process.c
src/gras_private.h
src/xbt/config.c
src/xbt/dict.c
src/xbt/dict_cursor.c
src/xbt/dict_elm.c
src/xbt/dynar.c
src/xbt/log.c
src/xbt/log_default_appender.c
src/xbt/module.c
src/xbt/set.c
testsuite/Makefile.am
testsuite/gras/datadesc_usage.c
testsuite/gras/mk_datadesc_structs.pl
testsuite/gras/trp_tcp_client.c
testsuite/run_tests.in
testsuite/xbt/config_usage.c
testsuite/xbt/dict_crash.c
testsuite/xbt/dict_usage.c
testsuite/xbt/dynar_double.c
testsuite/xbt/dynar_int.c
testsuite/xbt/dynar_string.c
testsuite/xbt/log_usage.c
testsuite/xbt/set_usage.c

index fcecf53..dc063e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,14 @@
+  Version 0.7 (protocol not changed; API changed)
+2004-09-08 Martin Quinson
+  - Reduce the number of system headers loaded, overload some more system
+    calls (such as malloc to cast the result of the system one, and work
+    properly on AIX)
+  - Fix and reintroduce the config support
+
 2004-09-07 Martin Quinson
-  Version 0.6.3 (protocol not changed; API changed)
-  - Source code reorganization to allow Arnaud to put the surf in the same
-    tree.
+  - Source code reorganization to allow Arnaud to surf all over there.
+  - Allow to document the logging categories
+  - Remove all uppercase from logging categories and useless cleanup in names.
 
 2004-08-18 Martin Quinson
   Version 0.6.2 (protocol not changed; API changed)
index 9305602..4c4b186 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "gras.h"
 
-GRAS_LOG_NEW_DEFAULT_CATEGORY(Ping);
+GRAS_LOG_NEW_DEFAULT_CATEGORY(Ping,"Messages specific to this example");
 
 /* **********************************************************************
  * Comon code
index be8f9b1..7572a09 100644 (file)
@@ -1,5 +1,6 @@
 include_HEADERS = gras.h gros.h
 nobase_include_HEADERS = \
+       gros/sysdep.h \
        gros/log.h gros/error.h \
        gros/module.h \
        gros/dynar.h gros/dict.h gros/set.h \
index 38f65ef..81c0fe1 100644 (file)
@@ -19,6 +19,8 @@
 
 #define GRAS_MAX_CHANNEL 10 /* FIXME: killme */
 
+#include <gros/sysdep.h>
+
 #include <gros/error.h>
 #include <gros/log.h>
 
index cee400b..67d94ff 100644 (file)
@@ -11,9 +11,6 @@
 #ifndef _GRAS_DYNAR_H
 #define _GRAS_DYNAR_H
 
-#include <stdlib.h> /* malloc() */
-#include <string.h> /* strlen() */
-
 typedef struct gras_dynar_s gras_dynar_t;
 
 /* pointer to a function freeing something */
index 029d263..46ada38 100644 (file)
@@ -15,6 +15,9 @@
 #include <stddef.h>    /* offsetof() */
 #include <sys/types.h>  /* size_t */
 #include <stdarg.h>
+
+#include <stdio.h> /* FIXME: Get rid of it */
+
 #ifdef HAVE_EXECINFO_H
 #include <execinfo.h>  /* to print the backtrace */
 #endif
@@ -68,7 +71,7 @@ typedef enum {
             __FILE__,__LINE__,                                \
              gras_error_name(errcode));                        \
      fflush(stdout);                                           \
-     abort();                                                  \
+     gras_abort();                                             \
   } } while(0)
 
 #define TRYEXPECT(action,expected_error)  do {                 \
@@ -77,7 +80,7 @@ typedef enum {
     fprintf(stderr,"Got error %s (instead of %s expected)\n",  \
            gras_error_name(errcode),                          \
            gras_error_name(expected_error));                  \
-    abort();                                                   \
+    gras_abort();                                              \
   }                                                            \
 } while(0)
 
@@ -143,8 +146,6 @@ typedef enum {
 #define RAISE_IMPOSSIBLE RAISE0(unknown_error,"The Impossible did happen")
 #define RAISE_UNIMPLEMENTED RAISE1(unknown_error,"Function %s unimplemented",__FUNCTION__)
 
-#define gras_abort abort
-
 #ifdef NDEBUG
 #define gras_assert(cond)
 #define gras_assert0(cond,msg)
index d918122..78027b6 100644 (file)
@@ -87,28 +87,26 @@ typedef enum {
  * GRAS_LOG_NEW_SUBCATEGORY:
  * @catName: name of new category
  * @parent: father of the new category in the tree
+ * @desc: string describing the purpose of this category
  *
  * Defines a new subcategory of the parent. 
  */
-//#ifndef NLOG
-#define GRAS_LOG_NEW_SUBCATEGORY(catName, parent)     \
+#define GRAS_LOG_NEW_SUBCATEGORY(catName, parent, desc) \
     extern gras_log_category_t _GRAS_LOGV(parent);    \
     gras_log_category_t _GRAS_LOGV(catName) = {       \
         &_GRAS_LOGV(parent), 0, 0,                    \
         #catName, gras_log_priority_uninitialized, 1, \
         0, 1                                          \
     };
-//#else /* No logging at all, please */
-//#define GRAS_LOG_NEW_SUBCATEGORY(catName,parent)
-//#endif
 
 /**
  * GRAS_LOG_NEW_CATEGORY:
  * @catName: name of new category
+ * @desc: string describing the purpose of this category
  *
  * Creates a new subcategory of the root category.
  */
-#define GRAS_LOG_NEW_CATEGORY(catName)  GRAS_LOG_NEW_SUBCATEGORY(catName, GRAS_LOG_ROOT_CAT)
+#define GRAS_LOG_NEW_CATEGORY(catName,desc)  GRAS_LOG_NEW_SUBCATEGORY(catName, GRAS_LOG_ROOT_CAT, desc)
 
 /**
  * GRAS_LOG_DEFAULT_CATEGORY:
@@ -127,24 +125,26 @@ typedef enum {
 /**
  * GRAS_LOG_NEW_DEFAULT_CATEGORY:
  * @cname: name of the cat
+ * @desc: string describing the purpose of this category
  *
  * Creates a new subcategory of the root category and makes it the default
  * (used by macros that don't explicitly specify a category).
  */
-#define GRAS_LOG_NEW_DEFAULT_CATEGORY(cname)        \
-    GRAS_LOG_NEW_CATEGORY(cname)                    \
+#define GRAS_LOG_NEW_DEFAULT_CATEGORY(cname,desc)        \
+    GRAS_LOG_NEW_CATEGORY(cname,desc)                    \
     GRAS_LOG_DEFAULT_CATEGORY(cname)
 
 /**
  * GRAS_LOG_NEW_DEFAULT_SUBCATEGORY:
  * @cname: name of the cat
  * @parent: name of the parent
+ * @desc: string describing the purpose of this category
  *
  * Creates a new subcategory of the parent category and makes it the default
  * (used by macros that don't explicitly specify a category).
  */
-#define GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(cname, parent)     \
-    GRAS_LOG_NEW_SUBCATEGORY(cname, parent)                 \
+#define GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(cname, parent, desc) \
+    GRAS_LOG_NEW_SUBCATEGORY(cname, parent, desc)             \
     GRAS_LOG_DEFAULT_CATEGORY(cname)
 
 /**
index 86b82dd..8eda89f 100644 (file)
@@ -1,6 +1,6 @@
 SUBDIRS=.  
 # amok not ported to GRAS NG yet
-AM_CFLAGS= -DNDEBUG 
+#AM_CFLAGS= -DNDEBUG 
 
 # -DNLOG   cuts absolutely all logs at compilation time.
 # -DNDEBUG cuts asserts and logs at "trace" and "debug" levels.
@@ -69,15 +69,17 @@ else
  lib_LTLIBRARIES= libgrasrl.la
 endif
 
-#  gros/config.c                               
 
 COMMON_S=\
   \
-  gros/module.c      gros/gros_interface.h                                      \
+  gros/gros_interface.h                                                         \
+  gros/sysdep.c                                                                 \
   gros/log.c         gros/log_default_appender.c   gros/error.c                 \
   gros/dynar.c                                                                  \
   gros/dict.c        gros/dict_elm.c               gros/dict_cursor.c           \
   gros/set.c                                                                    \
+  gros/module.c                                                                 \
+  gros/config.c                                                                 \
   \
   \
   gras/Transport/transport.c          gras/Transport/transport_private.h   gras/Transport/transport_plugin_buf.c  \
index 19562ec..f0c9c64 100644 (file)
@@ -9,7 +9,7 @@
    under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "gras/DataDesc/datadesc_private.h"
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(cbps,datadesc);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_cbps,datadesc,"callback persistant state");
 
 typedef struct {
   gras_datadesc_type_t *type;
@@ -28,7 +28,7 @@ struct s_gras_cbps {
 static void free_string(void *d);
 
 static void free_string(void *d){
-  free(*(void**)d);
+  gras_free(*(void**)d);
 }
 
 gras_error_t
@@ -36,7 +36,7 @@ gras_cbps_new(gras_cbps_t **dst) {
   gras_error_t errcode;
   gras_cbps_t *res;
 
-  if (!(res=malloc(sizeof(gras_cbps_t))))
+  if (!(res=gras_new(gras_cbps_t,1)))
     RAISE_MALLOC;
 
   TRY(gras_dynar_new(&(res->lints), sizeof(int), NULL));
@@ -61,7 +61,7 @@ gras_cbps_free(gras_cbps_t **state) {
   gras_dynar_free(    (*state)->frames    );
   gras_dynar_free(    (*state)->globals   );
 
-  free(*state);
+  gras_free(*state);
   *state = NULL;
 }
 
@@ -95,7 +95,7 @@ gras_cbps_v_push(gras_cbps_t        *ps,
     return errcode;
   }
  
-  p_var       = calloc(1, sizeof(gras_cbps_elm_t));
+  p_var       = gras_new0(gras_cbps_elm_t,1);
   p_var->type = ddt;
   p_var->data = data;
   
@@ -144,7 +144,7 @@ gras_cbps_v_pop (gras_cbps_t        *ps,
     *ddt = var->type;  
   data    = var->data;
   
-  free(var);
+  gras_free(var);
   
   gras_dynar_pop(ps->frames, &frame);
   {
@@ -156,7 +156,7 @@ gras_cbps_v_pop (gras_cbps_t        *ps,
       gras_dynar_get(frame, l, &_name);
       if (!strcmp(name, _name)) {
        gras_dynar_remove_at(frame, l, &_name);
-       free(_name);
+       gras_free(_name);
        break;
       }
     }
@@ -195,7 +195,7 @@ gras_cbps_v_set (gras_cbps_t        *ps,
     gras_dynar_new(&p_dynar, sizeof (gras_cbps_elm_t *), NULL);
     gras_dict_set(ps->space, name, (void **)p_dynar, NULL);
     
-    p_elm   = calloc(1, sizeof(gras_cbps_elm_t));
+    p_elm   = gras_new0(gras_cbps_elm_t,1);
     gras_dynar_push(ps->globals, &name);
   } else {
     gras_dynar_pop(p_dynar, &p_elm);
@@ -293,9 +293,9 @@ gras_cbps_block_end(gras_cbps_t *ps) {
       gras_dynar_free_container(varstack); /*already empty, save a test ;) */
     }
     
-    if (var->data) free(var->data);
-    free(var);
-    free(name);
+    if (var->data) gras_free(var->data);
+    gras_free(var);
+    gras_free(name);
   }
   gras_dynar_free_container(frame);/* we just emptied it */
   DEBUG0("<<< Block end");
index 889fc98..c2e5388 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "gras/DataDesc/datadesc_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(datadesc,GRAS);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(datadesc,gras,"Data description");
 /* FIXME: make this host-dependent using a trick such as UserData*/
 gras_set_t *gras_datadesc_set_local=NULL;
 
index f21bcc2..8216dde 100644 (file)
@@ -49,11 +49,10 @@ typedef struct {
 
   int endian;
 
-  int sizeof_scalars[9]; /* char,short,int,long,long_long,
-                           pdata,pfunc,
-                           float,double */
-
-  int struct_boundary;
+  int sizeofs[9]; /* char,short,int,long,long_long,
+                  pdata,pfunc,
+                  float,double */
+  int boundaries[9]; /* idem */
 } gras_arch_desc_t;
 
 extern const gras_arch_desc_t gras_arches[gras_arch_count];
index 22cf169..234da3b 100644 (file)
@@ -14,7 +14,8 @@
 
 #include "gras/DataDesc/datadesc_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(convert,datadesc);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_convert,datadesc,
+                                "Inter-architecture convertions");
 
 /***
  *** Table of all known architectures:
index a122879..904b316 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "gras/DataDesc/datadesc_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions");
 
 /**
  * gras_ddt_freev:
@@ -32,11 +32,10 @@ gras_ddt_new(const char            *name,
   gras_datadesc_type_t *res;
 
   GRAS_IN1("(%s)",name);
-  res=malloc(sizeof(gras_datadesc_type_t));
+  res=gras_new0(gras_datadesc_type_t,1);
   if (!res) 
     RAISE_MALLOC;
 
-  memset(res, 0, sizeof(gras_datadesc_type_t));
   res->name = strdup(name);
   res->name_len = strlen(name);
       
@@ -113,7 +112,7 @@ gras_datadesc_scalar(const char                      *name,
   for (arch = 0; arch < gras_arch_count; arch ++) {
     long int sz;
     long int mask;
-    res->size[arch] = gras_arches[arch].sizeof_scalars[type];
+    res->size[arch] = gras_arches[arch].sizeofs[type];
 
     sz = res->size[arch];
     mask = sz;
@@ -163,8 +162,8 @@ void gras_dd_cat_field_free(void *f) {
   GRAS_IN;
   if (field) {
     if (field->name) 
-      free(field->name);
-    free(field);
+      gras_free(field->name);
+    gras_free(field);
   }
   GRAS_OUT;
 }
@@ -234,24 +233,23 @@ gras_datadesc_struct_append(gras_datadesc_type_t  *struct_type,
               "Cannot add a dynamically sized field in structure %s",
               struct_type->name);
     
-  field=malloc(sizeof(gras_dd_cat_field_t));
+  field=gras_new(gras_dd_cat_field_t,1);
   if (!field)
     RAISE_MALLOC;
 
   field->name   = strdup(name);
 
   DEBUG0("----------------");
-  DEBUG4("PRE s={size=%ld,align=%ld,asize=%ld} struct_boundary=%d",
+  DEBUG3("PRE s={size=%ld,align=%ld,asize=%ld}",
         struct_type->size[GRAS_THISARCH], 
         struct_type->alignment[GRAS_THISARCH], 
-        struct_type->aligned_size[GRAS_THISARCH],
-        gras_arches[GRAS_THISARCH].struct_boundary);
+        struct_type->aligned_size[GRAS_THISARCH]);
      
      
   for (arch=0; arch<gras_arch_count; arch ++) {
     field->offset[arch] = aligned(struct_type->size[arch],
                                  min(field_type->alignment[arch],
-                                     gras_arches[arch].struct_boundary));
+                                     gras_arches[arch].boundaries));
 
     struct_type->size[arch] = field->offset[arch] + field_type->size[arch];
     struct_type->alignment[arch] = max(struct_type->alignment[arch],
@@ -357,17 +355,13 @@ gras_datadesc_union_append(gras_datadesc_type_t  *union_type,
     return no_error;
   }
     
-  field=malloc(sizeof(gras_dd_cat_field_t));
+  field=gras_new0(gras_dd_cat_field_t,1);
   if (!field)
     RAISE_MALLOC;
 
   field->name   = strdup(name);
-  for (arch=0; arch<gras_arch_count; arch ++) {
-    field->offset[arch] = 0; /* that's the purpose of union ;) */
-  }
   field->type   = field_type;
-  field->pre    = NULL;
-  field->post   = NULL;
+  /* All offset are left to 0 in an union */
   
   TRY(gras_dynar_push(union_type->category.union_data.fields, &field));
 
@@ -609,7 +603,7 @@ gras_error_t
 gras_datadesc_ref_pop_arr(gras_datadesc_type_t  *element_type,
                          gras_datadesc_type_t **dst) {
   gras_error_t errcode;
-  char *name=malloc(strlen(element_type->name) + 4);
+  char *name=(char*)gras_malloc(strlen(element_type->name) + 4);
 
   sprintf(name,"%s[]",element_type->name);
 
@@ -619,7 +613,7 @@ gras_datadesc_ref_pop_arr(gras_datadesc_type_t  *element_type,
   sprintf(name,"%s[]*",element_type->name);
   TRY(gras_datadesc_ref(name,*dst,dst));
 
-  free(name);
+  gras_free(name);
 
   return no_error;
 }
@@ -770,6 +764,6 @@ void gras_datadesc_free(gras_datadesc_type_t *type) {
     /* datadesc was invalid. Killing it is like euthanasy, I guess */
     break;
   }
-  free(type->name);
-  free(type);
+  gras_free(type->name);
+  gras_free(type);
 }
index d554ed1..fd9d4a5 100644 (file)
@@ -11,7 +11,8 @@
 #include "gras/DataDesc/datadesc_private.h"
 #include "gras/Transport/transport_interface.h" /* gras_trp_chunk_send/recv */
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(exchange,datadesc);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_exchange,datadesc,
+                                "Sending data over the network");
 
 #undef DETECT_CYCLE
 /* CRUDE HACK to turn all cycle detection of */
@@ -81,12 +82,13 @@ gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i) {
     if (r_arch != GRAS_THISARCH)
       TRY(gras_dd_convert_elm(int_type,1,r_arch, i,i));
   } else {
-    void *ptr = NULL;
-    ptr = malloc((size_t)int_type->size[r_arch]);
+    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));
-    free(ptr);
+    gras_free(ptr);
   }
   DEBUG1("recv_int(%d)",*i);
 
@@ -120,7 +122,7 @@ gras_dd_alloc_ref(gras_dict_t *refs,
   char *l_data = NULL;
 
   gras_assert1(size>0,"Cannot allocate %ld bytes!", size);
-  if (! (l_data = malloc((size_t)size)) )
+  if (! (l_data = gras_malloc((size_t)size)) )
     RAISE_MALLOC;
 
   *l_ref = l_data;
@@ -131,7 +133,7 @@ gras_dd_alloc_ref(gras_dict_t *refs,
 #ifdef DETECT_CYCLE
   if (r_ref && !gras_dd_is_r_null( r_ref, r_len)) {
     gras_error_t errcode;
-    void *ptr = malloc(sizeof(void *));
+    void *ptr = gras_malloc(sizeof(void *));
     if (!ptr)
       RAISE_MALLOC;
 
@@ -139,7 +141,7 @@ gras_dd_alloc_ref(gras_dict_t *refs,
 
     DEBUG2("Insert %p under %p",*(void**)ptr, *(void**)r_ref);
 
-    TRY(gras_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, free));
+    TRY(gras_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, gras_free));
   }
 #endif
   return no_error;
@@ -555,12 +557,13 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
       if (r_arch != GRAS_THISARCH)
        TRY(gras_dd_convert_elm(type,1,r_arch, l_data,l_data));
     } else {
-      void *ptr = NULL;
-      ptr = malloc((size_t)type->size[r_arch]);
+      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));
-      free(ptr);
+      gras_free(ptr);
     }
     break;
 
@@ -639,7 +642,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
       gras_assert(pointer_type);
     }
 
-    if (! (r_ref = malloc((size_t)pointer_type->size[r_arch])) )
+    if (! (r_ref = gras_malloc(pointer_type->size[r_arch])) )
       RAISE_MALLOC;
     TRY(gras_trp_chunk_recv(sock, (char*)r_ref,
                            pointer_type->size[r_arch]));
@@ -649,7 +652,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
       VERB1("Not receiving data remotely referenced @%p since it's NULL",
            *(void **)r_ref);
       *(void**)l_data = NULL;
-      free(r_ref);
+      gras_free(r_ref);
       break;
     }
     errcode = gras_dict_get_ext(refs,
@@ -702,7 +705,7 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
     } else {
       return errcode;
     }
-    free(r_ref);
+    gras_free(r_ref);
     break;
   }
 
@@ -734,12 +737,14 @@ gras_datadesc_recv_rec(gras_socket_t        *sock,
        if (r_arch != GRAS_THISARCH)
          TRY(gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data));
       } else {
-       ptr = malloc((size_t)sub_type->aligned_size[r_arch] * count);
+       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)
          TRY(gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data));
-       free(ptr);
+       gras_free(ptr);
       }
     } else {
       /* not scalar content, get it recursively (may contain pointers) */
index 1fd158f..cf3a2ff 100644 (file)
@@ -13,7 +13,8 @@
 #include "gras/DataDesc/datadesc_private.h"
 #include "gras/DataDesc/ddt_parse.yy.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_parse,datadesc);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_parse,datadesc,
+  "Parsing C data structures to build GRAS data description");
 
 typedef struct s_type_modifier{
   short is_unsigned;
@@ -110,11 +111,11 @@ static gras_error_t change_to_fixed_array(gras_dynar_t *dynar, long int size) {
 
   GRAS_IN;
   gras_dynar_pop(dynar,&former);
-  array.type_name=malloc(strlen(former.type->name)+20);
+  array.type_name=(char*)gras_malloc(strlen(former.type->name)+20);
   DEBUG2("Array specification (size=%ld, elm='%s'), change pushed type",
         size,former.type_name);
   sprintf(array.type_name,"%s[%ld]",former.type_name,size);
-  free(former.type_name);
+  gras_free(former.type_name);
 
   TRY(gras_datadesc_array_fixed(array.type_name, former.type, size, &array.type)); /* redeclaration are ignored */
 
@@ -131,10 +132,10 @@ static gras_error_t change_to_ref(gras_dynar_t *dynar) {
 
   GRAS_IN;
   gras_dynar_pop(dynar,&former);
-  ref.type_name=malloc(strlen(former.type->name)+2);
+  ref.type_name=(char*)gras_malloc(strlen(former.type->name)+2);
   DEBUG1("Ref specification (elm='%s'), change pushed type", former.type_name);
   sprintf(ref.type_name,"%s*",former.type_name);
-  free(former.type_name);
+  gras_free(former.type_name);
 
   TRY(gras_datadesc_ref(ref.type_name, former.type, &ref.type)); /* redeclaration are ignored */
 
@@ -156,7 +157,7 @@ static gras_error_t change_to_ref_pop_array(gras_dynar_t *dynar) {
   ref.type_name = strdup(ref.type->name);
   ref.name = former.name;
 
-  free(former.type_name);
+  gras_free(former.type_name);
 
   TRY(gras_dynar_push(dynar,&ref));
   GRAS_OUT;
@@ -372,14 +373,14 @@ static gras_error_t parse_statement(char   *definition,
 
        DEBUG2("Anotation: %s=%s",keyname,keyval);
        if (!strcmp(keyname,"size")) {
-         free(keyname);
+         gras_free(keyname);
          if (!identifier.tm.is_ref)
            PARSE_ERROR0("Size annotation for a field not being a reference");
          identifier.tm.is_ref--;
 
          if (!strcmp(keyval,"1")) {
            TRY(change_to_ref(identifiers));
-           free(keyval);
+           gras_free(keyval);
            continue;
          } else {
            char *p;
@@ -390,7 +391,7 @@ static gras_error_t parse_statement(char     *definition,
            if (fixed) {
              TRY(change_to_fixed_array(identifiers,atoi(keyval)));
              TRY(change_to_ref(identifiers));
-             free(keyval);
+             gras_free(keyval);
              continue;
 
            } else {
@@ -490,8 +491,8 @@ static gras_datadesc_type_t *parse_struct(char *definition) {
 
       VERB2("Append field '%s' to %p",field.name, struct_type);      
       TRYFAIL(gras_datadesc_struct_append(struct_type, field.name, field.type));
-      free(field.name);
-      free(field.type_name);
+      gras_free(field.name);
+      gras_free(field.type_name);
 
     }
     gras_dynar_reset(identifiers);
@@ -502,7 +503,7 @@ static gras_datadesc_type_t *parse_struct(char *definition) {
       DEBUG1("struct_type=%p",struct_type);
       VERB2("Push field '%s' into size stack of %p", name, struct_type);
       gras_datadesc_cb_field_push(struct_type, name);
-      free(name);
+      gras_free(name);
     }
     gras_dynar_reset(fields_to_push);
   }
@@ -579,7 +580,7 @@ gras_datadesc_parse(const char            *name,
   for (C_count=0; C_statement[C_count] != '\0'; C_count++)
     if (C_statement[C_count] == ';' || C_statement[C_count] == '{')
       semicolon_count++;
-  definition = malloc(C_count + semicolon_count + 1);
+  definition = (char*)gras_malloc(C_count + semicolon_count + 1);
   for (C_count=0,def_count=0; C_statement[C_count] != '\0'; C_count++) {
     definition[def_count++] = C_statement[C_count];
     if (C_statement[C_count] == ';' || C_statement[C_count] == '{') {
@@ -610,7 +611,7 @@ gras_datadesc_parse(const char            *name,
 
   gras_ddt_parse_pointer_string_close();
   VERB0("end of _gras_ddt_type_parse()");
-  free(definition);
+  gras_free(definition);
   /* register it under the name provided as symbol */
   if (strcmp(res->name,name)) {
     ERROR2("In GRAS_DEFINE_TYPE, the provided symbol (here %s) must be the C type name (here %s)",
index b0775f7..0d652ba 100644 (file)
@@ -441,7 +441,7 @@ char *yytext;
   int gras_ddt_parse_char_pos = 0;
   int gras_ddt_parse_tok_num = 0;
   const char *definition;
-  GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(lexer,ddt_parse);
+  GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_lexer,ddt_parse,"Lexer of the parsing");
 #define SHOW_WHERE DEBUG4("%d:%d (char #%d): seen '%s'", gras_ddt_parse_line_pos,gras_ddt_parse_col_pos,gras_ddt_parse_char_pos,yytext)
 #define annotate 1
 #define comment 2
index d2c731e..df0548b 100644 (file)
@@ -13,7 +13,7 @@
 #include "gras/Transport/transport_interface.h" /* gras_trp_chunk_send/recv */
 #include "gras/Virtu/virtu_interface.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(msg,GRAS);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(msg,gras,"High level messaging");
 
 gras_set_t *_gras_msgtype_set = NULL;
 static char GRAS_header[6];
@@ -60,8 +60,8 @@ gras_msg_exit(void) {
 void gras_msgtype_free(void *t) {
   gras_msgtype_t *msgtype=(gras_msgtype_t *)t;
   if (msgtype) {
-    free(msgtype->name);
-    free(msgtype);
+    gras_free(msgtype->name);
+    gras_free(msgtype);
   }
 }
 
@@ -77,7 +77,7 @@ static char *make_namev(const char *name, short int ver) {
   if (!ver)
     return (char *)name;
 
-  namev = malloc(strlen(name)+2+3+1);
+  namev = (char*)gras_malloc(strlen(name)+2+3+1);
 
   if (namev) {
       sprintf(namev,"%s_v%d",name,ver);
@@ -142,7 +142,7 @@ gras_msgtype_declare_v(const char            *name,
     return errcode; /* Was expecting for mismatch_error */
   }
 
-  if (! (msgtype = malloc(sizeof(gras_msgtype_t))) ) 
+  if (! (msgtype = gras_new(gras_msgtype_t,1)) ) 
     RAISE_MALLOC;
 
   msgtype->name = (namev == name ? strdup(name) : namev);
@@ -181,7 +181,7 @@ gras_msgtype_t * gras_msgtype_by_namev(const char      *name,
   if (errcode != no_error)
     res = NULL;
   if (name != namev) 
-    free(namev);
+    gras_free(namev);
   
   return res;
 }
@@ -260,14 +260,14 @@ gras_msg_recv(gras_socket_t   *sock,
           "Got error %s while retrieving the type associated to messages '%s'",
           gras_error_name(errcode),msg_name);
   /* FIXME: Survive unknown messages */
-  free(msg_name);
+  gras_free(msg_name);
 
   *payload_size=gras_datadesc_size((*msgtype)->ctn_type);
   gras_assert2(*payload_size > 0,
               "%s %s",
               "Dynamic array as payload is forbided for now (FIXME?).",
               "Reference to dynamic array is allowed.");
-  *payload = malloc(*payload_size);
+  *payload = gras_malloc(*payload_size);
   TRY(gras_datadesc_recv(sock, (*msgtype)->ctn_type, r_arch, *payload));
 
   return no_error;
@@ -314,7 +314,7 @@ gras_msg_wait(double                 timeout,
     if (msg.type->code == msgt_want->code) {
       *expeditor = msg.expeditor;
       memcpy(payload, msg.payload, msg.payload_size);
-      free(msg.payload);
+      gras_free(msg.payload);
       gras_dynar_cursor_rm(pd->msg_queue, &cpt);
       VERB0("The waited message was queued");
       return no_error;
@@ -326,7 +326,7 @@ gras_msg_wait(double                 timeout,
     TRY(gras_msg_recv(*expeditor, &msgt_got, &payload_got, &payload_size_got));
     if (msgt_got->code == msgt_want->code) {
       memcpy(payload, payload_got, payload_size_got);
-      free(payload_got);
+      gras_free(payload_got);
       VERB0("Got waited message");
       return no_error;
     }
@@ -407,7 +407,7 @@ gras_msg_handle(double timeOut) {
          cpt+1,cb,msgtype->name);
     if ((*cb)(expeditor,payload)) {
       /* cb handled the message */
-      free(payload);
+      gras_free(payload);
       return no_error;
     }
   }
@@ -422,7 +422,7 @@ gras_cbl_free(void *data){
   gras_cblist_t *list=*(void**)data;
   if (list) {
     gras_dynar_free(list->cbs);
-    free(list);
+    gras_free(list);
   }
 }
 
@@ -446,7 +446,7 @@ gras_cb_register(gras_msgtype_t *msgtype,
   }
   if (!list) {
     /* First cb? Create room */
-    list = malloc(sizeof(gras_cblist_t));
+    list = gras_new(gras_cblist_t,1);
     if (!list)
       RAISE_MALLOC;
 
index bb3729a..9f7575e 100644 (file)
@@ -26,7 +26,7 @@
 #include "timeouts.h"
 #include "protocol.h"
 
-GRAS_LOG_NEW_DEFAULT_CATEGORY(rl);
+GRAS_LOG_NEW_DEFAULT_CATEGORY(rl,"Real Life");
                              
 /* globals */
 static grasProcessData_t *_grasProcessData;
index 1e369c0..5d440fc 100644 (file)
@@ -8,11 +8,9 @@
 /* This program is free software; you can redistribute it and/or modify it
    under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include <time.h>       /* time() */
-
 #include "gras/Transport/transport_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(transport,GRAS);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(transport,gras,"Conveying bytes over the network");
 
 static gras_dict_t  *_gras_trp_plugins;     /* All registered plugins */
 static void gras_trp_plugin_free(void *p); /* free one of the plugins */
@@ -26,15 +24,13 @@ gras_error_t
 gras_trp_plugin_new(const char *name, gras_trp_setup_t setup) {
   gras_error_t errcode;
 
-  gras_trp_plugin_t *plug = malloc(sizeof(gras_trp_plugin_t));
+  gras_trp_plugin_t *plug = gras_new0(gras_trp_plugin_t, 1);
   
   DEBUG1("Create plugin %s",name);
 
   if (!plug) 
     RAISE_MALLOC;
 
-  memset(plug,0,sizeof(gras_trp_plugin_t));
-
   plug->name=strdup(name);
   if (!plug->name)
     RAISE_MALLOC;
@@ -43,8 +39,8 @@ gras_trp_plugin_new(const char *name, gras_trp_setup_t setup) {
   switch (errcode) {
   case mismatch_error:
     /* SG plugin return mismatch when in RL mode (and vice versa) */
-    free(plug->name);
-    free(plug);
+    gras_free(plug->name);
+    gras_free(plug);
     break;
 
   case no_error:
@@ -53,7 +49,7 @@ gras_trp_plugin_new(const char *name, gras_trp_setup_t setup) {
     break;
 
   default:
-    free(plug);
+    gras_free(plug);
     return errcode;
   }
   return no_error;
@@ -91,11 +87,11 @@ void gras_trp_plugin_free(void *p) {
       plug->exit(plug);
     } else if (plug->data) {
       DEBUG1("Plugin %s lacks exit(). Free data anyway.",plug->name);
-      free(plug->data);
+      gras_free(plug->data);
     }
 
-    free(plug->name);
-    free(plug);
+    gras_free(plug->name);
+    gras_free(plug);
   }
 }
 
@@ -110,7 +106,7 @@ gras_error_t gras_trp_socket_new(int incoming,
 
   gras_socket_t *sock;
 
-  if (! (sock=malloc(sizeof(gras_socket_t))) )
+  if (! (sock=gras_new(gras_socket_t,1)) )
     RAISE_MALLOC;
   DEBUG1("Create a new socket (%p)", sock);
 
@@ -165,7 +161,7 @@ gras_socket_server(unsigned short port,
         sock->accepting?'y':'n');
 
   if (errcode != no_error) {
-    free(sock);
+    gras_free(sock);
     return errcode;
   }
 
@@ -210,7 +206,7 @@ gras_socket_client(const char *host,
         sock->accepting?'y':'n');
 
   if (errcode != no_error) {
-    free(sock);
+    gras_free(sock);
     return errcode;
   }
 
@@ -234,8 +230,8 @@ void gras_socket_close(gras_socket_t *sock) {
 
        /* free the memory */
        if (sock->peer_name)
-         free(sock->peer_name);
-       free(sock);
+         gras_free(sock->peer_name);
+       gras_free(sock);
        return;
       }
     }
index 22d7ae6..01e4151 100644 (file)
@@ -15,7 +15,8 @@
 #include "gras_private.h"
 #include "transport_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_buf,transport);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_buf,transport,
+      "Generic buffered transport (works on top of TCP or SG)");
 
 /***
  *** Prototypes 
index 3fc5f57..825d2bc 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 #include "gras_private.h"
 #include "transport_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_file,transport);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_file,transport,
+       "Pseudo-transport to write to/read from a file");
 
 /***
  *** Prototypes 
@@ -52,7 +54,7 @@ typedef struct {
 gras_error_t
 gras_trp_file_setup(gras_trp_plugin_t *plug) {
 
-  gras_trp_file_plug_data_t *file = malloc(sizeof(gras_trp_file_plug_data_t));
+  gras_trp_file_plug_data_t *file = gras_new(gras_trp_file_plug_data_t,1);
   if (!file)
     RAISE_MALLOC;
 
index 27d108f..f86e756 100644 (file)
@@ -19,7 +19,7 @@
 #include "Virtu/virtu_sg.h"
 
 GRAS_LOG_EXTERNAL_CATEGORY(transport);
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_sg,transport);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_sg,transport,"SimGrid pseudo-transport");
 
 /***
  *** Prototypes 
index 4b3fa1e..438e009 100644 (file)
@@ -24,7 +24,7 @@
 #include "gras_private.h"
 #include "transport_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_tcp,transport);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_tcp,transport,"TCP transport");
 
 /***
  *** Prototypes 
index 7922d28..54b7f0e 100644 (file)
@@ -12,6 +12,8 @@
 #include "gras/Virtu/virtu_interface.h"
 #include "gras/Msg/msg_interface.h" /* FIXME: Get rid of this cyclic */
 
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,gras,"Process manipulation code");
+
 /* **************************************************************************
  * Process data
  * **************************************************************************/
index c49e663..7f4846f 100644 (file)
 
 #include "gras/Virtu/virtu_rl.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,GRAS);
-                             
+GRAS_LOG_EXTERNAL_CATEGORY(process);
+GRAS_LOG_DEFAULT_CATEGORY(process);
+
 /* globals */
 static gras_procdata_t *_gras_procdata = NULL;
 
 gras_error_t gras_process_init() {
   gras_error_t errcode;
 
-  if (!(_gras_procdata=(gras_procdata_t *)malloc(sizeof(gras_procdata_t))))
+  if (!(_gras_procdata=gras_new(gras_procdata_t,1)))
     RAISE_MALLOC;
 
   TRY(gras_procdata_init());
index 63ba131..869111f 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "Virtu/virtu_sg.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,GRAS);
+GRAS_LOG_EXTERNAL_CATEGORY(process);
 
 gras_error_t
 gras_process_init() {
index 3a3e4f2..9a4d4d5 100644 (file)
 #ifndef GRAS_PRIVATE_H
 #define GRAS_PRIVATE_H
 
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #define max(a, b) (((a) > (b))?(a):(b))
 #define min(a, b) (((a) < (b))?(a):(b))
 
@@ -26,6 +21,8 @@
 
 #include "gras_config.h"
 
+#include "gros/sysdep.h"
+
 #include "gros/error.h"
 #include "gros/log.h"
 #include "gros/module.h"
index 77a1a8b..c3202c8 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "gras_private.h" /* prototypes of this module */
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(config,tbx);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(config,gros,"configuration support");
 
 /* gras_cfgelm_t: the typedef corresponding to a config cell. 
 
@@ -44,13 +44,13 @@ void gras_cfg_str_free(void *d);
 void gras_cfg_host_free(void *d);
 
 void gras_cfg_str_free(void *d){
-  free(*(void**)d);
+  gras_free(*(void**)d);
 }
 void gras_cfg_host_free(void *d){
   gras_host_t *h=(gras_host_t*) *(void**)d; 
   if (h) {
-    if (h->name) free(h->name);
-    free(h);
+    if (h->name) gras_free(h->name);
+    gras_free(h);
   }
 }
 
@@ -128,14 +128,8 @@ gras_cfg_dump(const char *name,const char *indent,gras_cfg_t *cfg) {
   if (name)
     printf("%s>> Dumping of the config set '%s':\n",indent,name);
   gras_dict_foreach(dict,cursor,key,cell) {
-    if ((errcode=gras_dict_cursor_get_key(cursor,(char**)&name))  != no_error ||
-       (errcode=gras_dict_cursor_get_data(cursor,(void**)&cell)) != no_error) {
-      gras_dict_cursor_free(cursor);
-      return;
-    }
 
     printf("%s  %s:",indent,key);
-    fflush(stdout);
 
     size = gras_dynar_length(cell->content);
     printf("%d_to_%d_%s. Actual size=%d. List of values:\n",
@@ -143,6 +137,7 @@ gras_cfg_dump(const char *name,const char *indent,gras_cfg_t *cfg) {
           size);
 
     switch (cell->type) {
+       
     case gras_cfgelm_int:
       for (i=0; i<size; i++) {
        gras_dynar_get(cell->content,i,&ival);
@@ -178,6 +173,7 @@ gras_cfg_dump(const char *name,const char *indent,gras_cfg_t *cfg) {
   }
 
   if (name) printf("%s<< End of the config set '%s'\n",indent,name);
+  fflush(stdout);
 
   gras_dict_cursor_free(cursor);
   return;
@@ -196,7 +192,7 @@ void gras_cfgelm_free(void *data) {
 
   if (!c) return;
   gras_dynar_free(c->content);
-  free(c);
+  gras_free(c);
 }
 
 /*----[ Registering stuff ]-----------------------------------------------*/
@@ -218,6 +214,7 @@ gras_cfg_register(gras_cfg_t *cfg,
   gras_cfgelm_t *res;
   gras_error_t errcode;
 
+  DEBUG4("Register cfg elm %s (%d to %d %s)",name,min,max,gras_cfgelm_type_name[type]);
   TRYCATCH(mismatch_error,gras_dict_get((gras_dict_t*)cfg,name,(void**)&res));
 
   if (errcode != mismatch_error) {
@@ -225,7 +222,7 @@ gras_cfg_register(gras_cfg_t *cfg,
     /* Will be removed by the insertion of the new one */
   } 
 
-  res=malloc(sizeof(gras_cfgelm_t));
+  res=gras_new(gras_cfgelm_t,1);
   if (!res)
     RAISE_MALLOC;
 
@@ -296,7 +293,7 @@ gras_cfg_register_str(gras_cfg_t *cfg,const char *entry) {
     ERROR3("%s%s%s",
          "Invalid config element descriptor: ",entry,
          "; Should be <name>:<min nb>_to_<max nb>_<type>");
-    free(entrycpy);
+    gras_free(entrycpy);
     gras_abort();
   }
   *(tok++)='\0';
@@ -304,7 +301,7 @@ gras_cfg_register_str(gras_cfg_t *cfg,const char *entry) {
   min=strtol(tok, &tok, 10);
   if (!tok) {
     ERROR1("Invalid minimum in config element descriptor %s",entry);
-    free(entrycpy);
+    gras_free(entrycpy);
     gras_abort();
   }
 
@@ -312,7 +309,7 @@ gras_cfg_register_str(gras_cfg_t *cfg,const char *entry) {
     ERROR3("%s%s%s",
          "Invalid config element descriptor: ",entry,
          "; Should be <name>:<min nb>_to_<max nb>_<type>");
-    free(entrycpy);
+    gras_free(entrycpy);
     gras_abort();
   }
   tok += strlen("_to_");
@@ -320,7 +317,7 @@ gras_cfg_register_str(gras_cfg_t *cfg,const char *entry) {
   max=strtol(tok, &tok, 10);
   if (!tok) {
     ERROR1("Invalid maximum in config element descriptor %s",entry);
-    free(entrycpy);
+    gras_free(entrycpy);
     gras_abort();
   }
 
@@ -328,7 +325,7 @@ gras_cfg_register_str(gras_cfg_t *cfg,const char *entry) {
     ERROR3("%s%s%s",
          "Invalid config element descriptor: ",entry,
          "; Should be <name>:<min nb>_to_<max nb>_<type>");
-    free(entrycpy);
+    gras_free(entrycpy);
     gras_abort();
   }
 
@@ -339,14 +336,14 @@ gras_cfg_register_str(gras_cfg_t *cfg,const char *entry) {
     ERROR3("%s%s%s",
          "Invalid type in config element descriptor: ",entry,
          "; Should be one of 'string', 'int', 'host' or 'double'.");
-    free(entrycpy);
+    gras_free(entrycpy);
     gras_abort();
   }
 
   TRYCLEAN(gras_cfg_register(cfg,entrycpy,type,min,max),
-          free(entrycpy));
+          gras_free(entrycpy));
 
-  free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */
+  gras_free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */
   return no_error;
 }
 
@@ -374,7 +371,8 @@ gras_cfg_check(gras_cfg_t *cfg) {
             name,
             cell->min,
             gras_cfgelm_type_name[cell->type],
-            size);
+            size); 
+      gras_dict_cursor_free(cursor);
       return mismatch_error;
     }
 
@@ -384,11 +382,13 @@ gras_cfg_check(gras_cfg_t *cfg) {
             cell->max,
             gras_cfgelm_type_name[cell->type],
             size);
+      gras_dict_cursor_free(cursor);
       return mismatch_error;
     }
 
   }
 
+  gras_dict_cursor_free(cursor);
   return no_error;
 }
 
@@ -396,15 +396,17 @@ static gras_error_t gras_cfgelm_get(gras_cfg_t *cfg,
                                    const char *name,
                                    gras_cfgelm_type_t type,
                                    /* OUT */ gras_cfgelm_t **whereto){
-  gras_error_t errcode;
-
-  TRYCATCH(mismatch_error,gras_dict_get((gras_dict_t*)cfg,name,(void**)whereto));
+   
+  gras_error_t errcode = gras_dict_get((gras_dict_t*)cfg,name,
+                                      (void**)whereto);
 
   if (errcode == mismatch_error) {
     ERROR1("No registered cell %s in this config set",
           name);
     return mismatch_error;
   }
+  if (errcode != no_error)
+     return errcode;
 
   gras_assert3((*whereto)->type == type,
               "You tried to access to the config element %s as an %s, but its type is %s.",
@@ -542,12 +544,13 @@ gras_cfg_set_parse(gras_cfg_t *cfg, const char *options) {
   int len;
   gras_error_t errcode;
 
+  GRAS_IN;
   if (!options || !strlen(options)) { /* nothing to do */
     return no_error;
   }
   optionlist_cpy=strdup(options);
 
-  DEBUG1("Options list='%s'",options);
+  DEBUG1("List to parse and set:'%s'",options);
   option=optionlist_cpy;
   while (1) { /* breaks in the code */
 
@@ -555,7 +558,7 @@ gras_cfg_set_parse(gras_cfg_t *cfg, const char *options) {
       break;
     name=option;
     len=strlen(name);
-    DEBUG3("Parse list '%s'. len=%d; option-name=%d",name,len,option-name);
+    DEBUG3("Still to parse and set: '%s'. len=%d; option-name=%d",name,len,option-name);
 
     /* Pass the value */
     while (option-name<=(len-1) && *option != ' ' && *option != '\n' && *option != '\t') {
@@ -578,7 +581,7 @@ gras_cfg_set_parse(gras_cfg_t *cfg, const char *options) {
       if (option-name == len-1)
        option=NULL; /* don't do next iteration */
     }
-    DEBUG2("this='%s';rest='%s'",name,option);
+    DEBUG2("parse now:'%s'; parse later:'%s'",name,option);
 
     if (name[0] == ' ' || name[0] == '\n' || name[0] == '\t')
       continue;
@@ -587,7 +590,7 @@ gras_cfg_set_parse(gras_cfg_t *cfg, const char *options) {
     
     val=strchr(name,':');
     if (!val) {
-      free(optionlist_cpy);
+      gras_free(optionlist_cpy);
       gras_assert1(FALSE,
                   "Malformated option: '%s'; Should be of the form 'name:value'",
                   name);
@@ -602,51 +605,51 @@ gras_cfg_set_parse(gras_cfg_t *cfg, const char *options) {
       break;
     case mismatch_error:
       ERROR1("No registrated cell corresponding to '%s'.",name);
-      free(optionlist_cpy);
+      gras_free(optionlist_cpy);
       return mismatch_error;
       break;
     default:
-      free(optionlist_cpy);
+      gras_free(optionlist_cpy);
       return errcode;
     }
 
     switch (cell->type) {
     case gras_cfgelm_string:
       TRYCLEAN(gras_cfg_set_string(cfg, name, val),
-              free(optionlist_cpy));
+              gras_free(optionlist_cpy));
       break;
 
     case gras_cfgelm_int:
       i=strtol(val, &val, 0);
       if (val==NULL) {
-       free(optionlist_cpy);   
+       gras_free(optionlist_cpy);      
        gras_assert1(FALSE,
                     "Value of option %s not valid. Should be an integer",
                     name);
       }
 
       TRYCLEAN(gras_cfg_set_int(cfg,name,i),
-              free(optionlist_cpy));
+              gras_free(optionlist_cpy));
       break;
 
     case gras_cfgelm_double:
       d=strtod(val, &val);
       if (val==NULL) {
-       free(optionlist_cpy);   
+       gras_free(optionlist_cpy);      
        gras_assert1(FALSE,
               "Value of option %s not valid. Should be a double",
               name);
       }
 
       TRYCLEAN(gras_cfg_set_double(cfg,name,d),
-              free(optionlist_cpy));
+              gras_free(optionlist_cpy));
       break;
 
     case gras_cfgelm_host:
       str=val;
       val=strchr(val,':');
       if (!val) {
-       free(optionlist_cpy);   
+       gras_free(optionlist_cpy);      
        gras_assert1(FALSE,
               "Value of option %s not valid. Should be an host (machine:port)",
               name);
@@ -655,23 +658,23 @@ gras_cfg_set_parse(gras_cfg_t *cfg, const char *options) {
       *(val++)='\0';
       i=strtol(val, &val, 0);
       if (val==NULL) {
-       free(optionlist_cpy);   
+       gras_free(optionlist_cpy);      
        gras_assert1(FALSE,
               "Value of option %s not valid. Should be an host (machine:port)",
               name);
       }
 
       TRYCLEAN(gras_cfg_set_host(cfg,name,str,i),
-              free(optionlist_cpy));
+              gras_free(optionlist_cpy));
       break;      
 
     default: 
-      free(optionlist_cpy);
+      gras_free(optionlist_cpy);
       RAISE1(unknown_error,"Type of config element %s is not valid.",name);
     }
     
   }
-  free(optionlist_cpy);
+  gras_free(optionlist_cpy);
   return no_error;
 }
 
@@ -689,6 +692,7 @@ gras_cfg_set_int(gras_cfg_t *cfg,const char*name, int val) {
   gras_cfgelm_t *cell;
   gras_error_t errcode;
 
+  VERB2("Configuration setting: %s=%d",name,val);
   TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_int,&cell));
 
   if (cell->max > 1) {
@@ -712,6 +716,7 @@ gras_cfg_set_double(gras_cfg_t *cfg,const char*name, double val) {
   gras_cfgelm_t *cell;
   gras_error_t errcode;
 
+  VERB2("Configuration setting: %s=%f",name,val);
   TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_double,&cell));
 
   if (cell->max > 1) {
@@ -735,13 +740,15 @@ gras_error_t
 gras_cfg_set_string(gras_cfg_t *cfg,const char*name, const char*val) { 
   gras_cfgelm_t *cell;
   gras_error_t errcode;
+   char *newval = strdup(val);
 
+  VERB2("Configuration setting: %s=%s",name,val);
   TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_string,&cell));
 
   if (cell->max > 1) {
-    return gras_dynar_push(cell->content,&val);
+    return gras_dynar_push(cell->content,&newval);
   } else {
-    return gras_dynar_set(cell->content,0,&val);
+    return gras_dynar_set(cell->content,0,&newval);
   }
 }
 
@@ -762,8 +769,9 @@ gras_cfg_set_host(gras_cfg_t *cfg,const char*name,
                  const char *host,int port) {
   gras_cfgelm_t *cell;
   gras_error_t errcode;
-  gras_host_t *val=malloc(sizeof(gras_host_t));
+  gras_host_t *val=gras_new(gras_host_t,1);
 
+  VERB3("Configuration setting: %s=%s:%d",name,host,port);
   if (!val)
     RAISE_MALLOC;
   val->name = strdup(name);
@@ -956,7 +964,7 @@ gras_cfg_get_int   (gras_cfg_t  *cfg,
   TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_int,&cell));
 
   if (gras_dynar_length(cell->content) > 1) {
-    WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
+    WARN2("You asked for the first value of the config element '%s', but there is %d values",
             name, gras_dynar_length(cell->content));
   }
 
@@ -1079,9 +1087,17 @@ gras_error_t gras_cfg_get_dynar (gras_cfg_t    *cfg,
                                 const char    *name,
                                 gras_dynar_t **dynar) {
   gras_cfgelm_t *cell;
-  gras_error_t errcode;
+  gras_error_t errcode = gras_dict_get((gras_dict_t*)cfg,name,
+                                      (void**)&cell);
+
+  if (errcode == mismatch_error) {
+    ERROR1("No registered cell %s in this config set",
+          name);
+    return mismatch_error;
+  }
+  if (errcode != no_error)
+     return errcode;
 
-  TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_host,&cell));
   *dynar = cell->content;
   return no_error;
 }
index d62ec7f..cd98fa7 100644 (file)
@@ -17,7 +17,8 @@
 
 #include <stdio.h>
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dict,tbx);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dict,gros,
+   "Dictionaries provide the same functionnalities than hash tables");
 
 /*####[ Private prototypes ]#################################################*/
 
index 2840c7a..19e913b 100644 (file)
@@ -15,7 +15,7 @@
 #include <string.h> /* strlen() */
 
 GRAS_LOG_EXTERNAL_CATEGORY(dict);
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dict_cursor,dict);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dict_cursor,dict,"To traverse dictionaries");
 
 
 /*####[ Dict cursor functions ]#############################################*/
index 3652ec1..faff555 100644 (file)
 #include <stdio.h>
 
 GRAS_LOG_EXTERNAL_CATEGORY(dict);
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dict_elm,dict);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dict_elm,dict,"Dictionaries internals");
 
-GRAS_LOG_NEW_SUBCATEGORY(dict_add,dict);
-GRAS_LOG_NEW_SUBCATEGORY(dict_search,dict);
-GRAS_LOG_NEW_SUBCATEGORY(dict_remove,dict);
-GRAS_LOG_NEW_SUBCATEGORY(dict_collapse,dict);
-GRAS_LOG_NEW_SUBCATEGORY(dict_multi,dict);
+GRAS_LOG_NEW_SUBCATEGORY(dict_add,dict,"Dictionaries internals: elements addition");
+GRAS_LOG_NEW_SUBCATEGORY(dict_search,dict,"Dictionaries internals: searching");
+GRAS_LOG_NEW_SUBCATEGORY(dict_remove,dict,"Dictionaries internals: elements removal");
+GRAS_LOG_NEW_SUBCATEGORY(dict_collapse,dict,"Dictionaries internals: post-removal cleanup");
+GRAS_LOG_NEW_SUBCATEGORY(dict_multi,dict,"Dictionaries internals: dictionaries of dictionaries");
 
 /*####[ Private prototypes ]#################################################*/
 
index 9d705db..d059ec1 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "gras_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dynar,tbx);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dynar,gros,"Dynamic arrays");
 
 struct gras_dynar_s {
   size_t          size;
@@ -65,7 +65,7 @@ _gras_dynar_expand(gras_dynar_t * const dynar,
 
     const size_t new_size    = nb > (2*(old_size+1)) ? nb : (2*(old_size+1));
     const size_t new_length  = new_size*elmsize;
-    char * const new_data    = calloc(1, elmsize*new_size);
+    char * const new_data    = gras_malloc0(elmsize*new_size);
 
     DEBUG3("expend %p from %d to %d elements", dynar, old_size, nb);
     if (!new_data)
@@ -74,7 +74,7 @@ _gras_dynar_expand(gras_dynar_t * const dynar,
     if (old_data) {
       memcpy(new_data, old_data, used_length);
       _gras_clear_mem(old_data, old_length);
-      free(old_data);
+      gras_free(old_data);
     }
 
     _gras_clear_mem(new_data + used_length, new_length - used_length);
@@ -136,7 +136,7 @@ gras_dynar_new(gras_dynar_t   ** const p_dynar,
   gras_error_t  errcode = no_error;
   gras_dynar_t *dynar   = NULL;
 
-  if (!(dynar = calloc(1, sizeof(gras_dynar_t))))
+  if (!(dynar = gras_new0(gras_dynar_t,1)))
     RAISE_MALLOC;
 
   dynar->size    = 0;
@@ -163,12 +163,12 @@ gras_dynar_free_container(gras_dynar_t * const dynar) {
 
     if (dynar->data) {
       _gras_clear_mem(dynar->data, dynar->size);
-      free(dynar->data);
+      gras_free(dynar->data);
     }
 
     _gras_clear_mem(dynar, sizeof(gras_dynar_t));
 
-    free(dynar);
+    gras_free(dynar);
   }
 }
 
@@ -190,7 +190,7 @@ gras_dynar_reset(gras_dynar_t * const dynar) {
 
   if (dynar->data) {
     _gras_clear_mem(dynar->data, dynar->size);
-    free(dynar->data);
+    gras_free(dynar->data);
   }
 
   dynar->size = 0;
@@ -556,10 +556,10 @@ void gras_dynar_cursor_rm(gras_dynar_t * dynar,
   if (dynar->elmsize > sizeof(void*)) {
     DEBUG0("Elements too big to fit into a pointer");
     if (dynar->free) {
-      dst=malloc(dynar->elmsize);
+      dst=gras_malloc(dynar->elmsize);
       gras_dynar_remove_at(dynar,(*cursor)--,dst);
       (dynar->free)(dst);
-      free(dst);
+      gras_free(dst);
     } else {
       DEBUG0("Ok, we dont care about the element when no free function");
       gras_dynar_remove_at(dynar,(*cursor)--,NULL);
index fb86a02..3b415be 100644 (file)
@@ -24,7 +24,7 @@ static gras_dynar_t *gras_log_settings=NULL;
 static void _free_setting(void *s) {
   gras_log_setting_t *set=(gras_log_setting_t*)s;
   if (set) {
-    free(set->catname);
+    gras_free(set->catname);
 //    free(set); FIXME: uncommenting this leads to segfault when more than one chunk is passed as gras-log
   }
 }
@@ -45,9 +45,9 @@ gras_log_category_t _GRAS_LOGV(GRAS_LOG_ROOT_CAT) = {
   "root", gras_log_priority_uninitialized, 0,
   NULL, 0
 };
-GRAS_LOG_NEW_SUBCATEGORY(GRAS,GRAS_LOG_ROOT_CAT);
-GRAS_LOG_NEW_SUBCATEGORY(tbx,GRAS);
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log,tbx);
+GRAS_LOG_NEW_SUBCATEGORY(gras,GRAS_LOG_ROOT_CAT,"All GRAS categories");
+GRAS_LOG_NEW_SUBCATEGORY(gros,GRAS_LOG_ROOT_CAT,"All GROS categories (gras toolbox)");
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log,gros,"Loggings from the logging mecanism itself");
 
 
 static void _apply_control(gras_log_category_t* cat) {
@@ -225,13 +225,13 @@ static gras_error_t _gras_log_parse_setting(const char* control_string,
     } else {
       gras_assert1(FALSE,"Unknown priority name: %s",eq+1);
     }
-    free(neweq);
+    gras_free(neweq);
   } else {
     char buff[512];
     snprintf(buff,min(512,eq - dot - 1),"%s",dot+1);
     gras_assert1(FALSE,"Unknown setting of the log category: %s",buff);
   }
-  if (!(set->catname=malloc(dot - name+1)))
+  if (!(set->catname=(char*)gras_malloc(dot - name+1)))
     RAISE_MALLOC;
     
   strncpy(set->catname,name,dot-name);
@@ -321,7 +321,7 @@ gras_error_t gras_log_control_set(const char* control_string) {
     TRY(gras_dynar_new(&gras_log_settings,sizeof(gras_log_setting_t*),
                       _free_setting));
 
-  if (!(set = malloc(sizeof(gras_log_setting_t))))
+  if (! (set = gras_new(gras_log_setting_t,1)) )
     RAISE_MALLOC;
 
   if (!(cs=strdup(control_string)))
@@ -341,8 +341,8 @@ gras_error_t gras_log_control_set(const char* control_string) {
     }
     errcode = _gras_log_parse_setting(p,set);
     if (errcode != no_error) {
-      free(set);
-      free(cs);
+      gras_free(set);
+      gras_free(cs);
     }
     
     TRYCATCH(_gras_log_cat_searchsub(&_GRAS_LOGV(root),set->catname,&cat),
@@ -352,18 +352,18 @@ gras_error_t gras_log_control_set(const char* control_string) {
       DEBUG1("push %p to the settings",set);
       TRY(gras_dynar_push(gras_log_settings,&set));
       /* malloc in advance the next slot */
-      if (!(set = malloc(sizeof(gras_log_setting_t)))) { 
-       free(cs);
+      if (!(set = gras_new(gras_log_setting_t,1))) { 
+       gras_free(cs);
        RAISE_MALLOC;
       }
     } else {
       DEBUG0("Apply directly");
-      free(set->catname);
+      gras_free(set->catname);
       gras_log_threshold_set(cat,set->thresh);
     }
   }
-  free(set);
-  free(cs);
+  gras_free(set);
+  gras_free(cs);
   return no_error;
 } 
 
index 63cf205..3811738 100644 (file)
@@ -11,7 +11,7 @@
 #include "gras_private.h"
 #include <stdio.h>
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log_app,log);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log_app,log,"default logging handler");
 
 /**
  * The root category's default logging function.
index 4312035..6abd61c 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "gras_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(module,GRAS);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(module,gros, "module handling");
 
 extern void gras_log_exit(void);
 static int gras_running_process = 0;
index 543bcf3..3818021 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "gras_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(set,tbx);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(set,gros,"data container consisting in dict+dynar");
 
 /*####[ Type definition ]####################################################*/
 struct gras_set_ {
@@ -26,7 +26,7 @@ struct gras_set_ {
  * Creates a new set.
  */
 gras_error_t gras_set_new (gras_set_t **dst) {
-  gras_set_t *res=(gras_set_t*)malloc(sizeof(gras_set_t));
+  gras_set_t *res=gras_new(gras_set_t,1);
   gras_error_t errcode;
 
   if (!res)
@@ -49,7 +49,7 @@ void         gras_set_free(gras_set_t **set) {
   if (*set) {
     gras_dict_free ( &( (*set)->dict  ) );
     gras_dynar_free(    (*set)->dynar  );
-    free(*set);
+    gras_free(*set);
     *set=NULL;
   }
 }
@@ -182,7 +182,7 @@ void         gras_set_cursor_first       (gras_set_t   *set,
   if (set != NULL) {
     if (!*cursor) {
       DEBUG0("Create the cursor on first use");
-      *cursor = (gras_set_cursor_t*)malloc(sizeof(gras_set_cursor_t));
+      *cursor = gras_new(gras_set_cursor_t,1);
       gras_assert0(*cursor,
                   "Malloc error during the creation of the cursor");
     }
@@ -220,7 +220,7 @@ int          gras_set_cursor_get_or_free (gras_set_cursor_t **curs,
   cursor=*curs;
 
   if (! gras_dynar_cursor_get( cursor->set->dynar,&(cursor->val),elm) ) {
-    free(cursor);
+    gras_free(cursor);
     *curs=NULL;
     return FALSE;    
   } 
index 329970b..69d8654 100644 (file)
@@ -10,15 +10,15 @@ EXTRA_DIST=run_tests.in \
 
 # Test stuff
 
-gros_tests =                                  \
-       gros/dynar_int  gros/dynar_double gros/dynar_string   \
-       gros/dict_usage gros/dict_crash                 \
-       gros/set_usage                             \
-       gros/log_usage                             
-#      gros/config_usage
+gros_tests =                                                      \
+       gros/dynar_int    gros/dynar_double   gros/dynar_string   \
+       gros/dict_usage   gros/dict_crash                         \
+       gros/set_usage                                            \
+       gros/log_usage                                            \
+       gros/config_usage
 # gros/multidict_crash 
 
-RL_tests =                                    \
+RL_tests =                                              \
        gras/trp_tcp_client   gras/trp_tcp_server       \
        gras/trp_file_client  gras/trp_file_server      \
        gras/datadesc_usage
index 50dcf40..25e9d30 100644 (file)
@@ -12,7 +12,7 @@
 #include <gras.h>
 
 #include "gras/DataDesc/datadesc_interface.h"
-GRAS_LOG_NEW_DEFAULT_CATEGORY(test);
+GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
 
 #define READ  0
 #define WRITE 1
@@ -137,7 +137,7 @@ gras_error_t test_intref(gras_socket_t *sock, int direction) {
   gras_datadesc_type_t *my_type;
   int *i,*j;
   
-  if (! (i=malloc(sizeof(int))) )
+  if (! (i=gras_new(int,1)) )
     RAISE_MALLOC;
   *i=12345;
 
@@ -148,9 +148,9 @@ gras_error_t test_intref(gras_socket_t *sock, int direction) {
   TRY(write_read(my_type, &i,&j, sock,direction));
   if (direction == READ || direction == RW) {
     gras_assert(*i == *j);
-    free(j);
+    gras_free(j);
   }
-  free(i);
+  gras_free(i);
   return no_error;
 }
 
@@ -170,9 +170,9 @@ gras_error_t test_string(gras_socket_t *sock, int direction) {
       gras_assert4(i[cpt] == j[cpt],"i[%d]=%c  !=  j[%d]=%c",
                   cpt,i[cpt],cpt,j[cpt]);
     } 
-    free(j);
+    gras_free(j);
   }
-  free(i);
+  gras_free(i);
   return no_error;
 }
 
@@ -205,7 +205,7 @@ gras_error_t test_homostruct(gras_socket_t *sock, int direction) {
                        &my_type));
 
   /* init a value, exchange it and check its validity*/
-  if (! (i=malloc(sizeof(homostruct))) )
+  if (! (i=gras_new(homostruct,1)) )
     RAISE_MALLOC;
   i->a = 2235;    i->b = 433425;
   i->c = -23423;  i->d = -235235;
@@ -216,9 +216,9 @@ gras_error_t test_homostruct(gras_socket_t *sock, int direction) {
     gras_assert(i->b == j->b);
     gras_assert(i->c == j->c);
     gras_assert(i->d == j->d);
-    free(j);
+    gras_free(j);
   }
-  free(i);
+  gras_free(i);
   return no_error;
 }
 
@@ -252,7 +252,7 @@ gras_error_t test_hetestruct(gras_socket_t *sock, int direction) {
                        &my_type));
 
   /* init a value, exchange it and check its validity*/
-  if (! (i=malloc(sizeof(hetestruct))) )
+  if (! (i=gras_new(hetestruct,1)) )
     RAISE_MALLOC;
   i->c1 = 's'; i->l1 = 123455;
   i->c2 = 'e'; i->l2 = 774531;
@@ -263,9 +263,9 @@ gras_error_t test_hetestruct(gras_socket_t *sock, int direction) {
     gras_assert(i->c2 == j->c2);
     gras_assert2(i->l1 == j->l1,"i->l1(=%ld)  !=  j->l1(=%ld)",i->l1,j->l1);
     gras_assert(i->l2 == j->l2);
-    free(j);
+    gras_free(j);
   }
-  free(i);
+  gras_free(i);
   return no_error;
 }
 
@@ -294,7 +294,7 @@ gras_error_t test_nestedstruct(gras_socket_t *sock, int direction) {
                        &my_type));
 
   /* init a value, exchange it and check its validity*/
-  if (! (i=malloc(sizeof(nestedstruct))) )
+  if (! (i=gras_new(nestedstruct,1)) )
     RAISE_MALLOC;
   i->homo.a = 235231;  i->homo.b = -124151;
   i->homo.c = 211551;  i->homo.d = -664222;
@@ -311,9 +311,9 @@ gras_error_t test_nestedstruct(gras_socket_t *sock, int direction) {
     gras_assert(i->hete.c2 == j->hete.c2);
     gras_assert(i->hete.l1 == j->hete.l1);
     gras_assert(i->hete.l2 == j->hete.l2);
-    free(j);
+    gras_free(j);
   }
-  free(i);
+  gras_free(i);
   return no_error;
 }
 
@@ -345,7 +345,7 @@ gras_error_t declare_chained_list_type(void) {
 }
 
 chained_list_t * cons(int v, chained_list_t *l) {
-  chained_list_t *nl = malloc(sizeof (chained_list_t));
+  chained_list_t *nl = gras_new(chained_list_t,1);
   
   nl->v = v;
   nl->l = l;
@@ -355,7 +355,7 @@ chained_list_t * cons(int v, chained_list_t *l) {
 void list_free(chained_list_t*l) {
   if (l) {
     list_free(l->l);
-    free(l);
+    gras_free(l);
   }
 }
 int list_eq(chained_list_t*i,chained_list_t*j) {
@@ -536,11 +536,11 @@ gras_error_t test_clause(gras_socket_t *sock, int direction) {
   INFO0("---- Test on struct containing dynamic array and its size (cbps test) ----");
 
   /* create and fill the struct */
-  if (! (i=malloc(sizeof(Clause))) )
+  if (! (i=gras_new(Clause,1)) )
     RAISE_MALLOC;
 
   i->num_lits = 5432;
-  if (! (i->literals = malloc(sizeof(int) * i->num_lits)) )
+  if (! (i->literals = gras_new(int, i->num_lits)) )
     RAISE_MALLOC;
   for (cpt=0; cpt<i->num_lits; cpt++)
     i->literals[cpt] = cpt * cpt - ((cpt * cpt) / 2);
@@ -559,11 +559,11 @@ gras_error_t test_clause(gras_socket_t *sock, int direction) {
     for (cpt=0; cpt<i->num_lits; cpt++)
       gras_assert(i->literals[cpt] == j->literals[cpt]);
     
-    free(j->literals);
-    free(j);
+    gras_free(j->literals);
+    gras_free(j);
   }
-  free(i->literals);
-  free(i);
+  gras_free(i->literals);
+  gras_free(i);
   return no_error;
 }
 
@@ -609,7 +609,7 @@ int main(int argc,char *argv[]) {
   
   TRYFAIL(test_string(sock,direction)); 
 
-// TRYFAIL(test_structures(sock,direction));
+  TRYFAIL(test_structures(sock,direction));
 
   TRYFAIL(test_homostruct(sock,direction));
   TRYFAIL(test_hetestruct(sock,direction));
index 8365e77..43861b8 100755 (executable)
@@ -22,7 +22,7 @@ print "/* This file is perl-generated, of course */\n\n";
 print "#include <stdio.h>\n";
 print "#include <gras.h>\n\n";
 
-print "GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(structs,test);\n\n";
+print "GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(structs,test,\"Logs about the gigantic struct test\");\n\n";
 
 print "#define READ  0\n#define WRITE 1\n#define RW    2\n\n";
   
index 1e3a9e1..a62dbd6 100644 (file)
@@ -36,7 +36,7 @@ int main(int argc,char *argv[]) {
   
   if (strcmp(data_send, data_recv)) {
     fprintf(stderr, "===[CLIENT]=== String sent != string received\n");
-    exit(1);
+    gras_abort();
   } 
   fprintf(stderr,"===[CLIENT]=== Got a valid ACK\n");
   
index c7cc98c..c5acfb5 100755 (executable)
@@ -7,18 +7,18 @@ tests_nb=0
 rm -f test.failed test.success test.ignored
 
 if [ xvalgrind = "x$1" ] ; then
-  valgrind=valgrind
+  valgrind="libtool --mode=execute valgrind"
 else
   valgrind=
 fi
-#          config_usage                        \
-for test in gros/log_usage                           \
-            gros/dynar_int gros/dynar_double gros/dynar_string \
-           gros/dict_usage gros/dict_crash               \
+for test in gros/log_usage                                          \
+            gros/dynar_int gros/dynar_double gros/dynar_string      \
+           gros/dict_usage gros/dict_crash                         \
+           gros/config_usage                                       \
            \
            gras/datadesc_usage                       
 #          "gras/datadesc_usage --read @srcdir@/datadesc.little32" \
-#          "gras/datadesc_usage --read @srcdir@/datadesc.big32" \
+#          "gras/datadesc_usage --read @srcdir@/datadesc.big32"    \
 #          "gras/datadesc_usage --read @srcdir@/datadesc.big64" 
 
 #          "gras/datadesc_usage --read @srcdir@/datadesc.little64" \
index 793afd2..475bab4 100644 (file)
@@ -7,10 +7,6 @@
 
 /*====[ Prototypes ]=========================================================*/
 gras_cfg_t *make_set(void); /* build a minimal set */
-int test3(void); /* validate=>not enought */
-int test4(void); /* validate=> too many */
-int test5(void); /* get users list */
-
 
 /*====[ Code ]===============================================================*/
 gras_cfg_t *make_set(){
@@ -18,39 +14,21 @@ gras_cfg_t *make_set(){
   gras_error_t errcode;
 
   TRYFAIL(gras_cfg_new(&set));
-  gras_cfg_register_str(set,"hostname:1_to_1_string");
-  gras_cfg_register_str(set,"user:1_to_10_string");
-  gras_cfg_register_str(set,"speed:1_to_1_int");
+  TRYFAIL(gras_cfg_register_str(set,"speed:1_to_2_int"));
+  TRYFAIL(gras_cfg_register_str(set,"hostname:1_to_1_string"));
+  TRYFAIL(gras_cfg_register_str(set,"user:1_to_10_string"));
 
-  gras_cfg_set_parse(set,
-                  "hostname:veloce "
-                  "user:mquinson\nuser:ecaron\tuser:fsuter");
+  TRYFAIL(gras_cfg_set_parse(set, "hostname:veloce "
+                            "user:mquinson\nuser:oaumage\tuser:alegrand"));
   return set;
 }
-
-
-/*----[ get users list ]-----------------------------------------------------*/
-int test5()
-{
-  gras_dynar_t *dyn;
-  char *str;
-  int i;
-
-  gras_cfg_t *set=make_set();
-  gras_cfg_set_parse(set,"speed:42");
-  gras_cfg_check(set);
-  gras_cfg_get_dynar(set,"user",&dyn);
-  printf("Count: %d; Options: \n",gras_dynar_length(dyn));
-  gras_dynar_foreach(dyn,i,str) {
-    printf("%s\n",str);
-  }
-  gras_cfg_free(&set);
-  return 1;
-}
  
 int main(int argc, char **argv) {
   gras_error_t errcode;
   gras_cfg_t *set;
+
+  gras_dynar_t *dyn;
+  char *str;
   int ival;
   
   gras_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
@@ -61,31 +39,44 @@ int main(int argc, char **argv) {
   gras_cfg_free(&set);
 
 
-  fprintf(stderr,"==== Try to use an unregistered option (err msg expected).\n");
+  fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
   set=make_set();
   TRYEXPECT(mismatch_error,gras_cfg_set_parse(set,"color:blue"));
   gras_cfg_free(&set);
 
 
   fprintf(stderr,
-         "\n==== Validation test (err msg about not enough values expected)\n");
+         "==== Validation test. (ERROR EXPECTED: not enough values of 'speed')\n");
   set=make_set();
   gras_cfg_check(set);
   gras_cfg_free(&set);
+  gras_cfg_free(&set);
 
-  fprintf(stderr,"\n==== Validation test (too many elements)\n");
+  fprintf(stderr,"==== Validation test (ERROR EXPECTED: too many elements)\n");
   set=make_set();
   gras_cfg_set_parse(set,"hostname:toto:42");
-  gras_cfg_set_parse(set,"speed:42 speed:24");
+  gras_cfg_set_parse(set,"speed:42 speed:24 speed:34");
   gras_cfg_check(set);
+  gras_cfg_free(&set);
+
+  fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
+  set=make_set();
+  gras_cfg_set_parse(set,"hostname:toto:42 speed:42");
   gras_cfg_get_int(set,"speed",&ival);
-  printf("speed value: %d\n",ival);
+  fprintf(stderr,"speed value: %d\n",ival); 
   gras_cfg_free(&set);
 
-  fprintf(stderr,"\n§§§§§§§§§ %s Â§Â§Â§Â§Â§Â§Â§Â§Â§\n§§§ Expected: %s\n",
-        "TEST5",
-        "Count: 3; Options:\\nmquinson\\necaron\\nfsuter");
-  test5();
+  fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
+  set=make_set();
+  gras_cfg_set_parse(set,"speed:42");
+  gras_cfg_check(set);
+  gras_cfg_get_dynar(set,"user",&dyn);
+  fprintf(stderr,"Count: %d; Options: ",gras_dynar_length(dyn));
+  gras_dynar_foreach(dyn,ival,str) {
+    fprintf(stderr,"%s;",str);
+  }
+  fprintf(stderr,"\n");
+  gras_cfg_free(&set);
 
   gras_exit();
   return 0;
index 7c47823..99dadb3 100644 (file)
@@ -11,6 +11,7 @@
 #include <gras.h>
 #include <time.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #define NB_ELM 20000
 #define SIZEOFKEY 1024
@@ -20,6 +21,7 @@ static void print_str(void *str) {
   printf("%s",(char*)str);
 }
 
+GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
 
 static gras_error_t traverse(gras_dict_t *head) {
   gras_dict_cursor_t *cursor=NULL;
@@ -28,10 +30,8 @@ static gras_error_t traverse(gras_dict_t *head) {
 
   gras_dict_foreach(head,cursor,key,data) {
     //    printf("   Seen:  %s=%s\n",key,data);
-    if (strcmp(key,data)) {
-      printf("Key(%s) != value(%s). Abording\n",key,data);
-      abort();
-    }
+    gras_assert2 (!strcmp(key,data),
+      "Key(%s) != value(%s). Abording\n",key,data);
   }
   return no_error;
 }
index 3bbff8f..58acd2b 100644 (file)
@@ -14,6 +14,7 @@
 #include <gras.h>
 
 GRAS_LOG_EXTERNAL_CATEGORY(dict);
+GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
 
 static gras_error_t fill(gras_dict_t **head);
 static gras_error_t debuged_add(gras_dict_t *head,const char*key);
@@ -50,7 +51,7 @@ static gras_error_t debuged_add(gras_dict_t *head,const char*key)
   char *data=strdup(key);
 
   printf("   - Add %s\n",key);
-  errcode=gras_dict_set(head,key,data,&free);
+  errcode=gras_dict_set(head,key,data,&gras_free);
   if (GRAS_LOG_ISENABLED(dict,gras_log_priority_debug)) {
     gras_dict_dump(head,(void (*)(void*))&printf);
     fflush(stdout);
@@ -88,10 +89,8 @@ static gras_error_t traverse(gras_dict_t *head) {
 
   gras_dict_foreach(head,cursor,key,data) {
     printf("   - Seen:  %s->%s\n",key,data);
-    if (strcmp(key,data)) {
-      printf("Key(%s) != value(%s). Abording\n",key,data);
-      abort();
-    }
+    gras_assert2(!strcmp(key,data),
+                "Key(%s) != value(%s). Abording\n",key,data);
   }
   return no_error;
 }
@@ -118,13 +117,13 @@ int main(int argc,char **argv) {
 
   printf(" - Change some values\n");
   printf("   - Change 123 to 'Changed 123'\n");
-  TRYFAIL(gras_dict_set(head,"123",strdup("Changed 123"),&free));
+  TRYFAIL(gras_dict_set(head,"123",strdup("Changed 123"),&gras_free));
   printf("   - Change 123 back to '123'\n");
-  TRYFAIL(gras_dict_set(head,"123",strdup("123"),&free));
+  TRYFAIL(gras_dict_set(head,"123",strdup("123"),&gras_free));
   printf("   - Change 12a to 'Dummy 12a'\n");
-  TRYFAIL(gras_dict_set(head,"12a",strdup("Dummy 12a"),&free));
+  TRYFAIL(gras_dict_set(head,"12a",strdup("Dummy 12a"),&gras_free));
   printf("   - Change 12a to '12a'\n");
-  TRYFAIL(gras_dict_set(head,"12a",strdup("12a"),&free));
+  TRYFAIL(gras_dict_set(head,"12a",strdup("12a"),&gras_free));
 
   //  gras_dict_dump(head,(void (*)(void*))&printf);
   printf(" - Traverse the resulting dictionnary\n");
index e5005fe..0166813 100644 (file)
@@ -11,6 +11,8 @@
 #include <stdio.h>
 #include <gras.h>
 
+GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
+
 int main(int argc,char *argv[]) {
    gras_dynar_t *d;
    gras_error_t errcode;
@@ -19,16 +21,15 @@ int main(int argc,char *argv[]) {
    
    gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
 
-   fprintf(stderr,"==== Traverse the empty dynar\n");
+   INFO0("==== Traverse the empty dynar");
    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
    gras_dynar_foreach(d,cursor,cpt){
-     fprintf(stderr,
-            "Damnit, there is something in the empty dynar\n");
-     abort();
+     gras_assert0(FALSE,
+            "Damnit, there is something in the empty dynar");
    }
    gras_dynar_free(d);
 
-   fprintf(stderr,"==== Push/shift 5000 doubles\n");
+   INFO0("==== Push/shift 5000 doubles");
    TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
@@ -36,27 +37,21 @@ int main(int argc,char *argv[]) {
    }
    gras_dynar_foreach(d,cursor,d2){
      d1=(double)cursor;
-     if (d1 != d2) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one (%f!=%f)\n",
-              d1,d2);
-       abort();
-     }
+     gras_assert2(d1 == d2,
+           "The retrieved value is not the same than the injected one (%f!=%f)",
+                 d1,d2);
    }
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
      gras_dynar_shift(d,&d2);
-     if (d1 != d2) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one (%f!=%f)\n",
-              d1,d2);
-       abort();
-     }
+     gras_assert2(d1 == d2,
+           "The retrieved value is not the same than the injected one (%f!=%f)",
+                 d1,d2);
    }
    gras_dynar_free(d);
 
 
-   fprintf(stderr,"==== Unshift/pop 5000 doubles\n");
+   INFO0("==== Unshift/pop 5000 doubles");
    TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
@@ -65,18 +60,15 @@ int main(int argc,char *argv[]) {
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
      gras_dynar_pop(d,&d2);
-     if (d1 != d2) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one (%f!=%f)\n",
-              d1,d2);
-       abort();
-     }
+     gras_assert2 (d1 == d2,
+           "The retrieved value is not the same than the injected one (%f!=%f)",
+                  d1,d2);
    }
    gras_dynar_free(d);
 
 
 
-   fprintf(stderr,"==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything\n");
+   INFO0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
    TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
@@ -90,38 +82,29 @@ int main(int argc,char *argv[]) {
    for (cpt=0; cpt< 2500; cpt++) {
      d1=(double)cpt;
      gras_dynar_shift(d,&d2);
-     if (d1 != d2) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one at the begining (%f!=%f)\n",
-              d1,d2);
-       abort();
-     }
-     //     fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
+     gras_assert2(d1 == d2,
+           "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
+                 d1,d2);
+     DEBUG2("Pop %d, length=%d",cpt, gras_dynar_length(d));
    }
    for (cpt=999; cpt>=0; cpt--) {
      d1=(double)cpt;
      gras_dynar_shift(d,&d2);
-     if (d1 != d2) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one in the middle (%f!=%f)\n",
-              d1,d2);
-       abort();
-     }
+     gras_assert2 (d1 == d2,
+           "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
+                  d1,d2);
    }
    for (cpt=2500; cpt< 5000; cpt++) {
      d1=(double)cpt;
      gras_dynar_shift(d,&d2);
-     if (d1 != d2) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one at the end (%f!=%f)\n",
-              d1,d2);
-       abort();
-     }
+     gras_assert2 (d1 == d2,
+           "The retrieved value is not the same than the injected one at the end (%f!=%f)",
+                  d1,d2);
    }
    gras_dynar_free(d);
 
 
-   fprintf(stderr,"==== Push 5000 double, remove 2000-4000. free the rest\n");
+   INFO0("==== Push 5000 double, remove 2000-4000. free the rest");
    TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
@@ -130,12 +113,9 @@ int main(int argc,char *argv[]) {
    for (cpt=2000; cpt< 4000; cpt++) {
      d1=(double)cpt;
      gras_dynar_remove_at(d,2000,&d2);
-     if (d1 != d2) {
-       fprintf(stderr,
-           "Remove a bad value. Got %f, expected %f\n",
+     gras_assert2 (d1 == d2,
+           "Remove a bad value. Got %f, expected %f",
               d2,d1);
-       abort();
-     }
    }
    gras_dynar_free(d);
 
index aa8b8fe..2802c75 100644 (file)
@@ -12,7 +12,7 @@
 #include <gras.h>
 
 #define NB_ELEM 5000
-GRAS_LOG_NEW_DEFAULT_CATEGORY(test);
+GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
 
 int main(int argc,char *argv[]) {
    gras_dynar_t *d;
@@ -21,22 +21,19 @@ int main(int argc,char *argv[]) {
    
    gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
 
-   fprintf(stderr,"==== Traverse the empty dynar\n");
+   INFO0("==== Traverse the empty dynar");
    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
    gras_dynar_foreach(d,cursor,i){
-     fprintf(stderr,
-            "Damnit, there is something in the empty dynar\n");
-     abort();
+     gras_assert0(0,"Damnit, there is something in the empty dynar");
    }
    gras_dynar_free(d);
 
-   fprintf(stderr,
-          "==== Push %d int, set them again 3 times, traverse them, shift them\n",
-          NB_ELEM);
+   INFO1("==== Push %d int, set them again 3 times, traverse them, shift them",
+       NB_ELEM);
    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      TRYFAIL(gras_dynar_push(d,&cpt));
-     //fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d));
+     DEBUG2("Push %d, length=%d",cpt, gras_dynar_length(d));
    }
    for (cursor=0; cursor< NB_ELEM; cursor++) {
      gras_dynar_get(d,cursor,&cpt);
@@ -49,121 +46,97 @@ int main(int argc,char *argv[]) {
                  "The retrieved value is not the same than the injected one (%d!=%d)",
                  cursor,cpt);
    }
-   for (cpt=0; cpt< NB_ELEM; cpt++) {
+   for (cpt=0; cpt< NB_ELEM; cpt++)
      TRYFAIL(gras_dynar_set(d,cpt,&cpt));
-   }
-   for (cpt=0; cpt< NB_ELEM; cpt++) {
+
+   for (cpt=0; cpt< NB_ELEM; cpt++) 
      TRYFAIL(gras_dynar_set(d,cpt,&cpt));
-   }
-   for (cpt=0; cpt< NB_ELEM; cpt++) {
+   
+   for (cpt=0; cpt< NB_ELEM; cpt++) 
      TRYFAIL(gras_dynar_set(d,cpt,&cpt));
-   }
+   
    cpt=0;
    gras_dynar_foreach(d,cursor,i){
-     if (i != cpt) {
-       fprintf(stderr,
-         "The retrieved value is not the same than the injected one (%d!=%d)\n",
-              i,cpt);
-       abort();
-     }
+     gras_assert2(i == cpt,
+         "The retrieved value is not the same than the injected one (%d!=%d)",
+                 i,cpt);
      cpt++;
    }
-   if (cpt !=NB_ELEM) {
-     fprintf(stderr,
-            "Cannot retrieve my %d values. Last got one is %d\n",NB_ELEM,
-            cpt);
-       abort();
-   }     
+   gras_assert2(cpt == NB_ELEM,
+               "Cannot retrieve my %d values. Last got one is %d",
+               NB_ELEM, cpt);
 
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      gras_dynar_shift(d,&i);
-     if (i != cpt) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one (%d!=%d)\n",
+     gras_assert2(i == cpt,
+           "The retrieved value is not the same than the injected one (%d!=%d)",
               i,cpt);
-       abort();
-     }
-     //     fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
+     DEBUG2("Pop %d, length=%d",cpt, gras_dynar_length(d));
    }
    gras_dynar_free(d);
 
-
-   fprintf(stderr,"==== Unshift/pop %d int\n",NB_ELEM);
+   
+   INFO1("==== Unshift/pop %d int",NB_ELEM);
    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      TRYFAIL(gras_dynar_unshift(d,&cpt));
-     //     fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d));
+     DEBUG2("Push %d, length=%d",cpt, gras_dynar_length(d));
    }
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      gras_dynar_pop(d,&i);
-     if (i != cpt) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one (%d!=%d)\n",
-              i,cpt);
-       abort();
-     }
-     //     fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
+     gras_assert2(i == cpt,
+           "The retrieved value is not the same than the injected one (%d!=%d)",
+                i,cpt);
+     DEBUG2("Pop %d, length=%d",cpt, gras_dynar_length(d));
    }
    gras_dynar_free(d);
 
 
-
-   fprintf(stderr,"==== Push %d int, insert 1000 int in the middle, shift everything\n",NB_ELEM);
+   
+   INFO1("==== Push %d int, insert 1000 int in the middle, shift everything",NB_ELEM);
    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      TRYFAIL(gras_dynar_push(d,&cpt));
-     //     fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d));
+     DEBUG2("Push %d, length=%d",cpt, gras_dynar_length(d));
    }
    for (cpt=0; cpt< 1000; cpt++) {
      TRYFAIL(gras_dynar_insert_at(d,2500,&cpt));
-     //     fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d));
+     DEBUG2("Push %d, length=%d",cpt, gras_dynar_length(d));
    }
 
    for (cpt=0; cpt< 2500; cpt++) {
      gras_dynar_shift(d,&i);
-     if (i != cpt) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one at the begining (%d!=%d)\n",
+     gras_assert2(i == cpt,
+           "The retrieved value is not the same than the injected one at the begining (%d!=%d)",
               i,cpt);
-       abort();
-     }
-     //     fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
+     DEBUG2("Pop %d, length=%d",cpt, gras_dynar_length(d));
    }
    for (cpt=999; cpt>=0; cpt--) {
      gras_dynar_shift(d,&i);
-     if (i != cpt) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one in the middle (%d!=%d)\n",
+     gras_assert2(i == cpt,
+           "The retrieved value is not the same than the injected one in the middle (%d!=%d)",
               i,cpt);
-       abort();
-     }
    }
    for (cpt=2500; cpt< NB_ELEM; cpt++) {
      gras_dynar_shift(d,&i);
-     if (i != cpt) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one at the end (%d!=%d)\n",
+      gras_assert2(i == cpt,
+           "The retrieved value is not the same than the injected one at the end (%d!=%d)",
               i,cpt);
-       abort();
-     }
    }
    gras_dynar_free(d);
 
 
-   fprintf(stderr,"==== Push %d int, remove 2000-4000. free the rest\n",NB_ELEM);
+   INFO1("==== Push %d int, remove 2000-4000. free the rest",NB_ELEM);
    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
-   for (cpt=0; cpt< NB_ELEM; cpt++) {
+   for (cpt=0; cpt< NB_ELEM; cpt++) 
      TRYFAIL(gras_dynar_push(d,&cpt));
-   }
+   
    for (cpt=2000; cpt< 4000; cpt++) {
      gras_dynar_remove_at(d,2000,&i);
-     if (i != cpt) {
-       fprintf(stderr,
-           "Remove a bad value. Got %d, expected %d\n",
-              i,cpt);
-       abort();
-     }
-     //     fprintf (stderr,"remove %d, length=%d \n",cpt, gras_dynar_length(d));
+     gras_assert2(i == cpt,
+                 "Remove a bad value. Got %d, expected %d",
+                 i,cpt);
+     DEBUG2("remove %d, length=%d",cpt, gras_dynar_length(d));
    }
    gras_dynar_free(d);
 
index 6651a46..f2c647a 100644 (file)
 
 /* NB_ELEM HAS to be a multiple of 5 */
 #define NB_ELEM 5000
+GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
 
 void free_string(void *d);
 
 void free_string(void *d){
-  free(*(void**)d);
+  gras_free(*(void**)d);
 }
 
 int main(int argc,char *argv[]) {
@@ -29,16 +30,15 @@ int main(int argc,char *argv[]) {
    
    gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
    
-   fprintf(stderr,"==== Traverse the empty dynar\n");
+   INFO0("==== Traverse the empty dynar");
    TRYFAIL(gras_dynar_new(&d,sizeof(char *),&free_string));
    gras_dynar_foreach(d,cpt,s1){
-     fprintf(stderr,
-            "Damnit, there is something in the empty dynar\n");
-     abort();
+     gras_assert0(FALSE,
+                 "Damnit, there is something in the empty dynar");
    }
    gras_dynar_free(d);
 
-   fprintf(stderr,"==== Push %d strings, set them again 3 times, shift them\n",NB_ELEM);
+   INFO1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM);
    TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string));
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      sprintf(buf,"%d",cpt);
@@ -63,18 +63,15 @@ int main(int argc,char *argv[]) {
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      sprintf(buf,"%d",cpt);
      gras_dynar_shift(d,&s2);
-     if (strcmp(buf,s2)) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one (%s!=%s)\n",
-              buf,s2);
-       abort();
-     }
-     free(s2);
+     gras_assert2 (!strcmp(buf,s2),
+           "The retrieved value is not the same than the injected one (%s!=%s)",
+                  buf,s2);
+     gras_free(s2);
    }
    gras_dynar_free(d);
 
 
-   fprintf(stderr,"==== Unshift, traverse and pop %d strings\n",NB_ELEM);
+   INFO1("==== Unshift, traverse and pop %d strings",NB_ELEM);
    TRYFAIL(gras_dynar_new(&d,sizeof(char**),&free_string));
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      sprintf(buf,"%d",cpt);
@@ -83,29 +80,22 @@ int main(int argc,char *argv[]) {
    }
    gras_dynar_foreach(d,cpt,s1) {
      sprintf(buf,"%d",NB_ELEM - cpt -1);
-     if (strcmp(buf,s1)) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one (%s!=%s)\n",
+     gras_assert2 (!strcmp(buf,s1),
+           "The retrieved value is not the same than the injected one (%s!=%s)",
               buf,s1);
-       abort();
-     }
    }
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      sprintf(buf,"%d",cpt);
      gras_dynar_pop(d,&s2);
-     if (strcmp(buf,s2)) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one (%s!=%s)\n",
+     gras_assert2 (!strcmp(buf,s2),
+           "The retrieved value is not the same than the injected one (%s!=%s)",
               buf,s2);
-       abort();
-     }
-     free(s2);
+     gras_free(s2);
    }
    gras_dynar_free(d);
 
 
-
-   fprintf(stderr,"==== Push %d strings, insert %d strings in the middle, shift everything\n",NB_ELEM,NB_ELEM/5);
+   INFO2("==== Push %d strings, insert %d strings in the middle, shift everything",NB_ELEM,NB_ELEM/5);
    TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string));
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      sprintf(buf,"%d",cpt);
@@ -121,40 +111,31 @@ int main(int argc,char *argv[]) {
    for (cpt=0; cpt< NB_ELEM/2; cpt++) {
      sprintf(buf,"%d",cpt);
      gras_dynar_shift(d,&s2);
-     if (strcmp(buf,s2)) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one at the begining (%s!=%s)\n",
+     gras_assert2(!strcmp(buf,s2),
+           "The retrieved value is not the same than the injected one at the begining (%s!=%s)",
               buf,s2);
-       abort();
-     }
-     free(s2);
+      gras_free(s2);
    }
    for (cpt=(NB_ELEM/5)-1; cpt>=0; cpt--) {
      sprintf(buf,"%d",cpt);
      gras_dynar_shift(d,&s2);
-     if (strcmp(buf,s2)) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one in the middle (%s!=%s)\n",
+     gras_assert2 (!strcmp(buf,s2),
+           "The retrieved value is not the same than the injected one in the middle (%s!=%s)",
               buf,s2);
-       abort();
-     }
-     free(s2);
+     gras_free(s2);
    }
    for (cpt=NB_ELEM/2; cpt< NB_ELEM; cpt++) {
      sprintf(buf,"%d",cpt);
      gras_dynar_shift(d,&s2);
-     if (strcmp(buf,s2)) {
-       fprintf(stderr,
-           "The retrieved value is not the same than the injected one at the end (%s!=%s)\n",
+     gras_assert2 (!strcmp(buf,s2),
+           "The retrieved value is not the same than the injected one at the end (%s!=%s)",
               buf,s2);
-       abort();
-     }
-     free(s2);
+     gras_free(s2);
    }
    gras_dynar_free(d);
 
 
-   fprintf(stderr,"==== Push %d strings, remove %d-%d. free the rest\n",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5));
+   INFO3("==== Push %d strings, remove %d-%d. free the rest",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5));
    TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string));
    for (cpt=0; cpt< NB_ELEM; cpt++) {
      sprintf(buf,"%d",cpt);
@@ -164,13 +145,10 @@ int main(int argc,char *argv[]) {
    for (cpt=2*(NB_ELEM/5); cpt< 4*(NB_ELEM/5); cpt++) {
      sprintf(buf,"%d",cpt);
      gras_dynar_remove_at(d,2*(NB_ELEM/5),&s2);
-     if (strcmp(buf,s2)) {
-       fprintf(stderr,
-           "Remove a bad value. Got %s, expected %s\n",
-              s2,buf);
-       abort();
-     }
-     free(s2);
+     gras_assert2(!strcmp(buf,s2),
+                 "Remove a bad value. Got %s, expected %s",
+                 s2,buf);
+      gras_free(s2);
    }
    gras_dynar_free(d);
 
index 26679d4..5155fd9 100644 (file)
 #include <gras.h>
 #include <stdio.h>
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(Test, Top);
-GRAS_LOG_NEW_CATEGORY(Top);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(test, top,"Logging specific to this test");
+GRAS_LOG_NEW_CATEGORY(top,"Useless test channel");
 
 int main(int argc, char **argv) {
   gras_init_defaultlog(&argc,argv,"root.thresh=debug log.thresh=debug");
 
   DEBUG1("val=%d", 1);
   WARN1("val=%d", 2);
-  CDEBUG2(Top, "val=%d%s", 3, "!");
+  CDEBUG2(top, "val=%d%s", 3, "!");
   CRITICAL6("false alarm%s%s%s%s%s%s", "","","","","","!");
   
   gras_exit();
index 6eed1e7..81730ad 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <gras.h>
 
-GRAS_LOG_NEW_DEFAULT_CATEGORY(test);
+GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
 GRAS_LOG_EXTERNAL_CATEGORY(set);
 
 typedef struct  {
@@ -41,9 +41,9 @@ static void my_elem_free(void *e) {
   my_elem_t *elm=(my_elem_t*)e;
 
   if (elm) {
-    free(elm->name);
-    free(elm->data);
-    free(elm);
+    gras_free(elm->name);
+    gras_free(elm->data);
+    gras_free(elm);
   }
 }
 
@@ -54,7 +54,7 @@ static gras_error_t debuged_add_with_data(gras_set_t *set,
   gras_error_t  errcode;
   my_elem_t    *elm;
 
-  elm = (my_elem_t*)malloc(sizeof(my_elem_t));
+  elm = gras_new(my_elem_t,1);
   elm->name=strdup(name);
   elm->name_len=0;
 
@@ -153,10 +153,9 @@ static gras_error_t traverse(gras_set_t *set) {
   gras_set_foreach(set,cursor,elm) {
     gras_assert0(elm,"Dude ! Got a null elm during traversal!");
     printf("   - Id(%d):  %s->%s\n",elm->ID,elm->name,elm->data);
-    if (strcmp(elm->name,elm->data)) {
-      printf("Key(%s) != value(%s). Abording\n",elm->name,elm->data);
-      abort();
-    }
+    gras_assert2(!strcmp(elm->name,elm->data),
+                "Key(%s) != value(%s). Abording",
+                elm->name,elm->data);
   }
   return no_error;
 }