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 @@
-emacro(845, HTTPH) // Info 845: The left argument to operator '&&' is certain to be 0
-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
//////////////
......
......@@ -31,6 +31,7 @@ Read the vmod.vcc file (inputvcc) and produce:
vmod_if.h -- Prototypes for the implementation
vmod_if.c -- Magic glue & datastructures to make things a VMOD.
vmod_${name}.rst -- Extracted documentation
vmod_${name}.man.rst -- Extracted documentation (rst2man input)
"""
# This script should work with both Python 2 and Python 3.
......@@ -129,10 +130,14 @@ def unquote(txt):
def fmt_cstruct(fo, a, b):
''' 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:
t += "\t"
fo.write("%s%s\n" % (t, b))
t += '\t'
fo.write('%s%s\n' % (t, b))
#######################################################################
......@@ -430,7 +435,7 @@ class ProtoType(object):
return "typedef " + self.proto(args, name=self.typedef_name())
def argstructname(self):
return "struct %s_arg" % self.cname(True)
return "struct VARGS(%s)" % self.cname(False)
def argstructure(self):
s = "\n" + self.argstructname() + " {\n"
......@@ -471,7 +476,8 @@ class ProtoType(object):
self.retval.jsonproto(ll)
ll.append('%s.%s' % (self.st.vcc.csn, cfunc))
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:
ll.append("")
for i in self.args:
......@@ -662,8 +668,7 @@ class EventStanza(Stanza):
def cstuff(self, fo, where):
if where == 'h':
fo.write("vmod_event_f %s%s;\n" %
(self.vcc.sympfx, self.event_func))
fo.write("vmod_event_f VPFX(%s);\n" % self.event_func)
def cstruct(self, fo, define):
if define:
......@@ -741,7 +746,7 @@ class ObjectStanza(Stanza):
fo.write(' :ref:`%s`\n \n' % i.rstlbl)
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(self.init.cproto(
......@@ -952,8 +957,17 @@ class vcc(object):
fo.write("#endif\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):
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")
for j in self.contents:
......@@ -974,7 +988,7 @@ class vcc(object):
j.cstruct(fo, False)
fo.write("\n")
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")
def json(self, fo):
......@@ -1026,6 +1040,11 @@ class vcc(object):
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 <stdio.h>\n')
for i in ["vdef", "vrt", self.pfx, "vmod_abi"]:
......@@ -1033,7 +1052,7 @@ class vcc(object):
fo.write("\n")
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")
for i in self.contents:
......@@ -1053,6 +1072,10 @@ class vcc(object):
fo.write("\n/*lint -esym(754, " + self.csn + "::*) */\n")
self.cstruct_init(fo)
fx.write('#undef VPFX\n')
fx.write('#undef VARGS\n')
fx.write('#undef VENUM\n')
fx.close()
fo.write("\nstatic const char Vmod_Proto[] =\n")
......
......@@ -118,7 +118,7 @@ static const struct vrt_blob null_blob[1] = {{
static enum encoding
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"
WRONG("illegal encoding enum");
}
......@@ -126,7 +126,7 @@ parse_encoding(VCL_ENUM e)
static enum case_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"
WRONG("illegal case enum");
}
......
......@@ -94,16 +94,16 @@ xyzzy_author(VRT_CTX, VCL_ENUM person, VCL_ENUM someone)
(void)someone;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (person == xyzzy_enum_phk)
if (person == VENUM(phk))
return ("Poul-Henning");
assert(strcmp(person, "phk"));
if (person == xyzzy_enum_des)
if (person == VENUM(des))
return ("Dag-Erling");
assert(strcmp(person, "des"));
if (person == xyzzy_enum_kristian)
if (person == VENUM(kristian))
return ("Kristian");
assert(strcmp(person, "kristian"));
if (person == xyzzy_enum_mithrandir)
if (person == VENUM(mithrandir))
return ("Tollef");
assert(strcmp(person, "mithrandir"));
WRONG("Illegal VMOD enum");
......@@ -194,7 +194,7 @@ xyzzy_rot52(VRT_CTX, VCL_HTTP hp)
}
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];
......
......@@ -157,17 +157,17 @@ xyzzy_obj_test_priv_top(VRT_CTX,
* obj_opt (optional arguments and privs)
*/
struct xyzzy_debug_obj_opt {
unsigned magic;
#define VMOD_DEBUG_OBJ_OPT_MAGIC 0xccbd9b78
char *name;
struct xyzzy_obj_opt_meth_opt_arg args;
void *freeptr;
unsigned magic;
#define VMOD_DEBUG_OBJ_OPT_MAGIC 0xccbd9b78
char *name;
struct VARGS(obj_opt_meth_opt) args;
void *freeptr;
};
VCL_VOID v_matchproto_()
xyzzy_obj_opt__init(VRT_CTX,
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;
......@@ -221,7 +221,7 @@ xyzzy_obj_opt__fini(struct xyzzy_debug_obj_opt **op)
VCL_STRING v_matchproto_()
xyzzy_obj_opt_meth_opt(VRT_CTX,
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(o, VMOD_DEBUG_OBJ_OPT_MAGIC);
......
......@@ -182,7 +182,7 @@ struct vmod_directors_shard {
static enum by_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"
WRONG("illegal by enum");
}
......@@ -190,7 +190,7 @@ parse_by_e(VCL_ENUM e)
static enum healthy_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"
WRONG("illegal healthy enum");
}
......@@ -198,7 +198,7 @@ parse_healthy_e(VCL_ENUM e)
static enum resolve_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"
WRONG("illegal resolve enum");
}
......@@ -343,7 +343,7 @@ vmod_shard_associate(VRT_CTX,
VCL_BOOL v_matchproto_(td_directors_shard_add_backend)
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);
......@@ -361,7 +361,7 @@ vmod_shard_add_backend(VRT_CTX, struct vmod_directors_shard *vshard,
VCL_BOOL v_matchproto_(td_directors_shard_remove_backend)
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_STRING ident = args->valid_ident ? args->ident : NULL;
......@@ -498,7 +498,7 @@ shard_blob_key(VCL_BLOB key_blob)
#define tobit(args, name) ((args)->valid_##name ? arg_##name : 0)
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) |
tobit(a, key) |
......@@ -511,7 +511,7 @@ shard_backend_arg_mask(const struct vmod_shard_backend_arg * const a)
tobit(a, resolve));
}
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) |
tobit(a, key) |
......@@ -640,7 +640,7 @@ shard_param_args(VRT_CTX,
VCL_BACKEND v_matchproto_(td_directors_shard_backend)
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 *pp = NULL;
......@@ -884,7 +884,7 @@ shard_param_prep(VRT_CTX, struct vmod_directors_shard_param *p,
VCL_VOID v_matchproto_(td_directors_shard_param_set)
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);
......
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