cgen: implement IError.free() and use it for the builtin `none` const
parent
2e84773ef1
commit
99cc02685b
|
@ -62,3 +62,27 @@ fn opt_ok(data voidptr, mut option Option, size int) {
|
|||
C.memcpy(byteptr(&option.err) + sizeof(IError), data, size)
|
||||
}
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
pub fn (e &Error) free() {
|
||||
unsafe { e.msg.free() }
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
pub fn (n &None__) free() {
|
||||
unsafe { n.msg.free() }
|
||||
}
|
||||
|
||||
[typedef]
|
||||
struct C.IError {
|
||||
_object voidptr
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
pub fn (ie &IError) free() {
|
||||
unsafe {
|
||||
ie.msg.free()
|
||||
cie := &C.IError(ie)
|
||||
C.free(cie._object)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -975,8 +975,9 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) {
|
|||
stmt_pos = stmt.expr.position()
|
||||
}
|
||||
if stmt_pos.pos == 0 {
|
||||
print('autofree: first stmt pos = 0. ')
|
||||
println(stmt.type_name())
|
||||
$if trace_autofree ? {
|
||||
println('autofree: first stmt pos = 0. $stmt.type_name()')
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -4849,6 +4850,8 @@ fn (mut g Gen) const_decl_init_later(mod string, name string, val string, typ ta
|
|||
g.cleanups[mod].writeln('\tstring_free(&$cname);')
|
||||
} else if sym.kind == .map {
|
||||
g.cleanups[mod].writeln('\tmap_free(&$cname);')
|
||||
} else if styp == 'IError' {
|
||||
g.cleanups[mod].writeln('\tIError_free(&$cname);')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue