From 4c41f70e179eb2934ada8edadf7efedf2290693a Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 18 May 2009 08:32:41 +0000 Subject: [PATCH] Allow the exchange of 0-long dynamic vectors git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6285 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 14 +++- src/gras/DataDesc/datadesc_private.h | 8 +- src/gras/DataDesc/ddt_create.c | 14 ++-- src/gras/DataDesc/ddt_exchange.c | 112 +++++++++++++-------------- src/gras/Msg/gras_msg_exchange.c | 12 +-- src/gras/Msg/msg_interface.h | 2 +- 6 files changed, 83 insertions(+), 79 deletions(-) diff --git a/ChangeLog b/ChangeLog index bda8f2c0ec..d38785df8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,16 @@ SimGrid (3.4-svn) unstable; urgency=high - OVERALL CHANGES: - * Also include strbuff from xbt.h public header - GRAS: * fix a bug on struct sizeof computation, which prevented the exchange of arrays of structs in some conditions + * Allow the exchange of 0-long dynamic vectors. + - for that, use -1 as indicator of dynamic size instead of 0 + - This implied to change any size from unsigned long to long, + reducing a bit communication abilities, but I guess that with + 64bits being quite common, this is more than enough. + - This also induce a protocol change, thus bumping network protocol + version from 0 to 1 (if we have external users, we have to get + clean on that point too ;) MSG: * Allow to control the simulation from a trace file. @@ -25,6 +30,7 @@ SimGrid (3.4-svn) unstable; urgency=high process in the log messages. XBT: + * Also include strbuff from xbt.h public header * xbt_ex_display(): do not free the exception after displaying This allows to do more with the given exception afterward. Users should call xbt_ex_free() themselves. @@ -1206,4 +1212,4 @@ SimGrid (2.90) unstable; urgency=low For information, the beginning of coding on GRAS was back in june 2003. I guess that every line has been rewritten at least twice since -then. \ No newline at end of file +then. diff --git a/src/gras/DataDesc/datadesc_private.h b/src/gras/DataDesc/datadesc_private.h index 5560238652..f54928bce3 100644 --- a/src/gras/DataDesc/datadesc_private.h +++ b/src/gras/DataDesc/datadesc_private.h @@ -175,8 +175,8 @@ typedef struct s_gras_dd_cat_ref { typedef struct s_gras_dd_cat_array { gras_datadesc_type_t type; - /* element_count == 0 means dynamically defined */ - unsigned long int fixed_size; + /* element_count == -1 means dynamically defined */ + long int fixed_size; /* callback used to return the dynamic length */ gras_datadesc_type_cb_int_t dynamic_size; @@ -207,12 +207,12 @@ union u_gras_datadesc_category { */ typedef struct s_gras_datadesc_type { /* headers for the data set */ - unsigned int code; + int code; char *name; unsigned int name_len; /* payload */ - unsigned long int size[gras_arch_count]; + long int size[gras_arch_count]; /* Cannot be unsigned: -1 means dynamic */ unsigned long int alignment[gras_arch_count]; unsigned long int aligned_size[gras_arch_count]; diff --git a/src/gras/DataDesc/ddt_create.c b/src/gras/DataDesc/ddt_create.c index 72e896fd52..db76927f39 100644 --- a/src/gras/DataDesc/ddt_create.c +++ b/src/gras/DataDesc/ddt_create.c @@ -2,9 +2,7 @@ /* ddt_new - creation/deletion of datatypes structs (private to this module)*/ -/* Copyright (c) 2003 Olivier Aumage. */ -/* Copyright (c) 2003, 2004 Martin Quinson. */ -/* All rights reserved. */ +/* Copyright (c) 2003-2009 The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -202,7 +200,7 @@ gras_datadesc_struct_append(gras_datadesc_type_t struct_type, return; } - xbt_assert1(field_type->size != 0, + xbt_assert1(field_type->size[GRAS_THISARCH] >= 0, "Cannot add a dynamically sized field in structure %s", struct_type->name); @@ -339,7 +337,7 @@ void gras_datadesc_union_append(gras_datadesc_type_t union_type, int arch; XBT_IN3("(%s %s.%s;)",field_type->name,union_type->name,name); - xbt_assert1(field_type->size != 0, + xbt_assert1(field_type->size[GRAS_THISARCH] >= 0, "Cannot add a dynamically sized field in union %s", union_type->name); @@ -507,7 +505,7 @@ gras_datadesc_array_fixed(const char *name, } res = gras_ddt_new(name); - xbt_assert1(fixed_size > 0, "'%s' is a array of null fixed size",name); + xbt_assert1(fixed_size >= 0, "'%s' is a array of negative fixed size",name); for (arch=0; archsize[arch] = fixed_size * element_type->aligned_size[arch]; res->alignment[arch] = element_type->alignment[arch]; @@ -542,7 +540,7 @@ gras_datadesc_type_t gras_datadesc_array_dyn(const char *name, "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, + xbt_assert1(res->category.array_data.fixed_size == -1, "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); @@ -562,7 +560,7 @@ gras_datadesc_type_t gras_datadesc_array_dyn(const char *name, 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.fixed_size = -1; res->category.array_data.dynamic_size = dynamic_size; return res; diff --git a/src/gras/DataDesc/ddt_exchange.c b/src/gras/DataDesc/ddt_exchange.c index 8c597ecabb..90454a5a03 100644 --- a/src/gras/DataDesc/ddt_exchange.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -2,9 +2,7 @@ /* ddt_exchange - send/recv data described */ -/* Copyright (c) 2003 Olivier Aumage. */ -/* Copyright (c) 2003, 2004, 2005 Martin Quinson. */ -/* All rights reserved. */ +/* Copyright (c) 2003-2009 The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -20,42 +18,42 @@ const char *gras_datadesc_cat_names[9] = { "scalar", "struct", "union", "ref", "array", "ignored", "invalid"}; -static gras_datadesc_type_t uint_type = NULL; +static gras_datadesc_type_t int_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) { +gras_dd_send_int(gras_socket_t sock, int *i, int stable) { - if (!uint_type) { - uint_type = gras_datadesc_by_name("unsigned int"); - xbt_assert(uint_type); + if (!int_type) { + int_type = gras_datadesc_by_name("int"); + xbt_assert(int_type); } - DEBUG1("send_uint(%u)",*i); - gras_trp_send(sock, (char*)i, uint_type->size[GRAS_THISARCH], stable); + DEBUG1("send_int(%u)",*i); + gras_trp_send(sock, (char*)i, int_type->size[GRAS_THISARCH], stable); } static XBT_INLINE void -gras_dd_recv_uint(gras_socket_t sock, int r_arch, unsigned int *i) { +gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) { - if (!uint_type) { - uint_type = gras_datadesc_by_name("unsigned int"); - xbt_assert(uint_type); + if (!int_type) { + int_type = gras_datadesc_by_name("int"); + xbt_assert(int_type); } - if (uint_type->size[GRAS_THISARCH] >= uint_type->size[r_arch]) { - gras_trp_recv(sock, (char*)i, uint_type->size[r_arch]); + if (int_type->size[GRAS_THISARCH] >= int_type->size[r_arch]) { + gras_trp_recv(sock, (char*)i, int_type->size[r_arch]); if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(uint_type,1,r_arch, i,i); + gras_dd_convert_elm(int_type,1,r_arch, i,i); } else { - void *ptr = xbt_malloc(uint_type->size[r_arch]); + void *ptr = xbt_malloc(int_type->size[r_arch]); - gras_trp_recv(sock, (char*)ptr, uint_type->size[r_arch]); + gras_trp_recv(sock, (char*)ptr, int_type->size[r_arch]); if (r_arch != GRAS_THISARCH) - gras_dd_convert_elm(uint_type,1,r_arch, ptr,i); + gras_dd_convert_elm(int_type,1,r_arch, ptr,i); free(ptr); } - DEBUG1("recv_uint(%u)",*i); + DEBUG1("recv_int(%u)",*i); } /* @@ -253,7 +251,7 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, } if (reference_is_to_cpy) { - int subsubcount = 0; + int subsubcount = -1; void *l_referenced=NULL; VERB2("Copy a ref to '%s' referenced at %p",sub_type->name, (void*)*o_ref); @@ -263,21 +261,21 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, } 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 */ + /* 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) + if (subsubcount == -1) 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); + if (subsubcount != 0) + 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], @@ -314,9 +312,9 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, /* determine and send the element count */ array_count = array_data.fixed_size; - if (array_count == 0) + if (array_count == -1) array_count = subsize; - if (array_count == 0) { + if (array_count == -1) { array_count = array_data.dynamic_size(type,state,src); xbt_assert1(array_count >=0, "Invalid (negative) array size for type %s",type->name); @@ -354,7 +352,7 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, } default: - xbt_assert0(0, "Invalid type"); + xbt_die("Invalid type"); } return count; @@ -375,6 +373,7 @@ int gras_datadesc_memcpy(gras_datadesc_type_t type, xbt_assert0(type,"called with NULL type descriptor"); + DEBUG3("Memcopy a %s from %p to %p",gras_datadesc_get_name(type),src,dst); if (!state) { state = gras_cbps_new(); refs = xbt_dict_new(); @@ -458,7 +457,7 @@ gras_datadesc_send_rec(gras_socket_t sock, 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; + int field_num; union_data = type->category.union_data; @@ -477,7 +476,7 @@ gras_datadesc_send_rec(gras_socket_t sock, type->name, field_num, xbt_dynar_length(union_data.fields)); /* Send the field number */ - gras_dd_send_uint(sock, &field_num, 0 /* not stable */); + gras_dd_send_int(sock, &field_num, 0 /* not stable */); /* Send the content */ field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); @@ -503,7 +502,7 @@ gras_datadesc_send_rec(gras_socket_t sock, 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*/); + gras_dd_send_int(sock, &(sub_type->code),1 /*stable*/); } /* Send the actual value of the pointer for cycle handling */ @@ -551,7 +550,7 @@ gras_datadesc_send_rec(gras_socket_t sock, case e_gras_datadesc_type_cat_array: { gras_dd_cat_array_t array_data; - unsigned int count; + int count; char *ptr=data; long int elm_size; @@ -559,11 +558,11 @@ gras_datadesc_send_rec(gras_socket_t sock, /* determine and send the element count */ count = array_data.fixed_size; - if (count == 0) { + if (count == -1) { 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*/); + gras_dd_send_int(sock, &count, 0/*non-stable*/); } /* send the content */ @@ -595,7 +594,7 @@ gras_datadesc_send_rec(gras_socket_t sock, } default: - xbt_assert0(0, "Invalid type"); + xbt_die("Invalid type"); } } @@ -711,7 +710,7 @@ gras_datadesc_recv_rec(gras_socket_t sock, 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; + int field_num; union_data = type->category.union_data; @@ -719,7 +718,7 @@ gras_datadesc_recv_rec(gras_socket_t sock, "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); + gras_dd_recv_int(sock, r_arch, &field_num); if (field_num < 0) THROW1(mismatch_error,0, "Received union field for %s is negative", type->name); @@ -753,8 +752,8 @@ gras_datadesc_recv_rec(gras_socket_t sock, /* 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); + int ref_code; + gras_dd_recv_int(sock, r_arch, &ref_code); sub_type = gras_datadesc_by_id(ref_code); } @@ -793,20 +792,19 @@ gras_datadesc_recv_rec(gras_socket_t sock, } if (reference_is_to_recv) { - unsigned int subsubcount = 0; + int subsubcount = -1; 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 */ + /* 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); + if (subsubcount == -1) + gras_dd_recv_int(sock, r_arch, &subsubcount); subsub_type = array_data.type; @@ -845,20 +843,20 @@ gras_datadesc_recv_rec(gras_socket_t sock, case e_gras_datadesc_type_cat_array: { gras_dd_cat_array_t array_data; - unsigned int count; + 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) + if (count == -1) count = subsize; - if (count == 0) - gras_dd_recv_uint(sock, r_arch, &count); - if (count == 0) + if (count == -1) + gras_dd_recv_int(sock, r_arch, &count); + if (count == -1) THROW1(mismatch_error,0, - "Invalid (=0) array size for type %s",type->name); + "Invalid (=-1) array size for type %s",type->name); /* receive the content */ sub_type = array_data.type; @@ -880,7 +878,7 @@ gras_datadesc_recv_rec(gras_socket_t sock, 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.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; @@ -923,7 +921,7 @@ gras_datadesc_recv_rec(gras_socket_t sock, } default: - xbt_assert0(0, "Invalid type"); + xbt_die("Invalid type"); } if (type->recv) diff --git a/src/gras/Msg/gras_msg_exchange.c b/src/gras/Msg/gras_msg_exchange.c index 48d1b31b89..89bd7d74c2 100644 --- a/src/gras/Msg/gras_msg_exchange.c +++ b/src/gras/Msg/gras_msg_exchange.c @@ -2,8 +2,7 @@ /* gras message exchanges */ -/* Copyright (c) 2003, 2004, 2005, 2006, 2007 Martin Quinson. */ -/* All rights reserved. */ +/* Copyright (c) 2003-2009. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -395,7 +394,7 @@ gras_msg_handle(double timeOut) { TRY { xbt_dynar_foreach(list->cbs,cpt,cb) { if (!ran_ok) { - DEBUG4("Use the callback #%d (@%p) for incomming msg %s (payload_size=%d)", + DEBUG4("Use the callback #%d (@%p) for incomming msg '%s' (payload_size=%d)", cpt+1,cb,msg.type->name,msg.payl_size); if (!(*cb)(&ctx,msg.payl)) { /* cb handled the message */ @@ -418,12 +417,14 @@ gras_msg_handle(double timeOut) { e.host = (char*)gras_os_myname(); xbt_ex_setup_backtrace(&e); } - VERB5("Propagate %s exception ('%s') from '%s' RPC cb back to %s:%d", + INFO5("Propagate %s exception ('%s') from '%s' RPC cb back to %s:%d", (e.remote ? "remote" : "local"), e.msg, msg.type->name, gras_socket_peer_name(msg.expe), gras_socket_peer_port(msg.expe)); + if (XBT_LOG_ISENABLED(gras_msg,xbt_log_priority_info)) + xbt_ex_display(&e); gras_msg_send_ext(msg.expe, e_gras_msg_kind_rpcerror, msg.ID, msg.type, &e); e.file=old_file; @@ -431,7 +432,8 @@ gras_msg_handle(double timeOut) { ctx.answer_due = 0; ran_ok=1; } else { - RETHROW0("Callback raised an exception: %s"); + RETHROW4("Callback #%d (@%p) to message '%s' (payload size: %d) raised an exception: %s", + cpt+1,cb,msg.type->name,msg.payl_size); } } diff --git a/src/gras/Msg/msg_interface.h b/src/gras/Msg/msg_interface.h index 09df7c8738..092284133f 100644 --- a/src/gras/Msg/msg_interface.h +++ b/src/gras/Msg/msg_interface.h @@ -52,7 +52,7 @@ void gras_msg_send_namev(gras_socket_t sock, void gras_msg_listener_awake(void); void gras_msg_listener_close_socket(int sd); -#define GRAS_PROTOCOL_VERSION '\0'; +#define GRAS_PROTOCOL_VERSION '\1'; #endif /* GRAS_MSG_INTERFACE_H */ -- 2.20.1