diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index b33c15e454..5763725806 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4791,11 +4791,15 @@ fn (mut g Gen) write_init_function() { g.writeln('\t_closure_mtx_init();') } for mod_name in g.table.modules { - g.writeln('\t{ // Initializations for module $mod_name :') + mut is_empty := true // write globals and consts init later for var_name in g.sorted_global_const_names { if var := g.global_const_defs[var_name] { if var.mod == mod_name && var.init.len > 0 { + if is_empty { + is_empty = false + g.writeln('\t// Initializations for module $mod_name') + } g.writeln(var.init) } } @@ -4803,12 +4807,14 @@ fn (mut g Gen) write_init_function() { init_fn_name := '${mod_name}.init' if initfn := g.table.find_fn(init_fn_name) { if initfn.return_type == ast.void_type && initfn.params.len == 0 { + if is_empty { + g.writeln('\t// Initializations for module $mod_name') + } mod_c_name := util.no_dots(mod_name) init_fn_c_name := '${mod_c_name}__init' g.writeln('\t${init_fn_c_name}();') } } - g.writeln('\t}') } g.writeln('}') if g.pref.printfn_list.len > 0 && '_vinit' in g.pref.printfn_list { diff --git a/vlib/v/gen/c/testdata/embed.c.must_have b/vlib/v/gen/c/testdata/embed.c.must_have index 2895e456cd..2ed41aeafd 100644 --- a/vlib/v/gen/c/testdata/embed.c.must_have +++ b/vlib/v/gen/c/testdata/embed.c.must_have @@ -15,5 +15,3 @@ v__embed_file__EmbedFileIndexEntry* v__embed_file__find_index_entry_by_path(void v__embed_file__EmbedFileData my_source = _v_embed_file_metadata( res.path = _SLIT("embed.vv"); - -// Initializations for module v.embed_file : diff --git a/vlib/v/gen/c/testdata/embed_with_prod.c.must_have b/vlib/v/gen/c/testdata/embed_with_prod.c.must_have index 49a997a165..2e6a61f7db 100644 --- a/vlib/v/gen/c/testdata/embed_with_prod.c.must_have +++ b/vlib/v/gen/c/testdata/embed_with_prod.c.must_have @@ -28,5 +28,3 @@ v__embed_file__EmbedFileData my_source = _v_embed_file_metadata( res.path = _SLIT("embed.vv"); res.apath = _SLIT(""); res.uncompressed = v__embed_file__find_index_entry_by_path((voidptr)_v_embed_file_index, _SLIT("embed.vv"), _SLIT("none"))->data; - -// Initializations for module v.embed_file : diff --git a/vlib/v/gen/c/testdata/embed_with_prod_zlib.c.must_have b/vlib/v/gen/c/testdata/embed_with_prod_zlib.c.must_have index 4266f9eb49..0041395e52 100644 --- a/vlib/v/gen/c/testdata/embed_with_prod_zlib.c.must_have +++ b/vlib/v/gen/c/testdata/embed_with_prod_zlib.c.must_have @@ -28,5 +28,3 @@ v__embed_file__EmbedFileData my_source = _v_embed_file_metadata( res.path = _SLIT("embed.vv"); res.apath = _SLIT(""); res.compressed = v__embed_file__find_index_entry_by_path((voidptr)_v_embed_file_index, _SLIT("embed.vv"), _SLIT("zlib"))->data; - -// Initializations for module v.embed_file :