Revert "cgen: fix all -Wmissing-variable-declarations (#5802)"

This reverts commit ae349ca6ba.

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).
pull/6163/head
Delyan Angelov 2020-08-18 11:46:12 +03:00
parent 937a3e14c5
commit 2f6757a56a
2 changed files with 5 additions and 5 deletions

View File

@ -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_') {

View File

@ -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();