Fossil SCM

Minor interal json refactoring made possible by recent cson changes.

stephan 2012-07-05 19:24 trunk
Commit e40e79b7ab7b9f0fa6f85f95f97d5ae514c142de
2 files changed +8 -9 +1 -4
+8 -9
--- src/json.c
+++ src/json.c
@@ -872,18 +872,17 @@
872872
void json_warn( int code, char const * fmt, ... ){
873873
cson_object * obj = NULL;
874874
assert( (code>FSL_JSON_W_START)
875875
&& (code<FSL_JSON_W_END)
876876
&& "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));
882881
}
883882
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));
885884
cson_object_set(obj,"code",cson_value_new_integer(code));
886885
if(fmt && *fmt){
887886
/* FIXME: treat NULL fmt as standard warning message for
888887
the code, but we don't have those yet.
889888
*/
@@ -1445,11 +1444,11 @@
14451444
CSTR(g.json, jsonp);
14461445
VAL(gc, g.json.gc.v);
14471446
VAL(cmd, g.json.cmd.v);
14481447
VAL(param, g.json.param.v);
14491448
VAL(POST, g.json.post.v);
1450
- VAL(warnings, g.json.warnings.v);
1449
+ VAL(warnings, cson_array_value(g.json.warnings));
14511450
/*cson_output_opt outOpt;*/
14521451
14531452
14541453
#undef INT
14551454
#undef CSTR
@@ -1558,12 +1557,12 @@
15581557
/* i'm actually seeing sub-ms runtimes in some tests, but a time of
15591558
0 is "just wrong", so we'll bump that up to 1ms.
15601559
*/
15611560
cson_object_set(o,"procTimeMs", cson_value_new_integer((cson_int_t)((span>1.0)?span:1)));
15621561
}
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);
15651564
SET("warnings");
15661565
}
15671566
15681567
/* Only add the payload to SUCCESS responses. Else delete it. */
15691568
if( NULL != payload ){
15701569
--- 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 @@
245245
} param;
246246
struct {
247247
cson_value * v;
248248
cson_object * o;
249249
} 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 */
254251
} json;
255252
#endif /* FOSSIL_ENABLE_JSON */
256253
};
257254
258255
/*
259256
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button