lib: make private functions static and remove unused code
No binary (build failed)
—
(log yok)
| @@ -28,7 +28,7 @@ list. | |
| There are two functions for adding a node to a linked list: | |
| 1. Add it last in the list with `Curl_llist_append` | |
| - | 2. Add it after a specific existing node with `Curl_llist_insert_next` |
| + | 2. Add it after a specific existing node with `llist_insert_next` |
| When a node is added to a list, it stores an associated custom pointer to | |
| anything you like and you provide a pointer to a `struct Curl_llist_node` | |
| @@ -60,7 +60,7 @@ it: | |
| /* add the first struct to the list */ | |
| Curl_llist_append(&barlist, &entries[0], &entries[0].storage); | |
| - | See also `Curl_llist_insert_next`. |
| + | See also `llist_insert_next`. |
| ## Remove a node | |
| @@ -134,17 +134,17 @@ Adds `node` last in the `list` with a custom pointer to `elem`. | |
| The function is infallible. | |
| - | ## `Curl_llist_insert_next` |
| + | ## `llist_insert_next` |
| ~~~c | |
| - | void Curl_llist_insert_next(struct Curl_llist *list, |
| - | struct Curl_llist_node *node, |
| - | const void *elem, |
| - | struct Curl_llist_node *node); |
| + | void llist_insert_next(struct Curl_llist *list, |
| + | struct Curl_llist_node *before, |
| + | const void *elem, |
| + | struct Curl_llist_node *node); |
| ~~~ | |
| Adds `node` to the `list` with a custom pointer to `elem` immediately after | |
| - | the previous list `node`. |
| + | the previous list `before`. |
| The function is infallible. | |
| @@ -45,21 +45,21 @@ multi handle carries a "base timestamp", set once when created, and the | |
| timeout values are calculated relative to that. This works for about | |
| 500,000 years of continued operation of a multi handle. | |
| - | ## `Curl_splay` |
| + | ## `splay` |
| ~~~c | |
| - | struct Curl_tree *Curl_splay(struct curltime i, struct Curl_tree *t); |
| + | struct Curl_tree *splay(timediff_t key, struct Curl_tree *t); |
| ~~~ | |
| - | Rearranges the tree `t` after the provide time `i`. |
| + | Rearranges the tree `t` after the provide time `key`. |
| - | ## `Curl_splayinsert` |
| + | ## `splayinsert` |
| ~~~c | |
| - | struct Curl_tree *Curl_splayinsert(timediff_t key, |
| - | struct Curl_tree *t, |
| - | struct Curl_tree *node, |
| - | uint32_t id); |
| + | struct Curl_tree *splayinsert(timediff_t key, |
| + | struct Curl_tree *t, |
| + | struct Curl_tree *node, |
| + | uint32_t id); |
| ~~~ | |
| This function inserts a new `node` in the tree, using the given `key` | |
| @@ -72,12 +72,12 @@ has that arranged. | |
| It returns a pointer to the new tree root. | |
| - | ## `Curl_splaygetbest` |
| + | ## `splaygetbest` |
| ~~~c | |
| - | struct Curl_tree *Curl_splaygetbest(timediff_t key, |
| - | struct Curl_tree *tree, |
| - | struct Curl_tree **removed); |
| + | struct Curl_tree *splaygetbest(timediff_t key, |
| + | struct Curl_tree *tree, |
| + | struct Curl_tree **removed); |
| ~~~ | |
| If there is a node in the `tree` that has a timeout that is less than the | |
| @@ -86,12 +86,12 @@ in the `*removed` pointer (or NULL if there was no match). | |
| It returns a pointer to the new tree root. | |
| - | ## `Curl_splayremove` |
| + | ## `splayremove` |
| ~~~c | |
| - | int Curl_splayremove(struct Curl_tree *tree, |
| - | struct Curl_tree *node, |
| - | struct Curl_tree **newroot); |
| + | int splayremove(struct Curl_tree *tree, |
| + | struct Curl_tree *node, |
| + | struct Curl_tree **newroot); |
| ~~~ | |
| Removes a given `node` from a splay `tree`, and returns the `newroot` | |
| @@ -99,15 +99,6 @@ identifying the new tree root. | |
| Note that a clean tree without any nodes present implies a NULL pointer. | |
| - | ## `Curl_splayset` |
| - | |
| - | ~~~c |
| - | void Curl_splayset(struct Curl_tree *node, uint32_t id); |
| - | ~~~ |
| - | |
| - | Sets the `id` in the splay node. This value is not used |
| - | by the splay code itself and can be retrieved again with `Curl_splayget`. |
| - | |
| ## `Curl_splayget` | |
| ~~~c | |
| @@ -33,6 +33,7 @@ | |
| #define ITERINIT 0x5FEDCBA9 | |
| #endif | |
| + | |
| typedef size_t (*hash_function)(const void *key, | |
| size_t key_length, | |
| size_t slots_num); | |
| @@ -51,6 +52,24 @@ struct hash_functions { | |
| comp_function compare; | |
| }; | |
| + | /* @unittest 1603 |
| + | */ |
| + | UNITTEST size_t hash_str(const void *key, size_t key_length, size_t slots_num); |
| + | UNITTEST size_t hash_str(const void *key, size_t key_length, size_t slots_num) |
| + | { |
| + | const char *key_str = (const char *)key; |
| + | const char *end = key_str + key_length; |
| + | size_t h = 5381; |
| + | |
| + | while(key_str < end) { |
| + | size_t j = (size_t)*key_str++; |
| + | h += h << 5; |
| + | h ^= j; |
| + | } |
| + | |
| + | return (h % slots_num); |
| + | } |
| + | |
| /* Avoid treating the variable-length key[1] as a one-byte object. */ | |
| static char *hash_elem_key(struct Curl_hash_element *he) | |
| { | |
| @@ -89,7 +108,7 @@ static size_t compare_bytes(const void *key1, size_t key1_len, | |
| } | |
| static const struct hash_functions hash_functions[] = { | |
| - | { Curl_hash_str, compare_bytes }, |
| + | { hash_str, compare_bytes }, |
| { hash_socket, compare_socket } | |
| }; | |
| @@ -409,21 +428,6 @@ void Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user, | |
| } | |
| } | |
| - | size_t Curl_hash_str(const void *key, size_t key_length, size_t slots_num) |
| - | { |
| - | const char *key_str = (const char *)key; |
| - | const char *end = key_str + key_length; |
| - | size_t h = 5381; |
| - | |
| - | while(key_str < end) { |
| - | size_t j = (size_t)*key_str++; |
| - | h += h << 5; |
| - | h ^= j; |
| - | } |
| - | |
| - | return (h % slots_num); |
| - | } |
| - | |
| void Curl_hash_start_iterate(struct Curl_hash *hash, | |
| struct Curl_hash_iterator *iter) | |
| { | |
| @@ -83,7 +83,6 @@ size_t Curl_hash_count(struct Curl_hash *h); | |
| void Curl_hash_clean(struct Curl_hash *h); | |
| void Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user, | |
| int (*comp)(void *, void *)); | |
| - | size_t Curl_hash_str(const void *key, size_t key_length, size_t slots_num); |
| void Curl_hash_start_iterate(struct Curl_hash *hash, | |
| struct Curl_hash_iterator *iter); | |
| struct Curl_hash_element *Curl_hash_next_element( | |
| @@ -54,7 +54,7 @@ void Curl_llist_init(struct Curl_llist *l, Curl_llist_dtor dtor) | |
| } | |
| /* | |
| - | * Curl_llist_insert_next() |
| + | * llist_insert_next() |
| * | |
| * Inserts a new list element after the given one 'e'. If the given existing | |
| * entry is NULL and the list already has elements, the new one will be | |
| @@ -64,10 +64,13 @@ void Curl_llist_init(struct Curl_llist *l, Curl_llist_dtor dtor) | |
| * | |
| * @unittest 1300 | |
| */ | |
| - | void Curl_llist_insert_next(struct Curl_llist *list, |
| - | struct Curl_llist_node *e, /* may be NULL */ |
| - | const void *p, |
| - | struct Curl_llist_node *ne) |
| + | UNITTEST void llist_insert_next(struct Curl_llist *list, |
| + | struct Curl_llist_node *e, const void *p, |
| + | struct Curl_llist_node *ne); |
| + | UNITTEST void llist_insert_next(struct Curl_llist *list, |
| + | struct Curl_llist_node *e, /* may be NULL */ |
| + | const void *p, |
| + | struct Curl_llist_node *ne) |
| { | |
| DEBUGASSERT(list); | |
| DEBUGASSERT(list->_init == LLISTINIT); | |
| @@ -120,7 +123,7 @@ void Curl_llist_append(struct Curl_llist *list, const void *p, | |
| DEBUGASSERT(list); | |
| DEBUGASSERT(list->_init == LLISTINIT); | |
| DEBUGASSERT(ne); | |
| - | Curl_llist_insert_next(list, list->_tail, p, ne); |
| + | llist_insert_next(list, list->_tail, p, ne); |
| } | |
| void *Curl_node_take_elem(struct Curl_llist_node *e) | |
| @@ -51,8 +51,6 @@ struct Curl_llist_node { | |
| }; | |
| void Curl_llist_init(struct Curl_llist *l, Curl_llist_dtor dtor); | |
| - | void Curl_llist_insert_next(struct Curl_llist *list, struct Curl_llist_node *e, |
| - | const void *p, struct Curl_llist_node *ne); |
| void Curl_llist_append(struct Curl_llist *list, const void *p, | |
| struct Curl_llist_node *ne); | |
| void Curl_node_remove(struct Curl_llist_node *e); | |
| @@ -83,6 +83,8 @@ static void multi_xfer_bufs_free(struct Curl_multi *multi); | |
| #ifdef DEBUGBUILD | |
| static void multi_xfer_tbl_dump(struct Curl_multi *multi); | |
| #endif | |
| + | /* Get the # of transfers current in process/pending. */ |
| + | static uint32_t multi_xfers_running(struct Curl_multi *multi); |
| static const struct curltime *multi_now(struct Curl_multi *multi) | |
| { | |
| @@ -555,7 +557,7 @@ CURLMcode Curl_multi_add_handle(struct Curl_multi *multi, | |
| multi->admin->set.no_signal = data->set.no_signal; | |
| CURL_TRC_M(data, "added to multi, mid=%u, running=%u, total=%u", | |
| - | data->mid, Curl_multi_xfers_running(multi), |
| + | data->mid, multi_xfers_running(multi), |
| Curl_uint32_tbl_count(&multi->xfers)); | |
| return CURLM_OK; | |
| } | |
| @@ -875,7 +877,7 @@ CURLMcode Curl_multi_remove_handle(struct Curl_multi *multi, | |
| } | |
| CURL_TRC_M(data, "removed from multi, mid=%u, running=%u, total=%u", | |
| - | mid, Curl_multi_xfers_running(multi), |
| + | mid, multi_xfers_running(multi), |
| Curl_uint32_tbl_count(&multi->xfers)); | |
| return CURLM_OK; | |
| } | |
| @@ -2898,7 +2900,7 @@ static CURLMcode multi_perform(struct Curl_multi *multi, | |
| if(Curl_uint32_bset_first(&multi->process, &mid)) { | |
| CURL_TRC_M(multi->admin, "multi_perform(running=%u)", | |
| - | Curl_multi_xfers_running(multi)); |
| + | multi_xfers_running(multi)); |
| do { | |
| struct Curl_easy *data = Curl_multi_get_easy(multi, mid); | |
| CURLMcode mresult; | |
| @@ -2951,7 +2953,7 @@ static CURLMcode multi_perform(struct Curl_multi *multi, | |
| } | |
| if(running_handles) { | |
| - | uint32_t running = Curl_multi_xfers_running(multi); |
| + | uint32_t running = multi_xfers_running(multi); |
| *running_handles = (running < INT_MAX) ? (int)running : INT_MAX; | |
| } | |
| @@ -3300,7 +3302,7 @@ out: | |
| mresult = Curl_mntfy_dispatch_all(multi); | |
| if(running_handles) { | |
| - | uint32_t running = Curl_multi_xfers_running(multi); |
| + | uint32_t running = multi_xfers_running(multi); |
| *running_handles = (running < INT_MAX) ? (int)running : INT_MAX; | |
| } | |
| @@ -4160,7 +4162,7 @@ bool Curl_multi_knows_easy(struct Curl_multi *multi, struct Curl_easy *data) | |
| return Curl_uint32_tbl_get(&multi->xfers, data->mid) == data; | |
| } | |
| - | uint32_t Curl_multi_xfers_running(struct Curl_multi *multi) |
| + | static uint32_t multi_xfers_running(struct Curl_multi *multi) |
| { | |
| if(!multi) { | |
| DEBUGASSERT(0); | |
| @@ -164,9 +164,6 @@ bool Curl_multi_knows_easy(struct Curl_multi *multi, struct Curl_easy *data); | |
| * admin handle. */ | |
| uint32_t Curl_multi_xfers_attached(struct Curl_multi *multi); | |
| - | /* Get the # of transfers current in process/pending. */ |
| - | uint32_t Curl_multi_xfers_running(struct Curl_multi *multi); |
| - | |
| /* Mark a transfer as dirty, e.g. to be rerun at earliest convenience. | |
| * A cheap operation, can be done many times repeatedly. */ | |
| void Curl_multi_mark_dirty(struct Curl_easy *data); | |
| @@ -1446,14 +1446,6 @@ curl_off_t Curl_creader_client_length(struct Curl_easy *data) | |
| return r ? r->crt->total_length(data, r) : -1; | |
| } | |
| - | CURLcode Curl_creader_resume_from(struct Curl_easy *data, curl_off_t offset) |
| - | { |
| - | struct Curl_creader *r = data->req.reader.stack; |
| - | while(r && r->phase != CURL_CR_CLIENT) |
| - | r = r->next; |
| - | return r ? r->crt->resume_from(data, r, offset) : CURLE_READ_ERROR; |
| - | } |
| - | |
| CURLcode Curl_creader_unpause(struct Curl_easy *data) | |
| { | |
| struct Curl_creader *reader = data->req.reader.stack; | |
| @@ -376,20 +376,6 @@ curl_off_t Curl_creader_total_length(struct Curl_easy *data); | |
| */ | |
| curl_off_t Curl_creader_client_length(struct Curl_easy *data); | |
| - | /** |
| - | * Ask the installed reader at phase CURL_CR_CLIENT to start |
| - | * reading from the given offset. On success, this will reduce |
| - | * the `total_length()` by the amount. |
| - | * @param data the transfer to read client bytes for |
| - | * @param offset the offset where to start reads from, negative |
| - | * values will be ignored. |
| - | * @return CURLE_OK if offset could be set |
| - | * CURLE_READ_ERROR if not supported by reader or seek/read failed |
| - | * of offset larger than total length |
| - | * CURLE_PARTIAL_FILE if offset led to 0 total length |
| - | */ |
| - | CURLcode Curl_creader_resume_from(struct Curl_easy *data, curl_off_t offset); |
| - | |
| /** | |
| * Unpause all installed readers. | |
| */ | |
| @@ -26,6 +26,17 @@ | |
| #include "urldata.h" | |
| #include "splay.h" | |
| + | static struct Curl_tree *splay(timediff_t key, |
| + | struct Curl_tree *root); |
| + | |
| + | #ifdef UNITTESTS |
| + | uint32_t Curl_splayget(struct Curl_tree *node) |
| + | { |
| + | DEBUGASSERT(node); |
| + | return node->id; |
| + | } |
| + | |
| + | #endif |
| void Curl_timeouts_init(struct Curl_timeouts *timeouts, | |
| const struct curltime *ptime_base) | |
| @@ -56,7 +67,7 @@ int Curl_timeouts_next_ms(struct Curl_timeouts *timeouts, | |
| uint32_t *pmid) | |
| { | |
| if(timeouts->tree) { /* splay the lowest key to the root */ | |
| - | timeouts->tree = Curl_splay(TIMEDIFF_T_MIN, timeouts->tree); |
| + | timeouts->tree = splay(TIMEDIFF_T_MIN, timeouts->tree); |
| } | |
| if(timeouts->tree) { | |
| @@ -80,50 +91,6 @@ int Curl_timeouts_next_ms(struct Curl_timeouts *timeouts, | |
| return -1; | |
| } | |
| - | bool Curl_timeouts_remove_expired(struct Curl_timeouts *timeouts, |
| - | const struct curltime *ts, |
| - | uint32_t *pmid) |
| - | { |
| - | if(timeouts->tree) { |
| - | struct Curl_tree *t = NULL; |
| - | timediff_t elapsed_us = Curl_timeouts_offset_us(timeouts, ts); |
| - | timeouts->tree = Curl_splaygetbest(elapsed_us, timeouts->tree, &t); |
| - | if(t) { |
| - | *pmid = t->id; |
| - | return TRUE; |
| - | } |
| - | } |
| - | *pmid = UINT32_MAX; |
| - | return FALSE; |
| - | } |
| - | |
| - | void Curl_timeouts_add(struct Curl_timeouts *timeouts, |
| - | struct Curl_easy *data, |
| - | timediff_t offset_us) |
| - | { |
| - | struct Curl_tree *node = &data->state.timeouts.splaynode; |
| - | DEBUGASSERT(!node->registered); |
| - | timeouts->tree = Curl_splayinsert(offset_us, timeouts->tree, |
| - | node, data->mid); |
| - | } |
| - | |
| - | bool Curl_timeouts_remove(struct Curl_timeouts *timeouts, |
| - | struct Curl_easy *data) |
| - | { |
| - | struct Curl_tree *node = &data->state.timeouts.splaynode; |
| - | if(node->registered) { |
| - | int rc = Curl_splayremove(timeouts->tree, node, &timeouts->tree); |
| - | #ifdef DEBUGBUILD |
| - | if(rc) |
| - | curl_mfprintf(stderr, "Internal error removing splay node = %d\n", rc); |
| - | #else |
| - | (void)rc; |
| - | #endif |
| - | return TRUE; |
| - | } |
| - | return FALSE; |
| - | } |
| - | |
| /* | |
| * Splay using the key i (which may or may not be in the tree). | |
| * This rotates the tree, so: | |
| @@ -132,7 +99,7 @@ bool Curl_timeouts_remove(struct Curl_timeouts *timeouts, | |
| * - root->key may equal `key` or not | |
| * <https://en.wikipedia.org/wiki/Splay_tree> | |
| */ | |
| - | struct Curl_tree *Curl_splay(timediff_t key, |
| + | struct Curl_tree *splay(timediff_t key, |
| struct Curl_tree *root) | |
| { | |
| struct Curl_tree N, *l, *r, *y; | |
| @@ -203,12 +170,16 @@ struct Curl_tree *Curl_splay(timediff_t key, | |
| /* Insert key i into the tree t. Return a pointer to the resulting tree or | |
| * NULL if something went wrong. | |
| * | |
| - | * @unittest: 1309 |
| + | * @unittest 1309 |
| */ | |
| - | struct Curl_tree *Curl_splayinsert(timediff_t key, |
| - | struct Curl_tree *root, |
| - | struct Curl_tree *node, |
| - | uint32_t id) |
| + | UNITTEST struct Curl_tree *splayinsert(timediff_t key, |
| + | struct Curl_tree *root, |
| + | struct Curl_tree *node, |
| + | uint32_t id); |
| + | UNITTEST struct Curl_tree *splayinsert(timediff_t key, |
| + | struct Curl_tree *root, |
| + | struct Curl_tree *node, |
| + | uint32_t id) |
| { | |
| DEBUGASSERT(node); | |
| @@ -217,7 +188,7 @@ struct Curl_tree *Curl_splayinsert(timediff_t key, | |
| node->same = NULL; | |
| node->registered = TRUE; | |
| if(root) { | |
| - | root = Curl_splay(key, root); |
| + | root = splay(key, root); |
| DEBUGASSERT(root); | |
| if(key == root->key) { | |
| /* There already exists a node in the tree with the same key. | |
| @@ -248,12 +219,28 @@ struct Curl_tree *Curl_splayinsert(timediff_t key, | |
| return node; | |
| } | |
| + | void Curl_timeouts_add(struct Curl_timeouts *timeouts, |
| + | struct Curl_easy *data, |
| + | timediff_t offset_us) |
| + | { |
| + | struct Curl_tree *node = &data->state.timeouts.splaynode; |
| + | DEBUGASSERT(!node->registered); |
| + | timeouts->tree = splayinsert(offset_us, timeouts->tree, |
| + | node, data->mid); |
| + | } |
| + | |
| /* Finds and deletes the best-fit node from the tree. Return a pointer to the | |
| resulting tree. best-fit means the smallest node if it is not larger than | |
| - | the key */ |
| - | struct Curl_tree *Curl_splaygetbest(timediff_t key, |
| - | struct Curl_tree *root, |
| - | struct Curl_tree **removed) |
| + | the key |
| + | |
| + | @unittest 1309 |
| + | */ |
| + | UNITTEST struct Curl_tree *splaygetbest(timediff_t key, |
| + | struct Curl_tree *root, |
| + | struct Curl_tree **removed); |
| + | UNITTEST struct Curl_tree *splaygetbest(timediff_t key, |
| + | struct Curl_tree *root, |
| + | struct Curl_tree **removed) |
| { | |
| struct Curl_tree *x; | |
| @@ -263,7 +250,7 @@ struct Curl_tree *Curl_splaygetbest(timediff_t key, | |
| } | |
| /* find smallest */ | |
| - | root = Curl_splay(TIMEDIFF_T_MIN, root); |
| + | root = splay(TIMEDIFF_T_MIN, root); |
| DEBUGASSERT(root); | |
| if(key < root->key) { | |
| /* even the smallest is too big */ | |
| @@ -292,6 +279,23 @@ struct Curl_tree *Curl_splaygetbest(timediff_t key, | |
| return x; | |
| } | |
| + | bool Curl_timeouts_remove_expired(struct Curl_timeouts *timeouts, |
| + | const struct curltime *ts, |
| + | uint32_t *pmid) |
| + | { |
| + | if(timeouts->tree) { |
| + | struct Curl_tree *t = NULL; |
| + | timediff_t elapsed_us = Curl_timeouts_offset_us(timeouts, ts); |
| + | timeouts->tree = splaygetbest(elapsed_us, timeouts->tree, &t); |
| + | if(t) { |
| + | *pmid = t->id; |
| + | return TRUE; |
| + | } |
| + | } |
| + | *pmid = UINT32_MAX; |
| + | return FALSE; |
| + | } |
| + | |
| /* Deletes the node we point out from the tree if it is there. Stores a | |
| * pointer to the new resulting tree in 'newroot'. | |
| * | |
| @@ -301,11 +305,14 @@ struct Curl_tree *Curl_splaygetbest(timediff_t key, | |
| * NOTE: when the last node of the tree is removed, there is no tree left so | |
| * 'newroot' will be made to point to NULL. | |
| * | |
| - | * @unittest: 1309 |
| + | * @unittest 1309 |
| */ | |
| - | int Curl_splayremove(struct Curl_tree *root, |
| - | struct Curl_tree *removenode, |
| - | struct Curl_tree **newroot) |
| + | UNITTEST int splayremove(struct Curl_tree *root, |
| + | struct Curl_tree *removenode, |
| + | struct Curl_tree **newroot); |
| + | UNITTEST int splayremove(struct Curl_tree *root, |
| + | struct Curl_tree *removenode, |
| + | struct Curl_tree **newroot) |
| { | |
| struct Curl_tree *x; | |
| @@ -316,7 +323,7 @@ int Curl_splayremove(struct Curl_tree *root, | |
| if(!removenode->registered) | |
| return 2; | |
| - | root = Curl_splay(removenode->key, root); |
| + | root = splay(removenode->key, root); |
| DEBUGASSERT(root); | |
| /* First make sure that we got the same root key as the one we want | |
| @@ -357,7 +364,7 @@ int Curl_splayremove(struct Curl_tree *root, | |
| if(!root->smaller) | |
| x = root->larger; | |
| else { | |
| - | x = Curl_splay(removenode->key, root->smaller); |
| + | x = splay(removenode->key, root->smaller); |
| DEBUGASSERT(x); | |
| x->larger = root->larger; | |
| } | |
| @@ -367,15 +374,19 @@ int Curl_splayremove(struct Curl_tree *root, | |
| return 0; | |
| } | |
| - | /* set and get the custom payload for this tree node */ |
| - | void Curl_splayset(struct Curl_tree *node, uint32_t id) |
| - | { |
| - | DEBUGASSERT(node); |
| - | node->id = id; |
| - | } |
| - | |
| - | uint32_t Curl_splayget(struct Curl_tree *node) |
| + | bool Curl_timeouts_remove(struct Curl_timeouts *timeouts, |
| + | struct Curl_easy *data) |
| { | |
| - | DEBUGASSERT(node); |
| - | return node->id; |
| + | struct Curl_tree *node = &data->state.timeouts.splaynode; |
| + | if(node->registered) { |
| + | int rc = splayremove(timeouts->tree, node, &timeouts->tree); |
| + | #ifdef DEBUGBUILD |
| + | if(rc) |
| + | curl_mfprintf(stderr, "Internal error removing splay node = %d\n", rc); |
| + | #else |
| + | (void)rc; |
| + | #endif |
| + | return TRUE; |
| + | } |
| + | return FALSE; |
| } | |
| @@ -69,24 +69,8 @@ void Curl_timeouts_add(struct Curl_timeouts *timeouts, | |
| bool Curl_timeouts_remove(struct Curl_timeouts *timeouts, | |
| struct Curl_easy *data); | |
| - | struct Curl_tree *Curl_splay(timediff_t key, |
| - | struct Curl_tree *root); |
| - | |
| - | struct Curl_tree *Curl_splayinsert(timediff_t key, |
| - | struct Curl_tree *root, |
| - | struct Curl_tree *node, |
| - | uint32_t id); |
| - | |
| - | struct Curl_tree *Curl_splaygetbest(timediff_t key, |
| - | struct Curl_tree *root, |
| - | struct Curl_tree **removed); |
| - | |
| - | int Curl_splayremove(struct Curl_tree *root, |
| - | struct Curl_tree *removenode, |
| - | struct Curl_tree **newroot); |
| - | |
| - | /* set and get the custom payload for this tree node */ |
| - | void Curl_splayset(struct Curl_tree *node, uint32_t id); |
| + | #ifdef UNITTESTS |
| uint32_t Curl_splayget(struct Curl_tree *node); | |
| + | #endif |
| #endif /* HEADER_CURL_SPLAY_H */ | |
| @@ -193,10 +193,13 @@ static bool u8_strset_get_index(struct u8_strset *set, | |
| return FALSE; | |
| } | |
| + | #ifdef UNITTESTS |
| + | /* @unittest 3211 */ |
| uint16_t Curl_u8_strset_count(struct u8_strset *set) | |
| { | |
| return set->count; | |
| } | |
| + | #endif |
| const char *Curl_u8_strset_get(struct u8_strset *set, uint8_t id) | |
| { | |
| @@ -254,8 +257,11 @@ CURLcode Curl_u8_strset_setx(struct u8_strset *set, | |
| return Curl_u8_strset_setn(set, id, val); | |
| } | |
| - | CURLcode Curl_u8_strset_set(struct u8_strset *set, |
| - | uint8_t id, const char *str) |
| + | /* @unittest 3211 */ |
| + | UNITTEST CURLcode u8_strset_set(struct u8_strset *set, |
| + | uint8_t id, const char *str); |
| + | UNITTEST CURLcode u8_strset_set(struct u8_strset *set, |
| + | uint8_t id, const char *str) |
| { | |
| return Curl_u8_strset_setx(set, id, str, str ? strlen(str) : 0); | |
| } | |
| @@ -305,7 +311,7 @@ CURLcode Curl_u8_strset_copy(struct u8_strset *dest, struct u8_strset *src) | |
| Curl_u8_strset_clear(dest); | |
| for(i = 0; !result && (i < CURL_U8_SET_SLOT_CNT(src)); ++i) { | |
| if(src->data[i]) | |
| - | result = Curl_u8_strset_set(dest, src->ids[i], src->data[i]); |
| + | result = u8_strset_set(dest, src->ids[i], src->data[i]); |
| } | |
| return result; | |
| } | |
| @@ -61,12 +61,13 @@ struct u8_strset { | |
| void Curl_u8_strset_init(struct u8_strset *set); | |
| void Curl_u8_strset_clear(struct u8_strset *set); | |
| + | #ifdef UNITTESTS |
| uint16_t Curl_u8_strset_count(struct u8_strset *set); | |
| + | #endif |
| + | |
| const char *Curl_u8_strset_get(struct u8_strset *set, uint8_t id); | |
| /* Set string for id, makes a copy. */ | |
| - | CURLcode Curl_u8_strset_set(struct u8_strset *set, |
| - | uint8_t id, const char *str); |
| CURLcode Curl_u8_strset_setx(struct u8_strset *set, | |
| uint8_t id, const char *str, size_t slen); | |
| /* Set string for id, takes ownership of `str` even on failure. */ | |
| @@ -73,7 +73,7 @@ static CURLcode test_unit1300(const char *arg) | |
| "list tail should initiate to NULL"); | |
| /** | |
| - | * testing Curl_llist_insert_next |
| + | * testing llist_insert_next |
| * case 1: | |
| * list is empty | |
| * @assumptions: | |
| @@ -82,8 +82,8 @@ static CURLcode test_unit1300(const char *arg) | |
| * 3: list tail is the same as list head | |
| */ | |
| - | Curl_llist_insert_next(&llist, Curl_llist_head(&llist), &unusedData_case1, |
| - | &case1_list); |
| + | llist_insert_next(&llist, Curl_llist_head(&llist), &unusedData_case1, |
| + | &case1_list); |
| fail_unless(Curl_llist_count(&llist) == 1, | |
| "List size should be 1 after adding a new element"); | |
| @@ -95,7 +95,7 @@ static CURLcode test_unit1300(const char *arg) | |
| "tail and head should be the same"); | |
| /** | |
| - | * testing Curl_llist_insert_next |
| + | * testing llist_insert_next |
| * case 2: | |
| * list has 1 element, adding one element after the head | |
| * @assumptions: | |
| @@ -103,8 +103,8 @@ static CURLcode test_unit1300(const char *arg) | |
| * 2: the list tail should be our newly created element | |
| */ | |
| - | Curl_llist_insert_next(&llist, Curl_llist_head(&llist), |
| - | &unusedData_case3, &case3_list); |
| + | llist_insert_next(&llist, Curl_llist_head(&llist), |
| + | &unusedData_case3, &case3_list); |
| fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) == | |
| &unusedData_case3, | |
| "the node next to head is not getting set correctly"); | |
| @@ -112,7 +112,7 @@ static CURLcode test_unit1300(const char *arg) | |
| "the list tail is not getting set correctly"); | |
| /** | |
| - | * testing Curl_llist_insert_next |
| + | * testing llist_insert_next |
| * case 3: | |
| * list has >1 element, adding one element after "NULL" | |
| * @assumptions: | |
| @@ -120,8 +120,8 @@ static CURLcode test_unit1300(const char *arg) | |
| * 2: the list tail should different from newly created element | |
| */ | |
| - | Curl_llist_insert_next(&llist, Curl_llist_head(&llist), |
| - | &unusedData_case2, &case2_list); |
| + | llist_insert_next(&llist, Curl_llist_head(&llist), |
| + | &unusedData_case2, &case2_list); |
| fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) == | |
| &unusedData_case2, | |
| "the node next to head is not getting set correctly"); | |
| @@ -165,8 +165,8 @@ static CURLcode test_unit1300(const char *arg) | |
| * 2: element->previous->next is element->next | |
| * 3: element->next->previous is element->previous | |
| */ | |
| - | Curl_llist_insert_next(&llist, Curl_llist_head(&llist), &unusedData_case3, |
| - | &case4_list); |
| + | llist_insert_next(&llist, Curl_llist_head(&llist), &unusedData_case3, |
| + | &case4_list); |
| llist_size = Curl_llist_count(&llist); | |
| fail_unless(llist_size == 3, "should be 3 list members"); | |
| @@ -89,7 +89,7 @@ static void test_timeouts_nonzero_usec_base(void) | |
| "now offset did not shift by the base microseconds"); | |
| memset(&node, 0, sizeof(node)); | |
| - | timeouts.tree = Curl_splayinsert(deadline_offset, timeouts.tree, &node, 42); |
| + | timeouts.tree = splayinsert(deadline_offset, timeouts.tree, &node, 42); |
| timeout_ms = Curl_timeouts_next_ms(&timeouts, &now, &expire_offset, &mid); | |
| fail_unless(timeout_ms == 1150, "timeout changed with whole-second base"); | |
| @@ -116,7 +116,7 @@ static CURLcode test_unit1309(const char *arg) | |
| timediff_t key; | |
| key = (541 * i) % 1023; | |
| - | root = Curl_splayinsert(key, root, &nodes[i], (uint32_t)key); |
| + | root = splayinsert(key, root, &nodes[i], (uint32_t)key); |
| fail_unless(nodes[i].registered, "node should have been registered"); | |
| } | |
| @@ -129,14 +129,14 @@ static CURLcode test_unit1309(const char *arg) | |
| splayprint(root, 0, 1); | |
| curl_mprintf("remove node %d, payload %u\n", (int)rem, | |
| Curl_splayget(&nodes[rem])); | |
| - | rc = Curl_splayremove(root, &nodes[rem], &root); |
| + | rc = splayremove(root, &nodes[rem], &root); |
| if(rc) { | |
| /* failed! */ | |
| curl_mprintf("remove %d failed!\n", (int)rem); | |
| fail("remove"); | |
| } | |
| fail_unless(!nodes[rem].registered, "node should not be registered"); | |
| - | rc = Curl_splayremove(root, &nodes[rem], &root); |
| + | rc = splayremove(root, &nodes[rem], &root); |
| if(!rc) { | |
| /* failed! */ | |
| curl_mprintf("double remove %d did not fail!\n", (int)rem); | |
| @@ -154,8 +154,8 @@ static CURLcode test_unit1309(const char *arg) | |
| /* add some nodes with the same key */ | |
| for(j = 0; j <= i % 3; j++) { | |
| - | root = Curl_splayinsert(key, root, &nodes[(i * 3) + j], |
| - | (uint32_t)(key * 10 + j)); |
| + | root = splayinsert(key, root, &nodes[(i * 3) + j], |
| + | (uint32_t)(key * 10 + j)); |
| } | |
| } | |
| @@ -163,12 +163,12 @@ static CURLcode test_unit1309(const char *arg) | |
| for(i = 0; i <= 1100; i += 100) { | |
| curl_mprintf("Removing nodes not larger than %d\n", (int)i); | |
| tv_now = i; | |
| - | root = Curl_splaygetbest(tv_now, root, &removed); |
| + | root = splaygetbest(tv_now, root, &removed); |
| while(removed) { | |
| curl_mprintf("removed payload %u[%u]\n", | |
| Curl_splayget(removed) / 10, | |
| Curl_splayget(removed) % 10); | |
| - | root = Curl_splaygetbest(tv_now, root, &removed); |
| + | root = splaygetbest(tv_now, root, &removed); |
| } | |
| } | |
| @@ -177,14 +177,14 @@ static CURLcode test_unit1309(const char *arg) | |
| /* rebuild tree with duplicate values */ | |
| for(i = 0; i < NUM_NODES; i++) { | |
| timediff_t key = (541 * i) % 128; | |
| - | root = Curl_splayinsert(key, root, &nodes[i], (uint32_t)i); |
| + | root = splayinsert(key, root, &nodes[i], (uint32_t)i); |
| } | |
| removed = NULL; | |
| timeout_last = -1; | |
| for(i = 0; i <= 128; i += 32) { | |
| curl_mprintf("Removing nodes not larger than %d\n", (int)i); | |
| - | root = Curl_splaygetbest(i, root, &removed); |
| + | root = splaygetbest(i, root, &removed); |
| while(removed) { | |
| curl_mprintf("removed payload %u[timeout=%d]\n", | |
| Curl_splayget(removed), (int)removed->key); | |
| @@ -195,7 +195,7 @@ static CURLcode test_unit1309(const char *arg) | |
| fail("wrong timeout order"); | |
| } | |
| timeout_last = removed->key; | |
| - | root = Curl_splaygetbest(i, root, &removed); |
| + | root = splaygetbest(i, root, &removed); |
| } | |
| } | |
| @@ -125,10 +125,10 @@ static CURLcode test_unit1603(const char *arg) | |
| /* Ensure the key hashes are as expected in order to test both hash | |
| collisions and a full table. Unfortunately, the hashes can vary | |
| between architectures. */ | |
| - | if(Curl_hash_str(key1, strlen(key1), slots) != 1 || |
| - | Curl_hash_str(key2, strlen(key2), slots) != 0 || |
| - | Curl_hash_str(key3, strlen(key3), slots) != 2 || |
| - | Curl_hash_str(key4, strlen(key4), slots) != 1) |
| + | if(hash_str(key1, strlen(key1), slots) != 1 || |
| + | hash_str(key2, strlen(key2), slots) != 0 || |
| + | hash_str(key3, strlen(key3), slots) != 2 || |
| + | hash_str(key4, strlen(key4), slots) != 1) |
| curl_mfprintf(stderr, | |
| "Warning: hashes are not computed as expected on this " | |
| "architecture; test coverage is less comprehensive\n"); | |
| @@ -141,11 +141,11 @@ static void t3211_check_strset1(void) | |
| Curl_u8_strset_init(&set); | |
| fail_unless(!Curl_u8_strset_count(&set), "initial strset not empty"); | |
| - | result = Curl_u8_strset_set(&set, 0, "123"); |
| + | result = u8_strset_set(&set, 0, "123"); |
| fail_unless(!result, "add1 failed"); | |
| fail_unless(Curl_u8_strset_get(&set, 0), "get failed"); | |
| fail_unless(!t3211_strcmp("123", Curl_u8_strset_get(&set, 0)), "wrong get1"); | |
| - | result = Curl_u8_strset_set(&set, 0, "456"); |
| + | result = u8_strset_set(&set, 0, "456"); |
| fail_unless(!result, "add2 failed"); | |
| fail_unless(!t3211_strcmp("456", Curl_u8_strset_get(&set, 0)), "wrong get2"); | |
| Curl_u8_strset_unset(&set, 0); | |
| @@ -155,7 +155,7 @@ static void t3211_check_strset1(void) | |
| for(i = 0; i < 8; ++i) { | |
| idx = (uint8_t)((8 * i) + 3); | |
| curl_msnprintf(buf, sizeof(buf), "str-%d", idx); | |
| - | result = Curl_u8_strset_set(&set, idx, buf); |
| + | result = u8_strset_set(&set, idx, buf); |
| fail_unless(!result, "loop4-add failed"); | |
| fail_unless(!t3211_strcmp(buf, Curl_u8_strset_get(&set, idx)), | |
| "wrong get loop4"); | |
| @@ -177,7 +177,7 @@ static void t3211_check_strset1(void) | |
| /* Add entry 2 again, check */ | |
| idx = (uint8_t)((8 * 2) + 3); | |
| curl_msnprintf(buf, sizeof(buf), "str-%d", idx); | |
| - | result = Curl_u8_strset_set(&set, idx, buf); |
| + | result = u8_strset_set(&set, idx, buf); |
| fail_unless(!result, "re-add 2 failed"); | |
| fail_unless(!t3211_strcmp(buf, Curl_u8_strset_get(&set, idx)), | |
| "wrong re-add 2 get"); | |
| @@ -192,7 +192,7 @@ static void t3211_check_strset1(void) | |
| fail_unless(Curl_u8_strset_count(&set) == 8, "wrong count pre add 5"); | |
| idx = (uint8_t)((9 * 4) + 3); | |
| curl_msnprintf(buf, sizeof(buf), "str-%d", idx); | |
| - | result = Curl_u8_strset_set(&set, idx, buf); |
| + | result = u8_strset_set(&set, idx, buf); |
| fail_unless(!result, "add4 failed"); | |
| fail_unless(!t3211_strcmp(buf, Curl_u8_strset_get(&set, idx)), | |
| "wrong get4"); | |
| @@ -210,7 +210,7 @@ static void t3211_check_strset1(void) | |
| for(j = 0; j <= UINT8_MAX; ++j) { | |
| i = (uint8_t)j; | |
| curl_msnprintf(buf, sizeof(buf), "str-%d", i); | |
| - | result = Curl_u8_strset_set(&set, i, buf); |
| + | result = u8_strset_set(&set, i, buf); |
| fail_unless(!result, "loop256-add failed"); | |
| fail_unless(!t3211_strcmp(buf, Curl_u8_strset_get(&set, i)), | |
| "wrong get loop256"); | |