autofree: free references

pull/11529/head
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) {
sym := g.table.get_type_symbol(v.typ)
// if v.name.contains('output2') {
// 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 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}')
}
// }
if sym.kind == .array {
if sym.has_method('free') {
@ -3241,6 +3243,8 @@ fn (mut g Gen) autofree_variable(v ast.Var) {
}
if sym.has_method('free') {
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()
}