1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ci: fix failing -Werror steps for code generated by json.encode(map{'a': []string{}})

This commit is contained in:
Delyan Angelov 2021-03-18 11:58:32 +02:00
parent f7a8a460f6
commit 7bbcf02134
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 26 additions and 26 deletions

View File

@ -11,9 +11,23 @@ module json
struct C.cJSON {
valueint int
valuedouble f32
valuestring byteptr
valuestring charptr
}
fn C.cJSON_IsTrue(&C.cJSON) bool
fn C.cJSON_CreateNumber(int) &C.cJSON
fn C.cJSON_CreateBool(bool) &C.cJSON
fn C.cJSON_CreateString(charptr) &C.cJSON
fn C.cJSON_Parse(charptr) &C.cJSON
fn C.cJSON_PrintUnformatted(&C.cJSON) charptr
fn C.cJSON_Print(&C.cJSON) charptr
pub fn decode(typ voidptr, s string) ?voidptr {
// compiler implementation
return 0
@ -108,23 +122,9 @@ fn decode_string(root &C.cJSON) string {
}
// println('decode string valuestring="$root.valuestring"')
// return tos(root.valuestring, _strlen(root.valuestring))
return unsafe { tos_clone(root.valuestring) } // , _strlen(root.valuestring))
return unsafe { tos_clone(byteptr(root.valuestring)) } // , _strlen(root.valuestring))
}
fn C.cJSON_IsTrue(voidptr) bool
fn C.cJSON_CreateNumber(int) &C.cJSON
fn C.cJSON_CreateBool(bool) &C.cJSON
fn C.cJSON_CreateString(charptr) &C.cJSON
fn C.cJSON_Parse(charptr) &C.cJSON
fn C.cJSON_PrintUnformatted(voidptr) byteptr
fn C.cJSON_Print(voidptr) byteptr
fn decode_bool(root &C.cJSON) bool {
if isnil(root) {
return false
@ -178,24 +178,24 @@ fn encode_bool(val bool) &C.cJSON {
}
fn encode_string(val string) &C.cJSON {
return C.cJSON_CreateString(val.str)
return C.cJSON_CreateString(charptr(val.str))
}
// ///////////////////////
// user := decode_User(json_parse(js_string_var))
fn json_parse(s string) &C.cJSON {
return C.cJSON_Parse(s.str)
return C.cJSON_Parse(charptr(s.str))
}
// json_string := json_print(encode_User(user))
fn json_print(json &C.cJSON) string {
s := C.cJSON_PrintUnformatted(json)
return unsafe { tos(s, C.strlen(s)) }
return unsafe { tos(byteptr(s), C.strlen(s)) }
}
fn json_print_pretty(json &C.cJSON) string {
s := C.cJSON_Print(json)
return unsafe { tos(s, C.strlen(s)) }
return unsafe { tos(byteptr(s), C.strlen(s)) }
}
// / cjson wrappers

View File

@ -50,7 +50,7 @@ $dec_fn_dec {
if (error_ptr != NULL) {
// fprintf(stderr, "Error in decode() for $styp error_ptr=: %s\\n", error_ptr);
// printf("\\nbad js=%%s\\n", js.str);
return (Option_$styp){.state = 2,.err = v_error(tos2(error_ptr))};
return (Option_$styp){.state = 2,.err = v_error(tos2((byteptr)error_ptr))};
}
}
')
@ -211,10 +211,10 @@ fn (mut g Gen) decode_array(value_type table.Type) string {
fn_name := js_dec_name(styp)
mut s := ''
if is_js_prim(styp) {
s = '$styp val = ${fn_name}(jsval); '
s = '$styp val = ${fn_name}((cJSON *)jsval); '
} else {
s = '
Option_$styp val2 = $fn_name (jsval);
Option_$styp val2 = $fn_name ((cJSON *)jsval);
if(val2.state != 0) {
array_free(&res);
return *(Option_Array_$styp*)&val2;
@ -224,7 +224,7 @@ fn (mut g Gen) decode_array(value_type table.Type) string {
}
return '
if(root && !cJSON_IsArray(root) && !cJSON_IsNull(root)) {
return (Option_Array_$styp){.state = 2, .err = v_error(string_add(_SLIT("Json element is not an array: "), tos2(cJSON_PrintUnformatted(root))))};
return (Option_Array_$styp){.state = 2, .err = v_error(string_add(_SLIT("Json element is not an array: "), tos2((byteptr)cJSON_PrintUnformatted(root))))};
}
res = __new_array(0, 0, sizeof($styp));
const cJSON *jsval = NULL;
@ -268,14 +268,14 @@ fn (mut g Gen) decode_map(key_type table.Type, value_type table.Type) string {
}
return '
if(!cJSON_IsObject(root) && !cJSON_IsNull(root)) {
return (Option_Map_${styp}_$styp_v){ .state = 2, .err = v_error( string_add(_SLIT("Json element is not an object: "), tos2(cJSON_PrintUnformatted(root))) )};
return (Option_Map_${styp}_$styp_v){ .state = 2, .err = v_error( string_add(_SLIT("Json element is not an object: "), tos2((byteptr)cJSON_PrintUnformatted(root))) )};
}
res = new_map_2(sizeof($styp), sizeof($styp_v), $hash_fn, $key_eq_fn, $clone_fn, $free_fn);
cJSON *jsval = NULL;
cJSON_ArrayForEach(jsval, root)
{
$s
string key = tos2( (byteptr) jsval->string );
string key = tos2((byteptr)jsval->string);
map_set_1(&res, &key, &val);
}
'