Fossil SCM
Minor interal json refactoring made possible by recent cson changes.
Commit
e40e79b7ab7b9f0fa6f85f95f97d5ae514c142de
Parent
cde55bd7a3dc7c5…
2 files changed
+8
-9
+1
-4
+8
-9
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -872,18 +872,17 @@ | ||
| 872 | 872 | void json_warn( int code, char const * fmt, ... ){ |
| 873 | 873 | cson_object * obj = NULL; |
| 874 | 874 | assert( (code>FSL_JSON_W_START) |
| 875 | 875 | && (code<FSL_JSON_W_END) |
| 876 | 876 | && "Invalid warning code."); |
| 877 | - if(!g.json.warnings.v){ | |
| 878 | - g.json.warnings.v = cson_value_new_array(); | |
| 879 | - assert((NULL != g.json.warnings.v) && "Alloc error."); | |
| 880 | - g.json.warnings.a = cson_value_get_array(g.json.warnings.v); | |
| 881 | - json_gc_add("$WARNINGS",g.json.warnings.v); | |
| 877 | + if(!g.json.warnings){ | |
| 878 | + g.json.warnings = cson_new_array(); | |
| 879 | + assert((NULL != g.json.warnings) && "Alloc error."); | |
| 880 | + json_gc_add("$WARNINGS",cson_array_value(g.json.warnings)); | |
| 882 | 881 | } |
| 883 | 882 | obj = cson_new_object(); |
| 884 | - cson_array_append(g.json.warnings.a, cson_object_value(obj)); | |
| 883 | + cson_array_append(g.json.warnings, cson_object_value(obj)); | |
| 885 | 884 | cson_object_set(obj,"code",cson_value_new_integer(code)); |
| 886 | 885 | if(fmt && *fmt){ |
| 887 | 886 | /* FIXME: treat NULL fmt as standard warning message for |
| 888 | 887 | the code, but we don't have those yet. |
| 889 | 888 | */ |
| @@ -1445,11 +1444,11 @@ | ||
| 1445 | 1444 | CSTR(g.json, jsonp); |
| 1446 | 1445 | VAL(gc, g.json.gc.v); |
| 1447 | 1446 | VAL(cmd, g.json.cmd.v); |
| 1448 | 1447 | VAL(param, g.json.param.v); |
| 1449 | 1448 | VAL(POST, g.json.post.v); |
| 1450 | - VAL(warnings, g.json.warnings.v); | |
| 1449 | + VAL(warnings, cson_array_value(g.json.warnings)); | |
| 1451 | 1450 | /*cson_output_opt outOpt;*/ |
| 1452 | 1451 | |
| 1453 | 1452 | |
| 1454 | 1453 | #undef INT |
| 1455 | 1454 | #undef CSTR |
| @@ -1558,12 +1557,12 @@ | ||
| 1558 | 1557 | /* i'm actually seeing sub-ms runtimes in some tests, but a time of |
| 1559 | 1558 | 0 is "just wrong", so we'll bump that up to 1ms. |
| 1560 | 1559 | */ |
| 1561 | 1560 | cson_object_set(o,"procTimeMs", cson_value_new_integer((cson_int_t)((span>1.0)?span:1))); |
| 1562 | 1561 | } |
| 1563 | - if(g.json.warnings.v){ | |
| 1564 | - tmp = g.json.warnings.v; | |
| 1562 | + if(g.json.warnings){ | |
| 1563 | + tmp = cson_array_value(g.json.warnings); | |
| 1565 | 1564 | SET("warnings"); |
| 1566 | 1565 | } |
| 1567 | 1566 | |
| 1568 | 1567 | /* Only add the payload to SUCCESS responses. Else delete it. */ |
| 1569 | 1568 | if( NULL != payload ){ |
| 1570 | 1569 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -872,18 +872,17 @@ | |
| 872 | void json_warn( int code, char const * fmt, ... ){ |
| 873 | cson_object * obj = NULL; |
| 874 | assert( (code>FSL_JSON_W_START) |
| 875 | && (code<FSL_JSON_W_END) |
| 876 | && "Invalid warning code."); |
| 877 | if(!g.json.warnings.v){ |
| 878 | g.json.warnings.v = cson_value_new_array(); |
| 879 | assert((NULL != g.json.warnings.v) && "Alloc error."); |
| 880 | g.json.warnings.a = cson_value_get_array(g.json.warnings.v); |
| 881 | json_gc_add("$WARNINGS",g.json.warnings.v); |
| 882 | } |
| 883 | obj = cson_new_object(); |
| 884 | cson_array_append(g.json.warnings.a, cson_object_value(obj)); |
| 885 | cson_object_set(obj,"code",cson_value_new_integer(code)); |
| 886 | if(fmt && *fmt){ |
| 887 | /* FIXME: treat NULL fmt as standard warning message for |
| 888 | the code, but we don't have those yet. |
| 889 | */ |
| @@ -1445,11 +1444,11 @@ | |
| 1445 | CSTR(g.json, jsonp); |
| 1446 | VAL(gc, g.json.gc.v); |
| 1447 | VAL(cmd, g.json.cmd.v); |
| 1448 | VAL(param, g.json.param.v); |
| 1449 | VAL(POST, g.json.post.v); |
| 1450 | VAL(warnings, g.json.warnings.v); |
| 1451 | /*cson_output_opt outOpt;*/ |
| 1452 | |
| 1453 | |
| 1454 | #undef INT |
| 1455 | #undef CSTR |
| @@ -1558,12 +1557,12 @@ | |
| 1558 | /* i'm actually seeing sub-ms runtimes in some tests, but a time of |
| 1559 | 0 is "just wrong", so we'll bump that up to 1ms. |
| 1560 | */ |
| 1561 | cson_object_set(o,"procTimeMs", cson_value_new_integer((cson_int_t)((span>1.0)?span:1))); |
| 1562 | } |
| 1563 | if(g.json.warnings.v){ |
| 1564 | tmp = g.json.warnings.v; |
| 1565 | SET("warnings"); |
| 1566 | } |
| 1567 | |
| 1568 | /* Only add the payload to SUCCESS responses. Else delete it. */ |
| 1569 | if( NULL != payload ){ |
| 1570 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -872,18 +872,17 @@ | |
| 872 | void json_warn( int code, char const * fmt, ... ){ |
| 873 | cson_object * obj = NULL; |
| 874 | assert( (code>FSL_JSON_W_START) |
| 875 | && (code<FSL_JSON_W_END) |
| 876 | && "Invalid warning code."); |
| 877 | if(!g.json.warnings){ |
| 878 | g.json.warnings = cson_new_array(); |
| 879 | assert((NULL != g.json.warnings) && "Alloc error."); |
| 880 | json_gc_add("$WARNINGS",cson_array_value(g.json.warnings)); |
| 881 | } |
| 882 | obj = cson_new_object(); |
| 883 | cson_array_append(g.json.warnings, cson_object_value(obj)); |
| 884 | cson_object_set(obj,"code",cson_value_new_integer(code)); |
| 885 | if(fmt && *fmt){ |
| 886 | /* FIXME: treat NULL fmt as standard warning message for |
| 887 | the code, but we don't have those yet. |
| 888 | */ |
| @@ -1445,11 +1444,11 @@ | |
| 1444 | CSTR(g.json, jsonp); |
| 1445 | VAL(gc, g.json.gc.v); |
| 1446 | VAL(cmd, g.json.cmd.v); |
| 1447 | VAL(param, g.json.param.v); |
| 1448 | VAL(POST, g.json.post.v); |
| 1449 | VAL(warnings, cson_array_value(g.json.warnings)); |
| 1450 | /*cson_output_opt outOpt;*/ |
| 1451 | |
| 1452 | |
| 1453 | #undef INT |
| 1454 | #undef CSTR |
| @@ -1558,12 +1557,12 @@ | |
| 1557 | /* i'm actually seeing sub-ms runtimes in some tests, but a time of |
| 1558 | 0 is "just wrong", so we'll bump that up to 1ms. |
| 1559 | */ |
| 1560 | cson_object_set(o,"procTimeMs", cson_value_new_integer((cson_int_t)((span>1.0)?span:1))); |
| 1561 | } |
| 1562 | if(g.json.warnings){ |
| 1563 | tmp = cson_array_value(g.json.warnings); |
| 1564 | SET("warnings"); |
| 1565 | } |
| 1566 | |
| 1567 | /* Only add the payload to SUCCESS responses. Else delete it. */ |
| 1568 | if( NULL != payload ){ |
| 1569 |
+1
-4
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -245,14 +245,11 @@ | ||
| 245 | 245 | } param; |
| 246 | 246 | struct { |
| 247 | 247 | cson_value * v; |
| 248 | 248 | cson_object * o; |
| 249 | 249 | } reqPayload; /* request payload object (if any) */ |
| 250 | - struct { /* response warnings */ | |
| 251 | - cson_value * v; | |
| 252 | - cson_array * a; | |
| 253 | - } warnings; | |
| 250 | + cson_array * warnings; /* response warnings */ | |
| 254 | 251 | } json; |
| 255 | 252 | #endif /* FOSSIL_ENABLE_JSON */ |
| 256 | 253 | }; |
| 257 | 254 | |
| 258 | 255 | /* |
| 259 | 256 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -245,14 +245,11 @@ | |
| 245 | } param; |
| 246 | struct { |
| 247 | cson_value * v; |
| 248 | cson_object * o; |
| 249 | } reqPayload; /* request payload object (if any) */ |
| 250 | struct { /* response warnings */ |
| 251 | cson_value * v; |
| 252 | cson_array * a; |
| 253 | } warnings; |
| 254 | } json; |
| 255 | #endif /* FOSSIL_ENABLE_JSON */ |
| 256 | }; |
| 257 | |
| 258 | /* |
| 259 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -245,14 +245,11 @@ | |
| 245 | } param; |
| 246 | struct { |
| 247 | cson_value * v; |
| 248 | cson_object * o; |
| 249 | } reqPayload; /* request payload object (if any) */ |
| 250 | cson_array * warnings; /* response warnings */ |
| 251 | } json; |
| 252 | #endif /* FOSSIL_ENABLE_JSON */ |
| 253 | }; |
| 254 | |
| 255 | /* |
| 256 |