mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Fix #3250
This commit is contained in:
@@ -365,8 +365,10 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
|
|||||||
opt_write_start(w, opt, '{') or_return
|
opt_write_start(w, opt, '{') or_return
|
||||||
|
|
||||||
for name, i in info.names {
|
for name, i in info.names {
|
||||||
|
json_name := reflect.struct_tag_get(reflect.Struct_Tag(info.tags[i]), "json")
|
||||||
|
|
||||||
opt_write_iteration(w, opt, i) or_return
|
opt_write_iteration(w, opt, i) or_return
|
||||||
if json_name := string(reflect.struct_tag_get(auto_cast info.tags[i], "json")); json_name != "" {
|
if json_name != "" {
|
||||||
opt_write_key(w, opt, json_name) or_return
|
opt_write_key(w, opt, json_name) or_return
|
||||||
} else {
|
} else {
|
||||||
opt_write_key(w, opt, name) or_return
|
opt_write_key(w, opt, name) or_return
|
||||||
|
|||||||
@@ -204,8 +204,8 @@ parse_array :: proc(p: ^Parser) -> (value: Value, err: Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
bytes_make :: proc(size, alignment: int, allocator: mem.Allocator) -> (bytes: []byte, err: Error) {
|
bytes_make :: proc(size, alignment: int, allocator: mem.Allocator, loc := #caller_location) -> (bytes: []byte, err: Error) {
|
||||||
b, berr := mem.alloc_bytes(size, alignment, allocator)
|
b, berr := mem.alloc_bytes(size, alignment, allocator, loc)
|
||||||
if berr != nil {
|
if berr != nil {
|
||||||
if berr == .Out_Of_Memory {
|
if berr == .Out_Of_Memory {
|
||||||
err = .Out_Of_Memory
|
err = .Out_Of_Memory
|
||||||
@@ -217,9 +217,9 @@ bytes_make :: proc(size, alignment: int, allocator: mem.Allocator) -> (bytes: []
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
clone_string :: proc(s: string, allocator: mem.Allocator) -> (str: string, err: Error) {
|
clone_string :: proc(s: string, allocator: mem.Allocator, loc := #caller_location) -> (str: string, err: Error) {
|
||||||
n := len(s)
|
n := len(s)
|
||||||
b := bytes_make(n+1, 1, allocator) or_return
|
b := bytes_make(n+1, 1, allocator, loc) or_return
|
||||||
copy(b, s)
|
copy(b, s)
|
||||||
if len(b) > n {
|
if len(b) > n {
|
||||||
b[n] = 0
|
b[n] = 0
|
||||||
@@ -290,7 +290,7 @@ parse_object :: proc(p: ^Parser) -> (value: Value, err: Error) {
|
|||||||
|
|
||||||
|
|
||||||
// IMPORTANT NOTE(bill): unquote_string assumes a mostly valid string
|
// IMPORTANT NOTE(bill): unquote_string assumes a mostly valid string
|
||||||
unquote_string :: proc(token: Token, spec: Specification, allocator := context.allocator) -> (value: string, err: Error) {
|
unquote_string :: proc(token: Token, spec: Specification, allocator := context.allocator, loc := #caller_location) -> (value: string, err: Error) {
|
||||||
get_u2_rune :: proc(s: string) -> rune {
|
get_u2_rune :: proc(s: string) -> rune {
|
||||||
if len(s) < 4 || s[0] != '\\' || s[1] != 'x' {
|
if len(s) < 4 || s[0] != '\\' || s[1] != 'x' {
|
||||||
return -1
|
return -1
|
||||||
@@ -359,7 +359,7 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a
|
|||||||
i += w
|
i += w
|
||||||
}
|
}
|
||||||
if i == len(s) {
|
if i == len(s) {
|
||||||
return clone_string(s, allocator)
|
return clone_string(s, allocator, loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
b := bytes_make(len(s) + 2*utf8.UTF_MAX, 1, allocator) or_return
|
b := bytes_make(len(s) + 2*utf8.UTF_MAX, 1, allocator) or_return
|
||||||
|
|||||||
@@ -411,6 +411,12 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm
|
|||||||
continue struct_loop
|
continue struct_loop
|
||||||
} else {
|
} else {
|
||||||
// allows skipping unused struct fields
|
// allows skipping unused struct fields
|
||||||
|
|
||||||
|
// NOTE(bill): prevent possible memory leak if a string is unquoted
|
||||||
|
allocator := p.allocator
|
||||||
|
defer p.allocator = allocator
|
||||||
|
p.allocator = mem.nil_allocator()
|
||||||
|
|
||||||
parse_value(p) or_return
|
parse_value(p) or_return
|
||||||
if parse_comma(p) {
|
if parse_comma(p) {
|
||||||
break struct_loop
|
break struct_loop
|
||||||
|
|||||||
Reference in New Issue
Block a user