From 8a98063fe12e80a332a2f48d4b060815b7ae1efc Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 18 May 2009 08:32:29 +0000 Subject: [PATCH] Reindent some code, no real change (should do it for all my code once for good) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6283 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/gras/DataDesc/cbps.c | 452 +++--- src/gras/DataDesc/datadesc.c | 366 ++--- src/gras/DataDesc/datadesc_interface.h | 8 +- src/gras/DataDesc/datadesc_private.h | 178 +-- src/gras/DataDesc/ddt_convert.c | 328 ++--- src/gras/DataDesc/ddt_create.c | 1520 ++++++++++---------- src/gras/DataDesc/ddt_exchange.c | 1756 ++++++++++++------------ src/gras/DataDesc/ddt_parse.c | 1278 ++++++++--------- src/gras/Msg/gras_msg_listener.c | 182 +-- src/gras/Msg/gras_msg_mod.c | 90 +- src/gras/Msg/gras_msg_types.c | 394 +++--- src/gras/Msg/msg_interface.h | 30 +- src/gras/Msg/msg_private.h | 72 +- src/gras/Msg/rl_msg.c | 318 ++--- src/gras/Msg/rpc.c | 290 ++-- src/gras/Msg/sg_msg.c | 210 +-- src/gras/Msg/timer.c | 262 ++-- 17 files changed, 3867 insertions(+), 3867 deletions(-) diff --git a/src/gras/DataDesc/cbps.c b/src/gras/DataDesc/cbps.c index df1b055db7..7d56033604 100644 --- a/src/gras/DataDesc/cbps.c +++ b/src/gras/DataDesc/cbps.c @@ -14,100 +14,100 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_cbps,gras_ddt,"callback persistant state"); typedef struct { - gras_datadesc_type_t type; - void *data; + gras_datadesc_type_t type; + void *data; } s_gras_cbps_elm_t, *gras_cbps_elm_t; typedef struct s_gras_cbps { - xbt_dynar_t lints; /* simple stack of long integers (easy interface) */ + xbt_dynar_t lints; /* simple stack of long integers (easy interface) */ - xbt_dict_t space; /* varname x dynar of gras_cbps_elm_t */ - xbt_dynar_t frames; /* of dynar of names defined within this frame + xbt_dict_t space; /* varname x dynar of gras_cbps_elm_t */ + xbt_dynar_t frames; /* of dynar of names defined within this frame (and to pop when we leave it) */ - xbt_dynar_t globals; + xbt_dynar_t globals; } s_gras_cbps_t; gras_cbps_t gras_cbps_new(void) { - gras_cbps_t res; + gras_cbps_t res; - res=xbt_new(s_gras_cbps_t,1); + res=xbt_new(s_gras_cbps_t,1); - res->lints = xbt_dynar_new(sizeof(int), NULL); - res->space = xbt_dict_new(); - /* no leak, the content is freed manually on block_end */ - res->frames = xbt_dynar_new(sizeof(xbt_dynar_t), NULL); - res->globals = xbt_dynar_new(sizeof(char*), NULL); + res->lints = xbt_dynar_new(sizeof(int), NULL); + res->space = xbt_dict_new(); + /* no leak, the content is freed manually on block_end */ + res->frames = xbt_dynar_new(sizeof(xbt_dynar_t), NULL); + res->globals = xbt_dynar_new(sizeof(char*), NULL); - gras_cbps_block_begin(res); + gras_cbps_block_begin(res); - return res; + return res; } void gras_cbps_free(gras_cbps_t *state) { - xbt_dynar_free( &( (*state)->lints ) ); + xbt_dynar_free( &( (*state)->lints ) ); - gras_cbps_block_end(*state); - xbt_dict_free ( &( (*state)->space ) ); - xbt_dynar_free( &( (*state)->frames ) ); - xbt_dynar_free( &( (*state)->globals ) ); + gras_cbps_block_end(*state); + xbt_dict_free ( &( (*state)->space ) ); + xbt_dynar_free( &( (*state)->frames ) ); + xbt_dynar_free( &( (*state)->globals ) ); - free(*state); - *state = NULL; + free(*state); + *state = NULL; } void gras_cbps_reset(gras_cbps_t state) { - xbt_dynar_reset(state->lints); + xbt_dynar_reset(state->lints); - xbt_dict_reset (state->space); + xbt_dict_reset (state->space); - xbt_dynar_reset(state->frames); - xbt_dynar_reset(state->globals); + xbt_dynar_reset(state->frames); + xbt_dynar_reset(state->globals); } /** \brief Declare a new element in the PS, and give it a value. * * If an element of that - * name already exists, it is masked by the one given here, and will be + * name already exists, it is masked by the one given here, and will be * seeable again only after a pop to remove the value this push adds. */ void gras_cbps_v_push(gras_cbps_t ps, - const char *name, - void *data, - gras_datadesc_type_t ddt) { - - xbt_dynar_t varstack=NULL,frame; - gras_cbps_elm_t var; - char *varname = (char*)xbt_strdup(name); - xbt_ex_t e; - - DEBUG2("push(%s,%p)",name,(void*)data); - - TRY { - varstack = xbt_dict_get(ps->space, name); - } CATCH(e) { - if (e.category != mismatch_error) - RETHROW; - - DEBUG1("Create a new variable stack for '%s' into the space",name); - varstack = xbt_dynar_new(sizeof (gras_cbps_elm_t *), NULL); - xbt_dict_set(ps->space, varname, (void **)varstack, NULL); - xbt_ex_free(e); - /* leaking, you think? only if you do not close all the openned blocks ;)*/ - } - - var = xbt_new0(s_gras_cbps_elm_t,1); - var->type = ddt; - var->data = data; - - xbt_dynar_push(varstack, &var); - - xbt_dynar_pop(ps->frames, &frame); - DEBUG4("Push %s (%p @%p) into frame %p",varname,(void*)varname,(void*)&varname,(void*)frame); - xbt_dynar_push(frame, &varname); - xbt_dynar_push(ps->frames, &frame); + const char *name, + void *data, + gras_datadesc_type_t ddt) { + + xbt_dynar_t varstack=NULL,frame; + gras_cbps_elm_t var; + char *varname = (char*)xbt_strdup(name); + xbt_ex_t e; + + DEBUG2("push(%s,%p)",name,(void*)data); + + TRY { + varstack = xbt_dict_get(ps->space, name); + } CATCH(e) { + if (e.category != mismatch_error) + RETHROW; + + DEBUG1("Create a new variable stack for '%s' into the space",name); + varstack = xbt_dynar_new(sizeof (gras_cbps_elm_t *), NULL); + xbt_dict_set(ps->space, varname, (void **)varstack, NULL); + xbt_ex_free(e); + /* leaking, you think? only if you do not close all the openned blocks ;)*/ + } + + var = xbt_new0(s_gras_cbps_elm_t,1); + var->type = ddt; + var->data = data; + + xbt_dynar_push(varstack, &var); + + xbt_dynar_pop(ps->frames, &frame); + DEBUG4("Push %s (%p @%p) into frame %p",varname,(void*)varname,(void*)&varname,(void*)frame); + xbt_dynar_push(frame, &varname); + xbt_dynar_push(ps->frames, &frame); } /** \brief Retrieve an element from the PS, and remove it from the PS. @@ -116,61 +116,61 @@ gras_cbps_v_push(gras_cbps_t ps, * and not search in upper blocks since this denotes a programmation error. */ void -gras_cbps_v_pop (gras_cbps_t ps, - const char *name, - gras_datadesc_type_t *ddt, - void **res) { - xbt_dynar_t varstack,frame; - gras_cbps_elm_t var = NULL; - void *data = NULL; - xbt_ex_t e; - - DEBUG1("pop(%s)",name); - TRY { - varstack = xbt_dict_get(ps->space, name); - } CATCH(e) { - if (e.category != mismatch_error) - RETHROW; - - xbt_ex_free(e); - THROW1(not_found_error,1,"Asked to pop the non-existant %s", name); - } - xbt_dynar_pop(varstack, &var); - - if (!xbt_dynar_length(varstack)) { - DEBUG1("Last incarnation of %s poped. Kill it",name); - xbt_dict_remove(ps->space, name); - xbt_dynar_free(&varstack); - } - - if (ddt) - *ddt = var->type; - data = var->data; - - free(var); - - xbt_dynar_pop(ps->frames, &frame); - { - int l = xbt_dynar_length(frame); - - while (l--) { - char *_name = NULL; - - _name = xbt_dynar_get_as(frame, l, char*); - if (!strcmp(name, _name)) { - xbt_dynar_remove_at(frame, l, &_name); - free(_name); - break; - } - } - } - xbt_dynar_push(ps->frames, &frame); - - *res = data; +gras_cbps_v_pop (gras_cbps_t ps, + const char *name, + gras_datadesc_type_t *ddt, + void **res) { + xbt_dynar_t varstack,frame; + gras_cbps_elm_t var = NULL; + void *data = NULL; + xbt_ex_t e; + + DEBUG1("pop(%s)",name); + TRY { + varstack = xbt_dict_get(ps->space, name); + } CATCH(e) { + if (e.category != mismatch_error) + RETHROW; + + xbt_ex_free(e); + THROW1(not_found_error,1,"Asked to pop the non-existant %s", name); + } + xbt_dynar_pop(varstack, &var); + + if (!xbt_dynar_length(varstack)) { + DEBUG1("Last incarnation of %s poped. Kill it",name); + xbt_dict_remove(ps->space, name); + xbt_dynar_free(&varstack); + } + + if (ddt) + *ddt = var->type; + data = var->data; + + free(var); + + xbt_dynar_pop(ps->frames, &frame); + { + int l = xbt_dynar_length(frame); + + while (l--) { + char *_name = NULL; + + _name = xbt_dynar_get_as(frame, l, char*); + if (!strcmp(name, _name)) { + xbt_dynar_remove_at(frame, l, &_name); + free(_name); + break; + } + } + } + xbt_dynar_push(ps->frames, &frame); + + *res = data; } /** \brief Change the value of an element in the PS. - * + * * If it's not present in the current block, look in the upper ones. * If it's not present in any of them, modify in the globals * If not present there neither, the code may segfault (Oli?). @@ -180,68 +180,68 @@ gras_cbps_v_pop (gras_cbps_t ps, */ void gras_cbps_v_set (gras_cbps_t ps, - const char *name, - void *data, - gras_datadesc_type_t ddt) { - - xbt_dynar_t dynar = NULL; - gras_cbps_elm_t elm = NULL; - - DEBUG1("set(%s)",name); - dynar = xbt_dict_get_or_null(ps->space, name); - - if (dynar == NULL) { - dynar = xbt_dynar_new(sizeof (gras_cbps_elm_t), NULL); - xbt_dict_set(ps->space, name, (void **)dynar, NULL); - - elm = xbt_new0(s_gras_cbps_elm_t,1); - xbt_dynar_push(ps->globals, &name); - } else { - xbt_dynar_pop(dynar, &elm); - } - - elm->type = ddt; - elm->data = data; - - xbt_dynar_push(dynar, &elm); + const char *name, + void *data, + gras_datadesc_type_t ddt) { + + xbt_dynar_t dynar = NULL; + gras_cbps_elm_t elm = NULL; + + DEBUG1("set(%s)",name); + dynar = xbt_dict_get_or_null(ps->space, name); + + if (dynar == NULL) { + dynar = xbt_dynar_new(sizeof (gras_cbps_elm_t), NULL); + xbt_dict_set(ps->space, name, (void **)dynar, NULL); + + elm = xbt_new0(s_gras_cbps_elm_t,1); + xbt_dynar_push(ps->globals, &name); + } else { + xbt_dynar_pop(dynar, &elm); + } + + elm->type = ddt; + elm->data = data; + + xbt_dynar_push(dynar, &elm); } /** \brief Get the value of an element in the PS without modifying it. - * + * * (note that you get the content of the data struct and not a copy to it) * If it's not present in the current block, look in the upper ones. * If it's not present in any of them, look in the globals * If not present there neither, the code may segfault (Oli?). */ void * -gras_cbps_v_get (gras_cbps_t ps, - const char *name, - /* OUT */gras_datadesc_type_t *ddt) { - - xbt_dynar_t dynar = NULL; - gras_cbps_elm_t elm = NULL; - - DEBUG1("get(%s)",name); - dynar = xbt_dict_get(ps->space, name); - xbt_dynar_pop(dynar, &elm); - xbt_dynar_push(dynar, &elm); - - if (ddt) { - *ddt = elm->type; - } - - return elm->data; +gras_cbps_v_get (gras_cbps_t ps, + const char *name, + /* OUT */gras_datadesc_type_t *ddt) { + + xbt_dynar_t dynar = NULL; + gras_cbps_elm_t elm = NULL; + + DEBUG1("get(%s)",name); + dynar = xbt_dict_get(ps->space, name); + xbt_dynar_pop(dynar, &elm); + xbt_dynar_push(dynar, &elm); + + if (ddt) { + *ddt = elm->type; + } + + return elm->data; } -/** \brief Begins a new block. +/** \brief Begins a new block. * * Blocks are usefull to remove a whole set of declarations you don't even know * - * E.g., they constitute an elegent solution to recursive data structures. + * E.g., they constitute an elegent solution to recursive data structures. * - * push/pop may be used in some cases for that, but if your recursive data + * push/pop may be used in some cases for that, but if your recursive data * struct contains other structs needing themselves callbacks, you have to * use block_{begin,end} to do the trick. */ @@ -249,75 +249,75 @@ gras_cbps_v_get (gras_cbps_t ps, void gras_cbps_block_begin(gras_cbps_t ps) { - xbt_dynar_t dynar = NULL; + xbt_dynar_t dynar = NULL; - DEBUG0(">>> Block begin"); - dynar = xbt_dynar_new(sizeof (char *), NULL); - xbt_dynar_push(ps->frames, &dynar); + DEBUG0(">>> Block begin"); + dynar = xbt_dynar_new(sizeof (char *), NULL); + xbt_dynar_push(ps->frames, &dynar); } /** \brief End the current block, and go back to the upper one. */ void gras_cbps_block_end(gras_cbps_t ps) { - xbt_dynar_t frame = NULL; - unsigned int cursor = 0; - char *name = NULL; - - xbt_assert0(xbt_dynar_length(ps->frames), - "More block_end than block_begin"); - xbt_dynar_pop(ps->frames, &frame); - - xbt_dynar_foreach(frame, cursor, name) { - - xbt_dynar_t varstack = NULL; - gras_cbps_elm_t var = NULL; - - DEBUG2("Get ride of %s (%p)",name,(void*)name); - varstack = xbt_dict_get(ps->space, name); - xbt_dynar_pop(varstack, &var); - - if (!xbt_dynar_length(varstack)) { - xbt_dict_remove(ps->space, name); - xbt_dynar_free_container(&varstack); /*already empty, save a test ;) */ - } - - if (var->data) free(var->data); - free(var); - free(name); - } - xbt_dynar_free_container(&frame);/* we just emptied it */ - DEBUG0("<<< Block end"); + xbt_dynar_t frame = NULL; + unsigned int cursor = 0; + char *name = NULL; + + xbt_assert0(xbt_dynar_length(ps->frames), + "More block_end than block_begin"); + xbt_dynar_pop(ps->frames, &frame); + + xbt_dynar_foreach(frame, cursor, name) { + + xbt_dynar_t varstack = NULL; + gras_cbps_elm_t var = NULL; + + DEBUG2("Get ride of %s (%p)",name,(void*)name); + varstack = xbt_dict_get(ps->space, name); + xbt_dynar_pop(varstack, &var); + + if (!xbt_dynar_length(varstack)) { + xbt_dict_remove(ps->space, name); + xbt_dynar_free_container(&varstack); /*already empty, save a test ;) */ + } + + if (var->data) free(var->data); + free(var); + free(name); + } + xbt_dynar_free_container(&frame);/* we just emptied it */ + DEBUG0("<<< Block end"); } /** \brief Push a new integer value into the cbps. */ void gras_cbps_i_push(gras_cbps_t ps, - int val) { - DEBUG1("push %d as a size",val); - xbt_dynar_push_as(ps->lints,int,val); + int val) { + DEBUG1("push %d as a size",val); + xbt_dynar_push_as(ps->lints,int,val); } /** \brief Pop the lastly pushed integer value from the cbps. */ int gras_cbps_i_pop(gras_cbps_t ps) { - int ret; + int ret; - xbt_assert0(xbt_dynar_length(ps->lints) > 0, - "gras_cbps_i_pop: no value to pop"); - ret = xbt_dynar_pop_as(ps->lints,int); - DEBUG1("pop %d as a size",ret); - return ret; + xbt_assert0(xbt_dynar_length(ps->lints) > 0, + "gras_cbps_i_pop: no value to pop"); + ret = xbt_dynar_pop_as(ps->lints,int); + DEBUG1("pop %d as a size",ret); + return ret; } /** \brief Generic cb returning the lastly pushed value - * + * * Used by \ref gras_datadesc_ref_pop_arr */ int gras_datadesc_cb_pop(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - int res = gras_cbps_i_pop(vars); - DEBUG1("Pop %d as a size",res); - return res; + int res = gras_cbps_i_pop(vars); + DEBUG1("Pop %d as a size",res); + return res; } /* ************************* */ @@ -326,27 +326,27 @@ int gras_datadesc_cb_pop(gras_datadesc_type_t ignored, gras_cbps_t vars, void *d /** \brief Cb to push an integer. Must be attached to the field you want to push */ void gras_datadesc_cb_push_int(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - int *i = (int*)data; - gras_cbps_i_push(vars, (int) *i); + int *i = (int*)data; + gras_cbps_i_push(vars, (int) *i); } /** \brief Cb to push an unsigned integer. Must be attached to the field you want to push */ void gras_datadesc_cb_push_uint(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - unsigned int *i = (unsigned int*)data; - gras_cbps_i_push(vars, (int) *i); + unsigned int *i = (unsigned int*)data; + gras_cbps_i_push(vars, (int) *i); } /** \brief Cb to push an long integer. Must be attached to the field you want to push */ void gras_datadesc_cb_push_lint(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - long int *i = (long int*)data; - gras_cbps_i_push(vars, (int) *i); + long int *i = (long int*)data; + gras_cbps_i_push(vars, (int) *i); } /** \brief Cb to push an unsigned long integer. Must be attached to the field you want to push */ void gras_datadesc_cb_push_ulint(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - unsigned long int *i = (unsigned long int*)data; - gras_cbps_i_push(vars, (int) *i); + unsigned long int *i = (unsigned long int*)data; + gras_cbps_i_push(vars, (int) *i); } /* ************************************ */ @@ -354,34 +354,34 @@ void gras_datadesc_cb_push_ulint(gras_datadesc_type_t ignored, gras_cbps_t vars, /* ************************************ */ /** \brief Cb to push an integer as multiplier. Must be attached to the field you want to push */ void gras_datadesc_cb_push_int_mult(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - int old = *(int*)data; - int new = gras_cbps_i_pop(vars); - DEBUG2("push %d x %d as a size",old,new); - gras_cbps_i_push(vars, old*new); + int old = *(int*)data; + int new = gras_cbps_i_pop(vars); + DEBUG2("push %d x %d as a size",old,new); + gras_cbps_i_push(vars, old*new); } /** \brief Cb to push an unsigned integer as multiplier. Must be attached to the field you want to push */ void gras_datadesc_cb_push_uint_mult(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - unsigned int old = *(unsigned int*)data; - unsigned int new = gras_cbps_i_pop(vars); + unsigned int old = *(unsigned int*)data; + unsigned int new = gras_cbps_i_pop(vars); - DEBUG2("push %d x %d as a size",old,new); - gras_cbps_i_push(vars, (int) (old*new)); + DEBUG2("push %d x %d as a size",old,new); + gras_cbps_i_push(vars, (int) (old*new)); } /** \brief Cb to push an long integer as multiplier. Must be attached to the field you want to push */ void gras_datadesc_cb_push_lint_mult(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - long int i = *(long int*)data; - i *= gras_cbps_i_pop(vars); - gras_cbps_i_push(vars, (int) i); + long int i = *(long int*)data; + i *= gras_cbps_i_pop(vars); + gras_cbps_i_push(vars, (int) i); } /** \brief Cb to push an unsigned long integer as multiplier. Must be attached to the field you want to push */ void gras_datadesc_cb_push_ulint_mult(gras_datadesc_type_t ignored, gras_cbps_t vars, void *data) { - unsigned long int old = *(unsigned long int*)data; - unsigned long int new = gras_cbps_i_pop(vars); + unsigned long int old = *(unsigned long int*)data; + unsigned long int new = gras_cbps_i_pop(vars); - DEBUG2("push %ld x %ld as a size",old,new); - gras_cbps_i_push(vars, (int) (old * new) ); + DEBUG2("push %ld x %ld as a size",old,new); + gras_cbps_i_push(vars, (int) (old * new) ); } diff --git a/src/gras/DataDesc/datadesc.c b/src/gras/DataDesc/datadesc.c index adf8f76af1..09ba9fc849 100644 --- a/src/gras/DataDesc/datadesc.c +++ b/src/gras/DataDesc/datadesc.c @@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt,gras,"Data description"); static int _strlen_cb(/*@unused@*/gras_datadesc_type_t type,/*@unused@*/gras_cbps_t vars, void *data) { - return 1+(int)strlen(data); + return 1+(int)strlen(data); } @@ -28,132 +28,132 @@ _strlen_cb(/*@unused@*/gras_datadesc_type_t type,/*@unused@*/gras_cbps_t vars, v * gras_datadesc_init: * * Initialize the datadesc module. - * FIXME: We assume that when neither signed nor unsigned is given, + * FIXME: We assume that when neither signed nor unsigned is given, * that means signed. To be checked by configure. **/ void gras_datadesc_init(void) { - gras_datadesc_type_t ddt; /* What to add */ - - /* only initialize once */ - if (gras_datadesc_set_local != NULL) - return; - - VERB0("Initializing DataDesc"); - - gras_datadesc_set_local = xbt_set_new(); - - - /* all known datatypes */ - - ddt = gras_datadesc_scalar("signed char", - gras_ddt_scalar_char, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("char", - gras_ddt_scalar_char, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("unsigned char", - gras_ddt_scalar_char, - e_gras_dd_scalar_encoding_uint); - - ddt = gras_datadesc_scalar("signed short int", - gras_ddt_scalar_short, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("short int", - gras_ddt_scalar_short, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("short", - gras_ddt_scalar_short, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("unsigned short int", - gras_ddt_scalar_short, - e_gras_dd_scalar_encoding_uint); - - ddt = gras_datadesc_scalar("signed int", - gras_ddt_scalar_int, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("int", - gras_ddt_scalar_int, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("unsigned int", - gras_ddt_scalar_int, - e_gras_dd_scalar_encoding_uint); - - ddt = gras_datadesc_scalar("signed long int", - gras_ddt_scalar_long, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("long int", - gras_ddt_scalar_long, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("long", - gras_ddt_scalar_long, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("unsigned long int", - gras_ddt_scalar_long, - e_gras_dd_scalar_encoding_uint); - - ddt = gras_datadesc_scalar("signed long long int", - gras_ddt_scalar_long_long, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("long long int", - gras_ddt_scalar_long_long, - e_gras_dd_scalar_encoding_sint); - ddt = gras_datadesc_scalar("unsigned long long int", - gras_ddt_scalar_long_long, - e_gras_dd_scalar_encoding_uint); - - ddt = gras_datadesc_scalar("data pointer", - gras_ddt_scalar_pdata, - e_gras_dd_scalar_encoding_uint); - ddt = gras_datadesc_scalar("function pointer", - gras_ddt_scalar_pfunc, - e_gras_dd_scalar_encoding_uint); - - ddt = gras_datadesc_scalar("float", - gras_ddt_scalar_float, - e_gras_dd_scalar_encoding_float); - ddt = gras_datadesc_scalar("double", - gras_ddt_scalar_double, - e_gras_dd_scalar_encoding_float); - - ddt = gras_datadesc_array_dyn("char[]", - gras_datadesc_by_name("char"), - _strlen_cb); - gras_datadesc_ref("string",ddt); - gras_datadesc_ref("xbt_string_t",ddt); - - /* specific datatype: the exception type (for RPC) */ - ddt = gras_datadesc_struct("ex_t"); - gras_datadesc_struct_append(ddt,"msg",gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt,"category",gras_datadesc_by_name("int")); - gras_datadesc_struct_append(ddt,"value",gras_datadesc_by_name("int")); - - gras_datadesc_struct_append(ddt,"remote",gras_datadesc_by_name("short int")); - - gras_datadesc_struct_append(ddt,"host",gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt,"procname",gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt,"pid",gras_datadesc_by_name("long int")); - gras_datadesc_struct_append(ddt,"file",gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt,"line",gras_datadesc_by_name("int")); - gras_datadesc_struct_append(ddt,"func",gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt,"used",gras_datadesc_by_name("int")); - gras_datadesc_cb_field_push(ddt,"used"); - gras_datadesc_struct_append(ddt,"bt_strings", - gras_datadesc_ref_pop_arr(gras_datadesc_by_name("string"))); - - gras_datadesc_struct_close(ddt); - - /* specific datatype: xbt_peer_t */ - ddt = gras_datadesc_struct("s_xbt_peer_t"); - gras_datadesc_struct_append(ddt,"name",gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt,"port",gras_datadesc_by_name("int")); - gras_datadesc_struct_close(ddt); - - ddt = gras_datadesc_ref("xbt_peer_t",ddt); - - /* Dict containing the constant value (for the parsing macro) */ - gras_dd_constants = xbt_dict_new(); - + gras_datadesc_type_t ddt; /* What to add */ + + /* only initialize once */ + if (gras_datadesc_set_local != NULL) + return; + + VERB0("Initializing DataDesc"); + + gras_datadesc_set_local = xbt_set_new(); + + + /* all known datatypes */ + + ddt = gras_datadesc_scalar("signed char", + gras_ddt_scalar_char, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("char", + gras_ddt_scalar_char, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("unsigned char", + gras_ddt_scalar_char, + e_gras_dd_scalar_encoding_uint); + + ddt = gras_datadesc_scalar("signed short int", + gras_ddt_scalar_short, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("short int", + gras_ddt_scalar_short, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("short", + gras_ddt_scalar_short, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("unsigned short int", + gras_ddt_scalar_short, + e_gras_dd_scalar_encoding_uint); + + ddt = gras_datadesc_scalar("signed int", + gras_ddt_scalar_int, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("int", + gras_ddt_scalar_int, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("unsigned int", + gras_ddt_scalar_int, + e_gras_dd_scalar_encoding_uint); + + ddt = gras_datadesc_scalar("signed long int", + gras_ddt_scalar_long, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("long int", + gras_ddt_scalar_long, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("long", + gras_ddt_scalar_long, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("unsigned long int", + gras_ddt_scalar_long, + e_gras_dd_scalar_encoding_uint); + + ddt = gras_datadesc_scalar("signed long long int", + gras_ddt_scalar_long_long, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("long long int", + gras_ddt_scalar_long_long, + e_gras_dd_scalar_encoding_sint); + ddt = gras_datadesc_scalar("unsigned long long int", + gras_ddt_scalar_long_long, + e_gras_dd_scalar_encoding_uint); + + ddt = gras_datadesc_scalar("data pointer", + gras_ddt_scalar_pdata, + e_gras_dd_scalar_encoding_uint); + ddt = gras_datadesc_scalar("function pointer", + gras_ddt_scalar_pfunc, + e_gras_dd_scalar_encoding_uint); + + ddt = gras_datadesc_scalar("float", + gras_ddt_scalar_float, + e_gras_dd_scalar_encoding_float); + ddt = gras_datadesc_scalar("double", + gras_ddt_scalar_double, + e_gras_dd_scalar_encoding_float); + + ddt = gras_datadesc_array_dyn("char[]", + gras_datadesc_by_name("char"), + _strlen_cb); + gras_datadesc_ref("string",ddt); + gras_datadesc_ref("xbt_string_t",ddt); + + /* specific datatype: the exception type (for RPC) */ + ddt = gras_datadesc_struct("ex_t"); + gras_datadesc_struct_append(ddt,"msg",gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt,"category",gras_datadesc_by_name("int")); + gras_datadesc_struct_append(ddt,"value",gras_datadesc_by_name("int")); + + gras_datadesc_struct_append(ddt,"remote",gras_datadesc_by_name("short int")); + + gras_datadesc_struct_append(ddt,"host",gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt,"procname",gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt,"pid",gras_datadesc_by_name("long int")); + gras_datadesc_struct_append(ddt,"file",gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt,"line",gras_datadesc_by_name("int")); + gras_datadesc_struct_append(ddt,"func",gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt,"used",gras_datadesc_by_name("int")); + gras_datadesc_cb_field_push(ddt,"used"); + gras_datadesc_struct_append(ddt,"bt_strings", + gras_datadesc_ref_pop_arr(gras_datadesc_by_name("string"))); + + gras_datadesc_struct_close(ddt); + + /* specific datatype: xbt_peer_t */ + ddt = gras_datadesc_struct("s_xbt_peer_t"); + gras_datadesc_struct_append(ddt,"name",gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt,"port",gras_datadesc_by_name("int")); + gras_datadesc_struct_close(ddt); + + ddt = gras_datadesc_ref("xbt_peer_t",ddt); + + /* Dict containing the constant value (for the parsing macro) */ + gras_dd_constants = xbt_dict_new(); + } /** @@ -163,31 +163,31 @@ gras_datadesc_init(void) { **/ void gras_datadesc_exit(void) { - VERB0("Exiting DataDesc"); - xbt_set_free(&gras_datadesc_set_local); - xbt_dict_free(&gras_dd_constants); - DEBUG0("Exited DataDesc"); + VERB0("Exiting DataDesc"); + xbt_set_free(&gras_datadesc_set_local); + xbt_dict_free(&gras_dd_constants); + DEBUG0("Exited DataDesc"); } /** This is mainly to debug */ const char * gras_datadesc_get_name(gras_datadesc_type_t ddt) { - return ddt?(const char*)ddt->name:"(null)"; + return ddt?(const char*)ddt->name:"(null)"; } /** This is mainly to debug */ int gras_datadesc_get_id(gras_datadesc_type_t ddt) { - return ddt->code; + return ddt->code; } /** - * gras_datadesc_size: + * gras_datadesc_size: * * Returns the size occuped by data of this type (on the current arch). * */ int gras_datadesc_size(gras_datadesc_type_t type) { - return type?type->size[GRAS_THISARCH]:0; + return type?type->size[GRAS_THISARCH]:0; } /** @@ -196,56 +196,56 @@ int gras_datadesc_size(gras_datadesc_type_t type) { * For debugging purpose */ void gras_datadesc_type_dump(const gras_datadesc_type_t ddt){ - unsigned int cpt; - - printf("DataDesc dump:"); - if(!ddt) { - printf("(null)\n"); - return; - } - printf ("%s (ID:%d)\n",ddt->name,ddt->code); - printf (" category: %s\n",gras_datadesc_cat_names[ddt->category_code]); - - printf (" size["); - for (cpt=0; cpt0?", ":"", - cpt == GRAS_THISARCH ? ">":"", - ddt->size[cpt], - cpt == GRAS_THISARCH ? "<":""); - } - printf ("]\n"); - - printf (" alignment["); - for (cpt=0; cpt0?", ":"", - cpt == GRAS_THISARCH ? ">":"", - ddt->alignment[cpt], - cpt == GRAS_THISARCH ? "<":""); - } - printf ("]\n"); - - printf (" aligned_size["); - for (cpt=0; cpt0?", ":"", - cpt == GRAS_THISARCH ? ">":"", - ddt->aligned_size[cpt], - cpt == GRAS_THISARCH ? "<":""); - } - printf ("]\n"); - if (ddt->category_code == e_gras_datadesc_type_cat_struct) { - gras_dd_cat_struct_t struct_data; - gras_dd_cat_field_t field; - - struct_data = ddt->category.struct_data; - xbt_dynar_foreach(struct_data.fields, cpt, field) { - printf(">>> Dump field #%d (%s) (offset=%ld)\n", - cpt,field->name,field->offset[GRAS_THISARCH]); - gras_datadesc_type_dump(field->type); - printf("<<< end dump field #%d (%s)\n",cpt,field->name); - } - } - fflush(stdout); + unsigned int cpt; + + printf("DataDesc dump:"); + if(!ddt) { + printf("(null)\n"); + return; + } + printf ("%s (ID:%d)\n",ddt->name,ddt->code); + printf (" category: %s\n",gras_datadesc_cat_names[ddt->category_code]); + + printf (" size["); + for (cpt=0; cpt0?", ":"", + cpt == GRAS_THISARCH ? ">":"", + ddt->size[cpt], + cpt == GRAS_THISARCH ? "<":""); + } + printf ("]\n"); + + printf (" alignment["); + for (cpt=0; cpt0?", ":"", + cpt == GRAS_THISARCH ? ">":"", + ddt->alignment[cpt], + cpt == GRAS_THISARCH ? "<":""); + } + printf ("]\n"); + + printf (" aligned_size["); + for (cpt=0; cpt0?", ":"", + cpt == GRAS_THISARCH ? ">":"", + ddt->aligned_size[cpt], + cpt == GRAS_THISARCH ? "<":""); + } + printf ("]\n"); + if (ddt->category_code == e_gras_datadesc_type_cat_struct) { + gras_dd_cat_struct_t struct_data; + gras_dd_cat_field_t field; + + struct_data = ddt->category.struct_data; + xbt_dynar_foreach(struct_data.fields, cpt, field) { + printf(">>> Dump field #%d (%s) (offset=%ld)\n", + cpt,field->name,field->offset[GRAS_THISARCH]); + gras_datadesc_type_dump(field->type); + printf("<<< end dump field #%d (%s)\n",cpt,field->name); + } + } + fflush(stdout); } diff --git a/src/gras/DataDesc/datadesc_interface.h b/src/gras/DataDesc/datadesc_interface.h index 9b8231f63c..c311b30a4c 100644 --- a/src/gras/DataDesc/datadesc_interface.h +++ b/src/gras/DataDesc/datadesc_interface.h @@ -23,7 +23,7 @@ XBT_PUBLIC(const char *) gras_datadesc_arch_name(int code); /* compare two data type description */ XBT_PUBLIC(int) gras_datadesc_type_cmp(const gras_datadesc_type_t d1, - const gras_datadesc_type_t d2); + const gras_datadesc_type_t d2); /* Access function */ XBT_PUBLIC(int) gras_datadesc_size(gras_datadesc_type_t type); @@ -31,13 +31,13 @@ XBT_PUBLIC(int) gras_datadesc_size(gras_datadesc_type_t type); XBT_PUBLIC(int) gras_datadesc_memcpy(gras_datadesc_type_t type, void *src, void *dst); XBT_PUBLIC(void) gras_datadesc_send(gras_socket_t sock, gras_datadesc_type_t type, void *src); XBT_PUBLIC(void) gras_datadesc_recv(gras_socket_t sock, gras_datadesc_type_t type, - int r_arch, void *dst); + int r_arch, void *dst); /* Described data exchanges: IDL compilation FIXME: not implemented*/ void gras_datadesc_gen_cpy(gras_datadesc_type_t type, void *src, void **dst); void gras_datadesc_gen_send(gras_socket_t sock, gras_datadesc_type_t type, void *src); void gras_datadesc_gen_recv(gras_socket_t sock, gras_datadesc_type_t type, - int r_arch, void *dst); + int r_arch, void *dst); + - #endif /* GRAS_DATADESC_INTERFACE_H */ diff --git a/src/gras/DataDesc/datadesc_private.h b/src/gras/DataDesc/datadesc_private.h index 0e79380174..5560238652 100644 --- a/src/gras/DataDesc/datadesc_private.h +++ b/src/gras/DataDesc/datadesc_private.h @@ -31,7 +31,7 @@ /** * ddt_aligned: - * + * * Align the data v on the boundary a. */ #define ddt_aligned(v, a) (((v) + (a - 1)) & ~(a - 1)) @@ -44,26 +44,26 @@ void gras_ddt_freev(void *ddt); #define gras_arch_count 11 typedef enum { - gras_ddt_scalar_char = 0, - gras_ddt_scalar_short = 1, - gras_ddt_scalar_int = 2, - gras_ddt_scalar_long = 3, - gras_ddt_scalar_long_long = 4, + gras_ddt_scalar_char = 0, + gras_ddt_scalar_short = 1, + gras_ddt_scalar_int = 2, + gras_ddt_scalar_long = 3, + gras_ddt_scalar_long_long = 4, - gras_ddt_scalar_pdata = 5, - gras_ddt_scalar_pfunc = 6, + gras_ddt_scalar_pdata = 5, + gras_ddt_scalar_pfunc = 6, - gras_ddt_scalar_float = 7, - gras_ddt_scalar_double = 8 + gras_ddt_scalar_float = 7, + gras_ddt_scalar_double = 8 } gras_ddt_scalar_type_t; typedef struct { - const char *name; + const char *name; - int endian; + int endian; - int sizeofs[9]; /* char,short,int,long,long_long,pdata,pfunc,float,double */ - int boundaries[9]; /* idem */ + 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]; @@ -76,21 +76,21 @@ extern const char *gras_datadesc_cat_names[9]; /** * e_gras_datadesc_type_category: * - * Defines all possible type categories. + * Defines all possible type categories. */ typedef enum e_gras_datadesc_type_category { - - /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */ - - e_gras_datadesc_type_cat_undefined = 0, - - e_gras_datadesc_type_cat_scalar = 1, - e_gras_datadesc_type_cat_struct = 2, - e_gras_datadesc_type_cat_union = 3, - e_gras_datadesc_type_cat_ref = 4, /* ref to an uniq element */ - e_gras_datadesc_type_cat_array = 5, - - e_gras_datadesc_type_cat_invalid = 6 + + /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */ + + e_gras_datadesc_type_cat_undefined = 0, + + e_gras_datadesc_type_cat_scalar = 1, + e_gras_datadesc_type_cat_struct = 2, + e_gras_datadesc_type_cat_union = 3, + e_gras_datadesc_type_cat_ref = 4, /* ref to an uniq element */ + e_gras_datadesc_type_cat_array = 5, + + e_gras_datadesc_type_cat_invalid = 6 } gras_datadesc_type_category_t; /*------------------------------------------------*/ @@ -103,12 +103,12 @@ typedef enum e_gras_datadesc_type_category { */ typedef struct s_gras_dd_cat_field { - char *name; - long int offset[gras_arch_count]; - gras_datadesc_type_t type; - - gras_datadesc_type_cb_void_t send; - gras_datadesc_type_cb_void_t recv; + char *name; + long int offset[gras_arch_count]; + gras_datadesc_type_t type; + + gras_datadesc_type_cb_void_t send; + gras_datadesc_type_cb_void_t recv; } s_gras_dd_cat_field_t,*gras_dd_cat_field_t; @@ -120,17 +120,17 @@ void gras_dd_cat_field_free(void *f); * Specific fields of a scalar */ enum e_gras_dd_scalar_encoding { - e_gras_dd_scalar_encoding_undefined = 0, - - e_gras_dd_scalar_encoding_uint, - e_gras_dd_scalar_encoding_sint, - e_gras_dd_scalar_encoding_float, - - e_gras_dd_scalar_encoding_invalid + e_gras_dd_scalar_encoding_undefined = 0, + + e_gras_dd_scalar_encoding_uint, + e_gras_dd_scalar_encoding_sint, + e_gras_dd_scalar_encoding_float, + + e_gras_dd_scalar_encoding_invalid }; typedef struct s_gras_dd_cat_scalar { - enum e_gras_dd_scalar_encoding encoding; - gras_ddt_scalar_type_t type; /* to check easily that redefinition matches */ + enum e_gras_dd_scalar_encoding encoding; + gras_ddt_scalar_type_t type; /* to check easily that redefinition matches */ } gras_dd_cat_scalar_t; /** @@ -139,8 +139,8 @@ typedef struct s_gras_dd_cat_scalar { * Specific fields of a struct */ typedef struct s_gras_dd_cat_struct { - xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */ - int closed; /* gras_datadesc_declare_struct_close() was called */ + xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */ + int closed; /* gras_datadesc_declare_struct_close() was called */ } gras_dd_cat_struct_t; /** @@ -149,9 +149,9 @@ typedef struct s_gras_dd_cat_struct { * Specific fields of a union */ typedef struct s_gras_dd_cat_union { - gras_datadesc_type_cb_int_t selector; - xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */ - int closed; /* gras_datadesc_declare_union_close() was called */ + gras_datadesc_type_cb_int_t selector; + xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */ + int closed; /* gras_datadesc_declare_union_close() was called */ } gras_dd_cat_union_t; /** @@ -160,10 +160,10 @@ typedef struct s_gras_dd_cat_union { * Specific fields of a reference */ typedef struct s_gras_dd_cat_ref { - gras_datadesc_type_t type; + gras_datadesc_type_t type; - /* callback used to return the referenced type number */ - gras_datadesc_selector_t selector; + /* callback used to return the referenced type number */ + gras_datadesc_selector_t selector; } gras_dd_cat_ref_t; @@ -173,13 +173,13 @@ typedef struct s_gras_dd_cat_ref { * Specific fields of an array */ typedef struct s_gras_dd_cat_array { - gras_datadesc_type_t type; + gras_datadesc_type_t type; - /* element_count == 0 means dynamically defined */ - unsigned long int fixed_size; + /* element_count == 0 means dynamically defined */ + unsigned long int fixed_size; - /* callback used to return the dynamic length */ - gras_datadesc_type_cb_int_t dynamic_size; + /* callback used to return the dynamic length */ + gras_datadesc_type_cb_int_t dynamic_size; } gras_dd_cat_array_t; @@ -189,12 +189,12 @@ typedef struct s_gras_dd_cat_array { * Specific data to each possible category */ union u_gras_datadesc_category { - void *undefined_data; - gras_dd_cat_scalar_t scalar_data; - gras_dd_cat_struct_t struct_data; - gras_dd_cat_union_t union_data; - gras_dd_cat_ref_t ref_data; - gras_dd_cat_array_t array_data; + void *undefined_data; + gras_dd_cat_scalar_t scalar_data; + gras_dd_cat_struct_t struct_data; + gras_dd_cat_union_t union_data; + gras_dd_cat_ref_t ref_data; + gras_dd_cat_array_t array_data; }; /****************************************/ @@ -206,28 +206,28 @@ union u_gras_datadesc_category { * Type descriptor. */ typedef struct s_gras_datadesc_type { - /* headers for the data set */ - unsigned int code; - char *name; - unsigned int name_len; - - /* payload */ - unsigned long int size[gras_arch_count]; - - unsigned long int alignment[gras_arch_count]; - unsigned long int aligned_size[gras_arch_count]; - - enum e_gras_datadesc_type_category category_code; - union u_gras_datadesc_category category; - - gras_datadesc_type_cb_void_t send; - gras_datadesc_type_cb_void_t recv; - - /* flags */ - int cycle :1; - - /* random value for users (like default value or whatever) */ - char extra[SIZEOF_MAX]; + /* headers for the data set */ + unsigned int code; + char *name; + unsigned int name_len; + + /* payload */ + unsigned long int size[gras_arch_count]; + + unsigned long int alignment[gras_arch_count]; + unsigned long int aligned_size[gras_arch_count]; + + enum e_gras_datadesc_type_category category_code; + union u_gras_datadesc_category category; + + gras_datadesc_type_cb_void_t send; + gras_datadesc_type_cb_void_t recv; + + /* flags */ + int cycle :1; + + /* random value for users (like default value or whatever) */ + char extra[SIZEOF_MAX]; } s_gras_datadesc_type_t; @@ -236,10 +236,10 @@ typedef struct s_gras_datadesc_type { ***************************/ void gras_datadesc_free(gras_datadesc_type_t *type); - gras_datadesc_type_t - gras_datadesc_scalar(const char *name, - gras_ddt_scalar_type_t type, - enum e_gras_dd_scalar_encoding encoding); +gras_datadesc_type_t +gras_datadesc_scalar(const char *name, + gras_ddt_scalar_type_t type, + enum e_gras_dd_scalar_encoding encoding); /**************************************************** * Callback persistant state constructor/destructor * @@ -253,8 +253,8 @@ void gras_cbps_reset(gras_cbps_t state); ***************/ void gras_dd_convert_elm(gras_datadesc_type_t type, int count, - int r_arch, - void *src, void *dst); + int r_arch, + void *src, void *dst); /******************************************************************** * Dictionnary containing the constant values for the parsing macro * diff --git a/src/gras/DataDesc/ddt_convert.c b/src/gras/DataDesc/ddt_convert.c index fd20823961..e310edfec4 100644 --- a/src/gras/DataDesc/ddt_convert.c +++ b/src/gras/DataDesc/ddt_convert.c @@ -16,65 +16,65 @@ #include "gras/DataDesc/datadesc_private.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_convert,gras_ddt, - "Inter-architecture convertions"); + "Inter-architecture convertions"); /*** *** Table of all known architectures: *** l_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/8:) gras_arch=0; gras_arch_name=little32;; l_C:1/1:_I:2/2:4/4:4/4:8/4:_P:4/4:4/4:_D:4/4:8/4:) gras_arch=1; gras_arch_name=little32_4;; - + l_C:1/1:_I:2/2:4/4:8/8:8/8:_P:8/8:8/8:_D:4/4:8/8:) gras_arch=2; gras_arch_name=little64;; - + B_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/8:) gras_arch=3; gras_arch_name=big32;; B_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/4:) gras_arch=4; gras_arch_name=big32_8_4;; B_C:1/1:_I:2/2:4/4:4/4:8/4:_P:4/4:4/4:_D:4/4:8/4:) gras_arch=5; gras_arch_name=big32_4;; B_C:1/1:_I:2/2:4/2:4/2:8/2:_P:4/2:4/2:_D:4/2:8/2:) gras_arch=6; gras_arch_name=big32_2;; - + B_C:1/1:_I:2/2:4/4:8/8:8/8:_P:8/8:8/8:_D:4/4:8/8:) gras_arch=7; gras_arch_name=big64;; ***/ const gras_arch_desc_t gras_arches[gras_arch_count] = { - - {"little32_1", 0, {1,2,4,4,8, 4,4, 4,8}, /* little endian, 1 byte alignement (win32) */ - {1,1,1,1,1, 1,1, 1,1}}, - - {"little32_2", 0, {1,2,4,4,8, 4,4, 4,8}, /* little endian, 2 bytes alignements (win32) */ - {1,2,2,2,2, 2,2, 2,2}}, - - {"little32_4", 0, {1,2,4,4,8, 4,4, 4,8}, /* little endian, 4 bytes alignements (win32 and linux x86) */ - {1,2,4,4,4, 4,4, 4,4}}, - - {"little32_8", 0, {1,2,4,4,8, 4,4, 4,8}, /* little endian, 8 bytes alignement (win32) */ - {1,2,4,4,8, 4,4, 4,8}}, - - {"little64", 0, {1,2,4,8,8, 8,8, 4,8}, /* alpha, ia64 */ - {1,2,4,8,8, 8,8, 4,8}}, - - {"big32_8", 1, {1,2,4,4,8, 4,4, 4,8}, - {1,2,4,4,8, 4,4, 4,8}}, - - {"big32_8_4", 1, {1,2,4,4,8, 4,4, 4,8}, /* AIX */ - {1,2,4,4,8, 4,4, 4,4}}, - - {"big32_4", 1, {1,2,4,4,8, 4,4, 4,8}, /* G5 */ - {1,2,4,4,4, 4,4, 4,4}}, - - {"big32_2", 1, {1,2,4,4,8, 4,4, 4,8}, /* ARM */ - {1,2,2,2,2, 2,2, 2,2}}, - - {"big64", 1, {1,2,4,8,8, 8,8, 4,8}, /* sparc */ - {1,2,4,8,8, 8,8, 4,8}}, - - {"big64_8_4", 1, {1,2,4,8,8, 8,8, 4,8}, /* aix with -maix64 */ - {1,2,4,8,8, 8,8, 4,4}} + + {"little32_1", 0, {1,2,4,4,8, 4,4, 4,8}, /* little endian, 1 byte alignement (win32) */ + {1,1,1,1,1, 1,1, 1,1}}, + + {"little32_2", 0, {1,2,4,4,8, 4,4, 4,8}, /* little endian, 2 bytes alignements (win32) */ + {1,2,2,2,2, 2,2, 2,2}}, + + {"little32_4", 0, {1,2,4,4,8, 4,4, 4,8}, /* little endian, 4 bytes alignements (win32 and linux x86) */ + {1,2,4,4,4, 4,4, 4,4}}, + + {"little32_8", 0, {1,2,4,4,8, 4,4, 4,8}, /* little endian, 8 bytes alignement (win32) */ + {1,2,4,4,8, 4,4, 4,8}}, + + {"little64", 0, {1,2,4,8,8, 8,8, 4,8}, /* alpha, ia64 */ + {1,2,4,8,8, 8,8, 4,8}}, + + {"big32_8", 1, {1,2,4,4,8, 4,4, 4,8}, + {1,2,4,4,8, 4,4, 4,8}}, + + {"big32_8_4", 1, {1,2,4,4,8, 4,4, 4,8}, /* AIX */ + {1,2,4,4,8, 4,4, 4,4}}, + + {"big32_4", 1, {1,2,4,4,8, 4,4, 4,8}, /* G5 */ + {1,2,4,4,4, 4,4, 4,4}}, + + {"big32_2", 1, {1,2,4,4,8, 4,4, 4,8}, /* ARM */ + {1,2,2,2,2, 2,2, 2,2}}, + + {"big64", 1, {1,2,4,8,8, 8,8, 4,8}, /* sparc */ + {1,2,4,8,8, 8,8, 4,8}}, + + {"big64_8_4", 1, {1,2,4,8,8, 8,8, 4,8}, /* aix with -maix64 */ + {1,2,4,8,8, 8,8, 4,4}} }; const char *gras_datadesc_arch_name(int code) { - if (code < 0 || code >= gras_arch_count) - return "[unknown arch]"; - return gras_arches[code].name; + if (code < 0 || code >= gras_arch_count) + return "[unknown arch]"; + return gras_arches[code].name; } @@ -83,8 +83,8 @@ const char *gras_datadesc_arch_name(int code) { */ static void gras_dd_reverse_bytes(void *to, - const void *from, - size_t length); + const void *from, + size_t length); /** * gras_dd_convert_elm: @@ -95,39 +95,39 @@ gras_dd_reverse_bytes(void *to, */ void gras_dd_convert_elm(gras_datadesc_type_t type, int count, - int r_arch, - void *src, void *dst) { - gras_dd_cat_scalar_t scal = type->category.scalar_data; - int cpt; - const void *r_data; - void *l_data; - unsigned long r_size, l_size; - /* Hexadecimal displayer + int r_arch, + void *src, void *dst) { + gras_dd_cat_scalar_t scal = type->category.scalar_data; + int cpt; + const void *r_data; + void *l_data; + unsigned long r_size, l_size; + /* Hexadecimal displayer union { char c[sizeof(int)]; int i; } tester; - */ - - xbt_assert(type->category_code == e_gras_datadesc_type_cat_scalar); - xbt_assert(r_arch != GRAS_THISARCH); - - r_size = type->size[r_arch]; - l_size = type->size[GRAS_THISARCH]; - DEBUG4("r_size=%lu l_size=%lu, src=%p dst=%p", - r_size,l_size,src,dst); - - DEBUG2("remote=%c local=%c", gras_arches[r_arch].endian?'B':'l', - gras_arches[GRAS_THISARCH].endian?'B':'l'); - - if(r_size != l_size) { - for(cpt = 0, r_data = src, l_data = dst; - cpt < count; - cpt++, - r_data = (char *)r_data + r_size, - l_data = (char *)l_data + l_size) { - - /* + */ + + xbt_assert(type->category_code == e_gras_datadesc_type_cat_scalar); + xbt_assert(r_arch != GRAS_THISARCH); + + r_size = type->size[r_arch]; + l_size = type->size[GRAS_THISARCH]; + DEBUG4("r_size=%lu l_size=%lu, src=%p dst=%p", + r_size,l_size,src,dst); + + DEBUG2("remote=%c local=%c", gras_arches[r_arch].endian?'B':'l', + gras_arches[GRAS_THISARCH].endian?'B':'l'); + + if(r_size != l_size) { + for(cpt = 0, r_data = src, l_data = dst; + cpt < count; + cpt++, + r_data = (char *)r_data + r_size, + l_data = (char *)l_data + l_size) { + + /* fprintf(stderr,"r_data="); for (cpt=0; cpt 127) != (*l_sign > 127)) { - if(*r_sign > 127) - *l_sign += 128; - else - *l_sign -= 128; - } - } - } else { - DEBUG1("Extend %d bytes", sizeChange); - if (scal.encoding != e_gras_dd_scalar_encoding_sint) { - DEBUG0("This is signed"); - padding = 0; /* pad unsigned with 0 */ - } else { - /* extend sign */ - r_sign = gras_arches[r_arch].endian ? ((unsigned char*)r_data + r_size - 1) - : (unsigned char*)r_data; - padding = (*r_sign > 127) ? 0xff : 0; - } - - memset(l_data, padding, l_size); - memcpy(!gras_arches[r_arch].endian ? l_data : ((char *)l_data + sizeChange), - r_data, r_size); - - /* + */ + + /* Resize that damn integer, pal */ + + unsigned char *l_sign, *r_sign; + int padding; + int sizeChange = l_size - r_size; + int lowOrderFirst = !gras_arches[r_arch].endian || + gras_arches[r_arch].endian == gras_arches[GRAS_THISARCH].endian; + + DEBUG5("Resize integer %d from %lu @%p to %lu @%p", + cpt, r_size,r_data, l_size,l_data); + xbt_assert0(r_data != l_data, "Impossible to resize in place"); + + if(sizeChange < 0) { + DEBUG3("Truncate %d bytes (%s,%s)", -sizeChange, + lowOrderFirst?"lowOrderFirst":"bigOrderFirst", + scal.encoding == e_gras_dd_scalar_encoding_sint?"signed":"unsigned"); + /* Truncate high-order bytes. */ + memcpy(l_data, + gras_arches[r_arch].endian ? ((char*)r_data-sizeChange) + : r_data, + l_size); + + if(scal.encoding == e_gras_dd_scalar_encoding_sint) { + DEBUG0("This is signed"); + /* Make sure the high order bit of r_data and l_data are the same */ + l_sign = gras_arches[GRAS_THISARCH].endian + ? ((unsigned char*)l_data + l_size - 1) + : (unsigned char*)l_data; + r_sign = gras_arches[r_arch].endian + ? ((unsigned char*)r_data + r_size - 1) + : (unsigned char*)r_data; + DEBUG2("This is signed (r_sign=%c l_sign=%c", *r_sign,*l_sign); + + if ((*r_sign > 127) != (*l_sign > 127)) { + if(*r_sign > 127) + *l_sign += 128; + else + *l_sign -= 128; + } + } + } else { + DEBUG1("Extend %d bytes", sizeChange); + if (scal.encoding != e_gras_dd_scalar_encoding_sint) { + DEBUG0("This is signed"); + padding = 0; /* pad unsigned with 0 */ + } else { + /* extend sign */ + r_sign = gras_arches[r_arch].endian ? ((unsigned char*)r_data + r_size - 1) + : (unsigned char*)r_data; + padding = (*r_sign > 127) ? 0xff : 0; + } + + memset(l_data, padding, l_size); + memcpy(!gras_arches[r_arch].endian ? l_data : ((char *)l_data + sizeChange), + r_data, r_size); + + /* fprintf(stderr,"r_data="); for (cpt=0; cpt 1) { + /* flip bytes if needed */ + if(gras_arches[r_arch].endian != gras_arches[GRAS_THISARCH].endian && + (l_size * count) > 1) { - for(cpt = 0, r_data=dst, l_data=dst; - cpt < count; - cpt++, - r_data = (char *)r_data + l_size, /* resizing already done */ - l_data = (char *)l_data + l_size) { + for(cpt = 0, r_data=dst, l_data=dst; + cpt < count; + cpt++, + r_data = (char *)r_data + l_size, /* resizing already done */ + l_data = (char *)l_data + l_size) { - DEBUG1("Flip elm %d",cpt); - gras_dd_reverse_bytes(l_data, r_data, l_size); - } - } + DEBUG1("Flip elm %d",cpt); + gras_dd_reverse_bytes(l_data, r_data, l_size); + } + } } static void gras_dd_reverse_bytes(void *to, - const void *from, - size_t length) { + const void *from, + size_t length) { - char charBegin; - const char *fromBegin; - const char *fromEnd; - char *toBegin; - char *toEnd; + char charBegin; + const char *fromBegin; + const char *fromEnd; + char *toBegin; + char *toEnd; - for(fromBegin = (const char *)from, - fromEnd = fromBegin + length - 1, - toBegin = (char *)to, - toEnd = toBegin + length - 1; + for(fromBegin = (const char *)from, + fromEnd = fromBegin + length - 1, + toBegin = (char *)to, + toEnd = toBegin + length - 1; - fromBegin <= fromEnd; + fromBegin <= fromEnd; - fromBegin++, fromEnd--, + fromBegin++, fromEnd--, toBegin++, toEnd--) { - charBegin = *fromBegin; - *toBegin = *fromEnd; - *toEnd = charBegin; - } + charBegin = *fromBegin; + *toBegin = *fromEnd; + *toEnd = charBegin; + } } @@ -265,5 +265,5 @@ gras_dd_reverse_bytes(void *to, */ int gras_arch_selfid(void) { - return GRAS_THISARCH; + return GRAS_THISARCH; } diff --git a/src/gras/DataDesc/ddt_create.c b/src/gras/DataDesc/ddt_create.c index 5b1af089e7..72e896fd52 100644 --- a/src/gras/DataDesc/ddt_create.c +++ b/src/gras/DataDesc/ddt_create.c @@ -17,232 +17,232 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_create,gras_ddt,"Creating new datadescr /*** prototypes ***/ static gras_dd_cat_field_t - gras_dd_find_field(gras_datadesc_type_t type, - const char *field_name); +gras_dd_find_field(gras_datadesc_type_t type, + const char *field_name); /** * gras_ddt_freev: * * gime that memory back, dude. I mean it. */ void gras_ddt_freev(void *ddt) { - gras_datadesc_type_t type= (gras_datadesc_type_t)ddt; + gras_datadesc_type_t type= (gras_datadesc_type_t)ddt; - if (type) { - gras_datadesc_free(&type); - } + if (type) { + gras_datadesc_free(&type); + } } static gras_datadesc_type_t gras_ddt_new(const char *name) { - gras_datadesc_type_t res; + gras_datadesc_type_t res; - XBT_IN1("(%s)",name); - res=xbt_new0(s_gras_datadesc_type_t,1); + XBT_IN1("(%s)",name); + res=xbt_new0(s_gras_datadesc_type_t,1); - res->name = (char*)strdup(name); - res->name_len = strlen(name); - res->cycle = 0; + res->name = (char*)strdup(name); + res->name_len = strlen(name); + res->cycle = 0; - xbt_set_add(gras_datadesc_set_local, - (xbt_set_elm_t)res,gras_ddt_freev); - XBT_OUT; - return res; + xbt_set_add(gras_datadesc_set_local, + (xbt_set_elm_t)res,gras_ddt_freev); + XBT_OUT; + return res; } /** @brief retrieve an existing message type from its name (or NULL if it does not exist). */ gras_datadesc_type_t gras_datadesc_by_name_or_null (const char *name) { - xbt_ex_t e; - gras_datadesc_type_t res = NULL; - - TRY { - res = gras_datadesc_by_name(name); - } CATCH(e) { - res = NULL; - xbt_ex_free(e); - } - return res; + xbt_ex_t e; + gras_datadesc_type_t res = NULL; + + TRY { + res = gras_datadesc_by_name(name); + } CATCH(e) { + res = NULL; + xbt_ex_free(e); + } + return res; } /** * Search the given datadesc (or raises an exception if it can't be found) */ gras_datadesc_type_t gras_datadesc_by_name(const char *name) { - xbt_ex_t e; - gras_datadesc_type_t res = NULL; - volatile int found = 0; - TRY { - res = (gras_datadesc_type_t)xbt_set_get_by_name(gras_datadesc_set_local,name); - found = 1; - } CATCH(e) { - if (e.category != not_found_error) - RETHROW; - xbt_ex_free(e); - } - if (!found) - THROW1(not_found_error,0,"No registred datatype of that name: %s",name); - - return res; + xbt_ex_t e; + gras_datadesc_type_t res = NULL; + volatile int found = 0; + TRY { + res = (gras_datadesc_type_t)xbt_set_get_by_name(gras_datadesc_set_local,name); + found = 1; + } CATCH(e) { + if (e.category != not_found_error) + RETHROW; + xbt_ex_free(e); + } + if (!found) + THROW1(not_found_error,0,"No registred datatype of that name: %s",name); + + return res; } /** * Retrieve a type from its code (or NULL if not found) */ gras_datadesc_type_t gras_datadesc_by_id(long int code) { - xbt_ex_t e; - gras_datadesc_type_t res=NULL; - TRY { - res = (gras_datadesc_type_t)xbt_set_get_by_id(gras_datadesc_set_local,code); - } CATCH(e) { - if (e.category != not_found_error) - RETHROW; - xbt_ex_free(e); - res = NULL; - } - return res; + xbt_ex_t e; + gras_datadesc_type_t res=NULL; + TRY { + res = (gras_datadesc_type_t)xbt_set_get_by_id(gras_datadesc_set_local,code); + } CATCH(e) { + if (e.category != not_found_error) + RETHROW; + xbt_ex_free(e); + res = NULL; + } + return res; } /** * Create a new scalar and give a pointer to it */ gras_datadesc_type_t - gras_datadesc_scalar(const char *name, - gras_ddt_scalar_type_t type, - enum e_gras_dd_scalar_encoding encoding) { - - gras_datadesc_type_t res; - long int arch; - - XBT_IN; - res = gras_datadesc_by_name_or_null(name); - if (res) { - xbt_assert1(res->category_code == e_gras_datadesc_type_cat_scalar, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.scalar_data.encoding == encoding, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.scalar_data.type == type, - "Redefinition of type %s does not match", name); - VERB1("Discarding redefinition of %s",name); - return res; - } - res = gras_ddt_new(name); - - for (arch = 0; arch < gras_arch_count; arch ++) { - res->size[arch] = gras_arches[arch].sizeofs[type]; - res->alignment[arch] = gras_arches[arch].boundaries[type]; - res->aligned_size[arch] = ddt_aligned(res->size[arch], res->alignment[arch]); - } - - res->category_code = e_gras_datadesc_type_cat_scalar; - res->category.scalar_data.encoding = encoding; - res->category.scalar_data.type = type; - XBT_OUT; - - return res; +gras_datadesc_scalar(const char *name, + gras_ddt_scalar_type_t type, + enum e_gras_dd_scalar_encoding encoding) { + + gras_datadesc_type_t res; + long int arch; + + XBT_IN; + res = gras_datadesc_by_name_or_null(name); + if (res) { + xbt_assert1(res->category_code == e_gras_datadesc_type_cat_scalar, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.scalar_data.encoding == encoding, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.scalar_data.type == type, + "Redefinition of type %s does not match", name); + VERB1("Discarding redefinition of %s",name); + return res; + } + res = gras_ddt_new(name); + + for (arch = 0; arch < gras_arch_count; arch ++) { + res->size[arch] = gras_arches[arch].sizeofs[type]; + res->alignment[arch] = gras_arches[arch].boundaries[type]; + res->aligned_size[arch] = ddt_aligned(res->size[arch], res->alignment[arch]); + } + + res->category_code = e_gras_datadesc_type_cat_scalar; + res->category.scalar_data.encoding = encoding; + res->category.scalar_data.type = type; + XBT_OUT; + + return res; } /** Frees one struct or union field */ void gras_dd_cat_field_free(void *f) { - gras_dd_cat_field_t field = *(gras_dd_cat_field_t *)f; - XBT_IN; - if (field) { - if (field->name) - free(field->name); - free(field); - } - XBT_OUT; + gras_dd_cat_field_t field = *(gras_dd_cat_field_t *)f; + XBT_IN; + if (field) { + if (field->name) + free(field->name); + free(field); + } + XBT_OUT; } /** \brief Declare a new structure description */ gras_datadesc_type_t - gras_datadesc_struct(const char *name) { - - gras_datadesc_type_t res; - long int arch; - - XBT_IN1("(%s)",name); - res = gras_datadesc_by_name_or_null(name); - if (res) { - /* FIXME: Check that field redefinition matches */ - xbt_assert1(res->category_code == e_gras_datadesc_type_cat_struct, - "Redefinition of type %s does not match", name); - VERB1("Discarding redefinition of %s",name); - return res; - } - res = gras_ddt_new(name); - - for (arch=0; archsize[arch] = 0; - res->alignment[arch] = 0; - res->aligned_size[arch] = 0; - } - res->category_code = e_gras_datadesc_type_cat_struct; - res->category.struct_data.fields = - xbt_dynar_new(sizeof(gras_dd_cat_field_t), - gras_dd_cat_field_free); - - XBT_OUT; - return res; +gras_datadesc_struct(const char *name) { + + gras_datadesc_type_t res; + long int arch; + + XBT_IN1("(%s)",name); + res = gras_datadesc_by_name_or_null(name); + if (res) { + /* FIXME: Check that field redefinition matches */ + xbt_assert1(res->category_code == e_gras_datadesc_type_cat_struct, + "Redefinition of type %s does not match", name); + VERB1("Discarding redefinition of %s",name); + return res; + } + res = gras_ddt_new(name); + + for (arch=0; archsize[arch] = 0; + res->alignment[arch] = 0; + res->aligned_size[arch] = 0; + } + res->category_code = e_gras_datadesc_type_cat_struct; + res->category.struct_data.fields = + xbt_dynar_new(sizeof(gras_dd_cat_field_t), + gras_dd_cat_field_free); + + XBT_OUT; + return res; } /** \brief Append a new field to a structure description */ void gras_datadesc_struct_append(gras_datadesc_type_t struct_type, - const char *name, - gras_datadesc_type_t field_type) { - - gras_dd_cat_field_t field; - int arch; - - xbt_assert2(field_type, - "Cannot add the field '%s' into struct '%s': its type is NULL", - name,struct_type->name); - XBT_IN3("(%s %s.%s;)",field_type->name,struct_type->name,name); - if (struct_type->category.struct_data.closed) { - VERB1("Ignoring request to add field to struct %s (closed. Redefinition?)", - struct_type->name); - return; - } - - xbt_assert1(field_type->size != 0, - "Cannot add a dynamically sized field in structure %s", - struct_type->name); - - field=xbt_new(s_gras_dd_cat_field_t,1); - field->name = (char*)strdup(name); - - DEBUG0("----------------"); - 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]); - - - for (arch=0; archoffset[arch] = ddt_aligned(struct_type->size[arch], - field_type->alignment[arch]); - - struct_type->size[arch] = field->offset[arch] + field_type->size[arch]; - struct_type->alignment[arch] = max(struct_type->alignment[arch], - field_type->alignment[arch]); - struct_type->aligned_size[arch] = ddt_aligned(struct_type->size[arch], - struct_type->alignment[arch]); - } - field->type = field_type; - field->send = NULL; - field->recv = NULL; - - xbt_dynar_push(struct_type->category.struct_data.fields, &field); - - DEBUG3("Push a %s into %s at offset %ld.", - field_type->name, struct_type->name,field->offset[GRAS_THISARCH]); - DEBUG3(" f={size=%ld,align=%ld,asize=%ld}", - field_type->size[GRAS_THISARCH], - field_type->alignment[GRAS_THISARCH], - field_type->aligned_size[GRAS_THISARCH]); - DEBUG3(" s={size=%ld,align=%ld,asize=%ld}", - struct_type->size[GRAS_THISARCH], - struct_type->alignment[GRAS_THISARCH], - struct_type->aligned_size[GRAS_THISARCH]); - XBT_OUT; + const char *name, + gras_datadesc_type_t field_type) { + + gras_dd_cat_field_t field; + int arch; + + xbt_assert2(field_type, + "Cannot add the field '%s' into struct '%s': its type is NULL", + name,struct_type->name); + XBT_IN3("(%s %s.%s;)",field_type->name,struct_type->name,name); + if (struct_type->category.struct_data.closed) { + VERB1("Ignoring request to add field to struct %s (closed. Redefinition?)", + struct_type->name); + return; + } + + xbt_assert1(field_type->size != 0, + "Cannot add a dynamically sized field in structure %s", + struct_type->name); + + field=xbt_new(s_gras_dd_cat_field_t,1); + field->name = (char*)strdup(name); + + DEBUG0("----------------"); + 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]); + + + for (arch=0; archoffset[arch] = ddt_aligned(struct_type->size[arch], + field_type->alignment[arch]); + + struct_type->size[arch] = field->offset[arch] + field_type->size[arch]; + struct_type->alignment[arch] = max(struct_type->alignment[arch], + field_type->alignment[arch]); + struct_type->aligned_size[arch] = ddt_aligned(struct_type->size[arch], + struct_type->alignment[arch]); + } + field->type = field_type; + field->send = NULL; + field->recv = NULL; + + xbt_dynar_push(struct_type->category.struct_data.fields, &field); + + DEBUG3("Push a %s into %s at offset %ld.", + field_type->name, struct_type->name,field->offset[GRAS_THISARCH]); + DEBUG3(" f={size=%ld,align=%ld,asize=%ld}", + field_type->size[GRAS_THISARCH], + field_type->alignment[GRAS_THISARCH], + field_type->aligned_size[GRAS_THISARCH]); + DEBUG3(" s={size=%ld,align=%ld,asize=%ld}", + struct_type->size[GRAS_THISARCH], + struct_type->alignment[GRAS_THISARCH], + struct_type->aligned_size[GRAS_THISARCH]); + XBT_OUT; } /** \brief Close a structure description @@ -252,16 +252,16 @@ gras_datadesc_struct_append(gras_datadesc_type_t struct_type, void gras_datadesc_struct_close(gras_datadesc_type_t struct_type) { int arch; - XBT_IN; - struct_type->category.struct_data.closed = 1; - for (arch=0; archsize[arch] = struct_type->aligned_size[arch]; - } - DEBUG4("structure %s closed. size=%ld,align=%ld,asize=%ld", - struct_type->name, - struct_type->size[GRAS_THISARCH], - struct_type->alignment[GRAS_THISARCH], - struct_type->aligned_size[GRAS_THISARCH]); + XBT_IN; + struct_type->category.struct_data.closed = 1; + for (arch=0; archsize[arch] = struct_type->aligned_size[arch]; + } + DEBUG4("structure %s closed. size=%ld,align=%ld,asize=%ld", + struct_type->name, + struct_type->size[GRAS_THISARCH], + struct_type->alignment[GRAS_THISARCH], + struct_type->aligned_size[GRAS_THISARCH]); } /** @@ -275,7 +275,7 @@ gras_datadesc_struct_close(gras_datadesc_type_t struct_type) { */ void gras_datadesc_cycle_set(gras_datadesc_type_t ddt) { - ddt->cycle = 1; + ddt->cycle = 1; } /** @@ -287,84 +287,84 @@ gras_datadesc_cycle_set(gras_datadesc_type_t ddt) { */ void gras_datadesc_cycle_unset(gras_datadesc_type_t ddt) { - ddt->cycle = 0; + ddt->cycle = 0; } /** \brief Declare a new union description */ gras_datadesc_type_t - gras_datadesc_union(const char *name, - gras_datadesc_type_cb_int_t selector) { - - gras_datadesc_type_t res; - int arch; - - XBT_IN1("(%s)",name); - xbt_assert0(selector, - "Attempt to creat an union without field_count function"); - - res = gras_datadesc_by_name_or_null(name); - if (res) { - /* FIXME: Check that field redefinition matches */ - xbt_assert1(res->category_code == e_gras_datadesc_type_cat_union, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.union_data.selector == selector, - "Redefinition of type %s does not match", name); - VERB1("Discarding redefinition of %s",name); - return res; - } - - res = gras_ddt_new(name); - - for (arch=0; archsize[arch] = 0; - res->alignment[arch] = 0; - res->aligned_size[arch] = 0; - } - - res->category_code = e_gras_datadesc_type_cat_union; - res->category.union_data.fields = - xbt_dynar_new(sizeof(gras_dd_cat_field_t*), - gras_dd_cat_field_free); - res->category.union_data.selector = selector; - - return res; +gras_datadesc_union(const char *name, + gras_datadesc_type_cb_int_t selector) { + + gras_datadesc_type_t res; + int arch; + + XBT_IN1("(%s)",name); + xbt_assert0(selector, + "Attempt to creat an union without field_count function"); + + res = gras_datadesc_by_name_or_null(name); + if (res) { + /* FIXME: Check that field redefinition matches */ + xbt_assert1(res->category_code == e_gras_datadesc_type_cat_union, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.union_data.selector == selector, + "Redefinition of type %s does not match", name); + VERB1("Discarding redefinition of %s",name); + return res; + } + + res = gras_ddt_new(name); + + for (arch=0; archsize[arch] = 0; + res->alignment[arch] = 0; + res->aligned_size[arch] = 0; + } + + res->category_code = e_gras_datadesc_type_cat_union; + res->category.union_data.fields = + xbt_dynar_new(sizeof(gras_dd_cat_field_t*), + gras_dd_cat_field_free); + res->category.union_data.selector = selector; + + return res; } /** \brief Append a new field to an union description */ void gras_datadesc_union_append(gras_datadesc_type_t union_type, - const char *name, - gras_datadesc_type_t field_type) { - - gras_dd_cat_field_t field; - int arch; - - XBT_IN3("(%s %s.%s;)",field_type->name,union_type->name,name); - xbt_assert1(field_type->size != 0, - "Cannot add a dynamically sized field in union %s", - union_type->name); - - if (union_type->category.union_data.closed) { - VERB1("Ignoring request to add field to union %s (closed)", - union_type->name); - return; - } - - field=xbt_new0(s_gras_dd_cat_field_t,1); - - field->name = (char*)strdup(name); - field->type = field_type; - /* All offset are left to 0 in an union */ - - xbt_dynar_push(union_type->category.union_data.fields, &field); - - for (arch=0; archsize[arch] = max(union_type->size[arch], - field_type->size[arch]); - union_type->alignment[arch] = max(union_type->alignment[arch], - field_type->alignment[arch]); - union_type->aligned_size[arch] = ddt_aligned(union_type->size[arch], - union_type->alignment[arch]); - } + const char *name, + gras_datadesc_type_t field_type) { + + gras_dd_cat_field_t field; + int arch; + + XBT_IN3("(%s %s.%s;)",field_type->name,union_type->name,name); + xbt_assert1(field_type->size != 0, + "Cannot add a dynamically sized field in union %s", + union_type->name); + + if (union_type->category.union_data.closed) { + VERB1("Ignoring request to add field to union %s (closed)", + union_type->name); + return; + } + + field=xbt_new0(s_gras_dd_cat_field_t,1); + + field->name = (char*)strdup(name); + field->type = field_type; + /* All offset are left to 0 in an union */ + + xbt_dynar_push(union_type->category.union_data.fields, &field); + + for (arch=0; archsize[arch] = max(union_type->size[arch], + field_type->size[arch]); + union_type->alignment[arch] = max(union_type->alignment[arch], + field_type->alignment[arch]); + union_type->aligned_size[arch] = ddt_aligned(union_type->size[arch], + union_type->alignment[arch]); + } } @@ -374,7 +374,7 @@ void gras_datadesc_union_append(gras_datadesc_type_t union_type, */ void gras_datadesc_union_close(gras_datadesc_type_t union_type) { - union_type->category.union_data.closed = 1; + union_type->category.union_data.closed = 1; } /** \brief Copy a type under another name @@ -382,54 +382,54 @@ gras_datadesc_union_close(gras_datadesc_type_t union_type) { * This may reveal useful to circumvent parsing macro limitations */ gras_datadesc_type_t - gras_datadesc_copy(const char *name, - gras_datadesc_type_t copied) { +gras_datadesc_copy(const char *name, + gras_datadesc_type_t copied) { - gras_datadesc_type_t res = gras_ddt_new(name); - char *name_cpy = res->name; + gras_datadesc_type_t res = gras_ddt_new(name); + char *name_cpy = res->name; - memcpy(res,copied,sizeof(s_gras_datadesc_type_t)); - res->name = name_cpy; - return res; - } + memcpy(res,copied,sizeof(s_gras_datadesc_type_t)); + res->name = name_cpy; + return res; +} /** \brief Declare a new type being a reference to the one passed in arg */ gras_datadesc_type_t - gras_datadesc_ref(const char *name, - gras_datadesc_type_t referenced_type) { - - gras_datadesc_type_t res; - gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer"); - int arch; - - XBT_IN1("(%s)",name); - res = gras_datadesc_by_name_or_null(name); - if (res) { - xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref, - "Redefinition of %s does not match",name); - xbt_assert1(res->category.ref_data.type == referenced_type, - "Redefinition of %s does not match",name); - xbt_assert1(res->category.ref_data.selector == NULL, - "Redefinition of %s does not match",name); - VERB1("Discarding redefinition of %s",name); - return res; - } - - res = gras_ddt_new(name); - - xbt_assert0(pointer_type, "Cannot get the description of data pointer"); - - for (arch=0; archsize[arch] = pointer_type->size[arch]; - res->alignment[arch] = pointer_type->alignment[arch]; - res->aligned_size[arch] = pointer_type->aligned_size[arch]; - } - - res->category_code = e_gras_datadesc_type_cat_ref; - res->category.ref_data.type = referenced_type; - res->category.ref_data.selector = NULL; - - return res; +gras_datadesc_ref(const char *name, + gras_datadesc_type_t referenced_type) { + + gras_datadesc_type_t res; + gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer"); + int arch; + + XBT_IN1("(%s)",name); + res = gras_datadesc_by_name_or_null(name); + if (res) { + xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref, + "Redefinition of %s does not match",name); + xbt_assert1(res->category.ref_data.type == referenced_type, + "Redefinition of %s does not match",name); + xbt_assert1(res->category.ref_data.selector == NULL, + "Redefinition of %s does not match",name); + VERB1("Discarding redefinition of %s",name); + return res; + } + + res = gras_ddt_new(name); + + xbt_assert0(pointer_type, "Cannot get the description of data pointer"); + + for (arch=0; archsize[arch] = pointer_type->size[arch]; + res->alignment[arch] = pointer_type->alignment[arch]; + res->aligned_size[arch] = pointer_type->aligned_size[arch]; + } + + res->category_code = e_gras_datadesc_type_cat_ref; + res->category.ref_data.type = referenced_type; + res->category.ref_data.selector = NULL; + + return res; } /** \brief Declare a new type being a generic reference. * @@ -438,134 +438,134 @@ gras_datadesc_type_t * callback and expects it to return the type description to use. */ gras_datadesc_type_t - gras_datadesc_ref_generic(const char *name, - gras_datadesc_selector_t selector) { - - gras_datadesc_type_t res; - gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer"); - int arch; - - XBT_IN1("(%s)",name); - res = gras_datadesc_by_name_or_null(name); - - if (res) { - xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.ref_data.type == NULL, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.ref_data.selector == selector, - "Redefinition of type %s does not match", name); - VERB1("Discarding redefinition of %s",name); - return res; - } - res = gras_ddt_new(name); - - xbt_assert0(pointer_type, "Cannot get the description of data pointer"); - - for (arch=0; archsize[arch] = pointer_type->size[arch]; - res->alignment[arch] = pointer_type->alignment[arch]; - res->aligned_size[arch] = pointer_type->aligned_size[arch]; - } - - res->category_code = e_gras_datadesc_type_cat_ref; - - res->category.ref_data.type = NULL; - res->category.ref_data.selector = selector; - - return res; +gras_datadesc_ref_generic(const char *name, + gras_datadesc_selector_t selector) { + + gras_datadesc_type_t res; + gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer"); + int arch; + + XBT_IN1("(%s)",name); + res = gras_datadesc_by_name_or_null(name); + + if (res) { + xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.ref_data.type == NULL, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.ref_data.selector == selector, + "Redefinition of type %s does not match", name); + VERB1("Discarding redefinition of %s",name); + return res; + } + res = gras_ddt_new(name); + + xbt_assert0(pointer_type, "Cannot get the description of data pointer"); + + for (arch=0; archsize[arch] = pointer_type->size[arch]; + res->alignment[arch] = pointer_type->alignment[arch]; + res->aligned_size[arch] = pointer_type->aligned_size[arch]; + } + + res->category_code = e_gras_datadesc_type_cat_ref; + + res->category.ref_data.type = NULL; + res->category.ref_data.selector = selector; + + return res; } /** \brief Declare a new type being an array of fixed size and content */ 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 res; - int arch; - - XBT_IN1("(%s)",name); - res = gras_datadesc_by_name_or_null(name); - if (res) { - xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array, - "Redefinition of type %s does not match", name); - - if (res->category.array_data.type != element_type) { - ERROR1("Redefinition of type %s does not match: array elements differ", name); - gras_datadesc_type_dump(res->category.array_data.type); - gras_datadesc_type_dump(element_type); - } - - xbt_assert1(res->category.array_data.fixed_size == fixed_size, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.array_data.dynamic_size == NULL, - "Redefinition of type %s does not match", name); - VERB1("Discarding redefinition of %s",name); - - return res; - } - res = gras_ddt_new(name); - - xbt_assert1(fixed_size > 0, "'%s' is a array of null fixed size",name); - for (arch=0; archsize[arch] = fixed_size * element_type->aligned_size[arch]; - res->alignment[arch] = element_type->alignment[arch]; - res->aligned_size[arch] = res->size[arch]; - } - - res->category_code = e_gras_datadesc_type_cat_array; - - res->category.array_data.type = element_type; - res->category.array_data.fixed_size = fixed_size; - res->category.array_data.dynamic_size = NULL; - - return res; +gras_datadesc_array_fixed(const char *name, + gras_datadesc_type_t element_type, + long int fixed_size) { + + gras_datadesc_type_t res; + int arch; + + XBT_IN1("(%s)",name); + res = gras_datadesc_by_name_or_null(name); + if (res) { + xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array, + "Redefinition of type %s does not match", name); + + if (res->category.array_data.type != element_type) { + ERROR1("Redefinition of type %s does not match: array elements differ", name); + gras_datadesc_type_dump(res->category.array_data.type); + gras_datadesc_type_dump(element_type); + } + + xbt_assert1(res->category.array_data.fixed_size == fixed_size, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.array_data.dynamic_size == NULL, + "Redefinition of type %s does not match", name); + VERB1("Discarding redefinition of %s",name); + + return res; + } + res = gras_ddt_new(name); + + xbt_assert1(fixed_size > 0, "'%s' is a array of null fixed size",name); + for (arch=0; archsize[arch] = fixed_size * element_type->aligned_size[arch]; + res->alignment[arch] = element_type->alignment[arch]; + res->aligned_size[arch] = res->size[arch]; + } + + res->category_code = e_gras_datadesc_type_cat_array; + + res->category.array_data.type = element_type; + res->category.array_data.fixed_size = fixed_size; + res->category.array_data.dynamic_size = NULL; + + return res; } /** \brief Declare a new type being an array of fixed size, but accepting several content types. */ 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 res; - int arch; - - XBT_IN1("(%s)",name); - xbt_assert1(dynamic_size, - "'%s' is a dynamic array without size discriminant", - name); - - res = gras_datadesc_by_name_or_null(name); - if (res) { - xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.array_data.type == element_type, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.array_data.fixed_size == 0, - "Redefinition of type %s does not match", name); - xbt_assert1(res->category.array_data.dynamic_size == dynamic_size, - "Redefinition of type %s does not match", name); - VERB1("Discarding redefinition of %s",name); - - return res; - } - - res = gras_ddt_new(name); - - for (arch=0; archsize[arch] = 0; /* make sure it indicates "dynamic" */ - res->alignment[arch] = element_type->alignment[arch]; - res->aligned_size[arch] = 0; /*FIXME: That was so in GS, but looks stupid*/ - } - - res->category_code = e_gras_datadesc_type_cat_array; - - res->category.array_data.type = element_type; - res->category.array_data.fixed_size = 0; - res->category.array_data.dynamic_size = dynamic_size; - - return res; + gras_datadesc_type_t element_type, + gras_datadesc_type_cb_int_t dynamic_size) { + + gras_datadesc_type_t res; + int arch; + + XBT_IN1("(%s)",name); + xbt_assert1(dynamic_size, + "'%s' is a dynamic array without size discriminant", + name); + + res = gras_datadesc_by_name_or_null(name); + if (res) { + xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.array_data.type == element_type, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.array_data.fixed_size == 0, + "Redefinition of type %s does not match", name); + xbt_assert1(res->category.array_data.dynamic_size == dynamic_size, + "Redefinition of type %s does not match", name); + VERB1("Discarding redefinition of %s",name); + + return res; + } + + res = gras_ddt_new(name); + + for (arch=0; archsize[arch] = 0; /* make sure it indicates "dynamic" */ + res->alignment[arch] = element_type->alignment[arch]; + res->aligned_size[arch] = 0; /*FIXME: That was so in GS, but looks stupid*/ + } + + res->category_code = e_gras_datadesc_type_cat_array; + + res->category.array_data.type = element_type; + res->category.array_data.fixed_size = 0; + res->category.array_data.dynamic_size = dynamic_size; + + return res; } /** \brief Declare a new type being an array which size can be found with \ref gras_cbps_i_pop @@ -591,22 +591,22 @@ gras_datadesc_type_t gras_datadesc_array_dyn(const char *name, * */ gras_datadesc_type_t - gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) { +gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) { - gras_datadesc_type_t res; - char *name=(char*)xbt_malloc(strlen(element_type->name) + 4); + gras_datadesc_type_t res; + char *name=(char*)xbt_malloc(strlen(element_type->name) + 4); - sprintf(name,"%s[]",element_type->name); + sprintf(name,"%s[]",element_type->name); - res = gras_datadesc_array_dyn(name,element_type, - gras_datadesc_cb_pop); + res = gras_datadesc_array_dyn(name,element_type, + gras_datadesc_cb_pop); - sprintf(name,"%s[]*",element_type->name); - res = gras_datadesc_ref(name,res); + sprintf(name,"%s[]*",element_type->name); + res = gras_datadesc_ref(name,res); - free(name); + free(name); - return res; + return res; } /* @@ -617,23 +617,23 @@ gras_datadesc_type_t #include "xbt/dynar_private.h" static void gras_datadesc_dynar_cb(gras_datadesc_type_t typedesc, gras_cbps_t vars, void *data) { - gras_datadesc_type_t subtype; - xbt_dynar_t dynar=(xbt_dynar_t)data; + gras_datadesc_type_t subtype; + xbt_dynar_t dynar=(xbt_dynar_t)data; - memcpy(&dynar->free_f, &typedesc->extra, sizeof(dynar->free_f)); + memcpy(&dynar->free_f, &typedesc->extra, sizeof(dynar->free_f)); - /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */ - subtype = gras_dd_find_field(typedesc,"data")->type; + /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */ + subtype = gras_dd_find_field(typedesc,"data")->type; - /* this is now a ref to array of what we're looking for */ - subtype = subtype->category.ref_data.type; - subtype = subtype->category.array_data.type; + /* this is now a ref to array of what we're looking for */ + subtype = subtype->category.ref_data.type; + subtype = subtype->category.array_data.type; - DEBUG1("subtype is %s",subtype->name); + DEBUG1("subtype is %s",subtype->name); - dynar->elmsize = subtype->size[GRAS_THISARCH]; - dynar->size = dynar->used; - dynar->mutex = NULL; + dynar->elmsize = subtype->size[GRAS_THISARCH]; + dynar->size = dynar->used; + dynar->mutex = NULL; } /** \brief Declare a new type being a dynar in which each elements are of the given type @@ -647,122 +647,122 @@ static void gras_datadesc_dynar_cb(gras_datadesc_type_t typedesc, gras_cbps_t va */ gras_datadesc_type_t gras_datadesc_dynar(gras_datadesc_type_t elm_t, - void_f_pvoid_t free_func) { + void_f_pvoid_t free_func) { - char *buffname; - gras_datadesc_type_t res; + char *buffname; + gras_datadesc_type_t res; - asprintf(&buffname,"s_xbt_dynar_of_%s",elm_t->name); + asprintf(&buffname,"s_xbt_dynar_of_%s",elm_t->name); - res = gras_datadesc_struct(buffname); + res = gras_datadesc_struct(buffname); - gras_datadesc_struct_append(res, "size", - gras_datadesc_by_name("unsigned long int")); + gras_datadesc_struct_append(res, "size", + gras_datadesc_by_name("unsigned long int")); - gras_datadesc_struct_append(res, "used", - gras_datadesc_by_name("unsigned long int")); + gras_datadesc_struct_append(res, "used", + gras_datadesc_by_name("unsigned long int")); - gras_datadesc_struct_append(res, "elmsize", - gras_datadesc_by_name("unsigned long int")); + gras_datadesc_struct_append(res, "elmsize", + gras_datadesc_by_name("unsigned long int")); - gras_datadesc_struct_append(res, "data", - gras_datadesc_ref_pop_arr (elm_t)); + gras_datadesc_struct_append(res, "data", + gras_datadesc_ref_pop_arr (elm_t)); - gras_datadesc_struct_append(res, "free_f", - gras_datadesc_by_name("function pointer")); - memcpy(res->extra,&free_func,sizeof(free_func)); + gras_datadesc_struct_append(res, "free_f", + gras_datadesc_by_name("function pointer")); + memcpy(res->extra,&free_func,sizeof(free_func)); - gras_datadesc_struct_append(res, "mutex", - gras_datadesc_by_name("data pointer")); + gras_datadesc_struct_append(res, "mutex", + gras_datadesc_by_name("data pointer")); - gras_datadesc_struct_close(res); + gras_datadesc_struct_close(res); - gras_datadesc_cb_field_push(res, "used"); - gras_datadesc_cb_recv(res, &gras_datadesc_dynar_cb); + gras_datadesc_cb_field_push(res, "used"); + gras_datadesc_cb_recv(res, &gras_datadesc_dynar_cb); - /* build a ref to it */ - free(buffname); - asprintf(&buffname,"xbt_dynar_of_%s",elm_t->name); - res=gras_datadesc_ref(buffname,res); - free(buffname); - return res; + /* build a ref to it */ + free(buffname); + asprintf(&buffname,"xbt_dynar_of_%s",elm_t->name); + res=gras_datadesc_ref(buffname,res); + free(buffname); + return res; } #include "xbt/matrix.h" static void gras_datadesc_matrix_cb(gras_datadesc_type_t typedesc, gras_cbps_t vars, void *data) { - gras_datadesc_type_t subtype; - xbt_matrix_t matrix=(xbt_matrix_t)data; + gras_datadesc_type_t subtype; + xbt_matrix_t matrix=(xbt_matrix_t)data; - memcpy(&matrix->free_f, &typedesc->extra, sizeof(matrix->free_f)); + memcpy(&matrix->free_f, &typedesc->extra, sizeof(matrix->free_f)); - /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */ - subtype = gras_dd_find_field(typedesc,"data")->type; + /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */ + subtype = gras_dd_find_field(typedesc,"data")->type; - /* this is now a ref to array of what we're looking for */ - subtype = subtype->category.ref_data.type; - subtype = subtype->category.array_data.type; + /* this is now a ref to array of what we're looking for */ + subtype = subtype->category.ref_data.type; + subtype = subtype->category.array_data.type; - DEBUG1("subtype is %s",subtype->name); + DEBUG1("subtype is %s",subtype->name); - matrix->elmsize = subtype->size[GRAS_THISARCH]; + matrix->elmsize = subtype->size[GRAS_THISARCH]; } gras_datadesc_type_t gras_datadesc_matrix(gras_datadesc_type_t elm_t, - void_f_pvoid_t const free_f) { - char *buffname; - gras_datadesc_type_t res; - - asprintf(&buffname,"s_xbt_matrix_t(%s)",elm_t->name); - res = gras_datadesc_struct(buffname); - - gras_datadesc_struct_append(res, "lines", - gras_datadesc_by_name("unsigned int")); - gras_datadesc_struct_append(res, "rows", - gras_datadesc_by_name("unsigned int")); - - gras_datadesc_struct_append(res, "elmsize", - gras_datadesc_by_name("unsigned long int")); - - gras_datadesc_struct_append(res, "data", - gras_datadesc_ref_pop_arr (elm_t)); - gras_datadesc_struct_append(res, "free_f", - gras_datadesc_by_name("function pointer")); - gras_datadesc_struct_close(res); - - gras_datadesc_cb_field_push(res, "lines"); - gras_datadesc_cb_field_push_multiplier(res, "rows"); - - gras_datadesc_cb_recv(res, &gras_datadesc_matrix_cb); - memcpy(res->extra,&free_f,sizeof(free_f)); - - /* build a ref to it */ - free(buffname); - asprintf(&buffname,"xbt_matrix_t(%s)",elm_t->name); - res=gras_datadesc_ref(buffname,res); - free(buffname); - return res; + void_f_pvoid_t const free_f) { + char *buffname; + gras_datadesc_type_t res; + + asprintf(&buffname,"s_xbt_matrix_t(%s)",elm_t->name); + res = gras_datadesc_struct(buffname); + + gras_datadesc_struct_append(res, "lines", + gras_datadesc_by_name("unsigned int")); + gras_datadesc_struct_append(res, "rows", + gras_datadesc_by_name("unsigned int")); + + gras_datadesc_struct_append(res, "elmsize", + gras_datadesc_by_name("unsigned long int")); + + gras_datadesc_struct_append(res, "data", + gras_datadesc_ref_pop_arr (elm_t)); + gras_datadesc_struct_append(res, "free_f", + gras_datadesc_by_name("function pointer")); + gras_datadesc_struct_close(res); + + gras_datadesc_cb_field_push(res, "lines"); + gras_datadesc_cb_field_push_multiplier(res, "rows"); + + gras_datadesc_cb_recv(res, &gras_datadesc_matrix_cb); + memcpy(res->extra,&free_f,sizeof(free_f)); + + /* build a ref to it */ + free(buffname); + asprintf(&buffname,"xbt_matrix_t(%s)",elm_t->name); + res=gras_datadesc_ref(buffname,res); + free(buffname); + return res; } gras_datadesc_type_t gras_datadesc_import_nws(const char *name, - const DataDescriptor *desc, - unsigned long howmany) { - THROW_UNIMPLEMENTED; + const DataDescriptor *desc, + unsigned long howmany) { + THROW_UNIMPLEMENTED; } /** * (useful to push the sizes of the upcoming arrays, for example) */ void gras_datadesc_cb_send (gras_datadesc_type_t type, - gras_datadesc_type_cb_void_t send) { - type->send = send; + gras_datadesc_type_cb_void_t send) { + type->send = send; } /** * (useful to put the function pointers to the rigth value, for example) */ void gras_datadesc_cb_recv(gras_datadesc_type_t type, - gras_datadesc_type_cb_void_t recv) { - type->recv = recv; + gras_datadesc_type_cb_void_t recv) { + type->recv = recv; } /* * gras_dd_find_field: @@ -770,28 +770,28 @@ void gras_datadesc_cb_recv(gras_datadesc_type_t type, * Returns the type descriptor of the given field. Abort on error. */ static gras_dd_cat_field_t - gras_dd_find_field(gras_datadesc_type_t type, - const char *field_name) { - xbt_dynar_t field_array; - - gras_dd_cat_field_t field=NULL; - unsigned int field_num; - - if (type->category_code == e_gras_datadesc_type_cat_union) { - field_array = type->category.union_data.fields; - } else if (type->category_code == e_gras_datadesc_type_cat_struct) { - field_array = type->category.struct_data.fields; - } else { - ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,(void*)type); - xbt_abort(); - } - xbt_dynar_foreach(field_array,field_num,field) { - if (!strcmp(field_name,field->name)) { - return field; - } - } - ERROR2("No field named '%s' in '%s'",field_name,type->name); - xbt_abort(); +gras_dd_find_field(gras_datadesc_type_t type, + const char *field_name) { + xbt_dynar_t field_array; + + gras_dd_cat_field_t field=NULL; + unsigned int field_num; + + if (type->category_code == e_gras_datadesc_type_cat_union) { + field_array = type->category.union_data.fields; + } else if (type->category_code == e_gras_datadesc_type_cat_struct) { + field_array = type->category.struct_data.fields; + } else { + ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,(void*)type); + xbt_abort(); + } + xbt_dynar_foreach(field_array,field_num,field) { + if (!strcmp(field_name,field->name)) { + return field; + } + } + ERROR2("No field named '%s' in '%s'",field_name,type->name); + xbt_abort(); } @@ -800,11 +800,11 @@ static gras_dd_cat_field_t * (useful to push the sizes of the upcoming arrays, for example) */ void gras_datadesc_cb_field_send (gras_datadesc_type_t type, - const char *field_name, - gras_datadesc_type_cb_void_t send) { + const char *field_name, + gras_datadesc_type_cb_void_t send) { - gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); - field->send = send; + gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); + field->send = send; } @@ -814,26 +814,26 @@ void gras_datadesc_cb_field_send (gras_datadesc_type_t type, * \ref gras_datadesc_ref_pop_arr or directly with \ref gras_cbps_i_pop. */ void gras_datadesc_cb_field_push (gras_datadesc_type_t type, - const char *field_name) { - - gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); - gras_datadesc_type_t sub_type=field->type; - - DEBUG3("add a PUSHy cb to '%s' field (type '%s') of '%s'", - field_name,sub_type->name,type->name); - if (!strcmp("int",sub_type->name)) { - field->send = gras_datadesc_cb_push_int; - } else if (!strcmp("unsigned int",sub_type->name)) { - field->send = gras_datadesc_cb_push_uint; - } else if (!strcmp("long int",sub_type->name)) { - field->send = gras_datadesc_cb_push_lint; - } else if (!strcmp("unsigned long int",sub_type->name)) { - field->send = gras_datadesc_cb_push_ulint; - } else { - ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int", - sub_type->name); - xbt_abort(); - } + const char *field_name) { + + gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); + gras_datadesc_type_t sub_type=field->type; + + DEBUG3("add a PUSHy cb to '%s' field (type '%s') of '%s'", + field_name,sub_type->name,type->name); + if (!strcmp("int",sub_type->name)) { + field->send = gras_datadesc_cb_push_int; + } else if (!strcmp("unsigned int",sub_type->name)) { + field->send = gras_datadesc_cb_push_uint; + } else if (!strcmp("long int",sub_type->name)) { + field->send = gras_datadesc_cb_push_lint; + } else if (!strcmp("unsigned long int",sub_type->name)) { + field->send = gras_datadesc_cb_push_ulint; + } else { + ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int", + sub_type->name); + xbt_abort(); + } } /** @@ -845,26 +845,26 @@ void gras_datadesc_cb_field_push (gras_datadesc_type_t type, * The field must be an int, unsigned int, long int or unsigned long int. */ void gras_datadesc_cb_field_push_multiplier (gras_datadesc_type_t type, - const char *field_name) { - - gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); - gras_datadesc_type_t sub_type=field->type; - - DEBUG3("add a MPUSHy cb to '%s' field (type '%s') of '%s'", - field_name,sub_type->name,type->name); - if (!strcmp("int",sub_type->name)) { - field->send = gras_datadesc_cb_push_int_mult; - } else if (!strcmp("unsigned int",sub_type->name)) { - field->send = gras_datadesc_cb_push_uint_mult; - } else if (!strcmp("long int",sub_type->name)) { - field->send = gras_datadesc_cb_push_lint_mult; - } else if (!strcmp("unsigned long int",sub_type->name)) { - field->send = gras_datadesc_cb_push_ulint_mult; - } else { - ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int", - sub_type->name); - xbt_abort(); - } + const char *field_name) { + + gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); + gras_datadesc_type_t sub_type=field->type; + + DEBUG3("add a MPUSHy cb to '%s' field (type '%s') of '%s'", + field_name,sub_type->name,type->name); + if (!strcmp("int",sub_type->name)) { + field->send = gras_datadesc_cb_push_int_mult; + } else if (!strcmp("unsigned int",sub_type->name)) { + field->send = gras_datadesc_cb_push_uint_mult; + } else if (!strcmp("long int",sub_type->name)) { + field->send = gras_datadesc_cb_push_lint_mult; + } else if (!strcmp("unsigned long int",sub_type->name)) { + field->send = gras_datadesc_cb_push_ulint_mult; + } else { + ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int", + sub_type->name); + xbt_abort(); + } } /** @@ -872,11 +872,11 @@ void gras_datadesc_cb_field_push_multiplier (gras_datadesc_type_t type, * (useful to put the function pointers to the right value, for example) */ void gras_datadesc_cb_field_recv(gras_datadesc_type_t type, - const char *field_name, - gras_datadesc_type_cb_void_t recv) { + const char *field_name, + gras_datadesc_type_cb_void_t recv) { - gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); - field->recv = recv; + gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); + field->recv = recv; } /* @@ -884,30 +884,30 @@ void gras_datadesc_cb_field_recv(gras_datadesc_type_t type, */ void gras_datadesc_free(gras_datadesc_type_t *type) { - DEBUG1("Let's free ddt %s",(*type)->name); - - switch ((*type)->category_code) { - case e_gras_datadesc_type_cat_scalar: - case e_gras_datadesc_type_cat_ref: - case e_gras_datadesc_type_cat_array: - /* nothing to free in there */ - break; - - case e_gras_datadesc_type_cat_struct: - xbt_dynar_free(&( (*type)->category.struct_data.fields )); - break; - - case e_gras_datadesc_type_cat_union: - xbt_dynar_free(&( (*type)->category.union_data.fields )); - break; - - default: - /* datadesc was invalid. Killing it is like euthanasy, I guess */ - break; - } - free((*type)->name); - free(*type); - type=NULL; + DEBUG1("Let's free ddt %s",(*type)->name); + + switch ((*type)->category_code) { + case e_gras_datadesc_type_cat_scalar: + case e_gras_datadesc_type_cat_ref: + case e_gras_datadesc_type_cat_array: + /* nothing to free in there */ + break; + + case e_gras_datadesc_type_cat_struct: + xbt_dynar_free(&( (*type)->category.struct_data.fields )); + break; + + case e_gras_datadesc_type_cat_union: + xbt_dynar_free(&( (*type)->category.union_data.fields )); + break; + + default: + /* datadesc was invalid. Killing it is like euthanasy, I guess */ + break; + } + free((*type)->name); + free(*type); + type=NULL; } /** @@ -919,149 +919,149 @@ void gras_datadesc_free(gras_datadesc_type_t *type) { * but only the payload (actual type description). */ int gras_datadesc_type_cmp(const gras_datadesc_type_t d1, - const gras_datadesc_type_t d2) { - int ret; - unsigned int cpt; - gras_dd_cat_field_t field1,field2; - gras_datadesc_type_t field_desc_1,field_desc_2; - - if (d1 == d2) return 0; /* easy optimization */ - - if (!d1 && d2) { - DEBUG0("ddt_cmp: !d1 && d2 => 1"); - return 1; - } - if (!d1 && !d2) { - DEBUG0("ddt_cmp: !d1 && !d2 => 0"); - return 0; - } - if ( d1 && !d2) { - DEBUG0("ddt_cmp: d1 && !d2 => -1"); - return -1; - } - - for (cpt=0; cptsize[cpt] != d2->size[cpt]) { - DEBUG5("ddt_cmp: %s->size=%ld != %s->size=%ld (on %s)", - d1->name,d1->size[cpt],d2->name,d2->size[cpt], - gras_arches[cpt].name); - return d1->size[cpt] > d2->size[cpt] ? 1 : -1; - } - - if (d1->alignment[cpt] != d2->alignment[cpt]) { - DEBUG5("ddt_cmp: %s->alignment=%ld != %s->alignment=%ld (on %s)", - d1->name,d1->alignment[cpt],d2->name,d2->alignment[cpt], - gras_arches[cpt].name); - return d1->alignment[cpt] > d2->alignment[cpt] ? 1 : -1; - } - - if (d1->aligned_size[cpt] != d2->aligned_size[cpt]) { - DEBUG5("ddt_cmp: %s->aligned_size=%ld != %s->aligned_size=%ld (on %s)", - d1->name,d1->aligned_size[cpt],d2->name,d2->aligned_size[cpt], - gras_arches[cpt].name); - return d1->aligned_size[cpt] > d2->aligned_size[cpt] ? 1 : -1; - } - } - - if (d1->category_code != d2->category_code) { - DEBUG4("ddt_cmp: %s->cat=%s != %s->cat=%s", - d1->name,gras_datadesc_cat_names[d1->category_code], - d2->name,gras_datadesc_cat_names[d2->category_code]); - return d1->category_code > d2->category_code ? 1 : -1; - } - - if (d1->send != d2->send) { - DEBUG4("ddt_cmp: %s->send=%p != %s->send=%p", - d1->name,(void*)d1->send, d2->name,(void*)d2->send); - return 1; /* ISO C forbids ordered comparisons of pointers to functions */ - } - - if (d1->recv != d2->recv) { - DEBUG4("ddt_cmp: %s->recv=%p != %s->recv=%p", - d1->name,(void*)d1->recv, d2->name,(void*)d2->recv); - return 1; /* ISO C forbids ordered comparisons of pointers to functions */ - } - - switch (d1->category_code) { - case e_gras_datadesc_type_cat_scalar: - if (d1->category.scalar_data.encoding != d2->category.scalar_data.encoding) - return d1->category.scalar_data.encoding > d2->category.scalar_data.encoding ? 1 : -1 ; - break; - - case e_gras_datadesc_type_cat_struct: - if (xbt_dynar_length(d1->category.struct_data.fields) != - xbt_dynar_length(d2->category.struct_data.fields)) { - DEBUG4("ddt_cmp: %s (having %lu fields) != %s (having %lu fields)", - d1->name, xbt_dynar_length(d1->category.struct_data.fields), - d2->name, xbt_dynar_length(d2->category.struct_data.fields)); - - return xbt_dynar_length(d1->category.struct_data.fields) > - xbt_dynar_length(d2->category.struct_data.fields) ? - 1 : -1; - } - xbt_dynar_foreach(d1->category.struct_data.fields, cpt, field1) { - - field2 = xbt_dynar_get_as(d2->category.struct_data.fields, cpt, gras_dd_cat_field_t); - field_desc_1 = field1->type; - field_desc_2 = field2->type; - ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2); - if (ret) { - DEBUG6("%s->field[%d]=%s != %s->field[%d]=%s", - d1->name,cpt,field1->name, - d2->name,cpt,field2->name); - return ret; - } - - } - break; - - case e_gras_datadesc_type_cat_union: - if (d1->category.union_data.selector != d2->category.union_data.selector) - return 1; /* ISO C forbids ordered comparisons of pointers to functions */ - - if (xbt_dynar_length(d1->category.union_data.fields) != - xbt_dynar_length(d2->category.union_data.fields)) - return xbt_dynar_length(d1->category.union_data.fields) > - xbt_dynar_length(d2->category.union_data.fields) ? - 1 : -1; - - xbt_dynar_foreach(d1->category.union_data.fields, cpt, field1) { - - field2 = xbt_dynar_get_as(d2->category.union_data.fields, cpt, gras_dd_cat_field_t); - field_desc_1 = field1->type; - field_desc_2 = field2->type; - ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2); - if (ret) - return ret; - - } - break; - - - case e_gras_datadesc_type_cat_ref: - if (d1->category.ref_data.selector != d2->category.ref_data.selector) - return 1; /* ISO C forbids ordered comparisons of pointers to functions */ - - if (d1->category.ref_data.type != d2->category.ref_data.type) - return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1; - break; - - case e_gras_datadesc_type_cat_array: - if (d1->category.array_data.type != d2->category.array_data.type) - return d1->category.array_data.type > d2->category.array_data.type ? 1 : -1; - - if (d1->category.array_data.fixed_size != d2->category.array_data.fixed_size) - return d1->category.array_data.fixed_size > d2->category.array_data.fixed_size ? 1 : -1; - - if (d1->category.array_data.dynamic_size != d2->category.array_data.dynamic_size) - return 1; /* ISO C forbids ordered comparisons of pointers to functions */ - - break; - - default: - /* two stupidly created ddt are equally stupid ;) */ - break; - } - return 0; + const gras_datadesc_type_t d2) { + int ret; + unsigned int cpt; + gras_dd_cat_field_t field1,field2; + gras_datadesc_type_t field_desc_1,field_desc_2; + + if (d1 == d2) return 0; /* easy optimization */ + + if (!d1 && d2) { + DEBUG0("ddt_cmp: !d1 && d2 => 1"); + return 1; + } + if (!d1 && !d2) { + DEBUG0("ddt_cmp: !d1 && !d2 => 0"); + return 0; + } + if ( d1 && !d2) { + DEBUG0("ddt_cmp: d1 && !d2 => -1"); + return -1; + } + + for (cpt=0; cptsize[cpt] != d2->size[cpt]) { + DEBUG5("ddt_cmp: %s->size=%ld != %s->size=%ld (on %s)", + d1->name,d1->size[cpt],d2->name,d2->size[cpt], + gras_arches[cpt].name); + return d1->size[cpt] > d2->size[cpt] ? 1 : -1; + } + + if (d1->alignment[cpt] != d2->alignment[cpt]) { + DEBUG5("ddt_cmp: %s->alignment=%ld != %s->alignment=%ld (on %s)", + d1->name,d1->alignment[cpt],d2->name,d2->alignment[cpt], + gras_arches[cpt].name); + return d1->alignment[cpt] > d2->alignment[cpt] ? 1 : -1; + } + + if (d1->aligned_size[cpt] != d2->aligned_size[cpt]) { + DEBUG5("ddt_cmp: %s->aligned_size=%ld != %s->aligned_size=%ld (on %s)", + d1->name,d1->aligned_size[cpt],d2->name,d2->aligned_size[cpt], + gras_arches[cpt].name); + return d1->aligned_size[cpt] > d2->aligned_size[cpt] ? 1 : -1; + } + } + + if (d1->category_code != d2->category_code) { + DEBUG4("ddt_cmp: %s->cat=%s != %s->cat=%s", + d1->name,gras_datadesc_cat_names[d1->category_code], + d2->name,gras_datadesc_cat_names[d2->category_code]); + return d1->category_code > d2->category_code ? 1 : -1; + } + + if (d1->send != d2->send) { + DEBUG4("ddt_cmp: %s->send=%p != %s->send=%p", + d1->name,(void*)d1->send, d2->name,(void*)d2->send); + return 1; /* ISO C forbids ordered comparisons of pointers to functions */ + } + + if (d1->recv != d2->recv) { + DEBUG4("ddt_cmp: %s->recv=%p != %s->recv=%p", + d1->name,(void*)d1->recv, d2->name,(void*)d2->recv); + return 1; /* ISO C forbids ordered comparisons of pointers to functions */ + } + + switch (d1->category_code) { + case e_gras_datadesc_type_cat_scalar: + if (d1->category.scalar_data.encoding != d2->category.scalar_data.encoding) + return d1->category.scalar_data.encoding > d2->category.scalar_data.encoding ? 1 : -1 ; + break; + + case e_gras_datadesc_type_cat_struct: + if (xbt_dynar_length(d1->category.struct_data.fields) != + xbt_dynar_length(d2->category.struct_data.fields)) { + DEBUG4("ddt_cmp: %s (having %lu fields) != %s (having %lu fields)", + d1->name, xbt_dynar_length(d1->category.struct_data.fields), + d2->name, xbt_dynar_length(d2->category.struct_data.fields)); + + return xbt_dynar_length(d1->category.struct_data.fields) > + xbt_dynar_length(d2->category.struct_data.fields) ? + 1 : -1; + } + xbt_dynar_foreach(d1->category.struct_data.fields, cpt, field1) { + + field2 = xbt_dynar_get_as(d2->category.struct_data.fields, cpt, gras_dd_cat_field_t); + field_desc_1 = field1->type; + field_desc_2 = field2->type; + ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2); + if (ret) { + DEBUG6("%s->field[%d]=%s != %s->field[%d]=%s", + d1->name,cpt,field1->name, + d2->name,cpt,field2->name); + return ret; + } + + } + break; + + case e_gras_datadesc_type_cat_union: + if (d1->category.union_data.selector != d2->category.union_data.selector) + return 1; /* ISO C forbids ordered comparisons of pointers to functions */ + + if (xbt_dynar_length(d1->category.union_data.fields) != + xbt_dynar_length(d2->category.union_data.fields)) + return xbt_dynar_length(d1->category.union_data.fields) > + xbt_dynar_length(d2->category.union_data.fields) ? + 1 : -1; + + xbt_dynar_foreach(d1->category.union_data.fields, cpt, field1) { + + field2 = xbt_dynar_get_as(d2->category.union_data.fields, cpt, gras_dd_cat_field_t); + field_desc_1 = field1->type; + field_desc_2 = field2->type; + ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2); + if (ret) + return ret; + + } + break; + + + case e_gras_datadesc_type_cat_ref: + if (d1->category.ref_data.selector != d2->category.ref_data.selector) + return 1; /* ISO C forbids ordered comparisons of pointers to functions */ + + if (d1->category.ref_data.type != d2->category.ref_data.type) + return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1; + break; + + case e_gras_datadesc_type_cat_array: + if (d1->category.array_data.type != d2->category.array_data.type) + return d1->category.array_data.type > d2->category.array_data.type ? 1 : -1; + + if (d1->category.array_data.fixed_size != d2->category.array_data.fixed_size) + return d1->category.array_data.fixed_size > d2->category.array_data.fixed_size ? 1 : -1; + + if (d1->category.array_data.dynamic_size != d2->category.array_data.dynamic_size) + return 1; /* ISO C forbids ordered comparisons of pointers to functions */ + + break; + + default: + /* two stupidly created ddt are equally stupid ;) */ + break; + } + return 0; } diff --git a/src/gras/DataDesc/ddt_exchange.c b/src/gras/DataDesc/ddt_exchange.c index afabc4ce60..8c597ecabb 100644 --- a/src/gras/DataDesc/ddt_exchange.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -14,382 +14,382 @@ #include "gras/Transport/transport_interface.h" /* gras_trp_send/recv */ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_exchange,gras_ddt, - "Sending data over the network"); -const char *gras_datadesc_cat_names[9] = { - "undefined", - "scalar", "struct", "union", "ref", "array", "ignored", - "invalid"}; + "Sending data over the network"); +const char *gras_datadesc_cat_names[9] = { + "undefined", + "scalar", "struct", "union", "ref", "array", "ignored", + "invalid"}; static gras_datadesc_type_t uint_type = NULL; -static gras_datadesc_type_t pointer_type = NULL; +static gras_datadesc_type_t pointer_type = NULL; static XBT_INLINE void gras_dd_send_uint(gras_socket_t sock,unsigned int *i, int stable) { - if (!uint_type) { - uint_type = gras_datadesc_by_name("unsigned int"); - xbt_assert(uint_type); - } - - DEBUG1("send_uint(%u)",*i); - gras_trp_send(sock, (char*)i, uint_type->size[GRAS_THISARCH], stable); + if (!uint_type) { + uint_type = gras_datadesc_by_name("unsigned int"); + xbt_assert(uint_type); + } + + DEBUG1("send_uint(%u)",*i); + gras_trp_send(sock, (char*)i, uint_type->size[GRAS_THISARCH], stable); } static XBT_INLINE void gras_dd_recv_uint(gras_socket_t sock, int r_arch, unsigned int *i) { - if (!uint_type) { - uint_type = gras_datadesc_by_name("unsigned int"); - xbt_assert(uint_type); - } - - if (uint_type->size[GRAS_THISARCH] >= uint_type->size[r_arch]) { - gras_trp_recv(sock, (char*)i, uint_type->size[r_arch]); - if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(uint_type,1,r_arch, i,i); - } else { - void *ptr = xbt_malloc(uint_type->size[r_arch]); - - gras_trp_recv(sock, (char*)ptr, uint_type->size[r_arch]); - if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(uint_type,1,r_arch, ptr,i); - free(ptr); - } - DEBUG1("recv_uint(%u)",*i); + if (!uint_type) { + uint_type = gras_datadesc_by_name("unsigned int"); + xbt_assert(uint_type); + } + + if (uint_type->size[GRAS_THISARCH] >= uint_type->size[r_arch]) { + gras_trp_recv(sock, (char*)i, uint_type->size[r_arch]); + if (r_arch != GRAS_THISARCH) + gras_dd_convert_elm(uint_type,1,r_arch, i,i); + } else { + void *ptr = xbt_malloc(uint_type->size[r_arch]); + + gras_trp_recv(sock, (char*)ptr, uint_type->size[r_arch]); + if (r_arch != GRAS_THISARCH) + gras_dd_convert_elm(uint_type,1,r_arch, ptr,i); + free(ptr); + } + DEBUG1("recv_uint(%u)",*i); } /* - * Note: here we suppose that the remote NULL is a sequence + * Note: here we suppose that the remote NULL is a sequence * of 'length' bytes set to 0. * FIXME: Check in configure? */ -static XBT_INLINE int +static XBT_INLINE int gras_dd_is_r_null(char **r_ptr, long int length) { - int i; + int i; - for (i=0; isize[r_arch] */ - char **l_ref, - int detect_cycle) { - char *l_data = NULL; - - xbt_assert1(size>0,"Cannot allocate %ld bytes!", size); - l_data = xbt_malloc((size_t)size); - - *l_ref = l_data; - DEBUG5("alloc_ref: l_data=%p, &l_data=%p; r_ref=%p; *r_ref=%p, r_len=%ld", - (void*)l_data,(void*)&l_data, - (void*)r_ref, (void*)(r_ref?*r_ref:NULL), r_len); - if (detect_cycle && r_ref && !gras_dd_is_r_null( r_ref, r_len)) { - void *ptr = xbt_malloc(sizeof(void *)); - - memcpy(ptr,l_ref, sizeof(void *)); - - DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref); - - if (detect_cycle) - xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, xbt_free_f); - } + long int size, + char **r_ref, + long int r_len, /* pointer_type->size[r_arch] */ + char **l_ref, + int detect_cycle) { + char *l_data = NULL; + + xbt_assert1(size>0,"Cannot allocate %ld bytes!", size); + l_data = xbt_malloc((size_t)size); + + *l_ref = l_data; + DEBUG5("alloc_ref: l_data=%p, &l_data=%p; r_ref=%p; *r_ref=%p, r_len=%ld", + (void*)l_data,(void*)&l_data, + (void*)r_ref, (void*)(r_ref?*r_ref:NULL), r_len); + if (detect_cycle && r_ref && !gras_dd_is_r_null( r_ref, r_len)) { + void *ptr = xbt_malloc(sizeof(void *)); + + memcpy(ptr,l_ref, sizeof(void *)); + + DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref); + + if (detect_cycle) + xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, xbt_free_f); + } } static int gras_datadesc_memcpy_rec(gras_cbps_t state, - xbt_dict_t refs, - gras_datadesc_type_t type, - char *src, - char *dst, - int subsize, - int detect_cycle) { - - - xbt_ex_t e; - unsigned int cpt; - gras_datadesc_type_t sub_type; /* type on which we recurse */ - int count = 0; - - VERB5("Copy a %s (%s) from %p to %p (local sizeof=%ld)", - type->name, gras_datadesc_cat_names[type->category_code], - src,dst,type->size[GRAS_THISARCH]); - - if (type->send) { - type->send(type,state,src); - } - - switch (type->category_code) { - case e_gras_datadesc_type_cat_scalar: - memcpy(dst,src,type->size[GRAS_THISARCH]); - count += type->size[GRAS_THISARCH]; - break; - - case e_gras_datadesc_type_cat_struct: { - gras_dd_cat_struct_t struct_data; - gras_dd_cat_field_t field; - char *field_src; - char *field_dst; - - struct_data = type->category.struct_data; - xbt_assert1(struct_data.closed, - "Please call gras_datadesc_declare_struct_close on %s before copying it", - type->name); - VERB1(">> Copy all fields of the structure %s",type->name); - xbt_dynar_foreach(struct_data.fields, cpt, field) { - field_src = src + field->offset[GRAS_THISARCH]; - field_dst = dst + field->offset[GRAS_THISARCH]; - - sub_type = field->type; - - if (field->send) - field->send(type,state,field_src); - - DEBUG1("Copy field %s",field->name); - count += gras_datadesc_memcpy_rec(state,refs,sub_type, field_src, field_dst, 0, - detect_cycle || sub_type->cycle); - - if (XBT_LOG_ISENABLED(gras_ddt_exchange,xbt_log_priority_verbose)) { - if (sub_type == gras_datadesc_by_name("unsigned int")) { - VERB2("Copied value for field '%s': %d (type: unsigned int)",field->name, *(unsigned int*)field_dst); - } else if (sub_type == gras_datadesc_by_name("int")) { - VERB2("Copied value for field '%s': %d (type: int)",field->name, *(int*)field_dst); - - } else if (sub_type == gras_datadesc_by_name("unsigned long int")) { - VERB2("Copied value for field '%s': %ld (type: unsigned long int)",field->name, *(unsigned long int*)field_dst); - } else if (sub_type == gras_datadesc_by_name("long int")) { - VERB2("Copied value for field '%s': %ld (type: long int)",field->name, *(long int*)field_dst); - - } else if (sub_type == gras_datadesc_by_name("string")) { - VERB2("Copied value for field '%s': '%s' (type: string)", field->name, *(char**)field_dst); - } else { - VERB1("Copied a value for field '%s' (type not scalar?)", field->name); - } - } - - } - VERB1("<< Copied all fields of the structure %s", type->name); - - break; - } - - case e_gras_datadesc_type_cat_union: { - gras_dd_cat_union_t union_data; - gras_dd_cat_field_t field=NULL; - unsigned int field_num; - - union_data = type->category.union_data; - - xbt_assert1(union_data.closed, - "Please call gras_datadesc_declare_union_close on %s before copying it", - type->name); - /* retrieve the field number */ - field_num = union_data.selector(type, state, src); - - xbt_assert1(field_num > 0, - "union field selector of %s gave a negative value", - type->name); - - xbt_assert3(field_num < xbt_dynar_length(union_data.fields), - "union field selector of %s returned %d but there is only %lu fields", - type->name, field_num, xbt_dynar_length(union_data.fields)); - - /* Copy the content */ - field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); - sub_type = field->type; - - if (field->send) - field->send(type,state,src); - - count += gras_datadesc_memcpy_rec(state,refs, sub_type, src, dst,0, - detect_cycle || sub_type->cycle); - - break; - } - - case e_gras_datadesc_type_cat_ref: { - gras_dd_cat_ref_t ref_data; - char **o_ref=NULL; - char **n_ref=NULL; - int reference_is_to_cpy; - - ref_data = type->category.ref_data; - - /* Detect the referenced type */ - sub_type = ref_data.type; - if (sub_type == NULL) { - sub_type = (*ref_data.selector)(type,state,src); - } - - /* Send the pointed data only if not already sent */ - if (*(void**)src == NULL) { - VERB0("Not copying NULL referenced data"); - *(void**)dst = NULL; - break; - } - o_ref=(char**)src; - - reference_is_to_cpy = 0; - TRY { - if (detect_cycle) { - /* return ignored. Just checking whether it's known or not */ - n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*)); - } else { - reference_is_to_cpy = 1; - } - } CATCH(e) { - if (e.category != not_found_error) - RETHROW; - reference_is_to_cpy = 1; - xbt_ex_free(e); - } - - if (reference_is_to_cpy) { - int subsubcount = 0; - void *l_referenced=NULL; - VERB2("Copy a ref to '%s' referenced at %p",sub_type->name, (void*)*o_ref); - - if (!pointer_type) { - pointer_type = gras_datadesc_by_name("data pointer"); - xbt_assert(pointer_type); - } - - if (sub_type->category_code == e_gras_datadesc_type_cat_array) { - /* Damn. Reference to a dynamic array. Allocating the space for it + xbt_dict_t refs, + gras_datadesc_type_t type, + char *src, + char *dst, + int subsize, + int detect_cycle) { + + + xbt_ex_t e; + unsigned int cpt; + gras_datadesc_type_t sub_type; /* type on which we recurse */ + int count = 0; + + VERB5("Copy a %s (%s) from %p to %p (local sizeof=%ld)", + type->name, gras_datadesc_cat_names[type->category_code], + src,dst,type->size[GRAS_THISARCH]); + + if (type->send) { + type->send(type,state,src); + } + + switch (type->category_code) { + case e_gras_datadesc_type_cat_scalar: + memcpy(dst,src,type->size[GRAS_THISARCH]); + count += type->size[GRAS_THISARCH]; + break; + + case e_gras_datadesc_type_cat_struct: { + gras_dd_cat_struct_t struct_data; + gras_dd_cat_field_t field; + char *field_src; + char *field_dst; + + struct_data = type->category.struct_data; + xbt_assert1(struct_data.closed, + "Please call gras_datadesc_declare_struct_close on %s before copying it", + type->name); + VERB1(">> Copy all fields of the structure %s",type->name); + xbt_dynar_foreach(struct_data.fields, cpt, field) { + field_src = src + field->offset[GRAS_THISARCH]; + field_dst = dst + field->offset[GRAS_THISARCH]; + + sub_type = field->type; + + if (field->send) + field->send(type,state,field_src); + + DEBUG1("Copy field %s",field->name); + count += gras_datadesc_memcpy_rec(state,refs,sub_type, field_src, field_dst, 0, + detect_cycle || sub_type->cycle); + + if (XBT_LOG_ISENABLED(gras_ddt_exchange,xbt_log_priority_verbose)) { + if (sub_type == gras_datadesc_by_name("unsigned int")) { + VERB2("Copied value for field '%s': %d (type: unsigned int)",field->name, *(unsigned int*)field_dst); + } else if (sub_type == gras_datadesc_by_name("int")) { + VERB2("Copied value for field '%s': %d (type: int)",field->name, *(int*)field_dst); + + } else if (sub_type == gras_datadesc_by_name("unsigned long int")) { + VERB2("Copied value for field '%s': %ld (type: unsigned long int)",field->name, *(unsigned long int*)field_dst); + } else if (sub_type == gras_datadesc_by_name("long int")) { + VERB2("Copied value for field '%s': %ld (type: long int)",field->name, *(long int*)field_dst); + + } else if (sub_type == gras_datadesc_by_name("string")) { + VERB2("Copied value for field '%s': '%s' (type: string)", field->name, *(char**)field_dst); + } else { + VERB1("Copied a value for field '%s' (type not scalar?)", field->name); + } + } + + } + VERB1("<< Copied all fields of the structure %s", type->name); + + break; + } + + case e_gras_datadesc_type_cat_union: { + gras_dd_cat_union_t union_data; + gras_dd_cat_field_t field=NULL; + unsigned int field_num; + + union_data = type->category.union_data; + + xbt_assert1(union_data.closed, + "Please call gras_datadesc_declare_union_close on %s before copying it", + type->name); + /* retrieve the field number */ + field_num = union_data.selector(type, state, src); + + xbt_assert1(field_num > 0, + "union field selector of %s gave a negative value", + type->name); + + xbt_assert3(field_num < xbt_dynar_length(union_data.fields), + "union field selector of %s returned %d but there is only %lu fields", + type->name, field_num, xbt_dynar_length(union_data.fields)); + + /* Copy the content */ + field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); + sub_type = field->type; + + if (field->send) + field->send(type,state,src); + + count += gras_datadesc_memcpy_rec(state,refs, sub_type, src, dst,0, + detect_cycle || sub_type->cycle); + + break; + } + + case e_gras_datadesc_type_cat_ref: { + gras_dd_cat_ref_t ref_data; + char **o_ref=NULL; + char **n_ref=NULL; + int reference_is_to_cpy; + + ref_data = type->category.ref_data; + + /* Detect the referenced type */ + sub_type = ref_data.type; + if (sub_type == NULL) { + sub_type = (*ref_data.selector)(type,state,src); + } + + /* Send the pointed data only if not already sent */ + if (*(void**)src == NULL) { + VERB0("Not copying NULL referenced data"); + *(void**)dst = NULL; + break; + } + o_ref=(char**)src; + + reference_is_to_cpy = 0; + TRY { + if (detect_cycle) { + /* return ignored. Just checking whether it's known or not */ + n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*)); + } else { + reference_is_to_cpy = 1; + } + } CATCH(e) { + if (e.category != not_found_error) + RETHROW; + reference_is_to_cpy = 1; + xbt_ex_free(e); + } + + if (reference_is_to_cpy) { + int subsubcount = 0; + void *l_referenced=NULL; + VERB2("Copy a ref to '%s' referenced at %p",sub_type->name, (void*)*o_ref); + + if (!pointer_type) { + pointer_type = gras_datadesc_by_name("data pointer"); + xbt_assert(pointer_type); + } + + if (sub_type->category_code == e_gras_datadesc_type_cat_array) { + /* Damn. Reference to a dynamic array. Allocating the space for it is more complicated */ - gras_dd_cat_array_t array_data = sub_type->category.array_data; - gras_datadesc_type_t subsub_type; - - subsub_type = array_data.type; - subsubcount = array_data.fixed_size; - if (subsubcount == 0) - subsubcount = array_data.dynamic_size(subsub_type,state,*o_ref); - - gras_dd_alloc_ref(refs, - subsub_type->size[GRAS_THISARCH] * subsubcount, - o_ref,pointer_type->size[GRAS_THISARCH], - (char**)&l_referenced, - detect_cycle); - } else { - gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH], - o_ref,pointer_type->size[GRAS_THISARCH], - (char**)&l_referenced, - detect_cycle); - } - - count += gras_datadesc_memcpy_rec(state,refs, sub_type, - *o_ref,(char*)l_referenced, subsubcount, - detect_cycle || sub_type->cycle); - - *(void**)dst=l_referenced; - VERB3("'%s' previously referenced at %p now at %p", - sub_type->name, *(void**)o_ref, l_referenced); - - } else { - VERB2("NOT copying data previously referenced @%p (already done, @%p now)", - *(void**)o_ref, *(void**)n_ref); - - *(void**)dst=*n_ref; - - } - break; - } - - case e_gras_datadesc_type_cat_array: { - gras_dd_cat_array_t array_data; - unsigned long int array_count; - char *src_ptr=src; - char *dst_ptr=dst; - long int elm_size; - - array_data = type->category.array_data; - - /* determine and send the element count */ - array_count = array_data.fixed_size; - if (array_count == 0) - array_count = subsize; - if (array_count == 0) { - array_count = array_data.dynamic_size(type,state,src); - xbt_assert1(array_count >=0, - "Invalid (negative) array size for type %s",type->name); - } - - /* send the content */ - sub_type = array_data.type; - elm_size = sub_type->aligned_size[GRAS_THISARCH]; - if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) { - VERB1("Array of %ld scalars, copy it in one shot",array_count); - memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * array_count); - count += sub_type->aligned_size[GRAS_THISARCH] * array_count; - } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && - sub_type->category.array_data.fixed_size > 0 && - sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { - - VERB1("Array of %ld fixed array of scalars, copy it in one shot", - array_count); - memcpy(dst,src,sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] - * array_count * sub_type->category.array_data.fixed_size); - count += sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] - * array_count * sub_type->category.array_data.fixed_size; - - } else { - VERB1("Array of %ld stuff, copy it in one after the other",array_count); - for (cpt=0; cptcategory.array_data; + gras_datadesc_type_t subsub_type; + + subsub_type = array_data.type; + subsubcount = array_data.fixed_size; + if (subsubcount == 0) + subsubcount = array_data.dynamic_size(subsub_type,state,*o_ref); + + gras_dd_alloc_ref(refs, + subsub_type->size[GRAS_THISARCH] * subsubcount, + o_ref,pointer_type->size[GRAS_THISARCH], + (char**)&l_referenced, + detect_cycle); + } else { + gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH], + o_ref,pointer_type->size[GRAS_THISARCH], + (char**)&l_referenced, + detect_cycle); + } + + count += gras_datadesc_memcpy_rec(state,refs, sub_type, + *o_ref,(char*)l_referenced, subsubcount, detect_cycle || sub_type->cycle); - src_ptr += elm_size; - dst_ptr += elm_size; - } - } - break; - } - - default: - xbt_assert0(0, "Invalid type"); - } - - return count; + + *(void**)dst=l_referenced; + VERB3("'%s' previously referenced at %p now at %p", + sub_type->name, *(void**)o_ref, l_referenced); + + } else { + VERB2("NOT copying data previously referenced @%p (already done, @%p now)", + *(void**)o_ref, *(void**)n_ref); + + *(void**)dst=*n_ref; + + } + break; + } + + case e_gras_datadesc_type_cat_array: { + gras_dd_cat_array_t array_data; + unsigned long int array_count; + char *src_ptr=src; + char *dst_ptr=dst; + long int elm_size; + + array_data = type->category.array_data; + + /* determine and send the element count */ + array_count = array_data.fixed_size; + if (array_count == 0) + array_count = subsize; + if (array_count == 0) { + array_count = array_data.dynamic_size(type,state,src); + xbt_assert1(array_count >=0, + "Invalid (negative) array size for type %s",type->name); + } + + /* send the content */ + sub_type = array_data.type; + elm_size = sub_type->aligned_size[GRAS_THISARCH]; + if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) { + VERB1("Array of %ld scalars, copy it in one shot",array_count); + memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * array_count); + count += sub_type->aligned_size[GRAS_THISARCH] * array_count; + } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && + sub_type->category.array_data.fixed_size > 0 && + sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { + + VERB1("Array of %ld fixed array of scalars, copy it in one shot", + array_count); + memcpy(dst,src,sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] + * array_count * sub_type->category.array_data.fixed_size); + count += sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] + * array_count * sub_type->category.array_data.fixed_size; + + } else { + VERB1("Array of %ld stuff, copy it in one after the other",array_count); + for (cpt=0; cptcycle); + src_ptr += elm_size; + dst_ptr += elm_size; + } + } + break; + } + + default: + xbt_assert0(0, "Invalid type"); + } + + return count; } /** * gras_datadesc_memcpy: * - * Copy the data pointed by src and described by type + * Copy the data pointed by src and described by type * to a new location, and store a pointer to it in dst. * */ -int gras_datadesc_memcpy(gras_datadesc_type_t type, - void *src, void *dst) { - xbt_ex_t e; - static gras_cbps_t state=NULL; - static xbt_dict_t refs=NULL; /* all references already sent */ - int size=0; - - xbt_assert0(type,"called with NULL type descriptor"); - - if (!state) { - state = gras_cbps_new(); - refs = xbt_dict_new(); - } - - TRY { - size = gras_datadesc_memcpy_rec(state,refs,type,(char*)src,(char*)dst,0, - type->cycle); - } CLEANUP { - xbt_dict_reset(refs); - gras_cbps_reset(state); - } CATCH(e) { - RETHROW; - } - return size; +int gras_datadesc_memcpy(gras_datadesc_type_t type, + void *src, void *dst) { + xbt_ex_t e; + static gras_cbps_t state=NULL; + static xbt_dict_t refs=NULL; /* all references already sent */ + int size=0; + + xbt_assert0(type,"called with NULL type descriptor"); + + if (!state) { + state = gras_cbps_new(); + refs = xbt_dict_new(); + } + + TRY { + size = gras_datadesc_memcpy_rec(state,refs,type,(char*)src,(char*)dst,0, + type->cycle); + } CLEANUP { + xbt_dict_reset(refs); + gras_cbps_reset(state); + } CATCH(e) { + RETHROW; + } + return size; } /*** @@ -398,205 +398,205 @@ int gras_datadesc_memcpy(gras_datadesc_type_t type, static void gras_datadesc_send_rec(gras_socket_t sock, - gras_cbps_t state, - xbt_dict_t refs, - gras_datadesc_type_t type, - char *data, - int detect_cycle) { - - xbt_ex_t e; - unsigned int cpt; - gras_datadesc_type_t sub_type; /* type on which we recurse */ - - VERB2("Send a %s (%s)", - type->name, gras_datadesc_cat_names[type->category_code]); - - if (!strcmp(type->name,"string")) - VERB1("value: '%s'",*(char**)data); - - if (type->send) { - type->send(type,state,data); - DEBUG0("Run the emission callback"); - } - - switch (type->category_code) { - case e_gras_datadesc_type_cat_scalar: - gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1); - break; - - case e_gras_datadesc_type_cat_struct: { - gras_dd_cat_struct_t struct_data; - gras_dd_cat_field_t field; - char *field_data; - - struct_data = type->category.struct_data; - xbt_assert1(struct_data.closed, - "Please call gras_datadesc_declare_struct_close on %s before sending it", - type->name); - VERB1(">> Send all fields of the structure %s",type->name); - xbt_dynar_foreach(struct_data.fields, cpt, field) { - field_data = data; - field_data += field->offset[GRAS_THISARCH]; - - sub_type = field->type; - - if (field->send) { - DEBUG1("Run the emission callback of field %s", field->name); - field->send(type,state,field_data); - } - - VERB1("Send field %s",field->name); - gras_datadesc_send_rec(sock,state,refs,sub_type, field_data, - detect_cycle || sub_type->cycle); - - } - VERB1("<< Sent all fields of the structure %s", type->name); - - break; - } - - case e_gras_datadesc_type_cat_union: { - gras_dd_cat_union_t union_data; - gras_dd_cat_field_t field=NULL; - unsigned int field_num; - - union_data = type->category.union_data; - - xbt_assert1(union_data.closed, - "Please call gras_datadesc_declare_union_close on %s before sending it", - type->name); - /* retrieve the field number */ - field_num = union_data.selector(type, state, data); - - xbt_assert1(field_num > 0, - "union field selector of %s gave a negative value", - type->name); - - xbt_assert3(field_num < xbt_dynar_length(union_data.fields), - "union field selector of %s returned %d but there is only %lu fields", - type->name, field_num, xbt_dynar_length(union_data.fields)); - - /* Send the field number */ - gras_dd_send_uint(sock, &field_num, 0 /* not stable */); - - /* Send the content */ - field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); - sub_type = field->type; - - if (field->send) - field->send(type,state,data); - - gras_datadesc_send_rec(sock,state,refs, sub_type, data, - detect_cycle || sub_type->cycle); - - break; - } - - case e_gras_datadesc_type_cat_ref: { - gras_dd_cat_ref_t ref_data; - void **ref=(void**)data; - int reference_is_to_send; - - ref_data = type->category.ref_data; - - /* Detect the referenced type and send it to peer if needed */ - sub_type = ref_data.type; - if (sub_type == NULL) { - sub_type = (*ref_data.selector)(type,state,data); - gras_dd_send_uint(sock, &(sub_type->code),1 /*stable*/); - } - - /* Send the actual value of the pointer for cycle handling */ - if (!pointer_type) { - pointer_type = gras_datadesc_by_name("data pointer"); - xbt_assert(pointer_type); - } - - gras_trp_send(sock, (char*)data, - pointer_type->size[GRAS_THISARCH], 1 /*stable*/); - - /* Send the pointed data only if not already sent */ - if (*(void**)data == NULL) { - VERB0("Not sending NULL referenced data"); - break; - } - - reference_is_to_send = 0; - TRY { - if (detect_cycle) - /* return ignored. Just checking whether it's known or not */ - xbt_dict_get_ext(refs,(char*)ref, sizeof(char*)); - else - reference_is_to_send = 1; - } CATCH(e) { - if (e.category != not_found_error) - RETHROW; - reference_is_to_send = 1; - xbt_ex_free(e); - } - - if (reference_is_to_send) { - VERB1("Sending data referenced at %p", (void*)*ref); - if (detect_cycle) - xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL); - gras_datadesc_send_rec(sock,state,refs, sub_type, *ref, - detect_cycle || sub_type->cycle); - - } else { - VERB1("Not sending data referenced at %p (already done)", (void*)*ref); - } - - break; - } - - case e_gras_datadesc_type_cat_array: { - gras_dd_cat_array_t array_data; - unsigned int count; - char *ptr=data; - long int elm_size; - - array_data = type->category.array_data; - - /* determine and send the element count */ - count = array_data.fixed_size; - if (count == 0) { - count = array_data.dynamic_size(type,state,data); - xbt_assert1(count >=0, - "Invalid (negative) array size for type %s",type->name); - gras_dd_send_uint(sock, &count, 0/*non-stable*/); - } - - /* send the content */ - sub_type = array_data.type; - elm_size = sub_type->aligned_size[GRAS_THISARCH]; - if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) { - VERB1("Array of %d scalars, send it in one shot",count); - gras_trp_send(sock, data, - sub_type->aligned_size[GRAS_THISARCH] * count, - 0 /* not stable */); - } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && - sub_type->category.array_data.fixed_size > 0 && - sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { - - VERB1("Array of %d fixed array of scalars, send it in one shot",count); - gras_trp_send(sock, data, - sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] - * count * sub_type->category.array_data.fixed_size, - 0 /* not stable */); - - } else { - for (cpt=0; cptcycle); - ptr += elm_size; - } - } - break; - } - - default: - xbt_assert0(0, "Invalid type"); - } + gras_cbps_t state, + xbt_dict_t refs, + gras_datadesc_type_t type, + char *data, + int detect_cycle) { + + xbt_ex_t e; + unsigned int cpt; + gras_datadesc_type_t sub_type; /* type on which we recurse */ + + VERB2("Send a %s (%s)", + type->name, gras_datadesc_cat_names[type->category_code]); + + if (!strcmp(type->name,"string")) + VERB1("value: '%s'",*(char**)data); + + if (type->send) { + type->send(type,state,data); + DEBUG0("Run the emission callback"); + } + + switch (type->category_code) { + case e_gras_datadesc_type_cat_scalar: + gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1); + break; + + case e_gras_datadesc_type_cat_struct: { + gras_dd_cat_struct_t struct_data; + gras_dd_cat_field_t field; + char *field_data; + + struct_data = type->category.struct_data; + xbt_assert1(struct_data.closed, + "Please call gras_datadesc_declare_struct_close on %s before sending it", + type->name); + VERB1(">> Send all fields of the structure %s",type->name); + xbt_dynar_foreach(struct_data.fields, cpt, field) { + field_data = data; + field_data += field->offset[GRAS_THISARCH]; + + sub_type = field->type; + + if (field->send) { + DEBUG1("Run the emission callback of field %s", field->name); + field->send(type,state,field_data); + } + + VERB1("Send field %s",field->name); + gras_datadesc_send_rec(sock,state,refs,sub_type, field_data, + detect_cycle || sub_type->cycle); + + } + VERB1("<< Sent all fields of the structure %s", type->name); + + break; + } + + case e_gras_datadesc_type_cat_union: { + gras_dd_cat_union_t union_data; + gras_dd_cat_field_t field=NULL; + unsigned int field_num; + + union_data = type->category.union_data; + + xbt_assert1(union_data.closed, + "Please call gras_datadesc_declare_union_close on %s before sending it", + type->name); + /* retrieve the field number */ + field_num = union_data.selector(type, state, data); + + xbt_assert1(field_num > 0, + "union field selector of %s gave a negative value", + type->name); + + xbt_assert3(field_num < xbt_dynar_length(union_data.fields), + "union field selector of %s returned %d but there is only %lu fields", + type->name, field_num, xbt_dynar_length(union_data.fields)); + + /* Send the field number */ + gras_dd_send_uint(sock, &field_num, 0 /* not stable */); + + /* Send the content */ + field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); + sub_type = field->type; + + if (field->send) + field->send(type,state,data); + + gras_datadesc_send_rec(sock,state,refs, sub_type, data, + detect_cycle || sub_type->cycle); + + break; + } + + case e_gras_datadesc_type_cat_ref: { + gras_dd_cat_ref_t ref_data; + void **ref=(void**)data; + int reference_is_to_send; + + ref_data = type->category.ref_data; + + /* Detect the referenced type and send it to peer if needed */ + sub_type = ref_data.type; + if (sub_type == NULL) { + sub_type = (*ref_data.selector)(type,state,data); + gras_dd_send_uint(sock, &(sub_type->code),1 /*stable*/); + } + + /* Send the actual value of the pointer for cycle handling */ + if (!pointer_type) { + pointer_type = gras_datadesc_by_name("data pointer"); + xbt_assert(pointer_type); + } + + gras_trp_send(sock, (char*)data, + pointer_type->size[GRAS_THISARCH], 1 /*stable*/); + + /* Send the pointed data only if not already sent */ + if (*(void**)data == NULL) { + VERB0("Not sending NULL referenced data"); + break; + } + + reference_is_to_send = 0; + TRY { + if (detect_cycle) + /* return ignored. Just checking whether it's known or not */ + xbt_dict_get_ext(refs,(char*)ref, sizeof(char*)); + else + reference_is_to_send = 1; + } CATCH(e) { + if (e.category != not_found_error) + RETHROW; + reference_is_to_send = 1; + xbt_ex_free(e); + } + + if (reference_is_to_send) { + VERB1("Sending data referenced at %p", (void*)*ref); + if (detect_cycle) + xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL); + gras_datadesc_send_rec(sock,state,refs, sub_type, *ref, + detect_cycle || sub_type->cycle); + + } else { + VERB1("Not sending data referenced at %p (already done)", (void*)*ref); + } + + break; + } + + case e_gras_datadesc_type_cat_array: { + gras_dd_cat_array_t array_data; + unsigned int count; + char *ptr=data; + long int elm_size; + + array_data = type->category.array_data; + + /* determine and send the element count */ + count = array_data.fixed_size; + if (count == 0) { + count = array_data.dynamic_size(type,state,data); + xbt_assert1(count >=0, + "Invalid (negative) array size for type %s",type->name); + gras_dd_send_uint(sock, &count, 0/*non-stable*/); + } + + /* send the content */ + sub_type = array_data.type; + elm_size = sub_type->aligned_size[GRAS_THISARCH]; + if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) { + VERB1("Array of %d scalars, send it in one shot",count); + gras_trp_send(sock, data, + sub_type->aligned_size[GRAS_THISARCH] * count, + 0 /* not stable */); + } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && + sub_type->category.array_data.fixed_size > 0 && + sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { + + VERB1("Array of %d fixed array of scalars, send it in one shot",count); + gras_trp_send(sock, data, + sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] + * count * sub_type->category.array_data.fixed_size, + 0 /* not stable */); + + } else { + for (cpt=0; cptcycle); + ptr += elm_size; + } + } + break; + } + + default: + xbt_assert0(0, "Invalid type"); + } } /** @@ -605,29 +605,29 @@ gras_datadesc_send_rec(gras_socket_t sock, * Copy the data pointed by src and described by type to the socket * */ -void gras_datadesc_send(gras_socket_t sock, - gras_datadesc_type_t type, - void *src) { - - xbt_ex_t e; - static gras_cbps_t state=NULL; - static xbt_dict_t refs=NULL; /* all references already sent */ - - xbt_assert0(type,"called with NULL type descriptor"); - - if (!state) { - state = gras_cbps_new(); - refs = xbt_dict_new(); - } - - TRY { - gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle); - } CLEANUP { - xbt_dict_reset(refs); - gras_cbps_reset(state); - } CATCH(e) { - RETHROW; - } +void gras_datadesc_send(gras_socket_t sock, + gras_datadesc_type_t type, + void *src) { + + xbt_ex_t e; + static gras_cbps_t state=NULL; + static xbt_dict_t refs=NULL; /* all references already sent */ + + xbt_assert0(type,"called with NULL type descriptor"); + + if (!state) { + state = gras_cbps_new(); + refs = xbt_dict_new(); + } + + TRY { + gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle); + } CLEANUP { + xbt_dict_reset(refs); + gras_cbps_reset(state); + } CATCH(e) { + RETHROW; + } } /** @@ -636,337 +636,337 @@ void gras_datadesc_send(gras_socket_t sock, * Do the data reception job recursively. * * subsize used only to deal with vicious case of reference to dynamic array. - * This size is needed at the reference reception level (to allocate enough - * space) and at the array reception level (to fill enough room). - * + * This size is needed at the reference reception level (to allocate enough + * space) and at the array reception level (to fill enough room). + * * Having this size passed as an argument of the recursive function is a crude * hack, but I was told that working code is sometimes better than neat one ;) */ static void -gras_datadesc_recv_rec(gras_socket_t sock, - gras_cbps_t state, - xbt_dict_t refs, - gras_datadesc_type_t type, - int r_arch, - char **r_data, - long int r_lgr, - char *l_data, - int subsize, - int detect_cycle) { - - unsigned int cpt; - gras_datadesc_type_t sub_type; - xbt_ex_t e; - - VERB2("Recv a %s @%p", type->name, (void*)l_data); - xbt_assert(l_data); - - switch (type->category_code) { - case e_gras_datadesc_type_cat_scalar: - if (type->size[GRAS_THISARCH] == type->size[r_arch]) { - gras_trp_recv(sock, (char*)l_data, type->size[r_arch]); - if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(type,1,r_arch, l_data,l_data); - } else { - void *ptr = xbt_malloc(type->size[r_arch]); - - gras_trp_recv(sock, (char*)ptr, type->size[r_arch]); - if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(type,1,r_arch, ptr,l_data); - free(ptr); - } - break; - - case e_gras_datadesc_type_cat_struct: { - gras_dd_cat_struct_t struct_data; - gras_dd_cat_field_t field; - - struct_data = type->category.struct_data; - - xbt_assert1(struct_data.closed, - "Please call gras_datadesc_declare_struct_close on %s before receiving it", - type->name); - VERB1(">> Receive all fields of the structure %s",type->name); - xbt_dynar_foreach(struct_data.fields, cpt, field) { - char *field_data = l_data + field->offset[GRAS_THISARCH]; - - sub_type = field->type; - - gras_datadesc_recv_rec(sock,state,refs, sub_type, - r_arch,NULL,0, - field_data,-1, - detect_cycle || sub_type->cycle); - - if (field->recv) { - DEBUG1("Run the reception callback of field %s", field->name); - field->recv(type,state,(void*)l_data); - } - - } - VERB1("<< Received all fields of the structure %s", type->name); - - break; - } - - case e_gras_datadesc_type_cat_union: { - gras_dd_cat_union_t union_data; - gras_dd_cat_field_t field=NULL; - unsigned int field_num; - - union_data = type->category.union_data; - - xbt_assert1(union_data.closed, - "Please call gras_datadesc_declare_union_close on %s before receiving it", - type->name); - /* retrieve the field number */ - gras_dd_recv_uint(sock, r_arch, &field_num); - if (field_num < 0) - THROW1(mismatch_error,0, - "Received union field for %s is negative", type->name); - if (field_num > xbt_dynar_length(union_data.fields)) - THROW3(mismatch_error,0, - "Received union field for %s is said to be #%d but there is only %lu fields", - type->name, field_num, xbt_dynar_length(union_data.fields)); - - /* Recv the content */ - field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); - sub_type = field->type; - - gras_datadesc_recv_rec(sock,state,refs, sub_type, - r_arch,NULL,0, - l_data,-1, - detect_cycle || sub_type->cycle); - if (field->recv) - field->recv(type,state,l_data); - - break; - } - - case e_gras_datadesc_type_cat_ref: { - char **r_ref = NULL; - char **l_ref = NULL; - gras_dd_cat_ref_t ref_data; - int reference_is_to_recv = 0; - - ref_data = type->category.ref_data; - - /* Get the referenced type locally or from peer */ - sub_type = ref_data.type; - if (sub_type == NULL) { - unsigned int ref_code; - gras_dd_recv_uint(sock, r_arch, &ref_code); - sub_type = gras_datadesc_by_id(ref_code); - } - - /* Get the actual value of the pointer for cycle handling */ - if (!pointer_type) { - pointer_type = gras_datadesc_by_name("data pointer"); - xbt_assert(pointer_type); - } - - r_ref = xbt_malloc(pointer_type->size[r_arch]); - - gras_trp_recv(sock, (char*)r_ref, - pointer_type->size[r_arch]); - - /* Receive the pointed data only if not already sent */ - if (gras_dd_is_r_null(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); - break; - } - - reference_is_to_recv = 0; - TRY { - if (detect_cycle) { - l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]); - } else { - reference_is_to_recv = 1; - } - } CATCH(e) { - if (e.category != not_found_error) - RETHROW; - reference_is_to_recv = 1; - xbt_ex_free(e); - } - - if (reference_is_to_recv) { - unsigned int subsubcount = 0; - void *l_referenced=NULL; - - VERB2("Receiving a ref to '%s', remotely @%p", - sub_type->name, *(void**)r_ref); - if (sub_type->category_code == e_gras_datadesc_type_cat_array) { - /* Damn. Reference to a dynamic array. Allocating the space for it +gras_datadesc_recv_rec(gras_socket_t sock, + gras_cbps_t state, + xbt_dict_t refs, + gras_datadesc_type_t type, + int r_arch, + char **r_data, + long int r_lgr, + char *l_data, + int subsize, + int detect_cycle) { + + unsigned int cpt; + gras_datadesc_type_t sub_type; + xbt_ex_t e; + + VERB2("Recv a %s @%p", type->name, (void*)l_data); + xbt_assert(l_data); + + switch (type->category_code) { + case e_gras_datadesc_type_cat_scalar: + if (type->size[GRAS_THISARCH] == type->size[r_arch]) { + gras_trp_recv(sock, (char*)l_data, type->size[r_arch]); + if (r_arch != GRAS_THISARCH) + gras_dd_convert_elm(type,1,r_arch, l_data,l_data); + } else { + void *ptr = xbt_malloc(type->size[r_arch]); + + gras_trp_recv(sock, (char*)ptr, type->size[r_arch]); + if (r_arch != GRAS_THISARCH) + gras_dd_convert_elm(type,1,r_arch, ptr,l_data); + free(ptr); + } + break; + + case e_gras_datadesc_type_cat_struct: { + gras_dd_cat_struct_t struct_data; + gras_dd_cat_field_t field; + + struct_data = type->category.struct_data; + + xbt_assert1(struct_data.closed, + "Please call gras_datadesc_declare_struct_close on %s before receiving it", + type->name); + VERB1(">> Receive all fields of the structure %s",type->name); + xbt_dynar_foreach(struct_data.fields, cpt, field) { + char *field_data = l_data + field->offset[GRAS_THISARCH]; + + sub_type = field->type; + + gras_datadesc_recv_rec(sock,state,refs, sub_type, + r_arch,NULL,0, + field_data,-1, + detect_cycle || sub_type->cycle); + + if (field->recv) { + DEBUG1("Run the reception callback of field %s", field->name); + field->recv(type,state,(void*)l_data); + } + + } + VERB1("<< Received all fields of the structure %s", type->name); + + break; + } + + case e_gras_datadesc_type_cat_union: { + gras_dd_cat_union_t union_data; + gras_dd_cat_field_t field=NULL; + unsigned int field_num; + + union_data = type->category.union_data; + + xbt_assert1(union_data.closed, + "Please call gras_datadesc_declare_union_close on %s before receiving it", + type->name); + /* retrieve the field number */ + gras_dd_recv_uint(sock, r_arch, &field_num); + if (field_num < 0) + THROW1(mismatch_error,0, + "Received union field for %s is negative", type->name); + if (field_num > xbt_dynar_length(union_data.fields)) + THROW3(mismatch_error,0, + "Received union field for %s is said to be #%d but there is only %lu fields", + type->name, field_num, xbt_dynar_length(union_data.fields)); + + /* Recv the content */ + field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); + sub_type = field->type; + + gras_datadesc_recv_rec(sock,state,refs, sub_type, + r_arch,NULL,0, + l_data,-1, + detect_cycle || sub_type->cycle); + if (field->recv) + field->recv(type,state,l_data); + + break; + } + + case e_gras_datadesc_type_cat_ref: { + char **r_ref = NULL; + char **l_ref = NULL; + gras_dd_cat_ref_t ref_data; + int reference_is_to_recv = 0; + + ref_data = type->category.ref_data; + + /* Get the referenced type locally or from peer */ + sub_type = ref_data.type; + if (sub_type == NULL) { + unsigned int ref_code; + gras_dd_recv_uint(sock, r_arch, &ref_code); + sub_type = gras_datadesc_by_id(ref_code); + } + + /* Get the actual value of the pointer for cycle handling */ + if (!pointer_type) { + pointer_type = gras_datadesc_by_name("data pointer"); + xbt_assert(pointer_type); + } + + r_ref = xbt_malloc(pointer_type->size[r_arch]); + + gras_trp_recv(sock, (char*)r_ref, + pointer_type->size[r_arch]); + + /* Receive the pointed data only if not already sent */ + if (gras_dd_is_r_null(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); + break; + } + + reference_is_to_recv = 0; + TRY { + if (detect_cycle) { + l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]); + } else { + reference_is_to_recv = 1; + } + } CATCH(e) { + if (e.category != not_found_error) + RETHROW; + reference_is_to_recv = 1; + xbt_ex_free(e); + } + + if (reference_is_to_recv) { + unsigned int subsubcount = 0; + void *l_referenced=NULL; + + VERB2("Receiving a ref to '%s', remotely @%p", + sub_type->name, *(void**)r_ref); + if (sub_type->category_code == e_gras_datadesc_type_cat_array) { + /* Damn. Reference to a dynamic array. Allocating the space for it is more complicated */ - gras_dd_cat_array_t array_data = sub_type->category.array_data; - gras_datadesc_type_t subsub_type; - - subsubcount = array_data.fixed_size; - if (subsubcount == 0) - gras_dd_recv_uint(sock, r_arch, &subsubcount); - - subsub_type = array_data.type; - - - gras_dd_alloc_ref(refs, - subsub_type->size[GRAS_THISARCH] * subsubcount, - r_ref,pointer_type->size[r_arch], - (char**)&l_referenced, - detect_cycle); - } else { - gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH], - r_ref,pointer_type->size[r_arch], - (char**)&l_referenced, - detect_cycle); - } - - gras_datadesc_recv_rec(sock,state,refs, sub_type, - r_arch,r_ref,pointer_type->size[r_arch], - (char*)l_referenced, subsubcount, - detect_cycle || sub_type->cycle); - - *(void**)l_data=l_referenced; - VERB3("'%s' remotely referenced at %p locally at %p", - sub_type->name, *(void**)r_ref, l_referenced); - - } else { - VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)", - *(void**)r_ref, *(void**)l_ref); - - *(void**)l_data=*l_ref; - - } - free(r_ref); - break; - } - - case e_gras_datadesc_type_cat_array: { - gras_dd_cat_array_t array_data; - unsigned int count; - char *ptr; - long int elm_size; - - array_data = type->category.array_data; - /* determine element count locally, or from caller, or from peer */ - count = array_data.fixed_size; - if (count == 0) - count = subsize; - if (count == 0) - gras_dd_recv_uint(sock, r_arch, &count); - if (count == 0) - THROW1(mismatch_error,0, - "Invalid (=0) array size for type %s",type->name); - - /* receive the content */ - sub_type = array_data.type; - if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) { - VERB1("Array of %d scalars, get it in one shoot", count); - if (sub_type->aligned_size[GRAS_THISARCH] >= - sub_type->aligned_size[r_arch]) { - gras_trp_recv(sock, (char*)l_data, - sub_type->aligned_size[r_arch] * count); - if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data); - } else { - ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count); - - gras_trp_recv(sock, (char*)ptr, - sub_type->size[r_arch] * count); - if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data); - free(ptr); - } - } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && - sub_type->category.array_data.fixed_size > 0 && - sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { - gras_datadesc_type_t subsub_type; - array_data = sub_type->category.array_data; - subsub_type = array_data.type; - - VERB1("Array of %d fixed array of scalars, get it in one shot",count); - if (subsub_type->aligned_size[GRAS_THISARCH] >= - subsub_type->aligned_size[r_arch]) { - gras_trp_recv(sock, (char*)l_data, - subsub_type->aligned_size[r_arch] * count * - array_data.fixed_size); - if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data); - } else { - ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size); - - gras_trp_recv(sock, (char*)ptr, - subsub_type->size[r_arch] * count*array_data.fixed_size); - if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data); - free(ptr); - } - - - } else { - /* not scalar content, get it recursively (may contain pointers) */ - elm_size = sub_type->aligned_size[GRAS_THISARCH]; - VERB2("Receive a %d-long array of %s",count, sub_type->name); - - ptr = l_data; - for (cpt=0; cptcycle); - - ptr += elm_size; - } - } - break; - } - - default: - xbt_assert0(0, "Invalid type"); - } - - if (type->recv) - type->recv(type,state,l_data); - - if (!strcmp(type->name,"string")) - VERB1("value: '%s'",*(char**)l_data); + gras_dd_cat_array_t array_data = sub_type->category.array_data; + gras_datadesc_type_t subsub_type; + + subsubcount = array_data.fixed_size; + if (subsubcount == 0) + gras_dd_recv_uint(sock, r_arch, &subsubcount); + + subsub_type = array_data.type; + + + gras_dd_alloc_ref(refs, + subsub_type->size[GRAS_THISARCH] * subsubcount, + r_ref,pointer_type->size[r_arch], + (char**)&l_referenced, + detect_cycle); + } else { + gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH], + r_ref,pointer_type->size[r_arch], + (char**)&l_referenced, + detect_cycle); + } + + gras_datadesc_recv_rec(sock,state,refs, sub_type, + r_arch,r_ref,pointer_type->size[r_arch], + (char*)l_referenced, subsubcount, + detect_cycle || sub_type->cycle); + + *(void**)l_data=l_referenced; + VERB3("'%s' remotely referenced at %p locally at %p", + sub_type->name, *(void**)r_ref, l_referenced); + + } else { + VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)", + *(void**)r_ref, *(void**)l_ref); + + *(void**)l_data=*l_ref; + + } + free(r_ref); + break; + } + + case e_gras_datadesc_type_cat_array: { + gras_dd_cat_array_t array_data; + unsigned int count; + char *ptr; + long int elm_size; + + array_data = type->category.array_data; + /* determine element count locally, or from caller, or from peer */ + count = array_data.fixed_size; + if (count == 0) + count = subsize; + if (count == 0) + gras_dd_recv_uint(sock, r_arch, &count); + if (count == 0) + THROW1(mismatch_error,0, + "Invalid (=0) array size for type %s",type->name); + + /* receive the content */ + sub_type = array_data.type; + if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) { + VERB1("Array of %d scalars, get it in one shoot", count); + if (sub_type->aligned_size[GRAS_THISARCH] >= + sub_type->aligned_size[r_arch]) { + gras_trp_recv(sock, (char*)l_data, + sub_type->aligned_size[r_arch] * count); + if (r_arch != GRAS_THISARCH) + gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data); + } else { + ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count); + + gras_trp_recv(sock, (char*)ptr, + sub_type->size[r_arch] * count); + if (r_arch != GRAS_THISARCH) + gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data); + free(ptr); + } + } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && + sub_type->category.array_data.fixed_size > 0 && + sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { + gras_datadesc_type_t subsub_type; + array_data = sub_type->category.array_data; + subsub_type = array_data.type; + + VERB1("Array of %d fixed array of scalars, get it in one shot",count); + if (subsub_type->aligned_size[GRAS_THISARCH] >= + subsub_type->aligned_size[r_arch]) { + gras_trp_recv(sock, (char*)l_data, + subsub_type->aligned_size[r_arch] * count * + array_data.fixed_size); + if (r_arch != GRAS_THISARCH) + gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data); + } else { + ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size); + + gras_trp_recv(sock, (char*)ptr, + subsub_type->size[r_arch] * count*array_data.fixed_size); + if (r_arch != GRAS_THISARCH) + gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data); + free(ptr); + } + + + } else { + /* not scalar content, get it recursively (may contain pointers) */ + elm_size = sub_type->aligned_size[GRAS_THISARCH]; + VERB2("Receive a %d-long array of %s",count, sub_type->name); + + ptr = l_data; + for (cpt=0; cptcycle); + + ptr += elm_size; + } + } + break; + } + + default: + xbt_assert0(0, "Invalid type"); + } + + if (type->recv) + type->recv(type,state,l_data); + + if (!strcmp(type->name,"string")) + VERB1("value: '%s'",*(char**)l_data); } /** * gras_datadesc_recv: * - * Get an instance of the datatype described by @type from the @socket, + * Get an instance of the datatype described by @type from the @socket, * and store a pointer to it in @dst * */ void -gras_datadesc_recv(gras_socket_t sock, - gras_datadesc_type_t type, - int r_arch, - void *dst) { - - xbt_ex_t e; - static gras_cbps_t state=NULL; /* callback persistent state */ - static xbt_dict_t refs=NULL; /* all references already sent */ - - if (!state) { - state = gras_cbps_new(); - refs = xbt_dict_new(); - } - - xbt_assert0(type,"called with NULL type descriptor"); - TRY { - gras_datadesc_recv_rec(sock, state, refs, type, - r_arch, NULL, 0, - (char *) dst,-1, - type->cycle); - } CLEANUP { - xbt_dict_reset(refs); - gras_cbps_reset(state); - } CATCH(e) { - RETHROW; - } +gras_datadesc_recv(gras_socket_t sock, + gras_datadesc_type_t type, + int r_arch, + void *dst) { + + xbt_ex_t e; + static gras_cbps_t state=NULL; /* callback persistent state */ + static xbt_dict_t refs=NULL; /* all references already sent */ + + if (!state) { + state = gras_cbps_new(); + refs = xbt_dict_new(); + } + + xbt_assert0(type,"called with NULL type descriptor"); + TRY { + gras_datadesc_recv_rec(sock, state, refs, type, + r_arch, NULL, 0, + (char *) dst,-1, + type->cycle); + } CLEANUP { + xbt_dict_reset(refs); + gras_cbps_reset(state); + } CATCH(e) { + RETHROW; + } } diff --git a/src/gras/DataDesc/ddt_parse.c b/src/gras/DataDesc/ddt_parse.c index 3adaccf9cd..88646e4f47 100644 --- a/src/gras/DataDesc/ddt_parse.c +++ b/src/gras/DataDesc/ddt_parse.c @@ -16,667 +16,667 @@ #include "gras/DataDesc/ddt_parse.yy.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_parse,gras_ddt, - "Parsing C data structures to build GRAS data description"); + "Parsing C data structures to build GRAS data description"); typedef struct s_type_modifier{ - short is_long; - int is_unsigned:1; - int is_short:1; - - int is_struct:1; - int is_union:1; - int is_enum:1; - - int is_ref:1; - - int is_dynar:2; - int is_matrix:2; + short is_long; + int is_unsigned:1; + int is_short:1; + + int is_struct:1; + int is_union:1; + int is_enum:1; + + int is_ref:1; + + int is_dynar:2; + int is_matrix:2; } s_type_modifier_t,*type_modifier_t; typedef struct s_field { - gras_datadesc_type_t type; - char *type_name; - char *name; - s_type_modifier_t tm; + gras_datadesc_type_t type; + char *type_name; + char *name; + s_type_modifier_t tm; } s_identifier_t; - + extern char *gras_ddt_parse_text; /* text being considered in the parser */ /* local functions */ static void parse_type_modifier(type_modifier_t type_modifier) { - XBT_IN; - do { - if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) { - /* This only used when parsing 'short *' since this function returns when int, float, double,... is encountered */ - DEBUG0("This is a reference"); - type_modifier->is_ref++; - - } else if (!strcmp(gras_ddt_parse_text,"unsigned")) { - DEBUG0("This is an unsigned"); - type_modifier->is_unsigned = 1; - - } else if (!strcmp(gras_ddt_parse_text,"short")) { - DEBUG0("This is short"); - type_modifier->is_short = 1; - - } else if (!strcmp(gras_ddt_parse_text,"long")) { - DEBUG0("This is long"); - type_modifier->is_long++; /* handle "long long" */ - - } else if (!strcmp(gras_ddt_parse_text,"struct")) { - DEBUG0("This is a struct"); - type_modifier->is_struct = 1; - - } else if (!strcmp(gras_ddt_parse_text,"union")) { - DEBUG0("This is an union"); - type_modifier->is_union = 1; - - } else if (!strcmp(gras_ddt_parse_text,"enum")) { - DEBUG0("This is an enum"); - type_modifier->is_enum = 1; - - } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_EMPTY) { - DEBUG0("Pass space"); - - } else { - DEBUG1("Done with modifiers (got %s)",gras_ddt_parse_text); - break; - } - - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - if((gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) && - (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_STAR)) { - DEBUG2("Done with modifiers (got %s,%d)",gras_ddt_parse_text,gras_ddt_parse_tok_num); - break; - } - } while(1); - XBT_OUT; + XBT_IN; + do { + if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) { + /* This only used when parsing 'short *' since this function returns when int, float, double,... is encountered */ + DEBUG0("This is a reference"); + type_modifier->is_ref++; + + } else if (!strcmp(gras_ddt_parse_text,"unsigned")) { + DEBUG0("This is an unsigned"); + type_modifier->is_unsigned = 1; + + } else if (!strcmp(gras_ddt_parse_text,"short")) { + DEBUG0("This is short"); + type_modifier->is_short = 1; + + } else if (!strcmp(gras_ddt_parse_text,"long")) { + DEBUG0("This is long"); + type_modifier->is_long++; /* handle "long long" */ + + } else if (!strcmp(gras_ddt_parse_text,"struct")) { + DEBUG0("This is a struct"); + type_modifier->is_struct = 1; + + } else if (!strcmp(gras_ddt_parse_text,"union")) { + DEBUG0("This is an union"); + type_modifier->is_union = 1; + + } else if (!strcmp(gras_ddt_parse_text,"enum")) { + DEBUG0("This is an enum"); + type_modifier->is_enum = 1; + + } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_EMPTY) { + DEBUG0("Pass space"); + + } else { + DEBUG1("Done with modifiers (got %s)",gras_ddt_parse_text); + break; + } + + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + if((gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) && + (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_STAR)) { + DEBUG2("Done with modifiers (got %s,%d)",gras_ddt_parse_text,gras_ddt_parse_tok_num); + break; + } + } while(1); + XBT_OUT; } static void print_type_modifier(s_type_modifier_t tm) { - int i; + int i; - XBT_IN; - if (tm.is_unsigned) printf("(unsigned) "); - if (tm.is_short) printf("(short) "); - for (i=0 ; iname)+48); - DEBUG2("Array specification (size=%ld, elm='%s'), change pushed type", - size,former.type_name); - sprintf(array.type_name,"%s%s%s%s[%ld]", - (former.tm.is_unsigned?"u ":""), - (former.tm.is_short?"s ":""), - (former.tm.is_long?"l ":""), - former.type_name, - size); - free(former.type_name); - - array.type = gras_datadesc_array_fixed(array.type_name, former.type, size); /* redeclaration are ignored */ - array.name = former.name; - - xbt_dynar_push(dynar,&array); - XBT_OUT; + s_identifier_t former,array; + memset(&array,0,sizeof(array)); + + XBT_IN; + xbt_dynar_pop(dynar,&former); + array.type_name=(char*)xbt_malloc(strlen(former.type->name)+48); + DEBUG2("Array specification (size=%ld, elm='%s'), change pushed type", + size,former.type_name); + sprintf(array.type_name,"%s%s%s%s[%ld]", + (former.tm.is_unsigned?"u ":""), + (former.tm.is_short?"s ":""), + (former.tm.is_long?"l ":""), + former.type_name, + size); + free(former.type_name); + + array.type = gras_datadesc_array_fixed(array.type_name, former.type, size); /* redeclaration are ignored */ + array.name = former.name; + + xbt_dynar_push(dynar,&array); + XBT_OUT; } static void change_to_ref(xbt_dynar_t dynar) { - s_identifier_t former,ref; - memset(&ref,0,sizeof(ref)); + s_identifier_t former,ref; + memset(&ref,0,sizeof(ref)); - XBT_IN; - xbt_dynar_pop(dynar,&former); - ref.type_name=(char*)xbt_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); + XBT_IN; + xbt_dynar_pop(dynar,&former); + ref.type_name=(char*)xbt_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); - ref.type = gras_datadesc_ref(ref.type_name, former.type); /* redeclaration are ignored */ - ref.name = former.name; + ref.type = gras_datadesc_ref(ref.type_name, former.type); /* redeclaration are ignored */ + ref.name = former.name; - xbt_dynar_push(dynar,&ref); - XBT_OUT; + xbt_dynar_push(dynar,&ref); + XBT_OUT; } static void change_to_ref_pop_array(xbt_dynar_t dynar) { - s_identifier_t former,ref; - memset(&ref,0,sizeof(ref)); + s_identifier_t former,ref; + memset(&ref,0,sizeof(ref)); - XBT_IN; - xbt_dynar_pop(dynar,&former); - ref.type = gras_datadesc_ref_pop_arr(former.type); /* redeclaration are ignored */ - ref.type_name = (char*)strdup(ref.type->name); - ref.name = former.name; + XBT_IN; + xbt_dynar_pop(dynar,&former); + ref.type = gras_datadesc_ref_pop_arr(former.type); /* redeclaration are ignored */ + ref.type_name = (char*)strdup(ref.type->name); + ref.name = former.name; - free(former.type_name); + free(former.type_name); - xbt_dynar_push(dynar,&ref); - XBT_OUT; + xbt_dynar_push(dynar,&ref); + XBT_OUT; } static void change_to_dynar_of(xbt_dynar_t dynar,gras_datadesc_type_t subtype) { - s_identifier_t former,ref; - memset(&ref,0,sizeof(ref)); + s_identifier_t former,ref; + memset(&ref,0,sizeof(ref)); - XBT_IN; - xbt_dynar_pop(dynar,&former); - ref.type = gras_datadesc_dynar(subtype,NULL); /* redeclaration are ignored */ - ref.type_name = (char*)strdup(ref.type->name); - ref.name = former.name; + XBT_IN; + xbt_dynar_pop(dynar,&former); + ref.type = gras_datadesc_dynar(subtype,NULL); /* redeclaration are ignored */ + ref.type_name = (char*)strdup(ref.type->name); + ref.name = former.name; - free(former.type_name); + free(former.type_name); - xbt_dynar_push(dynar,&ref); - XBT_OUT; + xbt_dynar_push(dynar,&ref); + XBT_OUT; } static void change_to_matrix_of(xbt_dynar_t dynar,gras_datadesc_type_t subtype) { - s_identifier_t former,ref; - memset(&ref,0,sizeof(ref)); + s_identifier_t former,ref; + memset(&ref,0,sizeof(ref)); - XBT_IN; - xbt_dynar_pop(dynar,&former); - ref.type = gras_datadesc_matrix(subtype,NULL); /* redeclaration are ignored */ - ref.type_name = (char*)strdup(ref.type->name); - ref.name = former.name; + XBT_IN; + xbt_dynar_pop(dynar,&former); + ref.type = gras_datadesc_matrix(subtype,NULL); /* redeclaration are ignored */ + ref.type_name = (char*)strdup(ref.type->name); + ref.name = former.name; - free(former.type_name); + free(former.type_name); - xbt_dynar_push(dynar,&ref); - XBT_OUT; + xbt_dynar_push(dynar,&ref); + XBT_OUT; } static void add_free_f(xbt_dynar_t dynar,void_f_pvoid_t free_f) { - s_identifier_t former,ref; - memset(&ref,0,sizeof(ref)); - - XBT_IN; - xbt_dynar_pop(dynar,&former); - memcpy(former.type->extra,free_f, sizeof(free_f)); - xbt_dynar_push(dynar,&former); - XBT_OUT; + s_identifier_t former,ref; + memset(&ref,0,sizeof(ref)); + + XBT_IN; + xbt_dynar_pop(dynar,&former); + memcpy(former.type->extra,free_f, sizeof(free_f)); + xbt_dynar_push(dynar,&former); + XBT_OUT; } static void parse_statement(char *definition, - xbt_dynar_t identifiers, - xbt_dynar_t fields_to_push) { - char buffname[512]; - - s_identifier_t identifier; - - int expect_id_separator = 0; - - XBT_IN; - memset(&identifier,0,sizeof(identifier)); - - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_RA) { - XBT_OUT; - THROW0(mismatch_error,0,"End of the englobing structure or union"); - } - - if (XBT_LOG_ISENABLED(gras_ddt_parse,xbt_log_priority_debug)) { - int colon_pos; - for (colon_pos = gras_ddt_parse_col_pos; - definition[colon_pos] != ';'; - colon_pos++); - definition[colon_pos] = '\0'; - DEBUG3("Parse the statement \"%s%s;\" (col_pos=%d)", - gras_ddt_parse_text, - definition+gras_ddt_parse_col_pos, - gras_ddt_parse_col_pos); - definition[colon_pos] = ';'; - } - - if(gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) - PARSE_ERROR1("Unparsable symbol: found a typeless statement (got '%s' instead)", - gras_ddt_parse_text); - - /**** get the type modifier of this statement ****/ - parse_type_modifier(&identifier.tm); - - /* FIXME: This does not detect recursive definitions at all? */ - if (identifier.tm.is_union || identifier.tm.is_enum || identifier.tm.is_struct) - PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle recursive type definition yet"); - - /**** get the base type, giving "short a" the needed love ****/ - if (!identifier.tm.is_union && - !identifier.tm.is_enum && - !identifier.tm.is_struct && - - (identifier.tm.is_short || identifier.tm.is_long || identifier.tm.is_unsigned) && - - strcmp(gras_ddt_parse_text,"char") && - strcmp(gras_ddt_parse_text,"float") && - strcmp(gras_ddt_parse_text,"double") && - strcmp(gras_ddt_parse_text,"int") ) { - - /* bastard user, they omited "int" ! */ - identifier.type_name=(char*)strdup("int"); - DEBUG0("the base type is 'int', which were omited (you vicious user)"); - } else { - identifier.type_name=(char*)strdup(gras_ddt_parse_text); - DEBUG1("the base type is '%s'",identifier.type_name); - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - } - - /**** build the base type for latter use ****/ - if (identifier.tm.is_union) { - PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle union yet (get callback from annotation?)"); - - } else if (identifier.tm.is_enum) { - PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle enum yet"); - - } else if (identifier.tm.is_struct) { - sprintf(buffname,"struct %s",identifier.type_name); - identifier.type = gras_datadesc_struct(buffname); /* Get created when does not exist */ - - } else if (identifier.tm.is_unsigned) { - if (!strcmp(identifier.type_name,"int")) { - if (identifier.tm.is_long == 2) { - identifier.type = gras_datadesc_by_name("unsigned long long int"); - } else if (identifier.tm.is_long) { - identifier.type = gras_datadesc_by_name("unsigned long int"); - } else if (identifier.tm.is_short) { - identifier.type = gras_datadesc_by_name("unsigned short int"); - } else { - identifier.type = gras_datadesc_by_name("unsigned int"); - } - - } else if (!strcmp(identifier.type_name, "char")) { - identifier.type = gras_datadesc_by_name("unsigned char"); - - } else { /* impossible, gcc parses this shit before us */ - THROW_IMPOSSIBLE; - } - - } else if (!strcmp(identifier.type_name, "float")) { - /* no modificator allowed by gcc */ - identifier.type = gras_datadesc_by_name("float"); - - } else if (!strcmp(identifier.type_name, "double")) { - if (identifier.tm.is_long) - PARSE_ERROR0("long double not portable and thus not handled"); - - identifier.type = gras_datadesc_by_name("double"); - - } else { /* signed integer elemental */ - if (!strcmp(identifier.type_name,"int")) { - if (identifier.tm.is_long == 2) { - identifier.type = gras_datadesc_by_name("signed long long int"); - } else if (identifier.tm.is_long) { - identifier.type = gras_datadesc_by_name("signed long int"); - } else if (identifier.tm.is_short) { - identifier.type = gras_datadesc_by_name("signed short int"); - } else { - identifier.type = gras_datadesc_by_name("int"); - } - - } else if (!strcmp(identifier.type_name, "char")) { - identifier.type = gras_datadesc_by_name("char"); - - } else { - DEBUG1("Base type is a constructed one (%s)",identifier.type_name); - if (!strcmp(identifier.type_name,"xbt_matrix_t")) { - identifier.tm.is_matrix = 1; - } else if (!strcmp(identifier.type_name,"xbt_dynar_t")) { - identifier.tm.is_dynar = 1; - } else { - identifier.type = gras_datadesc_by_name(identifier.type_name); - if (!identifier.type) - PARSE_ERROR1("Unknown base type '%s'",identifier.type_name); - } - } - } - /* Now identifier.type and identifier.name speak about the base type. - Stars are not eaten unless 'int' was omitted. - We will have to enhance it if we are in fact asked for array or reference. - - Dynars and matrices also need some extra love (prodiged as annotations) - */ - - /**** look for the symbols of this type ****/ - for(expect_id_separator = 0; + xbt_dynar_t identifiers, + xbt_dynar_t fields_to_push) { + char buffname[512]; - (/*(gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_EMPTY) && FIXME*/ - (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_SEMI_COLON)) ; + s_identifier_t identifier; - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump() ) { + int expect_id_separator = 0; - if(expect_id_separator) { - if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_COLON) { - expect_id_separator = 0; - continue; + XBT_IN; + memset(&identifier,0,sizeof(identifier)); - } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_LB) { - /* Handle fixed size arrays */ gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_RB) { - PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot deal with [] constructs (yet)"); - - } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { - char *end; - long int size=strtol(gras_ddt_parse_text, &end, 10); - - if (end == gras_ddt_parse_text || *end != '\0') { - /* Not a number. Get the constant value, if any */ - int *storage=xbt_dict_get_or_null(gras_dd_constants,gras_ddt_parse_text); - if (storage) { - size = *storage; - } else { - PARSE_ERROR1("Unparsable size of array. Found '%s', expected number or known constant. Need to use gras_datadesc_set_const(), huh?", - gras_ddt_parse_text); - } - } - - /* replace the previously pushed type to an array of it */ - change_to_fixed_array(identifiers,size); - - /* eat the closing bracket */ - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RB) - PARSE_ERROR0("Unparsable size of array"); - DEBUG1("Fixed size array, size=%ld",size); - continue; - } else { - PARSE_ERROR0("Unparsable size of array"); + if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_RA) { + XBT_OUT; + THROW0(mismatch_error,0,"End of the englobing structure or union"); } - /* End of fixed size arrays handling */ - } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { - /* Handle annotation */ - s_identifier_t array; - char *keyname = NULL; - char *keyval = NULL; - memset(&array,0,sizeof(array)); - if (strcmp(gras_ddt_parse_text,"GRAS_ANNOTE")) - PARSE_ERROR1("Unparsable symbol: Expected 'GRAS_ANNOTE', got '%s'",gras_ddt_parse_text); - - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LP) - PARSE_ERROR1("Unparsable annotation: Expected parenthesis, got '%s'",gras_ddt_parse_text); - - while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY ); - - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) - PARSE_ERROR1("Unparsable annotation: Expected key name, got '%s'",gras_ddt_parse_text); - keyname = (char*)strdup(gras_ddt_parse_text); - - while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY ); - - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_COLON) - PARSE_ERROR1("Unparsable annotation: expected ',' after the key name, got '%s'",gras_ddt_parse_text); - - while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY ); - - /* get the value */ - - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) - PARSE_ERROR1("Unparsable annotation: Expected key value, got '%s'",gras_ddt_parse_text); - keyval = (char*)strdup(gras_ddt_parse_text); - - while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY ); - - /* Done with parsing the annotation. Now deal with it by replacing previously pushed type with the right one */ - - DEBUG2("Anotation: %s=%s",keyname,keyval); - if (!strcmp(keyname,"size")) { - 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")) { - change_to_ref(identifiers); - free(keyval); - } else { - char *p; - int fixed = 1; - for (p = keyval; *p != '\0'; p++) - if (! isdigit(*p) ) - fixed = 0; - if (fixed) { - change_to_fixed_array(identifiers,atoi(keyval)); - change_to_ref(identifiers); - free(keyval); - - } else { - change_to_ref_pop_array(identifiers); - xbt_dynar_push(fields_to_push,&keyval); - } - } - } else if (!strcmp(keyname,"subtype")) { - gras_datadesc_type_t subtype = gras_datadesc_by_name(keyval); - if (identifier.tm.is_matrix) { - change_to_matrix_of(identifiers,subtype); - identifier.tm.is_matrix = -1; - } else if (identifier.tm.is_dynar) { - change_to_dynar_of(identifiers,subtype); - identifier.tm.is_dynar = -1; - } else { - PARSE_ERROR1("subtype annotation only accepted for dynars and matrices, but passed to '%s'",identifier.type_name); - } - free(keyval); - } else if (!strcmp(keyname,"free_f")) { - int *storage=xbt_dict_get_or_null(gras_dd_constants,keyval); - if (!storage) - PARSE_ERROR1("value for free_f annotation of field %s is not a known constant",identifier.name); - if (identifier.tm.is_matrix == -1) { - add_free_f(identifiers,*(void_f_pvoid_t*)storage); - identifier.tm.is_matrix = 0; - } else if (identifier.tm.is_dynar == -1) { - add_free_f(identifiers,*(void_f_pvoid_t*)storage); - identifier.tm.is_dynar = 0; - } else { - PARSE_ERROR1("free_f annotation only accepted for dynars and matrices which subtype is already declared (field %s)", - identifier.name); - } - free(keyval); - } else { - free(keyval); - PARSE_ERROR1("Unknown annotation type: '%s'",keyname); + if (XBT_LOG_ISENABLED(gras_ddt_parse,xbt_log_priority_debug)) { + int colon_pos; + for (colon_pos = gras_ddt_parse_col_pos; + definition[colon_pos] != ';'; + colon_pos++); + definition[colon_pos] = '\0'; + DEBUG3("Parse the statement \"%s%s;\" (col_pos=%d)", + gras_ddt_parse_text, + definition+gras_ddt_parse_col_pos, + gras_ddt_parse_col_pos); + definition[colon_pos] = ';'; } - /* Get all the multipliers */ - while (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) { + if(gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) + PARSE_ERROR1("Unparsable symbol: found a typeless statement (got '%s' instead)", + gras_ddt_parse_text); + + /**** get the type modifier of this statement ****/ + parse_type_modifier(&identifier.tm); + + /* FIXME: This does not detect recursive definitions at all? */ + if (identifier.tm.is_union || identifier.tm.is_enum || identifier.tm.is_struct) + PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle recursive type definition yet"); - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + /**** get the base type, giving "short a" the needed love ****/ + if (!identifier.tm.is_union && + !identifier.tm.is_enum && + !identifier.tm.is_struct && - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) - PARSE_ERROR1("Unparsable annotation: Expected field name after '*', got '%s'",gras_ddt_parse_text); - - keyval = xbt_malloc(strlen(gras_ddt_parse_text)+2); - sprintf(keyval,"*%s",gras_ddt_parse_text); + (identifier.tm.is_short || identifier.tm.is_long || identifier.tm.is_unsigned) && + + strcmp(gras_ddt_parse_text,"char") && + strcmp(gras_ddt_parse_text,"float") && + strcmp(gras_ddt_parse_text,"double") && + strcmp(gras_ddt_parse_text,"int") ) { + + /* bastard user, they omited "int" ! */ + identifier.type_name=(char*)strdup("int"); + DEBUG0("the base type is 'int', which were omited (you vicious user)"); + } else { + identifier.type_name=(char*)strdup(gras_ddt_parse_text); + DEBUG1("the base type is '%s'",identifier.type_name); + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + } - /* ask caller to push field as a multiplier */ - xbt_dynar_push(fields_to_push,&keyval); + /**** build the base type for latter use ****/ + if (identifier.tm.is_union) { + PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle union yet (get callback from annotation?)"); + + } else if (identifier.tm.is_enum) { + PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle enum yet"); + + } else if (identifier.tm.is_struct) { + sprintf(buffname,"struct %s",identifier.type_name); + identifier.type = gras_datadesc_struct(buffname); /* Get created when does not exist */ + + } else if (identifier.tm.is_unsigned) { + if (!strcmp(identifier.type_name,"int")) { + if (identifier.tm.is_long == 2) { + identifier.type = gras_datadesc_by_name("unsigned long long int"); + } else if (identifier.tm.is_long) { + identifier.type = gras_datadesc_by_name("unsigned long int"); + } else if (identifier.tm.is_short) { + identifier.type = gras_datadesc_by_name("unsigned short int"); + } else { + identifier.type = gras_datadesc_by_name("unsigned int"); + } + + } else if (!strcmp(identifier.type_name, "char")) { + identifier.type = gras_datadesc_by_name("unsigned char"); + + } else { /* impossible, gcc parses this shit before us */ + THROW_IMPOSSIBLE; + } + + } else if (!strcmp(identifier.type_name, "float")) { + /* no modificator allowed by gcc */ + identifier.type = gras_datadesc_by_name("float"); + + } else if (!strcmp(identifier.type_name, "double")) { + if (identifier.tm.is_long) + PARSE_ERROR0("long double not portable and thus not handled"); + + identifier.type = gras_datadesc_by_name("double"); + + } else { /* signed integer elemental */ + if (!strcmp(identifier.type_name,"int")) { + if (identifier.tm.is_long == 2) { + identifier.type = gras_datadesc_by_name("signed long long int"); + } else if (identifier.tm.is_long) { + identifier.type = gras_datadesc_by_name("signed long int"); + } else if (identifier.tm.is_short) { + identifier.type = gras_datadesc_by_name("signed short int"); + } else { + identifier.type = gras_datadesc_by_name("int"); + } + + } else if (!strcmp(identifier.type_name, "char")) { + identifier.type = gras_datadesc_by_name("char"); + + } else { + DEBUG1("Base type is a constructed one (%s)",identifier.type_name); + if (!strcmp(identifier.type_name,"xbt_matrix_t")) { + identifier.tm.is_matrix = 1; + } else if (!strcmp(identifier.type_name,"xbt_dynar_t")) { + identifier.tm.is_dynar = 1; + } else { + identifier.type = gras_datadesc_by_name(identifier.type_name); + if (!identifier.type) + PARSE_ERROR1("Unknown base type '%s'",identifier.type_name); + } + } + } + /* Now identifier.type and identifier.name speak about the base type. + Stars are not eaten unless 'int' was omitted. + We will have to enhance it if we are in fact asked for array or reference. - /* skip blanks after this block*/ - while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) - == GRAS_DDT_PARSE_TOKEN_EMPTY ); + Dynars and matrices also need some extra love (prodiged as annotations) + */ + + /**** look for the symbols of this type ****/ + for(expect_id_separator = 0; + + (/*(gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_EMPTY) && FIXME*/ + (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_SEMI_COLON)) ; + + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump() ) { + + if(expect_id_separator) { + if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_COLON) { + expect_id_separator = 0; + continue; + + } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_LB) { + /* Handle fixed size arrays */ + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_RB) { + PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot deal with [] constructs (yet)"); + + } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { + char *end; + long int size=strtol(gras_ddt_parse_text, &end, 10); + + if (end == gras_ddt_parse_text || *end != '\0') { + /* Not a number. Get the constant value, if any */ + int *storage=xbt_dict_get_or_null(gras_dd_constants,gras_ddt_parse_text); + if (storage) { + size = *storage; + } else { + PARSE_ERROR1("Unparsable size of array. Found '%s', expected number or known constant. Need to use gras_datadesc_set_const(), huh?", + gras_ddt_parse_text); + } + } + + /* replace the previously pushed type to an array of it */ + change_to_fixed_array(identifiers,size); + + /* eat the closing bracket */ + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RB) + PARSE_ERROR0("Unparsable size of array"); + DEBUG1("Fixed size array, size=%ld",size); + continue; + } else { + PARSE_ERROR0("Unparsable size of array"); + } + /* End of fixed size arrays handling */ + + } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { + /* Handle annotation */ + s_identifier_t array; + char *keyname = NULL; + char *keyval = NULL; + memset(&array,0,sizeof(array)); + if (strcmp(gras_ddt_parse_text,"GRAS_ANNOTE")) + PARSE_ERROR1("Unparsable symbol: Expected 'GRAS_ANNOTE', got '%s'",gras_ddt_parse_text); + + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LP) + PARSE_ERROR1("Unparsable annotation: Expected parenthesis, got '%s'",gras_ddt_parse_text); + + while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY ); + + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) + PARSE_ERROR1("Unparsable annotation: Expected key name, got '%s'",gras_ddt_parse_text); + keyname = (char*)strdup(gras_ddt_parse_text); + + while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY ); + + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_COLON) + PARSE_ERROR1("Unparsable annotation: expected ',' after the key name, got '%s'",gras_ddt_parse_text); + + while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY ); + + /* get the value */ + + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) + PARSE_ERROR1("Unparsable annotation: Expected key value, got '%s'",gras_ddt_parse_text); + keyval = (char*)strdup(gras_ddt_parse_text); + + while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY ); + + /* Done with parsing the annotation. Now deal with it by replacing previously pushed type with the right one */ + + DEBUG2("Anotation: %s=%s",keyname,keyval); + if (!strcmp(keyname,"size")) { + 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")) { + change_to_ref(identifiers); + free(keyval); + } else { + char *p; + int fixed = 1; + for (p = keyval; *p != '\0'; p++) + if (! isdigit(*p) ) + fixed = 0; + if (fixed) { + change_to_fixed_array(identifiers,atoi(keyval)); + change_to_ref(identifiers); + free(keyval); + + } else { + change_to_ref_pop_array(identifiers); + xbt_dynar_push(fields_to_push,&keyval); + } + } + } else if (!strcmp(keyname,"subtype")) { + gras_datadesc_type_t subtype = gras_datadesc_by_name(keyval); + if (identifier.tm.is_matrix) { + change_to_matrix_of(identifiers,subtype); + identifier.tm.is_matrix = -1; + } else if (identifier.tm.is_dynar) { + change_to_dynar_of(identifiers,subtype); + identifier.tm.is_dynar = -1; + } else { + PARSE_ERROR1("subtype annotation only accepted for dynars and matrices, but passed to '%s'",identifier.type_name); + } + free(keyval); + } else if (!strcmp(keyname,"free_f")) { + int *storage=xbt_dict_get_or_null(gras_dd_constants,keyval); + if (!storage) + PARSE_ERROR1("value for free_f annotation of field %s is not a known constant",identifier.name); + if (identifier.tm.is_matrix == -1) { + add_free_f(identifiers,*(void_f_pvoid_t*)storage); + identifier.tm.is_matrix = 0; + } else if (identifier.tm.is_dynar == -1) { + add_free_f(identifiers,*(void_f_pvoid_t*)storage); + identifier.tm.is_dynar = 0; + } else { + PARSE_ERROR1("free_f annotation only accepted for dynars and matrices which subtype is already declared (field %s)", + identifier.name); + } + free(keyval); + } else { + free(keyval); + PARSE_ERROR1("Unknown annotation type: '%s'",keyname); + } + + /* Get all the multipliers */ + while (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) { + + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) + PARSE_ERROR1("Unparsable annotation: Expected field name after '*', got '%s'",gras_ddt_parse_text); + + keyval = xbt_malloc(strlen(gras_ddt_parse_text)+2); + sprintf(keyval,"*%s",gras_ddt_parse_text); + + /* ask caller to push field as a multiplier */ + xbt_dynar_push(fields_to_push,&keyval); + + /* skip blanks after this block*/ + while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) + == GRAS_DDT_PARSE_TOKEN_EMPTY ); + } + + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RP) + PARSE_ERROR1("Unparsable annotation: Expected parenthesis, got '%s'", + gras_ddt_parse_text); + + continue; + + /* End of annotation handling */ + } else { + PARSE_ERROR1("Unparsable symbol: Got '%s' instead of expected comma (',')",gras_ddt_parse_text); + } + } else if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_COLON) { + PARSE_ERROR0("Unparsable symbol: Unexpected comma (',')"); + } + + if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) { + identifier.tm.is_ref++; /* We indeed deal with multiple references with multiple annotations */ + continue; + } + + /* found a symbol name. Build the type and push it to dynar */ + if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { + + identifier.name=(char*)strdup(gras_ddt_parse_text); + DEBUG1("Found the identifier \"%s\"",identifier.name); + + xbt_dynar_push(identifiers, &identifier); + DEBUG1("Dynar_len=%lu",xbt_dynar_length(identifiers)); + expect_id_separator = 1; + continue; + } + + PARSE_ERROR0("Unparasable symbol (maybe a def struct in a def struct or a parser bug ;)"); } - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RP) - PARSE_ERROR1("Unparsable annotation: Expected parenthesis, got '%s'", - gras_ddt_parse_text); - - continue; - - /* End of annotation handling */ - } else { - PARSE_ERROR1("Unparsable symbol: Got '%s' instead of expected comma (',')",gras_ddt_parse_text); - } - } else if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_COLON) { - PARSE_ERROR0("Unparsable symbol: Unexpected comma (',')"); - } - - if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) { - identifier.tm.is_ref++; /* We indeed deal with multiple references with multiple annotations */ - continue; - } - - /* found a symbol name. Build the type and push it to dynar */ - if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { - - identifier.name=(char*)strdup(gras_ddt_parse_text); - DEBUG1("Found the identifier \"%s\"",identifier.name); - - xbt_dynar_push(identifiers, &identifier); - DEBUG1("Dynar_len=%lu",xbt_dynar_length(identifiers)); - expect_id_separator = 1; - continue; - } - - PARSE_ERROR0("Unparasable symbol (maybe a def struct in a def struct or a parser bug ;)"); - } - - if (identifier.tm.is_matrix>0) - PARSE_ERROR0("xbt_matrix_t field without 'subtype' annotation"); - if (identifier.tm.is_dynar>0) - PARSE_ERROR0("xbt_dynar_t field without 'subtype' annotation"); - - XBT_OUT; + if (identifier.tm.is_matrix>0) + PARSE_ERROR0("xbt_matrix_t field without 'subtype' annotation"); + if (identifier.tm.is_dynar>0) + PARSE_ERROR0("xbt_dynar_t field without 'subtype' annotation"); + + XBT_OUT; } static gras_datadesc_type_t parse_struct(char *definition) { - xbt_ex_t e; - - char buffname[32]; - static int anonymous_struct=0; - - xbt_dynar_t identifiers; - s_identifier_t field; - unsigned int iter; - int done; - - xbt_dynar_t fields_to_push; - char *name; - - gras_datadesc_type_t struct_type; - - XBT_IN; - identifiers = xbt_dynar_new(sizeof(s_identifier_t),NULL); - fields_to_push = xbt_dynar_new(sizeof(char*),NULL); - - /* Create the struct descriptor */ - if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { - struct_type = gras_datadesc_struct(gras_ddt_parse_text); - VERB1("Parse the struct '%s'", gras_ddt_parse_text); - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - } else { - sprintf(buffname,"anonymous struct %d",anonymous_struct++); - VERB1("Parse the anonymous struct nb %d", anonymous_struct); - struct_type = gras_datadesc_struct(buffname); - } - - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LA) - PARSE_ERROR1("Unparasable symbol: Expecting struct definition, but got %s instead of '{'", - gras_ddt_parse_text); - - /* Parse the identifiers */ - done = 0; - do { - TRY { - parse_statement(definition,identifiers,fields_to_push); - } CATCH(e) { - if (e.category != mismatch_error) - RETHROW; - xbt_ex_free(e); - done = 1; - } - - DEBUG1("This statement contained %lu identifiers",xbt_dynar_length(identifiers)); - /* append the identifiers we've found */ - xbt_dynar_foreach(identifiers,iter, field) { - if (field.tm.is_ref) - PARSE_ERROR2("Not enough GRAS_ANNOTATE to deal with all dereferencing levels of %s (%d '*' left)", - field.name,field.tm.is_ref); - - VERB2("Append field '%s' to %p",field.name, (void*)struct_type); - gras_datadesc_struct_append(struct_type, field.name, field.type); - free(field.name); - free(field.type_name); - - } - xbt_dynar_reset(identifiers); - DEBUG1("struct_type=%p",(void*)struct_type); - - /* Make sure that all fields declaring a size push it into the cbps */ - xbt_dynar_foreach(fields_to_push,iter, name) { - DEBUG1("struct_type=%p",(void*)struct_type); - if (name[0] == '*') { - VERB2("Push field '%s' as a multiplier into size stack of %p", - name+1, (void*)struct_type); - gras_datadesc_cb_field_push_multiplier(struct_type, name+1); - } else { - VERB2("Push field '%s' into size stack of %p", - name, (void*)struct_type); - gras_datadesc_cb_field_push(struct_type, name); - } - free(name); - } - xbt_dynar_reset(fields_to_push); - } while (!done); - gras_datadesc_struct_close(struct_type); - - /* terminates */ - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RA) - PARSE_ERROR1("Unparasable symbol: Expected '}' at the end of struct definition, got '%s'", - gras_ddt_parse_text); - - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - - xbt_dynar_free(&identifiers); - xbt_dynar_free(&fields_to_push); - XBT_OUT; - return struct_type; + xbt_ex_t e; + + char buffname[32]; + static int anonymous_struct=0; + + xbt_dynar_t identifiers; + s_identifier_t field; + unsigned int iter; + int done; + + xbt_dynar_t fields_to_push; + char *name; + + gras_datadesc_type_t struct_type; + + XBT_IN; + identifiers = xbt_dynar_new(sizeof(s_identifier_t),NULL); + fields_to_push = xbt_dynar_new(sizeof(char*),NULL); + + /* Create the struct descriptor */ + if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { + struct_type = gras_datadesc_struct(gras_ddt_parse_text); + VERB1("Parse the struct '%s'", gras_ddt_parse_text); + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + } else { + sprintf(buffname,"anonymous struct %d",anonymous_struct++); + VERB1("Parse the anonymous struct nb %d", anonymous_struct); + struct_type = gras_datadesc_struct(buffname); + } + + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LA) + PARSE_ERROR1("Unparasable symbol: Expecting struct definition, but got %s instead of '{'", + gras_ddt_parse_text); + + /* Parse the identifiers */ + done = 0; + do { + TRY { + parse_statement(definition,identifiers,fields_to_push); + } CATCH(e) { + if (e.category != mismatch_error) + RETHROW; + xbt_ex_free(e); + done = 1; + } + + DEBUG1("This statement contained %lu identifiers",xbt_dynar_length(identifiers)); + /* append the identifiers we've found */ + xbt_dynar_foreach(identifiers,iter, field) { + if (field.tm.is_ref) + PARSE_ERROR2("Not enough GRAS_ANNOTATE to deal with all dereferencing levels of %s (%d '*' left)", + field.name,field.tm.is_ref); + + VERB2("Append field '%s' to %p",field.name, (void*)struct_type); + gras_datadesc_struct_append(struct_type, field.name, field.type); + free(field.name); + free(field.type_name); + + } + xbt_dynar_reset(identifiers); + DEBUG1("struct_type=%p",(void*)struct_type); + + /* Make sure that all fields declaring a size push it into the cbps */ + xbt_dynar_foreach(fields_to_push,iter, name) { + DEBUG1("struct_type=%p",(void*)struct_type); + if (name[0] == '*') { + VERB2("Push field '%s' as a multiplier into size stack of %p", + name+1, (void*)struct_type); + gras_datadesc_cb_field_push_multiplier(struct_type, name+1); + } else { + VERB2("Push field '%s' into size stack of %p", + name, (void*)struct_type); + gras_datadesc_cb_field_push(struct_type, name); + } + free(name); + } + xbt_dynar_reset(fields_to_push); + } while (!done); + gras_datadesc_struct_close(struct_type); + + /* terminates */ + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RA) + PARSE_ERROR1("Unparasable symbol: Expected '}' at the end of struct definition, got '%s'", + gras_ddt_parse_text); + + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + + xbt_dynar_free(&identifiers); + xbt_dynar_free(&fields_to_push); + XBT_OUT; + return struct_type; } static gras_datadesc_type_t parse_typedef(char *definition) { - s_type_modifier_t tm; + s_type_modifier_t tm; - gras_datadesc_type_t struct_desc=NULL; - gras_datadesc_type_t typedef_desc=NULL; + gras_datadesc_type_t struct_desc=NULL; + gras_datadesc_type_t typedef_desc=NULL; - XBT_IN; - memset(&tm,0,sizeof(tm)); + XBT_IN; + memset(&tm,0,sizeof(tm)); - /* get the aliased type */ - parse_type_modifier(&tm); + /* get the aliased type */ + parse_type_modifier(&tm); - if (tm.is_struct) { - struct_desc = parse_struct(definition); - } + if (tm.is_struct) { + struct_desc = parse_struct(definition); + } - parse_type_modifier(&tm); + parse_type_modifier(&tm); - if (tm.is_ref) - PARSE_ERROR0("GRAS_DEFINE_TYPE cannot handle reference without annotation"); + if (tm.is_ref) + PARSE_ERROR0("GRAS_DEFINE_TYPE cannot handle reference without annotation"); - /* get the aliasing name */ - if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) - PARSE_ERROR1("Unparsable typedef: Expected the alias name, and got '%s'", - gras_ddt_parse_text); - - /* (FIXME: should) build the alias */ - PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle typedef yet"); + /* get the aliasing name */ + if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) + PARSE_ERROR1("Unparsable typedef: Expected the alias name, and got '%s'", + gras_ddt_parse_text); - XBT_OUT; - return typedef_desc; + /* (FIXME: should) build the alias */ + PARSE_ERROR0("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle typedef yet"); + + XBT_OUT; + return typedef_desc; } @@ -685,68 +685,68 @@ static gras_datadesc_type_t parse_typedef(char *definition) { * * Create a datadescription from the result of parsing the C type description */ -gras_datadesc_type_t +gras_datadesc_type_t gras_datadesc_parse(const char *name, - const char *C_statement) { - - gras_datadesc_type_t res=NULL; - char *definition; - int semicolon_count=0; - int def_count,C_count; - - XBT_IN; - /* reput the \n in place for debug */ - for (C_count=0; C_statement[C_count] != '\0'; C_count++) - if (C_statement[C_count] == ';' || C_statement[C_count] == '{') - semicolon_count++; - definition = (char*)xbt_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] == '{') { - definition[def_count++] = '\n'; - } - } - definition[def_count] = '\0'; - - /* init */ - VERB2("_gras_ddt_type_parse(%s) -> %d chars",definition, def_count); - gras_ddt_parse_pointer_string_init(definition); - - /* Do I have a typedef, or a raw struct ?*/ - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - - if ((gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) && (!strcmp(gras_ddt_parse_text,"struct"))) { - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - res = parse_struct(definition); - - } else if ((gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) && (!strcmp(gras_ddt_parse_text,"typedef"))) { - gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); - res = parse_typedef(definition); - - } else { - ERROR1("Failed to parse the following symbol (not a struct neither a typedef) :\n%s",definition); - xbt_abort(); - } - - gras_ddt_parse_pointer_string_close(); - VERB0("end of _gras_ddt_type_parse()"); - 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)", - name,res->name); - xbt_abort(); - } - gras_ddt_parse_lex_destroy(); - XBT_OUT; - return res; + const char *C_statement) { + + gras_datadesc_type_t res=NULL; + char *definition; + int semicolon_count=0; + int def_count,C_count; + + XBT_IN; + /* reput the \n in place for debug */ + for (C_count=0; C_statement[C_count] != '\0'; C_count++) + if (C_statement[C_count] == ';' || C_statement[C_count] == '{') + semicolon_count++; + definition = (char*)xbt_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] == '{') { + definition[def_count++] = '\n'; + } + } + definition[def_count] = '\0'; + + /* init */ + VERB2("_gras_ddt_type_parse(%s) -> %d chars",definition, def_count); + gras_ddt_parse_pointer_string_init(definition); + + /* Do I have a typedef, or a raw struct ?*/ + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + + if ((gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) && (!strcmp(gras_ddt_parse_text,"struct"))) { + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + res = parse_struct(definition); + + } else if ((gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) && (!strcmp(gras_ddt_parse_text,"typedef"))) { + gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); + res = parse_typedef(definition); + + } else { + ERROR1("Failed to parse the following symbol (not a struct neither a typedef) :\n%s",definition); + xbt_abort(); + } + + gras_ddt_parse_pointer_string_close(); + VERB0("end of _gras_ddt_type_parse()"); + 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)", + name,res->name); + xbt_abort(); + } + gras_ddt_parse_lex_destroy(); + XBT_OUT; + return res; } xbt_dict_t gras_dd_constants; /** \brief Declare a constant to the parsing mecanism. See the "\#define and fixed size array" section */ void gras_datadesc_set_const(const char*name, int value) { - int *stored = xbt_new(int, 1); - *stored=value; + int *stored = xbt_new(int, 1); + *stored=value; - xbt_dict_set(gras_dd_constants,name, stored, xbt_free_f); + xbt_dict_set(gras_dd_constants,name, stored, xbt_free_f); } diff --git a/src/gras/Msg/gras_msg_listener.c b/src/gras/Msg/gras_msg_listener.c index c7f4099fd5..9acc235326 100644 --- a/src/gras/Msg/gras_msg_listener.c +++ b/src/gras/Msg/gras_msg_listener.c @@ -18,102 +18,102 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_msg_read,gras_msg,"Message reader thread"); #include "gras/Transport/transport_interface.h" /* gras_select */ typedef struct s_gras_msg_listener_ { - xbt_queue_t incomming_messages; - xbt_queue_t socks_to_close; /* let the listener close the sockets, since it may be selecting on them. Darwin don't like this trick */ - gras_socket_t wakeup_sock_listener_side; - gras_socket_t wakeup_sock_master_side; - xbt_thread_t listener; + xbt_queue_t incomming_messages; + xbt_queue_t socks_to_close; /* let the listener close the sockets, since it may be selecting on them. Darwin don't like this trick */ + gras_socket_t wakeup_sock_listener_side; + gras_socket_t wakeup_sock_master_side; + xbt_thread_t listener; } s_gras_msg_listener_t; static void listener_function(void *p) { - gras_msg_listener_t me = (gras_msg_listener_t)p; - s_gras_msg_t msg; - xbt_ex_t e; - gras_msgtype_t msg_wakeup_listener_t = gras_msgtype_by_name("_wakeup_listener"); - DEBUG0("I'm the listener"); - while (1) { - DEBUG0("Selecting"); - msg.expe = gras_trp_select(-1); - DEBUG0("Select returned something"); - gras_msg_recv(msg.expe, &msg); - if (msg.type!=msg_wakeup_listener_t) - xbt_queue_push(me->incomming_messages, &msg); - else { - char got = *(char*)msg.payl; - if (got == '1') { - VERB0("Asked to get awake"); - free(msg.payl); - } else { - VERB0("Asked to die"); -// gras_socket_close(me->wakeup_sock_listener_side); - free(msg.payl); - return ; - } - } - /* empty the list of sockets to trash */ - TRY { + gras_msg_listener_t me = (gras_msg_listener_t)p; + s_gras_msg_t msg; + xbt_ex_t e; + gras_msgtype_t msg_wakeup_listener_t = gras_msgtype_by_name("_wakeup_listener"); + DEBUG0("I'm the listener"); while (1) { - int sock; - xbt_queue_shift_timed(me->socks_to_close,&sock,0); - if(tcp_close(sock) < 0) { - WARN3("error while closing tcp socket %d: %d (%s)\n", - sock, sock_errno, sock_errstr(sock_errno)); - } + DEBUG0("Selecting"); + msg.expe = gras_trp_select(-1); + DEBUG0("Select returned something"); + gras_msg_recv(msg.expe, &msg); + if (msg.type!=msg_wakeup_listener_t) + xbt_queue_push(me->incomming_messages, &msg); + else { + char got = *(char*)msg.payl; + if (got == '1') { + VERB0("Asked to get awake"); + free(msg.payl); + } else { + VERB0("Asked to die"); + // gras_socket_close(me->wakeup_sock_listener_side); + free(msg.payl); + return ; + } + } + /* empty the list of sockets to trash */ + TRY { + while (1) { + int sock; + xbt_queue_shift_timed(me->socks_to_close,&sock,0); + if(tcp_close(sock) < 0) { + WARN3("error while closing tcp socket %d: %d (%s)\n", + sock, sock_errno, sock_errstr(sock_errno)); + } + } + } CATCH(e) { + if (e.category != timeout_error) + RETHROW; + xbt_ex_free(e); + } } - } CATCH(e) { - if (e.category != timeout_error) - RETHROW; - xbt_ex_free(e); - } - } } gras_msg_listener_t gras_msg_listener_launch(xbt_queue_t msg_exchange){ - gras_msg_listener_t arg = xbt_new0(s_gras_msg_listener_t,1); - int my_port; - - DEBUG0("Launch listener"); - arg->incomming_messages = msg_exchange; - arg->socks_to_close = xbt_queue_new(0,sizeof(int)); - - /* get a free socket for the receiving part of the listener, taking care that it does not get saved as "myport" number */ - my_port = ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->myport; - arg->wakeup_sock_listener_side=gras_socket_server_range(5000,6000,-1,0); - ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->myport = my_port; - /* Connect the other part of the socket */ - arg->wakeup_sock_master_side=gras_socket_client(gras_os_myname(),gras_socket_my_port(arg->wakeup_sock_listener_side)); - - /* declare the message used to awake the listener from the master */ - gras_msgtype_declare("_wakeup_listener",gras_datadesc_by_name("char")); - - /* actually start the thread */ - arg->listener = xbt_thread_create("listener",listener_function,arg); - gras_os_sleep(0); /* TODO: useless? give the listener a chance to initialize even if the main is empty and we cancel it right afterward */ - return arg; + gras_msg_listener_t arg = xbt_new0(s_gras_msg_listener_t,1); + int my_port; + + DEBUG0("Launch listener"); + arg->incomming_messages = msg_exchange; + arg->socks_to_close = xbt_queue_new(0,sizeof(int)); + + /* get a free socket for the receiving part of the listener, taking care that it does not get saved as "myport" number */ + my_port = ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->myport; + arg->wakeup_sock_listener_side=gras_socket_server_range(5000,6000,-1,0); + ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->myport = my_port; + /* Connect the other part of the socket */ + arg->wakeup_sock_master_side=gras_socket_client(gras_os_myname(),gras_socket_my_port(arg->wakeup_sock_listener_side)); + + /* declare the message used to awake the listener from the master */ + gras_msgtype_declare("_wakeup_listener",gras_datadesc_by_name("char")); + + /* actually start the thread */ + arg->listener = xbt_thread_create("listener",listener_function,arg); + gras_os_sleep(0); /* TODO: useless? give the listener a chance to initialize even if the main is empty and we cancel it right afterward */ + return arg; } #include "gras/Virtu/virtu_private.h" /* procdata_t content */ void gras_msg_listener_shutdown(gras_msg_listener_t l) { - gras_procdata_t *pd = gras_procdata_get(); - char kill = '0'; - DEBUG0("Listener quit"); - - - if (pd->listener) - gras_msg_send(pd->listener->wakeup_sock_master_side,"_wakeup_listener",&kill); - - /* FIXME: thread_join is not implemented in SG (remove next conditional when fixed) - * But I guess it's not a big deal since we're terminating the thread mainly to - * make it free its OS locks on darwin. - * darwin is definitly different from the neat & nice SG world */ - if (gras_if_RL()) - xbt_thread_join(pd->listener->listener); - -// gras_socket_close(pd->listener->wakeup_sock_master_side); FIXME: uncommenting this leads to deadlock at terminaison - xbt_queue_free(&l->incomming_messages); - xbt_queue_free(&l->socks_to_close); - xbt_free(l); + gras_procdata_t *pd = gras_procdata_get(); + char kill = '0'; + DEBUG0("Listener quit"); + + + if (pd->listener) + gras_msg_send(pd->listener->wakeup_sock_master_side,"_wakeup_listener",&kill); + + /* FIXME: thread_join is not implemented in SG (remove next conditional when fixed) + * But I guess it's not a big deal since we're terminating the thread mainly to + * make it free its OS locks on darwin. + * darwin is definitly different from the neat & nice SG world */ + if (gras_if_RL()) + xbt_thread_join(pd->listener->listener); + + // gras_socket_close(pd->listener->wakeup_sock_master_side); FIXME: uncommenting this leads to deadlock at terminaison + xbt_queue_free(&l->incomming_messages); + xbt_queue_free(&l->socks_to_close); + xbt_free(l); } void gras_msg_listener_awake(){ @@ -127,12 +127,12 @@ void gras_msg_listener_awake(){ } } void gras_msg_listener_close_socket(int sd) { - gras_procdata_t *pd = gras_procdata_get(); - if (pd->listener) { - xbt_queue_push(pd->listener->socks_to_close,&sd); - gras_msg_listener_awake(); - } else { - /* do it myself */ - tcp_close(sd); - } + gras_procdata_t *pd = gras_procdata_get(); + if (pd->listener) { + xbt_queue_push(pd->listener->socks_to_close,&sd); + gras_msg_listener_awake(); + } else { + /* do it myself */ + tcp_close(sd); + } } diff --git a/src/gras/Msg/gras_msg_mod.c b/src/gras/Msg/gras_msg_mod.c index 185a07e78d..580a29909e 100644 --- a/src/gras/Msg/gras_msg_mod.c +++ b/src/gras/Msg/gras_msg_mod.c @@ -20,36 +20,36 @@ extern xbt_set_t _gras_msgtype_set; * Creating procdata for this module */ static void *gras_msg_procdata_new(void) { - gras_msg_procdata_t res = xbt_new(s_gras_msg_procdata_t,1); - - res->name = xbt_strdup("gras_msg"); - res->name_len = 0; - res->msg_queue = xbt_dynar_new(sizeof(s_gras_msg_t), NULL); - res->msg_waitqueue = xbt_dynar_new(sizeof(s_gras_msg_t), NULL); - res->cbl_list = xbt_dynar_new(sizeof(gras_cblist_t *),gras_cbl_free); - res->timers = xbt_dynar_new(sizeof(s_gras_timer_t), NULL); - res->msg_to_receive_queue = xbt_fifo_new(); - res->msg_to_receive_queue_meas = xbt_fifo_new(); - res->msg_received = xbt_queue_new(0,sizeof(s_gras_msg_t)); - - return (void*)res; + gras_msg_procdata_t res = xbt_new(s_gras_msg_procdata_t,1); + + res->name = xbt_strdup("gras_msg"); + res->name_len = 0; + res->msg_queue = xbt_dynar_new(sizeof(s_gras_msg_t), NULL); + res->msg_waitqueue = xbt_dynar_new(sizeof(s_gras_msg_t), NULL); + res->cbl_list = xbt_dynar_new(sizeof(gras_cblist_t *),gras_cbl_free); + res->timers = xbt_dynar_new(sizeof(s_gras_timer_t), NULL); + res->msg_to_receive_queue = xbt_fifo_new(); + res->msg_to_receive_queue_meas = xbt_fifo_new(); + res->msg_received = xbt_queue_new(0,sizeof(s_gras_msg_t)); + + return (void*)res; } /* * Freeing procdata for this module */ static void gras_msg_procdata_free(void *data) { - gras_msg_procdata_t res = (gras_msg_procdata_t)data; - - xbt_dynar_free(&( res->msg_queue )); - xbt_dynar_free(&( res->msg_waitqueue )); - xbt_dynar_free(&( res->cbl_list )); - xbt_dynar_free(&( res->timers )); - xbt_fifo_free( res->msg_to_receive_queue ); - xbt_fifo_free( res->msg_to_receive_queue_meas ); - - free(res->name); - free(res); + gras_msg_procdata_t res = (gras_msg_procdata_t)data; + + xbt_dynar_free(&( res->msg_queue )); + xbt_dynar_free(&( res->msg_waitqueue )); + xbt_dynar_free(&( res->cbl_list )); + xbt_dynar_free(&( res->timers )); + xbt_fifo_free( res->msg_to_receive_queue ); + xbt_fifo_free( res->msg_to_receive_queue_meas ); + + free(res->name); + free(res); } /* @@ -57,30 +57,30 @@ static void gras_msg_procdata_free(void *data) { */ int gras_msg_libdata_id; void gras_msg_register() { - gras_msg_libdata_id = gras_procdata_add("gras_msg",gras_msg_procdata_new, gras_msg_procdata_free); + gras_msg_libdata_id = gras_procdata_add("gras_msg",gras_msg_procdata_new, gras_msg_procdata_free); } /* * Initialize this submodule. */ void gras_msg_init(void) { - /* only initialize once */ - if (_gras_msgtype_set != NULL) - return; - - VERB0("Initializing Msg"); - - _gras_msgtype_set = xbt_set_new(); - - memcpy(_GRAS_header,"GRAS", 4); - _GRAS_header[4]=GRAS_PROTOCOL_VERSION; - _GRAS_header[5]=(char)GRAS_THISARCH; - - gras_msg_ctx_mallocator = - xbt_mallocator_new(1000, - gras_msg_ctx_mallocator_new_f, - gras_msg_ctx_mallocator_free_f, - gras_msg_ctx_mallocator_reset_f); + /* only initialize once */ + if (_gras_msgtype_set != NULL) + return; + + VERB0("Initializing Msg"); + + _gras_msgtype_set = xbt_set_new(); + + memcpy(_GRAS_header,"GRAS", 4); + _GRAS_header[4]=GRAS_PROTOCOL_VERSION; + _GRAS_header[5]=(char)GRAS_THISARCH; + + gras_msg_ctx_mallocator = + xbt_mallocator_new(1000, + gras_msg_ctx_mallocator_new_f, + gras_msg_ctx_mallocator_free_f, + gras_msg_ctx_mallocator_reset_f); } /* @@ -88,9 +88,9 @@ void gras_msg_init(void) { */ void gras_msg_exit(void) { - VERB0("Exiting Msg"); - xbt_set_free(&_gras_msgtype_set); + VERB0("Exiting Msg"); + xbt_set_free(&_gras_msgtype_set); - xbt_mallocator_free(gras_msg_ctx_mallocator); + xbt_mallocator_free(gras_msg_ctx_mallocator); } diff --git a/src/gras/Msg/gras_msg_types.c b/src/gras/Msg/gras_msg_types.c index 374b3fed22..824da04dcf 100644 --- a/src/gras/Msg/gras_msg_types.c +++ b/src/gras/Msg/gras_msg_types.c @@ -25,102 +25,102 @@ xbt_set_t _gras_msgtype_set = NULL; /* Reclamed memory */ void gras_msgtype_free(void *t) { - gras_msgtype_t msgtype=(gras_msgtype_t)t; - if (msgtype) { - free(msgtype->name); - free(msgtype); - } + gras_msgtype_t msgtype=(gras_msgtype_t)t; + if (msgtype) { + free(msgtype->name); + free(msgtype); + } } /** * Dump all declared message types (debugging purpose) */ -void gras_msgtype_dumpall(void) { - xbt_set_cursor_t cursor; - gras_msgtype_t msgtype=NULL; - - INFO0("Dump of all registered messages:"); - xbt_set_foreach(_gras_msgtype_set, cursor, msgtype) { - INFO6(" Message name: %s (v%d) %s; %s%s%s", - msgtype->name, msgtype->version, e_gras_msg_kind_names[msgtype->kind], - gras_datadesc_get_name(msgtype->ctn_type), - (msgtype->kind==e_gras_msg_kind_rpccall ? " -> ":""), - (msgtype->kind==e_gras_msg_kind_rpccall ? gras_datadesc_get_name(msgtype->answer_type) : "")); - } +void gras_msgtype_dumpall(void) { + xbt_set_cursor_t cursor; + gras_msgtype_t msgtype=NULL; + + INFO0("Dump of all registered messages:"); + xbt_set_foreach(_gras_msgtype_set, cursor, msgtype) { + INFO6(" Message name: %s (v%d) %s; %s%s%s", + msgtype->name, msgtype->version, e_gras_msg_kind_names[msgtype->kind], + gras_datadesc_get_name(msgtype->ctn_type), + (msgtype->kind==e_gras_msg_kind_rpccall ? " -> ":""), + (msgtype->kind==e_gras_msg_kind_rpccall ? gras_datadesc_get_name(msgtype->answer_type) : "")); + } } /** * make_namev: * - * Returns the versionned name of the message. + * Returns the versionned name of the message. * It's a newly allocated string, make sure to free it. */ static char *make_namev(const char *name, short int ver) { - if (!ver) - return xbt_strdup(name); + if (!ver) + return xbt_strdup(name); - return bprintf("%s_v%d",name,ver); + return bprintf("%s_v%d",name,ver); } /* Internal function doing the crude work of registering messages */ -void +void gras_msgtype_declare_ext(const char *name, - short int version, - e_gras_msg_kind_t kind, - gras_datadesc_type_t payload_request, - gras_datadesc_type_t payload_answer) { - - gras_msgtype_t msgtype=NULL; - char *namev=make_namev(name,version); - volatile int found = 0; - xbt_ex_t e; - - TRY { - msgtype = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set,namev); - found = 1; - } CATCH(e) { - if (e.category != not_found_error) { - xbt_free(namev); - RETHROW; - } - xbt_ex_free(e); - } - - if (found) { - VERB2("Re-register version %d of message '%s' (same kind & payload, ignored).", - version, name); - xbt_assert3(msgtype->kind == kind, - "Message %s re-registered as a %s (it was known as a %s)", - namev,e_gras_msg_kind_names[kind],e_gras_msg_kind_names[msgtype->kind]); - xbt_assert3(!gras_datadesc_type_cmp(msgtype->ctn_type, payload_request), - "Message %s re-registred with another payload (%s was %s)", - namev,gras_datadesc_get_name(payload_request), - gras_datadesc_get_name(msgtype->ctn_type)); - - xbt_assert3(!gras_datadesc_type_cmp(msgtype->answer_type, payload_answer), - "Message %s re-registred with another answer payload (%s was %s)", - namev,gras_datadesc_get_name(payload_answer), - gras_datadesc_get_name(msgtype->answer_type)); - - xbt_free(namev); - return ; /* do really ignore it */ - } - - VERB4("Register version %d of message '%s' " - "(payload: %s; answer payload: %s).", - version, name, gras_datadesc_get_name(payload_request), - gras_datadesc_get_name(payload_answer)); - - msgtype = xbt_new(s_gras_msgtype_t,1); - msgtype->name = namev; - msgtype->name_len = strlen(namev); - msgtype->version = version; - msgtype->kind = kind; - msgtype->ctn_type = payload_request; - msgtype->answer_type = payload_answer; - - xbt_set_add(_gras_msgtype_set, (xbt_set_elm_t)msgtype, - &gras_msgtype_free); + short int version, + e_gras_msg_kind_t kind, + gras_datadesc_type_t payload_request, + gras_datadesc_type_t payload_answer) { + + gras_msgtype_t msgtype=NULL; + char *namev=make_namev(name,version); + volatile int found = 0; + xbt_ex_t e; + + TRY { + msgtype = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set,namev); + found = 1; + } CATCH(e) { + if (e.category != not_found_error) { + xbt_free(namev); + RETHROW; + } + xbt_ex_free(e); + } + + if (found) { + VERB2("Re-register version %d of message '%s' (same kind & payload, ignored).", + version, name); + xbt_assert3(msgtype->kind == kind, + "Message %s re-registered as a %s (it was known as a %s)", + namev,e_gras_msg_kind_names[kind],e_gras_msg_kind_names[msgtype->kind]); + xbt_assert3(!gras_datadesc_type_cmp(msgtype->ctn_type, payload_request), + "Message %s re-registred with another payload (%s was %s)", + namev,gras_datadesc_get_name(payload_request), + gras_datadesc_get_name(msgtype->ctn_type)); + + xbt_assert3(!gras_datadesc_type_cmp(msgtype->answer_type, payload_answer), + "Message %s re-registred with another answer payload (%s was %s)", + namev,gras_datadesc_get_name(payload_answer), + gras_datadesc_get_name(msgtype->answer_type)); + + xbt_free(namev); + return ; /* do really ignore it */ + } + + VERB4("Register version %d of message '%s' " + "(payload: %s; answer payload: %s).", + version, name, gras_datadesc_get_name(payload_request), + gras_datadesc_get_name(payload_answer)); + + msgtype = xbt_new(s_gras_msgtype_t,1); + msgtype->name = namev; + msgtype->name_len = strlen(namev); + msgtype->version = version; + msgtype->kind = kind; + msgtype->ctn_type = payload_request; + msgtype->answer_type = payload_answer; + + xbt_set_add(_gras_msgtype_set, (xbt_set_elm_t)msgtype, + &gras_msgtype_free); } @@ -130,8 +130,8 @@ gras_msgtype_declare_ext(const char *name, * @param payload: datadescription of the payload */ void gras_msgtype_declare(const char *name, - gras_datadesc_type_t payload) { - gras_msgtype_declare_ext(name, 0, e_gras_msg_kind_oneway, payload, NULL); + gras_datadesc_type_t payload) { + gras_msgtype_declare_ext(name, 0, e_gras_msg_kind_oneway, payload, NULL); } @@ -142,63 +142,63 @@ void gras_msgtype_declare(const char *name, * @param version: something like versionning symbol * @param payload: datadescription of the payload * - * Registers a message to the GRAS mechanism. Use this version instead of + * Registers a message to the GRAS mechanism. Use this version instead of * gras_msgtype_declare when you change the semantic or syntax of a message and * want your programs to be able to deal with both versions. Internally, each - * will be handled as an independent message type, so you can register + * will be handled as an independent message type, so you can register * differents for each of them. */ void gras_msgtype_declare_v(const char *name, - short int version, - gras_datadesc_type_t payload) { - - gras_msgtype_declare_ext(name, version, - e_gras_msg_kind_oneway, payload, NULL); + short int version, + gras_datadesc_type_t payload) { + + gras_msgtype_declare_ext(name, version, + e_gras_msg_kind_oneway, payload, NULL); } /** @brief retrieve an existing message type from its name (raises an exception if it does not exist). */ gras_msgtype_t gras_msgtype_by_name (const char *name) { - return gras_msgtype_by_namev(name,0); + return gras_msgtype_by_namev(name,0); } /** @brief retrieve an existing message type from its name (or NULL if it does not exist). */ gras_msgtype_t gras_msgtype_by_name_or_null (const char *name) { - xbt_ex_t e; - gras_msgtype_t res = NULL; - - TRY { - res = gras_msgtype_by_namev(name,0); - } CATCH(e) { - res = NULL; - xbt_ex_free(e); - } - return res; + xbt_ex_t e; + gras_msgtype_t res = NULL; + + TRY { + res = gras_msgtype_by_namev(name,0); + } CATCH(e) { + res = NULL; + xbt_ex_free(e); + } + return res; } /** @brief retrieve an existing message type from its name and version. */ gras_msgtype_t gras_msgtype_by_namev(const char *name, - short int version) { - gras_msgtype_t res = NULL; - char *namev = make_namev(name,version); - volatile int found=0; - xbt_ex_t e; - - TRY { - res = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set, namev); - found=1; - } CATCH(e) { - xbt_ex_free(e); - } - if (!found) - THROW1(not_found_error,0,"No registred message of that name: %s",name); - - free(namev); - - return res; + short int version) { + gras_msgtype_t res = NULL; + char *namev = make_namev(name,version); + volatile int found=0; + xbt_ex_t e; + + TRY { + res = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set, namev); + found=1; + } CATCH(e) { + xbt_ex_free(e); + } + if (!found) + THROW1(not_found_error,0,"No registred message of that name: %s",name); + + free(namev); + + return res; } /** @brief retrieve an existing message type from its name and version. */ gras_msgtype_t gras_msgtype_by_id(int id) { - return (gras_msgtype_t)xbt_set_get_by_id(_gras_msgtype_set, id); + return (gras_msgtype_t)xbt_set_get_by_id(_gras_msgtype_set, id); } @@ -208,108 +208,108 @@ gras_msgtype_t gras_msgtype_by_id(int id) { /* ******************************************************************** */ void gras_cbl_free(void *data){ - gras_cblist_t *list=*(void**)data; - if (list) { - xbt_dynar_free(&( list->cbs )); - free(list); - } + gras_cblist_t *list=*(void**)data; + if (list) { + xbt_dynar_free(&( list->cbs )); + free(list); + } } -/** \brief Bind the given callback to the given message type +/** \brief Bind the given callback to the given message type * - * Several callbacks can be attached to a given message type. - * The lastly added one will get the message first, and + * Several callbacks can be attached to a given message type. + * The lastly added one will get the message first, and * if it returns a non-null value, the message will be passed to the * second one. And so on until one of the callbacks accepts the message. */ void gras_cb_register_(gras_msgtype_t msgtype, - gras_msg_cb_t cb) { - gras_msg_procdata_t pd= - (gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - gras_cblist_t *list=NULL; - unsigned int cpt; - - DEBUG2("Register %p as callback to '%s'",cb,msgtype->name); - - /* search the list of cb for this message on this host (creating if NULL) */ - xbt_dynar_foreach(pd->cbl_list,cpt,list) { - if (list->id == msgtype->code) { - break; - } else { - list=NULL; - } - } - if (!list) { - /* First cb? Create room */ - list = xbt_new(gras_cblist_t,1); - list->id = msgtype->code; - list->cbs = xbt_dynar_new(sizeof(gras_msg_cb_t), NULL); - xbt_dynar_push(pd->cbl_list,&list); - } - - /* Insert the new one into the set */ - xbt_dynar_insert_at(list->cbs,0,&cb); + gras_msg_cb_t cb) { + gras_msg_procdata_t pd= + (gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + gras_cblist_t *list=NULL; + unsigned int cpt; + + DEBUG2("Register %p as callback to '%s'",cb,msgtype->name); + + /* search the list of cb for this message on this host (creating if NULL) */ + xbt_dynar_foreach(pd->cbl_list,cpt,list) { + if (list->id == msgtype->code) { + break; + } else { + list=NULL; + } + } + if (!list) { + /* First cb? Create room */ + list = xbt_new(gras_cblist_t,1); + list->id = msgtype->code; + list->cbs = xbt_dynar_new(sizeof(gras_msg_cb_t), NULL); + xbt_dynar_push(pd->cbl_list,&list); + } + + /* Insert the new one into the set */ + xbt_dynar_insert_at(list->cbs,0,&cb); } /** \brief Unbind the given callback from the given message type */ void gras_cb_unregister_(gras_msgtype_t msgtype, - gras_msg_cb_t cb) { - - gras_msg_procdata_t pd= - (gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - gras_cblist_t *list; - gras_msg_cb_t cb_cpt; - unsigned int cpt; - int found = 0; - - /* search the list of cb for this message on this host */ - xbt_dynar_foreach(pd->cbl_list,cpt,list) { - if (list->id == msgtype->code) { - break; - } else { - list=NULL; - } - } - - /* Remove it from the set */ - if (list) { - xbt_dynar_foreach(list->cbs,cpt,cb_cpt) { - if (cb == cb_cpt) { - xbt_dynar_cursor_rm(list->cbs, &cpt); - found = 1; - } - } - } - if (!found) - VERB1("Ignoring removal of unexisting callback to msg id %d", - msgtype->code); + gras_msg_cb_t cb) { + + gras_msg_procdata_t pd= + (gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + gras_cblist_t *list; + gras_msg_cb_t cb_cpt; + unsigned int cpt; + int found = 0; + + /* search the list of cb for this message on this host */ + xbt_dynar_foreach(pd->cbl_list,cpt,list) { + if (list->id == msgtype->code) { + break; + } else { + list=NULL; + } + } + + /* Remove it from the set */ + if (list) { + xbt_dynar_foreach(list->cbs,cpt,cb_cpt) { + if (cb == cb_cpt) { + xbt_dynar_cursor_rm(list->cbs, &cpt); + found = 1; + } + } + } + if (!found) + VERB1("Ignoring removal of unexisting callback to msg id %d", + msgtype->code); } /** \brief Retrieve the expeditor of the message */ gras_socket_t gras_msg_cb_ctx_from(gras_msg_cb_ctx_t ctx) { - return ctx->expeditor; + return ctx->expeditor; } /* \brief Creates a new message exchange context (user should never have to) */ -gras_msg_cb_ctx_t gras_msg_cb_ctx_new(gras_socket_t expe, - gras_msgtype_t msgtype, - unsigned long int ID, - int answer_due, - double timeout) { - gras_msg_cb_ctx_t res=xbt_new(s_gras_msg_cb_ctx_t,1); - res->expeditor = expe; - res->msgtype = msgtype; - res->ID = ID; - res->timeout = timeout; - res->answer_due = answer_due; - - return res; +gras_msg_cb_ctx_t gras_msg_cb_ctx_new(gras_socket_t expe, + gras_msgtype_t msgtype, + unsigned long int ID, + int answer_due, + double timeout) { + gras_msg_cb_ctx_t res=xbt_new(s_gras_msg_cb_ctx_t,1); + res->expeditor = expe; + res->msgtype = msgtype; + res->ID = ID; + res->timeout = timeout; + res->answer_due = answer_due; + + return res; } -/* \brief Frees a message exchange context +/* \brief Frees a message exchange context * * This function is mainly useful with \ref gras_msg_wait_or, ie seldom. */ void gras_msg_cb_ctx_free(gras_msg_cb_ctx_t ctx) { - free(ctx); + free(ctx); } diff --git a/src/gras/Msg/msg_interface.h b/src/gras/Msg/msg_interface.h index ad28838d35..09df7c8738 100644 --- a/src/gras/Msg/msg_interface.h +++ b/src/gras/Msg/msg_interface.h @@ -21,22 +21,22 @@ * FIXME: it could be cleaned up ? */ typedef struct { - /* set headers */ - unsigned int ID; - char *name; - unsigned int name_len; + /* set headers */ + unsigned int ID; + char *name; + unsigned int name_len; - /* queue storing the msgs got while msg_wait'ing for something else. Reuse them ASAP. */ - xbt_dynar_t msg_queue; /* elm type: s_gras_msg_t */ + /* queue storing the msgs got while msg_wait'ing for something else. Reuse them ASAP. */ + xbt_dynar_t msg_queue; /* elm type: s_gras_msg_t */ - /* queue storing the msgs without callback got when handling. Feed them to wait() */ - xbt_dynar_t msg_waitqueue; /* elm type: s_gras_msg_t */ + /* queue storing the msgs without callback got when handling. Feed them to wait() */ + xbt_dynar_t msg_waitqueue; /* elm type: s_gras_msg_t */ - /* registered callbacks for each message */ - xbt_dynar_t cbl_list; /* elm type: gras_cblist_t */ + /* registered callbacks for each message */ + xbt_dynar_t cbl_list; /* elm type: gras_cblist_t */ - /* registered timers */ - xbt_dynar_t timers; /* elm type: s_gras_timer_t */ + /* registered timers */ + xbt_dynar_t timers; /* elm type: s_gras_timer_t */ /* queue storing the msgs that have to received and the process synchronization made (wait the surf action done) */ xbt_fifo_t msg_to_receive_queue; /* elm type: s_gras_msg_t */ @@ -47,11 +47,11 @@ typedef struct { void gras_msg_send_namev(gras_socket_t sock, - const char *namev, - void *payload); + const char *namev, + void *payload); void gras_msg_listener_awake(void); void gras_msg_listener_close_socket(int sd); - + #define GRAS_PROTOCOL_VERSION '\0'; diff --git a/src/gras/Msg/msg_private.h b/src/gras/Msg/msg_private.h index 0bc3c5cc8d..fca96b5f74 100644 --- a/src/gras/Msg/msg_private.h +++ b/src/gras/Msg/msg_private.h @@ -32,16 +32,16 @@ extern char _GRAS_header[6]; extern int gras_msg_libdata_id; /* The identifier of our libdata */ - + extern const char *e_gras_msg_kind_names[e_gras_msg_kind_count]; /* declare either regular messages or RPC or whatever */ -void +void gras_msgtype_declare_ext(const char *name, - short int version, - e_gras_msg_kind_t kind, - gras_datadesc_type_t payload_request, - gras_datadesc_type_t payload_answer); + short int version, + e_gras_msg_kind_t kind, + gras_datadesc_type_t payload_request, + gras_datadesc_type_t payload_answer); /** * gras_msgtype_t: @@ -49,16 +49,16 @@ gras_msgtype_declare_ext(const char *name, * Message type descriptor. There one of these for each registered version. */ typedef struct s_gras_msgtype { - /* headers for the data set */ - unsigned int code; - char *name; - unsigned int name_len; - - /* payload */ - short int version; - e_gras_msg_kind_t kind; - gras_datadesc_type_t ctn_type; - gras_datadesc_type_t answer_type; /* only used for RPC */ + /* headers for the data set */ + unsigned int code; + char *name; + unsigned int name_len; + + /* payload */ + short int version; + e_gras_msg_kind_t kind; + gras_datadesc_type_t ctn_type; + gras_datadesc_type_t answer_type; /* only used for RPC */ } s_gras_msgtype_t; extern xbt_set_t _gras_msgtype_set; /* of gras_msgtype_t */ @@ -67,12 +67,12 @@ void gras_msgtype_free(void *msgtype); /* functions to extract msg from socket or put it on wire (depend RL vs SG) */ void gras_msg_recv(gras_socket_t sock, - gras_msg_t msg/*OUT*/); + gras_msg_t msg/*OUT*/); void gras_msg_send_ext(gras_socket_t sock, - e_gras_msg_kind_t kind, - unsigned long int ID, - gras_msgtype_t msgtype, - void *payload); + e_gras_msg_kind_t kind, + unsigned long int ID, + gras_msgtype_t msgtype, + void *payload); /* The thread in charge of receiving messages and queuing them */ typedef struct s_gras_msg_listener_ *gras_msg_listener_t; @@ -87,8 +87,8 @@ void gras_msg_listener_shutdown(gras_msg_listener_t); * association between msg ID and cb list for a given process */ struct s_gras_cblist { - long int id; - xbt_dynar_t cbs; /* of gras_msg_cb_t */ + long int id; + xbt_dynar_t cbs; /* of gras_msg_cb_t */ }; typedef struct s_gras_cblist gras_cblist_t; @@ -101,11 +101,11 @@ void gras_cblist_free(void *cbl); * Context associated to a given callback (to either regular message or RPC) */ struct s_gras_msg_cb_ctx { - gras_socket_t expeditor; - gras_msgtype_t msgtype; - unsigned long int ID; - double timeout; - int answer_due; /* Whether the callback is expected to return a result (for sanity checks) */ + gras_socket_t expeditor; + gras_msgtype_t msgtype; + unsigned long int ID; + double timeout; + int answer_due; /* Whether the callback is expected to return a result (for sanity checks) */ }; typedef struct s_gras_msg_cb_ctx s_gras_msg_cb_ctx_t; @@ -113,20 +113,20 @@ typedef struct s_gras_msg_cb_ctx s_gras_msg_cb_ctx_t; * * TIMER * * * ********* */ typedef struct { - double expiry; - double period; - void_f_void_t action; - int repeat; + double expiry; + double period; + void_f_void_t action; + int repeat; } s_gras_timer_t, *gras_timer_t; /* returns 0 if it handled a timer, or the delay until next timer, or -1 if no armed timer */ double gras_msg_timer_handle(void); gras_msg_cb_ctx_t gras_msg_cb_ctx_new(gras_socket_t expe, - gras_msgtype_t msgtype, - unsigned long int ID, - int answer_due, - double timeout); + gras_msgtype_t msgtype, + unsigned long int ID, + int answer_due, + double timeout); diff --git a/src/gras/Msg/rl_msg.c b/src/gras/Msg/rl_msg.c index 148661df16..912b13ad1f 100644 --- a/src/gras/Msg/rl_msg.c +++ b/src/gras/Msg/rl_msg.c @@ -17,58 +17,58 @@ XBT_LOG_EXTERNAL_CATEGORY(gras_msg); XBT_LOG_DEFAULT_CATEGORY(gras_msg); void gras_msg_send_ext(gras_socket_t sock, - e_gras_msg_kind_t kind, - unsigned long int ID, - gras_msgtype_t msgtype, - void *payload) { - - static gras_datadesc_type_t string_type=NULL; - static gras_datadesc_type_t ulong_type=NULL; - char c_kind=(char)kind; - - xbt_assert0(msgtype,"Cannot send the NULL message"); - - if (!string_type) { - string_type = gras_datadesc_by_name("string"); - xbt_assert(string_type); - } - if (!ulong_type) { - ulong_type = gras_datadesc_by_name("unsigned long int"); - xbt_assert(ulong_type); - } - - DEBUG3("send '%s' to %s:%d", msgtype->name, - gras_socket_peer_name(sock),gras_socket_peer_port(sock)); - gras_trp_send(sock, _GRAS_header, 6, 1 /* stable */); - gras_trp_send(sock, &c_kind, 1, 1 /* stable */); - switch (kind) { - case e_gras_msg_kind_oneway: - break; - - case e_gras_msg_kind_rpccall: - case e_gras_msg_kind_rpcanswer: - case e_gras_msg_kind_rpcerror: - gras_datadesc_send(sock,ulong_type,&ID); - break; - - default: - THROW1(unknown_error,0,"Unknown msg kind %d",kind); - } - - gras_datadesc_send(sock, string_type, &msgtype->name); - if (kind == e_gras_msg_kind_rpcerror) { - /* error on remote host, carfull, payload is an exception */ - gras_datadesc_send(sock, gras_datadesc_by_name("ex_t"),payload); - } else if (kind == e_gras_msg_kind_rpcanswer) { - if (msgtype->answer_type) - gras_datadesc_send(sock, msgtype->answer_type, payload); - }else { - /* regular message */ - if (msgtype->ctn_type) - gras_datadesc_send(sock, msgtype->ctn_type, payload); - } - - gras_trp_flush(sock); + e_gras_msg_kind_t kind, + unsigned long int ID, + gras_msgtype_t msgtype, + void *payload) { + + static gras_datadesc_type_t string_type=NULL; + static gras_datadesc_type_t ulong_type=NULL; + char c_kind=(char)kind; + + xbt_assert0(msgtype,"Cannot send the NULL message"); + + if (!string_type) { + string_type = gras_datadesc_by_name("string"); + xbt_assert(string_type); + } + if (!ulong_type) { + ulong_type = gras_datadesc_by_name("unsigned long int"); + xbt_assert(ulong_type); + } + + DEBUG3("send '%s' to %s:%d", msgtype->name, + gras_socket_peer_name(sock),gras_socket_peer_port(sock)); + gras_trp_send(sock, _GRAS_header, 6, 1 /* stable */); + gras_trp_send(sock, &c_kind, 1, 1 /* stable */); + switch (kind) { + case e_gras_msg_kind_oneway: + break; + + case e_gras_msg_kind_rpccall: + case e_gras_msg_kind_rpcanswer: + case e_gras_msg_kind_rpcerror: + gras_datadesc_send(sock,ulong_type,&ID); + break; + + default: + THROW1(unknown_error,0,"Unknown msg kind %d",kind); + } + + gras_datadesc_send(sock, string_type, &msgtype->name); + if (kind == e_gras_msg_kind_rpcerror) { + /* error on remote host, carfull, payload is an exception */ + gras_datadesc_send(sock, gras_datadesc_by_name("ex_t"),payload); + } else if (kind == e_gras_msg_kind_rpcanswer) { + if (msgtype->answer_type) + gras_datadesc_send(sock, msgtype->answer_type, payload); + }else { + /* regular message */ + if (msgtype->ctn_type) + gras_datadesc_send(sock, msgtype->ctn_type, payload); + } + + gras_trp_flush(sock); } const char *hexa_str(unsigned char *data, int size, int downside); @@ -79,111 +79,111 @@ const char *hexa_str(unsigned char *data, int size, int downside); */ void gras_msg_recv(gras_socket_t sock, - gras_msg_t msg) { - - xbt_ex_t e; - static gras_datadesc_type_t string_type=NULL; - static gras_datadesc_type_t ulong_type=NULL; - char header[6]; - int cpt; - int r_arch; - char *msg_name=NULL; - char c_kind; - - xbt_assert1(!gras_socket_is_meas(sock), - "Asked to receive a message on the measurement socket %p", sock); - if (!string_type) { - string_type=gras_datadesc_by_name("string"); - xbt_assert(string_type); - } - if (!ulong_type) { - ulong_type = gras_datadesc_by_name("unsigned long int"); - xbt_assert(ulong_type); - } - - - TRY { - gras_trp_recv(sock, header, 6); - gras_trp_recv(sock, &c_kind, 1); - msg->kind=(e_gras_msg_kind_t)c_kind; - } CATCH(e) { - RETHROW0("Exception caught while trying to get the mesage header: %s"); - } - - for (cpt=0; cpt<4; cpt++) - if (header[cpt] != _GRAS_header[cpt]) - THROW2(mismatch_error,0, - "Incoming bytes do not look like a GRAS message (header='%s' not '%.4s')", - hexa_str((unsigned char*)header,4,0),_GRAS_header); - if (header[4] != _GRAS_header[4]) - THROW2(mismatch_error,0,"GRAS protocol mismatch (got %d, use %d)", - (int)header[4], (int)_GRAS_header[4]); - r_arch = (int)header[5]; - - switch (msg->kind) { - case e_gras_msg_kind_oneway: - break; - - case e_gras_msg_kind_rpccall: - case e_gras_msg_kind_rpcanswer: - case e_gras_msg_kind_rpcerror: - gras_datadesc_recv(sock,ulong_type,r_arch, &msg->ID); - break; - - default: - THROW_IMPOSSIBLE; - } - - gras_datadesc_recv(sock, string_type, r_arch, &msg_name); - DEBUG4("Handle an incoming message '%s' (%s) using protocol %d (remote is %s)", - msg_name, e_gras_msg_kind_names[msg->kind], (int)header[4],gras_datadesc_arch_name(r_arch)); - - TRY { - msg->type = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set,msg_name); - } CATCH(e) { - /* FIXME: Survive unknown messages */ - if (e.category == not_found_error) { - xbt_ex_free(e); - THROW1(not_found_error,0, "Received an unknown message: %s (FIXME: should survive to these)", msg_name); - } else - RETHROW1("Exception caught while retrieving the type associated to messages '%s' : %s", - msg_name); - } - free(msg_name); - - if (msg->kind == e_gras_msg_kind_rpcerror) { - /* error on remote host. Carfull with that exception, eugene */ - msg->payl_size=gras_datadesc_size(gras_datadesc_by_name("ex_t")); - msg->payl=xbt_malloc(msg->payl_size); - gras_datadesc_recv(sock, gras_datadesc_by_name("ex_t"), r_arch, msg->payl); - - } else if (msg->kind == e_gras_msg_kind_rpcanswer) { - /* answer to RPC */ - if (msg->type->answer_type) { - msg->payl_size=gras_datadesc_size(msg->type->answer_type); - xbt_assert2(msg->payl_size > 0, - "%s %s", - "Dynamic array as payload is forbided for now (FIXME?).", - "Reference to dynamic array is allowed."); - msg->payl = xbt_malloc(msg->payl_size); - gras_datadesc_recv(sock, msg->type->answer_type, r_arch, msg->payl); - } else { - msg->payl = NULL; - msg->payl_size = 0; - } - } else { - /* regular message */ - if (msg->type->ctn_type) { - msg->payl_size=gras_datadesc_size(msg->type->ctn_type); - xbt_assert2(msg->payl_size > 0, - "%s %s", - "Dynamic array as payload is forbided for now (FIXME?).", - "Reference to dynamic array is allowed."); - msg->payl = xbt_malloc(msg->payl_size); - gras_datadesc_recv(sock, msg->type->ctn_type, r_arch, msg->payl); - } else { - msg->payl = NULL; - msg->payl_size = 0; - } - } + gras_msg_t msg) { + + xbt_ex_t e; + static gras_datadesc_type_t string_type=NULL; + static gras_datadesc_type_t ulong_type=NULL; + char header[6]; + int cpt; + int r_arch; + char *msg_name=NULL; + char c_kind; + + xbt_assert1(!gras_socket_is_meas(sock), + "Asked to receive a message on the measurement socket %p", sock); + if (!string_type) { + string_type=gras_datadesc_by_name("string"); + xbt_assert(string_type); + } + if (!ulong_type) { + ulong_type = gras_datadesc_by_name("unsigned long int"); + xbt_assert(ulong_type); + } + + + TRY { + gras_trp_recv(sock, header, 6); + gras_trp_recv(sock, &c_kind, 1); + msg->kind=(e_gras_msg_kind_t)c_kind; + } CATCH(e) { + RETHROW0("Exception caught while trying to get the mesage header: %s"); + } + + for (cpt=0; cpt<4; cpt++) + if (header[cpt] != _GRAS_header[cpt]) + THROW2(mismatch_error,0, + "Incoming bytes do not look like a GRAS message (header='%s' not '%.4s')", + hexa_str((unsigned char*)header,4,0),_GRAS_header); + if (header[4] != _GRAS_header[4]) + THROW2(mismatch_error,0,"GRAS protocol mismatch (got %d, use %d)", + (int)header[4], (int)_GRAS_header[4]); + r_arch = (int)header[5]; + + switch (msg->kind) { + case e_gras_msg_kind_oneway: + break; + + case e_gras_msg_kind_rpccall: + case e_gras_msg_kind_rpcanswer: + case e_gras_msg_kind_rpcerror: + gras_datadesc_recv(sock,ulong_type,r_arch, &msg->ID); + break; + + default: + THROW_IMPOSSIBLE; + } + + gras_datadesc_recv(sock, string_type, r_arch, &msg_name); + DEBUG4("Handle an incoming message '%s' (%s) using protocol %d (remote is %s)", + msg_name, e_gras_msg_kind_names[msg->kind], (int)header[4],gras_datadesc_arch_name(r_arch)); + + TRY { + msg->type = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set,msg_name); + } CATCH(e) { + /* FIXME: Survive unknown messages */ + if (e.category == not_found_error) { + xbt_ex_free(e); + THROW1(not_found_error,0, "Received an unknown message: %s (FIXME: should survive to these)", msg_name); + } else + RETHROW1("Exception caught while retrieving the type associated to messages '%s' : %s", + msg_name); + } + free(msg_name); + + if (msg->kind == e_gras_msg_kind_rpcerror) { + /* error on remote host. Carfull with that exception, eugene */ + msg->payl_size=gras_datadesc_size(gras_datadesc_by_name("ex_t")); + msg->payl=xbt_malloc(msg->payl_size); + gras_datadesc_recv(sock, gras_datadesc_by_name("ex_t"), r_arch, msg->payl); + + } else if (msg->kind == e_gras_msg_kind_rpcanswer) { + /* answer to RPC */ + if (msg->type->answer_type) { + msg->payl_size=gras_datadesc_size(msg->type->answer_type); + xbt_assert2(msg->payl_size > 0, + "%s %s", + "Dynamic array as payload is forbided for now (FIXME?).", + "Reference to dynamic array is allowed."); + msg->payl = xbt_malloc(msg->payl_size); + gras_datadesc_recv(sock, msg->type->answer_type, r_arch, msg->payl); + } else { + msg->payl = NULL; + msg->payl_size = 0; + } + } else { + /* regular message */ + if (msg->type->ctn_type) { + msg->payl_size=gras_datadesc_size(msg->type->ctn_type); + xbt_assert2(msg->payl_size > 0, + "%s %s", + "Dynamic array as payload is forbided for now (FIXME?).", + "Reference to dynamic array is allowed."); + msg->payl = xbt_malloc(msg->payl_size); + gras_datadesc_recv(sock, msg->type->ctn_type, r_arch, msg->payl); + } else { + msg->payl = NULL; + msg->payl_size = 0; + } + } } diff --git a/src/gras/Msg/rpc.c b/src/gras/Msg/rpc.c index be3f040a70..7d7ac05c5c 100644 --- a/src/gras/Msg/rpc.c +++ b/src/gras/Msg/rpc.c @@ -8,7 +8,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "gras/Msg/msg_private.h" - + xbt_set_t _gras_rpctype_set = NULL; xbt_dynar_t _gras_rpc_cancelled = NULL; @@ -21,17 +21,17 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_msg_rpc,gras_msg,"RPC mecanism"); * @param payload_request: datatype of request * @param payload_answer: datatype of answer * - * Registers a new RPC message to the GRAS mechanism. RPC are constituted of a pair - * of messages. + * Registers a new RPC message to the GRAS mechanism. RPC are constituted of a pair + * of messages. */ void gras_msgtype_declare_rpc(const char *name, - gras_datadesc_type_t payload_request, - gras_datadesc_type_t payload_answer) { + gras_datadesc_type_t payload_request, + gras_datadesc_type_t payload_answer) { - gras_msgtype_declare_ext(name, 0, - e_gras_msg_kind_rpccall, - payload_request, payload_answer); + gras_msgtype_declare_ext(name, 0, + e_gras_msg_kind_rpccall, + payload_request, payload_answer); } @@ -42,8 +42,8 @@ gras_msgtype_declare_rpc(const char *name, * @param payload_request: datatype of request * @param payload_answer: datatype of answer * - * Registers a new RPC message to the GRAS mechanism. RPC are constituted of a pair - * of messages. + * Registers a new RPC message to the GRAS mechanism. RPC are constituted of a pair + * of messages. * * Use this version instead of gras_rpctype_declare when you change the * semantic or syntax of a message and want your programs to be able to deal @@ -52,162 +52,162 @@ gras_msgtype_declare_rpc(const char *name, */ void gras_msgtype_declare_rpc_v(const char *name, - short int version, - gras_datadesc_type_t payload_request, - gras_datadesc_type_t payload_answer) { + short int version, + gras_datadesc_type_t payload_request, + gras_datadesc_type_t payload_answer) { - gras_msgtype_declare_ext(name, version, - e_gras_msg_kind_rpccall, - payload_request, payload_answer); + gras_msgtype_declare_ext(name, version, + e_gras_msg_kind_rpccall, + payload_request, payload_answer); } static unsigned long int last_msg_ID = 0; static int msgfilter_rpcID(gras_msg_t msg, void* ctx) { - unsigned long int ID= *(unsigned long int*)ctx; - int res = msg->ID == ID && - (msg->kind == e_gras_msg_kind_rpcanswer || msg->kind == e_gras_msg_kind_rpcerror); - unsigned int cursor; - gras_msg_cb_ctx_t rpc_ctx; - - - DEBUG5("Filter a message of ID %lu, type '%s' and kind '%s'. Waiting for ID=%lu. %s", - msg->ID,msg->type->name,e_gras_msg_kind_names[msg->kind],ID, - res?"take it": "reject"); - - if (res && !_gras_rpc_cancelled) - return res; - - /* Check whether it is an old answer to a message we already canceled */ - xbt_dynar_foreach(_gras_rpc_cancelled,cursor,rpc_ctx) { - if (msg->ID == rpc_ctx->ID && msg->kind==e_gras_msg_kind_rpcanswer) { - VERB1("Got an answer to the already canceled (timeouted?) RPC %ld. Ignore it (leaking the payload!).",msg->ID); - xbt_dynar_cursor_rm (_gras_rpc_cancelled, &cursor); - return 1; - } - } - - return res; + unsigned long int ID= *(unsigned long int*)ctx; + int res = msg->ID == ID && + (msg->kind == e_gras_msg_kind_rpcanswer || msg->kind == e_gras_msg_kind_rpcerror); + unsigned int cursor; + gras_msg_cb_ctx_t rpc_ctx; + + + DEBUG5("Filter a message of ID %lu, type '%s' and kind '%s'. Waiting for ID=%lu. %s", + msg->ID,msg->type->name,e_gras_msg_kind_names[msg->kind],ID, + res?"take it": "reject"); + + if (res && !_gras_rpc_cancelled) + return res; + + /* Check whether it is an old answer to a message we already canceled */ + xbt_dynar_foreach(_gras_rpc_cancelled,cursor,rpc_ctx) { + if (msg->ID == rpc_ctx->ID && msg->kind==e_gras_msg_kind_rpcanswer) { + VERB1("Got an answer to the already canceled (timeouted?) RPC %ld. Ignore it (leaking the payload!).",msg->ID); + xbt_dynar_cursor_rm (_gras_rpc_cancelled, &cursor); + return 1; + } + } + + return res; } /* Mallocator cruft */ xbt_mallocator_t gras_msg_ctx_mallocator = NULL; void* gras_msg_ctx_mallocator_new_f(void) { - return xbt_new0(s_gras_msg_cb_ctx_t,1); + return xbt_new0(s_gras_msg_cb_ctx_t,1); } void gras_msg_ctx_mallocator_free_f(void* ctx) { - xbt_free(ctx); + xbt_free(ctx); } void gras_msg_ctx_mallocator_reset_f(void* ctx) { - memset(ctx, sizeof(s_gras_msg_cb_ctx_t),0); + memset(ctx, sizeof(s_gras_msg_cb_ctx_t),0); } /** @brief Launch a RPC call, but do not block for the answer */ -gras_msg_cb_ctx_t +gras_msg_cb_ctx_t gras_msg_rpc_async_call_(gras_socket_t server, - double timeOut, - gras_msgtype_t msgtype, - void *request) { - gras_msg_cb_ctx_t ctx = xbt_mallocator_get(gras_msg_ctx_mallocator); - - if (msgtype->ctn_type) { - xbt_assert1(request, - "RPC type '%s' convey a payload you must provide", - msgtype->name); - } else { - xbt_assert1(!request, - "No payload was declared for RPC type '%s'", - msgtype->name); - } - - ctx->ID = last_msg_ID++; - ctx->expeditor = server; - ctx->msgtype=msgtype; - ctx->timeout=timeOut; - - VERB4("Send to %s:%d a RPC of type '%s' (ID=%lu)", - gras_socket_peer_name(server), - gras_socket_peer_port(server), - msgtype->name,ctx->ID); - - gras_msg_send_ext(server, e_gras_msg_kind_rpccall, ctx->ID, msgtype, request); - - return ctx; + double timeOut, + gras_msgtype_t msgtype, + void *request) { + gras_msg_cb_ctx_t ctx = xbt_mallocator_get(gras_msg_ctx_mallocator); + + if (msgtype->ctn_type) { + xbt_assert1(request, + "RPC type '%s' convey a payload you must provide", + msgtype->name); + } else { + xbt_assert1(!request, + "No payload was declared for RPC type '%s'", + msgtype->name); + } + + ctx->ID = last_msg_ID++; + ctx->expeditor = server; + ctx->msgtype=msgtype; + ctx->timeout=timeOut; + + VERB4("Send to %s:%d a RPC of type '%s' (ID=%lu)", + gras_socket_peer_name(server), + gras_socket_peer_port(server), + msgtype->name,ctx->ID); + + gras_msg_send_ext(server, e_gras_msg_kind_rpccall, ctx->ID, msgtype, request); + + return ctx; } /** @brief Wait the answer of a RPC call previously launched asynchronously */ void gras_msg_rpc_async_wait(gras_msg_cb_ctx_t ctx, - void *answer) { - xbt_ex_t e; - s_gras_msg_t received; - - if (ctx->msgtype->answer_type) { - xbt_assert1(answer, - "Answers to RPC '%s' convey a payload you must accept", - ctx->msgtype->name); - } else { - xbt_assert1(!answer, - "No payload was declared for answers to RPC '%s'", - ctx->msgtype->name); - } - - TRY { - /* The filter returns 1 when we eat an old RPC answer to something canceled */ - do { - gras_msg_wait_ext_(ctx->timeout, - ctx->msgtype, NULL, msgfilter_rpcID, &ctx->ID, - &received); - } while (received.ID != ctx->ID); - - } CATCH(e) { - if (!_gras_rpc_cancelled) - _gras_rpc_cancelled = xbt_dynar_new(sizeof(ctx),NULL); - xbt_dynar_push(_gras_rpc_cancelled,&ctx); - INFO5("canceled RPC %ld pushed onto the stack (%s from %s:%d) Reason: %s", - ctx->ID,ctx->msgtype->name, - gras_socket_peer_name(ctx->expeditor),gras_socket_peer_port(ctx->expeditor), - e.msg); - RETHROW; - } - - xbt_mallocator_release(gras_msg_ctx_mallocator, ctx); - if (received.kind == e_gras_msg_kind_rpcerror) { - xbt_ex_t e; - memcpy(&e,received.payl,received.payl_size); - free(received.payl); - VERB3("Raise a remote exception cat:%d comming from %s (%s)", - e.category, e.host, e.msg); - __xbt_ex_ctx()->ctx_ex.msg = e.msg; - __xbt_ex_ctx()->ctx_ex.category = e.category; - __xbt_ex_ctx()->ctx_ex.value = e.value; - __xbt_ex_ctx()->ctx_ex.remote = 1; - __xbt_ex_ctx()->ctx_ex.host = e.host; - __xbt_ex_ctx()->ctx_ex.procname = e.procname; - __xbt_ex_ctx()->ctx_ex.pid = e.pid; - __xbt_ex_ctx()->ctx_ex.file = e.file; - __xbt_ex_ctx()->ctx_ex.line = e.line; - __xbt_ex_ctx()->ctx_ex.func = e.func; - __xbt_ex_ctx()->ctx_ex.used = e.used; - __xbt_ex_ctx()->ctx_ex.bt_strings = e.bt_strings; - memset(&__xbt_ex_ctx()->ctx_ex.bt,0, - sizeof(__xbt_ex_ctx()->ctx_ex.bt)); - DO_THROW(__xbt_ex_ctx()->ctx_ex); - } - memcpy(answer,received.payl,received.payl_size); - free(received.payl); + void *answer) { + xbt_ex_t e; + s_gras_msg_t received; + + if (ctx->msgtype->answer_type) { + xbt_assert1(answer, + "Answers to RPC '%s' convey a payload you must accept", + ctx->msgtype->name); + } else { + xbt_assert1(!answer, + "No payload was declared for answers to RPC '%s'", + ctx->msgtype->name); + } + + TRY { + /* The filter returns 1 when we eat an old RPC answer to something canceled */ + do { + gras_msg_wait_ext_(ctx->timeout, + ctx->msgtype, NULL, msgfilter_rpcID, &ctx->ID, + &received); + } while (received.ID != ctx->ID); + + } CATCH(e) { + if (!_gras_rpc_cancelled) + _gras_rpc_cancelled = xbt_dynar_new(sizeof(ctx),NULL); + xbt_dynar_push(_gras_rpc_cancelled,&ctx); + INFO5("canceled RPC %ld pushed onto the stack (%s from %s:%d) Reason: %s", + ctx->ID,ctx->msgtype->name, + gras_socket_peer_name(ctx->expeditor),gras_socket_peer_port(ctx->expeditor), + e.msg); + RETHROW; + } + + xbt_mallocator_release(gras_msg_ctx_mallocator, ctx); + if (received.kind == e_gras_msg_kind_rpcerror) { + xbt_ex_t e; + memcpy(&e,received.payl,received.payl_size); + free(received.payl); + VERB3("Raise a remote exception cat:%d comming from %s (%s)", + e.category, e.host, e.msg); + __xbt_ex_ctx()->ctx_ex.msg = e.msg; + __xbt_ex_ctx()->ctx_ex.category = e.category; + __xbt_ex_ctx()->ctx_ex.value = e.value; + __xbt_ex_ctx()->ctx_ex.remote = 1; + __xbt_ex_ctx()->ctx_ex.host = e.host; + __xbt_ex_ctx()->ctx_ex.procname = e.procname; + __xbt_ex_ctx()->ctx_ex.pid = e.pid; + __xbt_ex_ctx()->ctx_ex.file = e.file; + __xbt_ex_ctx()->ctx_ex.line = e.line; + __xbt_ex_ctx()->ctx_ex.func = e.func; + __xbt_ex_ctx()->ctx_ex.used = e.used; + __xbt_ex_ctx()->ctx_ex.bt_strings = e.bt_strings; + memset(&__xbt_ex_ctx()->ctx_ex.bt,0, + sizeof(__xbt_ex_ctx()->ctx_ex.bt)); + DO_THROW(__xbt_ex_ctx()->ctx_ex); + } + memcpy(answer,received.payl,received.payl_size); + free(received.payl); } /** @brief Conduct a RPC call */ void gras_msg_rpccall_(gras_socket_t server, - double timeout, - gras_msgtype_t msgtype, - void *request, void *answer) { + double timeout, + gras_msgtype_t msgtype, + void *request, void *answer) { - gras_msg_cb_ctx_t ctx; + gras_msg_cb_ctx_t ctx; - ctx = gras_msg_rpc_async_call_(server, timeout,msgtype,request); - gras_msg_rpc_async_wait(ctx, answer); + ctx = gras_msg_rpc_async_call_(server, timeout,msgtype,request); + gras_msg_rpc_async_wait(ctx, answer); } @@ -218,14 +218,14 @@ void gras_msg_rpccall_(gras_socket_t server, */ void gras_msg_rpcreturn(double timeOut,gras_msg_cb_ctx_t ctx,void *answer) { - xbt_assert0(ctx->answer_due, - "RPC return not allowed here. Either not a RPC message or already returned a result"); - ctx->answer_due = 0; - DEBUG5("Return to RPC '%s' from %s:%d (tOut=%f, payl=%p)", - ctx->msgtype->name, - gras_socket_peer_name(ctx->expeditor),gras_socket_peer_port(ctx->expeditor), - timeOut,answer); - gras_msg_send_ext(ctx->expeditor, e_gras_msg_kind_rpcanswer, - ctx->ID, ctx->msgtype, answer); + xbt_assert0(ctx->answer_due, + "RPC return not allowed here. Either not a RPC message or already returned a result"); + ctx->answer_due = 0; + DEBUG5("Return to RPC '%s' from %s:%d (tOut=%f, payl=%p)", + ctx->msgtype->name, + gras_socket_peer_name(ctx->expeditor),gras_socket_peer_port(ctx->expeditor), + timeOut,answer); + gras_msg_send_ext(ctx->expeditor, e_gras_msg_kind_rpcanswer, + ctx->ID, ctx->msgtype, answer); } diff --git a/src/gras/Msg/sg_msg.c b/src/gras/Msg/sg_msg.c index 7bda9a1395..779fa96bfa 100644 --- a/src/gras/Msg/sg_msg.c +++ b/src/gras/Msg/sg_msg.c @@ -23,140 +23,140 @@ XBT_LOG_DEFAULT_CATEGORY(gras_msg); typedef void* gras_trp_bufdata_; void gras_msg_send_ext(gras_socket_t sock, - e_gras_msg_kind_t kind, - unsigned long int ID, - gras_msgtype_t msgtype, - void *payload) { + e_gras_msg_kind_t kind, + unsigned long int ID, + gras_msgtype_t msgtype, + void *payload) { smx_action_t act; /* simix action */ - gras_trp_sg_sock_data_t *sock_data; + gras_trp_sg_sock_data_t *sock_data; gras_hostdata_t *hd; gras_trp_procdata_t trp_remote_proc; gras_msg_procdata_t msg_remote_proc; gras_msg_t msg; /* message to send */ - int whole_payload_size=0; /* msg->payload_size is used to memcpy the payload. + int whole_payload_size=0; /* msg->payload_size is used to memcpy the payload. This is used to report the load onto the simulator. It also counts the size of pointed stuff */ sock_data = (gras_trp_sg_sock_data_t *)sock->data; hd = (gras_hostdata_t *)SIMIX_host_get_data(SIMIX_host_self()); - xbt_assert1(!gras_socket_is_meas(sock), - "Asked to send a message on the measurement socket %p", sock); - + xbt_assert1(!gras_socket_is_meas(sock), + "Asked to send a message on the measurement socket %p", sock); + /*initialize gras message */ msg = xbt_new(s_gras_msg_t,1); msg->expe = sock; msg->kind = kind; msg->type = msgtype; msg->ID = ID; - if (kind == e_gras_msg_kind_rpcerror) { - /* error on remote host, carfull, payload is an exception */ - msg->payl_size=gras_datadesc_size(gras_datadesc_by_name("ex_t")); - msg->payl=xbt_malloc(msg->payl_size); - whole_payload_size = gras_datadesc_memcpy(gras_datadesc_by_name("ex_t"), - payload,msg->payl); - } else if (kind == e_gras_msg_kind_rpcanswer) { - msg->payl_size=gras_datadesc_size(msgtype->answer_type); - if (msg->payl_size) - msg->payl=xbt_malloc(msg->payl_size); - else - msg->payl=NULL; - - if (msgtype->answer_type) - whole_payload_size = gras_datadesc_memcpy(msgtype->answer_type, - payload, msg->payl); - } else { - msg->payl_size=gras_datadesc_size(msgtype->ctn_type); - msg->payl=msg->payl_size?xbt_malloc(msg->payl_size):NULL; - if (msgtype->ctn_type) - whole_payload_size = gras_datadesc_memcpy(msgtype->ctn_type, - payload, msg->payl); - } + if (kind == e_gras_msg_kind_rpcerror) { + /* error on remote host, carfull, payload is an exception */ + msg->payl_size=gras_datadesc_size(gras_datadesc_by_name("ex_t")); + msg->payl=xbt_malloc(msg->payl_size); + whole_payload_size = gras_datadesc_memcpy(gras_datadesc_by_name("ex_t"), + payload,msg->payl); + } else if (kind == e_gras_msg_kind_rpcanswer) { + msg->payl_size=gras_datadesc_size(msgtype->answer_type); + if (msg->payl_size) + msg->payl=xbt_malloc(msg->payl_size); + else + msg->payl=NULL; + + if (msgtype->answer_type) + whole_payload_size = gras_datadesc_memcpy(msgtype->answer_type, + payload, msg->payl); + } else { + msg->payl_size=gras_datadesc_size(msgtype->ctn_type); + msg->payl=msg->payl_size?xbt_malloc(msg->payl_size):NULL; + if (msgtype->ctn_type) + whole_payload_size = gras_datadesc_memcpy(msgtype->ctn_type, + payload, msg->payl); + } /* put the selectable socket on the queue */ - trp_remote_proc = (gras_trp_procdata_t) - gras_libdata_by_name_from_remote("gras_trp",sock_data->to_process); + trp_remote_proc = (gras_trp_procdata_t) + gras_libdata_by_name_from_remote("gras_trp",sock_data->to_process); - xbt_queue_push(trp_remote_proc->msg_selectable_sockets,&sock); + xbt_queue_push(trp_remote_proc->msg_selectable_sockets,&sock); - /* put message on msg_queue */ + /* put message on msg_queue */ msg_remote_proc = (gras_msg_procdata_t) - gras_libdata_by_name_from_remote("gras_msg",sock_data->to_process); + gras_libdata_by_name_from_remote("gras_msg",sock_data->to_process); xbt_fifo_push(msg_remote_proc->msg_to_receive_queue,msg); - - /* wait for the receiver */ - SIMIX_cond_wait(sock_data->cond, sock_data->mutex); - - /* creates simix action and waits its ends, waits in the sender host + + /* wait for the receiver */ + SIMIX_cond_wait(sock_data->cond, sock_data->mutex); + + /* creates simix action and waits its ends, waits in the sender host condition*/ - act = SIMIX_action_communicate(SIMIX_host_self(), - sock_data->to_host,msgtype->name, - (double)whole_payload_size, -1); - SIMIX_register_action_to_condition(act,sock_data->cond); - - VERB5("Sending to %s(%s) a message type '%s' kind '%s' ID %lu", - SIMIX_host_get_name(sock_data->to_host), - SIMIX_process_get_name(sock_data->to_process), - msg->type->name,e_gras_msg_kind_names[msg->kind], msg->ID); - - SIMIX_cond_wait(sock_data->cond, sock_data->mutex); - SIMIX_unregister_action_to_condition(act,sock_data->cond); - /* error treatmeant (FIXME)*/ - - /* cleanup structures */ - SIMIX_action_destroy(act); - SIMIX_mutex_unlock(sock_data->mutex); - - VERB0("Message sent"); + act = SIMIX_action_communicate(SIMIX_host_self(), + sock_data->to_host,msgtype->name, + (double)whole_payload_size, -1); + SIMIX_register_action_to_condition(act,sock_data->cond); + + VERB5("Sending to %s(%s) a message type '%s' kind '%s' ID %lu", + SIMIX_host_get_name(sock_data->to_host), + SIMIX_process_get_name(sock_data->to_process), + msg->type->name,e_gras_msg_kind_names[msg->kind], msg->ID); + + SIMIX_cond_wait(sock_data->cond, sock_data->mutex); + SIMIX_unregister_action_to_condition(act,sock_data->cond); + /* error treatmeant (FIXME)*/ + + /* cleanup structures */ + SIMIX_action_destroy(act); + SIMIX_mutex_unlock(sock_data->mutex); + + VERB0("Message sent"); } /* - * receive the next message on the given socket. + * receive the next message on the given socket. */ void gras_msg_recv(gras_socket_t sock, - gras_msg_t msg) { - - gras_trp_sg_sock_data_t *sock_data; - gras_trp_sg_sock_data_t *remote_sock_data; - gras_hostdata_t *remote_hd; - gras_msg_t msg_got; - gras_msg_procdata_t msg_procdata = - (gras_msg_procdata_t)gras_libdata_by_name("gras_msg"); - - xbt_assert1(!gras_socket_is_meas(sock), - "Asked to receive a message on the measurement socket %p", sock); - - xbt_assert0(msg,"msg is an out parameter of gras_msg_recv..."); - - sock_data = (gras_trp_sg_sock_data_t *)sock->data; - remote_sock_data = ((gras_trp_sg_sock_data_t *)sock->data)->to_socket->data; - DEBUG3("Remote host %s, Remote Port: %d Local port %d", - SIMIX_host_get_name(sock_data->to_host), sock->peer_port, sock->port); - remote_hd = (gras_hostdata_t *)SIMIX_host_get_data(sock_data->to_host); - - if (xbt_fifo_size(msg_procdata->msg_to_receive_queue) == 0 ) { - THROW_IMPOSSIBLE; - } - DEBUG1("Size msg_to_receive buffer: %d", - xbt_fifo_size(msg_procdata->msg_to_receive_queue)); - msg_got = xbt_fifo_shift(msg_procdata->msg_to_receive_queue); - - SIMIX_mutex_lock(remote_sock_data->mutex); - /* ok, I'm here, you can continuate the communication */ - SIMIX_cond_signal(remote_sock_data->cond); - - /* wait for communication end */ - SIMIX_cond_wait(remote_sock_data->cond,remote_sock_data->mutex); - - msg_got->expe= msg->expe; - memcpy(msg,msg_got,sizeof(s_gras_msg_t)); - xbt_free(msg_got); - SIMIX_mutex_unlock(remote_sock_data->mutex); - - VERB3("Received a message type '%s' kind '%s' ID %lu",// from %s", - msg->type->name, - e_gras_msg_kind_names[msg->kind], - msg->ID); + gras_msg_t msg) { + + gras_trp_sg_sock_data_t *sock_data; + gras_trp_sg_sock_data_t *remote_sock_data; + gras_hostdata_t *remote_hd; + gras_msg_t msg_got; + gras_msg_procdata_t msg_procdata = + (gras_msg_procdata_t)gras_libdata_by_name("gras_msg"); + + xbt_assert1(!gras_socket_is_meas(sock), + "Asked to receive a message on the measurement socket %p", sock); + + xbt_assert0(msg,"msg is an out parameter of gras_msg_recv..."); + + sock_data = (gras_trp_sg_sock_data_t *)sock->data; + remote_sock_data = ((gras_trp_sg_sock_data_t *)sock->data)->to_socket->data; + DEBUG3("Remote host %s, Remote Port: %d Local port %d", + SIMIX_host_get_name(sock_data->to_host), sock->peer_port, sock->port); + remote_hd = (gras_hostdata_t *)SIMIX_host_get_data(sock_data->to_host); + + if (xbt_fifo_size(msg_procdata->msg_to_receive_queue) == 0 ) { + THROW_IMPOSSIBLE; + } + DEBUG1("Size msg_to_receive buffer: %d", + xbt_fifo_size(msg_procdata->msg_to_receive_queue)); + msg_got = xbt_fifo_shift(msg_procdata->msg_to_receive_queue); + + SIMIX_mutex_lock(remote_sock_data->mutex); + /* ok, I'm here, you can continuate the communication */ + SIMIX_cond_signal(remote_sock_data->cond); + + /* wait for communication end */ + SIMIX_cond_wait(remote_sock_data->cond,remote_sock_data->mutex); + + msg_got->expe= msg->expe; + memcpy(msg,msg_got,sizeof(s_gras_msg_t)); + xbt_free(msg_got); + SIMIX_mutex_unlock(remote_sock_data->mutex); + + VERB3("Received a message type '%s' kind '%s' ID %lu",// from %s", + msg->type->name, + e_gras_msg_kind_names[msg->kind], + msg->ID); } diff --git a/src/gras/Msg/timer.c b/src/gras/Msg/timer.c index 49c0f1b2a3..f68376f973 100644 --- a/src/gras/Msg/timer.c +++ b/src/gras/Msg/timer.c @@ -14,166 +14,166 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_timer,gras, - "Delayed and repetitive actions"); + "Delayed and repetitive actions"); /** @brief Request \a action to be called once in \a delay seconds */ void gras_timer_delay(double delay, void_f_void_t action) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - - gras_timer_t timer = xbt_dynar_push_ptr(pd->timers); - - VERB1("Register delayed action %p", action); - timer->period = delay; - timer->expiry = delay+gras_os_time(); - timer->action = action; - timer->repeat = FALSE; + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + + gras_timer_t timer = xbt_dynar_push_ptr(pd->timers); + + VERB1("Register delayed action %p", action); + timer->period = delay; + timer->expiry = delay+gras_os_time(); + timer->action = action; + timer->repeat = FALSE; } /** @brief Request \a action to be called every \a interval seconds */ void gras_timer_repeat(double interval, void_f_void_t action) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - - gras_timer_t timer = xbt_dynar_push_ptr(pd->timers); - - VERB1("Register repetitive action %p", action); - timer->period = interval; - timer->expiry = interval+gras_os_time(); - timer->action = action; - timer->repeat = TRUE; + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + + gras_timer_t timer = xbt_dynar_push_ptr(pd->timers); + + VERB1("Register repetitive action %p", action); + timer->period = interval; + timer->expiry = interval+gras_os_time(); + timer->action = action; + timer->repeat = TRUE; } /** @brief Cancel a delayed task */ void gras_timer_cancel_delay(double interval, void_f_void_t action) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - unsigned int cursor; - int found; - s_gras_timer_t timer; - - found = FALSE; - xbt_dynar_foreach(pd->timers,cursor,timer){ - if (timer.repeat == FALSE && - timer.period == interval && - timer.action == action) { - - found = TRUE; - xbt_dynar_cursor_rm(pd->timers, &cursor); - } - } - - if (!found) - THROW2(mismatch_error,0,"Cannot remove the action %p delayed of %f second: not found", - action,interval); - + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + unsigned int cursor; + int found; + s_gras_timer_t timer; + + found = FALSE; + xbt_dynar_foreach(pd->timers,cursor,timer){ + if (timer.repeat == FALSE && + timer.period == interval && + timer.action == action) { + + found = TRUE; + xbt_dynar_cursor_rm(pd->timers, &cursor); + } + } + + if (!found) + THROW2(mismatch_error,0,"Cannot remove the action %p delayed of %f second: not found", + action,interval); + } /** @brief Cancel a repetitive task */ void gras_timer_cancel_repeat(double interval, void_f_void_t action) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - unsigned int cursor; - int found; - s_gras_timer_t timer; - - found = FALSE; - xbt_dynar_foreach(pd->timers,cursor,timer){ - if (timer.repeat == TRUE && - timer.period == interval && - timer.action == action) { - - found = TRUE; - xbt_dynar_cursor_rm(pd->timers, &cursor); - } - } - - if (!found) - THROW2(mismatch_error,0,"Cannot remove the action %p delayed of %f second: not found", - action,interval); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + unsigned int cursor; + int found; + s_gras_timer_t timer; + + found = FALSE; + xbt_dynar_foreach(pd->timers,cursor,timer){ + if (timer.repeat == TRUE && + timer.period == interval && + timer.action == action) { + + found = TRUE; + xbt_dynar_cursor_rm(pd->timers, &cursor); + } + } + + if (!found) + THROW2(mismatch_error,0,"Cannot remove the action %p delayed of %f second: not found", + action,interval); } /** @brief Cancel all delayed tasks */ void gras_timer_cancel_delay_all(void) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - unsigned int cursor; - int found; - s_gras_timer_t timer; - - found = FALSE; - xbt_dynar_foreach(pd->timers,cursor,timer){ - if (timer.repeat == FALSE) { - - found = TRUE; - xbt_dynar_cursor_rm(pd->timers, &cursor); - } - } - - if (!found) - THROW0(mismatch_error,0,"No delayed action to remove"); - + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + unsigned int cursor; + int found; + s_gras_timer_t timer; + + found = FALSE; + xbt_dynar_foreach(pd->timers,cursor,timer){ + if (timer.repeat == FALSE) { + + found = TRUE; + xbt_dynar_cursor_rm(pd->timers, &cursor); + } + } + + if (!found) + THROW0(mismatch_error,0,"No delayed action to remove"); + } /** @brief Cancel all repetitive tasks */ void gras_timer_cancel_repeat_all(void){ - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - unsigned int cursor; - int found; - s_gras_timer_t timer; - - found = FALSE; - xbt_dynar_foreach(pd->timers,cursor,timer){ - if (timer.repeat == FALSE) { - - found = TRUE; - xbt_dynar_cursor_rm(pd->timers, &cursor); - } - } - - if (!found) - THROW0(mismatch_error,0,"No repetitive action to remove"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + unsigned int cursor; + int found; + s_gras_timer_t timer; + + found = FALSE; + xbt_dynar_foreach(pd->timers,cursor,timer){ + if (timer.repeat == FALSE) { + + found = TRUE; + xbt_dynar_cursor_rm(pd->timers, &cursor); + } + } + + if (!found) + THROW0(mismatch_error,0,"No repetitive action to remove"); } /** @brief Cancel all delayed and repetitive tasks */ void gras_timer_cancel_all(void) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - xbt_dynar_reset( pd->timers ); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + xbt_dynar_reset( pd->timers ); } - + /* returns 0 if it handled a timer, or the delay until next timer, or -1 if no armed timer */ double gras_msg_timer_handle(void) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); - unsigned int cursor; - gras_timer_t timer; - double now=gras_os_time(); - double untilnext = -1.0; - - for (cursor=0; cursor < xbt_dynar_length(pd->timers); cursor++) { - double untilthis; - - timer = xbt_dynar_get_ptr (pd->timers, cursor); - untilthis = timer->expiry - now; - - DEBUG2("Action %p expires in %f", timer->action, untilthis); - - if (untilthis <= 0.0) { - void_f_void_t action = timer->action; - - DEBUG5("[%.0f] Serve %s action %p (%f<%f)",gras_os_time(), - timer->repeat ? "repetitive" : "delayed", timer->action, - timer->expiry, now); - - if (timer->repeat) { - timer->expiry = now + timer->period; - DEBUG4("[%.0f] Re-arm repetitive action %p for %f (period=%f)", - gras_os_time(), - timer->action, timer->expiry, timer->period); - } else { - DEBUG2("[%.0f] Remove %p now that it's done", gras_os_time(), timer->action); - xbt_dynar_cursor_rm(pd->timers, &cursor); - } - (*action)(); - return 0.0; - } else if (untilthis < untilnext || untilnext == -1) { - untilnext = untilthis; - } - } - return untilnext; + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); + unsigned int cursor; + gras_timer_t timer; + double now=gras_os_time(); + double untilnext = -1.0; + + for (cursor=0; cursor < xbt_dynar_length(pd->timers); cursor++) { + double untilthis; + + timer = xbt_dynar_get_ptr (pd->timers, cursor); + untilthis = timer->expiry - now; + + DEBUG2("Action %p expires in %f", timer->action, untilthis); + + if (untilthis <= 0.0) { + void_f_void_t action = timer->action; + + DEBUG5("[%.0f] Serve %s action %p (%f<%f)",gras_os_time(), + timer->repeat ? "repetitive" : "delayed", timer->action, + timer->expiry, now); + + if (timer->repeat) { + timer->expiry = now + timer->period; + DEBUG4("[%.0f] Re-arm repetitive action %p for %f (period=%f)", + gras_os_time(), + timer->action, timer->expiry, timer->period); + } else { + DEBUG2("[%.0f] Remove %p now that it's done", gras_os_time(), timer->action); + xbt_dynar_cursor_rm(pd->timers, &cursor); + } + (*action)(); + return 0.0; + } else if (untilthis < untilnext || untilnext == -1) { + untilnext = untilthis; + } + } + return untilnext; } -- 2.20.1