summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5c1d636)
- Interface cleanup.
. gras_datadesc_by_name returns the searched type or NULL.
That way, no variable is needed to use a type desc once, which makes
the code clearer.
. gras_datadesc_declare_[struct|union]_append_name is removed. The last
two parameters were strings (field name, type name), leading to
common errors.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@97
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
gras_msgtype_t *msg_t;
TRY(gras_datadesc_declare_struct("msg_ping_t",&payload_t));
gras_msgtype_t *msg_t;
TRY(gras_datadesc_declare_struct("msg_ping_t",&payload_t));
- TRY(gras_datadesc_declare_struct_append_name(payload_t,
- "dummy","msg_ping_t"));
+ TRY(gras_datadesc_declare_struct_append(payload_t,"dummy",
+ gras_datadesc_by_name("int")));
TRY(gras_msgtype_declare("ping", payload_t, &msg_t)); msg_t=NULL;
TRY(gras_msgtype_declare("pong", payload_t, &msg_t));
TRY(gras_msgtype_declare("ping", payload_t, &msg_t)); msg_t=NULL;
TRY(gras_msgtype_declare("pong", payload_t, &msg_t));
/***********************************************
**** Search and retrieve declared datatype ****
***********************************************/
/***********************************************
**** Search and retrieve declared datatype ****
***********************************************/
-gras_error_t gras_datadesc_by_name(const char *name,
- gras_datadesc_type_t **type);
+gras_datadesc_type_t *gras_datadesc_by_name(const char *name);
/******************************************
**** Declare datadescription yourself ****
/******************************************
**** Declare datadescription yourself ****
const char *name,
gras_datadesc_type_t *field_type);
gras_error_t
const char *name,
gras_datadesc_type_t *field_type);
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
gras_datadesc_declare_union(const char *name,
gras_datadesc_type_cb_int_t selector,
gras_datadesc_type_t **dst);
gras_datadesc_declare_union(const char *name,
gras_datadesc_type_cb_int_t selector,
gras_datadesc_type_t **dst);
const char *name,
gras_datadesc_type_t *field_type);
gras_error_t
const char *name,
gras_datadesc_type_t *field_type);
gras_error_t
-gras_datadesc_declare_union_append_name(gras_datadesc_type_t *union_type,
- const char *name,
- const char *field_type_name);
-gras_error_t
gras_datadesc_declare_ref(const char *name,
gras_datadesc_type_t *referenced_type,
gras_datadesc_type_t **dst);
gras_datadesc_declare_ref(const char *name,
gras_datadesc_type_t *referenced_type,
gras_datadesc_type_t **dst);
e_gras_dd_scalar_encoding_float,
NULL,&ddt));
e_gras_dd_scalar_encoding_float,
NULL,&ddt));
- TRYFAIL(gras_datadesc_by_name("char",&elm));
- TRYFAIL(gras_datadesc_declare_array_dyn("string", elm, _strlen_cb,&ddt));
+ TRYFAIL(gras_datadesc_declare_array_dyn("string",
+ gras_datadesc_by_name("char"),
+ _strlen_cb,&ddt));
// elm=ddt;
// TRYFAIL(gras_datadesc_declare_ref("string", elm, &ddt));
// elm=ddt;
// TRYFAIL(gras_datadesc_declare_ref("string", elm, &ddt));
*
* Retrieve a type from its name
*/
*
* 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;
+ }
-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_datadesc_declare_struct_append:
*
gras_error_t errcode;
gras_datadesc_type_t *res;
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;
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];
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_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;
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];
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) {
static gras_error_t
gras_dd_send_int(gras_socket_t *sock,int i) {
- 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]);
}
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;
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]));
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 */
}
/* 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_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 */
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;
if (! (r_ref = malloc((size_t)pointer_type->size[r_arch])) )
RAISE_MALLOC;
gras_error_t errcode;
static gras_datadesc_type_t *string_type=NULL;
gras_error_t errcode;
static gras_datadesc_type_t *string_type=NULL;
- if (!string_type)
- TRY(gras_datadesc_by_name("string", &string_type));
+ if (!string_type) {
+ string_type = gras_datadesc_by_name("string");
+ gras_assert(string_type);
+ }
TRY(gras_trp_chunk_send(sock, GRAS_header, 6));
TRY(gras_trp_chunk_send(sock, GRAS_header, 6));
int r_arch;
char *msg_name;
int r_arch;
char *msg_name;
- if (!string_type)
- TRY(gras_datadesc_by_name("string", &string_type));
+ if (!string_type) {
+ string_type=gras_datadesc_by_name("string");
+ gras_assert(string_type);
+ }
TRY(gras_trp_chunk_recv(sock, header, 6));
for (cpt=0; cpt<4; cpt++)
TRY(gras_trp_chunk_recv(sock, header, 6));
for (cpt=0; cpt<4; cpt++)
gras_error_t test_int(void) {
gras_error_t errcode;
gras_error_t test_int(void) {
gras_error_t errcode;
- gras_datadesc_type_t *type;
int i=5,*j=NULL;
INFO0("==== Test on integer ====");
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_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 ====");
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;
gras_assert(i == *j);
free(j);
return no_error;
typedef int array[SIZE];
gras_error_t test_array(void) {
gras_error_t errcode;
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;
gras_datadesc_type_t *my_type;
array i,*j;
- TRY(gras_datadesc_by_name("int", &int_type));
TRY(gras_datadesc_declare_array_fixed("fixed int array",
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++)
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_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;
gras_datadesc_type_t *my_type;
int *i,**j=NULL;
*i=45;
INFO1("==== Test on a reference to an integer (%p) ====",i);
*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);
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;
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) ====");
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;
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));
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))) )
/* 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));
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))) )
/* 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));
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))) )
/* 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("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*/
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) ====");
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)));
/* init a value, exchange it and check its validity*/
i = cons( rand(), cons( rand() , cons( rand(), NULL)));