X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5b9db2dcfeacc4003b9f5ad9923fd7ce1e0cad53..73d53de1c9a9a2b536522d0d2e04031276941caf:/src/gras/DataDesc/cbps.c diff --git a/src/gras/DataDesc/cbps.c b/src/gras/DataDesc/cbps.c index 02e320ee3e..e09d63c6d0 100644 --- a/src/gras/DataDesc/cbps.c +++ b/src/gras/DataDesc/cbps.c @@ -19,15 +19,42 @@ struct s_gras_dd_cbps { gras_dict_t *space; gras_dynar_t *stack; gras_dynar_t *globals; - }; +gras_error_t +gras_dd_cbps_new(gras_dd_cbps_t **dst) { + gras_error_t errcode; + gras_dd_cbps_t *res; + + if (!(res=malloc(sizeof(gras_dd_cbps_t)))) + RAISE_MALLOC; + + TRY(gras_dict_new(&(res->space))); + /* FIXME:leaking on content of dynars*/ + TRY(gras_dynar_new(&(res->stack), sizeof(gras_dynar_t*), NULL)); + TRY(gras_dynar_new(&(res->globals), sizeof(char*), NULL)); + + *dst = res; + return no_error; +} + +void +gras_dd_cbps_free(gras_dd_cbps_t **state) { + + gras_dict_free ( &( (*state)->space ) ); + gras_dynar_free( (*state)->stack ); + gras_dynar_free( (*state)->globals ); + + free(*state); + *state = NULL; +} + /** * gras_dd_cbps_push: * - * Declare a new element in the PS, and give it a value. If an element of that name already exists, - * it becomes masked by the one given here, and will be seable again only after a pop to remove the - * value this push adds. + * Declare a new element in the PS, and give it a value. If an element of that + * name already exists, it is masked by the one given here, and will be + * seeable again only after a pop to remove the value this push adds. */ void gras_dd_cbps_push(gras_dd_cbps_t *ps, @@ -38,11 +65,11 @@ gras_dd_cbps_push(gras_dd_cbps_t *ps, gras_dynar_t *p_dynar = NULL; gras_dd_cbps_elm_t *p_var = NULL; - gras_dict_retrieve(ps->space, name, (void **)&p_dynar); + gras_dict_get(ps->space, name, (void **)&p_dynar); if (!p_dynar) { gras_dynar_new(&p_dynar, sizeof (gras_dd_cbps_elm_t *), NULL); - gras_dict_insert(ps->space, name, (void **)p_dynar, NULL); + gras_dict_set(ps->space, name, (void **)p_dynar, NULL); /* FIXME: leaking on dynar. Insert in dict with a way to free it */ } @@ -60,8 +87,9 @@ gras_dd_cbps_push(gras_dd_cbps_t *ps, /** * gras_dd_cbps_pop: * - * Retrieve an element from the PS, and remove it from the PS. If it's not present in the current block, - * it will fail (with abort) and not search in upper blocks since this denotes a programmation error. + * Retrieve an element from the PS, and remove it from the PS. If it's not + * present in the current block, it will fail (with abort) and not search + * in upper blocks since this denotes a programmation error. */ void * gras_dd_cbps_pop (gras_dd_cbps_t *ps, @@ -72,7 +100,7 @@ gras_dd_cbps_pop (gras_dd_cbps_t *ps, void *data = NULL; /* FIXME: Error handling */ - gras_dict_retrieve(ps->space, name, (void **)&p_dynar); + gras_dict_get(ps->space, name, (void **)&p_dynar); gras_dynar_pop(p_dynar, &p_elm); if (!gras_dynar_length(p_dynar)) { @@ -112,11 +140,14 @@ gras_dd_cbps_pop (gras_dd_cbps_t *ps, /** * gras_dd_cbps_set: * - * Change the value of an element in the PS. If it's not present in the current block, look in the upper ones. - * If it's not present in any of them, look in the globals (FIXME: which no function of this API allows to set). + * Change the value of an element in the PS. + * If it's not present in the current block, look in the upper ones. + * If it's not present in any of them, look in the globals + * (FIXME: which no function of this API allows to set). * If not present there neither, the code may segfault (Oli?). * - * Once a reference to an element of that name is found somewhere in the PS, its value is changed. + * Once a reference to an element of that name is found somewhere in the PS, + * its value is changed. */ void gras_dd_cbps_set (gras_dd_cbps_t *ps, @@ -127,11 +158,11 @@ gras_dd_cbps_set (gras_dd_cbps_t *ps, gras_dynar_t *p_dynar = NULL; gras_dd_cbps_elm_t *p_elm = NULL; - gras_dict_retrieve(ps->space, name, (void **)&p_dynar); + gras_dict_get(ps->space, name, (void **)&p_dynar); if (!p_dynar) { gras_dynar_new(&p_dynar, sizeof (gras_dd_cbps_elm_t *), NULL); - gras_dict_insert(ps->space, name, (void **)p_dynar, NULL); + gras_dict_set(ps->space, name, (void **)p_dynar, NULL); p_elm = calloc(1, sizeof(gras_dd_cbps_elm_t)); gras_dynar_push(ps->globals, &name); @@ -149,9 +180,11 @@ gras_dd_cbps_set (gras_dd_cbps_t *ps, /** * gras_dd_cbps_get: * - * Get the value of an element in the PS without modifying it. + * Get the value of an element in the PS without modifying it. + * (note that you get the content of the data struct and not a copy to it) * If it's not present in the current block, look in the upper ones. - * If it's not present in any of them, look in the globals (FIXME: which no function of this API allows to set). + * If it's not present in any of them, look in the globals + * (FIXME: which no function of this API allows to set). * If not present there neither, the code may segfault (Oli?). */ void * @@ -163,7 +196,7 @@ gras_dd_cbps_get (gras_dd_cbps_t *ps, gras_dd_cbps_elm_t *p_elm = NULL; /* FIXME: Error handling */ - gras_dict_retrieve(ps->space, name, (void **)&p_dynar); + gras_dict_get(ps->space, name, (void **)&p_dynar); gras_dynar_pop(p_dynar, &p_elm); gras_dynar_push(p_dynar, &p_elm); @@ -180,11 +213,13 @@ gras_dd_cbps_get (gras_dd_cbps_t *ps, * * Begins a new block. * - * Blocks are usefull to remove a whole set of declarations you don't even know. + * Blocks are usefull to remove a whole set of declarations you don't even know * - * For example, they constitute a very elegent solution to recursive data structures. - * push/pop may be used in some cases for that, but if your recursive data struct contains - * other structs needing themselves callbacks, you have to use block_{begin,end} to do the trick. + * E.g., they constitute an elegent solution to recursive data structures. + * + * push/pop may be used in some cases for that, but if your recursive data + * struct contains other structs needing themselves callbacks, you have to + * use block_{begin,end} to do the trick. */ void @@ -211,12 +246,11 @@ gras_dd_cbps_block_end(gras_dd_cbps_t *ps) { gras_dynar_pop(ps->stack, &p_dynar); gras_dynar_foreach(p_dynar, cursor, name) { - /* inline the code of _gs_vars_pop(p_vars, name), which was used only once */ gras_dynar_t *p_dynar_elm = NULL; gras_dd_cbps_elm_t *p_elm = NULL; - gras_dict_retrieve(ps->space, name, (void **)&p_dynar_elm); + gras_dict_get(ps->space, name, (void **)&p_dynar_elm); gras_dynar_pop(p_dynar_elm, &p_elm); if (!gras_dynar_length(p_dynar_elm)) { @@ -227,7 +261,7 @@ gras_dd_cbps_block_end(gras_dd_cbps_t *ps) { free(p_elm); free(name); } - + gras_dynar_free_container(p_dynar); }