+ 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)
#include "gras.h"
-GRAS_LOG_NEW_DEFAULT_CATEGORY(Ping);
+GRAS_LOG_NEW_DEFAULT_CATEGORY(Ping,"Messages specific to this example");
/* **********************************************************************
* Comon code
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 \
#define GRAS_MAX_CHANNEL 10 /* FIXME: killme */
+#include <gros/sysdep.h>
+
#include <gros/error.h>
#include <gros/log.h>
#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 */
#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
__FILE__,__LINE__, \
gras_error_name(errcode)); \
fflush(stdout); \
- abort(); \
+ gras_abort(); \
} } while(0)
#define TRYEXPECT(action,expected_error) do { \
fprintf(stderr,"Got error %s (instead of %s expected)\n", \
gras_error_name(errcode), \
gras_error_name(expected_error)); \
- abort(); \
+ gras_abort(); \
} \
} while(0)
#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)
* 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:
/**
* 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)
/**
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.
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 \
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;
static void free_string(void *d);
static void free_string(void *d){
- free(*(void**)d);
+ gras_free(*(void**)d);
}
gras_error_t
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));
gras_dynar_free( (*state)->frames );
gras_dynar_free( (*state)->globals );
- free(*state);
+ gras_free(*state);
*state = NULL;
}
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;
*ddt = var->type;
data = var->data;
- free(var);
+ gras_free(var);
gras_dynar_pop(ps->frames, &frame);
{
gras_dynar_get(frame, l, &_name);
if (!strcmp(name, _name)) {
gras_dynar_remove_at(frame, l, &_name);
- free(_name);
+ gras_free(_name);
break;
}
}
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);
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");
#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;
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];
#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:
#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:
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);
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;
GRAS_IN;
if (field) {
if (field->name)
- free(field->name);
- free(field);
+ gras_free(field->name);
+ gras_free(field);
}
GRAS_OUT;
}
"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],
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));
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);
sprintf(name,"%s[]*",element_type->name);
TRY(gras_datadesc_ref(name,*dst,dst));
- free(name);
+ gras_free(name);
return no_error;
}
/* datadesc was invalid. Killing it is like euthanasy, I guess */
break;
}
- free(type->name);
- free(type);
+ gras_free(type->name);
+ gras_free(type);
}
#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 */
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);
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;
#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;
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;
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;
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]));
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,
} else {
return errcode;
}
- free(r_ref);
+ gras_free(r_ref);
break;
}
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) */
#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;
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 */
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 */
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;
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;
if (fixed) {
TRY(change_to_fixed_array(identifiers,atoi(keyval)));
TRY(change_to_ref(identifiers));
- free(keyval);
+ gras_free(keyval);
continue;
} else {
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);
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);
}
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] == '{') {
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)",
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
#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];
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);
}
}
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);
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);
if (errcode != no_error)
res = NULL;
if (name != namev)
- free(namev);
+ gras_free(namev);
return res;
}
"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;
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;
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;
}
cpt+1,cb,msgtype->name);
if ((*cb)(expeditor,payload)) {
/* cb handled the message */
- free(payload);
+ gras_free(payload);
return no_error;
}
}
gras_cblist_t *list=*(void**)data;
if (list) {
gras_dynar_free(list->cbs);
- free(list);
+ gras_free(list);
}
}
}
if (!list) {
/* First cb? Create room */
- list = malloc(sizeof(gras_cblist_t));
+ list = gras_new(gras_cblist_t,1);
if (!list)
RAISE_MALLOC;
#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;
/* 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 */
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;
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:
break;
default:
- free(plug);
+ gras_free(plug);
return errcode;
}
return no_error;
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);
}
}
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);
sock->accepting?'y':'n');
if (errcode != no_error) {
- free(sock);
+ gras_free(sock);
return errcode;
}
sock->accepting?'y':'n');
if (errcode != no_error) {
- free(sock);
+ gras_free(sock);
return errcode;
}
/* free the memory */
if (sock->peer_name)
- free(sock->peer_name);
- free(sock);
+ gras_free(sock->peer_name);
+ gras_free(sock);
return;
}
}
#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
#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
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;
#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
#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
#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
* **************************************************************************/
#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());
#include "Virtu/virtu_sg.h"
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,GRAS);
+GRAS_LOG_EXTERNAL_CATEGORY(process);
gras_error_t
gras_process_init() {
#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))
#include "gras_config.h"
+#include "gros/sysdep.h"
+
#include "gros/error.h"
#include "gros/log.h"
#include "gros/module.h"
#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.
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);
}
}
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",
size);
switch (cell->type) {
+
case gras_cfgelm_int:
for (i=0; i<size; i++) {
gras_dynar_get(cell->content,i,&ival);
}
if (name) printf("%s<< End of the config set '%s'\n",indent,name);
+ fflush(stdout);
gras_dict_cursor_free(cursor);
return;
if (!c) return;
gras_dynar_free(c->content);
- free(c);
+ gras_free(c);
}
/*----[ Registering stuff ]-----------------------------------------------*/
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) {
/* 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;
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';
min=strtol(tok, &tok, 10);
if (!tok) {
ERROR1("Invalid minimum in config element descriptor %s",entry);
- free(entrycpy);
+ gras_free(entrycpy);
gras_abort();
}
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_");
max=strtol(tok, &tok, 10);
if (!tok) {
ERROR1("Invalid maximum in config element descriptor %s",entry);
- free(entrycpy);
+ gras_free(entrycpy);
gras_abort();
}
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();
}
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;
}
name,
cell->min,
gras_cfgelm_type_name[cell->type],
- size);
+ size);
+ gras_dict_cursor_free(cursor);
return mismatch_error;
}
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;
}
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.",
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 */
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') {
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;
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);
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);
*(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;
}
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) {
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) {
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);
}
}
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);
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));
}
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;
}
#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 ]#################################################*/
#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 ]#############################################*/
#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 ]#################################################*/
#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;
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)
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);
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;
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);
}
}
if (dynar->data) {
_gras_clear_mem(dynar->data, dynar->size);
- free(dynar->data);
+ gras_free(dynar->data);
}
dynar->size = 0;
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);
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
}
}
"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) {
} 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);
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)))
}
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),
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;
}
#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.
#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;
#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_ {
* 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)
if (*set) {
gras_dict_free ( &( (*set)->dict ) );
gras_dynar_free( (*set)->dynar );
- free(*set);
+ gras_free(*set);
*set=NULL;
}
}
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");
}
cursor=*curs;
if (! gras_dynar_cursor_get( cursor->set->dynar,&(cursor->val),elm) ) {
- free(cursor);
+ gras_free(cursor);
*curs=NULL;
return FALSE;
}
# 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
#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
gras_datadesc_type_t *my_type;
int *i,*j;
- if (! (i=malloc(sizeof(int))) )
+ if (! (i=gras_new(int,1)) )
RAISE_MALLOC;
*i=12345;
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;
}
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;
}
&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;
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;
}
&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;
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;
}
&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;
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;
}
}
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;
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) {
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);
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;
}
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));
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";
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");
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" \
/*====[ 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(){
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");
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;
#include <gras.h>
#include <time.h>
#include <stdio.h>
+#include <stdlib.h>
#define NB_ELM 20000
#define SIZEOFKEY 1024
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;
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;
}
#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);
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);
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;
}
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");
#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;
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;
}
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;
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;
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;
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);
#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;
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);
"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);
/* 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[]) {
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);
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);
}
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);
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);
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);
#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();
#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 {
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);
}
}
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;
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;
}