From bfbe7002a7ff4147e838e6d88841ed8e87683683 Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 2 Nov 2004 11:34:14 +0000 Subject: [PATCH] The change Arnaud wanted so much: Big Star Erradication git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@450 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/Makefile.am | 2 - include/gras/cond.h | 24 +------ include/gras/datadesc.h | 149 +++++++++++++++++++-------------------- include/gras/messages.h | 44 ++++++------ include/gras/process.h | 26 +------ include/gras/transport.h | 26 +++---- include/gras/virtu.h | 34 +++------ include/xbt/config.h | 72 ++++++++++--------- include/xbt/dict.h | 64 ++++++++--------- include/xbt/dynar.h | 63 +++++++++++------ include/xbt/error.h | 54 ++++++-------- include/xbt/log.h | 60 ++++++++-------- include/xbt/set.h | 50 +++++++------ include/xbt/sysdep.h | 38 ++++++---- 14 files changed, 330 insertions(+), 376 deletions(-) diff --git a/include/Makefile.am b/include/Makefile.am index 30bddb4195..272953e6ca 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -12,8 +12,6 @@ nobase_include_HEADERS = \ \ gras/messages.h \ \ - gras/core.h\ - \ gras/modules/base.h \ gras/modules/bandwidth.h diff --git a/include/gras/cond.h b/include/gras/cond.h index b39485ab1f..42ca8dbd5b 100644 --- a/include/gras/cond.h +++ b/include/gras/cond.h @@ -12,29 +12,7 @@ #ifndef GRAS_COND_H #define GRAS_COND_H -#include /* offsetof() */ -#include /* size_t */ -#include - - -/*! C++ users need love */ -#ifndef BEGIN_DECL -# ifdef __cplusplus -# define BEGIN_DECL extern "C" { -# else -# define BEGIN_DECL -# endif -#endif - -/*! C++ users need love */ -#ifndef END_DECL -# ifdef __cplusplus -# define END_DECL } -# else -# define END_DECL -# endif -#endif -/* End of cruft for C++ */ +#include "xbt/misc.h" /* BEGIN_DECL */ BEGIN_DECL diff --git a/include/gras/datadesc.h b/include/gras/datadesc.h index d3e57965ad..eb5491d564 100644 --- a/include/gras/datadesc.h +++ b/include/gras/datadesc.h @@ -11,10 +11,6 @@ #ifndef GRAS_DATADESC_H #define GRAS_DATADESC_H -#include /* offsetof() */ -#include /* size_t */ -#include - #include "xbt/misc.h" /* BEGIN_DECL */ BEGIN_DECL @@ -24,132 +20,131 @@ BEGIN_DECL * * Opaque type describing a type description you don't want to open. */ -typedef struct s_gras_datadesc_type gras_datadesc_type_t; +typedef struct s_gras_datadesc_type *gras_datadesc_type_t; -typedef struct s_gras_cbps gras_cbps_t; +typedef struct s_gras_cbps *gras_cbps_t; /* callbacks prototypes */ -typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t *vars, void *data); -typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t *vars, void *data); -typedef gras_datadesc_type_t *(*gras_datadesc_selector_t)(gras_cbps_t *vars, void *data); +typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t vars, void *data); +typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t vars, void *data); +typedef gras_datadesc_type_t (*gras_datadesc_selector_t)(gras_cbps_t vars, void *data); /*********************************************** **** Search and retrieve declared datatype **** ***********************************************/ -gras_datadesc_type_t *gras_datadesc_by_name(const char *name); +gras_datadesc_type_t gras_datadesc_by_name(const char *name); /****************************************** **** Declare datadescription yourself **** ******************************************/ -gras_datadesc_type_t * - gras_datadesc_struct(const char *name); +gras_datadesc_type_t gras_datadesc_struct(const char *name); void - gras_datadesc_struct_append(gras_datadesc_type_t *struct_type, - const char *name, - gras_datadesc_type_t *field_type); + gras_datadesc_struct_append(gras_datadesc_type_t struct_type, + const char *name, + gras_datadesc_type_t field_type); void - gras_datadesc_struct_close(gras_datadesc_type_t *struct_type); + gras_datadesc_struct_close(gras_datadesc_type_t struct_type); -gras_datadesc_type_t * - gras_datadesc_union(const char *name, - gras_datadesc_type_cb_int_t selector); +gras_datadesc_type_t + gras_datadesc_union(const char *name, + gras_datadesc_type_cb_int_t selector); void - gras_datadesc_union_append(gras_datadesc_type_t *union_type, - const char *name, - gras_datadesc_type_t *field_type); + gras_datadesc_union_append(gras_datadesc_type_t union_type, + const char *name, + gras_datadesc_type_t field_type); void - gras_datadesc_union_close(gras_datadesc_type_t *union_type); + gras_datadesc_union_close(gras_datadesc_type_t union_type); -gras_datadesc_type_t * - gras_datadesc_ref(const char *name, - gras_datadesc_type_t *referenced_type); -gras_datadesc_type_t * +gras_datadesc_type_t + gras_datadesc_ref(const char *name, + gras_datadesc_type_t referenced_type); +gras_datadesc_type_t gras_datadesc_ref_generic(const char *name, gras_datadesc_selector_t selector); -gras_datadesc_type_t * - gras_datadesc_array_fixed(const char *name, - gras_datadesc_type_t *element_type, - long int fixed_size); -gras_datadesc_type_t * - gras_datadesc_array_dyn(const char *name, - gras_datadesc_type_t *element_type, - gras_datadesc_type_cb_int_t dynamic_size); +gras_datadesc_type_t + gras_datadesc_array_fixed(const char *name, + gras_datadesc_type_t element_type, + long int fixed_size); +gras_datadesc_type_t + gras_datadesc_array_dyn(const char *name, + gras_datadesc_type_t element_type, + gras_datadesc_type_cb_int_t dynamic_size); -gras_datadesc_type_t * - gras_datadesc_ref_pop_arr(gras_datadesc_type_t *element_type); +gras_datadesc_type_t + gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type); /********************************* * Change stuff within datadescs * *********************************/ -void gras_datadesc_cycle_set(gras_datadesc_type_t *type); -void gras_datadesc_cycle_unset(gras_datadesc_type_t *type); +void gras_datadesc_cycle_set(gras_datadesc_type_t type); +void gras_datadesc_cycle_unset(gras_datadesc_type_t type); -void gras_datadesc_cb_send (gras_datadesc_type_t *type, - gras_datadesc_type_cb_void_t pre); -void gras_datadesc_cb_recv(gras_datadesc_type_t *type, +void gras_datadesc_cb_send (gras_datadesc_type_t type, + gras_datadesc_type_cb_void_t pre); +void gras_datadesc_cb_recv(gras_datadesc_type_t type, gras_datadesc_type_cb_void_t post); -void gras_datadesc_cb_field_send (gras_datadesc_type_t *type, - const char *field_name, +void gras_datadesc_cb_field_send (gras_datadesc_type_t type, + const char *field_name, gras_datadesc_type_cb_void_t pre); -void gras_datadesc_cb_field_recv(gras_datadesc_type_t *type, - const char *field_name, +void gras_datadesc_cb_field_recv(gras_datadesc_type_t type, + const char *field_name, gras_datadesc_type_cb_void_t post); -void gras_datadesc_cb_field_push (gras_datadesc_type_t *type, - const char *field_name); +void gras_datadesc_cb_field_push (gras_datadesc_type_t type, + const char *field_name); /****************************** * Get stuff within datadescs * ******************************/ -char * gras_datadesc_get_name(gras_datadesc_type_t *ddt); -int gras_datadesc_get_id(gras_datadesc_type_t *ddt); +char * gras_datadesc_get_name(gras_datadesc_type_t ddt); +int gras_datadesc_get_id(gras_datadesc_type_t ddt); /******************************************************** * Advanced data describing: callback persistent states * ********************************************************/ /* simple one: push/pop sizes of arrays */ void -gras_cbps_i_push(gras_cbps_t *ps, int val); +gras_cbps_i_push(gras_cbps_t ps, int val); int -gras_cbps_i_pop(gras_cbps_t *ps); +gras_cbps_i_pop(gras_cbps_t ps); -int gras_datadesc_cb_pop(gras_cbps_t *vars, void *data); -void gras_datadesc_cb_push_int(gras_cbps_t *vars, void *data); -void gras_datadesc_cb_push_uint(gras_cbps_t *vars, void *data); -void gras_datadesc_cb_push_lint(gras_cbps_t *vars, void *data); -void gras_datadesc_cb_push_ulint(gras_cbps_t *vars, void *data); +int gras_datadesc_cb_pop(gras_cbps_t vars, void *data); +void gras_datadesc_cb_push_int(gras_cbps_t vars, void *data); +void gras_datadesc_cb_push_uint(gras_cbps_t vars, void *data); +void gras_datadesc_cb_push_lint(gras_cbps_t vars, void *data); +void gras_datadesc_cb_push_ulint(gras_cbps_t vars, void *data); /* complex one: complete variable environment support */ gras_error_t -gras_cbps_v_pop (gras_cbps_t *ps, - const char *name, - gras_datadesc_type_t **ddt, - void **res); + gras_cbps_v_pop (gras_cbps_t ps, + const char *name, + /* OUT */ gras_datadesc_type_t *ddt, + /* OUT */ void **res); gras_error_t -gras_cbps_v_push(gras_cbps_t *ps, - const char *name, - void *data, - gras_datadesc_type_t *ddt); +gras_cbps_v_push(gras_cbps_t ps, + const char *name, + void *data, + gras_datadesc_type_t ddt); void -gras_cbps_v_set (gras_cbps_t *ps, - const char *name, - void *data, - gras_datadesc_type_t *ddt); +gras_cbps_v_set (gras_cbps_t ps, + const char *name, + void *data, + gras_datadesc_type_t ddt); void * -gras_cbps_v_get (gras_cbps_t *ps, - const char *name, - gras_datadesc_type_t **ddt); +gras_cbps_v_get (gras_cbps_t ps, + const char *name, + /* OUT */ gras_datadesc_type_t *ddt); void -gras_cbps_block_begin(gras_cbps_t *ps); +gras_cbps_block_begin(gras_cbps_t ps); void -gras_cbps_block_end(gras_cbps_t *ps); +gras_cbps_block_end(gras_cbps_t ps); @@ -162,7 +157,7 @@ int gras_arch_selfid(void); /* ID of this arch */ /**************************** **** Parse C statements **** ****************************/ -gras_datadesc_type_t * +gras_datadesc_type_t gras_datadesc_parse(const char *name, const char *Cdefinition); #define GRAS_DEFINE_TYPE(name,def) \ @@ -223,8 +218,8 @@ typedef struct DataDescriptorStruct { gras_error_t gras_datadesc_import_nws(const char *name, const DataDescriptor *desc, - size_t howmany, - gras_datadesc_type_t **dst); + unsigned long howmany, + /* OUT */ gras_datadesc_type_t *dst); END_DECL diff --git a/include/gras/messages.h b/include/gras/messages.h index 96e8152cd3..032bbc2041 100644 --- a/include/gras/messages.h +++ b/include/gras/messages.h @@ -21,17 +21,17 @@ BEGIN_DECL /* msgtype declaration and retrival */ -typedef struct s_gras_msgtype gras_msgtype_t; +typedef struct s_gras_msgtype *gras_msgtype_t; -void gras_msgtype_declare (const char *name, - gras_datadesc_type_t *payload); -void gras_msgtype_declare_v(const char *name, - short int version, - gras_datadesc_type_t *payload); +void gras_msgtype_declare (const char *name, + gras_datadesc_type_t payload); +void gras_msgtype_declare_v(const char *name, + short int version, + gras_datadesc_type_t payload); -gras_msgtype_t *gras_msgtype_by_name (const char *name); -gras_msgtype_t *gras_msgtype_by_namev(const char *name, - short int version); +gras_msgtype_t gras_msgtype_by_name (const char *name); +gras_msgtype_t gras_msgtype_by_namev(const char *name, + short int version); /** * gras_cb_t: @@ -44,20 +44,20 @@ gras_msgtype_t *gras_msgtype_by_namev(const char *name, * * If the callback accepts the message, it should free it after use. */ -typedef int (*gras_cb_t)(gras_socket_t *expeditor, - void *payload); -void gras_cb_register (gras_msgtype_t *msgtype, - gras_cb_t cb); -void gras_cb_unregister(gras_msgtype_t *msgtype, - gras_cb_t cb); - -gras_error_t gras_msg_send(gras_socket_t *sock, - gras_msgtype_t *msgtype, +typedef int (*gras_cb_t)(gras_socket_t expeditor, + void *payload); +void gras_cb_register (gras_msgtype_t msgtype, + gras_cb_t cb); +void gras_cb_unregister(gras_msgtype_t msgtype, + gras_cb_t cb); + +gras_error_t gras_msg_send(gras_socket_t sock, + gras_msgtype_t msgtype, + void *payload); +gras_error_t gras_msg_wait(double timeout, + gras_msgtype_t msgt_want, + gras_socket_t *expeditor, void *payload); -gras_error_t gras_msg_wait(double timeout, - gras_msgtype_t *msgt_want, - gras_socket_t **expeditor, - void *payload); gras_error_t gras_msg_handle(double timeOut); diff --git a/include/gras/process.h b/include/gras/process.h index 5b528a4abf..761647f193 100644 --- a/include/gras/process.h +++ b/include/gras/process.h @@ -3,7 +3,7 @@ /* gras/core.h - Unsorted part of the GRAS public interface */ /* Authors: Martin Quinson */ -/* Copyright (C) 2003 the OURAGAN project. */ +/* Copyright (C) 2003,2004 the OURAGAN project. */ /* 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. */ @@ -11,29 +11,7 @@ #ifndef GRAS_PROCESS_H #define GRAS_PROCESS_H -#include /* offsetof() */ -#include /* size_t */ -#include - - -/*! C++ users need love */ -#ifndef BEGIN_DECL -# ifdef __cplusplus -# define BEGIN_DECL extern "C" { -# else -# define BEGIN_DECL -# endif -#endif - -/*! C++ users need love */ -#ifndef END_DECL -# ifdef __cplusplus -# define END_DECL } -# else -# define END_DECL -# endif -#endif -/* End of cruft for C++ */ +#include "xbt/misc.h" /* BEGIN_DECL */ BEGIN_DECL diff --git a/include/gras/transport.h b/include/gras/transport.h index 32a5cdb3c4..ca99c83b43 100644 --- a/include/gras/transport.h +++ b/include/gras/transport.h @@ -15,46 +15,46 @@ #include "xbt/error.h" -typedef struct s_gras_socket gras_socket_t; +typedef struct s_gras_socket *gras_socket_t; gras_error_t gras_socket_client(const char *host, unsigned short port, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *dst); gras_error_t gras_socket_server(unsigned short port, - /* OUT */ gras_socket_t **dst); -void gras_socket_close(gras_socket_t *sd); + /* OUT */ gras_socket_t *dst); +void gras_socket_close(gras_socket_t sd); /* get information about socket */ -int gras_socket_my_port (gras_socket_t *sock); -int gras_socket_peer_port(gras_socket_t *sock); -char *gras_socket_peer_name(gras_socket_t *sock); +int gras_socket_my_port (gras_socket_t sock); +int gras_socket_peer_port(gras_socket_t sock); +char *gras_socket_peer_name(gras_socket_t sock); /* extended interface to get all details */ gras_error_t gras_socket_client_ext(const char *host, unsigned short port, unsigned long int bufSize, int raw, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *dst); gras_error_t gras_socket_server_ext(unsigned short port, unsigned long int bufSize, int raw, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *dst); /* using raw sockets */ -gras_error_t gras_socket_raw_send(gras_socket_t *peer, +gras_error_t gras_socket_raw_send(gras_socket_t peer, unsigned int timeout, unsigned long int expSize, unsigned long int msgSize); -gras_error_t gras_socket_raw_recv(gras_socket_t *peer, +gras_error_t gras_socket_raw_recv(gras_socket_t peer, unsigned int timeout, unsigned long int expSize, unsigned long int msgSize); /* debuging functions */ gras_error_t gras_socket_client_from_file(const char*path, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *dst); gras_error_t gras_socket_server_from_file(const char*path, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *dst); #endif /* GRAS_TRANSPORT_H */ diff --git a/include/gras/virtu.h b/include/gras/virtu.h index 8da06b2e1b..2669f23ab0 100644 --- a/include/gras/virtu.h +++ b/include/gras/virtu.h @@ -11,29 +11,7 @@ #ifndef GRAS_VIRTU_H #define GRAS_VIRTU_H -#include /* offsetof() */ -#include /* size_t */ -#include - - -/*! C++ users need love */ -#ifndef BEGIN_DECL -# ifdef __cplusplus -# define BEGIN_DECL extern "C" { -# else -# define BEGIN_DECL -# endif -#endif - -/*! C++ users need love */ -#ifndef END_DECL -# ifdef __cplusplus -# define END_DECL } -# else -# define END_DECL -# endif -#endif -/* End of cruft for C++ */ +#include "xbt/misc.h" /* BEGIN_DECL */ BEGIN_DECL @@ -55,6 +33,16 @@ double gras_os_time(void); */ void gras_os_sleep(unsigned long sec, unsigned long usec); +/** + * gras_get_my_fqdn: + * + * Returns the fully-qualified name of the host machine, or NULL if the name + * cannot be determined. Always returns the same value, so multiple calls + * cause no problems. + */ +const char * +gras_get_my_fqdn(void); + END_DECL #endif /* GRAS_VIRTU_H */ diff --git a/include/xbt/config.h b/include/xbt/config.h index a4ff04f570..f12386eae7 100644 --- a/include/xbt/config.h +++ b/include/xbt/config.h @@ -5,7 +5,7 @@ /* This is useful to build named structs, like option or property sets. */ /* Authors: Martin Quinson */ -/* Copyright (C) 2001,2002,2003,2004 the OURAGAN project. */ +/* Copyright (C) 2001,2002,2003,2004 da GRAS posse. */ /* 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. */ @@ -13,6 +13,10 @@ #ifndef _GRAS_CONFIG_H_ #define _GRAS_CONFIG_H_ +#include "xbt/dynar.h" + +BEGIN_DECL + /* For now, a config is only a special dynar. But don't rely on it, */ /* it may change in the future. */ typedef gras_dynar_t gras_cfg_t; @@ -21,33 +25,34 @@ typedef gras_dynar_t gras_cfg_t; typedef enum { gras_cfgelm_int=0, gras_cfgelm_double, gras_cfgelm_string, gras_cfgelm_host, gras_cfgelm_type_count -} gras_cfgelm_type_t; +} e_gras_cfgelm_type_t; /*----[ Memory management ]-----------------------------------------------*/ -gras_cfg_t *gras_cfg_new (void); -void gras_cfg_cpy(gras_cfg_t **whereto, gras_cfg_t *tocopy); -void gras_cfg_free(gras_cfg_t **cfg); -void gras_cfg_dump(const char *name,const char*indent,gras_cfg_t *cfg); +gras_cfg_t gras_cfg_new (void); +void gras_cfg_cpy(gras_cfg_t tocopy, + /* OUT */ gras_cfg_t *whereto); +void gras_cfg_free(gras_cfg_t *cfg); +void gras_cfg_dump(const char *name,const char*indent,gras_cfg_t cfg); /*----[ Registering stuff ]-----------------------------------------------*/ /* Register a possible cell */ -void gras_cfg_register(gras_cfg_t *cfg, - const char *name, gras_cfgelm_type_t type, +void gras_cfg_register(gras_cfg_t cfg, + const char *name, e_gras_cfgelm_type_t type, int min, int max); /* Unregister a possible cell */ -gras_error_t gras_cfg_unregister(gras_cfg_t *cfg, const char *name); +gras_error_t gras_cfg_unregister(gras_cfg_t cfg, const char *name); /* Parse the configuration descriptor and register it */ /* Should be of the form ":_to__", */ /* with type being one of 'string','int', 'host' or 'double' */ -gras_error_t gras_cfg_register_str(gras_cfg_t *cfg, const char *entry); +gras_error_t gras_cfg_register_str(gras_cfg_t cfg, const char *entry); /* Check that each cell have the right amount of elements */ -gras_error_t gras_cfg_check(gras_cfg_t *cfg); +gras_error_t gras_cfg_check(gras_cfg_t cfg); /* Get the type of this option in that repository */ -gras_error_t gras_cfg_get_type(gras_cfg_t *cfg, const char *name, - /* OUT */ gras_cfgelm_type_t *type); +gras_error_t gras_cfg_get_type(gras_cfg_t cfg, const char *name, + /* OUT */ e_gras_cfgelm_type_t *type); /*----[ Setting ]--------------------------------------------------------- * gras_cfg_set_* functions. @@ -58,61 +63,62 @@ gras_error_t gras_cfg_get_type(gras_cfg_t *cfg, const char *name, * * string values are strdup'ed before use, so you have to free your copy */ -gras_error_t gras_cfg_set_vargs(gras_cfg_t *cfg, va_list pa); -gras_error_t gras_cfg_set(gras_cfg_t *cfg, ...); +gras_error_t gras_cfg_set_vargs(gras_cfg_t cfg, va_list pa); +gras_error_t gras_cfg_set(gras_cfg_t cfg, ...); /* Add the cells described in a string to a typed hash. */ -gras_error_t gras_cfg_set_parse(gras_cfg_t *cfg, const char *options); +gras_error_t gras_cfg_set_parse(gras_cfg_t cfg, const char *options); /* Set the value of the cell @name in @cfg with the provided value. */ -gras_error_t gras_cfg_set_int (gras_cfg_t *cfg, const char *name, +gras_error_t gras_cfg_set_int (gras_cfg_t cfg, const char *name, int val); -gras_error_t gras_cfg_set_double(gras_cfg_t *cfg, const char *name, +gras_error_t gras_cfg_set_double(gras_cfg_t cfg, const char *name, double val); -gras_error_t gras_cfg_set_string(gras_cfg_t *cfg, const char *name, +gras_error_t gras_cfg_set_string(gras_cfg_t cfg, const char *name, const char *val); -gras_error_t gras_cfg_set_host (gras_cfg_t *cfg, const char *name, +gras_error_t gras_cfg_set_host (gras_cfg_t cfg, const char *name, const char *host,int port); /* Remove the provided value from the cell @name in @cfg. */ -gras_error_t gras_cfg_rm_int (gras_cfg_t *cfg, const char *name, +gras_error_t gras_cfg_rm_int (gras_cfg_t cfg, const char *name, int val); -gras_error_t gras_cfg_rm_double(gras_cfg_t *cfg, const char *name, +gras_error_t gras_cfg_rm_double(gras_cfg_t cfg, const char *name, double val); -gras_error_t gras_cfg_rm_string(gras_cfg_t *cfg, const char *name, +gras_error_t gras_cfg_rm_string(gras_cfg_t cfg, const char *name, const char *val); -gras_error_t gras_cfg_rm_host (gras_cfg_t *cfg, const char *name, +gras_error_t gras_cfg_rm_host (gras_cfg_t cfg, const char *name, const char *host,int port); /* rm every values */ -gras_error_t gras_cfg_empty(gras_cfg_t *cfg, const char *name); +gras_error_t gras_cfg_empty(gras_cfg_t cfg, const char *name); /*----[ Getting ]---------------------------------------------------------*/ /* Returns a pointer to the values actually stored in the cache. Do not */ /* modify them unless you really know what you're doing. */ -gras_error_t gras_cfg_get_int (gras_cfg_t *cfg, +gras_error_t gras_cfg_get_int (gras_cfg_t cfg, const char *name, int *val); -gras_error_t gras_cfg_get_double(gras_cfg_t *cfg, +gras_error_t gras_cfg_get_double(gras_cfg_t cfg, const char *name, double *val); -gras_error_t gras_cfg_get_string(gras_cfg_t *cfg, +gras_error_t gras_cfg_get_string(gras_cfg_t cfg, const char *name, char **val); -gras_error_t gras_cfg_get_host (gras_cfg_t *cfg, +gras_error_t gras_cfg_get_host (gras_cfg_t cfg, const char *name, char **host, int *port); -gras_error_t gras_cfg_get_dynar (gras_cfg_t *cfg, - const char *name, - gras_dynar_t **dynar); - +gras_error_t gras_cfg_get_dynar (gras_cfg_t cfg, + const char *name, + /* OUT */ gras_dynar_t *dynar); +END_DECL + #endif /* _GRAS_CONFIG_H_ */ diff --git a/include/xbt/dict.h b/include/xbt/dict.h index a209155839..cb020d497b 100644 --- a/include/xbt/dict.h +++ b/include/xbt/dict.h @@ -17,19 +17,19 @@ extern "C" #endif /*####[ Type definition ]####################################################*/ -typedef struct gras_dict_ gras_dict_t; +typedef struct gras_dict_ *gras_dict_t; /*####[ Simple dict functions ]#############################################*/ -gras_dict_t *gras_dict_new(void); -void gras_dict_free(gras_dict_t **dict); +gras_dict_t gras_dict_new(void); +void gras_dict_free(gras_dict_t *dict); -void gras_dict_set (gras_dict_t *head, +void gras_dict_set (gras_dict_t head, const char *key, void *data, void_f_pvoid_t *free_ctn); -void gras_dict_set_ext(gras_dict_t *head, +void gras_dict_set_ext(gras_dict_t head, const char *key, int key_len, void *data, @@ -39,25 +39,25 @@ void gras_dict_set_ext(gras_dict_t *head, /* Search the given #key#. data=NULL when not found. */ /* Returns true if anything went ok, and false on internal error. */ /*---------------------------------------------------------------------------*/ -gras_error_t gras_dict_get(gras_dict_t *head,const char *key, +gras_error_t gras_dict_get(gras_dict_t head,const char *key, /* OUT */void **data); -gras_error_t gras_dict_get_ext(gras_dict_t *head,const char *key, +gras_error_t gras_dict_get_ext(gras_dict_t head,const char *key, int key_len, /* OUT */void **data); /*----[ gras_dict_remove ]---------------------------------------------------*/ /* Remove the entry associated with the given #key#. */ /* Returns if ok. Removing a non-existant key is ok. */ /*---------------------------------------------------------------------------*/ -gras_error_t gras_dict_remove(gras_dict_t *head,const char *key); +gras_error_t gras_dict_remove(gras_dict_t head,const char *key); -gras_error_t gras_dict_remove_ext(gras_dict_t *head,const char *key, - int key_len); +gras_error_t gras_dict_remove_ext(gras_dict_t head, + const char *key, int key_len); /*----[ gras_dict_dump ]-----------------------------------------------------*/ /* Outputs the content of the structure. (for debuging purpose) */ /* #output# is a function to output the data.If NULL, data won't be displayed*/ /*---------------------------------------------------------------------------*/ -void gras_dict_dump(gras_dict_t *head, +void gras_dict_dump(gras_dict_t head, void (*output)(void*)); /*----[ gras_dict_print ]----------------------------------------------------*/ /* To dump multicache, this function dump a cache */ @@ -81,11 +81,11 @@ void gras_dict_prints(void *data); /* The key are destroyed in the process. Think to strdup it before. */ /* Returns if it was ok or not */ /*---------------------------------------------------------------------------*/ -gras_error_t gras_multidict_set(gras_dict_t **head, +gras_error_t gras_multidict_set(gras_dict_t *head, int keycount,char **key, void *data,void (*free_ctn)(void*)); -gras_error_t gras_multidict_set_ext(gras_dict_t **head, +gras_error_t gras_multidict_set_ext(gras_dict_t *head, int keycount,char **key,int *key_len, void *data,void_f_pvoid_t *free_ctn); @@ -93,11 +93,11 @@ gras_error_t gras_multidict_set_ext(gras_dict_t **head, /* Search the given #key#. data=NULL when not found. */ /* Returns true if anything went ok, and false on internal error. */ /*---------------------------------------------------------------------------*/ -gras_error_t gras_multidict_get(gras_dict_t *head, +gras_error_t gras_multidict_get(gras_dict_t head, int keycount,const char **key, /* OUT */void **data); -gras_error_t gras_multidict_get_ext(gras_dict_t *head, +gras_error_t gras_multidict_get_ext(gras_dict_t head, int keycount,const char **key,int *key_len, /* OUT */void **data); @@ -105,40 +105,40 @@ gras_error_t gras_multidict_get_ext(gras_dict_t *head, /* Remove the entry associated with the given #key#. */ /* Returns if ok. Removing a non-existant key is ok. */ /*---------------------------------------------------------------------------*/ -gras_error_t gras_multidict_remove(gras_dict_t *head, +gras_error_t gras_multidict_remove(gras_dict_t head, int keycount,const char **key); -gras_error_t gras_multidict_remove_ext(gras_dict_t *head, +gras_error_t gras_multidict_remove_ext(gras_dict_t head, int keycount,const char **key,int *key_len); /*####[ Cache cursor functions ]#############################################*/ /* To traverse (simple) caches */ /* Don't add or remove entries to the cache while traversing !!! */ /*###########################################################################*/ -typedef struct gras_dict_cursor_ gras_dict_cursor_t; +typedef struct gras_dict_cursor_ *gras_dict_cursor_t; /* creator/destructor */ -gras_dict_cursor_t *gras_dict_cursor_new(const gras_dict_t *head); -void gras_dict_cursor_free(gras_dict_cursor_t *cursor); +gras_dict_cursor_t gras_dict_cursor_new(const gras_dict_t head); +void gras_dict_cursor_free(gras_dict_cursor_t *cursor); /* back to first element it is not enough to reinit the cache after an add/remove in cache*/ -void gras_dict_cursor_rewind(gras_dict_cursor_t *cursor); +void gras_dict_cursor_rewind(gras_dict_cursor_t cursor); -gras_error_t gras_dict_cursor_get_key (gras_dict_cursor_t *cursor, +gras_error_t gras_dict_cursor_get_key (gras_dict_cursor_t cursor, /*OUT*/char **key); -gras_error_t gras_dict_cursor_get_data (gras_dict_cursor_t *cursor, +gras_error_t gras_dict_cursor_get_data (gras_dict_cursor_t cursor, /*OUT*/void **data); -void gras_dict_cursor_first (const gras_dict_t *dict, - gras_dict_cursor_t **cursor); -void gras_dict_cursor_step (gras_dict_cursor_t *cursor); -int gras_dict_cursor_get_or_free (gras_dict_cursor_t **cursor, - char **key, - void **data); -#define gras_dict_foreach(dict,cursor,key,data) \ - for (cursor=NULL, gras_dict_cursor_first((dict),&(cursor)) ; \ - gras_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data)); \ +void gras_dict_cursor_first (const gras_dict_t dict, + gras_dict_cursor_t *cursor); +void gras_dict_cursor_step (gras_dict_cursor_t cursor); +int gras_dict_cursor_get_or_free (gras_dict_cursor_t *cursor, + char **key, + void **data); +#define gras_dict_foreach(dict,cursor,key,data) \ + for (cursor=NULL, gras_dict_cursor_first((dict),&(cursor)) ; \ + gras_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));\ gras_dict_cursor_step(cursor) ) #ifdef __cplusplus diff --git a/include/xbt/dynar.h b/include/xbt/dynar.h index 2a86250a75..801180a77f 100644 --- a/include/xbt/dynar.h +++ b/include/xbt/dynar.h @@ -11,47 +11,63 @@ #ifndef _GRAS_DYNAR_H #define _GRAS_DYNAR_H -typedef struct gras_dynar_s gras_dynar_t; +#include "xbt/misc.h" /* BEGIN_DECL */ + +BEGIN_DECL + +typedef struct gras_dynar_s *gras_dynar_t; /* pointer to a function freeing something */ typedef void (void_f_ppvoid_t)(void**); typedef void (void_f_pvoid_t) (void*); -gras_dynar_t *gras_dynar_new(unsigned long elm_size, +gras_dynar_t gras_dynar_new(unsigned long elm_size, void_f_pvoid_t *free_func); void gras_dynar_free(gras_dynar_t *dynar); void gras_dynar_free_container(gras_dynar_t *dynar); -unsigned long gras_dynar_length(const gras_dynar_t *dynar); -void gras_dynar_reset(gras_dynar_t *dynar); +unsigned long gras_dynar_length(const gras_dynar_t dynar); +void gras_dynar_reset(gras_dynar_t dynar); /* regular array functions */ -void gras_dynar_get_cpy(const gras_dynar_t *dynar, int idx, void *const dst); -void *gras_dynar_get_ptr(const gras_dynar_t * const dynar, - const int idx); +void gras_dynar_get_cpy(const gras_dynar_t dynar, int idx, void *const dst); +void *gras_dynar_get_ptr(const gras_dynar_t dynar, + const int idx); #define gras_dynar_get_as(dynar,idx,type) *(type*)gras_dynar_get_ptr(dynar,idx) -void gras_dynar_set(gras_dynar_t *dynar, int idx, const void *src); -void gras_dynar_replace(gras_dynar_t *dynar, +void gras_dynar_set(gras_dynar_t dynar, int idx, const void *src); +void gras_dynar_replace(gras_dynar_t dynar, int idx, const void *object); /* perl array function */ -void gras_dynar_insert_at(gras_dynar_t *dynar, - int idx, const void *src); -void gras_dynar_remove_at(gras_dynar_t *dynar, - int idx, void *object); -void gras_dynar_push (gras_dynar_t *dynar, const void *src); -void gras_dynar_pop (gras_dynar_t *dynar, void *const dst); -void gras_dynar_unshift (gras_dynar_t *dynar, const void *src); -void gras_dynar_shift (gras_dynar_t *dynar, void *const dst); -void gras_dynar_map (const gras_dynar_t *dynar, void_f_pvoid_t *operator); + +void gras_dynar_insert_at(gras_dynar_t dynar, + int idx, const void *src); +void gras_dynar_remove_at(gras_dynar_t dynar, + int idx, void *object); +void gras_dynar_push (gras_dynar_t dynar, const void *src); +void gras_dynar_pop (gras_dynar_t dynar, void *const dst); +void gras_dynar_unshift (gras_dynar_t dynar, const void *src); +void gras_dynar_shift (gras_dynar_t dynar, void *const dst); +void gras_dynar_map (const gras_dynar_t dynar, void_f_pvoid_t *operator); + +/* speed-optimized versions */ +void *gras_dynar_insert_at_ptr(gras_dynar_t const dynar, + const int idx); +void *gras_dynar_push_ptr(gras_dynar_t dynar); +void *gras_dynar_pop_ptr(gras_dynar_t dynar); + +#define gras_dynar_insert_at_as(dynar,idx,type,value) *(type*)gras_dynar_insert_at_ptr(dynar,idx)=value +#define gras_dynar_push_as(dynar,type,value) *(type*)gras_dynar_push_ptr(dynar)=value +#define gras_dynar_pop_as(dynar,type) *(type*)gras_dynar_pop_ptr(dynar) + /* cursor functions */ -void gras_dynar_cursor_first (const gras_dynar_t *dynar, int *cursor); -void gras_dynar_cursor_step (const gras_dynar_t *dynar, int *cursor); -int gras_dynar_cursor_get (const gras_dynar_t *dynar, int *cursor, void *whereto); +void gras_dynar_cursor_first (const gras_dynar_t dynar, int *cursor); +void gras_dynar_cursor_step (const gras_dynar_t dynar, int *cursor); +int gras_dynar_cursor_get (const gras_dynar_t dynar, int *cursor, void *whereto); /** * gras_dynar_foreach: @@ -79,7 +95,8 @@ int gras_dynar_cursor_get (const gras_dynar_t *dynar, int *cursor, void *wher gras_dynar_length(_dynar) && gras_dynar_cursor_get(_dynar,&_cursor,&_data); \ gras_dynar_cursor_step(_dynar,&_cursor)) */ -void gras_dynar_cursor_rm(gras_dynar_t * dynar, - int * const cursor); +void gras_dynar_cursor_rm(gras_dynar_t dynar, + int *const cursor); +END_DECL #endif /* _GRAS_DYNAR_H */ diff --git a/include/xbt/error.h b/include/xbt/error.h index 9aa54b2eaa..4dabcc80aa 100644 --- a/include/xbt/error.h +++ b/include/xbt/error.h @@ -3,7 +3,7 @@ /* gras/error.h - Error tracking support */ /* Authors: Martin Quinson */ -/* Copyright (C) 2003 the OURAGAN project. */ +/* Copyright (C) 2003,2004 da GRAS posse. */ /* 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. */ @@ -12,48 +12,34 @@ #ifndef GRAS_ERROR_H #define GRAS_ERROR_H -#include /* offsetof() */ -#include /* size_t */ -#include - #include /* FIXME: Get rid of it */ +#include "xbt/misc.h" /* BEGIN_DECL */ #include "xbt/log.h" #ifdef HAVE_EXECINFO_H #include /* to print the backtrace */ #endif -/* C++ users need love */ -#ifndef BEGIN_DECL -# ifdef __cplusplus -# define BEGIN_DECL extern "C" { -# else -# define BEGIN_DECL -# endif -#endif - -/*! C++ users need love */ -#ifndef END_DECL -# ifdef __cplusplus -# define END_DECL } -# else -# define END_DECL -# endif -#endif -/* End of cruft for C++ */ - BEGIN_DECL typedef enum { - no_error=0, /* succes */ -// malloc_error, /* Well known error */ - mismatch_error, /* The provided ID does not match */ - system_error, /* a syscall did fail */ - network_error, /* error while sending/receiving data */ - timeout_error, /* not quick enough, dude */ - thread_error, /* error while [un]locking */ - unknown_error + no_error=0, /* succes */ + mismatch_error=1, /* The provided ID does not match */ + system_error=2, /* a syscall did fail */ + network_error=3, /* error while sending/receiving data */ + timeout_error=4, /* not quick enough, dude */ + thread_error=5, /* error while [un]locking */ + unknown_error=6, + + /* remote errors: result of a RMI/RPC. + no_error(=0) is the same for both */ + remote_mismatch_error=129, + remote_system_error, + remote_network_error, + remote_timeout_error, + remote_thread_error, + remote_unknown_error } gras_error_t; /*@observer@*/ const char *gras_error_name(gras_error_t errcode); @@ -108,7 +94,7 @@ typedef enum { return code; \ } while (0) -#else +#else /* if 0 */ #define _GRAS_ERR_PRE do { #define _GRAS_ERR_POST(code) \ return code; \ @@ -168,6 +154,8 @@ typedef enum { #define gras_assert6(cond,msg,a,b,c,d,e,f) if (!(cond)) { CRITICAL6(msg,a,b,c,d,e,f); gras_abort(); } #endif +void gras_die(const char *msg); + #define DIE_IMPOSSIBLE gras_assert0(0,"The Impossible did happen (yet again)") #define gras_assert_error(a) gras_assert1(errcode == (a), "Error %s unexpected",gras_error_name(errcode)) diff --git a/include/xbt/log.h b/include/xbt/log.h index d95838a601..b2e83b5acc 100644 --- a/include/xbt/log.h +++ b/include/xbt/log.h @@ -21,7 +21,7 @@ #include "xbt/sysdep.h" /** - * gras_log_priority_t: + * e_gras_log_priority_t: * @gras_log_priority_none: used internally (don't poke with) * @gras_log_priority_debug: crufty output * @gras_log_priority_verbose: verbose output for the user wanting more @@ -47,7 +47,7 @@ typedef enum { gras_log_priority_infinite = 8, gras_log_priority_uninitialized = -1 -} gras_log_priority_t; +} e_gras_log_priority_t; /** @@ -93,8 +93,8 @@ typedef enum { * Defines a new subcategory of the parent. */ #define GRAS_LOG_NEW_SUBCATEGORY(catName, parent, desc) \ - extern gras_log_category_t _GRAS_LOGV(parent); \ - gras_log_category_t _GRAS_LOGV(catName) = { \ + extern s_gras_log_category_t _GRAS_LOGV(parent); \ + s_gras_log_category_t _GRAS_LOGV(catName) = { \ &_GRAS_LOGV(parent), 0, 0, \ #catName, gras_log_priority_uninitialized, 1, \ 0, 1 \ @@ -120,7 +120,7 @@ typedef enum { # define GRAS_LOG_DEFAULT_CATEGORY(cname) #else # define GRAS_LOG_DEFAULT_CATEGORY(cname) \ - static gras_log_category_t* _GRAS_LOGV(default) = &_GRAS_LOGV(cname) + static gras_log_category_t _GRAS_LOGV(default) = &_GRAS_LOGV(cname) #endif /** @@ -157,41 +157,41 @@ typedef enum { */ #define GRAS_LOG_EXTERNAL_CATEGORY(cname) \ - extern gras_log_category_t _GRAS_LOGV(cname) + extern s_gras_log_category_t _GRAS_LOGV(cname) /* Functions you may call */ extern void gras_log_control_set(const char* cs); /* Forward declarations */ -typedef struct gras_log_appender_s gras_log_appender_t; -typedef struct gras_log_event_s gras_log_event_t; -typedef struct gras_log_category_s gras_log_category_t; +typedef struct gras_log_appender_s s_gras_log_appender_t,*gras_log_appender_t; +typedef struct gras_log_event_s s_gras_log_event_t, *gras_log_event_t; +typedef struct gras_log_category_s s_gras_log_category_t,*gras_log_category_t; /** - * Do NOT access any members of this structure directly. + * Do NOT access any members of this structure directly. FIXME: move to private? */ struct gras_log_category_s { - gras_log_category_t *parent; -/*@null@*/ gras_log_category_t *firstChild; -/*@null@*/ gras_log_category_t *nextSibling; + gras_log_category_t parent; +/*@null@*/ gras_log_category_t firstChild; +/*@null@*/ gras_log_category_t nextSibling; const char *name; int threshold; int isThreshInherited; -/*@null@*/ gras_log_appender_t *appender; +/*@null@*/ gras_log_appender_t appender; int willLogToParent; /* TODO: Formats? */ }; struct gras_log_appender_s { - void (*do_append) (gras_log_appender_t* thisLogAppender, - gras_log_event_t* event, const char *fmt); + void (*do_append) (gras_log_appender_t thisLogAppender, + gras_log_event_t event, const char *fmt); void *appender_data; }; struct gras_log_event_s { - gras_log_category_t* cat; - gras_log_priority_t priority; + gras_log_category_t cat; + e_gras_log_priority_t priority; const char* fileName; const char* functionName; int lineNum; @@ -205,8 +205,8 @@ struct gras_log_event_s { * * Programatically alters a category's threshold priority (don't use). */ -extern void gras_log_threshold_set(gras_log_category_t* cat, - gras_log_priority_t thresholdPriority); +extern void gras_log_threshold_set(gras_log_category_t cat, + e_gras_log_priority_t thresholdPriority); /** * gras_log_parent_set: @@ -215,8 +215,8 @@ extern void gras_log_threshold_set(gras_log_category_t* cat, * * Programatically alter a category's parent (don't use). */ -extern void gras_log_parent_set(gras_log_category_t* cat, - gras_log_category_t* parent); +extern void gras_log_parent_set(gras_log_category_t cat, + gras_log_category_t parent); /** * gras_log_appender_set: @@ -225,21 +225,21 @@ extern void gras_log_parent_set(gras_log_category_t* cat, * * Programatically sets the category's appender (don't use). */ -extern void gras_log_appender_set(gras_log_category_t* cat, - gras_log_appender_t* app); +extern void gras_log_appender_set(gras_log_category_t cat, + gras_log_appender_t app); /* Functions that you shouldn't call. */ -extern void _gras_log_event_log(gras_log_event_t*ev, +extern void _gras_log_event_log(gras_log_event_t ev, const char *fmt, ...) _GRAS_GNUC_PRINTF(2,3); -extern int _gras_log_cat_init(gras_log_priority_t priority, - gras_log_category_t* category); +extern int _gras_log_cat_init(e_gras_log_priority_t priority, + gras_log_category_t category); -extern gras_log_category_t _GRAS_LOGV(GRAS_LOG_ROOT_CAT); +extern s_gras_log_category_t _GRAS_LOGV(GRAS_LOG_ROOT_CAT); GRAS_LOG_EXTERNAL_CATEGORY(GRAS); -extern gras_log_appender_t *gras_log_default_appender; +extern gras_log_appender_t gras_log_default_appender; /** * GRAS_LOG_ISENABLED: @@ -282,7 +282,7 @@ extern gras_log_appender_t *gras_log_default_appender; #define _GRAS_LOG_PRE(catv, priority) do { \ if (_GRAS_LOG_ISENABLEDV(catv, priority)) { \ - gras_log_event_t _log_ev = \ + s_gras_log_event_t _log_ev = \ {&(catv),priority,__FILE__,_GRAS_GNUC_FUNCTION,__LINE__}; \ _gras_log_event_log(&_log_ev diff --git a/include/xbt/set.h b/include/xbt/set.h index 5ab5d1c124..dc4a66a1e7 100644 --- a/include/xbt/set.h +++ b/include/xbt/set.h @@ -12,61 +12,59 @@ #ifndef _GRAS_SET_H #define _GRAS_SET_H -#ifdef __cplusplus -extern "C" -#endif +#include "xbt/misc.h" /* BEGIN_DECL */ + +BEGIN_DECL /*####[ Type definition ]####################################################*/ -typedef struct gras_set_ gras_set_t; +typedef struct gras_set_ *gras_set_t; typedef struct gras_set_elm_ { unsigned int ID; char *name; unsigned int name_len; -} gras_set_elm_t; +} s_gras_set_elm_t,*gras_set_elm_t; /*####[ Functions ]##########################################################*/ -gras_set_t *gras_set_new (void); -void gras_set_free(gras_set_t **set); +gras_set_t gras_set_new (void); +void gras_set_free(gras_set_t *set); -void gras_set_add (gras_set_t *set, - gras_set_elm_t *elm, +void gras_set_add (gras_set_t set, + gras_set_elm_t elm, void_f_pvoid_t *free_func); /*----[ gras_set_retrieve ]-------------------------------------------------*/ /* Search the given #key#. data=NULL when not found. */ /*---------------------------------------------------------------------------*/ -gras_error_t gras_set_get_by_name (gras_set_t *set, +gras_error_t gras_set_get_by_name (gras_set_t set, const char *key, - /* OUT */gras_set_elm_t **dst); -gras_error_t gras_set_get_by_name_ext(gras_set_t *set, + /* OUT */gras_set_elm_t *dst); +gras_error_t gras_set_get_by_name_ext(gras_set_t set, const char *name, int name_len, - /* OUT */gras_set_elm_t **dst); -gras_error_t gras_set_get_by_id (gras_set_t *set, + /* OUT */gras_set_elm_t *dst); +gras_error_t gras_set_get_by_id (gras_set_t set, int id, - /* OUT */gras_set_elm_t **dst); + /* OUT */gras_set_elm_t *dst); /*####[ Cache cursor functions ]#############################################*/ /* To traverse (simple) caches */ /* Don't add or remove entries to the cache while traversing !!! */ /*###########################################################################*/ -typedef struct gras_set_cursor_ gras_set_cursor_t; -/* creator/destructor */ -void gras_set_cursor_first (gras_set_t *set, - gras_set_cursor_t **cursor); -void gras_set_cursor_step (gras_set_cursor_t *cursor); -int gras_set_cursor_get_or_free (gras_set_cursor_t **cursor, - gras_set_elm_t **elm); +typedef struct gras_set_cursor_ *gras_set_cursor_t; + +void gras_set_cursor_first (gras_set_t set, + gras_set_cursor_t *cursor); +void gras_set_cursor_step (gras_set_cursor_t cursor); +int gras_set_cursor_get_or_free (gras_set_cursor_t *cursor, + gras_set_elm_t *elm); #define gras_set_foreach(set,cursor,elm) \ for ((cursor) = NULL, gras_set_cursor_first((set),&(cursor)) ; \ - gras_set_cursor_get_or_free(&(cursor),(gras_set_elm_t**)&(elm)); \ + gras_set_cursor_get_or_free(&(cursor),(gras_set_elm_t*)&(elm)); \ gras_set_cursor_step(cursor) ) -#ifdef __cplusplus -} -#endif +END_DECL #endif /* _GRAS_SET_H */ diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index 852c4665f7..59df441b65 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -18,17 +18,29 @@ #include /* FIXME: remove */ #include /* FIXME: remove */ - -#ifdef __cplusplus -extern "C" +#include + +#include "xbt/misc.h" +BEGIN_DECL +#if 0 +#define __CALLOC_OP(n, s) calloc((n), (s)) + #define __REALLOC_OP(n, s) realloc((n), (s)) +#define CALLOC(n, s) ((__CALLOC_OP ((n)?:(FAILURE("attempt to alloc 0 bytes"), 0), (s)?:(FAILURE("attempt to alloc 0 bytes"), 0)))?:(FAILURE("memory allocation error"), NULL)) + /* #define REALLOC(p, s) ((__REALLOC_OP ((p), (s)?:(FAILURE("attempt to alloc 0 bytes"), 0)))?:(FAILURE("memory reallocation error"), NULL)) */ + #define REALLOC(p, s) (__REALLOC_OP ((p), (s))) #endif - -char* gras_strdup (const char *str); -void* gras_malloc (long int bytes); -void* gras_malloc0 (long int bytes); -void* gras_realloc (void *memory, long int bytes); -void gras_free (void *memory); - + +#define gras_strdup(s) ((s)?(strdup(s)?:(gras_die("memory allocation error"),NULL))\ + :(NULL)) +#define gras_malloc(n) (malloc(n) ?: (gras_die("memory allocation error"),NULL)) +#define gras_malloc0(n) (calloc( (n),1 ) ?: (gras_die("memory allocation error"),NULL)) +#define gras_realloc(p,s) (s? (p? (realloc(p,s)?:gras_die("memory allocation error"),NULL) \ + : gras_malloc(s)) \ + : (p? (free(p),NULL) \ + : NULL)) +#define gras_free free /*nothing specific to do here. A poor valgrind replacement?*/ +#define gras_free_fct free /* replacement with the guareenty of being a function */ + #define gras_new(type, count) ((type*)gras_malloc (sizeof (type) * (count))) #define gras_new0(type, count) ((type*)gras_malloc0 (sizeof (type) * (count))) @@ -71,10 +83,6 @@ long int strtol(const char *nptr, char **endptr, int base); double strtod(const char *nptr, char **endptr); int atoi(const char *nptr); - - -#ifdef __cplusplus -} -#endif +END_DECL #endif /* _GRAS_SYSDEP_H */ -- 2.20.1