Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the ugly case of reference to dynamic array.
[simgrid.git] / src / gras / DataDesc / datadesc.c
1 /* $Id$ */
2
3 /* datadesc - data description in order to send/recv it in GRAS             */
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(DataDesc,GRAS);
14 /* FIXME: make this host-dependent using a trick such as UserData*/
15 gras_set_t *gras_datadesc_set_local=NULL;
16
17
18 /* callback for array size when sending strings */
19 static int
20 _strlen_cb(void                 *vars,
21            gras_datadesc_type_t *type,
22            void                 *data) {
23
24   return 1+(long int)strlen(data);
25 }
26
27
28 /**
29  * gras_datadesc_init:
30  *
31  * Initialize the datadesc module.
32  * FIXME: We assume that when neither signed nor unsigned is given, 
33  *    that means signed. To be checked by configure.
34  **/
35 void
36 gras_datadesc_init(void) {
37   gras_error_t errcode;
38   gras_datadesc_type_t *ddt; /* What to add */
39
40   /* only initialize once */
41   if (gras_datadesc_set_local != NULL)
42     return;
43   
44   VERB0("Initializing DataDesc");
45   
46   TRYFAIL(gras_set_new(&gras_datadesc_set_local));
47   
48   TRYFAIL(gras_datadesc_declare_scalar("signed char", 
49                                        gras_ddt_scalar_char, 
50                                        e_gras_dd_scalar_encoding_sint, 
51                                        NULL, &ddt));
52   TRYFAIL(gras_datadesc_declare_scalar("char", 
53                                        gras_ddt_scalar_char, 
54                                        e_gras_dd_scalar_encoding_sint, 
55                                        NULL, &ddt));
56   TRYFAIL(gras_datadesc_declare_scalar("unsigned char", 
57                                        gras_ddt_scalar_char, 
58                                        e_gras_dd_scalar_encoding_uint, 
59                                        NULL, &ddt));
60   
61   TRYFAIL(gras_datadesc_declare_scalar("signed short int", 
62                                        gras_ddt_scalar_short, 
63                                        e_gras_dd_scalar_encoding_sint, 
64                                        NULL, &ddt));
65   TRYFAIL(gras_datadesc_declare_scalar("short int", 
66                                        gras_ddt_scalar_short, 
67                                        e_gras_dd_scalar_encoding_sint, 
68                                        NULL, &ddt));
69   TRYFAIL(gras_datadesc_declare_scalar("unsigned short int", 
70                                        gras_ddt_scalar_short, 
71                                        e_gras_dd_scalar_encoding_uint, 
72                                        NULL, &ddt));
73   
74   TRYFAIL(gras_datadesc_declare_scalar("signed int", 
75                                        gras_ddt_scalar_int, 
76                                        e_gras_dd_scalar_encoding_sint, 
77                                        NULL, &ddt));
78   TRYFAIL(gras_datadesc_declare_scalar("int", 
79                                        gras_ddt_scalar_int, 
80                                        e_gras_dd_scalar_encoding_sint, 
81                                        NULL, &ddt));
82   TRYFAIL(gras_datadesc_declare_scalar("unsigned int", 
83                                        gras_ddt_scalar_int, 
84                                        e_gras_dd_scalar_encoding_uint, 
85                                        NULL, &ddt));
86   
87   TRYFAIL(gras_datadesc_declare_scalar("signed long int", 
88                                        gras_ddt_scalar_long, 
89                                        e_gras_dd_scalar_encoding_sint, 
90                                        NULL, &ddt));
91   TRYFAIL(gras_datadesc_declare_scalar("long int", 
92                                        gras_ddt_scalar_long, 
93                                        e_gras_dd_scalar_encoding_sint, 
94                                        NULL, &ddt));
95   TRYFAIL(gras_datadesc_declare_scalar("unsigned long int", 
96                                        gras_ddt_scalar_long, 
97                                        e_gras_dd_scalar_encoding_uint, 
98                                        NULL, &ddt));
99   
100   TRYFAIL(gras_datadesc_declare_scalar("signed long long int", 
101                                        gras_ddt_scalar_long_long, 
102                                        e_gras_dd_scalar_encoding_sint, 
103                                        NULL, &ddt));
104   TRYFAIL(gras_datadesc_declare_scalar("long long int", 
105                                        gras_ddt_scalar_long_long, 
106                                        e_gras_dd_scalar_encoding_sint, 
107                                        NULL, &ddt));
108   TRYFAIL(gras_datadesc_declare_scalar("unsigned long long int", 
109                                        gras_ddt_scalar_long_long, 
110                                        e_gras_dd_scalar_encoding_uint, 
111                                        NULL, &ddt));
112   
113   TRYFAIL(gras_datadesc_declare_scalar("data pointer", 
114                                        gras_ddt_scalar_pdata, 
115                                        e_gras_dd_scalar_encoding_uint, 
116                                        NULL, &ddt));
117   TRYFAIL(gras_datadesc_declare_scalar("function pointer", 
118                                        gras_ddt_scalar_pfunc, 
119                                        e_gras_dd_scalar_encoding_uint, 
120                                        NULL, &ddt));
121   
122   TRYFAIL(gras_datadesc_declare_scalar("float", 
123                                        gras_ddt_scalar_float, 
124                                        e_gras_dd_scalar_encoding_float, 
125                                        NULL, &ddt));
126   TRYFAIL(gras_datadesc_declare_scalar("double", 
127                                        gras_ddt_scalar_float, 
128                                        e_gras_dd_scalar_encoding_float, 
129                                        NULL,&ddt));
130
131   TRYFAIL(gras_datadesc_declare_array_dyn("char[]", 
132                                           gras_datadesc_by_name("char"), 
133                                           _strlen_cb,&ddt));
134   TRYFAIL(gras_datadesc_declare_ref("string", 
135                                     gras_datadesc_by_name("char[]"), 
136                                     &ddt));
137
138 }
139
140 /**
141  * gras_datadesc_exit:
142  *
143  * Finalize the datadesc module
144  **/
145 void
146 gras_datadesc_exit(void) {
147   VERB0("Exiting DataDesc");
148   gras_set_free(&gras_datadesc_set_local);
149   gras_datadesc_set_local = NULL;
150   DEBUG0("Exited DataDesc");
151 }
152
153 /**
154  * gras_datadesc_get_name:
155  *
156  * Returns the name of a datadescription (to ease the debug)
157  */
158 char *
159 gras_datadesc_get_name(gras_datadesc_type_t *ddt) {
160   return ddt->name;
161 }
162 /**
163  * gras_datadesc_get_id:
164  *
165  * Returns the name of a datadescription (to ease the debug)
166  */
167 int
168 gras_datadesc_get_id(gras_datadesc_type_t *ddt) {
169   return ddt->code;
170 }
171
172 /**
173  * gras_datadesc_type_dump:
174  *
175  * For debugging purpose
176  */
177 void gras_datadesc_type_dump(const gras_datadesc_type_t *ddt){
178   int i;
179
180   printf("DataDesc dump:");
181   if(!ddt) {
182     printf("(null)\n");
183     return;
184   }
185   printf ("%s (ID:%d)\n",ddt->name,ddt->code);
186   printf ("  refcounter=%d\n",ddt->refcounter);
187   printf ("  category: %s\n",gras_datadesc_cat_names[ddt->category_code]);
188
189   printf ("  size[");
190   for (i=0; i<gras_arch_count; i++) {
191     printf("%s%s%ld%s",
192            i>0?", ":"",
193            i == GRAS_THISARCH ? "*":"",
194            ddt->size[i],
195            i == GRAS_THISARCH ? "*":"");
196   }
197   printf ("]\n");
198
199   printf ("  alignment[");
200   for (i=0; i<gras_arch_count; i++) {
201     printf("%s%s%ld%s",
202            i>0?", ":"",
203            i == GRAS_THISARCH ? "*":"",
204            ddt->alignment[i],
205            i == GRAS_THISARCH ? "*":"");
206   }
207   printf ("]\n");
208
209   printf ("  aligned_size[");
210   for (i=0; i<gras_arch_count; i++) {
211     printf("%s%s%ld%s",
212            i>0?", ":"",
213            i == GRAS_THISARCH ? "*":"",
214            ddt->aligned_size[i],
215            i == GRAS_THISARCH ? "*":"");
216   }
217   printf ("]\n");
218   
219 }