Fossil SCM

factored out an extraneous parameter to json_gc_add().

stephan 2011-10-09 12:58 UTC json-multitag-test
Commit 7a83a5cbd0424cefa2cdc001de60153aede530f5
3 files changed +1 -1 +22 -17 +2 -2
+1 -1
--- src/cgi.c
+++ src/cgi.c
@@ -743,11 +743,11 @@
743743
contentLen ? cson_data_source_FILE_n : cson_data_source_FILE,
744744
contentLen ? (void *)&state : (void *)zIn, NULL, NULL );
745745
if(rc){
746746
goto invalidRequest;
747747
}else{
748
- json_gc_add( "POST.JSON", jv, 1 );
748
+ json_gc_add( "POST.JSON", jv );
749749
g.json.post.v = jv;
750750
g.json.post.o = cson_value_get_object( jv );
751751
if( !g.json.post.o ){ /* we don't support non-Object (Array) requests */
752752
goto invalidRequest;
753753
}
754754
--- src/cgi.c
+++ src/cgi.c
@@ -743,11 +743,11 @@
743 contentLen ? cson_data_source_FILE_n : cson_data_source_FILE,
744 contentLen ? (void *)&state : (void *)zIn, NULL, NULL );
745 if(rc){
746 goto invalidRequest;
747 }else{
748 json_gc_add( "POST.JSON", jv, 1 );
749 g.json.post.v = jv;
750 g.json.post.o = cson_value_get_object( jv );
751 if( !g.json.post.o ){ /* we don't support non-Object (Array) requests */
752 goto invalidRequest;
753 }
754
--- src/cgi.c
+++ src/cgi.c
@@ -743,11 +743,11 @@
743 contentLen ? cson_data_source_FILE_n : cson_data_source_FILE,
744 contentLen ? (void *)&state : (void *)zIn, NULL, NULL );
745 if(rc){
746 goto invalidRequest;
747 }else{
748 json_gc_add( "POST.JSON", jv );
749 g.json.post.v = jv;
750 g.json.post.o = cson_value_get_object( jv );
751 if( !g.json.post.o ){ /* we don't support non-Object (Array) requests */
752 goto invalidRequest;
753 }
754
+22 -17
--- src/json.c
+++ src/json.c
@@ -344,34 +344,40 @@
344344
return buf;
345345
}
346346
347347
/*
348348
** Adds v to the API-internal cleanup mechanism. key is ingored
349
-** (legacy). If freeOnError is true then v is passed to
350
-** cson_value_free() if the key cannot be inserted, otherweise
351
-** ownership of v is not changed on error. Failure to insert an item
352
-** may be caused by any of the following:
349
+** (legacy) but might be re-introduced and "should" be a unique
350
+** (app-wide) value. Failure to insert an item may be caused by any
351
+** of the following:
353352
**
354353
** - Allocation error.
355354
** - g.json.gc.a is NULL
356355
** - key is NULL or empty.
357356
**
358357
** Returns 0 on success.
359358
**
360
-** On success, ownership of v is transfered to (or shared with)
361
-** g.json.gc, and v will be valid until that object is cleaned up or
362
-** some internal code incorrectly removes it from the gc (which we
363
-** never do).
359
+** Ownership of v is transfered to (or shared with) g.json.gc, and v
360
+** will be valid until that object is cleaned up or some internal code
361
+** incorrectly removes it from the gc (which we never do). If this
362
+** function fails, it is fatal to the app (as it indicates an
363
+** allocation error (more likely than not) or a serious internal error
364
+** such as numeric overflow).
364365
*/
365
-int json_gc_add( char const * key, cson_value * v, char freeOnError ){
366
+void json_gc_add( char const * key, cson_value * v ){
366367
int const rc = cson_array_append( g.json.gc.a, v );
367368
assert( NULL != g.json.gc.a );
368
- if( (0 != rc) && freeOnError ){
369
+ if( 0 != rc ){
369370
cson_value_free( v );
370371
}
371372
assert( (0==rc) && "Adding item to GC failed." );
372
- return rc;
373
+ if(0!=rc){
374
+ fprintf(stderr,"%s: FATAL: alloc error.\n", fossil_nameofexe());
375
+ fossil_exit(1)/*not fossil_panic() b/c it might land us somewhere
376
+ where this function is called again.
377
+ */;
378
+ }
373379
}
374380
375381
376382
/*
377383
** Returns the value of json_rc_cstr(code) as a new JSON
@@ -761,13 +767,12 @@
761767
*/
762768
char const * zCookie = P(login_cookie_name());
763769
if( zCookie && *zCookie ){
764770
/* Transfer fossil's cookie to JSON for downstream convenience... */
765771
cson_value * v = cson_value_new_string(zCookie, strlen(zCookie));
766
- if(0 == json_gc_add( FossilJsonKeys.authToken, v, 1 )){
767
- g.json.authToken = v;
768
- }
772
+ json_gc_add( FossilJsonKeys.authToken, v );
773
+ g.json.authToken = v;
769774
}
770775
}
771776
}
772777
return g.json.authToken;
773778
}
@@ -822,11 +827,11 @@
822827
being of type string).
823828
*/
824829
v = cson_value_new_object();
825830
g.json.param.v = v;
826831
g.json.param.o = cson_value_get_object(v);
827
- json_gc_add("$PARAMS", v, 1);
832
+ json_gc_add("$PARAMS", v);
828833
}
829834
830835
/*
831836
** Appends a warning object to the (pending) JSON response.
832837
**
@@ -857,11 +862,11 @@
857862
&& "Invalid warning code.");
858863
if(!g.json.warnings.v){
859864
g.json.warnings.v = cson_value_new_array();
860865
assert((NULL != g.json.warnings.v) && "Alloc error.");
861866
g.json.warnings.a = cson_value_get_array(g.json.warnings.v);
862
- json_gc_add("$WARNINGS",g.json.warnings.v,0);
867
+ json_gc_add("$WARNINGS",g.json.warnings.v);
863868
}
864869
obj = cson_new_object();
865870
cson_array_append(g.json.warnings.a, cson_object_value(obj));
866871
cson_object_set(obj,"code",cson_value_new_integer(code));
867872
if(fmt && *fmt){
@@ -1044,11 +1049,11 @@
10441049
#endif
10451050
}
10461051
10471052
g.json.cmd.v = cson_value_new_array();
10481053
g.json.cmd.a = cson_value_get_array(g.json.cmd.v);
1049
- json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v, 1 );
1054
+ json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v );
10501055
/*
10511056
The following if/else block translates the PATH_INFO path (in
10521057
CLI/server modes) or g.argv (CLI mode) into an internal list so
10531058
that we can simplify command dispatching later on.
10541059
10551060
--- src/json.c
+++ src/json.c
@@ -344,34 +344,40 @@
344 return buf;
345 }
346
347 /*
348 ** Adds v to the API-internal cleanup mechanism. key is ingored
349 ** (legacy). If freeOnError is true then v is passed to
350 ** cson_value_free() if the key cannot be inserted, otherweise
351 ** ownership of v is not changed on error. Failure to insert an item
352 ** may be caused by any of the following:
353 **
354 ** - Allocation error.
355 ** - g.json.gc.a is NULL
356 ** - key is NULL or empty.
357 **
358 ** Returns 0 on success.
359 **
360 ** On success, ownership of v is transfered to (or shared with)
361 ** g.json.gc, and v will be valid until that object is cleaned up or
362 ** some internal code incorrectly removes it from the gc (which we
363 ** never do).
 
 
364 */
365 int json_gc_add( char const * key, cson_value * v, char freeOnError ){
366 int const rc = cson_array_append( g.json.gc.a, v );
367 assert( NULL != g.json.gc.a );
368 if( (0 != rc) && freeOnError ){
369 cson_value_free( v );
370 }
371 assert( (0==rc) && "Adding item to GC failed." );
372 return rc;
 
 
 
 
 
373 }
374
375
376 /*
377 ** Returns the value of json_rc_cstr(code) as a new JSON
@@ -761,13 +767,12 @@
761 */
762 char const * zCookie = P(login_cookie_name());
763 if( zCookie && *zCookie ){
764 /* Transfer fossil's cookie to JSON for downstream convenience... */
765 cson_value * v = cson_value_new_string(zCookie, strlen(zCookie));
766 if(0 == json_gc_add( FossilJsonKeys.authToken, v, 1 )){
767 g.json.authToken = v;
768 }
769 }
770 }
771 }
772 return g.json.authToken;
773 }
@@ -822,11 +827,11 @@
822 being of type string).
823 */
824 v = cson_value_new_object();
825 g.json.param.v = v;
826 g.json.param.o = cson_value_get_object(v);
827 json_gc_add("$PARAMS", v, 1);
828 }
829
830 /*
831 ** Appends a warning object to the (pending) JSON response.
832 **
@@ -857,11 +862,11 @@
857 && "Invalid warning code.");
858 if(!g.json.warnings.v){
859 g.json.warnings.v = cson_value_new_array();
860 assert((NULL != g.json.warnings.v) && "Alloc error.");
861 g.json.warnings.a = cson_value_get_array(g.json.warnings.v);
862 json_gc_add("$WARNINGS",g.json.warnings.v,0);
863 }
864 obj = cson_new_object();
865 cson_array_append(g.json.warnings.a, cson_object_value(obj));
866 cson_object_set(obj,"code",cson_value_new_integer(code));
867 if(fmt && *fmt){
@@ -1044,11 +1049,11 @@
1044 #endif
1045 }
1046
1047 g.json.cmd.v = cson_value_new_array();
1048 g.json.cmd.a = cson_value_get_array(g.json.cmd.v);
1049 json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v, 1 );
1050 /*
1051 The following if/else block translates the PATH_INFO path (in
1052 CLI/server modes) or g.argv (CLI mode) into an internal list so
1053 that we can simplify command dispatching later on.
1054
1055
--- src/json.c
+++ src/json.c
@@ -344,34 +344,40 @@
344 return buf;
345 }
346
347 /*
348 ** Adds v to the API-internal cleanup mechanism. key is ingored
349 ** (legacy) but might be re-introduced and "should" be a unique
350 ** (app-wide) value. Failure to insert an item may be caused by any
351 ** of the following:
 
352 **
353 ** - Allocation error.
354 ** - g.json.gc.a is NULL
355 ** - key is NULL or empty.
356 **
357 ** Returns 0 on success.
358 **
359 ** Ownership of v is transfered to (or shared with) g.json.gc, and v
360 ** will be valid until that object is cleaned up or some internal code
361 ** incorrectly removes it from the gc (which we never do). If this
362 ** function fails, it is fatal to the app (as it indicates an
363 ** allocation error (more likely than not) or a serious internal error
364 ** such as numeric overflow).
365 */
366 void json_gc_add( char const * key, cson_value * v ){
367 int const rc = cson_array_append( g.json.gc.a, v );
368 assert( NULL != g.json.gc.a );
369 if( 0 != rc ){
370 cson_value_free( v );
371 }
372 assert( (0==rc) && "Adding item to GC failed." );
373 if(0!=rc){
374 fprintf(stderr,"%s: FATAL: alloc error.\n", fossil_nameofexe());
375 fossil_exit(1)/*not fossil_panic() b/c it might land us somewhere
376 where this function is called again.
377 */;
378 }
379 }
380
381
382 /*
383 ** Returns the value of json_rc_cstr(code) as a new JSON
@@ -761,13 +767,12 @@
767 */
768 char const * zCookie = P(login_cookie_name());
769 if( zCookie && *zCookie ){
770 /* Transfer fossil's cookie to JSON for downstream convenience... */
771 cson_value * v = cson_value_new_string(zCookie, strlen(zCookie));
772 json_gc_add( FossilJsonKeys.authToken, v );
773 g.json.authToken = v;
 
774 }
775 }
776 }
777 return g.json.authToken;
778 }
@@ -822,11 +827,11 @@
827 being of type string).
828 */
829 v = cson_value_new_object();
830 g.json.param.v = v;
831 g.json.param.o = cson_value_get_object(v);
832 json_gc_add("$PARAMS", v);
833 }
834
835 /*
836 ** Appends a warning object to the (pending) JSON response.
837 **
@@ -857,11 +862,11 @@
862 && "Invalid warning code.");
863 if(!g.json.warnings.v){
864 g.json.warnings.v = cson_value_new_array();
865 assert((NULL != g.json.warnings.v) && "Alloc error.");
866 g.json.warnings.a = cson_value_get_array(g.json.warnings.v);
867 json_gc_add("$WARNINGS",g.json.warnings.v);
868 }
869 obj = cson_new_object();
870 cson_array_append(g.json.warnings.a, cson_object_value(obj));
871 cson_object_set(obj,"code",cson_value_new_integer(code));
872 if(fmt && *fmt){
@@ -1044,11 +1049,11 @@
1049 #endif
1050 }
1051
1052 g.json.cmd.v = cson_value_new_array();
1053 g.json.cmd.a = cson_value_get_array(g.json.cmd.v);
1054 json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v );
1055 /*
1056 The following if/else block translates the PATH_INFO path (in
1057 CLI/server modes) or g.argv (CLI mode) into an internal list so
1058 that we can simplify command dispatching later on.
1059
1060
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -61,11 +61,11 @@
6161
cson_value * v = NULL;
6262
Stmt q;
6363
static cson_value * eventTypeLabel = NULL;
6464
if(!eventTypeLabel){
6565
eventTypeLabel = json_new_string("checkin");
66
- json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel, 1);
66
+ json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel);
6767
}
6868
zParent = db_text(0,
6969
"SELECT uuid FROM plink, blob"
7070
" WHERE plink.cid=%d AND blob.rid=plink.pid AND plink.isprim",
7171
rid
@@ -167,11 +167,11 @@
167167
g.json.resultCode = FSL_JSON_E_DENIED;
168168
return NULL;
169169
}
170170
if(!eventTypeLabel){
171171
eventTypeLabel = json_new_string("ticket");
172
- json_gc_add("$EVENT_TYPE_LABEL(ticket)", eventTypeLabel, 1);
172
+ json_gc_add("$EVENT_TYPE_LABEL(ticket)", eventTypeLabel);
173173
}
174174
175175
pTktChng = manifest_get(rid, CFTYPE_TICKET);
176176
if( pTktChng==0 ){
177177
g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED;
178178
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -61,11 +61,11 @@
61 cson_value * v = NULL;
62 Stmt q;
63 static cson_value * eventTypeLabel = NULL;
64 if(!eventTypeLabel){
65 eventTypeLabel = json_new_string("checkin");
66 json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel, 1);
67 }
68 zParent = db_text(0,
69 "SELECT uuid FROM plink, blob"
70 " WHERE plink.cid=%d AND blob.rid=plink.pid AND plink.isprim",
71 rid
@@ -167,11 +167,11 @@
167 g.json.resultCode = FSL_JSON_E_DENIED;
168 return NULL;
169 }
170 if(!eventTypeLabel){
171 eventTypeLabel = json_new_string("ticket");
172 json_gc_add("$EVENT_TYPE_LABEL(ticket)", eventTypeLabel, 1);
173 }
174
175 pTktChng = manifest_get(rid, CFTYPE_TICKET);
176 if( pTktChng==0 ){
177 g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED;
178
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -61,11 +61,11 @@
61 cson_value * v = NULL;
62 Stmt q;
63 static cson_value * eventTypeLabel = NULL;
64 if(!eventTypeLabel){
65 eventTypeLabel = json_new_string("checkin");
66 json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel);
67 }
68 zParent = db_text(0,
69 "SELECT uuid FROM plink, blob"
70 " WHERE plink.cid=%d AND blob.rid=plink.pid AND plink.isprim",
71 rid
@@ -167,11 +167,11 @@
167 g.json.resultCode = FSL_JSON_E_DENIED;
168 return NULL;
169 }
170 if(!eventTypeLabel){
171 eventTypeLabel = json_new_string("ticket");
172 json_gc_add("$EVENT_TYPE_LABEL(ticket)", eventTypeLabel);
173 }
174
175 pTktChng = manifest_get(rid, CFTYPE_TICKET);
176 if( pTktChng==0 ){
177 g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED;
178

Keyboard Shortcuts

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