varnish-cache
varnish-cache copied to clipboard
vmod function/method name clash
As demonstrated with this patch
diff --git a/vmod/vmod_debug.vcc b/vmod/vmod_debug.vcc
index df8ba6247..310a046bb 100644
--- a/vmod/vmod_debug.vcc
+++ b/vmod/vmod_debug.vcc
@@ -69,6 +69,8 @@ $Function STRING test_priv_top(PRIV_TOP, STRING)
Test function for TOP private pointers
+$Function VOID obj_enum(ENUM { phk, des, kristian, mithrandir, martin })
+
$Object obj(STRING string="default", ENUM { one, two, three } number=one)
Test object
we do not support a function called obj.name with a method name for class obj.
Compiler error:
/usr/local/bin/python3.10 ../lib/libvcc/vmodtool.py --boilerplate -o vcc_debug_if ./vmod_debug.vcc
WARNING: Not emitting .RST for $Event event_function
WARNING: Not emitting .RST for $Event event_function
CC libvmod_debug_la-vcc_debug_if.lo
In file included from vcc_debug_if.c:10:
./vcc_debug_if.h:94:10: error: conflicting types for 'xyzzy_obj_enum'
VCL_VOID xyzzy_obj_enum(VRT_CTX, struct VPFX(debug_obj) *,
^
./vcc_debug_if.h:89:10: note: previous declaration is here
VCL_VOID xyzzy_obj_enum(VRT_CTX, VCL_ENUM);
^
vcc_debug_if.c:128:18: error: typedef redefinition with different types ('VCL_VOID (const struct vrt_ctx *, VCL_ENUM)' (aka 'void (const struct vrt_ctx *, const char *)') vs 'VCL_VOID (const struct vrt_ctx *, struct xyzzy_debug_obj *, VCL_ENUM)' (aka 'void (const struct vrt_ctx *, struct xyzzy_debug_obj *, const char *)'))
typedef VCL_VOID td_xyzzy_debug_obj_enum(VRT_CTX, VCL_ENUM);
^
vcc_debug_if.c:32:18: note: previous definition is here
typedef VCL_VOID td_xyzzy_debug_obj_enum(VRT_CTX,
^
vcc_debug_if.c:201:28: error: duplicate member 'obj_enum'
td_xyzzy_debug_obj_enum *obj_enum;
^
vcc_debug_if.c:198:28: note: previous declaration is here
td_xyzzy_debug_obj_enum *obj_enum;
^
3 errors generated.
make: *** [Makefile:1154: libvmod_debug_la-vcc_debug_if.lo] Error 1
suggestion: rename methods to obj__method (two underscores) and blacklist underscore as prefix/suffix for object/method/function names.
After looking into this, I think the suggested extra underscore should work on principle. Valid VCL symbols can't start with an underscore, so VMOD symbols can't either. See VCT_invalid_name() in varnishd and "Illegal name" in vmodtool.
Options discussed during bugwash:
- have vmodtool detect the clash and use the double underscore only if a clash exists.
- Expand
VPFX()intoVPFX_FUNCTION()andVPFX_METHOD()- do not want macro proliferation
- have
$Prefix_functionand$Prefix_methodin the vcc file
- Expand
- enable overriding the default cname as in
$Function VOID obj_enum(ENUM { phk, des, kristian, mithrandir, martin }) $cname=obj__enum
I will play with it...