mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-05 04:53:23 +02:00
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.
This commit is contained in:
@@ -136,6 +136,17 @@ enum {
|
||||
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 @@ static inline struct hpack_dht *hpack_dht_alloc()
|
||||
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 @@ static inline struct hpack_dht *hpack_dht_alloc()
|
||||
/* 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 */
|
||||
|
||||
Reference in New Issue
Block a user