Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Data description]
[simgrid.git] / src / gras / DataDesc / ddt_exchange.c
1 /* $Id$ */
2
3 /* ddt_exchange - send/recv data described                                  */
4
5 /* Authors: Olivier Aumage, Martin Quinson                                  */
6 /* Copyright (C) 2003, 2004 the GRAS posse.                                 */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include "DataDesc/datadesc_private.h"
12
13 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(exchange,DataDesc);
14
15 static const char *gras_datadesc_cat_names[9] = { 
16   "undefined", 
17   "scalar", "struct", "union", "ref", "array", "ignored",
18   "invalid"};
19
20 static gras_datadesc_type_t *int_type = NULL;
21 static gras_datadesc_type_t *pointer_type = NULL;    
22 static gras_error_t gras_dd_send_int(gras_socket_t *sock,             int  i);
23 static gras_error_t gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i);
24
25 static gras_error_t
26 gras_dd_alloc_ref(gras_dict_t *refs,  long int     size,
27                   char       **r_ref, long int     r_len,
28                   char       **l_ref);
29 static int 
30 gras_dd_is_r_null(char **r_ptr, long int length);
31
32 static gras_error_t 
33 gras_datadesc_send_rec(gras_socket_t        *sock,
34                        gras_dd_cbps_t       *state,
35                        gras_dict_t          *refs,
36                        gras_datadesc_type_t *type, 
37                        char                 *data);
38 static gras_error_t
39 gras_datadesc_recv_rec(gras_socket_t        *sock, 
40                        gras_dd_cbps_t       *state,
41                        gras_dict_t          *refs,
42                        gras_datadesc_type_t *type,
43                        int                   r_arch,
44                        char                **r_data,
45                        long int              r_lgr,
46                        char                **dst);
47
48
49 static gras_error_t
50 gras_dd_send_int(gras_socket_t *sock,int i) {
51
52   if (!int_type) {
53     int_type = gras_datadesc_by_name("int");
54      gras_assert(int_type);  
55   }
56    
57   DEBUG1("send_int(%d)",i);
58   return gras_trp_chunk_send(sock, (char*)&i, int_type->size[GRAS_THISARCH]);
59 }
60
61 static gras_error_t
62 gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i) {
63   gras_error_t errcode;
64
65   if (!int_type) {
66      int_type = gras_datadesc_by_name("int");
67      gras_assert(int_type);
68   }
69
70   if (int_type->size[GRAS_THISARCH] >= int_type->size[r_arch]) {
71     TRY(gras_trp_chunk_recv(sock, (char*)i, int_type->size[r_arch]));
72     TRY(gras_dd_convert_elm(int_type,r_arch, i,i));
73   } else {
74     void *ptr = NULL;
75     ptr = malloc((size_t)int_type->size[r_arch]);
76     TRY(gras_trp_chunk_recv(sock, (char*)ptr, int_type->size[r_arch]));
77     TRY(gras_dd_convert_elm(int_type,r_arch, ptr,i));
78     free(ptr);
79   }
80   DEBUG1("recv_int(%d)",*i);
81
82   return no_error;
83 }
84
85 /*
86  * Note: here we suppose that the remote NULL is a sequence 
87  *       of 'length' bytes set to 0.
88  * FIXME: Check in configure?
89  */
90 static int 
91 gras_dd_is_r_null(char **r_ptr, long int length) {
92   int i;
93
94   for (i=0; i<length; i++) {
95     if ( ((unsigned char*)r_ptr) [i]) {
96       return 0;
97     }
98   }
99
100   return 1;
101 }
102
103 static gras_error_t
104 gras_dd_alloc_ref(gras_dict_t *refs,
105                   long int     size,
106                   char       **r_ref,
107                   long int     r_len, /* pointer_type->size[r_arch] */
108                   char       **l_ref) {
109   char *l_data = NULL;
110   gras_error_t errcode;
111
112   gras_assert1(size>0,"Cannot allocate %d bytes!", size);
113   if (! (l_data = malloc((size_t)size)) )
114     RAISE_MALLOC;
115
116   *l_ref = l_data;
117   DEBUG2("l_data=%p, &l_data=%p",l_data,&l_data);
118
119   DEBUG3("alloc_ref: r_ref=%p; *r_ref=%p, r_len=%d",
120          r_ref, r_ref?*r_ref:NULL, r_len);
121   if (r_ref && !gras_dd_is_r_null( r_ref, r_len)) {
122     void *ptr = malloc(sizeof(void *));
123     if (!ptr)
124       RAISE_MALLOC;
125     //    memcpy(ptr,&l_data, sizeof(void *));
126     memcpy(ptr,l_ref, sizeof(void *));
127
128     DEBUG2("Insert %p under %p",*(void**)ptr, *(void**)r_ref);
129     /* FIXME: Leaking on the ptr. Do I really need to copy it? */
130     TRY(gras_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, NULL));
131   }
132   return no_error;
133 }
134
135 /**
136  * gras_datadesc_type_cmp:
137  *
138  * Compares two datadesc types with the same semantic than strcmp.
139  *
140  * This comparison does not take the set headers into account (name and ID), 
141  * but only the payload (actual type description).
142  */
143 int gras_datadesc_type_cmp(const gras_datadesc_type_t *d1,
144                            const gras_datadesc_type_t *d2) {
145   int ret,cpt;
146   gras_dd_cat_field_t *field1,*field2;
147   gras_datadesc_type_t *field_desc_1,*field_desc_2;
148
149
150   if (!d1 && d2) return 1;
151   if (!d1 && !d2) return 0;
152   if ( d1 && !d2) return -1;
153
154   if      (d1->size          != d2->size     )     
155     return d1->size          >  d2->size         ? 1 : -1;
156   if      (d1->alignment     != d2->alignment)     
157     return d1->alignment     >  d2->alignment    ? 1 : -1;
158   if      (d1->aligned_size  != d2->aligned_size)  
159     return d1->aligned_size  >  d2->aligned_size ? 1 : -1;
160
161   if      (d1->category_code != d2->category_code) 
162     return d1->category_code >  d2->category_code ? 1 : -1;
163
164   if      (d1->pre          != d2->pre)           
165     return d1->pre          >  d2->pre ? 1 : -1;
166   if      (d1->post         != d2->post)
167     return d1->post          > d2->post ? 1 : -1;
168
169   switch (d1->category_code) {
170   case e_gras_datadesc_type_cat_scalar:
171     if (d1->category.scalar_data.encoding != d2->category.scalar_data.encoding)
172       return d1->category.scalar_data.encoding > d2->category.scalar_data.encoding ? 1 : -1 ;
173     break;
174     
175   case e_gras_datadesc_type_cat_struct:    
176     if (gras_dynar_length(d1->category.struct_data.fields) != 
177         gras_dynar_length(d2->category.struct_data.fields))
178       return gras_dynar_length(d1->category.struct_data.fields) >
179         gras_dynar_length(d2->category.struct_data.fields) ?
180         1 : -1;
181     
182     gras_dynar_foreach(d1->category.struct_data.fields, cpt, field1) {
183       
184       gras_dynar_get(d2->category.struct_data.fields, cpt, field2);
185       gras_datadesc_by_id(field1->code,&field_desc_1); /* FIXME: errcode ignored */
186       gras_datadesc_by_id(field2->code,&field_desc_2);
187       ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2);
188       if (ret)
189         return ret;
190       
191     }
192     break;
193     
194   case e_gras_datadesc_type_cat_union:
195     if (d1->category.union_data.selector != d2->category.union_data.selector) 
196       return d1->category.union_data.selector > d2->category.union_data.selector ? 1 : -1;
197     
198     if (gras_dynar_length(d1->category.union_data.fields) != 
199         gras_dynar_length(d2->category.union_data.fields))
200       return gras_dynar_length(d1->category.union_data.fields) >
201              gras_dynar_length(d2->category.union_data.fields) ?
202         1 : -1;
203     
204     gras_dynar_foreach(d1->category.union_data.fields, cpt, field1) {
205       
206       gras_dynar_get(d2->category.union_data.fields, cpt, field2);
207       gras_datadesc_by_id(field1->code,&field_desc_1); /* FIXME: errcode ignored */
208       gras_datadesc_by_id(field2->code,&field_desc_2);
209       ret = gras_datadesc_type_cmp(field_desc_1,field_desc_2);
210       if (ret)
211         return ret;
212       
213     }
214     break;
215     
216     
217   case e_gras_datadesc_type_cat_ref:
218     if (d1->category.ref_data.selector != d2->category.ref_data.selector) 
219       return d1->category.ref_data.selector > d2->category.ref_data.selector ? 1 : -1;
220     
221     if (d1->category.ref_data.code != d2->category.ref_data.code) 
222       return d1->category.ref_data.code > d2->category.ref_data.code ? 1 : -1;
223     break;
224     
225   case e_gras_datadesc_type_cat_array:
226     if (d1->category.array_data.code != d2->category.array_data.code) 
227       return d1->category.array_data.code > d2->category.array_data.code ? 1 : -1;
228     
229     if (d1->category.array_data.fixed_size != d2->category.array_data.fixed_size) 
230       return d1->category.array_data.fixed_size > d2->category.array_data.fixed_size ? 1 : -1;
231     
232     if (d1->category.array_data.dynamic_size != d2->category.array_data.dynamic_size) 
233       return d1->category.array_data.dynamic_size > d2->category.array_data.dynamic_size ? 1 : -1;
234     
235     break;
236     
237   case e_gras_datadesc_type_cat_ignored:
238     /* That's ignored... */
239   default:
240     /* two stupidly created ddt are equally stupid ;) */
241     break;
242   }
243   return 0;
244   
245 }
246
247 /**
248  * gras_datadesc_cpy:
249  *
250  * Copy the data pointed by src and described by type 
251  * to a new location, and store a pointer to it in dst.
252  *
253  */
254 gras_error_t gras_datadesc_cpy(gras_datadesc_type_t *type, 
255                                void *src, 
256                                void **dst) {
257   RAISE_UNIMPLEMENTED;
258 }
259
260 static gras_error_t 
261 gras_datadesc_send_rec(gras_socket_t        *sock,
262                        gras_dd_cbps_t       *state,
263                        gras_dict_t          *refs,
264                        gras_datadesc_type_t *type, 
265                        char                 *data) {
266
267   gras_error_t          errcode;
268   int                   cpt;
269   gras_datadesc_type_t *sub_type; /* type on which we recurse */
270   
271   VERB2("Send a %s (%s)", 
272         type->name, gras_datadesc_cat_names[type->category_code]);
273
274   if (type->pre) {
275     type->pre(state,type,data);
276   }
277
278   switch (type->category_code) {
279   case e_gras_datadesc_type_cat_scalar:
280     TRY(gras_trp_chunk_send(sock, data, type->size[GRAS_THISARCH]));
281     break;
282
283   case e_gras_datadesc_type_cat_struct: {
284     gras_dd_cat_struct_t  struct_data;
285     gras_dd_cat_field_t  *field;
286     char                 *field_data;
287
288     struct_data = type->category.struct_data;
289     VERB1(">> Send all fields of the structure %s",type->name);
290     gras_dynar_foreach(struct_data.fields, cpt, field) {
291       field_data = data;
292       field_data += field->offset[GRAS_THISARCH];
293       
294       TRY(gras_datadesc_by_id(field->code, &sub_type));
295       
296       if (field->pre)
297         field->pre(state,sub_type,field_data);
298       
299       TRY(gras_datadesc_send_rec(sock,state,refs,sub_type, field_data));
300       
301       if (field->post)
302         field->post(state,sub_type,field_data);
303     }
304     VERB1("<< Sent all fields of the structure %s", type->name);
305     
306     break;
307   }
308
309   case e_gras_datadesc_type_cat_union: {
310     gras_dd_cat_union_t    union_data;
311     gras_dd_cat_field_t   *field;
312     int                    field_num;
313     
314     union_data = type->category.union_data;
315     
316     /* retrieve the field number */
317     field_num = union_data.selector(state, type, data);
318     
319     gras_assert1(field_num > 0,
320                  "union field selector of %s gave a negative value", 
321                  type->name);
322     
323     gras_assert3(field_num < gras_dynar_length(union_data.fields),
324          "union field selector of %s returned %d but there is only %d fields", 
325                  type->name, field_num, gras_dynar_length(union_data.fields));
326
327     /* Send the field number */
328     TRY(gras_dd_send_int(sock, field_num));
329     
330     /* Send the content */
331     gras_dynar_get(union_data.fields, field_num, field);
332     TRY(gras_datadesc_by_id(field->code, &sub_type));
333     
334     if (field->pre)
335       field->pre(state,sub_type,data);
336     
337     TRY(gras_datadesc_send_rec(sock,state,refs, sub_type, data));
338       
339     if (field->post)
340       field->post(state,sub_type,data);
341     
342     break;
343   }
344     
345   case e_gras_datadesc_type_cat_ref: {
346     gras_dd_cat_ref_t      ref_data;
347     int                    ref_code;
348
349     void                 **ref=(void**)data;
350     void *dummy;
351     
352     ref_data = type->category.ref_data;
353     
354     /* Detect the referenced type and send it to peer if needed */
355     ref_code = ref_data.code;
356     if (ref_code < 0) {
357       ref_code = ref_data.selector(state,type,data);
358       TRY(gras_dd_send_int(sock, ref_code));
359     }
360     
361     /* Send the actual value of the pointer for cycle handling */
362     if (!pointer_type) {
363       pointer_type = gras_datadesc_by_name("data pointer");
364       gras_assert(pointer_type);
365     }
366      
367     TRY(gras_trp_chunk_send(sock, (char*)data,
368                             pointer_type->size[GRAS_THISARCH]));
369     
370     /* Send the pointed data only if not already sent */
371     if (*(void**)data == NULL) {
372       VERB0("Not sending NULL referenced data");
373       break;
374     }
375     errcode = gras_dict_get_ext(refs,(char*)ref, sizeof(void*), &dummy);
376     if (errcode == mismatch_error) {
377       VERB1("Sending data referenced at %p", *ref);
378       TRY(gras_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL));
379       TRY(gras_datadesc_by_id(ref_code, &sub_type));
380       TRY(gras_datadesc_send_rec(sock,state,refs, sub_type, *ref));
381       
382     } else if (errcode == no_error) {
383       VERB1("Not sending data referenced at %p (already done)", *ref);
384     } else {
385       return errcode;
386     }
387     
388     break;
389   }
390
391   case e_gras_datadesc_type_cat_array: {
392     gras_dd_cat_array_t    array_data;
393     long int               count;
394     char                  *ptr=data;
395     long int               elm_size;
396     
397     array_data = type->category.array_data;
398     
399     /* determine and send the element count */
400     count = array_data.fixed_size;
401     if (count <= 0) {
402       count = array_data.dynamic_size(state,type,data);
403       gras_assert1(count >=0,
404                    "Invalid (negative) array size for type %s",type->name);
405       TRY(gras_dd_send_int(sock, count));
406     }
407     
408     /* send the content */
409     TRY(gras_datadesc_by_id(array_data.code, &sub_type));
410     elm_size = sub_type->aligned_size[GRAS_THISARCH];
411     for (cpt=0; cpt<count; cpt++) {
412       TRY(gras_datadesc_send_rec(sock,state,refs, sub_type, ptr));
413       ptr += elm_size;
414     }
415     break;
416   }
417
418   default:
419     gras_assert0(0, "Invalid type");
420   }
421
422   if (type->post) {
423     type->post(state,type,data);
424   }
425
426   return no_error;
427 }
428
429 /**
430  * gras_datadesc_send:
431  *
432  * Copy the data pointed by src and described by type to the socket
433  *
434  */
435 gras_error_t gras_datadesc_send(gras_socket_t *sock, 
436                                 gras_datadesc_type_t *type, 
437                                 void *src) {
438
439   gras_error_t errcode;
440   gras_dd_cbps_t *state = NULL;
441   gras_dict_t    *refs; /* all references already sent */
442  
443   TRY(gras_dict_new(&refs));
444   TRY(gras_dd_cbps_new(&state));
445
446   errcode = gras_datadesc_send_rec(sock,state,refs,type,(char*)src);
447
448   gras_dict_free(&refs);
449   gras_dd_cbps_free(&state);
450
451   return errcode;
452 }
453
454 /**
455  * gras_datadesc_recv_rec:
456  *
457  * Do the data reception job recursively.
458  */
459 gras_error_t
460 gras_datadesc_recv_rec(gras_socket_t        *sock, 
461                        gras_dd_cbps_t       *state,
462                        gras_dict_t          *refs,
463                        gras_datadesc_type_t *type,
464                        int                   r_arch,
465                        char                **r_data,
466                        long int              r_lgr,
467                        char                **dst) {
468
469   gras_error_t          errcode;
470   char                 *l_data = *dst; /* dereference to avoid typo */
471   int                   cpt;
472   gras_datadesc_type_t *sub_type;
473
474   VERB1("Recv a %s", type->name);
475
476   switch (type->category_code) {
477   case e_gras_datadesc_type_cat_scalar:
478     if (!l_data) {
479       TRY(gras_dd_alloc_ref(refs,type->size[GRAS_THISARCH],r_data,r_lgr, dst));
480       l_data = *dst;
481     } 
482     
483     if (type->size[GRAS_THISARCH] >= type->size[r_arch]) {
484       TRY(gras_trp_chunk_recv(sock, (char*)l_data, type->size[r_arch]));
485       TRY(gras_dd_convert_elm(type,r_arch, l_data,l_data));
486     } else {
487       void *ptr = NULL;
488       ptr = malloc((size_t)type->size[r_arch]);
489       TRY(gras_trp_chunk_recv(sock, (char*)ptr, type->size[r_arch]));
490       TRY(gras_dd_convert_elm(type,r_arch, ptr,l_data));
491       free(ptr);
492     }
493     break;
494
495   case e_gras_datadesc_type_cat_struct: {
496     gras_dd_cat_struct_t   struct_data;
497     gras_dd_cat_field_t   *field;
498
499     struct_data = type->category.struct_data;
500
501     if (!l_data) {
502       TRY(gras_dd_alloc_ref(refs,type->size[GRAS_THISARCH],r_data,r_lgr, dst));
503       l_data = *dst;
504     } 
505
506     VERB1(">> Receive all fields of the structure %s",type->name);
507     gras_dynar_foreach(struct_data.fields, cpt, field) {
508       char                 *field_data = l_data + field->offset[GRAS_THISARCH];
509
510       TRY(gras_datadesc_by_id(field->code, &sub_type));
511
512       TRY(gras_datadesc_recv_rec(sock,state,refs, sub_type,
513                                  r_arch,NULL,0,
514                                  &field_data));
515     }
516     VERB1("<< Received all fields of the structure %s", type->name);
517     
518     break;
519   }
520
521   case e_gras_datadesc_type_cat_union: {
522     gras_dd_cat_union_t    union_data;
523     gras_dd_cat_field_t   *field;
524     int                    field_num;
525
526     union_data = type->category.union_data;
527
528     if (!l_data) {
529       TRY(gras_dd_alloc_ref(refs,type->size[GRAS_THISARCH],r_data,r_lgr, dst));
530       l_data = *dst;
531     } 
532
533     /* retrieve the field number */
534     TRY(gras_dd_recv_int(sock, r_arch, &field_num));
535     if (field_num < 0)
536       RAISE1(mismatch_error,
537              "Received union field for %s is negative", type->name);
538     if (field_num < gras_dynar_length(union_data.fields)) 
539       RAISE3(mismatch_error,
540              "Received union field for %s is %d but there is only %d fields", 
541              type->name, field_num, gras_dynar_length(union_data.fields));
542     
543     /* Recv the content */
544     gras_dynar_get(union_data.fields, field_num, field);
545     TRY(gras_datadesc_by_id(field->code, &sub_type));
546     
547     TRY(gras_datadesc_recv_rec(sock,state,refs, sub_type,
548                                r_arch,NULL,0,
549                                dst));
550     break;
551   }
552
553   case e_gras_datadesc_type_cat_ref: {
554     char             **r_ref = NULL;
555     char             **l_ref = NULL;
556     gras_dd_cat_ref_t  ref_data;
557     int                ref_code;
558     
559     ref_data = type->category.ref_data;
560
561     /* Get the referenced type locally or from peer */
562     ref_code = ref_data.code;
563     if (ref_code < 0) 
564       TRY(gras_dd_recv_int(sock, r_arch, &ref_code));
565
566     /* Get the actual value of the pointer for cycle handling */
567     if (!pointer_type) {
568       pointer_type = gras_datadesc_by_name("data pointer");
569       gras_assert(pointer_type);
570     }
571
572     if (! (r_ref = malloc((size_t)pointer_type->size[r_arch])) )
573       RAISE_MALLOC;
574     TRY(gras_trp_chunk_recv(sock, (char*)r_ref,
575                             pointer_type->size[r_arch]));
576
577     if (!l_data) {
578       TRY(gras_dd_alloc_ref(refs,type->size[GRAS_THISARCH],r_data,r_lgr, dst));
579       l_data = *dst;
580     } 
581
582     /* Receive the pointed data only if not already sent */
583     if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
584       VERB1("Not receiving data remotely referenced at %p since it's NULL",
585             *(void **)r_ref);
586       *(void**)l_data = NULL;
587       break;
588     }
589     errcode = gras_dict_get_ext(refs,
590                                 (char*)r_ref, pointer_type->size[r_arch],
591                                 (void**)&l_ref);
592
593
594     if (errcode == mismatch_error) {
595       void *l_referenced=NULL;
596       VERB1("Receiving data remotely referenced at %p", *(void**)r_ref);
597
598       TRY(gras_datadesc_by_id(ref_code, &sub_type));
599       //      DEBUG2("l_ref= %p; &l_ref=%p",l_referenced,&l_referenced);
600       TRY(gras_datadesc_recv_rec(sock,state,refs, sub_type,
601                                  r_arch,r_ref,pointer_type->size[r_arch],
602                                  (char**)&l_referenced));
603       *(void**)l_data=l_referenced;
604       
605     } else if (errcode == no_error) {
606       VERB1("NOT receiving data remotely referenced at %p (already done). ",
607             *(void**)r_ref);
608
609       VERB2("l_ref=%p; *l_ref=%p", l_ref,*l_ref);
610
611       *(void**)l_data=*l_ref;
612
613     } else {
614       return errcode;
615     }
616     VERB1("*l_data=%p",*(void**)l_data);
617     break;
618   }
619
620   case e_gras_datadesc_type_cat_array: {
621     gras_dd_cat_array_t    array_data;
622     int       count;
623     char     *ptr;
624     long int  elm_size;
625
626     array_data = type->category.array_data;
627     /* determine element count locally or from peer */
628     count = array_data.fixed_size;
629     if (count <= 0)
630       TRY(gras_dd_recv_int(sock, r_arch, &count));
631     if (count < 0)
632       RAISE1(mismatch_error,
633              "Invalid (negative) array size for type %s",type->name);
634
635     /* receive the content */
636     TRY(gras_datadesc_by_id(array_data.code, &sub_type));
637     elm_size = sub_type->aligned_size[GRAS_THISARCH];
638     
639     if (!l_data) {
640       TRY(gras_dd_alloc_ref(refs,elm_size*count,r_data,r_lgr, dst));
641       l_data = *dst;
642     } 
643
644     ptr = l_data;
645     for (cpt=0; cpt<count; cpt++) {
646       TRY(gras_datadesc_recv_rec(sock,state,refs, sub_type,
647                                  r_arch, NULL, 0, &ptr));
648       ptr += elm_size;
649     }
650     break;
651   }
652         
653   default:
654     gras_assert0(0, "Invalid type");
655   }
656   
657   return no_error;
658 }
659
660 /**
661  * gras_datadesc_recv:
662  *
663  * Get an instance of the datatype described by @type from the @socket, 
664  * and store a pointer to it in @dst
665  *
666  */
667 gras_error_t
668 gras_datadesc_recv(gras_socket_t *sock, 
669                    gras_datadesc_type_t *type, 
670                    int r_arch,
671                    void **dst) {
672
673   gras_error_t errcode;
674   gras_dd_cbps_t *state = NULL; /* callback persistent state */
675   gras_dict_t    *refs;         /* all references already sent */
676
677   TRY(gras_dict_new(&refs));
678   TRY(gras_dd_cbps_new(&state));
679   if (!dst)
680     CRITICAL0("Cannot receive data into a NULL pointer!");
681   if (*dst) 
682     VERB0("'*dst' not NULL in datadesc_recv. Data to be copied there without malloc");
683
684   errcode = gras_datadesc_recv_rec(sock, state, refs, type, 
685                                    r_arch, NULL, 0,
686                                    (char **) dst);
687
688   gras_dict_free(&refs);
689   gras_dd_cbps_free(&state);
690
691   return errcode;
692 }