@@ -5869,14 +5869,14 @@ fn (mut g Gen) write_init_function() {
5869
5869
// ignore v.reflection already initialized above
5870
5870
continue
5871
5871
}
5872
- mut is_empty := true
5872
+ mut const_section_header_shown := false
5873
5873
// write globals and consts init later
5874
5874
for var_name in g.sorted_global_const_names {
5875
5875
if var := g.global_const_defs[var_name] {
5876
5876
if var.mod == mod_name && var.init.len > 0 {
5877
- if is_empty {
5878
- is_empty = false
5879
- g. writeln ( ' \t // Initializations for module ${mod_name} ' )
5877
+ if ! const_section_header_shown {
5878
+ g. writeln ( ' \t // Initializations of consts for module ${mod_name} ' )
5879
+ const_section_header_shown = true
5880
5880
}
5881
5881
g.writeln (var.init)
5882
5882
}
@@ -5885,12 +5885,21 @@ fn (mut g Gen) write_init_function() {
5885
5885
init_fn_name := '${mod_name} .init'
5886
5886
if initfn := g.table.find_fn (init_fn_name) {
5887
5887
if initfn.return_type == ast.void_type && initfn.params.len == 0 {
5888
- if is_empty {
5889
- g.writeln ('\t // Initializations for module ${mod_name} ' )
5888
+ mut should_be_skipped := false
5889
+ if initfn.source_fn != unsafe { nil } {
5890
+ fndecl := unsafe { & ast.FnDecl (initfn.source_fn) }
5891
+ if fndecl.should_be_skipped {
5892
+ should_be_skipped = fndecl.should_be_skipped
5893
+ }
5894
+ }
5895
+ if should_be_skipped {
5896
+ g.writeln ('\t // Skipping fn init() for module ${mod_name} ' )
5897
+ } else {
5898
+ g.writeln ('\t // Calling fn init() for module ${mod_name} ' )
5899
+ mod_c_name := util.no_dots (mod_name)
5900
+ init_fn_c_name := '${mod_c_name} __init'
5901
+ g.writeln ('\t ${init_fn_c_name} ();' )
5890
5902
}
5891
- mod_c_name := util.no_dots (mod_name)
5892
- init_fn_c_name := '${mod_c_name} __init'
5893
- g.writeln ('\t ${init_fn_c_name} ();' )
5894
5903
}
5895
5904
}
5896
5905
cleanup_fn_name := '${mod_name} .cleanup'
0 commit comments