3 /* ddt_new - creation/deletion of datatypes structs (private to this module)*/
5 /* Copyright (c) 2003 Olivier Aumage. */
6 /* Copyright (c) 2003, 2004 Martin Quinson. */
7 /* All rights reserved. */
9 /* This program is free software; you can redistribute it and/or modify it
10 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #include "xbt/misc.h" /* min()/max() */
13 #include "gras/DataDesc/datadesc_private.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions");
18 static gras_dd_cat_field_t
19 gras_dd_find_field(gras_datadesc_type_t type,
20 const char *field_name);
24 * gime that memory back, dude. I mean it.
26 void gras_ddt_freev(void *ddt) {
27 gras_datadesc_type_t type= (gras_datadesc_type_t)ddt;
30 gras_datadesc_free(&type);
34 static gras_datadesc_type_t gras_ddt_new(const char *name) {
35 gras_datadesc_type_t res;
38 res=xbt_new0(s_gras_datadesc_type_t,1);
40 res->name = (char*)strdup(name);
41 res->name_len = strlen(name);
44 xbt_set_add(gras_datadesc_set_local,
45 (xbt_set_elm_t)res,&gras_ddt_freev);
51 * This returns NULL when no type of this name can be found
53 gras_datadesc_type_t gras_datadesc_by_name(const char *name) {
55 gras_datadesc_type_t type;
58 if (xbt_set_get_by_name(gras_datadesc_set_local,
59 name,(xbt_set_elm_t*)&type) == no_error) {
69 * Retrieve a type from its code
71 xbt_error_t gras_datadesc_by_id(long int code,
72 gras_datadesc_type_t *type) {
74 return xbt_set_get_by_id(gras_datadesc_set_local,
75 code,(xbt_set_elm_t*)type);
79 * Create a new scalar and give a pointer to it
82 gras_datadesc_scalar(const char *name,
83 gras_ddt_scalar_type_t type,
84 enum e_gras_dd_scalar_encoding encoding) {
86 gras_datadesc_type_t res;
90 res = gras_datadesc_by_name(name);
92 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_scalar,
93 "Redefinition of type %s does not match", name);
94 xbt_assert1(res->category.scalar_data.encoding == encoding,
95 "Redefinition of type %s does not match", name);
96 xbt_assert1(res->category.scalar_data.type == type,
97 "Redefinition of type %s does not match", name);
98 VERB1("Discarding redefinition of %s",name);
101 res = gras_ddt_new(name);
103 for (arch = 0; arch < gras_arch_count; arch ++) {
104 res->size[arch] = gras_arches[arch].sizeofs[type];
105 res->alignment[arch] = gras_arches[arch].boundaries[type];
106 res->aligned_size[arch] = aligned(res->size[arch], res->alignment[arch]);
109 res->category_code = e_gras_datadesc_type_cat_scalar;
110 res->category.scalar_data.encoding = encoding;
111 res->category.scalar_data.type = type;
118 /** Frees one struct or union field */
119 void gras_dd_cat_field_free(void *f) {
120 gras_dd_cat_field_t field = *(gras_dd_cat_field_t *)f;
130 /** \brief Declare a new structure description */
132 gras_datadesc_struct(const char *name) {
134 gras_datadesc_type_t res;
137 XBT_IN1("(%s)",name);
138 res = gras_datadesc_by_name(name);
140 /* FIXME: Check that field redefinition matches */
141 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_struct,
142 "Redefinition of type %s does not match", name);
143 VERB1("Discarding redefinition of %s",name);
146 res = gras_ddt_new(name);
148 for (arch=0; arch<gras_arch_count; arch ++) {
150 res->alignment[arch] = 0;
151 res->aligned_size[arch] = 0;
153 res->category_code = e_gras_datadesc_type_cat_struct;
154 res->category.struct_data.fields =
155 xbt_dynar_new(sizeof(gras_dd_cat_field_t),
156 &gras_dd_cat_field_free);
162 /** \brief Append a new field to a structure description */
164 gras_datadesc_struct_append(gras_datadesc_type_t struct_type,
166 gras_datadesc_type_t field_type) {
168 gras_dd_cat_field_t field;
171 xbt_assert2(field_type,
172 "Cannot add the field '%s' into struct '%s': its type is NULL. Typo in get_by_name?",
173 name,struct_type->name);
174 XBT_IN3("(%s %s.%s;)",field_type->name,struct_type->name,name);
175 if (struct_type->category.struct_data.closed) {
176 VERB1("Ignoring request to add field to struct %s (closed. Redefinition?)",
181 xbt_assert1(field_type->size != 0,
182 "Cannot add a dynamically sized field in structure %s",
185 field=xbt_new(s_gras_dd_cat_field_t,1);
186 field->name = (char*)strdup(name);
188 DEBUG0("----------------");
189 DEBUG3("PRE s={size=%ld,align=%ld,asize=%ld}",
190 struct_type->size[GRAS_THISARCH],
191 struct_type->alignment[GRAS_THISARCH],
192 struct_type->aligned_size[GRAS_THISARCH]);
195 for (arch=0; arch<gras_arch_count; arch ++) {
196 field->offset[arch] = aligned(struct_type->size[arch],
197 field_type->alignment[arch]);
199 struct_type->size[arch] = field->offset[arch] + field_type->size[arch];
200 struct_type->alignment[arch] = max(struct_type->alignment[arch],
201 field_type->alignment[arch]);
202 struct_type->aligned_size[arch] = aligned(struct_type->size[arch],
203 struct_type->alignment[arch]);
205 field->type = field_type;
209 xbt_dynar_push(struct_type->category.struct_data.fields, &field);
211 DEBUG3("Push a %s into %s at offset %ld.",
212 field_type->name, struct_type->name,field->offset[GRAS_THISARCH]);
213 DEBUG3(" f={size=%ld,align=%ld,asize=%ld}",
214 field_type->size[GRAS_THISARCH],
215 field_type->alignment[GRAS_THISARCH],
216 field_type->aligned_size[GRAS_THISARCH]);
217 DEBUG3(" s={size=%ld,align=%ld,asize=%ld}",
218 struct_type->size[GRAS_THISARCH],
219 struct_type->alignment[GRAS_THISARCH],
220 struct_type->aligned_size[GRAS_THISARCH]);
224 /** \brief Close a structure description
226 * No new field can be added afterward, and it is mandatory to close the structure before using it.
229 gras_datadesc_struct_close(gras_datadesc_type_t struct_type) {
231 struct_type->category.struct_data.closed = 1;
232 DEBUG4("structure %s closed. size=%ld,align=%ld,asize=%ld",
234 struct_type->size[GRAS_THISARCH],
235 struct_type->alignment[GRAS_THISARCH],
236 struct_type->aligned_size[GRAS_THISARCH]);
240 * gras_datadesc_cycle_set:
242 * Tell GRAS that the pointers of the type described by ddt may present
243 * some loop, and that the cycle detection mechanism is needed.
245 * Note that setting this option when not needed have a rather bad effect
246 * on the performance (several times slower on big data).
249 gras_datadesc_cycle_set(gras_datadesc_type_t ddt) {
254 * gras_datadesc_cycle_unset:
256 * Tell GRAS that the pointers of the type described by ddt do not present
257 * any loop and that cycle detection mechanism are not needed.
261 gras_datadesc_cycle_unset(gras_datadesc_type_t ddt) {
265 /** \brief Declare a new union description */
267 gras_datadesc_union(const char *name,
268 gras_datadesc_type_cb_int_t selector) {
270 gras_datadesc_type_t res;
273 XBT_IN1("(%s)",name);
274 xbt_assert0(selector,
275 "Attempt to creat an union without field_count function");
277 res = gras_datadesc_by_name(name);
279 /* FIXME: Check that field redefinition matches */
280 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_union,
281 "Redefinition of type %s does not match", name);
282 xbt_assert1(res->category.union_data.selector == selector,
283 "Redefinition of type %s does not match", name);
284 VERB1("Discarding redefinition of %s",name);
288 res = gras_ddt_new(name);
290 for (arch=0; arch<gras_arch_count; arch ++) {
292 res->alignment[arch] = 0;
293 res->aligned_size[arch] = 0;
296 res->category_code = e_gras_datadesc_type_cat_union;
297 res->category.union_data.fields =
298 xbt_dynar_new(sizeof(gras_dd_cat_field_t*),
299 &gras_dd_cat_field_free);
300 res->category.union_data.selector = selector;
305 /** \brief Append a new field to an union description */
306 void gras_datadesc_union_append(gras_datadesc_type_t union_type,
308 gras_datadesc_type_t field_type) {
310 gras_dd_cat_field_t field;
313 XBT_IN3("(%s %s.%s;)",field_type->name,union_type->name,name);
314 xbt_assert1(field_type->size != 0,
315 "Cannot add a dynamically sized field in union %s",
318 if (union_type->category.union_data.closed) {
319 VERB1("Ignoring request to add field to union %s (closed)",
324 field=xbt_new0(s_gras_dd_cat_field_t,1);
326 field->name = (char*)strdup(name);
327 field->type = field_type;
328 /* All offset are left to 0 in an union */
330 xbt_dynar_push(union_type->category.union_data.fields, &field);
332 for (arch=0; arch<gras_arch_count; arch ++) {
333 union_type->size[arch] = max(union_type->size[arch],
334 field_type->size[arch]);
335 union_type->alignment[arch] = max(union_type->alignment[arch],
336 field_type->alignment[arch]);
337 union_type->aligned_size[arch] = aligned(union_type->size[arch],
338 union_type->alignment[arch]);
343 /** \brief Close an union description
345 * No new field can be added afterward, and it is mandatory to close the union before using it.
348 gras_datadesc_union_close(gras_datadesc_type_t union_type) {
349 union_type->category.union_data.closed = 1;
352 /** \brief Declare a new type being a reference to the one passed in arg */
354 gras_datadesc_ref(const char *name,
355 gras_datadesc_type_t referenced_type) {
357 gras_datadesc_type_t res;
358 gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
361 XBT_IN1("(%s)",name);
362 res = gras_datadesc_by_name(name);
364 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
365 "Redefinition of %s does not match",name);
366 xbt_assert1(res->category.ref_data.type == referenced_type,
367 "Redefinition of %s does not match",name);
368 xbt_assert1(res->category.ref_data.selector == NULL,
369 "Redefinition of %s does not match",name);
370 VERB1("Discarding redefinition of %s",name);
374 res = gras_ddt_new(name);
376 xbt_assert0(pointer_type, "Cannot get the description of data pointer");
378 for (arch=0; arch<gras_arch_count; arch ++){
379 res->size[arch] = pointer_type->size[arch];
380 res->alignment[arch] = pointer_type->alignment[arch];
381 res->aligned_size[arch] = pointer_type->aligned_size[arch];
384 res->category_code = e_gras_datadesc_type_cat_ref;
385 res->category.ref_data.type = referenced_type;
386 res->category.ref_data.selector = NULL;
390 /** \brief Declare a new type being a generic reference.
392 * The callback passed in argument is to be used to select which type is currently used.
393 * So, when GRAS wants to send a generic reference, it passes the current data to the selector
394 * callback and expects it to return the type description to use.
397 gras_datadesc_ref_generic(const char *name,
398 gras_datadesc_selector_t selector) {
400 gras_datadesc_type_t res;
401 gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
404 XBT_IN1("(%s)",name);
405 res = gras_datadesc_by_name(name);
407 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
408 "Redefinition of type %s does not match", name);
409 xbt_assert1(res->category.ref_data.type == NULL,
410 "Redefinition of type %s does not match", name);
411 xbt_assert1(res->category.ref_data.selector == selector,
412 "Redefinition of type %s does not match", name);
413 VERB1("Discarding redefinition of %s",name);
416 res = gras_ddt_new(name);
418 xbt_assert0(pointer_type, "Cannot get the description of data pointer");
420 for (arch=0; arch<gras_arch_count; arch ++) {
421 res->size[arch] = pointer_type->size[arch];
422 res->alignment[arch] = pointer_type->alignment[arch];
423 res->aligned_size[arch] = pointer_type->aligned_size[arch];
426 res->category_code = e_gras_datadesc_type_cat_ref;
428 res->category.ref_data.type = NULL;
429 res->category.ref_data.selector = selector;
434 /** \brief Declare a new type being an array of fixed size and content */
436 gras_datadesc_array_fixed(const char *name,
437 gras_datadesc_type_t element_type,
438 long int fixed_size) {
440 gras_datadesc_type_t res;
443 XBT_IN1("(%s)",name);
444 res = gras_datadesc_by_name(name);
446 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
447 "Redefinition of type %s does not match", name);
449 if (res->category.array_data.type != element_type) {
450 ERROR1("Redefinition of type %s does not match: array elements differ", name);
451 gras_datadesc_type_dump(res->category.array_data.type);
452 gras_datadesc_type_dump(element_type);
455 xbt_assert1(res->category.array_data.fixed_size == fixed_size,
456 "Redefinition of type %s does not match", name);
457 xbt_assert1(res->category.array_data.dynamic_size == NULL,
458 "Redefinition of type %s does not match", name);
459 VERB1("Discarding redefinition of %s",name);
463 res = gras_ddt_new(name);
465 xbt_assert1(fixed_size > 0, "'%s' is a array of null fixed size",name);
466 for (arch=0; arch<gras_arch_count; arch ++) {
467 res->size[arch] = fixed_size * element_type->aligned_size[arch];
468 res->alignment[arch] = element_type->alignment[arch];
469 res->aligned_size[arch] = res->size[arch];
472 res->category_code = e_gras_datadesc_type_cat_array;
474 res->category.array_data.type = element_type;
475 res->category.array_data.fixed_size = fixed_size;
476 res->category.array_data.dynamic_size = NULL;
481 /** \brief Declare a new type being an array of fixed size, but accepting several content types. */
482 gras_datadesc_type_t gras_datadesc_array_dyn(const char *name,
483 gras_datadesc_type_t element_type,
484 gras_datadesc_type_cb_int_t dynamic_size) {
486 gras_datadesc_type_t res;
489 XBT_IN1("(%s)",name);
490 xbt_assert1(dynamic_size,
491 "'%s' is a dynamic array without size discriminant",
494 res = gras_datadesc_by_name(name);
496 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
497 "Redefinition of type %s does not match", name);
498 xbt_assert1(res->category.array_data.type == element_type,
499 "Redefinition of type %s does not match", name);
500 xbt_assert1(res->category.array_data.fixed_size == 0,
501 "Redefinition of type %s does not match", name);
502 xbt_assert1(res->category.array_data.dynamic_size == dynamic_size,
503 "Redefinition of type %s does not match", name);
504 VERB1("Discarding redefinition of %s",name);
509 res = gras_ddt_new(name);
511 for (arch=0; arch<gras_arch_count; arch ++) {
512 res->size[arch] = 0; /* make sure it indicates "dynamic" */
513 res->alignment[arch] = element_type->alignment[arch];
514 res->aligned_size[arch] = 0; /*FIXME: That was so in GS, but looks stupid*/
517 res->category_code = e_gras_datadesc_type_cat_array;
519 res->category.array_data.type = element_type;
520 res->category.array_data.fixed_size = 0;
521 res->category.array_data.dynamic_size = dynamic_size;
526 /** \brief Declare a new type being an array which size can be found with \ref gras_cbps_i_pop
528 * Most of the time, you want to include a reference in your structure which
529 * is a pointer to a dynamic array whose size is fixed by another field of
532 * This case pops up so often that this function was created to take care of
533 * this case. It creates a dynamic array type whose size is poped from the
534 * current cbps, and then create a reference to it.
536 * The name of the created datatype will be the name of the element type, with
537 * '[]*' appended to it.
539 * Then to use it, you just have to make sure that your structure pre-callback
540 * does push the size of the array in the cbps (using #gras_cbps_i_push), and
543 * But be remember that this is a stack. If you have two different pop_arr, you
544 * should push the second one first, so that the first one is on the top of the
545 * list when the first field gets transfered.
549 gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) {
551 gras_datadesc_type_t res;
552 char *name=(char*)xbt_malloc(strlen(element_type->name) + 4);
554 sprintf(name,"%s[]",element_type->name);
556 res = gras_datadesc_array_dyn(name,element_type,
557 gras_datadesc_cb_pop);
559 sprintf(name,"%s[]*",element_type->name);
560 res = gras_datadesc_ref(name,res);
567 #include "xbt/dynar_private.h"
568 static void gras_datadesc_dynar_cb(gras_datadesc_type_t typedesc, gras_cbps_t vars, void *data) {
569 gras_datadesc_type_t subtype;
570 xbt_dynar_t dynar=(xbt_dynar_t)data;
572 memcpy(&dynar->free_f, &typedesc->extra, sizeof(dynar->free_f));
574 /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */
575 subtype = gras_dd_find_field(typedesc,"data")->type;
577 /* this is now a ref to array of what we're looking for */
578 subtype = subtype->category.ref_data.type;
579 subtype = subtype->category.array_data.type;
581 DEBUG1("subtype is %s",subtype->name);
583 dynar->elmsize = subtype->size[GRAS_THISARCH];
584 dynar->size = dynar->used;
588 gras_datadesc_dynar(gras_datadesc_type_t elm_t,
589 void_f_pvoid_t *free_func) {
592 gras_datadesc_type_t res;
594 buffname=xbt_new0(char, strlen(elm_t->name)+10);
595 sprintf(buffname,"dynar(%s)_s",elm_t->name);
597 res = gras_datadesc_struct(buffname);
599 gras_datadesc_struct_append(res, "size", gras_datadesc_by_name("unsigned long int"));
601 gras_datadesc_struct_append(res, "used", gras_datadesc_by_name("unsigned long int"));
602 gras_datadesc_cb_field_push(res, "used");
604 gras_datadesc_struct_append(res, "elmsize", gras_datadesc_by_name("unsigned long int"));
606 gras_datadesc_struct_append(res, "data", gras_datadesc_ref_pop_arr (elm_t));
608 gras_datadesc_struct_append(res, "free_f", gras_datadesc_by_name("function pointer"));
609 memcpy(res->extra,&free_func,sizeof(free_func));
611 gras_datadesc_struct_close(res);
613 gras_datadesc_cb_recv(res, &gras_datadesc_dynar_cb);
615 /* build a ref to it */
616 sprintf(buffname,"dynar(%s)",elm_t->name);
617 res=gras_datadesc_ref(buffname,res);
623 gras_datadesc_import_nws(const char *name,
624 const DataDescriptor *desc,
625 unsigned long howmany,
626 /* OUT */ gras_datadesc_type_t *dst) {
631 * (useful to push the sizes of the upcoming arrays, for example)
633 void gras_datadesc_cb_send (gras_datadesc_type_t type,
634 gras_datadesc_type_cb_void_t send) {
638 * (useful to put the function pointers to the rigth value, for example)
640 void gras_datadesc_cb_recv(gras_datadesc_type_t type,
641 gras_datadesc_type_cb_void_t recv) {
645 * gras_dd_find_field:
647 * Returns the type descriptor of the given field. Abort on error.
649 static gras_dd_cat_field_t
650 gras_dd_find_field(gras_datadesc_type_t type,
651 const char *field_name) {
652 xbt_dynar_t field_array;
654 gras_dd_cat_field_t field=NULL;
657 if (type->category_code == e_gras_datadesc_type_cat_union) {
658 field_array = type->category.union_data.fields;
659 } else if (type->category_code == e_gras_datadesc_type_cat_struct) {
660 field_array = type->category.struct_data.fields;
662 ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,(void*)type);
665 xbt_dynar_foreach(field_array,field_num,field) {
666 if (!strcmp(field_name,field->name)) {
670 ERROR2("No field nammed %s in %s",field_name,type->name);
676 * The given datadesc must be a struct or union (abort if not).
677 * (useful to push the sizes of the upcoming arrays, for example)
679 void gras_datadesc_cb_field_send (gras_datadesc_type_t type,
680 const char *field_name,
681 gras_datadesc_type_cb_void_t send) {
683 gras_dd_cat_field_t field=gras_dd_find_field(type,field_name);
688 * The value, which must be an int, unsigned int, long int or unsigned long int
689 * is pushed to the stacks of sizes and can then be retrieved with
690 * \ref gras_datadesc_ref_pop_arr or directly with \ref gras_cbps_i_pop.
692 void gras_datadesc_cb_field_push (gras_datadesc_type_t type,
693 const char *field_name) {
695 gras_dd_cat_field_t field=gras_dd_find_field(type,field_name);
696 gras_datadesc_type_t sub_type=field->type;
698 DEBUG3("add a PUSHy cb to '%s' field (type '%s') of '%s'",
699 field_name,sub_type->name,type->name);
700 if (!strcmp("int",sub_type->name)) {
701 field->send = gras_datadesc_cb_push_int;
702 } else if (!strcmp("unsigned int",sub_type->name)) {
703 field->send = gras_datadesc_cb_push_uint;
704 } else if (!strcmp("long int",sub_type->name)) {
705 field->send = gras_datadesc_cb_push_lint;
706 } else if (!strcmp("unsigned long int",sub_type->name)) {
707 field->send = gras_datadesc_cb_push_ulint;
709 ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int",
715 * The given datadesc must be a struct or union (abort if not).
716 * (useful to put the function pointers to the right value, for example)
718 void gras_datadesc_cb_field_recv(gras_datadesc_type_t type,
719 const char *field_name,
720 gras_datadesc_type_cb_void_t recv) {
722 gras_dd_cat_field_t field=gras_dd_find_field(type,field_name);
727 * Free a datadesc. Should only be called at xbt_exit.
729 void gras_datadesc_free(gras_datadesc_type_t *type) {
731 DEBUG1("Let's free ddt %s",(*type)->name);
733 switch ((*type)->category_code) {
734 case e_gras_datadesc_type_cat_scalar:
735 case e_gras_datadesc_type_cat_ref:
736 case e_gras_datadesc_type_cat_array:
737 /* nothing to free in there */
740 case e_gras_datadesc_type_cat_struct:
741 xbt_dynar_free(&( (*type)->category.struct_data.fields ));
744 case e_gras_datadesc_type_cat_union:
745 xbt_dynar_free(&( (*type)->category.union_data.fields ));
749 /* datadesc was invalid. Killing it is like euthanasy, I guess */
758 * gras_datadesc_type_cmp:
760 * Compares two datadesc types with the same semantic than strcmp.
762 * This comparison does not take the set headers into account (name and ID),
763 * but only the payload (actual type description).
765 int gras_datadesc_type_cmp(const gras_datadesc_type_t d1,
766 const gras_datadesc_type_t d2) {
768 gras_dd_cat_field_t field1,field2;
769 gras_datadesc_type_t field_desc_1,field_desc_2;
771 if (d1 == d2) return 0; /* easy optimization */
774 DEBUG0("ddt_cmp: !d1 && d2 => 1");
778 DEBUG0("ddt_cmp: !d1 && !d2 => 0");
782 DEBUG0("ddt_cmp: d1 && !d2 => -1");
786 for (cpt=0; cpt<gras_arch_count; cpt++) {
787 if (d1->size[cpt] != d2->size[cpt]) {
788 DEBUG5("ddt_cmp: %s->size=%ld != %s->size=%ld (on %s)",
789 d1->name,d1->size[cpt],d2->name,d2->size[cpt],
790 gras_arches[cpt].name);
791 return d1->size[cpt] > d2->size[cpt] ? 1 : -1;
794 if (d1->alignment[cpt] != d2->alignment[cpt]) {
795 DEBUG5("ddt_cmp: %s->alignment=%ld != %s->alignment=%ld (on %s)",
796 d1->name,d1->alignment[cpt],d2->name,d2->alignment[cpt],
797 gras_arches[cpt].name);
798 return d1->alignment[cpt] > d2->alignment[cpt] ? 1 : -1;
801 if (d1->aligned_size[cpt] != d2->aligned_size[cpt]) {
802 DEBUG5("ddt_cmp: %s->aligned_size=%ld != %s->aligned_size=%ld (on %s)",
803 d1->name,d1->aligned_size[cpt],d2->name,d2->aligned_size[cpt],
804 gras_arches[cpt].name);
805 return d1->aligned_size[cpt] > d2->aligned_size[cpt] ? 1 : -1;
809 if (d1->category_code != d2->category_code) {
810 DEBUG4("ddt_cmp: %s->cat=%s != %s->cat=%s",
811 d1->name,gras_datadesc_cat_names[d1->category_code],
812 d2->name,gras_datadesc_cat_names[d2->category_code]);
813 return d1->category_code > d2->category_code ? 1 : -1;
816 if (d1->send != d2->send) {
817 DEBUG4("ddt_cmp: %s->send=%p != %s->send=%p",
818 d1->name,(void*)d1->send, d2->name,(void*)d2->send);
819 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
822 if (d1->recv != d2->recv) {
823 DEBUG4("ddt_cmp: %s->recv=%p != %s->recv=%p",
824 d1->name,(void*)d1->recv, d2->name,(void*)d2->recv);
825 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
828 switch (d1->category_code) {
829 case e_gras_datadesc_type_cat_scalar:
830 if (d1->category.scalar_data.encoding != d2->category.scalar_data.encoding)
831 return d1->category.scalar_data.encoding > d2->category.scalar_data.encoding ? 1 : -1 ;
834 case e_gras_datadesc_type_cat_struct:
835 if (xbt_dynar_length(d1->category.struct_data.fields) !=
836 xbt_dynar_length(d2->category.struct_data.fields)) {
837 DEBUG4("ddt_cmp: %s (having %lu fields) != %s (having %lu fields)",
838 d1->name, xbt_dynar_length(d1->category.struct_data.fields),
839 d2->name, xbt_dynar_length(d2->category.struct_data.fields));
841 return xbt_dynar_length(d1->category.struct_data.fields) >
842 xbt_dynar_length(d2->category.struct_data.fields) ?
845 xbt_dynar_foreach(d1->category.struct_data.fields, cpt, field1) {
847 field2 = xbt_dynar_get_as(d2->category.struct_data.fields, cpt, gras_dd_cat_field_t);
848 field_desc_1 = field1->type;
849 field_desc_2 = field2->type;
850 ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2);
852 DEBUG6("%s->field[%d]=%s != %s->field[%d]=%s",
853 d1->name,cpt,field1->name,
854 d2->name,cpt,field2->name);
861 case e_gras_datadesc_type_cat_union:
862 if (d1->category.union_data.selector != d2->category.union_data.selector)
863 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
865 if (xbt_dynar_length(d1->category.union_data.fields) !=
866 xbt_dynar_length(d2->category.union_data.fields))
867 return xbt_dynar_length(d1->category.union_data.fields) >
868 xbt_dynar_length(d2->category.union_data.fields) ?
871 xbt_dynar_foreach(d1->category.union_data.fields, cpt, field1) {
873 field2 = xbt_dynar_get_as(d2->category.union_data.fields, cpt, gras_dd_cat_field_t);
874 field_desc_1 = field1->type;
875 field_desc_2 = field2->type;
876 ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2);
884 case e_gras_datadesc_type_cat_ref:
885 if (d1->category.ref_data.selector != d2->category.ref_data.selector)
886 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
888 if (d1->category.ref_data.type != d2->category.ref_data.type)
889 return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1;
892 case e_gras_datadesc_type_cat_array:
893 if (d1->category.array_data.type != d2->category.array_data.type)
894 return d1->category.array_data.type > d2->category.array_data.type ? 1 : -1;
896 if (d1->category.array_data.fixed_size != d2->category.array_data.fixed_size)
897 return d1->category.array_data.fixed_size > d2->category.array_data.fixed_size ? 1 : -1;
899 if (d1->category.array_data.dynamic_size != d2->category.array_data.dynamic_size)
900 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
905 /* two stupidly created ddt are equally stupid ;) */