From af56b01a412a4d39af020330518cca10544a4af8 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 30 Jun 2020 16:30:02 +0300 Subject: [PATCH] cgen: parametrize g_str_buf size by V_STRBUF_MB; free in _vcleanup() --- vlib/v/gen/cgen.v | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index c743b5e25b..627ea17918 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -10,6 +10,7 @@ import v.pref import v.token import v.util import v.depgraph +import os // NB: keywords after 'new' are reserved in C++ const ( @@ -2762,8 +2763,9 @@ fn (mut g Gen) write_init_function() { } if g.pref.autofree { // Pre-allocate the string buffer - // TODO make it configurable - g.writeln('g_str_buf = malloc(1024 * 1000);') + s_str_buf_size := os.getenv('V_STRBUF_MB') + 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('\tvinit_string_literals();') @@ -2785,6 +2787,7 @@ fn (mut g Gen) write_init_function() { g.writeln('void _vcleanup() {') // g.writeln('puts("cleaning up...");') g.writeln(g.cleanups.str()) + g.writeln('\tfree(g_str_buf);') g.writeln('}') if g.pref.printfn_list.len > 0 && '_vcleanup' in g.pref.printfn_list { println(g.out.after(fn_vcleanup_start_pos))