Skip to content

Commit

Permalink
vmodtool: Add option to specify c names of arguments and avoid "bool"
Browse files Browse the repository at this point in the history
I tried gcc version 15.0.0 20241203 and even without -std=c23, it would reserve
"bool":

In file included from vcc_std_if.c:10:
vcc_std_if.h:78:33: error: two or more data types in declaration specifiers
   78 |         VCL_BOOL                bool;
      |                                 ^~~~

(and more)

So this patch adds the option to specify the c name of arguments to vmod
functions/methods by separating it with a colon:

	vclname:cname

We use this facility to rename the "bool" argument to vmod_std functions to
"boola".
  • Loading branch information
nigoroll committed Dec 3, 2024
1 parent f7b6e24 commit 2c73ff9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/libvcc/vmodtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ def __init__(self, st, retval=True, prefix=""):
err("arguments cannot be of type '%s'" % t.vt, warn=False)
if t.nm is None:
t.nm2 = "arg%d" % n
elif ':' in t.nm:
[t.nm, t.nm2] = t.nm.split(':')
else:
t.nm2 = t.nm
self.args.append(t)
Expand Down
4 changes: 2 additions & 2 deletions vmod/vmod_std.vcc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Example::
std.cache_req_body(std.bytes(real=10.0*1024));

$Function INT integer([STRING s], [INT fallback],
[BOOL bool], [BYTES bytes], [DURATION duration], [REAL real],
[BOOL bool:boola], [BYTES bytes], [DURATION duration], [REAL real],
[TIME time])

Returns an INT from a STRING, BOOL or other quantity.
Expand Down Expand Up @@ -376,7 +376,7 @@ Example::
}

$Function REAL real([STRING s], [REAL fallback], [INT integer],
[BOOL bool], [BYTES bytes], [DURATION duration],
[BOOL bool:boola], [BYTES bytes], [DURATION duration],
[TIME time])

Returns a REAL from a STRING, BOOL or other quantity.
Expand Down
4 changes: 2 additions & 2 deletions vmod/vmod_std_conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ vmod_integer(VRT_CTX, struct VARGS(integer) *a)

r = NAN;
if (a->valid_bool)
return (a->bool ? 1 : 0);
return (a->boola ? 1 : 0);

if (a->valid_bytes)
return (a->bytes);
Expand Down Expand Up @@ -255,7 +255,7 @@ vmod_real(VRT_CTX, struct VARGS(real) *a)
return ((VCL_REAL)a->integer);

if (a->valid_bool)
return ((VCL_REAL)(a->bool ? 1 : 0));
return ((VCL_REAL)(a->boola ? 1 : 0));

if (a->valid_bytes)
return ((VCL_REAL)a->bytes);
Expand Down

0 comments on commit 2c73ff9

Please sign in to comment.