+ * \param elm_t: the datadesc of the elements
+ * \param free_func: the function to use to free the elements when the dynar gets freed
+ */
+gras_datadesc_type_t
+gras_datadesc_dynar(gras_datadesc_type_t elm_t, void_f_pvoid_t free_func)
+{
+
+ char *buffname;
+ gras_datadesc_type_t res;
+
+ buffname = bprintf("s_xbt_dynar_of_%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, "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, "data",
+ gras_datadesc_ref_pop_arr(elm_t));
+
+ gras_datadesc_struct_append(res, "free_f",
+ gras_datadesc_by_name("function pointer"));
+ memcpy(res->extra, &free_func, sizeof(free_func));
+
+ gras_datadesc_struct_append(res, "mutex",
+ gras_datadesc_by_name("data pointer"));
+
+ 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 */
+ free(buffname);
+ buffname = bprintf("xbt_dynar_of_%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;
+
+ XBT_DEBUG("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;
+
+ buffname = bprintf("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_matrix_cb);
+ memcpy(res->extra, &free_f, sizeof(free_f));
+
+ /* build a ref to it */
+ free(buffname);
+ buffname = bprintf("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,
+ const DataDescriptor * desc,
+ unsigned long howmany)
+{
+ THROW_UNIMPLEMENTED;
+}
+
+/**
+ * (useful to push the sizes of the upcoming arrays, for example)
+ */
+void gras_datadesc_cb_send(gras_datadesc_type_t type,
+ gras_datadesc_type_cb_void_t send)
+{
+ type->send = send;
+}
+
+/**
+ * (useful to put the function pointers to the rigth value, for example)
+ */
+void gras_datadesc_cb_recv(gras_datadesc_type_t type,
+ gras_datadesc_type_cb_void_t recv)
+{
+ type->recv = recv;
+}
+
+/*
+ * gras_dd_find_field:
+ *
+ * Returns the type descriptor of the given field. Abort on error.
+ */
+static gras_dd_cat_field_t
+gras_dd_find_field(gras_datadesc_type_t type, const char *field_name)
+{
+ xbt_dynar_t field_array;
+
+ gras_dd_cat_field_t field = NULL;
+ unsigned int field_num;
+
+ if (type->category_code == e_gras_datadesc_type_cat_union) {
+ field_array = type->category.union_data.fields;
+ } else if (type->category_code == e_gras_datadesc_type_cat_struct) {
+ field_array = type->category.struct_data.fields;
+ } else {
+ XBT_ERROR("%s (%p) is not a struct nor an union. There is no field.",
+ type->name, (void *) type);
+ xbt_abort();
+ }
+ xbt_dynar_foreach(field_array, field_num, field) {
+ if (!strcmp(field_name, field->name)) {
+ return field;
+ }
+ }
+ XBT_ERROR("No field named '%s' in '%s'", field_name, type->name);
+ xbt_abort();
+
+}
+
+/**
+ * The given datadesc must be a struct or union (abort if not).
+ * (useful to push the sizes of the upcoming arrays, for example)