*
* Retrieve a type from its name
*/
-gras_error_t gras_datadesc_by_name(const char *name,
- gras_datadesc_type_t **type) {
- return gras_set_get_by_name(gras_datadesc_set_local,
- name,(gras_set_elm_t**)type);
+gras_datadesc_type_t *gras_datadesc_by_name(const char *name) {
+
+ gras_datadesc_type_t *type;
+
+ if (gras_set_get_by_name(gras_datadesc_set_local,
+ name,(gras_set_elm_t**)&type) == no_error) {
+ return type;
+ } else {
+ return NULL;
+ }
}
/**
return no_error;
}
-gras_error_t
-gras_datadesc_declare_struct_append_name(gras_datadesc_type_t *struct_type,
- const char *name,
- const char *field_type_name){
- gras_error_t errcode;
- gras_datadesc_type_t *field_type;
-
- errcode = gras_datadesc_by_name(field_type_name, &field_type);
- if (errcode != no_error) {
- WARN2("Got error '%s' while looking for '%s'",
- gras_error_name(errcode), field_type_name);
- return errcode;
- }
- return gras_datadesc_declare_struct_append(struct_type,name,field_type);
-}
/**
* gras_datadesc_declare_struct_append:
*
gras_error_t errcode;
gras_datadesc_type_t *res;
- gras_datadesc_type_t *pointer_type;
+ gras_datadesc_type_t *pointer_type = gras_datadesc_by_name("data pointer");
int arch;
TRY(gras_ddt_new(name,dst));
res=*dst;
- TRY(gras_datadesc_by_name("data pointer", &pointer_type));
+ gras_assert0(pointer_type, "Cannot get the description of data pointer");
for (arch=0; arch<gras_arch_count; arch ++) {
res->size[arch] = pointer_type->size[arch];
gras_error_t errcode;
gras_datadesc_type_t *res;
- gras_datadesc_type_t *pointer_type;
+ gras_datadesc_type_t *pointer_type = gras_datadesc_by_name("data pointer");
int arch;
TRY(gras_ddt_new(name,dst));
res=*dst;
- TRY(gras_datadesc_by_name("data pointer", &pointer_type));
+ gras_assert0(pointer_type, "Cannot get the description of data pointer");
for (arch=0; arch<gras_arch_count; arch ++) {
res->size[arch] = pointer_type->size[arch];
static gras_error_t
gras_dd_send_int(gras_socket_t *sock,int i) {
- gras_error_t errcode;
- if (!int_type)
- TRY(gras_datadesc_by_name("int", &int_type));
-
+ if (!int_type) {
+ int_type = gras_datadesc_by_name("int");
+ gras_assert(int_type);
+ }
+
DEBUG1("send_int(%d)",i);
return gras_trp_chunk_send(sock, (char*)&i, int_type->size[GRAS_THISARCH]);
}
gras_dd_recv_int(gras_socket_t *sock, int r_arch, int *i) {
gras_error_t errcode;
- if (!int_type)
- TRY(gras_datadesc_by_name("int", &int_type));
+ if (!int_type) {
+ int_type = gras_datadesc_by_name("int");
+ gras_assert(int_type);
+ }
if (int_type->size[GRAS_THISARCH] >= int_type->size[r_arch]) {
TRY(gras_trp_chunk_recv(sock, (char*)i, int_type->size[r_arch]));
}
/* Send the actual value of the pointer for cycle handling */
- if (!pointer_type)
- TRY(gras_datadesc_by_name("data pointer", &pointer_type));
+ if (!pointer_type) {
+ pointer_type = gras_datadesc_by_name("data pointer");
+ gras_assert(pointer_type);
+ }
+
TRY(gras_trp_chunk_send(sock, (char*)data,
pointer_type->size[GRAS_THISARCH]));
TRY(gras_dd_recv_int(sock, r_arch, &ref_code));
/* Get the actual value of the pointer for cycle handling */
- if (!pointer_type)
- TRY(gras_datadesc_by_name("data pointer", &pointer_type));
+ if (!pointer_type) {
+ pointer_type = gras_datadesc_by_name("data pointer");
+ gras_assert(pointer_type);
+ }
if (! (r_ref = malloc((size_t)pointer_type->size[r_arch])) )
RAISE_MALLOC;
gras_error_t test_int(void) {
gras_error_t errcode;
- gras_datadesc_type_t *type;
int i=5,*j=NULL;
INFO0("==== Test on integer ====");
- TRY(gras_datadesc_by_name("int", &type));
- TRY(write_read(type, (void*)&i,(void**) &j));
+ TRY(write_read(gras_datadesc_by_name("int"), (void*)&i,(void**) &j));
gras_assert(i == *j);
free(j);
return no_error;
}
gras_error_t test_float(void) {
gras_error_t errcode;
- gras_datadesc_type_t *type;
float i=5.0,*j=NULL;
INFO0("==== Test on float ====");
- TRY(gras_datadesc_by_name("float", &type));
- TRY(write_read(type, (void*)&i,(void**) &j));
+ TRY(write_read(gras_datadesc_by_name("float"), (void*)&i,(void**) &j));
gras_assert(i == *j);
free(j);
return no_error;
typedef int array[SIZE];
gras_error_t test_array(void) {
gras_error_t errcode;
- gras_datadesc_type_t *int_type;
gras_datadesc_type_t *my_type;
array i,*j;
}
j=NULL;
- TRY(gras_datadesc_by_name("int", &int_type));
TRY(gras_datadesc_declare_array_fixed("fixed int array",
- int_type, 5, &my_type));
+ gras_datadesc_by_name("int"),
+ 5, &my_type));
TRY(write_read(my_type, (void*)&i,(void**) &j));
for (cpt=0; cpt<SIZE; cpt++)
}
gras_error_t test_intref(void) {
gras_error_t errcode;
- gras_datadesc_type_t *int_type;
gras_datadesc_type_t *my_type;
int *i,**j=NULL;
*i=45;
INFO1("==== Test on a reference to an integer (%p) ====",i);
- TRY(gras_datadesc_by_name("int", &int_type));
- TRY(gras_datadesc_declare_ref("int*",int_type,&my_type));
+ TRY(gras_datadesc_declare_ref("int*",gras_datadesc_by_name("int"),&my_type));
TRY(write_read(my_type, (void*)&i,(void**) &j));
gras_assert(*i == **j);
typedef char *string;
gras_error_t test_string(void) {
gras_error_t errcode;
- gras_datadesc_type_t *type;
char *i=strdup("Some data");
char *j=NULL;
INFO0("==== Test on string (dynamic array) ====");
- TRY(gras_datadesc_by_name("string", &type));
- TRY(write_read(type, (void*)i,(void**) &j));
+ TRY(write_read(gras_datadesc_by_name("string"), (void*)i,(void**) &j));
gras_assert(!strcmp(i,j));
free(j);
return no_error;
INFO0("==== Test on homogeneous structure ====");
/* create descriptor */
TRY(gras_datadesc_declare_struct("homostruct",&my_type));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"a","signed int"));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"b","int"));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"c","int"));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"d","int"));
+ TRY(gras_datadesc_declare_struct_append(my_type,"a",
+ gras_datadesc_by_name("signed int")));
+ TRY(gras_datadesc_declare_struct_append(my_type,"b",
+ gras_datadesc_by_name("int")));
+ TRY(gras_datadesc_declare_struct_append(my_type,"c",
+ gras_datadesc_by_name("int")));
+ TRY(gras_datadesc_declare_struct_append(my_type,"d",
+ gras_datadesc_by_name("int")));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(homostruct))) )
INFO0("==== Test on heterogeneous structure ====");
/* create descriptor */
TRY(gras_datadesc_declare_struct("hetestruct",&my_type));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"c1","unsigned char"));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"l1","unsigned long int"));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"c2","unsigned char"));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"l2","unsigned long int"));
+ TRY(gras_datadesc_declare_struct_append(my_type,"c1",
+ gras_datadesc_by_name("unsigned char")));
+ TRY(gras_datadesc_declare_struct_append(my_type,"l1",
+ gras_datadesc_by_name("unsigned long int")));
+ TRY(gras_datadesc_declare_struct_append(my_type,"c2",
+ gras_datadesc_by_name("unsigned char")));
+ TRY(gras_datadesc_declare_struct_append(my_type,"l2",
+ gras_datadesc_by_name("unsigned long int")));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(hetestruct))) )
INFO0("==== Test on nested structures ====");
/* create descriptor */
TRY(gras_datadesc_declare_struct("nestedstruct",&my_type));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"hete","hetestruct"));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"homo","homostruct"));
+ TRY(gras_datadesc_declare_struct_append(my_type,"hete",
+ gras_datadesc_by_name("hetestruct")));
+ TRY(gras_datadesc_declare_struct_append(my_type,"homo",
+ gras_datadesc_by_name("homostruct")));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(nestedstruct))) )
TRY(gras_datadesc_declare_struct("chained_list_t",&my_type));
TRY(gras_datadesc_declare_ref("chained_list_t*",my_type,&ref_my_type));
- TRY(gras_datadesc_declare_struct_append_name(my_type,"v","int"));
+ TRY(gras_datadesc_declare_struct_append(my_type,"v",
+ gras_datadesc_by_name("int")));
TRY(gras_datadesc_declare_struct_append(my_type,"l",ref_my_type));
/* init a value, exchange it and check its validity*/
chained_list_t *i, *j;
INFO0("==== Test on graph (cyclique chained list) ====");
- TRY(gras_datadesc_by_name("chained_list_t*", &my_type));
+ my_type = gras_datadesc_by_name("chained_list_t*");
+ gras_assert(my_type);
/* init a value, exchange it and check its validity*/
i = cons( rand(), cons( rand() , cons( rand(), NULL)));