free strings
parent
d1b732cbcc
commit
3a8cdadcf5
|
@ -1018,6 +1018,9 @@ fn (p mut Parser) close_scope() {
|
|||
if v.typ.starts_with('array_') {
|
||||
p.genln('v_array_free($v.name); // close_scope free')
|
||||
}
|
||||
else if v.typ == 'string' {
|
||||
p.genln('v_string_free($v.name); // close_scope free')
|
||||
}
|
||||
else {
|
||||
p.genln('free($v.name); // close_scope free')
|
||||
}
|
||||
|
@ -1839,6 +1842,7 @@ fn (p mut Parser) index_expr(typ string, fn_ph int) string {
|
|||
p.gen(']/*r$typ $v.is_mut*/')
|
||||
}
|
||||
}
|
||||
// TODO move this from index_expr()
|
||||
// TODO if p.tok in ...
|
||||
// if p.tok in [.assign, .plus_assign, .minus_assign]
|
||||
if p.tok == .assign || p.tok == .plus_assign || p.tok == .minus_assign ||
|
||||
|
@ -2335,6 +2339,7 @@ fn (p mut Parser) string_expr() {
|
|||
return
|
||||
}
|
||||
// tmp := p.get_tmp()
|
||||
p.is_alloc = true // $ interpolation means there's allocation
|
||||
mut args := '"'
|
||||
mut format := '"'
|
||||
p.fgen('\'')
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
module builtin
|
||||
|
||||
// V strings are not null-terminated.
|
||||
struct string {
|
||||
mut:
|
||||
hash_cache int
|
||||
|
@ -25,7 +24,8 @@ fn C.strlen(s byteptr) int
|
|||
|
||||
fn todo() { }
|
||||
|
||||
// Converts a C string to a V string
|
||||
// Converts a C string to a V string.
|
||||
// String data is reused, not copied.
|
||||
pub fn tos(s byteptr, len int) string {
|
||||
// This should never happen.
|
||||
if isnil(s) {
|
||||
|
@ -48,6 +48,7 @@ pub fn tos_clone(s byteptr) string {
|
|||
}
|
||||
|
||||
// Same as `tos`, but calculates the length. Called by `string(bytes)` casts.
|
||||
// Used only internally.
|
||||
fn tos2(s byteptr) string {
|
||||
if isnil(s) {
|
||||
panic('tos2: nil string')
|
||||
|
@ -730,7 +731,7 @@ pub fn (c byte) is_letter() bool {
|
|||
}
|
||||
|
||||
pub fn (s string) free() {
|
||||
C.free(s.str)
|
||||
free(s.str)
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue