cgen: when building a shared library, make vinit() a constructor

pull/5153/head
pancake 2020-05-31 17:27:23 +02:00 committed by GitHub
parent 411868a43a
commit 304258162c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -2651,7 +2651,14 @@ fn (mut g Gen) write_init_function() {
return return
} }
fn_vinit_start_pos := g.out.len fn_vinit_start_pos := g.out.len
g.writeln('void _vinit() {') needs_constructor := g.pref.is_shared && g.pref.os != .windows
if needs_constructor {
g.writeln('__attribute__ ((constructor))')
g.writeln('void _vinit() {')
g.writeln('static bool once = false; if (once) {return;} once = true;')
} else {
g.writeln('void _vinit() {')
}
if g.pref.autofree { if g.pref.autofree {
// Pre-allocate the string buffer // Pre-allocate the string buffer
// TODO make it configurable // TODO make it configurable