Commit ce9c09a2 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Negative SIZE to debug.workspace_allocate() now means

"leave this much free in workspace".

Add debug.typesize() which can tell us the C-sizeof() various types.
parent 1ed2adc1
......@@ -167,6 +167,8 @@ $Function VOID workspace_allocate(ENUM { client, backend, session, thread },
INT size)
Allocate and zero out SIZE bytes from a workspace.
If SIZE is negative, all but that many bytes are allocated from the workspace.
(NB: Beware of the alignment imposed on workspace allocations.)
$Function BOOL workspace_overflowed(ENUM { client, backend, session, thread })
......@@ -203,3 +205,17 @@ Synchronize with a varnishtest shared barrier.
$Function VOID test_probe(PROBE probe, PROBE same = 0)
Only here to make sure probe definitions are passed properly.
$Function INT typesize(STRING)
Returns the size in bytes of a collection of C-datatypes.
* 'p' = pointer
* 'i' = int
* 'd' = double
* 'f' = float
* 'l' = long
* 's' = short
* 'z' = size_t
* 'o' = off_t
* 'j' = intmax_t
......@@ -410,6 +410,10 @@ vmod_workspace_allocate(VRT_CTX, VCL_ENUM which, VCL_INT size)
WS_Assert(ws);
AZ(ws->r);
if (size < 0) {
size += WS_Reserve(ws, 0);
WS_Release(ws, 0);
}
s = WS_Alloc(ws, size);
if (!s)
return;
......@@ -544,3 +548,27 @@ vmod_test_probe(VRT_CTX, VCL_PROBE probe, VCL_PROBE same)
CHECK_OBJ_ORNULL(same, VRT_BACKEND_PROBE_MAGIC);
AZ(same == NULL || probe == same);
}
VCL_INT
vmod_typesize(VRT_CTX, VCL_STRING s)
{
int i = 0;
const char *p;
(void)ctx;
for (p = s; *p; p++) {
switch (*p) {
case 'p': i += sizeof(void *); break;
case 'i': i += sizeof(int); break;
case 'd': i += sizeof(double); break;
case 'f': i += sizeof(float); break;
case 'l': i += sizeof(long); break;
case 's': i += sizeof(short); break;
case 'z': i += sizeof(size_t); break;
case 'o': i += sizeof(off_t); break;
case 'j': i += sizeof(intmax_t); break;
default: return(-1);
}
}
return (i);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment