Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
27bed0ed
Commit
27bed0ed
authored
Nov 13, 2019
by
Dridi Boukelmoune
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach struct padding to vtc.typesize()
And start adding some coverage, certainly not exhaustive.
parent
4495a0e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
5 deletions
+134
-5
m00000.vtc
bin/varnishtest/tests/m00000.vtc
+121
-0
vmod_vtc.c
lib/libvmod_vtc/vmod_vtc.c
+13
-5
No files found.
bin/varnishtest/tests/m00000.vtc
View file @
27bed0ed
...
...
@@ -143,3 +143,124 @@ varnish v1 -errvcl {Failed initialization} {
new shp = directors.shard_param();
}
}
varnish v1 -cliok "param.set vcc_allow_inline_c on"
varnish v1 -vcl {
import std;
import vtc;
backend be none;
C{
struct empty { };
struct zc {
size_t z;
char c;
};
struct ic {
int i;
char c;
};
struct sc {
short s;
char c;
};
struct cc {
char c1;
char c2;
};
struct czc {
char c1;
size_t z;
char c2;
};
struct cic {
char c1;
int i;
char c2;
};
struct csc {
char c1;
short s;
char c2;
};
struct uzp { /* same as vrt_blob */
unsigned u;
size_t z;
void *p;
};
#define SETHDR(type) \
VRT_SetHdr(ctx, \
&VGC_HDR_RESP_ ## type ## _2d_sizeof, \
VRT_INT_string(ctx, sizeof(struct type)), \
vrt_magic_string_end)
}C
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
C{ SETHDR(empty); }C
set resp.http.empty-typesize = vtc.typesize("");
set resp.http.empty-match =
(resp.http.empty-sizeof == resp.http.empty-typesize);
C{ SETHDR(zc); }C
set resp.http.zc-typesize = vtc.typesize("zc");
set resp.http.zc-match =
(resp.http.zc-sizeof == resp.http.zc-typesize);
C{ SETHDR(ic); }C
set resp.http.ic-typesize = vtc.typesize("ic");
set resp.http.ic-match =
(resp.http.ic-sizeof == resp.http.ic-typesize);
C{ SETHDR(sc); }C
set resp.http.sc-typesize = vtc.typesize("sc");
set resp.http.sc-match =
(resp.http.sc-sizeof == resp.http.sc-typesize);
C{ SETHDR(cc); }C
set resp.http.cc-typesize = vtc.typesize("cc");
set resp.http.cc-match =
(resp.http.cc-sizeof == resp.http.cc-typesize);
C{ SETHDR(czc); }C
set resp.http.czc-typesize = vtc.typesize("czc");
set resp.http.czc-match =
(resp.http.czc-sizeof == resp.http.czc-typesize);
C{ SETHDR(cic); }C
set resp.http.cic-typesize = vtc.typesize("cic");
set resp.http.cic-match =
(resp.http.cic-sizeof == resp.http.cic-typesize);
C{ SETHDR(csc); }C
set resp.http.csc-typesize = vtc.typesize("csc");
set resp.http.csc-match =
(resp.http.csc-sizeof == resp.http.csc-typesize);
C{ SETHDR(uzp); }C
set resp.http.uzp-typesize = vtc.typesize("uzp");
set resp.http.uzp-match =
(resp.http.uzp-sizeof == resp.http.uzp-typesize);
}
}
client c1 {
txreq
rxresp
expect resp.http.empty-match == true
expect resp.http.zc-match == true
expect resp.http.ic-match == true
expect resp.http.sc-match == true
expect resp.http.cc-match == true
expect resp.http.czc-match == true
expect resp.http.cic-match == true
expect resp.http.csc-match == true
expect resp.http.uzp-match == true
} -run
lib/libvmod_vtc/vmod_vtc.c
View file @
27bed0ed
...
...
@@ -267,14 +267,15 @@ vmod_workspace_dump(VRT_CTX, VCL_ENUM which, VCL_ENUM where,
VCL_INT
v_matchproto_
(
td_vtc_typesize
)
vmod_typesize
(
VRT_CTX
,
VCL_STRING
s
)
{
size_t
i
=
0
,
l
,
a
;
const
char
*
p
;
size_t
i
=
0
,
l
,
a
,
p
=
0
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
AN
(
s
);
for
(
p
=
s
;
*
p
;
p
++
)
{
switch
(
*
p
)
{
for
(
;
*
s
;
s
++
)
{
switch
(
*
s
)
{
#define VTC_TYPESIZE(c, t) case c: l = sizeof(t); break;
VTC_TYPESIZE
(
'c'
,
char
)
VTC_TYPESIZE
(
'd'
,
double
)
VTC_TYPESIZE
(
'f'
,
float
)
VTC_TYPESIZE
(
'i'
,
int
)
...
...
@@ -288,10 +289,17 @@ vmod_typesize(VRT_CTX, VCL_STRING s)
#undef VTC_TYPESIZE
default
:
return
(
-
1
);
}
if
(
l
>
p
)
p
=
l
;
a
=
i
%
l
;
if
(
a
!=
0
)
i
+=
(
l
-
a
);
i
+=
(
l
-
a
);
/* align */
i
+=
l
;
}
if
(
i
>
0
)
{
a
=
i
%
p
;
if
(
a
!=
0
)
i
+=
(
p
-
a
);
/* pad */
}
return
((
VCL_INT
)
i
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment