hash: provide asserts to verify API use

- converted the Curl_hash_count() macro to a function

- Discourage accessing struct fields directly

- Document the internal API in HASH.md

Closes #14503
This commit is contained in:
Daniel Stenberg 2024-08-12 14:06:12 +02:00
parent 41a01033b3
commit c0233a35da
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
9 changed files with 246 additions and 15 deletions

View file

@ -247,10 +247,8 @@ static size_t trhash(void *key, size_t key_length, size_t slots_num)
static size_t trhash_compare(void *k1, size_t k1_len, void *k2, size_t k2_len)
{
(void)k1_len;
(void)k2_len;
return *(struct Curl_easy **)k1 == *(struct Curl_easy **)k2;
return !memcmp(k1, k2, k1_len);
}
static void trhash_dtor(void *nada)
@ -2929,18 +2927,24 @@ CURLMcode Curl_multi_pollset_ev(struct Curl_multi *multi,
}
if(last_action && (last_action != cur_action)) {
/* Socket was used already, but different action now */
if(last_action & CURL_POLL_IN)
if(last_action & CURL_POLL_IN) {
DEBUGASSERT(entry->readers);
entry->readers--;
if(last_action & CURL_POLL_OUT)
}
if(last_action & CURL_POLL_OUT) {
DEBUGASSERT(entry->writers);
entry->writers--;
if(cur_action & CURL_POLL_IN)
}
if(cur_action & CURL_POLL_IN) {
entry->readers++;
}
if(cur_action & CURL_POLL_OUT)
entry->writers++;
}
else if(!last_action &&
!Curl_hash_pick(&entry->transfers, (char *)&data, /* hash key */
sizeof(struct Curl_easy *))) {
DEBUGASSERT(entry->users < 100000); /* detect weird values */
/* a new transfer using this socket */
entry->users++;
if(cur_action & CURL_POLL_IN)
@ -3002,6 +3006,7 @@ CURLMcode Curl_multi_pollset_ev(struct Curl_multi *multi,
if(entry) {
unsigned char oldactions = last_ps->actions[i];
/* this socket has been removed. Decrease user count */
DEBUGASSERT(entry->users);
entry->users--;
if(oldactions & CURL_POLL_OUT)
entry->writers--;