1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

autofree: free references

This commit is contained in:
Alexander Medvednikov 2021-09-18 04:19:16 +03:00
parent 44ec8a8cd4
commit 6d47dd22df
2 changed files with 18 additions and 1 deletions

View File

@ -3204,7 +3204,9 @@ fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int
fn (mut g Gen) autofree_variable(v ast.Var) { fn (mut g Gen) autofree_variable(v ast.Var) {
sym := g.table.get_type_symbol(v.typ) sym := g.table.get_type_symbol(v.typ)
// if v.name.contains('output2') { // if v.name.contains('output2') {
if g.is_autofree {
// eprintln(' > var name: ${v.name:-20s} | is_arg: ${v.is_arg.str():6} | var type: ${int(v.typ):8} | type_name: ${sym.name:-33s}') // eprintln(' > var name: ${v.name:-20s} | is_arg: ${v.is_arg.str():6} | var type: ${int(v.typ):8} | type_name: ${sym.name:-33s}')
}
// } // }
if sym.kind == .array { if sym.kind == .array {
if sym.has_method('free') { if sym.has_method('free') {
@ -3241,6 +3243,8 @@ fn (mut g Gen) autofree_variable(v ast.Var) {
} }
if sym.has_method('free') { if sym.has_method('free') {
g.autofree_var_call(c_name(sym.name) + '_free', v) g.autofree_var_call(c_name(sym.name) + '_free', v)
} else if v.typ.is_real_pointer() {
g.autofree_var_call('free', v)
} }
} }

View File

@ -0,0 +1,13 @@
struct User {
name string
age int
}
fn simple() {
user := &User{'Bob', 31}
println('done')
}
fn main() {
simple()
}