From: drh <> Date: Fri, 29 Sep 2023 16:37:22 +0000 (+0000) Subject: Additional refactoring and cleanup. X-Git-Tag: version-3.45.0~116^2~133 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a99e2fb576d793299a18a47f62330d3093a7a36e;p=thirdparty%2Fsqlite.git Additional refactoring and cleanup. FossilOrigin-Name: 45dd1760875b1ad899a10189c6f5a0a9a0677903794fb5a06ffacd39952a7882 --- diff --git a/manifest b/manifest index 7fcd2bd9c7..8a5c90e20d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\scomments\sand\sprocedure\snames\sfor\sclarity\sin\sthe\sJSON\nimplementation. -D 2023-09-29T12:45:14.794 +C Additional\srefactoring\sand\scleanup. +D 2023-09-29T16:37:22.006 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -670,7 +670,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 92d7c2ea8db842cd6a7a7b664bf43d5ae75e097981f001a5ab3860bd222132ca +F src/json.c d7de85731741831d299cfd76520f6af7e72b3b175f3cbfe22d0454e8abbb6090 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40 @@ -2123,8 +2123,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c0cba3461d6111b3aeb77726880221f1240355f0b57e060febbdeb12fb688c0 -R d73ce77d34a070de20c2504f2815e166 +P 9b620d813ef483f1277c1683c5e926a882f07f3b90804dea0c91b325ff8e45a4 +R bcca84e0a588bc606d4e22707cc86ed4 U drh -Z 100adbc30a124e4f2d5cc09bea6ade0f +Z 4c6f8cb9c19d993b3edfba11c172dd33 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7f67a4ccc1..9118fea8e8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9b620d813ef483f1277c1683c5e926a882f07f3b90804dea0c91b325ff8e45a4 \ No newline at end of file +45dd1760875b1ad899a10189c6f5a0a9a0677903794fb5a06ffacd39952a7882 \ No newline at end of file diff --git a/src/json.c b/src/json.c index 97a6aebf4e..b381e7b28e 100644 --- a/src/json.c +++ b/src/json.c @@ -2657,7 +2657,7 @@ static int jsonIs4HexB(const char *z, int *pOp){ ** -4 ',' seen ** -5 ':' seen */ -static int jsonParseValueB(JsonParse *pParse, u32 i){ +static int jsonTranslateTextValueToBlob(JsonParse *pParse, u32 i){ char c; u32 j; u32 iThis, iStart; @@ -2677,7 +2677,7 @@ json_parse_restart: iStart = pParse->nBlob; for(j=i+1;;j++){ u32 iBlob = pParse->nBlob; - x = jsonParseValueB(pParse, j); + x = jsonTranslateTextValueToBlob(pParse, j); if( x<=0 ){ int op; if( x==(-2) ){ @@ -2723,7 +2723,7 @@ json_parse_restart: goto parse_object_value; } } - x = jsonParseValueB(pParse, j); + x = jsonTranslateTextValueToBlob(pParse, j); if( x!=(-5) ){ if( x!=(-1) ) pParse->iErr = j; return -1; @@ -2731,7 +2731,7 @@ json_parse_restart: j = pParse->iErr+1; } parse_object_value: - x = jsonParseValueB(pParse, j); + x = jsonTranslateTextValueToBlob(pParse, j); if( x<=0 ){ if( x!=(-1) ) pParse->iErr = j; return -1; @@ -2750,7 +2750,7 @@ json_parse_restart: break; } } - x = jsonParseValueB(pParse, j); + x = jsonTranslateTextValueToBlob(pParse, j); if( x==(-4) ){ j = pParse->iErr; continue; @@ -2780,7 +2780,7 @@ json_parse_restart: return -1; } for(j=i+1;;j++){ - x = jsonParseValueB(pParse, j); + x = jsonTranslateTextValueToBlob(pParse, j); if( x<=0 ){ if( x==(-3) ){ j = pParse->iErr; @@ -2804,7 +2804,7 @@ json_parse_restart: break; } } - x = jsonParseValueB(pParse, j); + x = jsonTranslateTextValueToBlob(pParse, j); if( x==(-4) ){ j = pParse->iErr; continue; @@ -3117,13 +3117,13 @@ json_parse_restart: ** pParse must be initialized to an empty parse object prior to calling ** this routine. */ -static int jsonParseB( +static int jsonConvertTextToBlob( JsonParse *pParse, /* Initialize and fill this JsonParse object */ sqlite3_context *pCtx /* Report errors here */ ){ int i; const char *zJson = pParse->zJson; - i = jsonParseValueB(pParse, 0); + i = jsonTranslateTextValueToBlob(pParse, 0); if( pParse->oom ) i = -1; if( i>0 ){ assert( pParse->iDepth==0 ); @@ -4089,6 +4089,25 @@ static void jsonTest1Func( UNUSED_PARAMETER(argc); sqlite3_result_int(ctx, sqlite3_value_subtype(argv[0])==JSON_SUBTYPE); } + +/* SQL Function: jsonb_test2(BLOB_JSON) +** +** Render BLOB_JSON back into text. +** Development testing only. +*/ +static void jsonbTest2( + sqlite3_context *ctx, + int argc, + sqlite3_value **argv +){ + const u8 *aBlob; + int nBlob; + UNUSED_PARAMETER(argc); + + aBlob = (const u8*)sqlite3_value_blob(argv[0]); + nBlob = sqlite3_value_bytes(argv[0]); + jsonReturnTextJsonFromBlob(ctx, aBlob, nBlob); +} #endif /* SQLITE_DEBUG */ /**************************************************************************** @@ -4134,7 +4153,7 @@ static void jsonbFunc( memset(&x, 0, sizeof(x)); x.zJson = (char*)zJson; x.nJson = nJson; - if( jsonParseB(pParse, ctx) ){ + if( jsonConvertTextToBlob(pParse, ctx) ){ sqlite3_result_error(ctx, "malformed JSON", -1); }else{ sqlite3_result_blob(ctx, pParse->aBlob, pParse->nBlob, sqlite3_free); @@ -4146,25 +4165,6 @@ static void jsonbFunc( } } -/* SQL Function: jsonb_test2(BLOB_JSON) -** -** Render BLOB_JSON back into text. -** Development testing only. -*/ -static void jsonbTest2( - sqlite3_context *ctx, - int argc, - sqlite3_value **argv -){ - const u8 *aBlob; - int nBlob; - UNUSED_PARAMETER(argc); - - aBlob = (const u8*)sqlite3_value_blob(argv[0]); - nBlob = sqlite3_value_bytes(argv[0]); - jsonReturnTextJsonFromBlob(ctx, aBlob, nBlob); -} - /* ** Implementation of the json_quote(VALUE) function. Return a JSON value ** corresponding to the SQL value input. Mostly this means putting @@ -5549,36 +5549,35 @@ static sqlite3_module jsonTreeModule = { void sqlite3RegisterJsonFunctions(void){ #ifndef SQLITE_OMIT_JSON static FuncDef aJsonFunc[] = { - JFUNCTION(json, 1, 0, jsonRemoveFunc), - JFUNCTION(json_array, -1, 0, jsonArrayFunc), - JFUNCTION(json_array_length, 1, 0, jsonArrayLengthFunc), - JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc), - JFUNCTION(json_error_position,1, 0, jsonErrorFunc), - JFUNCTION(json_extract, -1, 0, jsonExtractFunc), - JFUNCTION(jsonb_extract, -1, JSON_BLOB, jsonExtractFunc), - JFUNCTION(->, 2, JSON_JSON, jsonExtractFunc), - JFUNCTION(->>, 2, JSON_SQL, jsonExtractFunc), - JFUNCTION(json_insert, -1, 0, jsonSetFunc), - JFUNCTION(json_object, -1, 0, jsonObjectFunc), - JFUNCTION(json_patch, 2, 0, jsonPatchFunc), - JFUNCTION(json_quote, 1, 0, jsonQuoteFunc), - JFUNCTION(json_remove, -1, 0, jsonRemoveFunc), - JFUNCTION(json_replace, -1, 0, jsonReplaceFunc), - JFUNCTION(json_set, -1, JSON_ISSET, jsonSetFunc), - JFUNCTION(json_type, 1, 0, jsonTypeFunc), - JFUNCTION(json_type, 2, 0, jsonTypeFunc), - JFUNCTION(json_valid, 1, 0, jsonValidFunc), - JFUNCTION(jsonb, 1, JSON_BLOB, jsonbFunc), - JFUNCTION(jsonb_test2, 1, 0, jsonbTest2), - JFUNCTION(jsonb_insert, -1, JSON_BLOB, jsonSetFunc), - JFUNCTION(jsonb_patch, 2, JSON_BLOB, jsonPatchFunc), - JFUNCTION(jsonb_quote, 1, JSON_BLOB, jsonQuoteFunc), - JFUNCTION(jsonb_remove, -1, JSON_BLOB, jsonRemoveFunc), - JFUNCTION(jsonb_replace, -1, JSON_BLOB, jsonReplaceFunc), + JFUNCTION(json, 1, 0, jsonRemoveFunc), + JFUNCTION(jsonb, 1, JSON_BLOB, jsonbFunc), + JFUNCTION(json_array, -1, 0, jsonArrayFunc), + JFUNCTION(json_array_length, 1, 0, jsonArrayLengthFunc), + JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc), + JFUNCTION(json_error_position,1, 0, jsonErrorFunc), + JFUNCTION(json_extract, -1, 0, jsonExtractFunc), + JFUNCTION(jsonb_extract, -1, JSON_BLOB, jsonExtractFunc), + JFUNCTION(->, 2, JSON_JSON, jsonExtractFunc), + JFUNCTION(->>, 2, JSON_SQL, jsonExtractFunc), + JFUNCTION(json_insert, -1, 0, jsonSetFunc), + JFUNCTION(jsonb_insert, -1, JSON_BLOB, jsonSetFunc), + JFUNCTION(json_object, -1, 0, jsonObjectFunc), + JFUNCTION(json_patch, 2, 0, jsonPatchFunc), + JFUNCTION(jsonb_patch, 2, JSON_BLOB, jsonPatchFunc), + JFUNCTION(json_quote, 1, 0, jsonQuoteFunc), + JFUNCTION(json_remove, -1, 0, jsonRemoveFunc), + JFUNCTION(jsonb_remove, -1, JSON_BLOB, jsonRemoveFunc), + JFUNCTION(json_replace, -1, 0, jsonReplaceFunc), + JFUNCTION(jsonb_replace, -1, JSON_BLOB, jsonReplaceFunc), + JFUNCTION(json_set, -1, JSON_ISSET, jsonSetFunc), JFUNCTION(jsonb_set, -1, JSON_ISSET|JSON_BLOB, jsonSetFunc), + JFUNCTION(json_type, 1, 0, jsonTypeFunc), + JFUNCTION(json_type, 2, 0, jsonTypeFunc), + JFUNCTION(json_valid, 1, 0, jsonValidFunc), #if SQLITE_DEBUG - JFUNCTION(json_parse, 1, 0, jsonParseFunc), - JFUNCTION(json_test1, 1, 0, jsonTest1Func), + JFUNCTION(json_parse, 1, 0, jsonParseFunc), + JFUNCTION(json_test1, 1, 0, jsonTest1Func), + JFUNCTION(jsonb_test2, 1, 0, jsonbTest2), #endif WAGGREGATE(json_group_array, 1, 0, 0, jsonArrayStep, jsonArrayFinal, jsonArrayValue, jsonGroupInverse,