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");
20 * gime that memory back, dude. I mean it.
22 void gras_ddt_freev(void *ddt) {
23 gras_datadesc_type_t type= (gras_datadesc_type_t)ddt;
26 gras_datadesc_free(&type);
30 static gras_datadesc_type_t gras_ddt_new(const char *name) {
31 gras_datadesc_type_t res;
34 res=xbt_new0(s_gras_datadesc_type_t,1);
36 res->name = (char*)strdup(name);
37 res->name_len = strlen(name);
40 xbt_set_add(gras_datadesc_set_local,
41 (xbt_set_elm_t)res,&gras_ddt_freev);
47 * gras_datadesc_by_name:
49 * Retrieve a type from its name
51 gras_datadesc_type_t gras_datadesc_by_name(const char *name) {
53 gras_datadesc_type_t type;
56 if (xbt_set_get_by_name(gras_datadesc_set_local,
57 name,(xbt_set_elm_t*)&type) == no_error) {
67 * gras_datadesc_by_id:
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 * gras_datadesc_scalar:
81 * Create a new scalar and give a pointer to it
84 gras_datadesc_scalar(const char *name,
85 gras_ddt_scalar_type_t type,
86 enum e_gras_dd_scalar_encoding encoding) {
88 gras_datadesc_type_t res;
92 res = gras_datadesc_by_name(name);
94 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_scalar,
95 "Redefinition of type %s does not match", name);
96 xbt_assert1(res->category.scalar_data.encoding == encoding,
97 "Redefinition of type %s does not match", name);
98 xbt_assert1(res->category.scalar_data.type == type,
99 "Redefinition of type %s does not match", name);
100 VERB1("Discarding redefinition of %s",name);
103 res = gras_ddt_new(name);
105 for (arch = 0; arch < gras_arch_count; arch ++) {
106 res->size[arch] = gras_arches[arch].sizeofs[type];
107 res->alignment[arch] = gras_arches[arch].boundaries[type];
108 res->aligned_size[arch] = aligned(res->size[arch], res->alignment[arch]);
111 res->category_code = e_gras_datadesc_type_cat_scalar;
112 res->category.scalar_data.encoding = encoding;
113 res->category.scalar_data.type = type;
121 * gras_dd_cat_field_free:
123 * Frees one struct or union field
125 void gras_dd_cat_field_free(void *f) {
126 gras_dd_cat_field_t field = *(gras_dd_cat_field_t *)f;
130 xbt_free(field->name);
137 * gras_datadesc_struct:
139 * Create a new struct and give a pointer to it
142 gras_datadesc_struct(const char *name) {
144 gras_datadesc_type_t res;
147 XBT_IN1("(%s)",name);
148 res = gras_datadesc_by_name(name);
150 /* FIXME: Check that field redefinition matches */
151 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_struct,
152 "Redefinition of type %s does not match", name);
153 VERB1("Discarding redefinition of %s",name);
156 res = gras_ddt_new(name);
158 for (arch=0; arch<gras_arch_count; arch ++) {
160 res->alignment[arch] = 0;
161 res->aligned_size[arch] = 0;
163 res->category_code = e_gras_datadesc_type_cat_struct;
164 res->category.struct_data.fields =
165 xbt_dynar_new(sizeof(gras_dd_cat_field_t),
166 &gras_dd_cat_field_free);
173 * gras_datadesc_struct_append:
175 * Append a field to the struct
178 gras_datadesc_struct_append(gras_datadesc_type_t struct_type,
180 gras_datadesc_type_t field_type) {
182 gras_dd_cat_field_t field;
185 xbt_assert2(field_type,
186 "Cannot add the field '%s' into struct '%s': its type is NULL. Typo in get_by_name?",
187 name,struct_type->name);
188 XBT_IN3("(%s %s.%s;)",field_type->name,struct_type->name,name);
189 if (struct_type->category.struct_data.closed) {
190 VERB1("Ignoring request to add field to struct %s (closed. Redefinition?)",
195 xbt_assert1(field_type->size != 0,
196 "Cannot add a dynamically sized field in structure %s",
199 field=xbt_new(s_gras_dd_cat_field_t,1);
200 field->name = (char*)strdup(name);
202 DEBUG0("----------------");
203 DEBUG3("PRE s={size=%ld,align=%ld,asize=%ld}",
204 struct_type->size[GRAS_THISARCH],
205 struct_type->alignment[GRAS_THISARCH],
206 struct_type->aligned_size[GRAS_THISARCH]);
209 for (arch=0; arch<gras_arch_count; arch ++) {
210 field->offset[arch] = aligned(struct_type->size[arch],
211 field_type->alignment[arch]);
213 struct_type->size[arch] = field->offset[arch] + field_type->size[arch];
214 struct_type->alignment[arch] = max(struct_type->alignment[arch],
215 field_type->alignment[arch]);
216 struct_type->aligned_size[arch] = aligned(struct_type->size[arch],
217 struct_type->alignment[arch]);
219 field->type = field_type;
223 xbt_dynar_push(struct_type->category.struct_data.fields, &field);
225 DEBUG3("Push a %s into %s at offset %ld.",
226 field_type->name, struct_type->name,field->offset[GRAS_THISARCH]);
227 DEBUG3(" f={size=%ld,align=%ld,asize=%ld}",
228 field_type->size[GRAS_THISARCH],
229 field_type->alignment[GRAS_THISARCH],
230 field_type->aligned_size[GRAS_THISARCH]);
231 DEBUG3(" s={size=%ld,align=%ld,asize=%ld}",
232 struct_type->size[GRAS_THISARCH],
233 struct_type->alignment[GRAS_THISARCH],
234 struct_type->aligned_size[GRAS_THISARCH]);
239 gras_datadesc_struct_close(gras_datadesc_type_t struct_type) {
241 struct_type->category.struct_data.closed = 1;
242 DEBUG4("structure %s closed. size=%ld,align=%ld,asize=%ld",
244 struct_type->size[GRAS_THISARCH],
245 struct_type->alignment[GRAS_THISARCH],
246 struct_type->aligned_size[GRAS_THISARCH]);
250 * gras_datadesc_cycle_set:
252 * Tell GRAS that the pointers of the type described by @ddt may present
253 * some loop, and that the cycle detection mecanism is needed.
255 * Note that setting this option when not needed have a rather bad effect
256 * on the performance (several times slower on big data).
259 gras_datadesc_cycle_set(gras_datadesc_type_t ddt) {
263 * gras_datadesc_cycle_unset:
265 * Tell GRAS that the pointers of the type described by @ddt do not present
266 * any loop and that cycle detection mecanism are not needed.
270 gras_datadesc_cycle_unset(gras_datadesc_type_t ddt) {
275 * gras_datadesc_union:
277 * Create a new union and give a pointer to it
280 gras_datadesc_union(const char *name,
281 gras_datadesc_type_cb_int_t selector) {
283 gras_datadesc_type_t res;
286 XBT_IN1("(%s)",name);
287 xbt_assert0(selector,
288 "Attempt to creat an union without field_count function");
290 res = gras_datadesc_by_name(name);
292 /* FIXME: Check that field redefinition matches */
293 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_union,
294 "Redefinition of type %s does not match", name);
295 xbt_assert1(res->category.union_data.selector == selector,
296 "Redefinition of type %s does not match", name);
297 VERB1("Discarding redefinition of %s",name);
301 res = gras_ddt_new(name);
303 for (arch=0; arch<gras_arch_count; arch ++) {
305 res->alignment[arch] = 0;
306 res->aligned_size[arch] = 0;
309 res->category_code = e_gras_datadesc_type_cat_union;
310 res->category.union_data.fields =
311 xbt_dynar_new(sizeof(gras_dd_cat_field_t*),
312 &gras_dd_cat_field_free);
313 res->category.union_data.selector = selector;
319 * gras_datadesc_union_append:
321 * Append a field to the union
324 gras_datadesc_union_append(gras_datadesc_type_t union_type,
326 gras_datadesc_type_t field_type) {
328 gras_dd_cat_field_t field;
331 XBT_IN3("(%s %s.%s;)",field_type->name,union_type->name,name);
332 xbt_assert1(field_type->size != 0,
333 "Cannot add a dynamically sized field in union %s",
336 if (union_type->category.union_data.closed) {
337 VERB1("Ignoring request to add field to union %s (closed)",
342 field=xbt_new0(s_gras_dd_cat_field_t,1);
344 field->name = (char*)strdup(name);
345 field->type = field_type;
346 /* All offset are left to 0 in an union */
348 xbt_dynar_push(union_type->category.union_data.fields, &field);
350 for (arch=0; arch<gras_arch_count; arch ++) {
351 union_type->size[arch] = max(union_type->size[arch],
352 field_type->size[arch]);
353 union_type->alignment[arch] = max(union_type->alignment[arch],
354 field_type->alignment[arch]);
355 union_type->aligned_size[arch] = aligned(union_type->size[arch],
356 union_type->alignment[arch]);
361 gras_datadesc_union_close(gras_datadesc_type_t union_type) {
362 union_type->category.union_data.closed = 1;
367 * Create a new ref to a fixed type and give a pointer to it
370 gras_datadesc_ref(const char *name,
371 gras_datadesc_type_t referenced_type) {
373 gras_datadesc_type_t res;
374 gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
377 XBT_IN1("(%s)",name);
378 res = gras_datadesc_by_name(name);
380 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
381 "Redefinition of %s does not match",name);
382 xbt_assert1(res->category.ref_data.type == referenced_type,
383 "Redefinition of %s does not match",name);
384 xbt_assert1(res->category.ref_data.selector == NULL,
385 "Redefinition of %s does not match",name);
386 VERB1("Discarding redefinition of %s",name);
390 res = gras_ddt_new(name);
392 xbt_assert0(pointer_type, "Cannot get the description of data pointer");
394 for (arch=0; arch<gras_arch_count; arch ++){
395 res->size[arch] = pointer_type->size[arch];
396 res->alignment[arch] = pointer_type->alignment[arch];
397 res->aligned_size[arch] = pointer_type->aligned_size[arch];
400 res->category_code = e_gras_datadesc_type_cat_ref;
401 res->category.ref_data.type = referenced_type;
402 res->category.ref_data.selector = NULL;
407 * gras_datadesc_ref_generic:
409 * Create a new ref to a type given at use time, and give a pointer to it
412 gras_datadesc_ref_generic(const char *name,
413 gras_datadesc_selector_t selector) {
415 gras_datadesc_type_t res;
416 gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
419 XBT_IN1("(%s)",name);
420 res = gras_datadesc_by_name(name);
422 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
423 "Redefinition of type %s does not match", name);
424 xbt_assert1(res->category.ref_data.type == NULL,
425 "Redefinition of type %s does not match", name);
426 xbt_assert1(res->category.ref_data.selector == selector,
427 "Redefinition of type %s does not match", name);
428 VERB1("Discarding redefinition of %s",name);
431 res = gras_ddt_new(name);
433 xbt_assert0(pointer_type, "Cannot get the description of data pointer");
435 for (arch=0; arch<gras_arch_count; arch ++) {
436 res->size[arch] = pointer_type->size[arch];
437 res->alignment[arch] = pointer_type->alignment[arch];
438 res->aligned_size[arch] = pointer_type->aligned_size[arch];
441 res->category_code = e_gras_datadesc_type_cat_ref;
443 res->category.ref_data.type = NULL;
444 res->category.ref_data.selector = selector;
450 * gras_datadesc_array_fixed:
452 * Create a new array and give a pointer to it
455 gras_datadesc_array_fixed(const char *name,
456 gras_datadesc_type_t element_type,
457 long int fixed_size) {
459 gras_datadesc_type_t res;
462 XBT_IN1("(%s)",name);
463 res = gras_datadesc_by_name(name);
465 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
466 "Redefinition of type %s does not match", name);
467 xbt_assert1(res->category.array_data.type == element_type,
468 "Redefinition of type %s does not match", name);
469 xbt_assert1(res->category.array_data.fixed_size == fixed_size,
470 "Redefinition of type %s does not match", name);
471 xbt_assert1(res->category.array_data.dynamic_size == NULL,
472 "Redefinition of type %s does not match", name);
473 VERB1("Discarding redefinition of %s",name);
477 res = gras_ddt_new(name);
479 xbt_assert1(fixed_size > 0, "'%s' is a array of null fixed size",name);
480 for (arch=0; arch<gras_arch_count; arch ++) {
481 res->size[arch] = fixed_size * element_type->aligned_size[arch];
482 res->alignment[arch] = element_type->alignment[arch];
483 res->aligned_size[arch] = res->size[arch];
486 res->category_code = e_gras_datadesc_type_cat_array;
488 res->category.array_data.type = element_type;
489 res->category.array_data.fixed_size = fixed_size;
490 res->category.array_data.dynamic_size = NULL;
495 * gras_datadesc_array_dyn:
497 * Create a new array and give a pointer to it
500 gras_datadesc_array_dyn(const char *name,
501 gras_datadesc_type_t element_type,
502 gras_datadesc_type_cb_int_t dynamic_size) {
504 gras_datadesc_type_t res;
507 XBT_IN1("(%s)",name);
508 xbt_assert1(dynamic_size,
509 "'%s' is a dynamic array without size discriminant",
512 res = gras_datadesc_by_name(name);
514 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
515 "Redefinition of type %s does not match", name);
516 xbt_assert1(res->category.array_data.type == element_type,
517 "Redefinition of type %s does not match", name);
518 xbt_assert1(res->category.array_data.fixed_size == 0,
519 "Redefinition of type %s does not match", name);
520 xbt_assert1(res->category.array_data.dynamic_size == dynamic_size,
521 "Redefinition of type %s does not match", name);
522 VERB1("Discarding redefinition of %s",name);
527 res = gras_ddt_new(name);
529 for (arch=0; arch<gras_arch_count; arch ++) {
530 res->size[arch] = 0; /* make sure it indicates "dynamic" */
531 res->alignment[arch] = element_type->alignment[arch];
532 res->aligned_size[arch] = 0; /*FIXME: That was so in GS, but looks stupid*/
535 res->category_code = e_gras_datadesc_type_cat_array;
537 res->category.array_data.type = element_type;
538 res->category.array_data.fixed_size = 0;
539 res->category.array_data.dynamic_size = dynamic_size;
545 * gras_datadesc_ref_pop_arr:
547 * Most of the time, you want to include a reference in your structure which
548 * is a pointer to a dynamic array whose size is fixed by another field of
551 * This case pops up so often that this function was created to take care of
552 * this case. It creates a dynamic array type whose size is poped from the
553 * current cbps, and then create a reference to it.
555 * The name of the created datatype will be the name of the element type, with
556 * '[]*' appended to it.
558 * Then to use it, you just have to make sure that your structure pre-callback
559 * does push the size of the array in the cbps (using #gras_cbps_i_push), and
562 * But be remember that this is a stack. If you have two different pop_arr, you
563 * should push the second one first, so that the first one is on the top of the
564 * list when the first field gets transfered.
568 gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) {
570 gras_datadesc_type_t res;
571 char *name=(char*)xbt_malloc(strlen(element_type->name) + 4);
573 sprintf(name,"%s[]",element_type->name);
575 res = gras_datadesc_array_dyn(name,element_type,
576 gras_datadesc_cb_pop);
578 sprintf(name,"%s[]*",element_type->name);
579 res = gras_datadesc_ref(name,res);
586 gras_datadesc_import_nws(const char *name,
587 const DataDescriptor *desc,
588 unsigned long howmany,
589 /* OUT */ gras_datadesc_type_t *dst) {
594 * gras_datadesc_cb_send:
596 * Add a pre-send callback to this datadesc.
597 * (useful to push the sizes of the upcoming arrays, for example)
599 void gras_datadesc_cb_send (gras_datadesc_type_t type,
600 gras_datadesc_type_cb_void_t send) {
604 * gras_datadesc_cb_recv:
606 * Add a post-receive callback to this datadesc.
607 * (useful to put the function pointers to the rigth value, for example)
609 void gras_datadesc_cb_recv(gras_datadesc_type_t type,
610 gras_datadesc_type_cb_void_t recv) {
614 * gras_dd_find_field:
616 * Returns the type descriptor of the given field. Abort on error.
618 static gras_datadesc_type_t
619 gras_dd_find_field(gras_datadesc_type_t type,
620 const char *field_name) {
621 xbt_dynar_t field_array;
623 gras_dd_cat_field_t field=NULL;
626 if (type->category_code == e_gras_datadesc_type_cat_union) {
627 field_array = type->category.union_data.fields;
628 } else if (type->category_code == e_gras_datadesc_type_cat_struct) {
629 field_array = type->category.struct_data.fields;
631 ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,(void*)type);
634 xbt_dynar_foreach(field_array,field_num,field) {
635 if (!strcmp(field_name,field->name)) {
639 ERROR2("No field nammed %s in %s",field_name,type->name);
645 * gras_datadesc_cb_field_send:
647 * Add a pre-send callback to the given field of the datadesc (which must be a struct or union).
648 * (useful to push the sizes of the upcoming arrays, for example)
650 void gras_datadesc_cb_field_send (gras_datadesc_type_t type,
651 const char *field_name,
652 gras_datadesc_type_cb_void_t send) {
654 gras_datadesc_type_t sub_type=gras_dd_find_field(type,field_name);
655 sub_type->send = send;
659 * gras_datadesc_cb_field_push:
661 * Add a pre-send callback to the given field resulting in its value to be pushed to
662 * the stack of sizes. It must be a int, unsigned int, long int or unsigned long int.
664 void gras_datadesc_cb_field_push (gras_datadesc_type_t type,
665 const char *field_name) {
667 gras_datadesc_type_t sub_type=gras_dd_find_field(type,field_name);
668 if (!strcmp("int",sub_type->name)) {
669 sub_type->send = gras_datadesc_cb_push_int;
670 } else if (!strcmp("unsigned int",sub_type->name)) {
671 sub_type->send = gras_datadesc_cb_push_uint;
672 } else if (!strcmp("long int",sub_type->name)) {
673 sub_type->send = gras_datadesc_cb_push_lint;
674 } else if (!strcmp("unsigned long int",sub_type->name)) {
675 sub_type->send = gras_datadesc_cb_push_ulint;
677 ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int",
683 * gras_datadesc_cb_field_recv:
685 * Add a post-receive callback to the given field of the datadesc (which must be a struct or union).
686 * (useful to put the function pointers to the right value, for example)
688 void gras_datadesc_cb_field_recv(gras_datadesc_type_t type,
689 const char *field_name,
690 gras_datadesc_type_cb_void_t recv) {
692 gras_datadesc_type_t sub_type=gras_dd_find_field(type,field_name);
693 sub_type->recv = recv;
697 * gras_datadesc_free:
699 * Free a datadesc. Should only be called at xbt_exit.
701 void gras_datadesc_free(gras_datadesc_type_t *type) {
703 DEBUG1("Let's free ddt %s",(*type)->name);
705 switch ((*type)->category_code) {
706 case e_gras_datadesc_type_cat_scalar:
707 case e_gras_datadesc_type_cat_ref:
708 case e_gras_datadesc_type_cat_array:
709 /* nothing to free in there */
712 case e_gras_datadesc_type_cat_ignored:
713 if ((*type)->category.ignored_data.free_func) {
714 (*type)->category.ignored_data.free_func
715 ((*type)->category.ignored_data.default_value);
719 case e_gras_datadesc_type_cat_struct:
720 xbt_dynar_free(&( (*type)->category.struct_data.fields ));
723 case e_gras_datadesc_type_cat_union:
724 xbt_dynar_free(&( (*type)->category.union_data.fields ));
728 /* datadesc was invalid. Killing it is like euthanasy, I guess */
731 xbt_free((*type)->name);
737 * gras_datadesc_type_cmp:
739 * Compares two datadesc types with the same semantic than strcmp.
741 * This comparison does not take the set headers into account (name and ID),
742 * but only the payload (actual type description).
744 int gras_datadesc_type_cmp(const gras_datadesc_type_t d1,
745 const gras_datadesc_type_t d2) {
747 gras_dd_cat_field_t field1,field2;
748 gras_datadesc_type_t field_desc_1,field_desc_2;
750 if (d1 == d2) return 0; /* easy optimization */
753 DEBUG0("ddt_cmp: !d1 && d2 => 1");
757 DEBUG0("ddt_cmp: !d1 && !d2 => 0");
761 DEBUG0("ddt_cmp: d1 && !d2 => -1");
765 for (cpt=0; cpt<gras_arch_count; cpt++) {
766 if (d1->size[cpt] != d2->size[cpt]) {
767 DEBUG5("ddt_cmp: %s->size=%ld != %s->size=%ld (on %s)",
768 d1->name,d1->size[cpt],d2->name,d2->size[cpt],
769 gras_arches[cpt].name);
770 return d1->size[cpt] > d2->size[cpt] ? 1 : -1;
773 if (d1->alignment[cpt] != d2->alignment[cpt]) {
774 DEBUG5("ddt_cmp: %s->alignment=%ld != %s->alignment=%ld (on %s)",
775 d1->name,d1->alignment[cpt],d2->name,d2->alignment[cpt],
776 gras_arches[cpt].name);
777 return d1->alignment[cpt] > d2->alignment[cpt] ? 1 : -1;
780 if (d1->aligned_size[cpt] != d2->aligned_size[cpt]) {
781 DEBUG5("ddt_cmp: %s->aligned_size=%ld != %s->aligned_size=%ld (on %s)",
782 d1->name,d1->aligned_size[cpt],d2->name,d2->aligned_size[cpt],
783 gras_arches[cpt].name);
784 return d1->aligned_size[cpt] > d2->aligned_size[cpt] ? 1 : -1;
788 if (d1->category_code != d2->category_code) {
789 DEBUG4("ddt_cmp: %s->cat=%s != %s->cat=%s",
790 d1->name,gras_datadesc_cat_names[d1->category_code],
791 d2->name,gras_datadesc_cat_names[d2->category_code]);
792 return d1->category_code > d2->category_code ? 1 : -1;
795 if (d1->send != d2->send) {
796 DEBUG4("ddt_cmp: %s->send=%p != %s->send=%p",
797 d1->name,(void*)d1->send, d2->name,(void*)d2->send);
798 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
801 if (d1->recv != d2->recv) {
802 DEBUG4("ddt_cmp: %s->recv=%p != %s->recv=%p",
803 d1->name,(void*)d1->recv, d2->name,(void*)d2->recv);
804 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
807 switch (d1->category_code) {
808 case e_gras_datadesc_type_cat_scalar:
809 if (d1->category.scalar_data.encoding != d2->category.scalar_data.encoding)
810 return d1->category.scalar_data.encoding > d2->category.scalar_data.encoding ? 1 : -1 ;
813 case e_gras_datadesc_type_cat_struct:
814 if (xbt_dynar_length(d1->category.struct_data.fields) !=
815 xbt_dynar_length(d2->category.struct_data.fields)) {
816 DEBUG4("ddt_cmp: %s (having %lu fields) != %s (having %lu fields)",
817 d1->name, xbt_dynar_length(d1->category.struct_data.fields),
818 d2->name, xbt_dynar_length(d2->category.struct_data.fields));
820 return xbt_dynar_length(d1->category.struct_data.fields) >
821 xbt_dynar_length(d2->category.struct_data.fields) ?
824 xbt_dynar_foreach(d1->category.struct_data.fields, cpt, field1) {
826 field2 = xbt_dynar_get_as(d2->category.struct_data.fields, cpt, gras_dd_cat_field_t);
827 field_desc_1 = field1->type;
828 field_desc_2 = field2->type;
829 ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2);
831 DEBUG6("%s->field[%d]=%s != %s->field[%d]=%s",
832 d1->name,cpt,field1->name,
833 d2->name,cpt,field2->name);
840 case e_gras_datadesc_type_cat_union:
841 if (d1->category.union_data.selector != d2->category.union_data.selector)
842 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
844 if (xbt_dynar_length(d1->category.union_data.fields) !=
845 xbt_dynar_length(d2->category.union_data.fields))
846 return xbt_dynar_length(d1->category.union_data.fields) >
847 xbt_dynar_length(d2->category.union_data.fields) ?
850 xbt_dynar_foreach(d1->category.union_data.fields, cpt, field1) {
852 field2 = xbt_dynar_get_as(d2->category.union_data.fields, cpt, gras_dd_cat_field_t);
853 field_desc_1 = field1->type;
854 field_desc_2 = field2->type;
855 ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2);
863 case e_gras_datadesc_type_cat_ref:
864 if (d1->category.ref_data.selector != d2->category.ref_data.selector)
865 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
867 if (d1->category.ref_data.type != d2->category.ref_data.type)
868 return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1;
871 case e_gras_datadesc_type_cat_array:
872 if (d1->category.array_data.type != d2->category.array_data.type)
873 return d1->category.array_data.type > d2->category.array_data.type ? 1 : -1;
875 if (d1->category.array_data.fixed_size != d2->category.array_data.fixed_size)
876 return d1->category.array_data.fixed_size > d2->category.array_data.fixed_size ? 1 : -1;
878 if (d1->category.array_data.dynamic_size != d2->category.array_data.dynamic_size)
879 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
883 case e_gras_datadesc_type_cat_ignored:
884 /* That's ignored... */
886 /* two stupidly created ddt are equally stupid ;) */