]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: address singleuse issues
authorDaniel Stenberg <daniel@haxx.se>
Tue, 24 Jun 2025 14:26:22 +0000 (16:26 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 25 Jun 2025 09:46:26 +0000 (11:46 +0200)
- markup some functions UNITTEST, so that they are static unless in a
  unit test build

- make some functions #ifdef UNITTESTS as they are only used from unit
  tests

- adjusted unit tests accordingly to use local prototypes for functions
  not global in the library

Closes #17734

lib/llist.c
lib/llist.h
lib/uint-bset.c
lib/uint-hash.c
lib/uint-spbset.c
lib/uint-spbset.h
lib/uint-table.c
lib/uint-table.h
tests/unit/unit1300.c
tests/unit/unit3212.c
tests/unit/unit3213.c

index 82934425cfc90c9fe0fe51604fc015a14255f0c5..c9a7d4a8a789b2ba033b92bd53874c010d2c8b35 100644 (file)
@@ -181,7 +181,8 @@ void *Curl_node_take_elem(struct Curl_llist_node *e)
 /*
  * @unittest: 1300
  */
-void
+UNITTEST void Curl_node_uremove(struct Curl_llist_node *, void *);
+UNITTEST void
 Curl_node_uremove(struct Curl_llist_node *e, void *user)
 {
   struct Curl_llist *list;
index 597c0e00a33fd1d2399bab0336b62fc48e149980..a865b38f05e6ed8734e0a7d590296f96bfa7f2bd 100644 (file)
@@ -57,7 +57,6 @@ void Curl_llist_insert_next(struct Curl_llist *, struct Curl_llist_node *,
                             const void *, struct Curl_llist_node *node);
 void Curl_llist_append(struct Curl_llist *,
                        const void *, struct Curl_llist_node *node);
-void Curl_node_uremove(struct Curl_llist_node *, void *);
 void Curl_node_remove(struct Curl_llist_node *);
 void Curl_llist_destroy(struct Curl_llist *, void *);
 
index b31409cebb86dbc804ab7dc5d5626b98663d53ba..e612c390a6ba1d96a9b957361e66b93876450102 100644 (file)
@@ -74,14 +74,13 @@ void Curl_uint_bset_destroy(struct uint_bset *bset)
   memset(bset, 0, sizeof(*bset));
 }
 
-
-unsigned int Curl_uint_bset_capacity(struct uint_bset *bset)
+#ifdef UNITTESTS
+UNITTEST unsigned int Curl_uint_bset_capacity(struct uint_bset *bset)
 {
   return bset->nslots * 64;
 }
 
-
-unsigned int Curl_uint_bset_count(struct uint_bset *bset)
+UNITTEST unsigned int Curl_uint_bset_count(struct uint_bset *bset)
 {
   unsigned int i;
   unsigned int n = 0;
@@ -91,7 +90,7 @@ unsigned int Curl_uint_bset_count(struct uint_bset *bset)
   }
   return n;
 }
-
+#endif
 
 bool Curl_uint_bset_empty(struct uint_bset *bset)
 {
index afeb684d0cab341cba8d3fd1b6641c303ece2697..58a1cf59f9917fd13a9d71b144267a62e9804630 100644 (file)
@@ -206,10 +206,12 @@ static void uint_hash_clear(struct uint_hash *h)
   }
 }
 
-void Curl_uint_hash_clear(struct uint_hash *h)
+#ifdef UNITTESTS
+UNITTEST void Curl_uint_hash_clear(struct uint_hash *h)
 {
   uint_hash_clear(h);
 }
