+
+ 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) {
+ XBT_VERB("Not copying NULL referenced data");
+ *(void **) dst = NULL;
+ break;
+ }
+ o_ref = (char **) src;
+
+ reference_is_to_cpy = 1;
+ if (detect_cycle &&
+ (n_ref =
+ xbt_dict_get_or_null_ext(refs, (char *) o_ref,
+ sizeof(char *)))) {
+ /* already known, no need to copy it */
+ //XBT_INFO("Cycle detected");
+ reference_is_to_cpy = 0;
+ }
+
+ if (reference_is_to_cpy) {
+ int subsubcount = -1;
+ void *l_referenced = NULL;
+ XBT_VERB("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 == -1)
+ subsubcount =
+ array_data.dynamic_size(subsub_type, state, *o_ref);
+
+ 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],
+ (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;
+ XBT_VERB("'%s' previously referenced at %p now at %p",
+ sub_type->name, *(void **) o_ref, l_referenced);
+
+ } else {
+ XBT_VERB
+ ("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 == -1)
+ array_count = subsize;
+ if (array_count == -1) {
+ array_count = array_data.dynamic_size(type, state, src);
+ xbt_assert(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) {
+ XBT_VERB("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) {
+
+ XBT_VERB("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 {
+ XBT_VERB("Array of %ld stuff, copy it in one after the other",
+ array_count);
+ for (cpt = 0; cpt < array_count; cpt++) {
+ XBT_VERB("Copy the %dth stuff out of %ld", cpt, array_count);
+ count +=
+ gras_datadesc_memcpy_rec(state, refs, sub_type, src_ptr,
+ dst_ptr, 0, detect_cycle
+ || sub_type->cycle);
+ src_ptr += elm_size;
+ dst_ptr += elm_size;
+ }
+ }
+ break;
+ }
+