cgen: parametrize g_str_buf size by V_STRBUF_MB; free in _vcleanup()

pull/5586/head
Delyan Angelov 2020-06-30 16:30:02 +03:00
parent 55989b3c2c
commit af56b01a41
1 changed files with 5 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import v.pref
import v.token import v.token
import v.util import v.util
import v.depgraph import v.depgraph
import os
// NB: keywords after 'new' are reserved in C++ // NB: keywords after 'new' are reserved in C++
const ( const (
@ -2762,8 +2763,9 @@ fn (mut g Gen) write_init_function() {
} }
if g.pref.autofree { if g.pref.autofree {
// Pre-allocate the string buffer // Pre-allocate the string buffer
// TODO make it configurable s_str_buf_size := os.getenv('V_STRBUF_MB')
g.writeln('g_str_buf = malloc(1024 * 1000);') mb_size := if s_str_buf_size == '' { 1 } else { s_str_buf_size.int() }
g.writeln('g_str_buf = malloc( ${mb_size} * 1024 * 1000 );')
} }
g.writeln('\tbuiltin_init();') g.writeln('\tbuiltin_init();')
g.writeln('\tvinit_string_literals();') g.writeln('\tvinit_string_literals();')
@ -2785,6 +2787,7 @@ fn (mut g Gen) write_init_function() {
g.writeln('void _vcleanup() {') g.writeln('void _vcleanup() {')
// g.writeln('puts("cleaning up...");') // g.writeln('puts("cleaning up...");')
g.writeln(g.cleanups.str()) g.writeln(g.cleanups.str())
g.writeln('\tfree(g_str_buf);')
g.writeln('}') g.writeln('}')
if g.pref.printfn_list.len > 0 && '_vcleanup' in g.pref.printfn_list { if g.pref.printfn_list.len > 0 && '_vcleanup' in g.pref.printfn_list {
println(g.out.after(fn_vcleanup_start_pos)) println(g.out.after(fn_vcleanup_start_pos))