From: drh <> Date: Mon, 9 Oct 2023 18:33:01 +0000 (+0000) Subject: Systematize the names of some of the translation function in the JSON X-Git-Tag: version-3.45.0~116^2~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f32aa3434648a03a308d7251d21a3334664e9fcc;p=thirdparty%2Fsqlite.git Systematize the names of some of the translation function in the JSON implementation. FossilOrigin-Name: db44bd1d62084ef69c808f7d07e0a25d5a089dcb8b98b1b5d026777591bbdefc --- diff --git a/manifest b/manifest index d523129a6f..3959f0c228 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sthe\slatest\strunk\sfixes\sand\senhancements\sinto\sthe\sjsonb\sbranch,\sand\nespecially\sthe\sJSON\scache\sspill\sUAF\sfix. -D 2023-10-09T12:57:03.290 +C Systematize\sthe\snames\sof\ssome\sof\sthe\stranslation\sfunction\sin\sthe\sJSON\nimplementation. +D 2023-10-09T18:33:01.568 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -245,7 +245,7 @@ F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java fde5f758ad170ca45ae00b12194c8ba8d8f3090bd64cc3e002dd9c5e7dff8568 F ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java c0fbfd3779fc92982c7935325a7484dee43eeb80d716989ed31218f453addb94 F ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java 4cb7fc70efd55583fed6033c34a8719da42975ca97ef4781dda0b9f6cc8ec2e8 -F ext/jni/src/org/sqlite/jni/CApi.java c1dde485a3a3f43c46c8d9c527f9ba5bf303fe0409b2c0de253fb7b6e1055f7e w ext/jni/src/org/sqlite/jni/SQLite3Jni.java +F ext/jni/src/org/sqlite/jni/CApi.java c1dde485a3a3f43c46c8d9c527f9ba5bf303fe0409b2c0de253fb7b6e1055f7e F ext/jni/src/org/sqlite/jni/CallbackProxy.java 064a8a00e4c63cc501c30504f93ca996d422c5f010067f969b2d0a10f0868153 F ext/jni/src/org/sqlite/jni/CollationCallback.java 8cf57cb014a645ecc12609eed17308852a597bc5e83d82a4fdb90f7fadc25f9d F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 0c62245e000d5db52576c728cac20f6a31f31f5cf40ca4cbcd64b22964e82ae5 @@ -674,7 +674,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 8717fe7a6461f24ba7b92ccd323c8e2417f44f2a959704c5a05a7aac1ca0df12 +F src/json.c bbf52181d04e09852e273f11cf31544a8030ffc911359cb7f77e39f252cce7a6 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40 @@ -2128,8 +2128,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 cbea16c29eb0507f39b5a1cf744a3bb9bb7c71ac156e84a19d03a37cb1816891 a163fecca90cab9d1b7bf8ebac78d498775eed7b6d81e7920e3401633c3a4b60 -R 1dd322f61ae3b783d06705b01094df38 +P 9422c24f4a8b290dcae61e50ec81be5b314b22c61a2bca1e194e47da1316b6e6 +R 3ec6096d3289810ffc9770092e31c712 U drh -Z 41e410a665a938a0454df231f95bd4b4 +Z 411045c6779d7c6439ce2a3295f7e71a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e2032820b2..533952e38f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9422c24f4a8b290dcae61e50ec81be5b314b22c61a2bca1e194e47da1316b6e6 \ No newline at end of file +db44bd1d62084ef69c808f7d07e0a25d5a089dcb8b98b1b5d026777591bbdefc \ No newline at end of file diff --git a/src/json.c b/src/json.c index d4367324d8..c2b7e39225 100644 --- a/src/json.c +++ b/src/json.c @@ -337,7 +337,7 @@ struct JsonParse { u32 iErr; /* Error location in zJson[] */ u32 iSubst; /* Last JSON_SUBST entry in aNode[] */ u32 iHold; /* Age of this entry in the cache for LRU replacement */ - /* Binary format */ + /* Storage for the binary JSONB format */ u32 nBlob; /* Bytes of aBlob[] actually used */ u32 nBlobAlloc; /* Bytes allocated to aBlob[] */ u8 *aBlob; /* BLOB representation of zJson */ @@ -356,12 +356,12 @@ struct JsonParse { ** Forward references **************************************************************************/ static void jsonReturnStringAsBlob(JsonString*); -static void jsonRenderNodeAsBlob(JsonParse*,JsonNode*,JsonParse*); +static void jsonXlateNodeToBlob(JsonParse*,JsonNode*,JsonParse*); static int jsonParseAddNode(JsonParse*,u32,u32,const char*); -static int jsonParseValueFromBlob(JsonParse *pParse, u32 i); +static int jsonXlateBlobToNode(JsonParse *pParse, u32 i); static int jsonFuncArgMightBeBinary(sqlite3_value *pJson); static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**); -static u32 jsonRenderBlob(JsonParse*,u32,JsonString*); +static u32 jsonXlateBlobToText(JsonParse*,u32,JsonString*); /************************************************************************** ** Utility routines for dealing with JsonString objects @@ -735,7 +735,7 @@ static void jsonAppendSqlValue( memset(&px, 0, sizeof(px)); px.aBlob = (u8*)sqlite3_value_blob(pValue); px.nBlob = sqlite3_value_bytes(pValue); - jsonRenderBlob(&px, 0, p); + jsonXlateBlobToText(&px, 0, p); }else if( p->eErr==0 ){ sqlite3_result_error(p->pCtx, "JSON cannot hold BLOB values", -1); p->eErr = JSTRING_ERR; @@ -868,11 +868,10 @@ static int jsonParseAddCleanup( } /* -** Convert the JsonNode pNode into a pure JSON string and -** append to pOut. Subsubstructure is also included. Return -** the number of JsonNode objects that are encoded. +** Translate the JsonNode pNode into a pure JSON string and +** append that string on pOut. Subsubstructure is also included. */ -static void jsonRenderNodeAsText( +static void jsonXlateNodeToText( JsonParse *pParse, /* the complete parse of the JSON */ JsonNode *pNode, /* The node to render */ JsonString *pOut /* Write JSON here */ @@ -947,7 +946,7 @@ static void jsonRenderNodeAsText( while( j<=pNode->n ){ if( (pNode[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){ jsonAppendSeparator(pOut); - jsonRenderNodeAsText(pParse, &pNode[j], pOut); + jsonXlateNodeToText(pParse, &pNode[j], pOut); } j += jsonNodeSize(&pNode[j]); } @@ -967,9 +966,9 @@ static void jsonRenderNodeAsText( while( j<=pNode->n ){ if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){ jsonAppendSeparator(pOut); - jsonRenderNodeAsText(pParse, &pNode[j], pOut); + jsonXlateNodeToText(pParse, &pNode[j], pOut); jsonAppendChar(pOut, ':'); - jsonRenderNodeAsText(pParse, &pNode[j+1], pOut); + jsonXlateNodeToText(pParse, &pNode[j+1], pOut); } j += 1 + jsonNodeSize(&pNode[j+1]); } @@ -1012,7 +1011,7 @@ static void jsonReturnNodeAsJson( if( flags & JSON_BLOB ){ JsonParse x; memset(&x, 0, sizeof(x)); - jsonRenderNodeAsBlob(pParse, pNode, &x); + jsonXlateNodeToBlob(pParse, pNode, &x); if( x.oom ){ sqlite3_result_error_nomem(pCtx); sqlite3_free(x.aBlob); @@ -1021,7 +1020,7 @@ static void jsonReturnNodeAsJson( } }else{ jsonStringInit(&s, pCtx); - jsonRenderNodeAsText(pParse, pNode, &s); + jsonXlateNodeToText(pParse, pNode, &s); if( bGenerateAlt && pParse->zAlt==0 && jsonForceRCStr(&s) ){ pParse->zAlt = sqlite3RCStrRef(s.zBuf); pParse->nAlt = s.nUsed; @@ -1072,7 +1071,7 @@ static u32 jsonHexToInt4(const char *z){ ** value returned is either RFC-8259 JSON text or a BLOB in the JSONB ** format, depending on the JSON_BLOB flag of the function user-data. */ -static void jsonReturnNodeAsSql( +static void jsonReturnFromNode( JsonParse *pParse, /* Complete JSON parse tree */ JsonNode *pNode, /* Node to return */ sqlite3_context *pCtx /* Return value for this function */ @@ -1510,8 +1509,11 @@ static const struct NanInfName { }; /* -** Parse a single JSON value which begins at pParse->zJson[i]. Return the -** index of the first character past the end of the value parsed. +** Translate a single element of JSON text beginning at pParse->zJson[i] into +** its JsonNode representation. Append the translation onto the +** pParse->aNode[] array, which is increased in size as necessary. +** Return the pJson->zJson[] index of the first character past the end of +** the element that was parsed. ** ** Special return values: ** @@ -1522,7 +1524,7 @@ static const struct NanInfName { ** -4 ',' seen / the index in zJson[] of the seen character ** -5 ':' seen / */ -static int jsonParseValueFromText(JsonParse *pParse, u32 i){ +static int jsonXlateTextToNode(JsonParse *pParse, u32 i){ char c; u32 j; int iThis; @@ -1541,7 +1543,7 @@ json_parse_restart: } for(j=i+1;;j++){ u32 nNode = pParse->nNode; - x = jsonParseValueFromText(pParse, j); + x = jsonXlateTextToNode(pParse, j); if( x<=0 ){ if( x==(-2) ){ j = pParse->iErr; @@ -1584,7 +1586,7 @@ json_parse_restart: goto parse_object_value; } } - x = jsonParseValueFromText(pParse, j); + x = jsonXlateTextToNode(pParse, j); if( x!=(-5) ){ if( x!=(-1) ) pParse->iErr = j; return -1; @@ -1592,7 +1594,7 @@ json_parse_restart: j = pParse->iErr+1; } parse_object_value: - x = jsonParseValueFromText(pParse, j); + x = jsonXlateTextToNode(pParse, j); if( x<=0 ){ if( x!=(-1) ) pParse->iErr = j; return -1; @@ -1611,7 +1613,7 @@ json_parse_restart: break; } } - x = jsonParseValueFromText(pParse, j); + x = jsonXlateTextToNode(pParse, j); if( x==(-4) ){ j = pParse->iErr; continue; @@ -1640,7 +1642,7 @@ json_parse_restart: } memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u)); for(j=i+1;;j++){ - x = jsonParseValueFromText(pParse, j); + x = jsonXlateTextToNode(pParse, j); if( x<=0 ){ if( x==(-3) ){ j = pParse->iErr; @@ -1664,7 +1666,7 @@ json_parse_restart: break; } } - x = jsonParseValueFromText(pParse, j); + x = jsonXlateTextToNode(pParse, j); if( x==(-4) ){ j = pParse->iErr; continue; @@ -2004,9 +2006,9 @@ static int jsonParse( if( pParse->isBinary ){ pParse->aBlob = (u8*)pParse->zJson; pParse->nBlob = pParse->nJson; - i = jsonParseValueFromBlob(pParse, 0); + i = jsonXlateBlobToNode(pParse, 0); }else{ - i = jsonParseValueFromText(pParse, 0); + i = jsonXlateTextToNode(pParse, 0); } if( pParse->oom ) i = -1; if( !pParse->isBinary && i>0 ){ @@ -2679,12 +2681,12 @@ static int jsonIs4HexB(const char *z, int *pOp){ } /* -** Parse a single JSON text value which begins at pParse->zJson[i] into -** its equivalent BLOB representation in pParse->aBlob[]. The parse is -** appended to pParse->aBlob[] beginning at pParse->nBlob. The size of +** Translate a single element of JSON text at pParse->zJson[i] into +** its equivalent binary JSONB representation. Append the translation into +** pParse->aBlob[] beginning at pParse->nBlob. The size of ** pParse->aBlob[] is increased as necessary. ** -** Return the index of the first character past the end of the value parsed, +** Return the index of the first character past the end of the element parsed, ** or one of the following special result codes: ** ** 0 End of input @@ -2694,7 +2696,7 @@ static int jsonIs4HexB(const char *z, int *pOp){ ** -4 ',' seen / the index in zJson[] of the seen character ** -5 ':' seen / */ -static int jsonTranslateTextValueToBlob(JsonParse *pParse, u32 i){ +static int jsonXlateTextToBlob(JsonParse *pParse, u32 i){ char c; u32 j; u32 iThis, iStart; @@ -2714,7 +2716,7 @@ json_parse_restart: iStart = pParse->nBlob; for(j=i+1;;j++){ u32 iBlob = pParse->nBlob; - x = jsonTranslateTextValueToBlob(pParse, j); + x = jsonXlateTextToBlob(pParse, j); if( x<=0 ){ int op; if( x==(-2) ){ @@ -2760,7 +2762,7 @@ json_parse_restart: goto parse_object_value; } } - x = jsonTranslateTextValueToBlob(pParse, j); + x = jsonXlateTextToBlob(pParse, j); if( x!=(-5) ){ if( x!=(-1) ) pParse->iErr = j; return -1; @@ -2768,7 +2770,7 @@ json_parse_restart: j = pParse->iErr+1; } parse_object_value: - x = jsonTranslateTextValueToBlob(pParse, j); + x = jsonXlateTextToBlob(pParse, j); if( x<=0 ){ if( x!=(-1) ) pParse->iErr = j; return -1; @@ -2787,7 +2789,7 @@ json_parse_restart: break; } } - x = jsonTranslateTextValueToBlob(pParse, j); + x = jsonXlateTextToBlob(pParse, j); if( x==(-4) ){ j = pParse->iErr; continue; @@ -2815,7 +2817,7 @@ json_parse_restart: return -1; } for(j=i+1;;j++){ - x = jsonTranslateTextValueToBlob(pParse, j); + x = jsonXlateTextToBlob(pParse, j); if( x<=0 ){ if( x==(-3) ){ j = pParse->iErr; @@ -2839,7 +2841,7 @@ json_parse_restart: break; } } - x = jsonTranslateTextValueToBlob(pParse, j); + x = jsonXlateTextToBlob(pParse, j); if( x==(-4) ){ j = pParse->iErr; continue; @@ -3156,7 +3158,7 @@ static int jsonConvertTextToBlob( ){ int i; const char *zJson = pParse->zJson; - i = jsonTranslateTextValueToBlob(pParse, 0); + i = jsonXlateTextToBlob(pParse, 0); if( pParse->oom ) i = -1; if( i>0 ){ assert( pParse->iDepth==0 ); @@ -3194,7 +3196,7 @@ static void jsonReturnStringAsBlob(JsonString *pStr){ memset(&px, 0, sizeof(px)); px.zJson = pStr->zBuf; px.nJson = pStr->nUsed; - (void)jsonTranslateTextValueToBlob(&px, 0); + (void)jsonXlateTextToBlob(&px, 0); if( px.oom ){ sqlite3_free(px.aBlob); sqlite3_result_error_nomem(pStr->pCtx); @@ -3253,9 +3255,10 @@ static u32 jsonbPayloadSize(JsonParse *pParse, u32 i, u32 *pSz){ /* -** Convert the binary BLOB representation of JSON beginning at -** aBlob[0] and extending for no more than nBlob bytes into -** a pure JSON string. The string is appended to pOut. +** Translate the binary JSONB representation of JSON beginning at +** pParse->aBlob[i] into a JSON text string. Append the JSON +** text onto the end of pOut. Return the index in pParse->aBlob[] +** of the first byte past the end of the element that is translated. ** ** If an error is detected in the BLOB input, the pOut->eErr flag ** might get set to JSTRING_MALFORMED. But not all BLOB input errors @@ -3264,7 +3267,7 @@ static u32 jsonbPayloadSize(JsonParse *pParse, u32 i, u32 *pSz){ ** ** The pOut->eErr JSTRING_OOM flag is set on a OOM. */ -static u32 jsonRenderBlob( +static u32 jsonXlateBlobToText( JsonParse *pParse, /* the complete parse of the JSON */ u32 i, /* Start rendering at this index */ JsonString *pOut /* Write JSON here */ @@ -3403,7 +3406,7 @@ static u32 jsonRenderBlob( j = i+n; iEnd = j+sz; while( j0 ) pOut->nUsed--; @@ -3416,7 +3419,7 @@ static u32 jsonRenderBlob( j = i+n; iEnd = j+sz; while( j0 ) pOut->nUsed--; @@ -3458,14 +3461,13 @@ static int jsonFuncArgMightBeBinary(sqlite3_value *pJson){ return sz+n==(u32)nBlob; } -/* Parse a single element of binary JSON into the legacy Node structure. -** Return the index of the first byte past the end of the binary JSON element. -** -** This routine is a temporary translator while the legacy Node encoding -** is still in use. It will be removed after all processing translates -** to the new BLOB encoding. +/* Translate a single element of JSONB into the JsonNode format. The +** first byte of the element to be translated is at pParse->aBlob[i]. +** Return the index in pParse->aBlob[] of the first byte past the end +** of the JSONB element. Append the JsonNode translation in +** pParse->aNode[], which is increased in size as necessary. */ -static int jsonParseValueFromBlob(JsonParse *pParse, u32 i){ +static int jsonXlateBlobToNode(JsonParse *pParse, u32 i){ u8 t; /* Node type */ u32 sz; /* Node size */ u32 x; /* Index of payload start */ @@ -3535,7 +3537,7 @@ static int jsonParseValueFromBlob(JsonParse *pParse, u32 i){ int iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0); u32 j = i+x; while( joom ){ pParse->aNode[pParse->nNode-1].jnFlags |= JNODE_LABEL; @@ -3569,10 +3571,11 @@ static int jsonParseValueFromBlob(JsonParse *pParse, u32 i){ } /* -** Convert pNode that belongs to pParse into the BLOB representation. -** The BLOB representation is added to the pOut->aBlob[] array. +** Translate pNode (which is always a node found in pParse->aNode[]) into +** the JSONB representation and append the translation onto the end of the +** pOut->aBlob[] array. */ -static void jsonRenderNodeAsBlob( +static void jsonXlateNodeToBlob( JsonParse *pParse, /* the complete parse of the JSON */ JsonNode *pNode, /* The node to render */ JsonParse *pOut /* Write the BLOB rendering of JSON here */ @@ -3661,7 +3664,7 @@ static void jsonRenderNodeAsBlob( for(;;){ while( j<=pNode->n ){ if( (pNode[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){ - jsonRenderNodeAsBlob(pParse, &pNode[j], pOut); + jsonXlateNodeToBlob(pParse, &pNode[j], pOut); } j += jsonNodeSize(&pNode[j]); } @@ -3682,8 +3685,8 @@ static void jsonRenderNodeAsBlob( for(;;){ while( j<=pNode->n ){ if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){ - jsonRenderNodeAsBlob(pParse, &pNode[j], pOut); - jsonRenderNodeAsBlob(pParse, &pNode[j+1], pOut); + jsonXlateNodeToBlob(pParse, &pNode[j], pOut); + jsonXlateNodeToBlob(pParse, &pNode[j+1], pOut); } j += 1 + jsonNodeSize(&pNode[j+1]); } @@ -3850,7 +3853,7 @@ static void jsonReturnTextJsonFromBlob( x.aBlob = (u8*)aBlob; x.nBlob = nBlob; jsonStringInit(&s, ctx); - jsonRenderBlob(&x, 0, &s); + jsonXlateBlobToText(&x, 0, &s); jsonReturnString(&s); } @@ -4431,13 +4434,13 @@ static void jsonExtractFunc( if( flags & JSON_JSON ){ jsonReturnNodeAsJson(p, pNode, ctx, 0); }else{ - jsonReturnNodeAsSql(p, pNode, ctx); + jsonReturnFromNode(p, pNode, ctx); sqlite3_result_subtype(ctx, 0); } } }else{ pNode = jsonLookup(p, zPath, 0, ctx); - if( p->nErr==0 && pNode ) jsonReturnNodeAsSql(p, pNode, ctx); + if( p->nErr==0 && pNode ) jsonReturnFromNode(p, pNode, ctx); } }else{ /* Two or more PATH arguments results in a JSON array with each @@ -4451,7 +4454,7 @@ static void jsonExtractFunc( if( p->nErr ) break; jsonAppendSeparator(&jx); if( pNode ){ - jsonRenderNodeAsText(p, pNode, &jx); + jsonXlateNodeToText(p, pNode, &jx); }else{ jsonAppendRawNZ(&jx, "null", 4); } @@ -5379,7 +5382,7 @@ static int jsonEachColumn( case JEACH_KEY: { if( p->i==0 ) break; if( p->eType==JSON_OBJECT ){ - jsonReturnNodeAsSql(&p->sParse, pThis, ctx); + jsonReturnFromNode(&p->sParse, pThis, ctx); }else if( p->eType==JSON_ARRAY ){ u32 iKey; if( p->bRecursive ){ @@ -5395,7 +5398,7 @@ static int jsonEachColumn( } case JEACH_VALUE: { if( pThis->jnFlags & JNODE_LABEL ) pThis++; - jsonReturnNodeAsSql(&p->sParse, pThis, ctx); + jsonReturnFromNode(&p->sParse, pThis, ctx); break; } case JEACH_TYPE: { @@ -5406,7 +5409,7 @@ static int jsonEachColumn( case JEACH_ATOM: { if( pThis->jnFlags & JNODE_LABEL ) pThis++; if( pThis->eType>=JSON_ARRAY ) break; - jsonReturnNodeAsSql(&p->sParse, pThis, ctx); + jsonReturnFromNode(&p->sParse, pThis, ctx); break; } case JEACH_ID: {