mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
parent
f2c281eadf
commit
a66c4c9340
2 changed files with 12 additions and 2 deletions
10
vlib/json/tests/json_decode_arr_ref_test.v
Normal file
10
vlib/json/tests/json_decode_arr_ref_test.v
Normal file
|
@ -0,0 +1,10 @@
|
|||
import json
|
||||
|
||||
struct Test {
|
||||
a string
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
x := json.decode([]&Test, '[{"a":"a"}]') or { exit(1) }
|
||||
assert x[0].a == 'a'
|
||||
}
|
|
@ -1021,7 +1021,7 @@ fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size
|
|||
s = '${styp} val = ${fn_name}((cJSON *)jsval); '
|
||||
} else if is_array_fixed_val {
|
||||
s = '
|
||||
${result_name}_${styp} val2 = ${fn_name} ((cJSON *)jsval);
|
||||
${result_name}_${styp.replace('*', '_ptr')} val2 = ${fn_name} ((cJSON *)jsval);
|
||||
if(val2.is_error) {
|
||||
${array_free_str}
|
||||
return *(${result_name}_${ret_styp}*)&val2;
|
||||
|
@ -1030,7 +1030,7 @@ fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size
|
|||
memcpy(&val, (${styp}*)val2.data, sizeof(${styp}));'
|
||||
} else {
|
||||
s = '
|
||||
${result_name}_${styp} val2 = ${fn_name} ((cJSON *)jsval);
|
||||
${result_name}_${styp.replace('*', '_ptr')} val2 = ${fn_name} ((cJSON *)jsval);
|
||||
if(val2.is_error) {
|
||||
${array_free_str}
|
||||
return *(${result_name}_${ret_styp}*)&val2;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue