[master] 6495bc17b Add a utility macro to allocate mini-objects on the workspace
Nils Goroll
nils.goroll at uplex.de
Mon Oct 3 14:32:06 UTC 2022
commit 6495bc17b0da035759c77b3073f8a874694168de
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Thu Jun 2 16:32:57 2022 +0200
Add a utility macro to allocate mini-objects on the workspace
isn't this something we would have wanted all along?
This simplifies the common pattern to allocate/initialize a miniobj
on the workspace to
WS_TASK_ALLOC_OBJ(ctx, myobj, MYOBJ_MAGIC);
if (myobj == NULL)
return (error);
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 7b4d8f9a7..5c690df8f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -850,6 +850,15 @@ const char *WS_Printf(struct ws *ws, const char *fmt, ...) v_printflike_(2, 3);
void WS_VSB_new(struct vsb *, struct ws *);
char *WS_VSB_finish(struct vsb *, struct ws *, size_t *);
+/* WS utility */
+#define WS_TASK_ALLOC_OBJ(ctx, ptr, magic) do { \
+ ptr = WS_Alloc((ctx)->ws, sizeof *(ptr)); \
+ if ((ptr) == NULL) \
+ VRT_fail(ctx, "Out of workspace for " #magic); \
+ else \
+ INIT_OBJ(ptr, magic); \
+} while(0)
+
/* cache_rfc2616.c */
void RFC2616_Ttl(struct busyobj *, vtim_real now, vtim_real *t_origin,
float *ttl, float *grace, float *keep);
More information about the varnish-commit
mailing list