From 2f6757a56af3d18eea662e3821f6910615c0000f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 18 Aug 2020 11:46:12 +0300 Subject: [PATCH] Revert "cgen: fix all -Wmissing-variable-declarations (#5802)" This reverts commit ae349ca6ba432e427eb2f81c8bf6d96a524fefa8. Fixing these warnings, unfortunately also means, that hot code (which reloads a shared library during runtime) can not use V constants, because the private static C variables in the shared library will not be initialized by _vinit(), which is only called by the main V program. For example in examples/hot_reload/bounce.v, using `gx.blue`, defined as: ` blue = Color { r: 0, g: 0, b: 255 }` ... will instead use a const with all 0 fields (i.e. a black color). --- vlib/v/gen/cgen.v | 6 +++--- vlib/v/gen/cheaders.v | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index ae5084989c..778f966aed 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -879,7 +879,7 @@ fn (mut g Gen) stmt(node ast.Stmt) { } ast.GlobalDecl { styp := g.typ(node.typ) - g.definitions.writeln('static $styp $node.name; // global') + g.definitions.writeln('$styp $node.name; // global') } ast.GoStmt { g.go_stmt(node) @@ -3201,7 +3201,7 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) { } } ast.StringLiteral { - g.definitions.writeln('static string _const_$name; // a string literal, inited later') + g.definitions.writeln('string _const_$name; // a string literal, inited later') if g.pref.build_mode != .build_module { g.stringliterals.writeln('\t_const_$name = $val;') } @@ -3228,7 +3228,7 @@ fn (mut g Gen) const_decl_init_later(mod, name, val string, typ table.Type) { styp := g.typ(typ) // cname := '_const_$name' - g.definitions.writeln('static $styp $cname; // inited later') + g.definitions.writeln('$styp $cname; // inited later') g.inits[mod].writeln('\t$cname = $val;') if g.pref.autofree { if styp.starts_with('array_') { diff --git a/vlib/v/gen/cheaders.v b/vlib/v/gen/cheaders.v index be88c8b0b7..2fc0735947 100644 --- a/vlib/v/gen/cheaders.v +++ b/vlib/v/gen/cheaders.v @@ -225,7 +225,7 @@ $c_common_macros #endif // g_live_info is used by live.info() -static void* g_live_info = NULL; +void* g_live_info = NULL; //============================== HELPER C MACROS =============================*/ //#define tos4(s, slen) ((string){.str=(s), .len=(slen)}) @@ -265,7 +265,7 @@ static inline bool _us64_lt(uint64_t a, int64_t b) { return a < INT64_MAX && (in //================================== GLOBALS =================================*/ //byte g_str_buf[1024]; -static byte* g_str_buf; +byte* g_str_buf; int load_so(byteptr); void reload_so(); void _vinit();