mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: use C.cJSON_free, for freeing the intermediate result in json_print and json_print_pretty (#15029)
This commit is contained in:
parent
16a6972e2a
commit
d12a8aef68
@ -28,6 +28,8 @@ fn C.cJSON_PrintUnformatted(&C.cJSON) &char
|
|||||||
|
|
||||||
fn C.cJSON_Print(&C.cJSON) &char
|
fn C.cJSON_Print(&C.cJSON) &char
|
||||||
|
|
||||||
|
fn C.cJSON_free(voidptr)
|
||||||
|
|
||||||
pub fn decode(typ voidptr, s string) ?voidptr {
|
pub fn decode(typ voidptr, s string) ?voidptr {
|
||||||
// compiler implementation
|
// compiler implementation
|
||||||
return 0
|
return 0
|
||||||
@ -215,12 +217,16 @@ fn json_parse(s string) &C.cJSON {
|
|||||||
// json_string := json_print(encode_User(user))
|
// json_string := json_print(encode_User(user))
|
||||||
fn json_print(json &C.cJSON) string {
|
fn json_print(json &C.cJSON) string {
|
||||||
s := C.cJSON_PrintUnformatted(json)
|
s := C.cJSON_PrintUnformatted(json)
|
||||||
return unsafe { tos(&u8(s), C.strlen(&char(s))) }
|
r := unsafe { tos_clone(&u8(s)) }
|
||||||
|
C.cJSON_free(s)
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_print_pretty(json &C.cJSON) string {
|
fn json_print_pretty(json &C.cJSON) string {
|
||||||
s := C.cJSON_Print(json)
|
s := C.cJSON_Print(json)
|
||||||
return unsafe { tos(&u8(s), C.strlen(&char(s))) }
|
r := unsafe { tos_clone(&u8(s)) }
|
||||||
|
C.cJSON_free(s)
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// / cjson wrappers
|
// / cjson wrappers
|
||||||
|
Loading…
x
Reference in New Issue
Block a user