mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: do not free strings in const decls
This commit is contained in:
parent
6dad3cc018
commit
013a4fc0f6
@ -83,7 +83,7 @@ mut:
|
|||||||
attrs []string // attributes before next decl stmt
|
attrs []string // attributes before next decl stmt
|
||||||
is_builtin_mod bool
|
is_builtin_mod bool
|
||||||
hotcode_fn_names []string
|
hotcode_fn_names []string
|
||||||
cur_fn &ast.FnDecl = 0
|
//cur_fn ast.FnDecl
|
||||||
cur_generic_type table.Type // `int`, `string`, etc in `foo<T>()`
|
cur_generic_type table.Type // `int`, `string`, etc in `foo<T>()`
|
||||||
sql_i int
|
sql_i int
|
||||||
sql_stmt_name string
|
sql_stmt_name string
|
||||||
@ -93,6 +93,7 @@ mut:
|
|||||||
strs_to_free string
|
strs_to_free string
|
||||||
inside_call bool
|
inside_call bool
|
||||||
has_main bool
|
has_main bool
|
||||||
|
inside_const bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -2517,6 +2518,11 @@ fn (mut g Gen) return_statement(node ast.Return) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (mut g Gen) const_decl(node ast.ConstDecl) {
|
fn (mut g Gen) const_decl(node ast.ConstDecl) {
|
||||||
|
g.inside_const = true
|
||||||
|
defer {
|
||||||
|
g.inside_const = false
|
||||||
|
}
|
||||||
|
|
||||||
for field in node.fields {
|
for field in node.fields {
|
||||||
name := c_name(field.name)
|
name := c_name(field.name)
|
||||||
// TODO hack. Cut the generated value and paste it into definitions.
|
// TODO hack. Cut the generated value and paste it into definitions.
|
||||||
|
@ -28,6 +28,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
|||||||
g.cur_generic_type = 0
|
g.cur_generic_type = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//g.cur_fn = it
|
||||||
fn_start_pos := g.out.len
|
fn_start_pos := g.out.len
|
||||||
msvc_attrs := g.write_fn_attrs()
|
msvc_attrs := g.write_fn_attrs()
|
||||||
// Live
|
// Live
|
||||||
|
@ -135,7 +135,6 @@ fn (mut g Gen) string_literal(node ast.StringLiteral) {
|
|||||||
// g.write('tos4("$escaped_val", $it.val.len)')
|
// g.write('tos4("$escaped_val", $it.val.len)')
|
||||||
// g.write('_SLIT("$escaped_val")')
|
// g.write('_SLIT("$escaped_val")')
|
||||||
g.write('tos_lit("$escaped_val")')
|
g.write('tos_lit("$escaped_val")')
|
||||||
// g.write('tos_lit("$escaped_val")')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +142,9 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
|
|||||||
mut cur_line := ''
|
mut cur_line := ''
|
||||||
mut tmp := ''
|
mut tmp := ''
|
||||||
free := g.pref.autofree && g.inside_call && !g.inside_return &&
|
free := g.pref.autofree && g.inside_call && !g.inside_return &&
|
||||||
g.inside_ternary == 0 && g.cur_fn != 0 &&
|
g.inside_ternary == 0 && !g.inside_const
|
||||||
g.cur_fn.name != ''
|
//&& g.cur_fn != 0 &&
|
||||||
|
//g.cur_fn.name != ''
|
||||||
if free {
|
if free {
|
||||||
// Save the string expr in a temporary variable, so that it can be removed after the call.
|
// Save the string expr in a temporary variable, so that it can be removed after the call.
|
||||||
tmp = g.new_tmp_var()
|
tmp = g.new_tmp_var()
|
||||||
|
Loading…
Reference in New Issue
Block a user