Commit 0fca8adf authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add VARGS() macro for vmod argument structures.

Change name for enums and args to have "enum_" and "arg_" prefixes.

Minimal changes to the vmods to react to these changes.
parent d4180b6a
...@@ -67,6 +67,12 @@ ...@@ -67,6 +67,12 @@
-emacro(845, HTTPH) // Info 845: The left argument to operator '&&' is certain to be 0 -emacro(845, HTTPH) // Info 845: The left argument to operator '&&' is certain to be 0
-esym(773, PCRE_DATE) // Expression-like macro '___' not parenthesized -esym(773, PCRE_DATE) // Expression-like macro '___' not parenthesized
//////////////
// Macros defined differently in each VMOD
-esym(767, VPFX) // macro '___' was defined differently in another module
-esym(767, VARGS) // macro '___' was defined differently in another module
-esym(767, VENUM) // macro '___' was defined differently in another module
////////////// //////////////
-efunc(1791, pdiff) // return last on line -efunc(1791, pdiff) // return last on line
////////////// //////////////
......
...@@ -31,6 +31,7 @@ Read the vmod.vcc file (inputvcc) and produce: ...@@ -31,6 +31,7 @@ Read the vmod.vcc file (inputvcc) and produce:
vmod_if.h -- Prototypes for the implementation vmod_if.h -- Prototypes for the implementation
vmod_if.c -- Magic glue & datastructures to make things a VMOD. vmod_if.c -- Magic glue & datastructures to make things a VMOD.
vmod_${name}.rst -- Extracted documentation vmod_${name}.rst -- Extracted documentation
vmod_${name}.man.rst -- Extracted documentation (rst2man input)
""" """
# This script should work with both Python 2 and Python 3. # This script should work with both Python 2 and Python 3.
...@@ -129,10 +130,14 @@ def unquote(txt): ...@@ -129,10 +130,14 @@ def unquote(txt):
def fmt_cstruct(fo, a, b): def fmt_cstruct(fo, a, b):
''' Output line in vmod struct ''' ''' Output line in vmod struct '''
t = "\t%s\t" % a t = '\t%s' % a
if len(t.expandtabs()) > 40:
t += '\n\t\t\t\t\t'
else:
t += '\t'
while len(t.expandtabs()) < 40: while len(t.expandtabs()) < 40:
t += "\t" t += '\t'
fo.write("%s%s\n" % (t, b)) fo.write('%s%s\n' % (t, b))
####################################################################### #######################################################################
...@@ -430,7 +435,7 @@ class ProtoType(object): ...@@ -430,7 +435,7 @@ class ProtoType(object):
return "typedef " + self.proto(args, name=self.typedef_name()) return "typedef " + self.proto(args, name=self.typedef_name())
def argstructname(self): def argstructname(self):
return "struct %s_arg" % self.cname(True) return "struct VARGS(%s)" % self.cname(False)
def argstructure(self): def argstructure(self):
s = "\n" + self.argstructname() + " {\n" s = "\n" + self.argstructname() + " {\n"
...@@ -471,7 +476,8 @@ class ProtoType(object): ...@@ -471,7 +476,8 @@ class ProtoType(object):
self.retval.jsonproto(ll) self.retval.jsonproto(ll)
ll.append('%s.%s' % (self.st.vcc.csn, cfunc)) ll.append('%s.%s' % (self.st.vcc.csn, cfunc))
if self.argstruct: if self.argstruct:
ll.append(self.argstructname()) # We cannot use VARGS() here, we are after the #undef
ll.append('struct arg_%s' % self.cname(True))
else: else:
ll.append("") ll.append("")
for i in self.args: for i in self.args:
...@@ -662,8 +668,7 @@ class EventStanza(Stanza): ...@@ -662,8 +668,7 @@ class EventStanza(Stanza):
def cstuff(self, fo, where): def cstuff(self, fo, where):
if where == 'h': if where == 'h':
fo.write("vmod_event_f %s%s;\n" % fo.write("vmod_event_f VPFX(%s);\n" % self.event_func)
(self.vcc.sympfx, self.event_func))
def cstruct(self, fo, define): def cstruct(self, fo, define):
if define: if define:
...@@ -741,7 +746,7 @@ class ObjectStanza(Stanza): ...@@ -741,7 +746,7 @@ class ObjectStanza(Stanza):
fo.write(' :ref:`%s`\n \n' % i.rstlbl) fo.write(' :ref:`%s`\n \n' % i.rstlbl)
def cstuff(self, fo, w): def cstuff(self, fo, w):
sn = self.vcc.sympfx + self.vcc.modname + "_" + self.proto.name sn = 'VPFX(' + self.vcc.modname + '_' + self.proto.name + ')'
fo.write("struct %s;\n" % sn) fo.write("struct %s;\n" % sn)
fo.write(self.init.cproto( fo.write(self.init.cproto(
...@@ -952,8 +957,17 @@ class vcc(object): ...@@ -952,8 +957,17 @@ class vcc(object):
fo.write("#endif\n") fo.write("#endif\n")
fo.write("\n") fo.write("\n")
fo.write('#define VPFX(a) %s##a\n' % self.sympfx)
fo.write('#define VARGS(a) arg_%s##a\n' % self.sympfx)
fo.write('#define VENUM(a) enum_%s##a\n' % self.sympfx)
fo.write('\n')
for j in sorted(self.enums): for j in sorted(self.enums):
fo.write("extern VCL_ENUM %senum_%s;\n" % (self.sympfx, j)) fo.write("extern VCL_ENUM VENUM(%s);\n" % j)
fo.write("\n")
for j in sorted(self.enums):
fo.write("//lint -esym(759, enum_%s%s)\n" % (self.sympfx, j))
fo.write("//lint -esym(765, enum_%s%s)\n" % (self.sympfx, j))
fo.write("\n") fo.write("\n")
for j in self.contents: for j in self.contents:
...@@ -974,7 +988,7 @@ class vcc(object): ...@@ -974,7 +988,7 @@ class vcc(object):
j.cstruct(fo, False) j.cstruct(fo, False)
fo.write("\n") fo.write("\n")
for j in sorted(self.enums): for j in sorted(self.enums):
fo.write("\t&%senum_%s,\n" % (self.sympfx, j)) fmt_cstruct(fo, '.enum_%s =' % j, '&VENUM(%s),' % j)
fo.write("};\n") fo.write("};\n")
def json(self, fo): def json(self, fo):
...@@ -1026,6 +1040,11 @@ class vcc(object): ...@@ -1026,6 +1040,11 @@ class vcc(object):
write_c_file_warning(fo) write_c_file_warning(fo)
fx.write('#define VPFX(a) %s##a\n' % self.sympfx)
fx.write('#define VARGS(a) arg_%s##a\n' % self.sympfx)
fx.write('#define VENUM(a) enum_%s##a\n' % self.sympfx)
fx.write('\n')
fo.write('#include "config.h"\n') fo.write('#include "config.h"\n')
fo.write('#include <stdio.h>\n') fo.write('#include <stdio.h>\n')
for i in ["vdef", "vrt", self.pfx, "vmod_abi"]: for i in ["vdef", "vrt", self.pfx, "vmod_abi"]:
...@@ -1033,7 +1052,7 @@ class vcc(object): ...@@ -1033,7 +1052,7 @@ class vcc(object):
fo.write("\n") fo.write("\n")
for j in sorted(self.enums): for j in sorted(self.enums):
fo.write('VCL_ENUM %senum_%s = "%s";\n' % (self.sympfx, j, j)) fo.write('VCL_ENUM VENUM(%s) = "%s";\n' % (j, j))
fo.write("\n") fo.write("\n")
for i in self.contents: for i in self.contents:
...@@ -1053,6 +1072,10 @@ class vcc(object): ...@@ -1053,6 +1072,10 @@ class vcc(object):
fo.write("\n/*lint -esym(754, " + self.csn + "::*) */\n") fo.write("\n/*lint -esym(754, " + self.csn + "::*) */\n")
self.cstruct_init(fo) self.cstruct_init(fo)
fx.write('#undef VPFX\n')
fx.write('#undef VARGS\n')
fx.write('#undef VENUM\n')
fx.close() fx.close()
fo.write("\nstatic const char Vmod_Proto[] =\n") fo.write("\nstatic const char Vmod_Proto[] =\n")
......
...@@ -118,7 +118,7 @@ static const struct vrt_blob null_blob[1] = {{ ...@@ -118,7 +118,7 @@ static const struct vrt_blob null_blob[1] = {{
static enum encoding static enum encoding
parse_encoding(VCL_ENUM e) parse_encoding(VCL_ENUM e)
{ {
#define VMODENUM(n) if (e == vmod_enum_ ## n) return(n); #define VMODENUM(n) if (e == VENUM(n)) return(n);
#include "tbl_encodings.h" #include "tbl_encodings.h"
WRONG("illegal encoding enum"); WRONG("illegal encoding enum");
} }
...@@ -126,7 +126,7 @@ parse_encoding(VCL_ENUM e) ...@@ -126,7 +126,7 @@ parse_encoding(VCL_ENUM e)
static enum case_e static enum case_e
parse_case(VCL_ENUM e) parse_case(VCL_ENUM e)
{ {
#define VMODENUM(n) if (e == vmod_enum_ ## n) return(n); #define VMODENUM(n) if (e == VENUM(n)) return(n);
#include "tbl_case.h" #include "tbl_case.h"
WRONG("illegal case enum"); WRONG("illegal case enum");
} }
......
...@@ -94,16 +94,16 @@ xyzzy_author(VRT_CTX, VCL_ENUM person, VCL_ENUM someone) ...@@ -94,16 +94,16 @@ xyzzy_author(VRT_CTX, VCL_ENUM person, VCL_ENUM someone)
(void)someone; (void)someone;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (person == xyzzy_enum_phk) if (person == VENUM(phk))
return ("Poul-Henning"); return ("Poul-Henning");
assert(strcmp(person, "phk")); assert(strcmp(person, "phk"));
if (person == xyzzy_enum_des) if (person == VENUM(des))
return ("Dag-Erling"); return ("Dag-Erling");
assert(strcmp(person, "des")); assert(strcmp(person, "des"));
if (person == xyzzy_enum_kristian) if (person == VENUM(kristian))
return ("Kristian"); return ("Kristian");
assert(strcmp(person, "kristian")); assert(strcmp(person, "kristian"));
if (person == xyzzy_enum_mithrandir) if (person == VENUM(mithrandir))
return ("Tollef"); return ("Tollef");
assert(strcmp(person, "mithrandir")); assert(strcmp(person, "mithrandir"));
WRONG("Illegal VMOD enum"); WRONG("Illegal VMOD enum");
...@@ -194,7 +194,7 @@ xyzzy_rot52(VRT_CTX, VCL_HTTP hp) ...@@ -194,7 +194,7 @@ xyzzy_rot52(VRT_CTX, VCL_HTTP hp)
} }
VCL_STRING v_matchproto_(td_debug_argtest) VCL_STRING v_matchproto_(td_debug_argtest)
xyzzy_argtest(VRT_CTX, struct xyzzy_argtest_arg *arg) xyzzy_argtest(VRT_CTX, struct VARGS(argtest) *arg)
{ {
char buf[100]; char buf[100];
......
...@@ -160,14 +160,14 @@ struct xyzzy_debug_obj_opt { ...@@ -160,14 +160,14 @@ struct xyzzy_debug_obj_opt {
unsigned magic; unsigned magic;
#define VMOD_DEBUG_OBJ_OPT_MAGIC 0xccbd9b78 #define VMOD_DEBUG_OBJ_OPT_MAGIC 0xccbd9b78
char *name; char *name;
struct xyzzy_obj_opt_meth_opt_arg args; struct VARGS(obj_opt_meth_opt) args;
void *freeptr; void *freeptr;
}; };
VCL_VOID v_matchproto_() VCL_VOID v_matchproto_()
xyzzy_obj_opt__init(VRT_CTX, xyzzy_obj_opt__init(VRT_CTX,
struct xyzzy_debug_obj_opt **op, const char *vcl_name, struct xyzzy_debug_obj_opt **op, const char *vcl_name,
struct xyzzy_obj_opt__init_arg *args) struct VARGS(obj_opt__init) *args)
{ {
struct xyzzy_debug_obj_opt *o; struct xyzzy_debug_obj_opt *o;
...@@ -221,7 +221,7 @@ xyzzy_obj_opt__fini(struct xyzzy_debug_obj_opt **op) ...@@ -221,7 +221,7 @@ xyzzy_obj_opt__fini(struct xyzzy_debug_obj_opt **op)
VCL_STRING v_matchproto_() VCL_STRING v_matchproto_()
xyzzy_obj_opt_meth_opt(VRT_CTX, xyzzy_obj_opt_meth_opt(VRT_CTX,
struct xyzzy_debug_obj_opt *o, struct xyzzy_debug_obj_opt *o,
struct xyzzy_obj_opt_meth_opt_arg *args) struct VARGS(obj_opt_meth_opt) *args)
{ {
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_OPT_MAGIC); CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_OPT_MAGIC);
......
...@@ -182,7 +182,7 @@ struct vmod_directors_shard { ...@@ -182,7 +182,7 @@ struct vmod_directors_shard {
static enum by_e static enum by_e
parse_by_e(VCL_ENUM e) parse_by_e(VCL_ENUM e)
{ {
#define VMODENUM(n) if (e == vmod_enum_ ## n) return(BY_ ## n); #define VMODENUM(n) if (e == VENUM(n)) return(BY_ ## n);
#include "tbl_by.h" #include "tbl_by.h"
WRONG("illegal by enum"); WRONG("illegal by enum");
} }
...@@ -190,7 +190,7 @@ parse_by_e(VCL_ENUM e) ...@@ -190,7 +190,7 @@ parse_by_e(VCL_ENUM e)
static enum healthy_e static enum healthy_e
parse_healthy_e(VCL_ENUM e) parse_healthy_e(VCL_ENUM e)
{ {
#define VMODENUM(n) if (e == vmod_enum_ ## n) return(n); #define VMODENUM(n) if (e == VENUM(n)) return(n);
#include "tbl_healthy.h" #include "tbl_healthy.h"
WRONG("illegal healthy enum"); WRONG("illegal healthy enum");
} }
...@@ -198,7 +198,7 @@ parse_healthy_e(VCL_ENUM e) ...@@ -198,7 +198,7 @@ parse_healthy_e(VCL_ENUM e)
static enum resolve_e static enum resolve_e
parse_resolve_e(VCL_ENUM e) parse_resolve_e(VCL_ENUM e)
{ {
#define VMODENUM(n) if (e == vmod_enum_ ## n) return(n); #define VMODENUM(n) if (e == VENUM(n)) return(n);
#include "tbl_resolve.h" #include "tbl_resolve.h"
WRONG("illegal resolve enum"); WRONG("illegal resolve enum");
} }
...@@ -343,7 +343,7 @@ vmod_shard_associate(VRT_CTX, ...@@ -343,7 +343,7 @@ vmod_shard_associate(VRT_CTX,
VCL_BOOL v_matchproto_(td_directors_shard_add_backend) VCL_BOOL v_matchproto_(td_directors_shard_add_backend)
vmod_shard_add_backend(VRT_CTX, struct vmod_directors_shard *vshard, vmod_shard_add_backend(VRT_CTX, struct vmod_directors_shard *vshard,
struct vmod_shard_add_backend_arg *args) struct VARGS(shard_add_backend) *args)
{ {
CHECK_OBJ_NOTNULL(vshard, VMOD_SHARD_SHARD_MAGIC); CHECK_OBJ_NOTNULL(vshard, VMOD_SHARD_SHARD_MAGIC);
...@@ -361,7 +361,7 @@ vmod_shard_add_backend(VRT_CTX, struct vmod_directors_shard *vshard, ...@@ -361,7 +361,7 @@ vmod_shard_add_backend(VRT_CTX, struct vmod_directors_shard *vshard,
VCL_BOOL v_matchproto_(td_directors_shard_remove_backend) VCL_BOOL v_matchproto_(td_directors_shard_remove_backend)
vmod_shard_remove_backend(VRT_CTX, struct vmod_directors_shard *vshard, vmod_shard_remove_backend(VRT_CTX, struct vmod_directors_shard *vshard,
struct vmod_shard_remove_backend_arg *args) struct VARGS(shard_remove_backend) *args)
{ {
VCL_BACKEND be = args->valid_backend ? args->backend : NULL; VCL_BACKEND be = args->valid_backend ? args->backend : NULL;
VCL_STRING ident = args->valid_ident ? args->ident : NULL; VCL_STRING ident = args->valid_ident ? args->ident : NULL;
...@@ -498,7 +498,7 @@ shard_blob_key(VCL_BLOB key_blob) ...@@ -498,7 +498,7 @@ shard_blob_key(VCL_BLOB key_blob)
#define tobit(args, name) ((args)->valid_##name ? arg_##name : 0) #define tobit(args, name) ((args)->valid_##name ? arg_##name : 0)
static uint32_t static uint32_t
shard_backend_arg_mask(const struct vmod_shard_backend_arg * const a) shard_backend_arg_mask(const struct VARGS(shard_backend) * const a)
{ {
return (tobit(a, by) | return (tobit(a, by) |
tobit(a, key) | tobit(a, key) |
...@@ -511,7 +511,7 @@ shard_backend_arg_mask(const struct vmod_shard_backend_arg * const a) ...@@ -511,7 +511,7 @@ shard_backend_arg_mask(const struct vmod_shard_backend_arg * const a)
tobit(a, resolve)); tobit(a, resolve));
} }
static uint32_t static uint32_t
shard_param_set_mask(const struct vmod_shard_param_set_arg * const a) shard_param_set_mask(const struct VARGS(shard_param_set) * const a)
{ {
return (tobit(a, by) | return (tobit(a, by) |
tobit(a, key) | tobit(a, key) |
...@@ -640,7 +640,7 @@ shard_param_args(VRT_CTX, ...@@ -640,7 +640,7 @@ shard_param_args(VRT_CTX,
VCL_BACKEND v_matchproto_(td_directors_shard_backend) VCL_BACKEND v_matchproto_(td_directors_shard_backend)
vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard, vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
struct vmod_shard_backend_arg *a) struct VARGS(shard_backend) *a)
{ {
struct vmod_directors_shard_param pstk; struct vmod_directors_shard_param pstk;
struct vmod_directors_shard_param *pp = NULL; struct vmod_directors_shard_param *pp = NULL;
...@@ -884,7 +884,7 @@ shard_param_prep(VRT_CTX, struct vmod_directors_shard_param *p, ...@@ -884,7 +884,7 @@ shard_param_prep(VRT_CTX, struct vmod_directors_shard_param *p,
VCL_VOID v_matchproto_(td_directors_shard_param_set) VCL_VOID v_matchproto_(td_directors_shard_param_set)
vmod_shard_param_set(VRT_CTX, struct vmod_directors_shard_param *p, vmod_shard_param_set(VRT_CTX, struct vmod_directors_shard_param *p,
struct vmod_shard_param_set_arg *a) struct VARGS(shard_param_set) *a)
{ {
uint32_t args = shard_param_set_mask(a); uint32_t args = shard_param_set_mask(a);
......
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