From: mquinson Date: Fri, 9 Jun 2006 14:44:48 +0000 (+0000) Subject: Automatically generate matrices datatype description (same way than what we did for... X-Git-Tag: v3.3~2995 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a0cf4f541ebaa9d44fd3c8966d078713dd9ee224 Automatically generate matrices datatype description (same way than what we did for dynars), plus lots of cosmetics git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2363 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/gras/DataDesc/datadesc.c b/src/gras/DataDesc/datadesc.c index 7be56977d5..1f7cb1cf83 100644 --- a/src/gras/DataDesc/datadesc.c +++ b/src/gras/DataDesc/datadesc.c @@ -43,6 +43,9 @@ gras_datadesc_init(void) { 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); @@ -112,7 +115,7 @@ gras_datadesc_init(void) { _strlen_cb); ddt = gras_datadesc_ref("string",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")); @@ -133,7 +136,7 @@ gras_datadesc_init(void) { gras_datadesc_struct_close(ddt); - + /* specific datatype: xbt_host_t */ ddt = gras_datadesc_struct("s_xbt_host_t"); gras_datadesc_struct_append(ddt,"name",gras_datadesc_by_name("string")); gras_datadesc_struct_append(ddt,"port",gras_datadesc_by_name("int")); diff --git a/src/gras/DataDesc/ddt_create.c b/src/gras/DataDesc/ddt_create.c index 2a5cffa7fa..f8f7fc0c1d 100644 --- a/src/gras/DataDesc/ddt_create.c +++ b/src/gras/DataDesc/ddt_create.c @@ -572,6 +572,12 @@ gras_datadesc_type_t return res; } +/* + *## + *## Constructor of container datatypes + *## + */ + #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; @@ -604,34 +610,93 @@ gras_datadesc_dynar(gras_datadesc_type_t elm_t, char *buffname; gras_datadesc_type_t res; - buffname=xbt_new0(char, strlen(elm_t->name)+10); - sprintf(buffname,"dynar(%s)_s",elm_t->name); + asprintf(&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, "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, "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")); + 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_field_push(res, "used"); gras_datadesc_cb_recv(res, &gras_datadesc_dynar_cb); /* build a ref to it */ - sprintf(buffname,"dynar(%s)",elm_t->name); + free(buffname); + asprintf(&buffname,"dynar(%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; + + 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; + + /* 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); + + 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_dynar_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, diff --git a/src/gras/DataDesc/ddt_exchange.c b/src/gras/DataDesc/ddt_exchange.c index 62873e4ace..019aa5f901 100644 --- a/src/gras/DataDesc/ddt_exchange.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -160,19 +160,19 @@ gras_datadesc_copy_rec(gras_cbps_t state, 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); + 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); + 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); + 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); + 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); + 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 a value for field '%s' (type not scalar?)", field->name); } }