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() */
14 #include "gras/DataDesc/datadesc_private.h"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions");
19 static gras_dd_cat_field_t
20 gras_dd_find_field(gras_datadesc_type_t type,
21 const char *field_name);
25 * gime that memory back, dude. I mean it.
27 void gras_ddt_freev(void *ddt) {
28 gras_datadesc_type_t type= (gras_datadesc_type_t)ddt;
31 gras_datadesc_free(&type);
35 static gras_datadesc_type_t gras_ddt_new(const char *name) {
36 gras_datadesc_type_t res;
39 res=xbt_new0(s_gras_datadesc_type_t,1);
41 res->name = (char*)strdup(name);
42 res->name_len = strlen(name);
45 xbt_set_add(gras_datadesc_set_local,
46 (xbt_set_elm_t)res,&gras_ddt_freev);
52 * This returns NULL no type of this name can be found instead of throwing exceptions which would complicate the GRAS_DEFINE_TYPE macro
54 gras_datadesc_type_t gras_datadesc_by_name(const char *name) {
56 gras_datadesc_type_t res;
58 res = (gras_datadesc_type_t)xbt_set_get_by_name(gras_datadesc_set_local,name);
60 if (e.category != mismatch_error)
68 * Retrieve a type from its code
70 gras_datadesc_type_t gras_datadesc_by_id(long int code) {
71 return (gras_datadesc_type_t)xbt_set_get_by_id(gras_datadesc_set_local,code);
75 * Create a new scalar and give a pointer to it
78 gras_datadesc_scalar(const char *name,
79 gras_ddt_scalar_type_t type,
80 enum e_gras_dd_scalar_encoding encoding) {
82 gras_datadesc_type_t res;
86 res = gras_datadesc_by_name(name);
88 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_scalar,
89 "Redefinition of type %s does not match", name);
90 xbt_assert1(res->category.scalar_data.encoding == encoding,
91 "Redefinition of type %s does not match", name);
92 xbt_assert1(res->category.scalar_data.type == type,
93 "Redefinition of type %s does not match", name);
94 VERB1("Discarding redefinition of %s",name);
97 res = gras_ddt_new(name);
99 for (arch = 0; arch < gras_arch_count; arch ++) {
100 res->size[arch] = gras_arches[arch].sizeofs[type];
101 res->alignment[arch] = gras_arches[arch].boundaries[type];
102 res->aligned_size[arch] = aligned(res->size[arch], res->alignment[arch]);
105 res->category_code = e_gras_datadesc_type_cat_scalar;
106 res->category.scalar_data.encoding = encoding;
107 res->category.scalar_data.type = type;
114 /** Frees one struct or union field */
115 void gras_dd_cat_field_free(void *f) {
116 gras_dd_cat_field_t field = *(gras_dd_cat_field_t *)f;
126 /** \brief Declare a new structure description */
128 gras_datadesc_struct(const char *name) {
130 gras_datadesc_type_t res;
133 XBT_IN1("(%s)",name);
134 res = gras_datadesc_by_name(name);
136 /* FIXME: Check that field redefinition matches */
137 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_struct,
138 "Redefinition of type %s does not match", name);
139 VERB1("Discarding redefinition of %s",name);
142 res = gras_ddt_new(name);
144 for (arch=0; arch<gras_arch_count; arch ++) {
146 res->alignment[arch] = 0;
147 res->aligned_size[arch] = 0;
149 res->category_code = e_gras_datadesc_type_cat_struct;
150 res->category.struct_data.fields =
151 xbt_dynar_new(sizeof(gras_dd_cat_field_t),
152 &gras_dd_cat_field_free);
158 /** \brief Append a new field to a structure description */
160 gras_datadesc_struct_append(gras_datadesc_type_t struct_type,
162 gras_datadesc_type_t field_type) {
164 gras_dd_cat_field_t field;
167 xbt_assert2(field_type,
168 "Cannot add the field '%s' into struct '%s': its type is NULL. Typo in get_by_name?",
169 name,struct_type->name);
170 XBT_IN3("(%s %s.%s;)",field_type->name,struct_type->name,name);
171 if (struct_type->category.struct_data.closed) {
172 VERB1("Ignoring request to add field to struct %s (closed. Redefinition?)",
177 xbt_assert1(field_type->size != 0,
178 "Cannot add a dynamically sized field in structure %s",
181 field=xbt_new(s_gras_dd_cat_field_t,1);
182 field->name = (char*)strdup(name);
184 DEBUG0("----------------");
185 DEBUG3("PRE s={size=%ld,align=%ld,asize=%ld}",
186 struct_type->size[GRAS_THISARCH],
187 struct_type->alignment[GRAS_THISARCH],
188 struct_type->aligned_size[GRAS_THISARCH]);
191 for (arch=0; arch<gras_arch_count; arch ++) {
192 field->offset[arch] = aligned(struct_type->size[arch],
193 field_type->alignment[arch]);
195 struct_type->size[arch] = field->offset[arch] + field_type->size[arch];
196 struct_type->alignment[arch] = max(struct_type->alignment[arch],
197 field_type->alignment[arch]);
198 struct_type->aligned_size[arch] = aligned(struct_type->size[arch],
199 struct_type->alignment[arch]);
201 field->type = field_type;
205 xbt_dynar_push(struct_type->category.struct_data.fields, &field);
207 DEBUG3("Push a %s into %s at offset %ld.",
208 field_type->name, struct_type->name,field->offset[GRAS_THISARCH]);
209 DEBUG3(" f={size=%ld,align=%ld,asize=%ld}",
210 field_type->size[GRAS_THISARCH],
211 field_type->alignment[GRAS_THISARCH],
212 field_type->aligned_size[GRAS_THISARCH]);
213 DEBUG3(" s={size=%ld,align=%ld,asize=%ld}",
214 struct_type->size[GRAS_THISARCH],
215 struct_type->alignment[GRAS_THISARCH],
216 struct_type->aligned_size[GRAS_THISARCH]);
220 /** \brief Close a structure description
222 * No new field can be added afterward, and it is mandatory to close the structure before using it.
225 gras_datadesc_struct_close(gras_datadesc_type_t struct_type) {
227 struct_type->category.struct_data.closed = 1;
228 DEBUG4("structure %s closed. size=%ld,align=%ld,asize=%ld",
230 struct_type->size[GRAS_THISARCH],
231 struct_type->alignment[GRAS_THISARCH],
232 struct_type->aligned_size[GRAS_THISARCH]);
236 * gras_datadesc_cycle_set:
238 * Tell GRAS that the pointers of the type described by ddt may present
239 * some loop, and that the cycle detection mechanism is needed.
241 * Note that setting this option when not needed have a rather bad effect
242 * on the performance (several times slower on big data).
245 gras_datadesc_cycle_set(gras_datadesc_type_t ddt) {
250 * gras_datadesc_cycle_unset:
252 * Tell GRAS that the pointers of the type described by ddt do not present
253 * any loop and that cycle detection mechanism are not needed.
257 gras_datadesc_cycle_unset(gras_datadesc_type_t ddt) {
261 /** \brief Declare a new union description */
263 gras_datadesc_union(const char *name,
264 gras_datadesc_type_cb_int_t selector) {
266 gras_datadesc_type_t res;
269 XBT_IN1("(%s)",name);
270 xbt_assert0(selector,
271 "Attempt to creat an union without field_count function");
273 res = gras_datadesc_by_name(name);
275 /* FIXME: Check that field redefinition matches */
276 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_union,
277 "Redefinition of type %s does not match", name);
278 xbt_assert1(res->category.union_data.selector == selector,
279 "Redefinition of type %s does not match", name);
280 VERB1("Discarding redefinition of %s",name);
284 res = gras_ddt_new(name);
286 for (arch=0; arch<gras_arch_count; arch ++) {
288 res->alignment[arch] = 0;
289 res->aligned_size[arch] = 0;
292 res->category_code = e_gras_datadesc_type_cat_union;
293 res->category.union_data.fields =
294 xbt_dynar_new(sizeof(gras_dd_cat_field_t*),
295 &gras_dd_cat_field_free);
296 res->category.union_data.selector = selector;
301 /** \brief Append a new field to an union description */
302 void gras_datadesc_union_append(gras_datadesc_type_t union_type,
304 gras_datadesc_type_t field_type) {
306 gras_dd_cat_field_t field;
309 XBT_IN3("(%s %s.%s;)",field_type->name,union_type->name,name);
310 xbt_assert1(field_type->size != 0,
311 "Cannot add a dynamically sized field in union %s",
314 if (union_type->category.union_data.closed) {
315 VERB1("Ignoring request to add field to union %s (closed)",
320 field=xbt_new0(s_gras_dd_cat_field_t,1);
322 field->name = (char*)strdup(name);
323 field->type = field_type;
324 /* All offset are left to 0 in an union */
326 xbt_dynar_push(union_type->category.union_data.fields, &field);
328 for (arch=0; arch<gras_arch_count; arch ++) {
329 union_type->size[arch] = max(union_type->size[arch],
330 field_type->size[arch]);
331 union_type->alignment[arch] = max(union_type->alignment[arch],
332 field_type->alignment[arch]);
333 union_type->aligned_size[arch] = aligned(union_type->size[arch],
334 union_type->alignment[arch]);
339 /** \brief Close an union description
341 * No new field can be added afterward, and it is mandatory to close the union before using it.
344 gras_datadesc_union_close(gras_datadesc_type_t union_type) {
345 union_type->category.union_data.closed = 1;
348 /** \brief Declare a new type being a reference to the one passed in arg */
350 gras_datadesc_ref(const char *name,
351 gras_datadesc_type_t referenced_type) {
353 gras_datadesc_type_t res;
354 gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
357 XBT_IN1("(%s)",name);
358 res = gras_datadesc_by_name(name);
360 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
361 "Redefinition of %s does not match",name);
362 xbt_assert1(res->category.ref_data.type == referenced_type,
363 "Redefinition of %s does not match",name);
364 xbt_assert1(res->category.ref_data.selector == NULL,
365 "Redefinition of %s does not match",name);
366 VERB1("Discarding redefinition of %s",name);
370 res = gras_ddt_new(name);
372 xbt_assert0(pointer_type, "Cannot get the description of data pointer");
374 for (arch=0; arch<gras_arch_count; arch ++){
375 res->size[arch] = pointer_type->size[arch];
376 res->alignment[arch] = pointer_type->alignment[arch];
377 res->aligned_size[arch] = pointer_type->aligned_size[arch];
380 res->category_code = e_gras_datadesc_type_cat_ref;
381 res->category.ref_data.type = referenced_type;
382 res->category.ref_data.selector = NULL;
386 /** \brief Declare a new type being a generic reference.
388 * The callback passed in argument is to be used to select which type is currently used.
389 * So, when GRAS wants to send a generic reference, it passes the current data to the selector
390 * callback and expects it to return the type description to use.
393 gras_datadesc_ref_generic(const char *name,
394 gras_datadesc_selector_t selector) {
396 gras_datadesc_type_t res;
397 gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
400 XBT_IN1("(%s)",name);
401 res = gras_datadesc_by_name(name);
404 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
405 "Redefinition of type %s does not match", name);
406 xbt_assert1(res->category.ref_data.type == NULL,
407 "Redefinition of type %s does not match", name);
408 xbt_assert1(res->category.ref_data.selector == selector,
409 "Redefinition of type %s does not match", name);
410 VERB1("Discarding redefinition of %s",name);
413 res = gras_ddt_new(name);
415 xbt_assert0(pointer_type, "Cannot get the description of data pointer");
417 for (arch=0; arch<gras_arch_count; arch ++) {
418 res->size[arch] = pointer_type->size[arch];
419 res->alignment[arch] = pointer_type->alignment[arch];
420 res->aligned_size[arch] = pointer_type->aligned_size[arch];
423 res->category_code = e_gras_datadesc_type_cat_ref;
425 res->category.ref_data.type = NULL;
426 res->category.ref_data.selector = selector;
431 /** \brief Declare a new type being an array of fixed size and content */
433 gras_datadesc_array_fixed(const char *name,
434 gras_datadesc_type_t element_type,
435 long int fixed_size) {
437 gras_datadesc_type_t res;
440 XBT_IN1("(%s)",name);
441 res = gras_datadesc_by_name(name);
443 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
444 "Redefinition of type %s does not match", name);
446 if (res->category.array_data.type != element_type) {
447 ERROR1("Redefinition of type %s does not match: array elements differ", name);
448 gras_datadesc_type_dump(res->category.array_data.type);
449 gras_datadesc_type_dump(element_type);
452 xbt_assert1(res->category.array_data.fixed_size == fixed_size,
453 "Redefinition of type %s does not match", name);
454 xbt_assert1(res->category.array_data.dynamic_size == NULL,
455 "Redefinition of type %s does not match", name);
456 VERB1("Discarding redefinition of %s",name);
460 res = gras_ddt_new(name);
462 xbt_assert1(fixed_size > 0, "'%s' is a array of null fixed size",name);
463 for (arch=0; arch<gras_arch_count; arch ++) {
464 res->size[arch] = fixed_size * element_type->aligned_size[arch];
465 res->alignment[arch] = element_type->alignment[arch];
466 res->aligned_size[arch] = res->size[arch];
469 res->category_code = e_gras_datadesc_type_cat_array;
471 res->category.array_data.type = element_type;
472 res->category.array_data.fixed_size = fixed_size;
473 res->category.array_data.dynamic_size = NULL;
478 /** \brief Declare a new type being an array of fixed size, but accepting several content types. */
479 gras_datadesc_type_t gras_datadesc_array_dyn(const char *name,
480 gras_datadesc_type_t element_type,
481 gras_datadesc_type_cb_int_t dynamic_size) {
483 gras_datadesc_type_t res;
486 XBT_IN1("(%s)",name);
487 xbt_assert1(dynamic_size,
488 "'%s' is a dynamic array without size discriminant",
491 res = gras_datadesc_by_name(name);
493 xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
494 "Redefinition of type %s does not match", name);
495 xbt_assert1(res->category.array_data.type == element_type,
496 "Redefinition of type %s does not match", name);
497 xbt_assert1(res->category.array_data.fixed_size == 0,
498 "Redefinition of type %s does not match", name);
499 xbt_assert1(res->category.array_data.dynamic_size == dynamic_size,
500 "Redefinition of type %s does not match", name);
501 VERB1("Discarding redefinition of %s",name);
506 res = gras_ddt_new(name);
508 for (arch=0; arch<gras_arch_count; arch ++) {
509 res->size[arch] = 0; /* make sure it indicates "dynamic" */
510 res->alignment[arch] = element_type->alignment[arch];
511 res->aligned_size[arch] = 0; /*FIXME: That was so in GS, but looks stupid*/
514 res->category_code = e_gras_datadesc_type_cat_array;
516 res->category.array_data.type = element_type;
517 res->category.array_data.fixed_size = 0;
518 res->category.array_data.dynamic_size = dynamic_size;
523 /** \brief Declare a new type being an array which size can be found with \ref gras_cbps_i_pop
525 * Most of the time, you want to include a reference in your structure which
526 * is a pointer to a dynamic array whose size is fixed by another field of
529 * This case pops up so often that this function was created to take care of
530 * this case. It creates a dynamic array type whose size is poped from the
531 * current cbps, and then create a reference to it.
533 * The name of the created datatype will be the name of the element type, with
534 * '[]*' appended to it.
536 * Then to use it, you just have to make sure that your structure pre-callback
537 * does push the size of the array in the cbps (using #gras_cbps_i_push), and
540 * But be remember that this is a stack. If you have two different pop_arr, you
541 * should push the second one first, so that the first one is on the top of the
542 * list when the first field gets transfered.
546 gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) {
548 gras_datadesc_type_t res;
549 char *name=(char*)xbt_malloc(strlen(element_type->name) + 4);
551 sprintf(name,"%s[]",element_type->name);
553 res = gras_datadesc_array_dyn(name,element_type,
554 gras_datadesc_cb_pop);
556 sprintf(name,"%s[]*",element_type->name);
557 res = gras_datadesc_ref(name,res);
564 #include "xbt/dynar_private.h"
565 static void gras_datadesc_dynar_cb(gras_datadesc_type_t typedesc, gras_cbps_t vars, void *data) {
566 gras_datadesc_type_t subtype;
567 xbt_dynar_t dynar=(xbt_dynar_t)data;
569 memcpy(&dynar->free_f, &typedesc->extra, sizeof(dynar->free_f));
571 /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */
572 subtype = gras_dd_find_field(typedesc,"data")->type;
574 /* this is now a ref to array of what we're looking for */
575 subtype = subtype->category.ref_data.type;
576 subtype = subtype->category.array_data.type;
578 DEBUG1("subtype is %s",subtype->name);
580 dynar->elmsize = subtype->size[GRAS_THISARCH];
581 dynar->size = dynar->used;
585 gras_datadesc_dynar(gras_datadesc_type_t elm_t,
586 void_f_pvoid_t *free_func) {
589 gras_datadesc_type_t res;
591 buffname=xbt_new0(char, strlen(elm_t->name)+10);
592 sprintf(buffname,"dynar(%s)_s",elm_t->name);
594 res = gras_datadesc_struct(buffname);
596 gras_datadesc_struct_append(res, "size", gras_datadesc_by_name("unsigned long int"));
598 gras_datadesc_struct_append(res, "used", gras_datadesc_by_name("unsigned long int"));
599 gras_datadesc_cb_field_push(res, "used");
601 gras_datadesc_struct_append(res, "elmsize", gras_datadesc_by_name("unsigned long int"));
603 gras_datadesc_struct_append(res, "data", gras_datadesc_ref_pop_arr (elm_t));
605 gras_datadesc_struct_append(res, "free_f", gras_datadesc_by_name("function pointer"));
606 memcpy(res->extra,&free_func,sizeof(free_func));
608 gras_datadesc_struct_close(res);
610 gras_datadesc_cb_recv(res, &gras_datadesc_dynar_cb);
612 /* build a ref to it */
613 sprintf(buffname,"dynar(%s)",elm_t->name);
614 res=gras_datadesc_ref(buffname,res);
620 gras_datadesc_import_nws(const char *name,
621 const DataDescriptor *desc,
622 unsigned long howmany,
623 /* OUT */ gras_datadesc_type_t *dst) {
628 * (useful to push the sizes of the upcoming arrays, for example)
630 void gras_datadesc_cb_send (gras_datadesc_type_t type,
631 gras_datadesc_type_cb_void_t send) {
635 * (useful to put the function pointers to the rigth value, for example)
637 void gras_datadesc_cb_recv(gras_datadesc_type_t type,
638 gras_datadesc_type_cb_void_t recv) {
642 * gras_dd_find_field:
644 * Returns the type descriptor of the given field. Abort on error.
646 static gras_dd_cat_field_t
647 gras_dd_find_field(gras_datadesc_type_t type,
648 const char *field_name) {
649 xbt_dynar_t field_array;
651 gras_dd_cat_field_t field=NULL;
654 if (type->category_code == e_gras_datadesc_type_cat_union) {
655 field_array = type->category.union_data.fields;
656 } else if (type->category_code == e_gras_datadesc_type_cat_struct) {
657 field_array = type->category.struct_data.fields;
659 ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,(void*)type);
662 xbt_dynar_foreach(field_array,field_num,field) {
663 if (!strcmp(field_name,field->name)) {
667 ERROR2("No field nammed %s in %s",field_name,type->name);
673 * The given datadesc must be a struct or union (abort if not).
674 * (useful to push the sizes of the upcoming arrays, for example)
676 void gras_datadesc_cb_field_send (gras_datadesc_type_t type,
677 const char *field_name,
678 gras_datadesc_type_cb_void_t send) {
680 gras_dd_cat_field_t field=gras_dd_find_field(type,field_name);
685 * The value, which must be an int, unsigned int, long int or unsigned long int
686 * is pushed to the stacks of sizes and can then be retrieved with
687 * \ref gras_datadesc_ref_pop_arr or directly with \ref gras_cbps_i_pop.
689 void gras_datadesc_cb_field_push (gras_datadesc_type_t type,
690 const char *field_name) {
692 gras_dd_cat_field_t field=gras_dd_find_field(type,field_name);
693 gras_datadesc_type_t sub_type=field->type;
695 DEBUG3("add a PUSHy cb to '%s' field (type '%s') of '%s'",
696 field_name,sub_type->name,type->name);
697 if (!strcmp("int",sub_type->name)) {
698 field->send = gras_datadesc_cb_push_int;
699 } else if (!strcmp("unsigned int",sub_type->name)) {
700 field->send = gras_datadesc_cb_push_uint;
701 } else if (!strcmp("long int",sub_type->name)) {
702 field->send = gras_datadesc_cb_push_lint;
703 } else if (!strcmp("unsigned long int",sub_type->name)) {
704 field->send = gras_datadesc_cb_push_ulint;
706 ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int",
712 * The given datadesc must be a struct or union (abort if not).
713 * (useful to put the function pointers to the right value, for example)
715 void gras_datadesc_cb_field_recv(gras_datadesc_type_t type,
716 const char *field_name,
717 gras_datadesc_type_cb_void_t recv) {
719 gras_dd_cat_field_t field=gras_dd_find_field(type,field_name);
724 * Free a datadesc. Should only be called at xbt_exit.
726 void gras_datadesc_free(gras_datadesc_type_t *type) {
728 DEBUG1("Let's free ddt %s",(*type)->name);
730 switch ((*type)->category_code) {
731 case e_gras_datadesc_type_cat_scalar:
732 case e_gras_datadesc_type_cat_ref:
733 case e_gras_datadesc_type_cat_array:
734 /* nothing to free in there */
737 case e_gras_datadesc_type_cat_struct:
738 xbt_dynar_free(&( (*type)->category.struct_data.fields ));
741 case e_gras_datadesc_type_cat_union:
742 xbt_dynar_free(&( (*type)->category.union_data.fields ));
746 /* datadesc was invalid. Killing it is like euthanasy, I guess */
755 * gras_datadesc_type_cmp:
757 * Compares two datadesc types with the same semantic than strcmp.
759 * This comparison does not take the set headers into account (name and ID),
760 * but only the payload (actual type description).
762 int gras_datadesc_type_cmp(const gras_datadesc_type_t d1,
763 const gras_datadesc_type_t d2) {
765 gras_dd_cat_field_t field1,field2;
766 gras_datadesc_type_t field_desc_1,field_desc_2;
768 if (d1 == d2) return 0; /* easy optimization */
771 DEBUG0("ddt_cmp: !d1 && d2 => 1");
775 DEBUG0("ddt_cmp: !d1 && !d2 => 0");
779 DEBUG0("ddt_cmp: d1 && !d2 => -1");
783 for (cpt=0; cpt<gras_arch_count; cpt++) {
784 if (d1->size[cpt] != d2->size[cpt]) {
785 DEBUG5("ddt_cmp: %s->size=%ld != %s->size=%ld (on %s)",
786 d1->name,d1->size[cpt],d2->name,d2->size[cpt],
787 gras_arches[cpt].name);
788 return d1->size[cpt] > d2->size[cpt] ? 1 : -1;
791 if (d1->alignment[cpt] != d2->alignment[cpt]) {
792 DEBUG5("ddt_cmp: %s->alignment=%ld != %s->alignment=%ld (on %s)",
793 d1->name,d1->alignment[cpt],d2->name,d2->alignment[cpt],
794 gras_arches[cpt].name);
795 return d1->alignment[cpt] > d2->alignment[cpt] ? 1 : -1;
798 if (d1->aligned_size[cpt] != d2->aligned_size[cpt]) {
799 DEBUG5("ddt_cmp: %s->aligned_size=%ld != %s->aligned_size=%ld (on %s)",
800 d1->name,d1->aligned_size[cpt],d2->name,d2->aligned_size[cpt],
801 gras_arches[cpt].name);
802 return d1->aligned_size[cpt] > d2->aligned_size[cpt] ? 1 : -1;
806 if (d1->category_code != d2->category_code) {
807 DEBUG4("ddt_cmp: %s->cat=%s != %s->cat=%s",
808 d1->name,gras_datadesc_cat_names[d1->category_code],
809 d2->name,gras_datadesc_cat_names[d2->category_code]);
810 return d1->category_code > d2->category_code ? 1 : -1;
813 if (d1->send != d2->send) {
814 DEBUG4("ddt_cmp: %s->send=%p != %s->send=%p",
815 d1->name,(void*)d1->send, d2->name,(void*)d2->send);
816 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
819 if (d1->recv != d2->recv) {
820 DEBUG4("ddt_cmp: %s->recv=%p != %s->recv=%p",
821 d1->name,(void*)d1->recv, d2->name,(void*)d2->recv);
822 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
825 switch (d1->category_code) {
826 case e_gras_datadesc_type_cat_scalar:
827 if (d1->category.scalar_data.encoding != d2->category.scalar_data.encoding)
828 return d1->category.scalar_data.encoding > d2->category.scalar_data.encoding ? 1 : -1 ;
831 case e_gras_datadesc_type_cat_struct:
832 if (xbt_dynar_length(d1->category.struct_data.fields) !=
833 xbt_dynar_length(d2->category.struct_data.fields)) {
834 DEBUG4("ddt_cmp: %s (having %lu fields) != %s (having %lu fields)",
835 d1->name, xbt_dynar_length(d1->category.struct_data.fields),
836 d2->name, xbt_dynar_length(d2->category.struct_data.fields));
838 return xbt_dynar_length(d1->category.struct_data.fields) >
839 xbt_dynar_length(d2->category.struct_data.fields) ?
842 xbt_dynar_foreach(d1->category.struct_data.fields, cpt, field1) {
844 field2 = xbt_dynar_get_as(d2->category.struct_data.fields, cpt, gras_dd_cat_field_t);
845 field_desc_1 = field1->type;
846 field_desc_2 = field2->type;
847 ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2);
849 DEBUG6("%s->field[%d]=%s != %s->field[%d]=%s",
850 d1->name,cpt,field1->name,
851 d2->name,cpt,field2->name);
858 case e_gras_datadesc_type_cat_union:
859 if (d1->category.union_data.selector != d2->category.union_data.selector)
860 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
862 if (xbt_dynar_length(d1->category.union_data.fields) !=
863 xbt_dynar_length(d2->category.union_data.fields))
864 return xbt_dynar_length(d1->category.union_data.fields) >
865 xbt_dynar_length(d2->category.union_data.fields) ?
868 xbt_dynar_foreach(d1->category.union_data.fields, cpt, field1) {
870 field2 = xbt_dynar_get_as(d2->category.union_data.fields, cpt, gras_dd_cat_field_t);
871 field_desc_1 = field1->type;
872 field_desc_2 = field2->type;
873 ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2);
881 case e_gras_datadesc_type_cat_ref:
882 if (d1->category.ref_data.selector != d2->category.ref_data.selector)
883 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
885 if (d1->category.ref_data.type != d2->category.ref_data.type)
886 return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1;
889 case e_gras_datadesc_type_cat_array:
890 if (d1->category.array_data.type != d2->category.array_data.type)
891 return d1->category.array_data.type > d2->category.array_data.type ? 1 : -1;
893 if (d1->category.array_data.fixed_size != d2->category.array_data.fixed_size)
894 return d1->category.array_data.fixed_size > d2->category.array_data.fixed_size ? 1 : -1;
896 if (d1->category.array_data.dynamic_size != d2->category.array_data.dynamic_size)
897 return 1; /* ISO C forbids ordered comparisons of pointers to functions */
902 /* two stupidly created ddt are equally stupid ;) */