diff --git a/Engine/cs_par_base.c b/Engine/cs_par_base.c index 09be24a67b6..3e1f2005960 100644 --- a/Engine/cs_par_base.c +++ b/Engine/cs_par_base.c @@ -27,6 +27,7 @@ #include "csoundCore.h" #include "cs_par_base.h" +static int csp_set_exists(struct set_t *set, void *data); int csp_thread_index_get(CSOUND *csound) { @@ -172,19 +173,18 @@ void csp_barrier_dealloc(CSOUND *csound, void **barrier) */ /* static prototypes */ -static int set_element_delloc(CSOUND *csound, +static void set_element_delloc(CSOUND *csound, struct set_element_t **set_element); -static int set_element_alloc(CSOUND *csound, +static void set_element_alloc(CSOUND *csound, struct set_element_t **set_element, char *data); -static int set_is_set(CSOUND *csound, struct set_t *set); +static int set_is_set(struct set_t *set); #if 0 static int set_element_is_set_element(CSOUND *csound, struct set_element_t *set_element); #endif - -int csp_set_alloc(CSOUND *csound, struct set_t **set, +void csp_set_alloc(CSOUND *csound, struct set_t **set, set_element_data_eq *ele_eq_func, set_element_data_print *ele_print_func) { @@ -202,16 +202,16 @@ int csp_set_alloc(CSOUND *csound, struct set_t **set, p->ele_print_func = ele_print_func; p->cache = NULL; //printf("csp_set_alloc: %p\n", p); - return CSOUND_SUCCESS; + return; } -int csp_set_dealloc(CSOUND *csound, struct set_t **set) +void csp_set_dealloc(CSOUND *csound, struct set_t **set) { struct set_element_t *ele; struct set_t *p = *set; if (UNLIKELY(set == NULL || *set == NULL)) csound->Die(csound, Str("Invalid NULL Parameter set")); - if (UNLIKELY(!set_is_set(csound, *set))) + if (UNLIKELY(!set_is_set(*set))) csound->Die(csound, Str("Invalid Parameter set not a set")); if (p->cache != NULL) csound->Free(csound, p->cache); @@ -226,10 +226,10 @@ int csp_set_dealloc(CSOUND *csound, struct set_t **set) csound->Free(csound, p); *set = NULL; - return CSOUND_SUCCESS; + return; } -static int set_element_alloc(CSOUND *csound, +static void set_element_alloc(CSOUND *csound, struct set_element_t **set_element, char *data) { @@ -244,10 +244,10 @@ static int set_element_alloc(CSOUND *csound, memcpy((*set_element)->hdr, SET_ELEMENT_HDR, HDR_LEN); (*set_element)->data = cs_strdup(csound, data); - return CSOUND_SUCCESS; + return; } -static int set_element_delloc(CSOUND *csound, +static void set_element_delloc(CSOUND *csound, struct set_element_t **set_element) { if (UNLIKELY(set_element == NULL || *set_element == NULL)) @@ -255,12 +255,11 @@ static int set_element_delloc(CSOUND *csound, csound->Free(csound, *set_element); *set_element = NULL; - return CSOUND_SUCCESS; + return; } -static int set_is_set(CSOUND *csound, struct set_t *set) +static int set_is_set(struct set_t *set) { - IGN(csound); char buf[4]; if (set == NULL) return 0; memcpy(buf, (char *)set, HDR_LEN); @@ -281,11 +280,11 @@ static int } #endif -int csp_set_alloc_string(CSOUND *csound, struct set_t **set) +void csp_set_alloc_string(CSOUND *csound, struct set_t **set) { - return csp_set_alloc(csound, set, - csp_set_element_string_eq, - csp_set_element_string_print); + csp_set_alloc(csound, set, + csp_set_element_string_eq, + csp_set_element_string_print); } int csp_set_element_string_eq(struct set_element_t *ele1, @@ -314,7 +313,7 @@ void csp_set_element_ptr_print(CSOUND *csound, csound->Message(csound, "%p", ele->data); } -static int set_update_cache(CSOUND *csound, struct set_t *set) +static void set_update_cache(CSOUND *csound, struct set_t *set) { if (set->cache != NULL) { csound->Free(csound, set->cache); @@ -333,41 +332,30 @@ static int set_update_cache(CSOUND *csound, struct set_t *set) ele = ele->next; } } - return CSOUND_SUCCESS; + return; } /* * if out_set_element is not NULL and the element corresponding to * data is not found it will not be changed */ -static int set_element_get(CSOUND *csound, struct set_t *set, +static void set_element_get(struct set_t *set, char *data, struct set_element_t **out_set_element) { - IGN(csound); -#ifdef SET_DEBUG - if (UNLIKELY(set == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter set")); - if (UNLIKELY(data == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter data")); - if (UNLIKELY(out_set_element == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter out_set_element")); -#endif - { - struct set_element_t *ele = set->head; - struct set_element_t data_ele = { SET_ELEMENT_HDR, data, 0 }; - while (ele != NULL) { - if (set->ele_eq_func(ele, &data_ele)) { - *out_set_element = ele; - break; - } - ele = ele->next; + struct set_element_t *ele = set->head; + struct set_element_t data_ele = { SET_ELEMENT_HDR, data, 0 }; + while (ele != NULL) { + if (set->ele_eq_func(ele, &data_ele)) { + *out_set_element = ele; + break; } + ele = ele->next; } - return CSOUND_SUCCESS; + return; } -int csp_set_add(CSOUND *csound, struct set_t *set, void *data) +void csp_set_add(CSOUND *csound, struct set_t *set, void *data) { struct set_element_t *ele = NULL; #ifdef SET_DEBUG @@ -377,8 +365,8 @@ int csp_set_add(CSOUND *csound, struct set_t *set, void *data) csound->Die(csound, "Invalid NULL Parameter data"); #endif - if (csp_set_exists(csound, set, data)) { - return CSOUND_SUCCESS; + if (csp_set_exists(set, data)) { + return; } set_element_alloc(csound, &ele, data); @@ -394,10 +382,10 @@ int csp_set_add(CSOUND *csound, struct set_t *set, void *data) set_update_cache(csound, set); - return CSOUND_SUCCESS; + return; } -int csp_set_remove(CSOUND *csound, struct set_t *set, void *data) +void csp_set_remove(CSOUND *csound, struct set_t *set, void *data) { #ifdef SET_DEBUG if (UNLIKELY(set == NULL)) @@ -430,30 +418,30 @@ int csp_set_remove(CSOUND *csound, struct set_t *set, void *data) } set_update_cache(csound, set); - return CSOUND_SUCCESS; + return; } -int csp_set_exists(CSOUND *csound, struct set_t *set, void *data) +static int csp_set_exists(struct set_t *set, void *data) { struct set_element_t *ele = NULL; -#ifdef SET_DEBUG - if (UNLIKELY(set == NULL)) - csound->Die(csound, "Invalid NULL Parameter set"); - if (UNLIKELY(data == NULL)) - csound->Die(csound, "Invalid NULL Parameter data"); -#endif - set_element_get(csound, set, data, &ele); +/* #ifdef SET_DEBUG */ +/* if (UNLIKELY(set == NULL)) */ +/* csound->Die(csound, "Invalid NULL Parameter set"); */ +/* if (UNLIKELY(data == NULL)) */ +/* csound->Die(csound, "Invalid NULL Parameter data"); */ +/* #endif */ + set_element_get(set, data, &ele); return (ele == NULL ? 0 : 1); } -int csp_set_print(CSOUND *csound, struct set_t *set) +void csp_set_print(CSOUND *csound, struct set_t *set) { struct set_element_t *ele; #ifdef SET_DEBUG if (UNLIKELY(set == NULL)) csound->Die(csound, "Invalid NULL Parameter set"); - if (UNLIKELY(!set_is_set(csound, set))) + if (UNLIKELY(!set_is_set(set))) csound->Die(csound, "Invalid Parameter set not a set"); #endif @@ -467,7 +455,7 @@ int csp_set_print(CSOUND *csound, struct set_t *set) } csound->Message(csound, " }\n"); - return CSOUND_SUCCESS; + return; } inline int csp_set_count(struct set_t *set) @@ -475,7 +463,7 @@ inline int csp_set_count(struct set_t *set) #ifdef SET_DEBUG if (UNLIKELY(set == NULL)) csound->Die(csound, "Invalid NULL Parameter set"); - if (UNLIKELY(!set_is_set(csound, set))) + if (UNLIKELY(!set_is_set(set))) csound->Die(csound, "Invalid Parameter set not a set"); #endif @@ -484,40 +472,40 @@ inline int csp_set_count(struct set_t *set) /* 0 indexed */ // FIXME inlining breaks linkage for MSVC -/*inline*/ int csp_set_get_num(struct set_t *set, int num, void **data) +/*inline*/ void csp_set_get_num(struct set_t *set, int num, void **data) { -#ifdef SET_DEBUG - if (UNLIKELY(set == NULL)) - csound->Die(csound, "Invalid NULL Parameter set"); - if (UNLIKELY(!set_is_set(csound, set))) - csound->Die(csound, "Invalid Parameter set not a set"); - if (UNLIKELY(um >= set->count)) - csound->Die(csound, "Invalid Parameter num is out of bounds"); - if (UNLIKELY(data == NULL)) - csound->Die(csound, "Invalid NULL Parameter data"); -#endif +/* #ifdef SET_DEBUG */ +/* if (UNLIKELY(set == NULL)) */ +/* csound->Die(csound, "Invalid NULL Parameter set"); */ +/* if (UNLIKELY(!set_is_set(set))) */ +/* csound->Die(csound, "Invalid Parameter set not a set"); */ +/* if (UNLIKELY(um >= set->count)) */ +/* csound->Die(csound, "Invalid Parameter num is out of bounds"); */ +/* if (UNLIKELY(data == NULL)) */ +/* csound->Die(csound, "Invalid NULL Parameter data"); */ +/* #endif */ *data = set->cache[num]->data; - /* - if (set->cache != NULL) { - } - else { - int ctr = 0; - struct set_element_t *ele = set->head; - while (ctr < num && ele != NULL) { - ctr++; - ele = ele->next; - } - if (ctr == num && ele != NULL) { - *data = ele->data; - } - } - */ - return CSOUND_SUCCESS; + /* if (set->cache != NULL) { */ + + /* } */ + /* else { */ + /* int ctr = 0; */ + /* struct set_element_t *ele = set->head; */ + /* while (ctr < num && ele != NULL) { */ + /* ctr++; */ + /* ele = ele->next; */ + /* } */ + /* if (ctr == num && ele != NULL) { */ + /* *data = ele->data; */ + /* } */ + /* } */ + + return; } -int csp_set_union(CSOUND *csound, struct set_t *first, +void csp_set_union(CSOUND *csound, struct set_t *first, struct set_t *second, struct set_t **result) { int ctr = 0; @@ -526,11 +514,11 @@ int csp_set_union(CSOUND *csound, struct set_t *first, #ifdef SET_DEBUG if (UNLIKELY(first == NULL)) csound->Die(csound, "Invalid NULL Parameter first"); - if (UNLIKELY(!set_is_set(csound, first))) + if (UNLIKELY(!set_is_set(first))) csound->Die(csound, "Invalid Parameter set not a first"); if (UNLIKELY(second == NULL)) csound->Die(csound, "Invalid NULL Parameter second"); - if (UNLIKELY(!set_is_set(csound, second))) + if (UNLIKELY(!set_is_set(second))) csound->Die(csound, "Invalid Parameter set not a second"); if (UNLIKELY(result == NULL)) csound->Die(csound, "Invalid NULL Parameter result"); @@ -559,10 +547,10 @@ int csp_set_union(CSOUND *csound, struct set_t *first, csp_set_add(csound, *result, data); ctr++; } - return CSOUND_SUCCESS; + return; } -int csp_set_intersection(CSOUND *csound, struct set_t *first, +void csp_set_intersection(CSOUND *csound, struct set_t *first, struct set_t *second, struct set_t **result) { int ctr = 0; @@ -570,11 +558,11 @@ int csp_set_intersection(CSOUND *csound, struct set_t *first, #ifdef SET_DEBUG if (UNLIKELY(first == NULL)) csound->Die(csound, "Invalid NULL Parameter first"); - if (UNLIKELY(!set_is_set(csound, first))) + if (UNLIKELY(!set_is_set(first))) csound->Die(csound, "Invalid Parameter set not a first"); if (UNLIKELY(second == NULL)) csound->Die(csound, "Invalid NULL Parameter second"); - if (UNLIKELY(!set_is_set(csound, second))) + if (UNLIKELY(!set_is_set(second))) csound->Die(csound, "Invalid Parameter set not a second"); if (UNLIKELY(result == NULL)) csound->Die(csound, "Invalid NULL Parameter result"); @@ -591,11 +579,11 @@ int csp_set_intersection(CSOUND *csound, struct set_t *first, while (ctr < first_len) { void *data = NULL; csp_set_get_num(first, ctr, &data); - if (csp_set_exists(csound, second, data)) { + if (csp_set_exists(second, data)) { csp_set_add(csound, *result, data); } ctr++; } - return CSOUND_SUCCESS; + return; } diff --git a/H/cs_par_base.h b/H/cs_par_base.h index df4c21b7fd8..5db406e6420 100644 --- a/H/cs_par_base.h +++ b/H/cs_par_base.h @@ -130,34 +130,33 @@ void csp_set_element_string_print(CSOUND *csound, struct set_element_t *ele); void csp_set_element_ptr_print(CSOUND *csound, struct set_element_t *ele); /* allocating sets with specification of element equality and printing functions */ -int csp_set_alloc(CSOUND *csound, struct set_t **set, - set_element_data_eq *ele_eq_func, - set_element_data_print *ele_print_func); -int csp_set_dealloc(CSOUND *csound, struct set_t **set); +void csp_set_alloc(CSOUND *csound, struct set_t **set, + set_element_data_eq *ele_eq_func, + set_element_data_print *ele_print_func); +void csp_set_dealloc(CSOUND *csound, struct set_t **set); /* shortcut to get a set of strings uses string element equality and printing functions */ -int csp_set_alloc_string(CSOUND *csound, struct set_t **set); +void csp_set_alloc_string(CSOUND *csound, struct set_t **set); /* functions to manipulate set, return CSOUND_SUCCESS if successful */ -int csp_set_add(CSOUND *csound, struct set_t *set, void *data); -int csp_set_remove(CSOUND *csound, struct set_t *set, void *data); +void csp_set_add(CSOUND *csound, struct set_t *set, void *data); +void csp_set_remove(CSOUND *csound, struct set_t *set, void *data); /* check element existance returns 1 if data exists */ -int csp_set_exists(CSOUND *csound, struct set_t *set, void *data); -int csp_set_print(CSOUND *csound, struct set_t *set); +void csp_set_print(CSOUND *csound, struct set_t *set); /* get a count and access members */ int csp_set_count(struct set_t *set); -int csp_set_get_num(struct set_t *set, int num, void **data); +void csp_set_get_num(struct set_t *set, int num, void **data); /* * set union and intersection * allocates a new set in result * union/intersect first and second putting into result */ -int csp_set_union(CSOUND *csound, struct set_t *first, - struct set_t *second, struct set_t **result); -int csp_set_intersection(CSOUND *csound, struct set_t *first, - struct set_t *second, struct set_t **result); +void csp_set_union(CSOUND *csound, struct set_t *first, + struct set_t *second, struct set_t **result); +void csp_set_intersection(CSOUND *csound, struct set_t *first, + struct set_t *second, struct set_t **result); /* spinlock */