From 7dc1f0e2c0b12206841e4acbe2b0f8e5bc6bbb86 Mon Sep 17 00:00:00 2001 From: mquinson Date: Thu, 19 Jul 2007 04:50:48 +0000 Subject: [PATCH] New function allowing to alias datatypes git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3866 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/gras/datadesc.h | 3 +++ src/gras/DataDesc/ddt_create.c | 16 ++++++++++++++++ src/gras/DataDesc/ddt_exchange.c | 18 +++++++++--------- src/gras/Msg/sg_msg.c | 12 ++++++------ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/include/gras/datadesc.h b/include/gras/datadesc.h index 0966e86183..a3c27d2698 100644 --- a/include/gras/datadesc.h +++ b/include/gras/datadesc.h @@ -348,6 +348,9 @@ XBT_PUBLIC(void) gras_datadesc_union_close(gras_datadesc_type_t union_type); XBT_PUBLIC(gras_datadesc_type_t) gras_datadesc_ref(const char *name, gras_datadesc_type_t referenced_type); +XBT_PUBLIC(gras_datadesc_type_t) + gras_datadesc_copy(const char *name, + gras_datadesc_type_t copied_type); XBT_PUBLIC(gras_datadesc_type_t) gras_datadesc_ref_generic(const char *name, gras_datadesc_selector_t selector); diff --git a/src/gras/DataDesc/ddt_create.c b/src/gras/DataDesc/ddt_create.c index d0e2792c6e..87e7c56018 100644 --- a/src/gras/DataDesc/ddt_create.c +++ b/src/gras/DataDesc/ddt_create.c @@ -373,6 +373,22 @@ gras_datadesc_union_close(gras_datadesc_type_t union_type) { union_type->category.union_data.closed = 1; } +/** \brief Copy a type under another name + * + * 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_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; + } + /** \brief Declare a new type being a reference to the one passed in arg */ gras_datadesc_type_t gras_datadesc_ref(const char *name, diff --git a/src/gras/DataDesc/ddt_exchange.c b/src/gras/DataDesc/ddt_exchange.c index 8c15e20abc..e0d59d16ae 100644 --- a/src/gras/DataDesc/ddt_exchange.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -105,7 +105,7 @@ gras_dd_alloc_ref(xbt_dict_t refs, } static int -gras_datadesc_copy_rec(gras_cbps_t state, +gras_datadesc_memcpy_rec(gras_cbps_t state, xbt_dict_t refs, gras_datadesc_type_t type, char *src, @@ -154,7 +154,7 @@ gras_datadesc_copy_rec(gras_cbps_t state, field->send(type,state,field_src); DEBUG1("Copy field %s",field->name); - count += gras_datadesc_copy_rec(state,refs,sub_type, field_src, field_dst, 0, + 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)) { @@ -209,7 +209,7 @@ gras_datadesc_copy_rec(gras_cbps_t state, if (field->send) field->send(type,state,src); - count += gras_datadesc_copy_rec(state,refs, sub_type, src, dst,0, + count += gras_datadesc_memcpy_rec(state,refs, sub_type, src, dst,0, detect_cycle || sub_type->cycle); break; @@ -285,7 +285,7 @@ gras_datadesc_copy_rec(gras_cbps_t state, detect_cycle); } - count += gras_datadesc_copy_rec(state,refs, sub_type, + count += gras_datadesc_memcpy_rec(state,refs, sub_type, *o_ref,(char*)l_referenced, subsubcount, detect_cycle || sub_type->cycle); @@ -344,7 +344,7 @@ gras_datadesc_copy_rec(gras_cbps_t state, 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; @@ -360,13 +360,13 @@ gras_datadesc_copy_rec(gras_cbps_t state, return count; } /** - * gras_datadesc_copy: + * gras_datadesc_memcpy: * * 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_copy(gras_datadesc_type_t type, +int gras_datadesc_memcpy(gras_datadesc_type_t type, void *src, void *dst) { xbt_ex_t e; static gras_cbps_t state=NULL; @@ -381,8 +381,8 @@ int gras_datadesc_copy(gras_datadesc_type_t type, } TRY { - size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0, - type->cycle); + size = gras_datadesc_memcpy_rec(state,refs,type,(char*)src,(char*)dst,0, + type->cycle); } CLEANUP { xbt_dict_reset(refs); gras_cbps_reset(state); diff --git a/src/gras/Msg/sg_msg.c b/src/gras/Msg/sg_msg.c index 0012b3e79b..6abe45c481 100644 --- a/src/gras/Msg/sg_msg.c +++ b/src/gras/Msg/sg_msg.c @@ -54,20 +54,20 @@ void gras_msg_send_ext(gras_socket_t sock, /* 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_copy(gras_datadesc_by_name("ex_t"), - payload,msg->payl); + 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); msg->payl=xbt_malloc(msg->payl_size); if (msgtype->answer_type) - whole_payload_size = gras_datadesc_copy(msgtype->answer_type, - payload, msg->payl); + 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_copy(msgtype->ctn_type, - payload, msg->payl); + whole_payload_size = gras_datadesc_memcpy(msgtype->ctn_type, + payload, msg->payl); } /* put the selectable socket on the queue */ -- 2.20.1