- case e_gras_datadesc_type_cat_union: {
- gras_dd_cat_union_t union_data;
- gras_dd_cat_field_t field=NULL;
- int field_num;
-
- union_data = type->category.union_data;
-
- xbt_assert1(union_data.closed,
- "Please call gras_datadesc_declare_union_close on %s before sending it",
- type->name);
- /* retrieve the field number */
- field_num = union_data.selector(state, data);
-
- xbt_assert1(field_num > 0,
- "union field selector of %s gave a negative value",
- type->name);
-
- xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
- "union field selector of %s returned %d but there is only %lu fields",
- type->name, field_num, xbt_dynar_length(union_data.fields));
-
- /* Send the field number */
- TRY(gras_dd_send_int(sock, field_num));
-
- /* Send the content */
- field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
- sub_type = field->type;
-
- if (field->pre)
- field->pre(state,data);
-
- TRY(gras_datadesc_send_rec(sock,state,refs, sub_type, data, detect_cycle || sub_type->cycle));
-
- if (field->post)
- field->post(state,data);
-
- break;
- }
-
- case e_gras_datadesc_type_cat_ref: {
- gras_dd_cat_ref_t ref_data;
-
- void **ref=(void**)data;
- void *dummy;
-
- ref_data = type->category.ref_data;
-
- /* Detect the referenced type and send it to peer if needed */
- sub_type = ref_data.type;
- if (sub_type == NULL) {
- sub_type = (*ref_data.selector)(state,data);
- TRY(gras_dd_send_int(sock, sub_type->code));
- }
-
- /* Send the actual value of the pointer for cycle handling */
- if (!pointer_type) {
- pointer_type = gras_datadesc_by_name("data pointer");
- xbt_assert(pointer_type);
- }
-
- TRY(gras_trp_chunk_send(sock, (char*)data,
- pointer_type->size[GRAS_THISARCH]));
-
- /* Send the pointed data only if not already sent */
- if (*(void**)data == NULL) {
- VERB0("Not sending NULL referenced data");
- break;
- }
- errcode = detect_cycle
- ? xbt_dict_get_ext(refs,(char*)ref, sizeof(void*), &dummy)
- : mismatch_error;
- if (errcode == mismatch_error) {
- VERB1("Sending data referenced at %p", (void*)*ref);
- if (detect_cycle)
- xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
- TRY(gras_datadesc_send_rec(sock,state,refs, sub_type, *ref, detect_cycle || sub_type->cycle));
-
- } else if (errcode == no_error) {
- VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
- } else {
- return errcode;
- }
-
- break;
- }
-
- case e_gras_datadesc_type_cat_array: {
- gras_dd_cat_array_t array_data;
- long int count;
- char *ptr=data;
- long int elm_size;
-
- array_data = type->category.array_data;
-
- /* determine and send the element count */
- count = array_data.fixed_size;
- if (count == 0) {
- count = array_data.dynamic_size(state,data);
- xbt_assert1(count >=0,
- "Invalid (negative) array size for type %s",type->name);
- TRY(gras_dd_send_int(sock, count));
- }
-
- /* 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) {
- VERB1("Array of %ld scalars, send it in one shot",count);
- TRY(gras_trp_chunk_send(sock, data,
- sub_type->aligned_size[GRAS_THISARCH] * 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) {
-
- VERB1("Array of %ld fixed array of scalars, send it in one shot",count);
- TRY(gras_trp_chunk_send(sock, data,
- sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
- * count * sub_type->category.array_data.fixed_size));
-
- } else {
- for (cpt=0; cpt<count; cpt++) {
- TRY(gras_datadesc_send_rec(sock,state,refs, sub_type, ptr, detect_cycle || sub_type->cycle));
- ptr += elm_size;