ci: fix failing -Werror steps for code generated by json.encode(map{'a': []string{}})
parent
f7a8a460f6
commit
7bbcf02134
|
@ -11,9 +11,23 @@ module json
|
||||||
struct C.cJSON {
|
struct C.cJSON {
|
||||||
valueint int
|
valueint int
|
||||||
valuedouble f32
|
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 {
|
pub fn decode(typ voidptr, s string) ?voidptr {
|
||||||
// compiler implementation
|
// compiler implementation
|
||||||
return 0
|
return 0
|
||||||
|
@ -108,23 +122,9 @@ fn decode_string(root &C.cJSON) string {
|
||||||
}
|
}
|
||||||
// println('decode string valuestring="$root.valuestring"')
|
// println('decode string valuestring="$root.valuestring"')
|
||||||
// return tos(root.valuestring, _strlen(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 {
|
fn decode_bool(root &C.cJSON) bool {
|
||||||
if isnil(root) {
|
if isnil(root) {
|
||||||
return false
|
return false
|
||||||
|
@ -178,24 +178,24 @@ fn encode_bool(val bool) &C.cJSON {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_string(val string) &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))
|
// user := decode_User(json_parse(js_string_var))
|
||||||
fn json_parse(s string) &C.cJSON {
|
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))
|
// 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(s, C.strlen(s)) }
|
return unsafe { tos(byteptr(s), C.strlen(s)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
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(s, C.strlen(s)) }
|
return unsafe { tos(byteptr(s), C.strlen(s)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// / cjson wrappers
|
// / cjson wrappers
|
||||||
|
|
|
@ -50,7 +50,7 @@ $dec_fn_dec {
|
||||||
if (error_ptr != NULL) {
|
if (error_ptr != NULL) {
|
||||||
// fprintf(stderr, "Error in decode() for $styp error_ptr=: %s\\n", error_ptr);
|
// fprintf(stderr, "Error in decode() for $styp error_ptr=: %s\\n", error_ptr);
|
||||||
// printf("\\nbad js=%%s\\n", js.str);
|
// 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)
|
fn_name := js_dec_name(styp)
|
||||||
mut s := ''
|
mut s := ''
|
||||||
if is_js_prim(styp) {
|
if is_js_prim(styp) {
|
||||||
s = '$styp val = ${fn_name}(jsval); '
|
s = '$styp val = ${fn_name}((cJSON *)jsval); '
|
||||||
} else {
|
} else {
|
||||||
s = '
|
s = '
|
||||||
Option_$styp val2 = $fn_name (jsval);
|
Option_$styp val2 = $fn_name ((cJSON *)jsval);
|
||||||
if(val2.state != 0) {
|
if(val2.state != 0) {
|
||||||
array_free(&res);
|
array_free(&res);
|
||||||
return *(Option_Array_$styp*)&val2;
|
return *(Option_Array_$styp*)&val2;
|
||||||
|
@ -224,7 +224,7 @@ fn (mut g Gen) decode_array(value_type table.Type) string {
|
||||||
}
|
}
|
||||||
return '
|
return '
|
||||||
if(root && !cJSON_IsArray(root) && !cJSON_IsNull(root)) {
|
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));
|
res = __new_array(0, 0, sizeof($styp));
|
||||||
const cJSON *jsval = NULL;
|
const cJSON *jsval = NULL;
|
||||||
|
@ -268,14 +268,14 @@ fn (mut g Gen) decode_map(key_type table.Type, value_type table.Type) string {
|
||||||
}
|
}
|
||||||
return '
|
return '
|
||||||
if(!cJSON_IsObject(root) && !cJSON_IsNull(root)) {
|
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);
|
res = new_map_2(sizeof($styp), sizeof($styp_v), $hash_fn, $key_eq_fn, $clone_fn, $free_fn);
|
||||||
cJSON *jsval = NULL;
|
cJSON *jsval = NULL;
|
||||||
cJSON_ArrayForEach(jsval, root)
|
cJSON_ArrayForEach(jsval, root)
|
||||||
{
|
{
|
||||||
$s
|
$s
|
||||||
string key = tos2( (byteptr) jsval->string );
|
string key = tos2((byteptr)jsval->string);
|
||||||
map_set_1(&res, &key, &val);
|
map_set_1(&res, &key, &val);
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
|
|
Loading…
Reference in New Issue