BUILD: hpack: make sure the hpack table can still be built standalone
Recent commit 2bdcc70fa7 ("MEDIUM: hpack: use a pool for the hpack table")
made the hpack code finally use a pool with very unintrusive code that was
assumed to be trivial enough to adjust if the code needed to be reused
outside of haproxy. Unfortunately the code in contrib/hpack already uses
it and broke the oss-fuzz tests as it doesn't build anymore.
This patch adds an HPACK_STANDALONE macro to decide if we should use the
pools or malloc+free. The resulting macros are called hpack_alloc() and
hpack_free() respectively, and the size must be passed into the pool
itself.
diff --git a/include/common/hpack-tbl.h b/include/common/hpack-tbl.h
index 44c0cc1..6d529f2 100644
--- a/include/common/hpack-tbl.h
+++ b/include/common/hpack-tbl.h
@@ -136,6 +136,17 @@
extern const struct http_hdr hpack_sht[HPACK_SHT_SIZE];
extern struct pool_head *pool_head_hpack_tbl;
+/* when built outside of haproxy, HPACK_STANDALONE must be defined, and
+ * pool_head_hpack_tbl->size must be set to the DHT size.
+ */
+#ifndef HPACK_STANDALONE
+#define hpack_alloc(pool) pool_alloc(pool)
+#define hpack_free(pool, ptr) pool_free(pool, ptr)
+#else
+#define hpack_alloc(pool) malloc(pool->size)
+#define hpack_free(pool, ptr) free(ptr)
+#endif
+
extern int __hpack_dht_make_room(struct hpack_dht *dht, unsigned int needed);
extern int hpack_dht_insert(struct hpack_dht *dht, struct ist name, struct ist value);
@@ -243,7 +254,7 @@
if (unlikely(!pool_head_hpack_tbl))
return NULL;
- dht = pool_alloc(pool_head_hpack_tbl);
+ dht = hpack_alloc(pool_head_hpack_tbl);
if (dht)
hpack_dht_init(dht, pool_head_hpack_tbl->size);
return dht;
@@ -252,7 +263,7 @@
/* free a dynamic headers table */
static inline void hpack_dht_free(struct hpack_dht *dht)
{
- pool_free(pool_head_hpack_tbl, dht);
+ hpack_free(pool_head_hpack_tbl, dht);
}
#endif /* _COMMON_HPACK_TBL_H */