lib: add meta_hash to connection, eliminate hash_offt

With a meta_hash at each connection (similar to easy handle, let
multi_ev.c store its pollsets as meta data, no longer needing its own
hashes.

This eliminates the last use of Curl_hash_offt. Remove it.

Closes #17095
This commit is contained in:
Stefan Eissing 2025-04-18 11:03:29 +02:00 committed by Daniel Stenberg
parent 1d66a769d7
commit 657aae79c0
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
18 changed files with 126 additions and 343 deletions

View file

@ -2,7 +2,7 @@
<info>
<keywords>
unittest
hash
uint_hash
</keywords>
</info>
@ -16,7 +16,7 @@ none
unittest
</features>
<name>
Internal hash_offt create/add/destroy testing, exercising clean functions
Internal uint_hash create/add/destroy testing, exercising clean functions
</name>
</client>
</testcase>

View file

@ -25,13 +25,13 @@
#include "curlx.h"
#include "hash_offt.h"
#include "uint-hash.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_hash_offt hash_static;
static struct uint_hash hash_static;
static void mydtor(curl_off_t id, void *elem)
static void mydtor(unsigned int id, void *elem)
{
int *ptr = (int *)elem;
(void)id;
@ -40,13 +40,13 @@ static void mydtor(curl_off_t id, void *elem)
static CURLcode unit_setup(void)
{
Curl_hash_offt_init(&hash_static, 15, mydtor);
Curl_uint_hash_init(&hash_static, 15, mydtor);
return CURLE_OK;
}
static void unit_stop(void)
{
Curl_hash_offt_destroy(&hash_static);
Curl_uint_hash_destroy(&hash_static);
}
UNITTEST_START
@ -54,34 +54,34 @@ UNITTEST_START
int *value2;
bool ok;
curl_off_t key = 20;
curl_off_t key2 = 25;
unsigned int key = 20;
unsigned int key2 = 25;
value = malloc(sizeof(int));
abort_unless(value != NULL, "Out of memory");
*value = 199;
ok = Curl_hash_offt_set(&hash_static, key, value);
ok = Curl_uint_hash_set(&hash_static, key, value);
if(!ok)
free(value);
abort_unless(ok, "insertion into hash failed");
v = Curl_hash_offt_get(&hash_static, key);
v = Curl_uint_hash_get(&hash_static, key);
abort_unless(v == value, "lookup present entry failed");
v = Curl_hash_offt_get(&hash_static, key2);
v = Curl_uint_hash_get(&hash_static, key2);
abort_unless(!v, "lookup missing entry failed");
Curl_hash_offt_clear(&hash_static);
Curl_uint_hash_clear(&hash_static);
/* Attempt to add another key/value pair */
value2 = malloc(sizeof(int));
abort_unless(value2 != NULL, "Out of memory");
*value2 = 204;
ok = Curl_hash_offt_set(&hash_static, key2, value2);
ok = Curl_uint_hash_set(&hash_static, key2, value2);
if(!ok)
free(value2);
abort_unless(ok, "insertion into hash failed");
v = Curl_hash_offt_get(&hash_static, key2);
v = Curl_uint_hash_get(&hash_static, key2);
abort_unless(v == value2, "lookup present entry failed");
v = Curl_hash_offt_get(&hash_static, key);
v = Curl_uint_hash_get(&hash_static, key);
abort_unless(!v, "lookup missing entry failed");
UNITTEST_STOP