Logo AND Algorithmique Numérique Distribuée

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