+#endif
 
 void Curl_uint_hash_destroy(struct uint_hash *h)
 {
index 578b9bd07c1442036cb47dcebf3959f221ea3c91..d12cdcb4aa1fa69bae1f1ebb0705e811e0c79687 100644 (file)
@@ -35,6 +35,9 @@
 #define CURL_UINT_SPBSET_MAGIC  0x70737362
 #endif
 
+/* Clear the bitset, making it empty. */
+UNITTEST void Curl_uint_spbset_clear(struct uint_spbset *bset);
+
 void Curl_uint_spbset_init(struct uint_spbset *bset)
 {
   memset(bset, 0, sizeof(*bset));
@@ -77,7 +80,7 @@ bool Curl_uint_spbset_empty(struct uint_spbset *bset)
   return TRUE;
 }
 
-void Curl_uint_spbset_clear(struct uint_spbset *bset)
+UNITTEST void Curl_uint_spbset_clear(struct uint_spbset *bset)
 {
   struct uint_spbset_chunk *next, *chunk;
 
index 571d56753cdc7d827f2901363f8e0a435b27c159..bd2347902c3b9f29934b75cad9889465a8aa33ad 100644 (file)
@@ -64,9 +64,6 @@ unsigned int Curl_uint_spbset_count(struct uint_spbset *bset);
 /* TRUE of bitset is empty */
 bool Curl_uint_spbset_empty(struct uint_spbset *bset);
 
-/* Clear the bitset, making it empty. */
-void Curl_uint_spbset_clear(struct uint_spbset *bset);
-
 /* Add the number `i` to the bitset.
  * Numbers can be added more than once, without making a difference.
  * Returns FALSE if allocations failed. */
index c235fc08bb0ee800cb244e304c3642270daaf2fe..21bcb6e1cf380e1a0b9bf9f48e9931f52c66f6be 100644 (file)
@@ -34,6 +34,9 @@
 #define CURL_UINT_TBL_MAGIC  0x62757473
 #endif
 
+/* Clear the table, making it empty. */
+UNITTEST void Curl_uint_tbl_clear(struct uint_tbl *tbl);
+
 void Curl_uint_tbl_init(struct uint_tbl *tbl,
                         Curl_uint_tbl_entry_dtor *entry_dtor)
 {
@@ -95,8 +98,7 @@ void Curl_uint_tbl_destroy(struct uint_tbl *tbl)
   memset(tbl, 0, sizeof(*tbl));
 }
 
-
-void Curl_uint_tbl_clear(struct uint_tbl *tbl)
+UNITTEST void Curl_uint_tbl_clear(struct uint_tbl *tbl)
 {
   DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC);
   uint_tbl_clear_rows(tbl, 0, tbl->nrows);
index 2c05b1de1ab9a5ef23ef0a31fd58a70b64da8bb0..c74ec7ad634d15788836dd24f5542722c2185cdc 100644 (file)
@@ -60,9 +60,6 @@ unsigned int Curl_uint_tbl_capacity(struct uint_tbl *tbl);
 /* Get the number of entries in the table. */
 unsigned int Curl_uint_tbl_count(struct uint_tbl *tbl);
 
-/* Clear the table, making it empty. */
-void Curl_uint_tbl_clear(struct uint_tbl *tbl);
-
 /* Get the entry for key or NULL if not present */
 void *Curl_uint_tbl_get(struct uint_tbl *tbl, unsigned int key);
 
index 544ac71c757afaf8101112d84bb368329aff07d7..d86fac54d58033018b799490f3c7db252630fd7f 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "llist.h"
 
+UNITTEST void Curl_node_uremove(struct Curl_llist_node *, void *);
+
 static void test_Curl_llist_dtor(void *key, void *value)
 {
   /* used by the llist API, does nothing here */
index 9ffa85ca4be4e78a7709ee45f47eed56f271b666..f53c1d6c15dfeb31d693ba239336f21220080d42 100644 (file)
@@ -27,6 +27,8 @@
 #include "uint-table.h"
 #include "curl_trc.h"
 
+UNITTEST void Curl_uint_tbl_clear(struct uint_tbl *tbl);
+
 #define TBL_SIZE    100
 
 static CURLcode t3212_setup(struct uint_tbl *tbl)
index 96c3a564ad6111f20467e10f2e33b458c030bc27..bb5738d2fb21e0dcbdc98de0865f848b07e1fe09 100644 (file)
@@ -27,6 +27,8 @@
 #include "uint-spbset.h"
 #include "curl_trc.h"
 
+UNITTEST void Curl_uint_spbset_clear(struct uint_spbset *bset);
+
 static void check_spbset(const char *name, const unsigned int *s, size_t slen)
 {
   struct uint_spbset bset;