X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e649c3530c0f9b73ecf464f7b2834f4b3da004e3..5fb2fa67ea062d8c26cfe3e6669a93fc2b7607bd:/src/gras/DataDesc/ddt_create.c diff --git a/src/gras/DataDesc/ddt_create.c b/src/gras/DataDesc/ddt_create.c index ebb8df9ea1..5dfcdea030 100644 --- a/src/gras/DataDesc/ddt_create.c +++ b/src/gras/DataDesc/ddt_create.c @@ -14,6 +14,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions"); +/*** prototypes ***/ +static gras_dd_cat_field_t + gras_dd_find_field(gras_datadesc_type_t type, + const char *field_name); /** * gras_ddt_freev: * @@ -117,13 +121,13 @@ void gras_dd_cat_field_free(void *f) { XBT_IN; if (field) { if (field->name) - xbt_free(field->name); - xbt_free(field); + free(field->name); + free(field); } XBT_OUT; } -/** Create a new struct and give a pointer to it */ +/** \brief Declare a new structure description */ gras_datadesc_type_t gras_datadesc_struct(const char *name) { @@ -155,7 +159,7 @@ gras_datadesc_type_t return res; } -/** Append a field to the struct */ +/** \brief Append a new field to a structure description */ void gras_datadesc_struct_append(gras_datadesc_type_t struct_type, const char *name, @@ -199,8 +203,8 @@ gras_datadesc_struct_append(gras_datadesc_type_t struct_type, struct_type->alignment[arch]); } field->type = field_type; - field->pre = NULL; - field->post = NULL; + field->send = NULL; + field->recv = NULL; xbt_dynar_push(struct_type->category.struct_data.fields, &field); @@ -217,7 +221,9 @@ gras_datadesc_struct_append(gras_datadesc_type_t struct_type, XBT_OUT; } -/** No new field can be added afterward, and it is mandatory to close the structure before using it. +/** \brief Close a structure description + * + * No new field can be added afterward, and it is mandatory to close the structure before using it. */ void gras_datadesc_struct_close(gras_datadesc_type_t struct_type) { @@ -234,7 +240,7 @@ gras_datadesc_struct_close(gras_datadesc_type_t struct_type) { * gras_datadesc_cycle_set: * * Tell GRAS that the pointers of the type described by ddt may present - * some loop, and that the cycle detection mecanism is needed. + * some loop, and that the cycle detection mechanism is needed. * * Note that setting this option when not needed have a rather bad effect * on the performance (several times slower on big data). @@ -248,7 +254,7 @@ gras_datadesc_cycle_set(gras_datadesc_type_t ddt) { * gras_datadesc_cycle_unset: * * Tell GRAS that the pointers of the type described by ddt do not present - * any loop and that cycle detection mecanism are not needed. + * any loop and that cycle detection mechanism are not needed. * (default) */ void @@ -256,14 +262,10 @@ gras_datadesc_cycle_unset(gras_datadesc_type_t ddt) { ddt->cycle = 0; } -/** - * gras_datadesc_union: - * - * Create a new union and give a pointer to it - */ +/** \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_union(const char *name, + gras_datadesc_type_cb_int_t selector) { gras_datadesc_type_t res; int arch; @@ -300,15 +302,10 @@ gras_datadesc_union(const char *name, return res; } -/** - * gras_datadesc_union_append: - * - * Append a field to the union - */ -void -gras_datadesc_union_append(gras_datadesc_type_t union_type, - const char *name, - gras_datadesc_type_t field_type) { +/** \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; @@ -343,12 +340,16 @@ gras_datadesc_union_append(gras_datadesc_type_t union_type, } -/** No new field can be added afterward, and it is mandatory to close the union before using it.*/ +/** \brief Close an union description + * + * No new field can be added afterward, and it is mandatory to close the union before using it. + */ void gras_datadesc_union_close(gras_datadesc_type_t union_type) { union_type->category.union_data.closed = 1; } +/** \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) { @@ -386,7 +387,8 @@ gras_datadesc_type_t return res; } -/** +/** \brief Declare a new type being a generic reference. + * * The callback passed in argument is to be used to select which type is currently used. * So, when GRAS wants to send a generic reference, it passes the current data to the selector * callback and expects it to return the type description to use. @@ -429,9 +431,7 @@ gras_datadesc_type_t return res; } -/* - * Create a new array and give a pointer to it - */ +/** \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, @@ -445,8 +445,13 @@ gras_datadesc_type_t 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); + + 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, @@ -472,13 +477,11 @@ gras_datadesc_type_t return res; } -/* - * Create a new array and give a pointer to it - */ -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) { + +/** \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; @@ -520,7 +523,8 @@ gras_datadesc_type_t return res; } -/** +/** \brief Declare a new type being an array which size can be found with \ref gras_cbps_i_pop + * * Most of the time, you want to include a reference in your structure which * is a pointer to a dynamic array whose size is fixed by another field of * your structure. @@ -555,10 +559,66 @@ gras_datadesc_type_t sprintf(name,"%s[]*",element_type->name); res = gras_datadesc_ref(name,res); - xbt_free(name); + free(name); return res; } + +#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; + + 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; + + /* 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); + + dynar->elmsize = subtype->size[GRAS_THISARCH]; + dynar->size = dynar->used; +} + +gras_datadesc_type_t +gras_datadesc_dynar(gras_datadesc_type_t elm_t, + void_f_pvoid_t *free_func) { + + char *buffname; + gras_datadesc_type_t res; + + buffname=xbt_new0(char, strlen(elm_t->name)+10); + sprintf(buffname,"dynar(%s)_s",elm_t->name); + + res = gras_datadesc_struct(buffname); + + 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_cb_field_push(res, "used"); + + 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")); + memcpy(res->extra,&free_func,sizeof(free_func)); + + gras_datadesc_struct_close(res); + + gras_datadesc_cb_recv(res, &gras_datadesc_dynar_cb); + + /* build a ref to it */ + sprintf(buffname,"dynar(%s)",elm_t->name); + res=gras_datadesc_ref(buffname,res); + free(buffname); + return res; +} + xbt_error_t gras_datadesc_import_nws(const char *name, const DataDescriptor *desc, @@ -586,7 +646,7 @@ void gras_datadesc_cb_recv(gras_datadesc_type_t type, * * Returns the type descriptor of the given field. Abort on error. */ -static gras_datadesc_type_t +static gras_dd_cat_field_t gras_dd_find_field(gras_datadesc_type_t type, const char *field_name) { xbt_dynar_t field_array; @@ -604,7 +664,7 @@ static gras_datadesc_type_t } xbt_dynar_foreach(field_array,field_num,field) { if (!strcmp(field_name,field->name)) { - return field->type; + return field; } } ERROR2("No field nammed %s in %s",field_name,type->name); @@ -620,8 +680,8 @@ void gras_datadesc_cb_field_send (gras_datadesc_type_t type, const char *field_name, gras_datadesc_type_cb_void_t send) { - gras_datadesc_type_t sub_type=gras_dd_find_field(type,field_name); - sub_type->send = send; + gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); + field->send = send; } /** @@ -632,15 +692,19 @@ void gras_datadesc_cb_field_send (gras_datadesc_type_t type, void gras_datadesc_cb_field_push (gras_datadesc_type_t type, const char *field_name) { - gras_datadesc_type_t sub_type=gras_dd_find_field(type,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)) { - sub_type->send = gras_datadesc_cb_push_int; + field->send = gras_datadesc_cb_push_int; } else if (!strcmp("unsigned int",sub_type->name)) { - sub_type->send = gras_datadesc_cb_push_uint; + field->send = gras_datadesc_cb_push_uint; } else if (!strcmp("long int",sub_type->name)) { - sub_type->send = gras_datadesc_cb_push_lint; + field->send = gras_datadesc_cb_push_lint; } else if (!strcmp("unsigned long int",sub_type->name)) { - sub_type->send = gras_datadesc_cb_push_ulint; + 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); @@ -655,8 +719,8 @@ void gras_datadesc_cb_field_recv(gras_datadesc_type_t type, const char *field_name, gras_datadesc_type_cb_void_t recv) { - gras_datadesc_type_t sub_type=gras_dd_find_field(type,field_name); - sub_type->recv = recv; + gras_dd_cat_field_t field=gras_dd_find_field(type,field_name); + field->recv = recv; } /* @@ -673,13 +737,6 @@ void gras_datadesc_free(gras_datadesc_type_t *type) { /* nothing to free in there */ break; - case e_gras_datadesc_type_cat_ignored: - if ((*type)->category.ignored_data.free_func) { - (*type)->category.ignored_data.free_func - ((*type)->category.ignored_data.default_value); - } - break; - case e_gras_datadesc_type_cat_struct: xbt_dynar_free(&( (*type)->category.struct_data.fields )); break; @@ -692,8 +749,8 @@ void gras_datadesc_free(gras_datadesc_type_t *type) { /* datadesc was invalid. Killing it is like euthanasy, I guess */ break; } - xbt_free((*type)->name); - xbt_free(*type); + free((*type)->name); + free(*type); type=NULL; } @@ -844,8 +901,6 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t d1, break; - case e_gras_datadesc_type_cat_ignored: - /* That's ignored... */ default: /* two stupidly created ddt are equally stupid ;) */ break;