Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
89377621bd7d1b10670c3bc006b1ecdc8c746139
[simgrid.git] / src / gras / DataDesc / ddt_create.c
1 /* $Id$ */
2
3 /* ddt_new - creation/deletion of datatypes structs (private to this module)*/
4
5 /* Copyright (c) 2003 Olivier Aumage.                                       */
6 /* Copyright (c) 2003, 2004 Martin Quinson.                                 */
7 /* All rights reserved.                                                     */
8
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. */
11
12 #include "xbt/misc.h" /* min()/max() */
13 #include "gras/DataDesc/datadesc_private.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions");
16
17 /**
18  * gras_ddt_freev:
19  *
20  * gime that memory back, dude. I mean it.
21  */
22 void gras_ddt_freev(void *ddt) {
23   gras_datadesc_type_t type= (gras_datadesc_type_t)ddt;
24   
25   if (type) {
26     gras_datadesc_free(&type);
27   }
28 }
29
30 static gras_datadesc_type_t gras_ddt_new(const char *name) {
31   gras_datadesc_type_t res;
32
33   XBT_IN1("(%s)",name);
34   res=xbt_new0(s_gras_datadesc_type_t,1);
35
36   res->name = (char*)strdup(name);
37   res->name_len = strlen(name);
38   res->cycle = 0;
39       
40   xbt_set_add(gras_datadesc_set_local,
41                (xbt_set_elm_t)res,&gras_ddt_freev);
42   XBT_OUT;
43   return res;
44 }
45
46 /**
47  * gras_datadesc_by_name:
48  *
49  * Retrieve a type from its name
50  */
51 gras_datadesc_type_t gras_datadesc_by_name(const char *name) {
52
53   gras_datadesc_type_t type;
54
55   XBT_IN1("(%s)",name);
56   if (xbt_set_get_by_name(gras_datadesc_set_local,
57                            name,(xbt_set_elm_t*)&type) == no_error) {
58     XBT_OUT;
59     return type;
60   } else { 
61     XBT_OUT;
62     return NULL;
63   }
64 }
65
66 /**
67  * gras_datadesc_by_id:
68  *
69  * Retrieve a type from its code
70  */
71 xbt_error_t gras_datadesc_by_id(long int              code,
72                                  gras_datadesc_type_t *type) {
73   XBT_IN;
74   return xbt_set_get_by_id(gras_datadesc_set_local,
75                             code,(xbt_set_elm_t*)type);
76 }
77
78 /**
79  * gras_datadesc_scalar:
80  *
81  * Create a new scalar and give a pointer to it 
82  */
83 gras_datadesc_type_t 
84   gras_datadesc_scalar(const char                      *name,
85                        gras_ddt_scalar_type_t           type,
86                        enum e_gras_dd_scalar_encoding   encoding) {
87
88   gras_datadesc_type_t res;
89   long int arch;
90
91   XBT_IN;
92   res = gras_datadesc_by_name(name);
93   if (res) {
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);
101     return res;
102   }
103   res = gras_ddt_new(name);
104
105   for (arch = 0; arch < gras_arch_count; arch ++) {
106 #if 0
107     long int sz;
108     long int mask;
109 #endif
110     res->size[arch]         = gras_arches[arch].sizeofs[type];
111     res->alignment[arch]    = gras_arches[arch].boundaries[type];
112     res->aligned_size[arch] = aligned(res->size[arch], res->alignment[arch]);
113 /* FIXME: kill the following after discution with Oli */
114 #if 0
115     sz = res->size[arch];
116     mask = sz;
117     
118     /* just in case you wonder, x>>1 == x/2 on all architectures when x>=0
119        and a size is always>=0 */
120     
121     /* make sure mask have all the bits under the biggest one of size set to 1
122        Example: size=000100101 => mask=0000111111 */
123     while ((sz >>= 1)) {
124       mask |= sz;
125     } 
126     
127     if (res->size[arch] & (mask >> 1)) { /* if size have bits to one beside its biggest */
128       /* size is not a power of 2 */
129       /* alignment= next power of 2 after size */
130       res->alignment[arch] = (res->size[arch] & ~(mask >> 1)) << 1;
131       xbt_assert0(res->alignment[arch] != 0,
132                    "scalar type too large");
133       
134       res->aligned_size[arch] = aligned(res->size[arch], res->alignment[arch]);
135       xbt_assert0 (res->aligned_size[arch] >= 0,
136                     "scalar type too large");
137       
138     } else {
139       /* size is a power of 2, life is great */
140       res->alignment[arch]       = res->size[arch];
141       res->aligned_size[arch]    = res->size[arch];
142     }
143 #endif     
144   }
145
146   res->category_code                 = e_gras_datadesc_type_cat_scalar;
147   res->category.scalar_data.encoding = encoding;
148   res->category.scalar_data.type     = type;
149   XBT_OUT;
150   
151   return res;
152 }
153
154
155 /**
156  * gras_dd_cat_field_free:
157  *
158  * Frees one struct or union field
159  */
160 void gras_dd_cat_field_free(void *f) {
161   gras_dd_cat_field_t field = *(gras_dd_cat_field_t *)f;
162   XBT_IN;
163   if (field) {
164     if (field->name) 
165       xbt_free(field->name);
166     xbt_free(field);
167   }
168   XBT_OUT;
169 }
170
171 /**
172  * gras_datadesc_struct:
173  *
174  * Create a new struct and give a pointer to it 
175  */
176 gras_datadesc_type_t 
177   gras_datadesc_struct(const char            *name) {
178
179   gras_datadesc_type_t res;
180   long int arch;
181   
182   XBT_IN1("(%s)",name);
183   res = gras_datadesc_by_name(name);
184   if (res) {
185     /* FIXME: Check that field redefinition matches */
186     xbt_assert1(res->category_code == e_gras_datadesc_type_cat_struct,
187                  "Redefinition of type %s does not match", name);
188     VERB1("Discarding redefinition of %s",name);
189     return res;
190   }
191   res = gras_ddt_new(name);
192
193   for (arch=0; arch<gras_arch_count; arch ++) {
194     res->size[arch] = 0;
195     res->alignment[arch] = 0;
196     res->aligned_size[arch] = 0;
197   }
198   res->category_code = e_gras_datadesc_type_cat_struct;
199   res->category.struct_data.fields = 
200        xbt_dynar_new(sizeof(gras_dd_cat_field_t),
201                       &gras_dd_cat_field_free);
202
203   XBT_OUT;
204   return res;
205 }
206
207 /**
208  * gras_datadesc_struct_append:
209  *
210  * Append a field to the struct
211  */
212 void
213 gras_datadesc_struct_append(gras_datadesc_type_t struct_type,
214                             const char          *name,
215                             gras_datadesc_type_t field_type) {
216
217   gras_dd_cat_field_t field;
218   int arch;
219
220   xbt_assert2(field_type,
221                "Cannot add the field '%s' into struct '%s': its type is NULL. Typo in get_by_name?",
222                name,struct_type->name);
223   XBT_IN3("(%s %s.%s;)",field_type->name,struct_type->name,name);
224   if (struct_type->category.struct_data.closed) {
225     VERB1("Ignoring request to add field to struct %s (closed. Redefinition?)",
226           struct_type->name);
227     return;
228   }
229
230   xbt_assert1(field_type->size != 0,
231                "Cannot add a dynamically sized field in structure %s",
232                struct_type->name);
233     
234   field=xbt_new(s_gras_dd_cat_field_t,1);
235   field->name   = (char*)strdup(name);
236
237   DEBUG0("----------------");
238   DEBUG3("PRE s={size=%ld,align=%ld,asize=%ld}",
239          struct_type->size[GRAS_THISARCH], 
240          struct_type->alignment[GRAS_THISARCH], 
241          struct_type->aligned_size[GRAS_THISARCH]);
242      
243      
244   for (arch=0; arch<gras_arch_count; arch ++) {
245     field->offset[arch] = aligned(struct_type->size[arch],
246                                   field_type->alignment[arch]);
247
248     struct_type->size[arch] = field->offset[arch] + field_type->size[arch];
249     struct_type->alignment[arch] = max(struct_type->alignment[arch],
250                                        field_type->alignment[arch]);
251     struct_type->aligned_size[arch] = aligned(struct_type->size[arch],
252                                               struct_type->alignment[arch]);
253   }
254   field->type   = field_type;
255   field->pre    = NULL;
256   field->post   = NULL;
257   
258   xbt_dynar_push(struct_type->category.struct_data.fields, &field);
259
260   DEBUG3("Push a %s into %s at offset %ld.",
261          field_type->name, struct_type->name,field->offset[GRAS_THISARCH]);
262   DEBUG3("  f={size=%ld,align=%ld,asize=%ld}",
263          field_type->size[GRAS_THISARCH], 
264          field_type->alignment[GRAS_THISARCH], 
265          field_type->aligned_size[GRAS_THISARCH]);
266   DEBUG3("  s={size=%ld,align=%ld,asize=%ld}",
267          struct_type->size[GRAS_THISARCH], 
268          struct_type->alignment[GRAS_THISARCH], 
269          struct_type->aligned_size[GRAS_THISARCH]);
270   XBT_OUT;
271 }
272
273 void
274 gras_datadesc_struct_close(gras_datadesc_type_t struct_type) {
275   XBT_IN;
276   struct_type->category.struct_data.closed = 1;
277 }
278
279 /**
280  * gras_datadesc_cycle_set:
281  * 
282  * Tell GRAS that the pointers of the type described by @ddt may present
283  * some loop, and that the cycle detection mecanism is needed.
284  *
285  * Note that setting this option when not needed have a rather bad effect 
286  * on the performance (several times slower on big data).
287  */
288 void
289 gras_datadesc_cycle_set(gras_datadesc_type_t ddt) {
290   ddt->cycle = 1;
291 }
292 /**
293  * gras_datadesc_cycle_unset:
294  * 
295  * Tell GRAS that the pointers of the type described by @ddt do not present
296  * any loop and that cycle detection mecanism are not needed.
297  * (default)
298  */
299 void
300 gras_datadesc_cycle_unset(gras_datadesc_type_t ddt) {
301   ddt->cycle = 0;
302 }
303
304 /**
305  * gras_datadesc_union:
306  *
307  * Create a new union and give a pointer to it 
308  */
309 gras_datadesc_type_t 
310 gras_datadesc_union(const char                   *name,
311                     gras_datadesc_type_cb_int_t   selector) {
312
313   gras_datadesc_type_t res;
314   int arch;
315
316   XBT_IN1("(%s)",name);
317   xbt_assert0(selector,
318                "Attempt to creat an union without field_count function");
319
320   res = gras_datadesc_by_name(name);
321   if (res) {
322     /* FIXME: Check that field redefinition matches */
323     xbt_assert1(res->category_code == e_gras_datadesc_type_cat_union,
324                  "Redefinition of type %s does not match", name);
325     xbt_assert1(res->category.union_data.selector == selector,
326                  "Redefinition of type %s does not match", name);
327     VERB1("Discarding redefinition of %s",name);
328     return res;
329   }
330
331   res = gras_ddt_new(name);
332
333   for (arch=0; arch<gras_arch_count; arch ++) {
334      res->size[arch] = 0;
335      res->alignment[arch] = 0;
336      res->aligned_size[arch] = 0;
337   }
338
339   res->category_code            = e_gras_datadesc_type_cat_union;
340   res->category.union_data.fields =
341      xbt_dynar_new(sizeof(gras_dd_cat_field_t*),
342                     &gras_dd_cat_field_free);
343   res->category.union_data.selector = selector;
344
345   return res;
346 }
347
348 /**
349  * gras_datadesc_union_append:
350  *
351  * Append a field to the union
352  */
353 void
354 gras_datadesc_union_append(gras_datadesc_type_t  union_type,
355                            const char           *name,
356                            gras_datadesc_type_t  field_type) {
357
358   gras_dd_cat_field_t field;
359   int arch;
360
361   XBT_IN3("(%s %s.%s;)",field_type->name,union_type->name,name);
362   xbt_assert1(field_type->size != 0,
363                "Cannot add a dynamically sized field in union %s",
364                union_type->name);
365
366   if (union_type->category.union_data.closed) {
367     VERB1("Ignoring request to add field to union %s (closed)",
368            union_type->name);
369     return;
370   }
371     
372   field=xbt_new0(s_gras_dd_cat_field_t,1);
373
374   field->name   = (char*)strdup(name);
375   field->type   = field_type;
376   /* All offset are left to 0 in an union */
377   
378   xbt_dynar_push(union_type->category.union_data.fields, &field);
379
380   for (arch=0; arch<gras_arch_count; arch ++) {
381     union_type->size[arch] = max(union_type->size[arch],
382                                  field_type->size[arch]);
383     union_type->alignment[arch] = max(union_type->alignment[arch],
384                                       field_type->alignment[arch]);
385     union_type->aligned_size[arch] = aligned(union_type->size[arch],
386                                              union_type->alignment[arch]);
387   }
388 }
389
390 void
391 gras_datadesc_union_close(gras_datadesc_type_t union_type) {
392    union_type->category.union_data.closed = 1;
393 }
394 /**
395  * gras_datadesc_ref:
396  *
397  * Create a new ref to a fixed type and give a pointer to it 
398  */
399 gras_datadesc_type_t 
400   gras_datadesc_ref(const char           *name,
401                     gras_datadesc_type_t  referenced_type) {
402
403   gras_datadesc_type_t res;
404   gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
405   int arch;
406
407   XBT_IN1("(%s)",name);
408   res = gras_datadesc_by_name(name);
409   if (res) {
410     xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
411                  "Redefinition of %s does not match",name);
412     xbt_assert1(res->category.ref_data.type == referenced_type,
413                  "Redefinition of %s does not match",name);
414     xbt_assert1(res->category.ref_data.selector == NULL,
415                  "Redefinition of %s does not match",name);
416     VERB1("Discarding redefinition of %s",name);
417     return res;
418   }
419
420   res = gras_ddt_new(name);
421
422   xbt_assert0(pointer_type, "Cannot get the description of data pointer");
423       
424   for (arch=0; arch<gras_arch_count; arch ++){
425     res->size[arch] = pointer_type->size[arch];
426     res->alignment[arch] = pointer_type->alignment[arch];
427     res->aligned_size[arch] = pointer_type->aligned_size[arch];
428   }
429   
430   res->category_code              = e_gras_datadesc_type_cat_ref;
431   res->category.ref_data.type     = referenced_type;
432   res->category.ref_data.selector = NULL;
433
434   return res;
435 }
436 /**
437  * gras_datadesc_ref_generic:
438  *
439  * Create a new ref to a type given at use time, and give a pointer to it 
440  */
441 gras_datadesc_type_t 
442   gras_datadesc_ref_generic(const char                *name,
443                             gras_datadesc_selector_t   selector) {
444
445   gras_datadesc_type_t res;
446   gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
447   int arch;
448
449   XBT_IN1("(%s)",name);
450   res = gras_datadesc_by_name(name);
451   if (res) {
452     xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
453                  "Redefinition of type %s does not match", name);
454     xbt_assert1(res->category.ref_data.type == NULL,
455                  "Redefinition of type %s does not match", name);
456     xbt_assert1(res->category.ref_data.selector == selector,
457                  "Redefinition of type %s does not match", name);
458     VERB1("Discarding redefinition of %s",name);
459     return res;
460   }
461   res = gras_ddt_new(name);
462
463   xbt_assert0(pointer_type, "Cannot get the description of data pointer");
464       
465   for (arch=0; arch<gras_arch_count; arch ++) {
466     res->size[arch] = pointer_type->size[arch];
467     res->alignment[arch] = pointer_type->alignment[arch];
468     res->aligned_size[arch] = pointer_type->aligned_size[arch];
469   }
470
471   res->category_code            = e_gras_datadesc_type_cat_ref;
472
473   res->category.ref_data.type     = NULL;
474   res->category.ref_data.selector = selector;
475
476   return res;
477 }
478
479 /**
480  * gras_datadesc_array_fixed:
481  *
482  * Create a new array and give a pointer to it 
483  */
484 gras_datadesc_type_t 
485   gras_datadesc_array_fixed(const char           *name,
486                             gras_datadesc_type_t  element_type,
487                             long int              fixed_size) {
488
489   gras_datadesc_type_t res;
490   int arch;
491
492   XBT_IN1("(%s)",name);
493   res = gras_datadesc_by_name(name);
494   if (res) {
495     xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
496                  "Redefinition of type %s does not match", name);
497     xbt_assert1(res->category.array_data.type == element_type,
498                  "Redefinition of type %s does not match", name);
499     xbt_assert1(res->category.array_data.fixed_size == fixed_size,
500                  "Redefinition of type %s does not match", name);
501     xbt_assert1(res->category.array_data.dynamic_size == NULL,
502                  "Redefinition of type %s does not match", name);
503     VERB1("Discarding redefinition of %s",name);
504
505     return res;
506   }
507   res = gras_ddt_new(name);
508
509   xbt_assert1(fixed_size > 0, "'%s' is a array of null fixed size",name);
510   for (arch=0; arch<gras_arch_count; arch ++) {
511     res->size[arch] = fixed_size * element_type->aligned_size[arch];
512     res->alignment[arch] = element_type->alignment[arch];
513     res->aligned_size[arch] = res->size[arch];
514   }  
515
516   res->category_code            = e_gras_datadesc_type_cat_array;
517
518   res->category.array_data.type         = element_type;
519   res->category.array_data.fixed_size   = fixed_size;
520   res->category.array_data.dynamic_size = NULL;
521
522   return res;
523 }
524 /**
525  * gras_datadesc_array_dyn:
526  *
527  * Create a new array and give a pointer to it 
528  */
529 gras_datadesc_type_t 
530   gras_datadesc_array_dyn(const char                  *name,
531                           gras_datadesc_type_t         element_type,
532                           gras_datadesc_type_cb_int_t  dynamic_size) {
533
534   gras_datadesc_type_t res;
535   int arch;
536
537   XBT_IN1("(%s)",name);
538   xbt_assert1(dynamic_size,
539                "'%s' is a dynamic array without size discriminant",
540                name);
541
542   res = gras_datadesc_by_name(name);
543   if (res) {
544     xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
545                  "Redefinition of type %s does not match", name);
546     xbt_assert1(res->category.array_data.type == element_type,
547                  "Redefinition of type %s does not match", name);
548     xbt_assert1(res->category.array_data.fixed_size == 0,
549                  "Redefinition of type %s does not match", name);
550     xbt_assert1(res->category.array_data.dynamic_size == dynamic_size,
551                  "Redefinition of type %s does not match", name);
552     VERB1("Discarding redefinition of %s",name);
553
554     return res;
555   }
556
557   res = gras_ddt_new(name);
558
559   for (arch=0; arch<gras_arch_count; arch ++) {
560     res->size[arch] = 0; /* make sure it indicates "dynamic" */
561     res->alignment[arch] = element_type->alignment[arch];
562     res->aligned_size[arch] = 0; /*FIXME: That was so in GS, but looks stupid*/
563   }
564
565   res->category_code            = e_gras_datadesc_type_cat_array;
566
567   res->category.array_data.type         = element_type;
568   res->category.array_data.fixed_size   = 0;
569   res->category.array_data.dynamic_size = dynamic_size;
570
571   return res;
572 }
573
574 /**
575  * gras_datadesc_ref_pop_arr:
576  *
577  * Most of the time, you want to include a reference in your structure which
578  * is a pointer to a dynamic array whose size is fixed by another field of 
579  * your structure.
580  *
581  * This case pops up so often that this function was created to take care of
582  * this case. It creates a dynamic array type whose size is poped from the 
583  * current cbps, and then create a reference to it.
584  *
585  * The name of the created datatype will be the name of the element type, with
586  * '[]*' appended to it.
587  *
588  * Then to use it, you just have to make sure that your structure pre-callback
589  * does push the size of the array in the cbps (using #gras_cbps_i_push), and 
590  * you are set. 
591  *
592  * But be remember that this is a stack. If you have two different pop_arr, you
593  * should push the second one first, so that the first one is on the top of the 
594  * list when the first field gets transfered.
595  *
596  */
597 gras_datadesc_type_t 
598   gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) {
599
600   gras_datadesc_type_t res;
601   char *name=(char*)xbt_malloc(strlen(element_type->name) + 4);
602
603   sprintf(name,"%s[]",element_type->name);
604
605   res = gras_datadesc_array_dyn(name,element_type,
606                                 gras_datadesc_cb_pop);
607
608   sprintf(name,"%s[]*",element_type->name);
609   res = gras_datadesc_ref(name,res);
610
611   xbt_free(name);
612
613   return res;
614 }
615 xbt_error_t
616 gras_datadesc_import_nws(const char           *name,
617                          const DataDescriptor *desc,
618                          unsigned long         howmany,
619                /* OUT */ gras_datadesc_type_t *dst) {
620   RAISE_UNIMPLEMENTED;
621 }
622
623 /**
624  * gras_datadesc_cb_send:
625  *
626  * Add a pre-send callback to this datadesc.
627  * (useful to push the sizes of the upcoming arrays, for example)
628  */
629 void gras_datadesc_cb_send (gras_datadesc_type_t          type,
630                             gras_datadesc_type_cb_void_t  send) {
631   type->send = send;
632 }
633 /**
634  * gras_datadesc_cb_recv:
635  *
636  * Add a post-receive callback to this datadesc.
637  * (useful to put the function pointers to the rigth value, for example)
638  */
639 void gras_datadesc_cb_recv(gras_datadesc_type_t          type,
640                            gras_datadesc_type_cb_void_t  recv) {
641   type->recv = recv;
642 }
643 /**
644  * gras_dd_find_field:
645  * 
646  * Returns the type descriptor of the given field. Abort on error.
647  */
648 static gras_datadesc_type_t 
649   gras_dd_find_field(gras_datadesc_type_t  type,
650                      const char           *field_name) {
651    xbt_dynar_t         field_array;
652    
653    gras_dd_cat_field_t  field=NULL;
654    int                  field_num;
655    
656    if (type->category_code == e_gras_datadesc_type_cat_union) {
657       field_array = type->category.union_data.fields;
658    } else if (type->category_code == e_gras_datadesc_type_cat_struct) {
659       field_array = type->category.struct_data.fields;
660    } else {
661       ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,(void*)type);
662       xbt_abort();
663    }
664    xbt_dynar_foreach(field_array,field_num,field) {
665       if (!strcmp(field_name,field->name)) {
666          return field->type;
667       }
668    }
669    ERROR2("No field nammed %s in %s",field_name,type->name);
670    xbt_abort();
671
672 }
673                                   
674 /**
675  * gras_datadesc_cb_field_send:
676  *
677  * Add a pre-send callback to the given field of the datadesc (which must be a struct or union).
678  * (useful to push the sizes of the upcoming arrays, for example)
679  */
680 void gras_datadesc_cb_field_send (gras_datadesc_type_t          type,
681                                   const char                   *field_name,
682                                   gras_datadesc_type_cb_void_t  send) {
683    
684    gras_datadesc_type_t sub_type=gras_dd_find_field(type,field_name);   
685    sub_type->send = send;
686 }
687
688 /**
689  * gras_datadesc_cb_field_push:
690  *
691  * Add a pre-send callback to the given field resulting in its value to be pushed to
692  * the stack of sizes. It must be a int, unsigned int, long int or unsigned long int.
693  */
694 void gras_datadesc_cb_field_push (gras_datadesc_type_t  type,
695                                   const char           *field_name) {
696    
697    gras_datadesc_type_t sub_type=gras_dd_find_field(type,field_name);
698    if (!strcmp("int",sub_type->name)) {
699       sub_type->send = gras_datadesc_cb_push_int;
700    } else if (!strcmp("unsigned int",sub_type->name)) {
701       sub_type->send = gras_datadesc_cb_push_uint;
702    } else if (!strcmp("long int",sub_type->name)) {
703       sub_type->send = gras_datadesc_cb_push_lint;
704    } else if (!strcmp("unsigned long int",sub_type->name)) {
705       sub_type->send = gras_datadesc_cb_push_ulint;
706    } else {
707       ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int",
708              sub_type->name);
709       xbt_abort();
710    }
711 }
712 /**
713  * gras_datadesc_cb_field_recv:
714  *
715  * Add a post-receive callback to the given field of the datadesc (which must be a struct or union).
716  * (useful to put the function pointers to the right value, for example)
717  */
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) {
721    
722    gras_datadesc_type_t sub_type=gras_dd_find_field(type,field_name);   
723    sub_type->recv = recv;
724 }
725
726 /**
727  * gras_datadesc_free:
728  *
729  * Free a datadesc. Should only be called at xbt_exit. 
730  */
731 void gras_datadesc_free(gras_datadesc_type_t *type) {
732
733   DEBUG1("Let's free ddt %s",(*type)->name);
734   
735   switch ((*type)->category_code) {
736   case e_gras_datadesc_type_cat_scalar:
737   case e_gras_datadesc_type_cat_ref:
738   case e_gras_datadesc_type_cat_array:
739     /* nothing to free in there */
740     break;
741     
742   case e_gras_datadesc_type_cat_ignored:
743     if ((*type)->category.ignored_data.free_func) {
744       (*type)->category.ignored_data.free_func
745         ((*type)->category.ignored_data.default_value);
746     }
747     break;
748     
749   case e_gras_datadesc_type_cat_struct:
750     xbt_dynar_free(&( (*type)->category.struct_data.fields ));
751     break;
752     
753   case e_gras_datadesc_type_cat_union:
754     xbt_dynar_free(&( (*type)->category.union_data.fields ));
755     break;
756     
757   default:
758     /* datadesc was invalid. Killing it is like euthanasy, I guess */
759     break;
760   }
761   xbt_free((*type)->name);
762   xbt_free(*type);
763   type=NULL;
764 }