From 4bc1cc18476aaa674f8a24f859e1ed754c365505 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 13 Oct 2022 21:08:34 +0000 Subject: [PATCH 01/65] This experimental branch attempts to use columns for an index-on-expression in place of the expression that is being indexed. This particular check-in mostly works, but there are still issues. FossilOrigin-Name: 2e8d4fd4cfd9e82f33c707ba246fe2bb3ca01762cf5ac5905058fbc7adf0abe7 --- manifest | 31 ++++++++++++++++------------- manifest.uuid | 2 +- src/analyze.c | 1 + src/build.c | 1 + src/expr.c | 28 ++++++++++++++++++++++++++ src/insert.c | 1 + src/sqliteInt.h | 20 +++++++++++++++++++ src/upsert.c | 1 + src/where.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ src/whereexpr.c | 1 + 10 files changed, 123 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 13be78b776..f752561d83 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sthe\srest\sof\stesting1.js\sinto\stester1.js\sand\seliminate\sthe\sdependency\son\sjaccwabyt_test.c.\sExtend\sthe\slist\sof\sdefault\sconfig-related\s#defines\sin\ssqlite3-wasm.c\sand\sreorganize\sthem\sfor\smaintainability. -D 2022-10-13T16:48:35.302 +C This\sexperimental\sbranch\sattempts\sto\suse\scolumns\sfor\san\sindex-on-expression\nin\splace\sof\sthe\sexpression\sthat\sis\sbeing\sindexed.\s\sThis\sparticular\scheck-in\nmostly\sworks,\sbut\sthere\sare\sstill\sissues. +D 2022-10-13T21:08:34.457 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -550,7 +550,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F sqlite_cfg.h.in baf2e409c63d4e7a765e17769b6ff17c5a82bbd9cbf1e284fd2e4cefaff3fcf2 F src/alter.c 0390ca1d69ec3626cfa9f153114b7ab233e6b2bada6a9eb91361ed385fe90deb -F src/analyze.c aabdf3769c7fd9954a8ec508eb7041ae174b66f88d12c47199fabbea9a646467 +F src/analyze.c d2fce73f6a024897593012c6ca25368629fa4aeb49960d88a52fac664582e483 F src/attach.c 4431f82f0247bf3aaf91589acafdff77d1882235c95407b36da1585c765fbbc8 F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 @@ -559,7 +559,7 @@ F src/btmutex.c 6ffb0a22c19e2f9110be0964d0731d2ef1c67b5f7fabfbaeb7b9dabc4b7740ca F src/btree.c 74fc5f6a0577df703d6f98d0c51ee0d8d91d22dbc0ba86e42e056517e2b45576 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e -F src/build.c 6e3ee380a4f0ff95de4b53bf510f66600cff08e4e04b92e95fae789072563f8f +F src/build.c e9b3adf21cdae3c9ca9450ee8463f2094f133c23734b81fd371f23b3d5d345ca F src/callback.c 4cd7225b26a97f7de5fee5ae10464bed5a78f2adefe19534cc2095b3a8ca484a F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 428b47a2548c7c2c2f885189b42fdcc178fb03c276a2d58b3008b10da29373d5 @@ -567,7 +567,7 @@ F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5 F src/dbpage.c 5808e91bc27fa3981b028000f8fadfdc10ce9e59a34ce7dc4e035a69be3906ec F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e -F src/expr.c d199850a925665df7f8ac29fa938909f65a2bd32354aa206aa8c25fc74ff3d3d +F src/expr.c b60036e4bb9080c741a970df3b3cfffc6292aadec3670b7b04bfae6f662ff245 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 722f20779f5342a787922deded3628d8c74b5249cab04098cf17ee2f2aaff002 F src/func.c 8f72e88cccdee22185133c10f96ccd61dc34c5ea4b1fa9a73c237ef59b2e64f1 @@ -576,7 +576,7 @@ F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c aea5361767817f917b0f0f647a1f0b1621bd858938ae6ae545c3b6b9814b798f +F src/insert.c b972b1642cd0f7d5ae4964d713b65158a7bfa6a6e8786a9e8e57bd9c0b4a896d F src/json.c 7749b98c62f691697c7ee536b570c744c0583cab4a89200fdd0fc2aa8cc8cbd6 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 853385cc7a604157e137585097949252d5d0c731768e16b044608e5c95c3614b @@ -622,7 +622,7 @@ F src/shell.c.in 2915eaf22bda89ad6533851a051de4773c249185360fe1fc7b4477b8f9063b2 F src/sqlite.h.in d9c8a6243fc0a1c270d69db33758e34b810af3462f9bc5b4af113b347e07c69d F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 5336beea1868d99d2f62e628dbea55e97267dbff8193291ab175e960c5df9141 -F src/sqliteInt.h d15694b228fe5082587e13ac14f3e449621a5fe6d5933f5dee6e3c9491260da3 +F src/sqliteInt.h a856afa8ff20886d1b0c668b9e3c62daf7875989a1db79e60f121778d48015e1 F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -685,7 +685,7 @@ F src/tokenize.c 1305797eab3542a0896b552c6e7669c972c1468e11e92b370533c1f37a37082 F src/treeview.c 07787f67cd297a6d09d04b8d70c06769c60c9c1d9080378f93929c16f8fd3298 F src/trigger.c 4163ada044af89d51caba1cb713a73165347b2ec05fe84a283737c134d61fcd5 F src/update.c 5b0302c47cf31b533d5dff04c497ca1d8b9d89c39727e633fbe7b882fd5ac5aa -F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 +F src/upsert.c 5303dc6c518fa7d4b280ec65170f465c7a70b7ac2b22491598f6d0b4875b3145 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 0be191521ff6d2805995f4910f0b6231b42843678b2efdc1abecaf39929a673f F src/vacuum.c bb346170b0b54c6683bba4a5983aea40485597fdf605c87ec8bc2e199fe88cd8 @@ -704,10 +704,10 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 63e712bcad47f70e94c2150976cd7da5040933699e3938d4189d064acbe40891 +F src/where.c 5cd2a96f99841e0ba3e5564d53b5ad397d3e8a42ce6e4694cd332da4e2c527f1 F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 F src/wherecode.c bb88be457df3a6a01c844074ab79a9ba74279e73185f1362383aa697e3cae5dc -F src/whereexpr.c 55a39f42aaf982574fbf52906371a84cceed98a994422198dfd03db4fce4cc46 +F src/whereexpr.c bf8c155212c886621d71c951053660de6fcc4ee907b17aa02da0a96a39aa9405 F src/window.c 928e215840e2f2d9a2746e018c9643ef42c66c4ab6630ef0df7fa388fa145e86 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 @@ -2031,8 +2031,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cb94350185f555c333b628ee846c47bcc9df5f76bb82de569b8322f30dbbe1bc -R 32dab828066657d904ede486bb592456 -U stephan -Z 3fd1b23c49b42c2df54d60ffd9b89d7f +P 4e2a8aff2dd4b6e148f45184e2523ebe47815257eca97fa3d32bcbf9625f0def +R 6b28e91c7f03fb2da80daeebeb46b73a +T *branch * index-expr-opt +T *sym-index-expr-opt * +T -sym-trunk * +U drh +Z 4c1c25db22a8599a4330b36a4516d3d7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7e72bfdd21..c689c214d4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4e2a8aff2dd4b6e148f45184e2523ebe47815257eca97fa3d32bcbf9625f0def \ No newline at end of file +2e8d4fd4cfd9e82f33c707ba246fe2bb3ca01762cf5ac5905058fbc7adf0abe7 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 39009899ab..8562b9d7f1 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -953,6 +953,7 @@ static void analyzeVdbeCommentIndexWithColumnName( if( NEVER(i==XN_ROWID) ){ VdbeComment((v,"%s.rowid",pIdx->zName)); }else if( i==XN_EXPR ){ + assert( pIdx->bHasExpr ); VdbeComment((v,"%s.expr(%d)",pIdx->zName, k)); }else{ VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zCnName)); diff --git a/src/build.c b/src/build.c index be6b01eb08..502826bfc8 100644 --- a/src/build.c +++ b/src/build.c @@ -4192,6 +4192,7 @@ void sqlite3CreateIndex( j = XN_EXPR; pIndex->aiColumn[i] = XN_EXPR; pIndex->uniqNotNull = 0; + pIndex->bHasExpr = 1; }else{ j = pCExpr->iColumn; assert( j<=0x7fff ); diff --git a/src/expr.c b/src/expr.c index bceb5efb08..3630b47aa8 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4043,6 +4043,26 @@ static int exprCodeInlineFunction( return target; } +/* +** Check to see if pExpr is one of the indexed expression on pParse->pIdxExpr. +** If it is, then resolve the expression by reading from the index and +** return the register into which the value has been read. If there is +** no match, return negative. +*/ +static SQLITE_NOINLINE int sqlite3ExprIndexLookup( + Parse *pParse, /* The parsing context */ + Expr *pExpr, /* The expression to potentially bypass */ + int target /* Where to store the result of the expression */ +){ + IndexExpr *p; + for(p=pParse->pIdxExpr; p; p=p->pIENext){ + if( sqlite3ExprCompare(0, pExpr, p->pExpr, p->iDataCur)!=0 ) continue; + sqlite3VdbeAddOp3(pParse->pVdbe, OP_Column, p->iIdxCur, p->iIdxCol, target); + return target; + } + return -1; /* Not found */ +} + /* ** Generate code into the current Vdbe to evaluate the given @@ -4068,6 +4088,14 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ assert( target>0 && target<=pParse->nMem ); assert( v!=0 ); + if( pParse->pIdxExpr!=0 + && pExpr!=0 + && !ExprHasProperty(pExpr, EP_Leaf) + && (r1 = sqlite3ExprIndexLookup(pParse, pExpr, target))>=0 + ){ + return r1; + } + expr_code_doover: if( pExpr==0 ){ op = TK_NULL; diff --git a/src/insert.c b/src/insert.c index 6c71391a1b..3e0d696d74 100644 --- a/src/insert.c +++ b/src/insert.c @@ -96,6 +96,7 @@ const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){ aff = SQLITE_AFF_INTEGER; }else{ assert( x==XN_EXPR ); + assert( pIdx->bHasExpr ); assert( pIdx->aColExpr!=0 ); aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr); } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 6f1109f2f6..caf7610adb 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1189,6 +1189,7 @@ typedef struct FuncDef FuncDef; typedef struct FuncDefHash FuncDefHash; typedef struct IdList IdList; typedef struct Index Index; +typedef struct IndexExpr IndexExpr; typedef struct IndexSample IndexSample; typedef struct KeyClass KeyClass; typedef struct KeyInfo KeyInfo; @@ -2616,6 +2617,7 @@ struct Index { unsigned bNoQuery:1; /* Do not use this index to optimize queries */ unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */ unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */ + unsigned bHasExpr:1; /* This is an index on an expression */ #ifdef SQLITE_ENABLE_STAT4 int nSample; /* Number of elements in aSample[] */ int nSampleCol; /* Size of IndexSample.anEq[] and so on */ @@ -3563,6 +3565,23 @@ struct TriggerPrg { # define DbMaskNonZero(M) (M)!=0 #endif +/* +** If there is an index on an expression in scope such that the value +** of the expression pExpr can be read out of the index with cursor iCur +** at column iCol, then an instance of this object records that fact. +** +** A linked list of these objects is attached to Parse and records all +** expressions that can be short-circuited by extracting a valid from +** an index. +*/ +struct IndexExpr { + Expr *pExpr; /* The expression contained in the index */ + int iDataCur; /* The data cursor associated with the index */ + int iIdxCur; /* The index cursor */ + int iIdxCol; /* The column of the index that contains pExpr */ + IndexExpr *pIENext; /* Next in a list of all indexed expressions */ +}; + /* ** An instance of the ParseCleanup object specifies an operation that ** should be performed after parsing to deallocation resources obtained @@ -3621,6 +3640,7 @@ struct Parse { int nLabelAlloc; /* Number of slots in aLabel */ int *aLabel; /* Space to hold the labels */ ExprList *pConstExpr;/* Constant expressions */ + IndexExpr *pIdxExpr; /* List of all expression in active indexes */ Token constraintName;/* Name of the constraint currently being parsed */ yDbMask writeMask; /* Start a write transaction on these databases */ yDbMask cookieMask; /* Bitmask of schema verified databases */ diff --git a/src/upsert.c b/src/upsert.c index fb6c7c0c07..85994020cf 100644 --- a/src/upsert.c +++ b/src/upsert.c @@ -166,6 +166,7 @@ int sqlite3UpsertAnalyzeTarget( if( pIdx->aiColumn[ii]==XN_EXPR ){ assert( pIdx->aColExpr!=0 ); assert( pIdx->aColExpr->nExpr>ii ); + assert( pIdx->bHasExpr ); pExpr = pIdx->aColExpr->a[ii].pExpr; if( pExpr->op!=TK_COLLATE ){ sCol[0].pLeft = pExpr; diff --git a/src/where.c b/src/where.c index b0c0ea7d4e..220ea5139d 100644 --- a/src/where.c +++ b/src/where.c @@ -5383,6 +5383,55 @@ static SQLITE_NOINLINE void whereCheckIfBloomFilterIsUseful( } } +/* +** This is an sqlite3ParserAddCleanup() callback that is invoked to +** free the Parse->pIdxExpr list when the Parse object is destroyed. +*/ +static void whereIndexExprCleanup(sqlite3 *db, void *pObject){ + Parse *pParse = (Parse*)pObject; + while( pParse->pIdxExpr!=0 ){ + IndexExpr *p = pParse->pIdxExpr; + pParse->pIdxExpr = p->pIENext; + sqlite3ExprDelete(db, p->pExpr); + sqlite3DbFreeNN(db, p); + } +} + +/* +** The index pIdx is used by a query and contains one or more expressions. +** In other words pIdx is an index on an expression. iIdxCur is the cursor +** number for the index and iDataCur is the cursor number for the corresponding +** table. +** +** This routine adds IndexExpr entries to the Parse->pIdxExpr field for +** each of the expressions in the index so that the expression code generator +** will know to replace occurrences of the indexed expression with +** references to the corresponding column of the index. +*/ +static SQLITE_NOINLINE void whereAddIndexExpr( + Parse *pParse, /* Add IndexExpr entries to pParse->pIdxExpr */ + Index *pIdx, /* The index-on-expression that contains the expressions */ + int iIdxCur, /* Cursor number for pIdx */ + int iDataCur /* Cursor for the corresponding table */ +){ + int i; + IndexExpr *p; + for(i=0; inColumn; i++){ + if( pIdx->aiColumn[i]!=XN_EXPR ) continue; + p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexExpr)); + if( p==0 ) break; + p->pIENext = pParse->pIdxExpr; + p->pExpr = sqlite3ExprDup(pParse->db, pIdx->aColExpr->a[i].pExpr, 0); + p->iDataCur = iDataCur; + p->iIdxCur = iIdxCur; + p->iIdxCol = i; + pParse->pIdxExpr = p; + if( p->pIENext==0 ){ + sqlite3ParserAddCleanup(pParse, whereIndexExprCleanup, pParse); + } + } +} + /* ** Generate the beginning of the loop used for WHERE clause processing. ** The return value is a pointer to an opaque structure that contains @@ -5928,6 +5977,9 @@ WhereInfo *sqlite3WhereBegin( op = OP_ReopenIdx; }else{ iIndexCur = pParse->nTab++; + if( pIx->bHasExpr ){ + whereAddIndexExpr(pParse, pIx, iIndexCur, pTabItem->iCursor); + } } pLevel->iIdxCur = iIndexCur; assert( pIx!=0 ); diff --git a/src/whereexpr.c b/src/whereexpr.c index 8c9233ebd3..20e569642a 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -989,6 +989,7 @@ static SQLITE_NOINLINE int exprMightBeIndexed2( if( pIdx->aColExpr==0 ) continue; for(i=0; inKeyCol; i++){ if( pIdx->aiColumn[i]!=XN_EXPR ) continue; + assert( pIdx->bHasExpr ); if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){ aiCurCol[0] = iCur; aiCurCol[1] = XN_EXPR; From 859434d049a41edd3eb961b85b1b930cebac6540 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 14 Oct 2022 02:00:54 +0000 Subject: [PATCH 02/65] Cancel IndexExpr objects when they go out of scope. FossilOrigin-Name: 0963519371bb7ac02adb323430855760fb9b82a23745e47c504aaf393d22ac34 --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/where.c | 11 +++++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f752561d83..573214d62d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C This\sexperimental\sbranch\sattempts\sto\suse\scolumns\sfor\san\sindex-on-expression\nin\splace\sof\sthe\sexpression\sthat\sis\sbeing\sindexed.\s\sThis\sparticular\scheck-in\nmostly\sworks,\sbut\sthere\sare\sstill\sissues. -D 2022-10-13T21:08:34.457 +C Cancel\sIndexExpr\sobjects\swhen\sthey\sgo\sout\sof\sscope. +D 2022-10-14T02:00:54.507 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -704,7 +704,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 5cd2a96f99841e0ba3e5564d53b5ad397d3e8a42ce6e4694cd332da4e2c527f1 +F src/where.c 39889861616d7751efacb9e5aa84ec5635dbf12a137725f57aa25fc6b622e15c F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 F src/wherecode.c bb88be457df3a6a01c844074ab79a9ba74279e73185f1362383aa697e3cae5dc F src/whereexpr.c bf8c155212c886621d71c951053660de6fcc4ee907b17aa02da0a96a39aa9405 @@ -2031,11 +2031,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 4e2a8aff2dd4b6e148f45184e2523ebe47815257eca97fa3d32bcbf9625f0def -R 6b28e91c7f03fb2da80daeebeb46b73a -T *branch * index-expr-opt -T *sym-index-expr-opt * -T -sym-trunk * +P 2e8d4fd4cfd9e82f33c707ba246fe2bb3ca01762cf5ac5905058fbc7adf0abe7 +R 6e639b412a6a288ed64157bd3e723cf0 U drh -Z 4c1c25db22a8599a4330b36a4516d3d7 +Z c5e6e161a1559a577698a45d0fdb903e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c689c214d4..78c84b6668 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2e8d4fd4cfd9e82f33c707ba246fe2bb3ca01762cf5ac5905058fbc7adf0abe7 \ No newline at end of file +0963519371bb7ac02adb323430855760fb9b82a23745e47c504aaf393d22ac34 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 220ea5139d..0bba48883e 100644 --- a/src/where.c +++ b/src/where.c @@ -6376,6 +6376,17 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ }else{ last = pWInfo->iEndWhere; } + if( pIdx->bHasExpr ){ + IndexExpr *p = pParse->pIdxExpr; + while( p ){ + if( p->iIdxCur==pLevel->iIdxCur ){ + p->iDataCur = -1; + p->iIdxCur = -1; + p->pExpr->op = TK_ILLEGAL; + } + p = p->pIENext; + } + } k = pLevel->addrBody + 1; #ifdef SQLITE_DEBUG if( db->flags & SQLITE_VdbeAddopTrace ){ From 7a98937db2414e60a75991e637c0da6b87dd6336 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 15 Oct 2022 11:27:01 +0000 Subject: [PATCH 03/65] Only extract an expression from an index when the index is not a null row in an outer join. FossilOrigin-Name: 08b033c737d1a84859291f50e2985c9dad8d660a50185d55d3171165a8e08d4c --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 22 +++++++++++++++++++++- src/sqliteInt.h | 1 + src/where.c | 16 ++++++++-------- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index e6e98f6967..697406e18c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sfixes\sfrom\strunk. -D 2022-10-14T19:56:58.085 +C Only\sextract\san\sexpression\sfrom\san\sindex\swhen\sthe\sindex\sis\snot\sa\snull\srow\nin\san\souter\sjoin. +D 2022-10-15T11:27:01.598 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -567,7 +567,7 @@ F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5 F src/dbpage.c 5808e91bc27fa3981b028000f8fadfdc10ce9e59a34ce7dc4e035a69be3906ec F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e -F src/expr.c b60036e4bb9080c741a970df3b3cfffc6292aadec3670b7b04bfae6f662ff245 +F src/expr.c 8e260b0082700cb009238eb41cb28a8fce0290356b9fd25a72017c7fb48cb463 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 722f20779f5342a787922deded3628d8c74b5249cab04098cf17ee2f2aaff002 F src/func.c fe2a795ad647ce42054873ac91c43beb7b5d204892903a67f6e7e314379b9d4a @@ -622,7 +622,7 @@ F src/shell.c.in 2915eaf22bda89ad6533851a051de4773c249185360fe1fc7b4477b8f9063b2 F src/sqlite.h.in d9c8a6243fc0a1c270d69db33758e34b810af3462f9bc5b4af113b347e07c69d F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 5336beea1868d99d2f62e628dbea55e97267dbff8193291ab175e960c5df9141 -F src/sqliteInt.h a856afa8ff20886d1b0c668b9e3c62daf7875989a1db79e60f121778d48015e1 +F src/sqliteInt.h 30e6fdc957f09dbdbe1bcf73874263427bbd9a321cd2a583de74bdb030c9fa78 F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -704,7 +704,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 39889861616d7751efacb9e5aa84ec5635dbf12a137725f57aa25fc6b622e15c +F src/where.c 8517a0ee4a3169368176fda649e2693ee013d7bdca72d485050e91cd640735f7 F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 F src/wherecode.c bb88be457df3a6a01c844074ab79a9ba74279e73185f1362383aa697e3cae5dc F src/whereexpr.c bf8c155212c886621d71c951053660de6fcc4ee907b17aa02da0a96a39aa9405 @@ -2031,8 +2031,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 0963519371bb7ac02adb323430855760fb9b82a23745e47c504aaf393d22ac34 ed14863dd72e35fa3a23320c3d5a8166515faea39a555c28a27b2d35e701eac4 -R a9b714ce8ec9ca5df691ed405bb47472 +P 1cb65f36c3539302767f551ed53082f054666a7cb2696cef0990ab6747edbc52 +R b4967a409c773c44f7c239bcdd51f4f2 U drh -Z 5b8c2826f1d75c8b25b3831a35d10fbe +Z 10f741f9b8a389bcee87379894e97dc0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2169956f70..8ced3b3665 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1cb65f36c3539302767f551ed53082f054666a7cb2696cef0990ab6747edbc52 \ No newline at end of file +08b033c737d1a84859291f50e2985c9dad8d660a50185d55d3171165a8e08d4c \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 3630b47aa8..0ff364ddca 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4055,9 +4055,29 @@ static SQLITE_NOINLINE int sqlite3ExprIndexLookup( int target /* Where to store the result of the expression */ ){ IndexExpr *p; + Vdbe *v; for(p=pParse->pIdxExpr; p; p=p->pIENext){ + if( p->iDataCur<0 ) continue; if( sqlite3ExprCompare(0, pExpr, p->pExpr, p->iDataCur)!=0 ) continue; - sqlite3VdbeAddOp3(pParse->pVdbe, OP_Column, p->iIdxCur, p->iIdxCol, target); + v = pParse->pVdbe; + assert( v!=0 ); + if( p->bMaybeNullRow ){ + /* If the index is on a NULL row due to an outer join, then we + ** cannot extract the value from the index. The value must be + ** computed using the original expression. */ + int addr = sqlite3VdbeCurrentAddr(v); + sqlite3VdbeAddOp3(v, OP_IfNullRow, p->iIdxCur, addr+3, target); + VdbeCoverage(v); + sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target); + sqlite3VdbeGoto(v, 0); + p = pParse->pIdxExpr; + pParse->pIdxExpr = 0; + sqlite3ExprCode(pParse, pExpr, target); + pParse->pIdxExpr = p; + sqlite3VdbeJumpHere(v, addr+2); + }else{ + sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target); + } return target; } return -1; /* Not found */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index caf7610adb..fffe981488 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3579,6 +3579,7 @@ struct IndexExpr { int iDataCur; /* The data cursor associated with the index */ int iIdxCur; /* The index cursor */ int iIdxCol; /* The column of the index that contains pExpr */ + u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */ IndexExpr *pIENext; /* Next in a list of all indexed expressions */ }; diff --git a/src/where.c b/src/where.c index 0bba48883e..d43c2b2050 100644 --- a/src/where.c +++ b/src/where.c @@ -5409,22 +5409,23 @@ static void whereIndexExprCleanup(sqlite3 *db, void *pObject){ ** references to the corresponding column of the index. */ static SQLITE_NOINLINE void whereAddIndexExpr( - Parse *pParse, /* Add IndexExpr entries to pParse->pIdxExpr */ - Index *pIdx, /* The index-on-expression that contains the expressions */ - int iIdxCur, /* Cursor number for pIdx */ - int iDataCur /* Cursor for the corresponding table */ + Parse *pParse, /* Add IndexExpr entries to pParse->pIdxExpr */ + Index *pIdx, /* The index-on-expression that contains the expressions */ + int iIdxCur, /* Cursor number for pIdx */ + SrcItem *pTabItem /* The FROM clause entry for the table */ ){ int i; IndexExpr *p; for(i=0; inColumn; i++){ if( pIdx->aiColumn[i]!=XN_EXPR ) continue; - p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexExpr)); + p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexExpr)); if( p==0 ) break; p->pIENext = pParse->pIdxExpr; p->pExpr = sqlite3ExprDup(pParse->db, pIdx->aColExpr->a[i].pExpr, 0); - p->iDataCur = iDataCur; + p->iDataCur = pTabItem->iCursor; p->iIdxCur = iIdxCur; p->iIdxCol = i; + p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0; pParse->pIdxExpr = p; if( p->pIENext==0 ){ sqlite3ParserAddCleanup(pParse, whereIndexExprCleanup, pParse); @@ -5978,7 +5979,7 @@ WhereInfo *sqlite3WhereBegin( }else{ iIndexCur = pParse->nTab++; if( pIx->bHasExpr ){ - whereAddIndexExpr(pParse, pIx, iIndexCur, pTabItem->iCursor); + whereAddIndexExpr(pParse, pIx, iIndexCur, pTabItem); } } pLevel->iIdxCur = iIndexCur; @@ -6382,7 +6383,6 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ if( p->iIdxCur==pLevel->iIdxCur ){ p->iDataCur = -1; p->iIdxCur = -1; - p->pExpr->op = TK_ILLEGAL; } p = p->pIENext; } From f3adb7c43092d6af97a71e32e3cb4f714afe63ea Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 15 Oct 2022 12:01:40 +0000 Subject: [PATCH 04/65] Enable the index-on-expression optimization even when the expression is used as an argument to an aggregate function. FossilOrigin-Name: 462b3c7f39724dc814f55e7a225e7d0c48f81c524cdda797a66e9e198c35ce58 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 697406e18c..af4a5b033e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Only\sextract\san\sexpression\sfrom\san\sindex\swhen\sthe\sindex\sis\snot\sa\snull\srow\nin\san\souter\sjoin. -D 2022-10-15T11:27:01.598 +C Enable\sthe\sindex-on-expression\soptimization\seven\swhen\sthe\sexpression\sis\nused\sas\san\sargument\sto\san\saggregate\sfunction. +D 2022-10-15T12:01:40.334 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -567,7 +567,7 @@ F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5 F src/dbpage.c 5808e91bc27fa3981b028000f8fadfdc10ce9e59a34ce7dc4e035a69be3906ec F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e -F src/expr.c 8e260b0082700cb009238eb41cb28a8fce0290356b9fd25a72017c7fb48cb463 +F src/expr.c 4a13a0e5c30be801b0adc295ef74e0f1aa8c041aefdcb5d0d424337ecefa2806 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 722f20779f5342a787922deded3628d8c74b5249cab04098cf17ee2f2aaff002 F src/func.c fe2a795ad647ce42054873ac91c43beb7b5d204892903a67f6e7e314379b9d4a @@ -2031,8 +2031,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 1cb65f36c3539302767f551ed53082f054666a7cb2696cef0990ab6747edbc52 -R b4967a409c773c44f7c239bcdd51f4f2 +P 08b033c737d1a84859291f50e2985c9dad8d660a50185d55d3171165a8e08d4c +R a01b27e71bf0d1c060a37cd77d73f0f5 U drh -Z 10f741f9b8a389bcee87379894e97dc0 +Z 807c2ee5a3bf759378437d2cb1bbfe03 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8ced3b3665..ce95dd861c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -08b033c737d1a84859291f50e2985c9dad8d660a50185d55d3171165a8e08d4c \ No newline at end of file +462b3c7f39724dc814f55e7a225e7d0c48f81c524cdda797a66e9e198c35ce58 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 0ff364ddca..4bff004119 100644 --- a/src/expr.c +++ b/src/expr.c @@ -5618,7 +5618,13 @@ int sqlite3ExprCompare( if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){ return 1; } - return 2; + if( pA->op==TK_AGG_COLUMN && pB->op==TK_COLUMN + && pB->iTable<0 && pA->iTable==iTab + ){ + /* fall through */ + }else{ + return 2; + } } assert( !ExprHasProperty(pA, EP_IntValue) ); assert( !ExprHasProperty(pB, EP_IntValue) ); From 956392694abaaa832ec3186f7b6af5043f71e623 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 16 Oct 2022 15:38:03 +0000 Subject: [PATCH 05/65] Add a top-level license and build-time version info header to generated sqlite3*.js. Correct a broken link in ext/wasm/index.html. FossilOrigin-Name: 0f1a06e8e39a1fbc74f1aff9cc59787282dfbf847d6c5c7edb3f7d410db0e4b7 --- ext/wasm/GNUmakefile | 24 ++++++++++++++--- ext/wasm/api/extern-post-js.js | 3 ++- ext/wasm/api/extern-pre-js.js | 3 +++ ext/wasm/api/post-js-footer.js | 3 ++- ext/wasm/api/pre-js.js | 7 +++++ ext/wasm/api/sqlite3-api-cleanup.js | 27 +++++++++---------- .../api/sqlite3-license-version-header.js | 25 +++++++++++++++++ ext/wasm/index.html | 2 +- manifest | 27 ++++++++++--------- manifest.uuid | 2 +- 10 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 ext/wasm/api/sqlite3-license-version-header.js diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index cf0e8b1081..c4c2886da3 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -49,6 +49,7 @@ dir.fiddle := fiddle CLEAN_FILES := *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ emcc_enable_bigint ?= 1 sqlite3.c := $(dir.top)/sqlite3.c +sqlite3.h := $(dir.top)/sqlite3.h SQLITE_OPT = \ -DSQLITE_ENABLE_FTS4 \ -DSQLITE_ENABLE_RTREE \ @@ -109,7 +110,7 @@ emcc_opt_full := $(emcc_opt) -g3 ######################################################################## -$(sqlite3.c): +$(sqlite3.c) $(sqlite3.h): $(MAKE) -C $(dir.top) sqlite3.c clean: @@ -130,7 +131,10 @@ EXPORTED_FUNCTIONS.api: $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE) cat $(EXPORTED_FUNCTIONS.api.in) > $@ CLEAN_FILES += EXPORTED_FUNCTIONS.api -sqlite3-api.jses := $(dir.api)/sqlite3-api-prologue.js +sqlite3-license-version.js := sqlite3-license-version.js +sqlite3-license-version-header.js := $(dir.api)/sqlite3-license-version-header.js +sqlite3-api.jses := $(sqlite3-license-version.js) +sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js sqlite3-api.jses += $(dir.common)/whwasmutil.js sqlite3-api.jses += $(dir.jacc)/jaccwabyt.js sqlite3-api.jses += $(dir.api)/sqlite3-api-glue.js @@ -141,6 +145,7 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js sqlite3-api.js := sqlite3-api.js CLEAN_FILES += $(sqlite3-api.js) +CLEAN_FILES += $(sqlite3-license-version.js) $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) @echo "Making $@..." @for i in $(sqlite3-api.jses); do \ @@ -171,9 +176,20 @@ extern-pre-js.js := $(dir.api)/extern-pre-js.js pre-post-common.flags := \ --post-js=$(post-js.js) \ --extern-post-js=$(extern-post-js.js) \ - --extern-pre-js=$(extern-pre-js.js) + --extern-pre-js=$(dir.wasm)/$(sqlite3-license-version.js) pre-post-jses.deps := $(post-js.js) \ - $(extern-post-js.js) $(extern-pre-js.js) + $(extern-post-js.js) $(extern-pre-js.js) $(sqlite3-license-version.js) +$(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) $(MAKEFILE) + @echo "Making $@..."; { \ + cat $(sqlite3-license-version-header.js); \ + echo '/*'; \ + echo '** This code was built from sqlite3 version...'; \ + echo "** "; \ + awk -e '/define SQLITE_VERSION/{$$1=""; print "**" $$0}' \ + -e '/define SQLITE_SOURCE_ID/{$$1=""; print "**" $$0}' $(sqlite3.h); \ + echo '*/'; \ + } > $@ + ######################################################################## # call-make-pre-js creates rules for pre-js-$(1).js. $1 = the base # name of the JS file on whose behalf this pre-js is for. diff --git a/ext/wasm/api/extern-post-js.js b/ext/wasm/api/extern-post-js.js index 5ebb5a31e7..51e8d12b2b 100644 --- a/ext/wasm/api/extern-post-js.js +++ b/ext/wasm/api/extern-post-js.js @@ -1,5 +1,6 @@ /* extern-post-js.js must be appended to the resulting sqlite3.js - file. */ + file. It gets its name from being used as the value for + the --extern-post-js=... Emscripten flag. */ (function(){ /** In order to hide the sqlite3InitModule()'s resulting Emscripten diff --git a/ext/wasm/api/extern-pre-js.js b/ext/wasm/api/extern-pre-js.js index 26d066d2ee..7d47d33e33 100644 --- a/ext/wasm/api/extern-pre-js.js +++ b/ext/wasm/api/extern-pre-js.js @@ -1,4 +1,7 @@ /* extern-pre-js.js must be prepended to the resulting sqlite3.js file. This file is currently only used for holding snippets during test and development. + + It gets its name from being used as the value for the + --extern-pre-js=... Emscripten flag. */ diff --git a/ext/wasm/api/post-js-footer.js b/ext/wasm/api/post-js-footer.js index ee470928ba..58882cbd9c 100644 --- a/ext/wasm/api/post-js-footer.js +++ b/ext/wasm/api/post-js-footer.js @@ -1,3 +1,4 @@ /* The current function scope was opened via post-js-header.js, which - gets prepended to this at build-time. */ + gets prepended to this at build-time. This file closes that + scope. */ })/*postRun.push(...)*/; diff --git a/ext/wasm/api/pre-js.js b/ext/wasm/api/pre-js.js index 502ecf348f..b6630416dd 100644 --- a/ext/wasm/api/pre-js.js +++ b/ext/wasm/api/pre-js.js @@ -1,3 +1,9 @@ +/** + BEGIN FILE: api/pre-js.js + + This file is intended to be prepended to the sqlite3.js build using + Emscripten's --pre-js=THIS_FILE flag (or equivalent). +*/ Module['locateFile'] = function(path, prefix) { return prefix + path; }; @@ -39,3 +45,4 @@ Module[xInstantiateWasm] = function callee(imports,onSuccess){ scripts. */ Module[xInstantiateWasm].uri = 'sqlite3.wasm'; +/* END FILE: api/pre-js.js */ diff --git a/ext/wasm/api/sqlite3-api-cleanup.js b/ext/wasm/api/sqlite3-api-cleanup.js index c2a3425891..555e5d31c5 100644 --- a/ext/wasm/api/sqlite3-api-cleanup.js +++ b/ext/wasm/api/sqlite3-api-cleanup.js @@ -20,17 +20,15 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build /** Install a suitable default configuration for sqlite3ApiBootstrap(). */ - const SABC = self.sqlite3ApiConfig || Object.create(null); - if(undefined===SABC.Module){ - SABC.Module = Module /* ==> Currently needs to be exposed here for - test code. NOT part of the public API. */; - } - if(undefined===SABC.exports){ - SABC.exports = Module['asm']; - } - if(undefined===SABC.memory){ - SABC.memory = Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */; - } + const SABC = Object.assign( + Object.create(null), { + Module: Module /* ==> Currently needs to be exposed here for + test code. NOT part of the public API. */, + exports: Module['asm'], + memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */ + }, + self.sqlite3ApiConfig || Object.create(null) + ); /** For current (2022-08-22) purposes, automatically call @@ -38,10 +36,11 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build point, as we really want client code to be able to call this to configure certain parts. Clients may modify self.sqlite3ApiBootstrap.defaultConfig to tweak the default - configuration used by a no-args call to sqlite3ApiBootstrap(). + configuration used by a no-args call to sqlite3ApiBootstrap(), + but must have first loaded their WASM module in order to be + able to provide the necessary configuration state. */ //console.warn("self.sqlite3ApiConfig = ",self.sqlite3ApiConfig); - const rmApiConfig = (SABC !== self.sqlite3ApiConfig); self.sqlite3ApiConfig = SABC; let sqlite3; try{ @@ -51,7 +50,7 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build throw e; }finally{ delete self.sqlite3ApiBootstrap; - if(rmApiConfig) delete self.sqlite3ApiConfig; + delete self.sqlite3ApiConfig; } if(self.location && +self.location.port > 1024){ diff --git a/ext/wasm/api/sqlite3-license-version-header.js b/ext/wasm/api/sqlite3-license-version-header.js new file mode 100644 index 0000000000..f8b3eddc5f --- /dev/null +++ b/ext/wasm/api/sqlite3-license-version-header.js @@ -0,0 +1,25 @@ +/* +** LICENSE for the sqlite3 WebAssembly/JavaScript APIs. +** +** This bundle (typically released as sqlite3.js or sqlite3-wasmfs.js) +** is an amalgamation of JavaScript source code from two projects: +** +** 1) https://emscripten.org: the Emscripten "glue code" is covered by +** the terms of the MIT license and University of Illinois/NCSA +** Open Source License, as described at: +** +** https://emscripten.org/docs/introducing_emscripten/emscripten_license.html +** +** 2) https://sqlite.org: all code and documentation labeled as being +** from this source are released under the same terms as the sqlite3 +** C library: +** +** 2022-10-16 +** +** The author disclaims copyright to this source code. In place of a +** legal notice, here is a blessing: +** +** * May you do good and not evil. +** * May you find forgiveness for yourself and forgive others. +** * May you share freely, never taking more than you give. +*/ diff --git a/ext/wasm/index.html b/ext/wasm/index.html index 01d178bb7a..a7f0974fbe 100644 --- a/ext/wasm/index.html +++ b/ext/wasm/index.html @@ -46,7 +46,7 @@
  • tester1: Core unit and regression tests for the various APIs and surrounding utility code.
  • -
  • tester1-worker: same thing +
  • tester1-worker: same thing but running in a Worker.
  • diff --git a/manifest b/manifest index df43c1449f..2f0d88b24d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\susing\sthe\spush-down\soptimization\son\scompound\sSELECTs\swhere\scomponent\sSELECTs\suse\sdifferent\scollation\ssequences.\sdbsqlfuzz\s11516f050100243e5a845f5a2b48a90ed2efaf2e. -D 2022-10-14T19:30:34.777 +C Add\sa\stop-level\slicense\sand\sbuild-time\sversion\sinfo\sheader\sto\sgenerated\ssqlite3*.js.\sCorrect\sa\sbroken\slink\sin\sext/wasm/index.html. +D 2022-10-16T15:38:03.833 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -473,22 +473,23 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0 -F ext/wasm/GNUmakefile 4ec270532b921c7c4b437fbdb06f6a0ce41f3bd874395ce70dbc933c8553efa9 +F ext/wasm/GNUmakefile e298b8a91fab19b758fc9e843601d50129afec1e5a6fcf4328affe3f34f40b3e F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 F ext/wasm/api/README.md 62758e8dd98741d41505f69130cc767013d2e871ebb9e4313d8f8b97d95071d8 -F ext/wasm/api/extern-post-js.js dc68cbf552d8ea085181400a6963907c32e0b088b03ffd8969b1869fea246629 -F ext/wasm/api/extern-pre-js.js 20143b16b672d0a576fbf768a786d12ee1f84e222126477072389b992542a5b2 -F ext/wasm/api/post-js-footer.js b64319261d920211b8700004d08b956a6c285f3b0bba81456260a713ed04900c +F ext/wasm/api/extern-post-js.js dfae3a5f621ae94f1fae671f8013ed6464355f11e2adda38ed8b10bf1929f337 +F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 +F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1ecc5ba9e64ef90a8b -F ext/wasm/api/pre-js.js 2db711eb637991b383fc6b5c0f3df65ec48a7201e5730e304beba8de2d3f9b0b -F ext/wasm/api/sqlite3-api-cleanup.js 5d22d1d3818ecacb23bfa223d5970cd0617d8cdbb48c8bc4bbd463f05b021a99 +F ext/wasm/api/pre-js.js 5b550904322d73127badd4347ca967ea525b901573559736f92d326ad9b7bb76 +F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383bd7ee0de0178b1b3e988588 F ext/wasm/api/sqlite3-api-glue.js 842dc03783aecc951a543a209523343a6fda9af258fb0bee08e8cc2dc3c4d8ae F ext/wasm/api/sqlite3-api-oo1.js 00f5cfce0989d2e08d7b21765d703c69234245d03a0cce8fcb32ccfcd53ffdbb F ext/wasm/api/sqlite3-api-opfs.js 5a8ab3b76880c8ada8710ca9ba1ca5b160872edfd8bd5322e4f179a7f41cc616 F ext/wasm/api/sqlite3-api-prologue.js b7c82a22d50658a48463fa646a23135273bc2cfa843aedda32627ff281c12e4d F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8 +F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 F ext/wasm/api/sqlite3-wasm.c 4c131945ced4b08a694d287abcdb066b896d961ef79ee5241805ecc37e83d63a F ext/wasm/batch-runner.html cf1a410c92bad50fcec2ddc71390b4e9df63a6ea1bef12a5163a66a0af4d78d9 @@ -507,7 +508,7 @@ F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d695 F ext/wasm/fiddle/fiddle-worker.js 531859a471924a0ea48afa218e6877f0c164ca324d51e15843ed6ecc1c65c7ee F ext/wasm/fiddle/fiddle.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715 -F ext/wasm/index.html 9ae9f9629310ed3ee88901aa14e20195815583806af245da08c2ecb43ced2243 +F ext/wasm/index.html f41ff0b3cef07196b18f3f917c46560a0d5289064d344b438b254c41ed0f2c76 F ext/wasm/jaccwabyt/jaccwabyt.js 0d7f32817456a0f3937fcfd934afeb32154ca33580ab264dab6c285e6dbbd215 F ext/wasm/jaccwabyt/jaccwabyt.md 9aa6951b529a8b29f578ec8f0355713c39584c92cf1708f63ba0cf917cb5b68e F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e1029186d836d14b83845fbe06 @@ -2031,8 +2032,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 565d74c36f2dd4612860c7ee561682c50db28cfa5384346528292019dbfdf86c -R 75e7f9b91b017a681d1ae11ac5186379 -U dan -Z 42c84fae9e00b1c8a3d198c324edcd95 +P ed14863dd72e35fa3a23320c3d5a8166515faea39a555c28a27b2d35e701eac4 +R 664fdd2b5e755302311ec6a1ceb0cf59 +U stephan +Z 70648a34d9cd28a66a6a4694b2eeaced # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 65ef760f0e..0ece5330b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ed14863dd72e35fa3a23320c3d5a8166515faea39a555c28a27b2d35e701eac4 \ No newline at end of file +0f1a06e8e39a1fbc74f1aff9cc59787282dfbf847d6c5c7edb3f7d410db0e4b7 \ No newline at end of file From 8ffc98999d4fae6598aff02cabf63ba4c3829c95 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 16 Oct 2022 16:38:15 +0000 Subject: [PATCH 06/65] JS: add build-time-generated version info to the sqlite3.version object. Remove some stray debug output from tester1.js. FossilOrigin-Name: b5f462c2d85d503f6492ec20580d57cb4c926712f6306a6be764bd09d1f5e8b8 --- ext/wasm/GNUmakefile | 17 +++++++++++++++++ ext/wasm/api/README.md | 4 ++++ ext/wasm/api/sqlite3-api-glue.js | 5 ----- ext/wasm/api/sqlite3-api-prologue.js | 11 +++++++++++ ext/wasm/tester1.js | 10 ++++------ ext/wasm/version-json.c | 26 ++++++++++++++++++++++++++ manifest | 21 +++++++++++---------- manifest.uuid | 2 +- 8 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 ext/wasm/version-json.c diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index c4c2886da3..45ab3b8386 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -125,6 +125,10 @@ else $(info Development build. Use '$(MAKE) release' for a smaller release build.) endif +version-json: version-json.c $(sqlite3.c) $(MAKEFILE) + $(CC) -O0 -I$(dir.top) -o $@ $(SQLITE_OPT) -DHAVE_MREMAP=0 $< $(sqlite3.c) +CLEAN_FILES := version-json + EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api EXPORTED_FUNCTIONS.api: $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE) @@ -133,11 +137,13 @@ CLEAN_FILES += EXPORTED_FUNCTIONS.api sqlite3-license-version.js := sqlite3-license-version.js sqlite3-license-version-header.js := $(dir.api)/sqlite3-license-version-header.js +sqlite3-api-build-version.js := $(dir.api)/sqlite3-api-build-version.js sqlite3-api.jses := $(sqlite3-license-version.js) sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js sqlite3-api.jses += $(dir.common)/whwasmutil.js sqlite3-api.jses += $(dir.jacc)/jaccwabyt.js sqlite3-api.jses += $(dir.api)/sqlite3-api-glue.js +sqlite3-api.jses += $(sqlite3-api-build-version.js) sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.js sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js sqlite3-api.jses += $(dir.api)/sqlite3-api-opfs.js @@ -146,6 +152,7 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js sqlite3-api.js := sqlite3-api.js CLEAN_FILES += $(sqlite3-api.js) CLEAN_FILES += $(sqlite3-license-version.js) +CLEAN_FILES += $(sqlite3-api-build-version.js) $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) @echo "Making $@..." @for i in $(sqlite3-api.jses); do \ @@ -154,6 +161,16 @@ $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) echo "/* END FILE: $$i */"; \ done > $@ +$(sqlite3-api-build-version.js): version-json + @echo "Making $@..." + @{ \ + echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \ + echo -n ' sqlite3.version = '; \ + ./version-json; \ + echo ';'; \ + echo '});'; \ + } > $@ + ######################################################################## # --post-js and --pre-js are emcc flags we use to append/prepend JS to # the generated emscripten module file. diff --git a/ext/wasm/api/README.md b/ext/wasm/api/README.md index edac17fa1e..dfb13c569f 100644 --- a/ext/wasm/api/README.md +++ b/ext/wasm/api/README.md @@ -48,6 +48,10 @@ browser client: Invokes functionality exposed by the previous two files to flesh out low-level parts of `sqlite3-api-prologue.js`. Most of these pieces related to the `sqlite3.capi.wasm` object. +- `sqlite3-api-build-version.js`\ + Gets created by the build process and populates the + `sqlite3.version` object. This part is not critical, but records the + version of the library against which this module was built. - `sqlite3-api-oo1.js`\ Provides a high-level object-oriented wrapper to the lower-level C API, colloquially known as OO API #1. Its API is similar to other diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index fd1f0c3e02..bfacef3b3c 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -688,9 +688,4 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } }/*kvvfs*/ - sqlite3.version = Object.assign(Object.create(null),{ - library: sqlite3.capi.sqlite3_libversion(), - sourceId: sqlite3.capi.sqlite3_sourceid() - }); }); - diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index a267e93454..7d9ae96914 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -1281,6 +1281,17 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( SQLite3Error: SQLite3Error, capi, config, + /** + Holds the version info of the sqlite3 source tree from which + the generated sqlite3-api.js gets built. Note that its version + may well differ from that reported by sqlite3_libversion(), but + that should be considered a source file mismatch, as the JS and + WASM files are intended to be built and distributed together. + + This object is initially a placeholder which gets replaced by a + build-generated object. + */ + version: Object.create(null), /** Performs any optional asynchronous library-level initialization which might be required. This function returns a Promise which diff --git a/ext/wasm/tester1.js b/ext/wasm/tester1.js index 37a992d619..72991c451c 100644 --- a/ext/wasm/tester1.js +++ b/ext/wasm/tester1.js @@ -696,10 +696,10 @@ if(autoResolvePtr){ wts.$ppV = 0; T.assert(!wts.$ppV); - WTStruct.debugFlags(0x03); + //WTStruct.debugFlags(0x03); wts.$ppV = wts; T.assert(wts === wts.$ppV) - WTStruct.debugFlags(0); + //WTStruct.debugFlags(0); } wts.setMemberCString('cstr', "A C-string."); T.assert(Array.isArray(wts.ondispose)). @@ -1022,7 +1022,7 @@ ;/*end of C/WASM utils checks*/ //////////////////////////////////////////////////////////////////////// - T.g('sqlite3.oo1 sanity checks') + T.g('sqlite3.oo1') .t('Create db', function(sqlite3){ const db = this.db = new sqlite3.oo1.DB(); T.assert(Number.isInteger(db.pointer)). @@ -1037,8 +1037,7 @@ }) //////////////////////////////////////////////////////////////////// - .t('DB.Stmt sanity checks', function(S){ - let pId; + .t('DB.Stmt', function(S){ let st = this.db.prepare( new TextEncoder('utf-8').encode("select 3 as a") ); @@ -1073,7 +1072,6 @@ .assert(false===st.step()) .assert(!st._mayGet) ; - pId = st.pointer; T.assert(0===capi.sqlite3_strglob("*.txt", "foo.txt")). assert(0!==capi.sqlite3_strglob("*.txt", "foo.xtx")). assert(0===capi.sqlite3_strlike("%.txt", "foo.txt", 0)). diff --git a/ext/wasm/version-json.c b/ext/wasm/version-json.c new file mode 100644 index 0000000000..cb5083a40a --- /dev/null +++ b/ext/wasm/version-json.c @@ -0,0 +1,26 @@ +/* +** 2022-10-16 +** +** The author disclaims copyright to this source code. In place of a +** legal notice, here is a blessing: +** +** * May you do good and not evil. +** * May you find forgiveness for yourself and forgive others. +** * May you share freely, never taking more than you give. +** +************************************************************************* +** This file simply outputs sqlite3 version information in JSON form, +** intended for embedding in the sqlite3 JS API build. +*/ +#include +#include "sqlite3.h" +int main(int argc, char const * const * argv){ + if(argc || argv){/*unused*/} + printf("{\"libVersion\": \"%s\", " + "\"libVersionNumber\": %d, " + "\"sourceId\": \"%s\"}"/*missing newline is intentional*/, + SQLITE_VERSION, + SQLITE_VERSION_NUMBER, + SQLITE_SOURCE_ID); + return 0; +} diff --git a/manifest b/manifest index 2f0d88b24d..6e78bd13e1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stop-level\slicense\sand\sbuild-time\sversion\sinfo\sheader\sto\sgenerated\ssqlite3*.js.\sCorrect\sa\sbroken\slink\sin\sext/wasm/index.html. -D 2022-10-16T15:38:03.833 +C JS:\sadd\sbuild-time-generated\sversion\sinfo\sto\sthe\ssqlite3.version\sobject.\sRemove\ssome\sstray\sdebug\soutput\sfrom\stester1.js. +D 2022-10-16T16:38:15.159 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -473,21 +473,21 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0 -F ext/wasm/GNUmakefile e298b8a91fab19b758fc9e843601d50129afec1e5a6fcf4328affe3f34f40b3e +F ext/wasm/GNUmakefile ce1eb95ca32b23ce3400b26e99c23f6b2737a5356cb4eff2b8b364d7630a8cc9 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 -F ext/wasm/api/README.md 62758e8dd98741d41505f69130cc767013d2e871ebb9e4313d8f8b97d95071d8 +F ext/wasm/api/README.md 946398dd80bfd673f098b9d6ca3564e1fc77b03e660274d132f267c407b8703c F ext/wasm/api/extern-post-js.js dfae3a5f621ae94f1fae671f8013ed6464355f11e2adda38ed8b10bf1929f337 F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1ecc5ba9e64ef90a8b F ext/wasm/api/pre-js.js 5b550904322d73127badd4347ca967ea525b901573559736f92d326ad9b7bb76 F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383bd7ee0de0178b1b3e988588 -F ext/wasm/api/sqlite3-api-glue.js 842dc03783aecc951a543a209523343a6fda9af258fb0bee08e8cc2dc3c4d8ae +F ext/wasm/api/sqlite3-api-glue.js 05eb701460bb72edbe3bf923bd51262551614612c37802fc597eabb4c6b83232 F ext/wasm/api/sqlite3-api-oo1.js 00f5cfce0989d2e08d7b21765d703c69234245d03a0cce8fcb32ccfcd53ffdbb F ext/wasm/api/sqlite3-api-opfs.js 5a8ab3b76880c8ada8710ca9ba1ca5b160872edfd8bd5322e4f179a7f41cc616 -F ext/wasm/api/sqlite3-api-prologue.js b7c82a22d50658a48463fa646a23135273bc2cfa843aedda32627ff281c12e4d +F ext/wasm/api/sqlite3-api-prologue.js a17b35814c6399a2e69c7836e5fd2eaa71f755ee51f96cb69d68cbf99985d45b F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8 F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 @@ -527,12 +527,13 @@ F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33 F ext/wasm/test-opfs-vfs.js 56c3d725044c668fa7910451e96c1195d25ad95825f9ac79f747a7759d1973d0 F ext/wasm/tester1-worker.html 0af7a22025ff1da72a84765d64f8f221844a57c6e6e314acf3a30f176101fd3f F ext/wasm/tester1.html fde0e0bdeaaa2c39877c749dc86a8c1c306f771c3d75b89a6289a5ed11243e9d -F ext/wasm/tester1.js d6a66fc36c7571b8050314b6d0e93e69cd6def88df14fb3ef2403e7aa244ec36 +F ext/wasm/tester1.js fd333bc7608a91c86ae6147aa489840c06f4131119cc26d66976874a50da7cab F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893 F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9dd8ae2cc8719b506b6e013e F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3 F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494 +F ext/wasm/version-json.c 03c6fb4efefd7c5b14f618b36648e71da741e39059ea5059c39495fdceaed144 F ext/wasm/wasmfs.make 3cce1820006196de140f90f2da4b4ea657083fb5bfee7d125be43f7a85748c8f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 @@ -2032,8 +2033,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 ed14863dd72e35fa3a23320c3d5a8166515faea39a555c28a27b2d35e701eac4 -R 664fdd2b5e755302311ec6a1ceb0cf59 +P 0f1a06e8e39a1fbc74f1aff9cc59787282dfbf847d6c5c7edb3f7d410db0e4b7 +R 33971fddc9aa38f4e82f55e933f782a8 U stephan -Z 70648a34d9cd28a66a6a4694b2eeaced +Z 0dd1ff3eef43ed68b7aa15bcdfe291e6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0ece5330b0..5d2cd089f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f1a06e8e39a1fbc74f1aff9cc59787282dfbf847d6c5c7edb3f7d410db0e4b7 \ No newline at end of file +b5f462c2d85d503f6492ec20580d57cb4c926712f6306a6be764bd09d1f5e8b8 \ No newline at end of file From 824bb5b8db88d064640a8e9d72b2204b916433e0 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 16 Oct 2022 18:50:55 +0000 Subject: [PATCH 07/65] Add aggregate function support to sqlite3.oo1.DB.createFunction(). Change signature of the options object used by that function so that the callback property names match those of the corresponding C APIs. FossilOrigin-Name: a7db6e4b50beebfb1c97e0c4de49538d8199c166b18a0b1b175736c593128a00 --- ext/wasm/api/sqlite3-api-oo1.js | 111 +++++++++++++++++++++++--------- ext/wasm/demo-123.js | 2 +- ext/wasm/tester1.js | 69 ++++++++++++++++++-- manifest | 16 ++--- manifest.uuid | 2 +- 5 files changed, 151 insertions(+), 49 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index fa6c6d8e5f..f775406756 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -45,8 +45,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /** If object opts has _its own_ property named p then that property's value is returned, else dflt is returned. */ - const getOwnOption = (opts, p, dflt)=> - opts.hasOwnProperty(p) ? opts[p] : dflt; + const getOwnOption = (opts, p, dflt)=>{ + const d = Object.getOwnPropertyDescriptor(opts,p); + return d ? d.value : dflt; + }; // Documented in DB.checkRc() const checkSqlite3Rc = function(dbPtr, sqliteResultCode){ @@ -810,12 +812,14 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ `xFunc` to align with the C API documentation). In the final case, the function's name must be the 'name' property. - This can currently only be used to create scalar functions, not - aggregate or window functions (requires only a bit of - refactoring to support aggregates and window functions). + The first two call forms can only be used for creating scalar + functions. Creating an aggregate function requires the + options-object form (see below for details). UDFs cannot currently be removed from a DB handle after they're - added. + added. More correctly, they can be removed as documented for + sqlite3_create_function_v2(), but doing so will "leak" the + JS-created WASM binding of those functions. On success, returns this object. Throws on error. @@ -825,18 +829,35 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ cannot be determined. The docs for sqlite3_create_function_v2() describe the conversions in more detail. + The values set in the options object differ for scalar and + aggregate functions: + + - Scalar: set the `xFunc` function-type property to the UDF + function. + + - Aggregate: set the `xStep` and `xFinal` function-type + properties to the "step" and "final" callbacks for the + aggregate. Do not set the `xFunc` property. + + The options object may optionally have an `xDestroy` + function-type property, as per + sqlite3_create_function_v2(). Its argument will be the + WASM-pointer-type value of the `pApp` property, and this + function will throw if `pApp` is defined but is not null, + undefined, or a numeric (WASM pointer) value. + The optional options object may contain flags to modify how the function is defined: - - .arity: the number of arguments which SQL calls to this - function expect or require. The default value is - `callback.length` (i.e. the number of declared parameters it - has) **MINUS 1** (see below for why). As a special case, if - callback.length is 0, its arity is also 0 instead of -1. A - negative arity value means that the function is variadic and - may accept any number of arguments, up to sqlite3's - compile-time limits. sqlite3 will enforce the argument count if - is zero or greater. + - `arity`: the number of arguments which SQL calls to this + function expect or require. The default value is `xFunc.length` + or `xStep.length` (i.e. the number of declared parameters it + has) **MINUS 1** (see below for why). As a special case, if the + `length` is 0, its arity is also 0 instead of -1. A negative + arity value means that the function is variadic and may accept + any number of arguments, up to sqlite3's compile-time + limits. sqlite3 will enforce the argument count if is zero or + greater. The callback always receives a pointer to an `sqlite3_context` object as its first argument. Any arguments after that are from @@ -852,44 +873,70 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ - .deterministic = SQLITE_DETERMINISTIC - .directOnly = SQLITE_DIRECTONLY - .innocuous = SQLITE_INNOCUOUS - - TODO: for the (optionsObject) form, accept callbacks for - aggregate and window functions. - */ - createFunction: function f(name, callback, opt){ + createFunction: function f(name, xFunc, opt){ + let xStep, xFinal; + const isFunc = (f)=>(f instanceof Function); switch(arguments.length){ case 1: /* (optionsObject) */ opt = name; name = opt.name; - callback = opt.xFunc || opt.callback; + xFunc = opt.xFunc; break; case 2: /* (name, callback|optionsObject) */ - if(!(callback instanceof Function)){ - opt = callback; - callback = opt.xFunc || opt.callback; + if(!isFunc(xFunc)){ + opt = xFunc; + xFunc = opt.xFunc; } break; + case 3: /* name, xFunc, opt */ + break; default: break; } if(!opt) opt = {}; - if(!(callback instanceof Function)){ - toss3("Invalid arguments: expecting a callback function."); - }else if('string' !== typeof name){ + if('string' !== typeof name){ toss3("Invalid arguments: missing function name."); } + xStep = opt.xStep; + xFinal = opt.xFinal; + if(isFunc(xFunc)){ + if(isFunc(xStep) || isFunc(xFinal)){ + toss3("Ambiguous arguments: scalar or aggregate?"); + } + xStep = xFinal = null; + }else if(isFunc(xStep)){ + if(!isFunc(xFinal)){ + toss3("Missing xFinal() callback for aggregate UDF."); + } + xFunc = null; + }else if(isFunc(xFinal)){ + toss3("Missing xStep() callback for aggregate UDF."); + }else{ + toss3("Missing function-type properties."); + } + const pApp = opt.pApp; + if(undefined!==pApp && (('number'!==typeof pApp) + || !capi.util.isInt32(pApp))){ + toss3("Invalid value for pApp property. Must be a legal WASM pointer value."); + } + const xDestroy = opt.xDestroy; + if(xDestroy && !isFunc(xDestroy)){ + toss3("xDestroy property must be a function."); + } let fFlags = 0 /*flags for sqlite3_create_function_v2()*/; if(getOwnOption(opt, 'deterministic')) fFlags |= capi.SQLITE_DETERMINISTIC; if(getOwnOption(opt, 'directOnly')) fFlags |= capi.SQLITE_DIRECTONLY; if(getOwnOption(opt, 'innocuous')) fFlags |= capi.SQLITE_INNOCUOUS; name = name.toLowerCase(); + const xArity = xFunc || xStep; + const arity = getOwnOption(opt, 'arity'); DB.checkRc(this, capi.sqlite3_create_function_v2( this.pointer, name, - (opt.hasOwnProperty('arity') - ? +opt.arity - : (callback.length ? callback.length-1/*for pCtx arg*/ : 0)), - capi.SQLITE_UTF8 | fFlags, null/*pApp*/, callback, - null/*xStep*/, null/*xFinal*/, null/*xDestroy*/)); + ('number'===typeof arity + ? arity + : (xArity.length ? xArity.length-1/*for pCtx arg*/ : 0)), + capi.SQLITE_UTF8 | fFlags, pApp, + xFunc, xStep, xFinal, xDestroy)); return this; }/*createFunction()*/, /** diff --git a/ext/wasm/demo-123.js b/ext/wasm/demo-123.js index ff36aaf4e2..04a999488a 100644 --- a/ext/wasm/demo-123.js +++ b/ext/wasm/demo-123.js @@ -160,7 +160,7 @@ log("Create a scalar UDF..."); db.createFunction({ name: 'twice', - callback: function(pCx, arg){ // note the call arg count + xFunc: function(pCx, arg){ // note the call arg count return arg + arg; } }); diff --git a/ext/wasm/tester1.js b/ext/wasm/tester1.js index 72991c451c..aef9d2301b 100644 --- a/ext/wasm/tester1.js +++ b/ext/wasm/tester1.js @@ -1179,14 +1179,14 @@ assert(5===db.selectValue("select foo($a,$b)",{$a:0,$b:5})); db.createFunction("bar", { arity: -1, - callback: function(pCx){ - var rc = 0; - for(let i = 1; i < arguments.length; ++i) rc += arguments[i]; + xFunc: (pCx,...args)=>{ + let rc = 0; + for(const v of args) rc += v; return rc; } }).createFunction({ name: "asis", - callback: (pCx,arg)=>arg + xFunc: (pCx,arg)=>arg }); T.assert(0===db.selectValue("select bar()")). assert(1===db.selectValue("select bar(1)")). @@ -1225,9 +1225,64 @@ //////////////////////////////////////////////////////////////////// .t({ - name: 'Aggregate UDFs (tests are TODO)', - predicate: testIsTodo - }) + name: 'Aggregate UDFs', + test: function(sqlite3){ + const db = this.db; + const aggState = {summer: 0, summerN: 0}; + db.createFunction({ + name: 'summer', + xStep: function(pCtx, n){ + aggState.summer += n; + }, + xFinal: function(pCtx){ + const rc = aggState.summer; + aggState.summer = 0; + return rc; + } + }); + let v = db.selectValue([ + "with cte(v) as (", + "select 3 union all select 5 union all select 7", + ") select summer(v) from cte" + ]); + T.assert(15===v); + T.mustThrowMatching(()=>db.selectValue("select summer(1,2)"), + /wrong number of arguments/); + db.createFunction({ + name: 'summerN', + arity: -1, + xStep: function(pCtx, ...args){ + for(const v of args) aggState.summerN += v; + }, + xFinal: function(pCtx){ + const rc = aggState.summerN; + aggState.summerN = 0; + return rc; + } + }); + T.assert(18===db.selectValue('select summerN(1,8,9)')); + T.mustThrowMatching(()=>{ + db.createFunction('nope',{ + xFunc: ()=>{}, xStep: ()=>{} + }); + }, /scalar or aggregate\?/); + T.mustThrowMatching(()=>{ + db.createFunction('nope',{xStep: ()=>{}}); + }, /Missing xFinal/); + T.mustThrowMatching(()=>{ + db.createFunction('nope',{xFinal: ()=>{}}); + }, /Missing xStep/); + T.mustThrowMatching(()=>{ + db.createFunction('nope',{}); + }, /Missing function-type properties/); + T.mustThrowMatching(()=>{ + db.createFunction('nope',{xFunc:()=>{}, xDestroy:'nope'}); + }, /xDestroy property must be a function/); + T.mustThrowMatching(()=>{ + db.createFunction('nope',{xFunc:()=>{}, pApp:'nope'}); + }, /Invalid value for pApp/); + } + }/*aggregate UDFs*/) //////////////////////////////////////////////////////////////////// .t({ diff --git a/manifest b/manifest index 6e78bd13e1..00b073fd77 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C JS:\sadd\sbuild-time-generated\sversion\sinfo\sto\sthe\ssqlite3.version\sobject.\sRemove\ssome\sstray\sdebug\soutput\sfrom\stester1.js. -D 2022-10-16T16:38:15.159 +C Add\saggregate\sfunction\ssupport\sto\ssqlite3.oo1.DB.createFunction().\sChange\ssignature\sof\sthe\soptions\sobject\sused\sby\sthat\sfunction\sso\sthat\sthe\scallback\sproperty\snames\smatch\sthose\sof\sthe\scorresponding\sC\sAPIs. +D 2022-10-16T18:50:55.647 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -485,7 +485,7 @@ F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1 F ext/wasm/api/pre-js.js 5b550904322d73127badd4347ca967ea525b901573559736f92d326ad9b7bb76 F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383bd7ee0de0178b1b3e988588 F ext/wasm/api/sqlite3-api-glue.js 05eb701460bb72edbe3bf923bd51262551614612c37802fc597eabb4c6b83232 -F ext/wasm/api/sqlite3-api-oo1.js 00f5cfce0989d2e08d7b21765d703c69234245d03a0cce8fcb32ccfcd53ffdbb +F ext/wasm/api/sqlite3-api-oo1.js f7f1fa6e6364347e99d0619ac1d3766dabab1e114cdf343259f38372576b6650 F ext/wasm/api/sqlite3-api-opfs.js 5a8ab3b76880c8ada8710ca9ba1ca5b160872edfd8bd5322e4f179a7f41cc616 F ext/wasm/api/sqlite3-api-prologue.js a17b35814c6399a2e69c7836e5fd2eaa71f755ee51f96cb69d68cbf99985d45b F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8 @@ -500,7 +500,7 @@ F ext/wasm/common/testing.css 53394885077edd3db22d2a0896192334dfc06fb3d1da0b646e F ext/wasm/common/whwasmutil.js 50d2ede0b0fa01c1d467e1801fab79f5e46bb02bcbd2b0232e4fdc6090a47818 F ext/wasm/demo-123-worker.html e50b51dc7271b9d3cc830cb7c2fba294d622f56b7acb199f7257d11195a63d49 F ext/wasm/demo-123.html 7c239c9951d1b113f9f532969ac039294cf1dcfee2b3ae0a2c1ed2b3d59f8dfa -F ext/wasm/demo-123.js d563cf9d725692ccd940c46df1c026d87863e0544942a2ba2015f17fba3f6f74 +F ext/wasm/demo-123.js e0cbeb3495e14103763d5c49794a24d67cf3d78e0ed5b82843be70c0c2ee4b3b F ext/wasm/demo-kvvfs1.html 7d4f28873de67f51ac18c584b7d920825139866a96049a49c424d6f5a0ea5e7f F ext/wasm/demo-kvvfs1.js 105596bd2ccd0b1deb5fde8e99b536e8242d4bb5932fac0c8403ff3a6bc547e8 F ext/wasm/fiddle.make 3f4efd62bc2a9c883bfcea52ae2755114a62d444d6d042df287f4aef301d6c6c @@ -527,7 +527,7 @@ F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33 F ext/wasm/test-opfs-vfs.js 56c3d725044c668fa7910451e96c1195d25ad95825f9ac79f747a7759d1973d0 F ext/wasm/tester1-worker.html 0af7a22025ff1da72a84765d64f8f221844a57c6e6e314acf3a30f176101fd3f F ext/wasm/tester1.html fde0e0bdeaaa2c39877c749dc86a8c1c306f771c3d75b89a6289a5ed11243e9d -F ext/wasm/tester1.js fd333bc7608a91c86ae6147aa489840c06f4131119cc26d66976874a50da7cab +F ext/wasm/tester1.js 8161dcc4b21902dadec2d3a5dc5700cab9c1641db0603e2ea56ea2a8de6cbab3 F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893 F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9dd8ae2cc8719b506b6e013e F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae @@ -2033,8 +2033,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 0f1a06e8e39a1fbc74f1aff9cc59787282dfbf847d6c5c7edb3f7d410db0e4b7 -R 33971fddc9aa38f4e82f55e933f782a8 +P b5f462c2d85d503f6492ec20580d57cb4c926712f6306a6be764bd09d1f5e8b8 +R dc71c7ee6cfc588ad89cef2f6b6a3e75 U stephan -Z 0dd1ff3eef43ed68b7aa15bcdfe291e6 +Z 295c02a265fc3379708e7d138c173321 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5d2cd089f9..f04ed5fbac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b5f462c2d85d503f6492ec20580d57cb4c926712f6306a6be764bd09d1f5e8b8 \ No newline at end of file +a7db6e4b50beebfb1c97e0c4de49538d8199c166b18a0b1b175736c593128a00 \ No newline at end of file From 2676fc58c86a497f8f2510dfe48e843d7371d88b Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 16 Oct 2022 18:57:15 +0000 Subject: [PATCH 08/65] Minor tweak to get bring an edge case of oo1.DB.createFunction() into aggreement with its docs. FossilOrigin-Name: 8d59ccd9f357fbed0b0790508ca9027194fc4b0131029f9f460c7b4bde806a5f --- ext/wasm/api/sqlite3-api-oo1.js | 5 +++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index f775406756..f1014fcc00 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -915,8 +915,9 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ toss3("Missing function-type properties."); } const pApp = opt.pApp; - if(undefined!==pApp && (('number'!==typeof pApp) - || !capi.util.isInt32(pApp))){ + if(undefined!==pApp && + null!==pApp && + (('number'!==typeof pApp) || !capi.util.isInt32(pApp))){ toss3("Invalid value for pApp property. Must be a legal WASM pointer value."); } const xDestroy = opt.xDestroy; diff --git a/manifest b/manifest index 00b073fd77..d7401cafab 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\saggregate\sfunction\ssupport\sto\ssqlite3.oo1.DB.createFunction().\sChange\ssignature\sof\sthe\soptions\sobject\sused\sby\sthat\sfunction\sso\sthat\sthe\scallback\sproperty\snames\smatch\sthose\sof\sthe\scorresponding\sC\sAPIs. -D 2022-10-16T18:50:55.647 +C Minor\stweak\sto\sget\sbring\san\sedge\scase\sof\soo1.DB.createFunction()\sinto\saggreement\swith\sits\sdocs. +D 2022-10-16T18:57:15.939 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -485,7 +485,7 @@ F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1 F ext/wasm/api/pre-js.js 5b550904322d73127badd4347ca967ea525b901573559736f92d326ad9b7bb76 F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383bd7ee0de0178b1b3e988588 F ext/wasm/api/sqlite3-api-glue.js 05eb701460bb72edbe3bf923bd51262551614612c37802fc597eabb4c6b83232 -F ext/wasm/api/sqlite3-api-oo1.js f7f1fa6e6364347e99d0619ac1d3766dabab1e114cdf343259f38372576b6650 +F ext/wasm/api/sqlite3-api-oo1.js 9a5f0c00d476c504f16dcd456e1743dbc2826ca3d10645dfa62663a39e3ed0d8 F ext/wasm/api/sqlite3-api-opfs.js 5a8ab3b76880c8ada8710ca9ba1ca5b160872edfd8bd5322e4f179a7f41cc616 F ext/wasm/api/sqlite3-api-prologue.js a17b35814c6399a2e69c7836e5fd2eaa71f755ee51f96cb69d68cbf99985d45b F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8 @@ -2033,8 +2033,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 b5f462c2d85d503f6492ec20580d57cb4c926712f6306a6be764bd09d1f5e8b8 -R dc71c7ee6cfc588ad89cef2f6b6a3e75 +P a7db6e4b50beebfb1c97e0c4de49538d8199c166b18a0b1b175736c593128a00 +R 3422110515a596def98dff69dd1bdfc7 U stephan -Z 295c02a265fc3379708e7d138c173321 +Z eb1680ea30bd7067803bb7e8ee35441a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f04ed5fbac..946bd8b7e8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a7db6e4b50beebfb1c97e0c4de49538d8199c166b18a0b1b175736c593128a00 \ No newline at end of file +8d59ccd9f357fbed0b0790508ca9027194fc4b0131029f9f460c7b4bde806a5f \ No newline at end of file From e493f8f0cd2f04a7ef84c06dfef0040db3f6cf64 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 16 Oct 2022 23:33:24 +0000 Subject: [PATCH 09/65] Typo fix. FossilOrigin-Name: 650126c92aa191d6361a32ec90ca7def60a2df22ba6bec1d2354692fe3504423 --- ext/wasm/index.html | 11 +++++------ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ext/wasm/index.html b/ext/wasm/index.html index a7f0974fbe..663d4c9240 100644 --- a/ext/wasm/index.html +++ b/ext/wasm/index.html @@ -87,12 +87,11 @@ worker due to an Emscripten limitation.
  • test-opfs-vfs (same - with verbose output and sanity-checking tests) is an - experiment in implementing a syncronous sqlite3 VFS proxy - for a fully asynchronous backend interface (namely OPFS), - using SharedArrayBuffer and the Atomics APIs to regulate - communication between the synchronous interface and the - async impl. + with verbose output and sanity-checking tests) is an + sqlite3_vfs OPFS proxy using SharedArrayBuffer and the + Atomics APIs to regulate communication between the + synchronous sqlite3_vfs interface and the async OPFS + impl.
  • diff --git a/manifest b/manifest index d7401cafab..a206aae7bb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\stweak\sto\sget\sbring\san\sedge\scase\sof\soo1.DB.createFunction()\sinto\saggreement\swith\sits\sdocs. -D 2022-10-16T18:57:15.939 +C Typo\sfix. +D 2022-10-16T23:33:24.941 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -508,7 +508,7 @@ F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d695 F ext/wasm/fiddle/fiddle-worker.js 531859a471924a0ea48afa218e6877f0c164ca324d51e15843ed6ecc1c65c7ee F ext/wasm/fiddle/fiddle.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715 -F ext/wasm/index.html f41ff0b3cef07196b18f3f917c46560a0d5289064d344b438b254c41ed0f2c76 +F ext/wasm/index.html d75b516236c6869568ff691b9b7ff61307d6436e059b5657dadc473b6f41e581 F ext/wasm/jaccwabyt/jaccwabyt.js 0d7f32817456a0f3937fcfd934afeb32154ca33580ab264dab6c285e6dbbd215 F ext/wasm/jaccwabyt/jaccwabyt.md 9aa6951b529a8b29f578ec8f0355713c39584c92cf1708f63ba0cf917cb5b68e F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e1029186d836d14b83845fbe06 @@ -2033,8 +2033,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 a7db6e4b50beebfb1c97e0c4de49538d8199c166b18a0b1b175736c593128a00 -R 3422110515a596def98dff69dd1bdfc7 +P 8d59ccd9f357fbed0b0790508ca9027194fc4b0131029f9f460c7b4bde806a5f +R 7eb92d13aa47fc635e45e77480d0d518 U stephan -Z eb1680ea30bd7067803bb7e8ee35441a +Z e9d4f2e253f6a0945cb00e8689db7471 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 946bd8b7e8..e7aecb1f4e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d59ccd9f357fbed0b0790508ca9027194fc4b0131029f9f460c7b4bde806a5f \ No newline at end of file +650126c92aa191d6361a32ec90ca7def60a2df22ba6bec1d2354692fe3504423 \ No newline at end of file From 135c9ff6f7077435614e5226dbb5361e33bd1cac Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 17 Oct 2022 09:56:51 +0000 Subject: [PATCH 10/65] Remove a use of alloca() that does more harm than good. FossilOrigin-Name: 2ab3cf4d71b23a4c0b69f977828d82df7bbc080c29ae189e0d78d38efee50c96 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wherecode.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index a206aae7bb..93a3db2696 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Typo\sfix. -D 2022-10-16T23:33:24.941 +C Remove\sa\suse\sof\salloca()\sthat\sdoes\smore\sharm\sthan\sgood. +D 2022-10-17T09:56:51.582 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -708,7 +708,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 63e712bcad47f70e94c2150976cd7da5040933699e3938d4189d064acbe40891 F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 -F src/wherecode.c bb88be457df3a6a01c844074ab79a9ba74279e73185f1362383aa697e3cae5dc +F src/wherecode.c 8ec5a413f12af06638dcca36d0954be2151eea6f293d3c67397cef6a90d6adf1 F src/whereexpr.c 55a39f42aaf982574fbf52906371a84cceed98a994422198dfd03db4fce4cc46 F src/window.c 928e215840e2f2d9a2746e018c9643ef42c66c4ab6630ef0df7fa388fa145e86 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -2033,8 +2033,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 8d59ccd9f357fbed0b0790508ca9027194fc4b0131029f9f460c7b4bde806a5f -R 7eb92d13aa47fc635e45e77480d0d518 -U stephan -Z e9d4f2e253f6a0945cb00e8689db7471 +P 650126c92aa191d6361a32ec90ca7def60a2df22ba6bec1d2354692fe3504423 +R 0976ce63c2884a014f8f48854ee7e700 +U drh +Z eaf9cf4bd31fd72933cff88a3ffeecd2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e7aecb1f4e..ee9a25c253 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -650126c92aa191d6361a32ec90ca7def60a2df22ba6bec1d2354692fe3504423 \ No newline at end of file +2ab3cf4d71b23a4c0b69f977828d82df7bbc080c29ae189e0d78d38efee50c96 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 85d9be5011..c2e7278d1a 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2314,7 +2314,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( int nNotReady; /* The number of notReady tables */ SrcItem *origSrc; /* Original list of tables */ nNotReady = pWInfo->nLevel - iLevel - 1; - pOrTab = sqlite3StackAllocRaw(db, + pOrTab = sqlite3DbMallocRawNN(db, sizeof(*pOrTab)+ nNotReady*sizeof(pOrTab->a[0])); if( pOrTab==0 ) return notReady; pOrTab->nAlloc = (u8)(nNotReady + 1); @@ -2567,7 +2567,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( assert( pLevel->op==OP_Return ); pLevel->p2 = sqlite3VdbeCurrentAddr(v); - if( pWInfo->nLevel>1 ){ sqlite3StackFree(db, pOrTab); } + if( pWInfo->nLevel>1 ){ sqlite3DbFreeNN(db, pOrTab); } if( !untestedTerms ) disableTerm(pLevel, pTerm); }else #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ From ce4b0fdf8a04b2ccaf2a587d0f8d9f3382355d51 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 17 Oct 2022 10:15:41 +0000 Subject: [PATCH 11/65] Make use of alloca() in wherePathSolver() when SQLITE_USE_ALLOCA is defined. FossilOrigin-Name: 45752471521f8d4a6cad4bce40f907018acd403ffd3b8170020c34e4e0b6b91b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqliteInt.h | 4 ++++ src/where.c | 9 +++------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 93a3db2696..f650226ca1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\suse\sof\salloca()\sthat\sdoes\smore\sharm\sthan\sgood. -D 2022-10-17T09:56:51.582 +C Make\suse\sof\salloca()\sin\swherePathSolver()\swhen\sSQLITE_USE_ALLOCA\sis\sdefined. +D 2022-10-17T10:15:41.927 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,7 +624,7 @@ F src/shell.c.in 2915eaf22bda89ad6533851a051de4773c249185360fe1fc7b4477b8f9063b2 F src/sqlite.h.in d9c8a6243fc0a1c270d69db33758e34b810af3462f9bc5b4af113b347e07c69d F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 5336beea1868d99d2f62e628dbea55e97267dbff8193291ab175e960c5df9141 -F src/sqliteInt.h d15694b228fe5082587e13ac14f3e449621a5fe6d5933f5dee6e3c9491260da3 +F src/sqliteInt.h 27916b91f3aafd09d1b50f62948e0d506a58933f4cf5f5c136233658fbd39e60 F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -706,7 +706,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 63e712bcad47f70e94c2150976cd7da5040933699e3938d4189d064acbe40891 +F src/where.c ab74681d07e310fb81c01c2bb1068378764cfff9e431e2b01aacc7a3678a018d F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 F src/wherecode.c 8ec5a413f12af06638dcca36d0954be2151eea6f293d3c67397cef6a90d6adf1 F src/whereexpr.c 55a39f42aaf982574fbf52906371a84cceed98a994422198dfd03db4fce4cc46 @@ -2033,8 +2033,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 650126c92aa191d6361a32ec90ca7def60a2df22ba6bec1d2354692fe3504423 -R 0976ce63c2884a014f8f48854ee7e700 +P 2ab3cf4d71b23a4c0b69f977828d82df7bbc080c29ae189e0d78d38efee50c96 +R fd1636fa451b5b8e84570a9195b2236a U drh -Z eaf9cf4bd31fd72933cff88a3ffeecd2 +Z 2743069ef130a7abdc131b5ac7f77275 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ee9a25c253..d362e0dc32 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2ab3cf4d71b23a4c0b69f977828d82df7bbc080c29ae189e0d78d38efee50c96 \ No newline at end of file +45752471521f8d4a6cad4bce40f907018acd403ffd3b8170020c34e4e0b6b91b \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 6f1109f2f6..05bc6dd4c5 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4391,12 +4391,16 @@ int sqlite3HeapNearlyFull(void); */ #ifdef SQLITE_USE_ALLOCA # define sqlite3StackAllocRaw(D,N) alloca(N) +# define sqlite3StackAllocRawNN(D,N) alloca(N) # define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N) # define sqlite3StackFree(D,P) +# define sqlite3StackFreeNN(D,P) #else # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N) +# define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N) # define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N) # define sqlite3StackFree(D,P) sqlite3DbFree(D,P) +# define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P) #endif /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they diff --git a/src/where.c b/src/where.c index b0c0ea7d4e..2bd3e055db 100644 --- a/src/where.c +++ b/src/where.c @@ -4701,7 +4701,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ int mxChoice; /* Maximum number of simultaneous paths tracked */ int nLoop; /* Number of terms in the join */ Parse *pParse; /* Parsing context */ - sqlite3 *db; /* The database connection */ int iLoop; /* Loop counter over the terms of the join */ int ii, jj; /* Loop counters */ int mxI = 0; /* Index of next entry to replace */ @@ -4720,7 +4719,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ int nSpace; /* Bytes of space allocated at pSpace */ pParse = pWInfo->pParse; - db = pParse->db; nLoop = pWInfo->nLevel; /* TUNING: For simple queries, only the best path is tracked. ** For 2-way joins, the 5 best paths are followed. @@ -4743,7 +4741,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ /* Allocate and initialize space for aTo, aFrom and aSortCost[] */ nSpace = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2; nSpace += sizeof(LogEst) * nOrderBy; - pSpace = sqlite3DbMallocRawNN(db, nSpace); + pSpace = sqlite3StackAllocRawNN(pParse->db, nSpace); if( pSpace==0 ) return SQLITE_NOMEM_BKPT; aTo = (WherePath*)pSpace; aFrom = aTo+mxChoice; @@ -5001,7 +4999,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ if( nFrom==0 ){ sqlite3ErrorMsg(pParse, "no query solution"); - sqlite3DbFreeNN(db, pSpace); + sqlite3StackFreeNN(pParse->db, pSpace); return SQLITE_ERROR; } @@ -5083,8 +5081,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ pWInfo->nRowOut = pFrom->nRow; /* Free temporary memory and return success */ - assert( db!=0 ); - sqlite3DbNNFreeNN(db, pSpace); + sqlite3StackFreeNN(pParse->db, pSpace); return SQLITE_OK; } From 08535840c6a279a69a421a3be3b23fac355d80ac Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 17 Oct 2022 14:30:01 +0000 Subject: [PATCH 12/65] Get the indexed expression optimization working for virtual generated columns. FossilOrigin-Name: 8a510cb0880349370ad19b0852f270ca072bff7871f0dc272964af31c32a7c37 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 1 + src/where.c | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index e2d3074db5..cf96d243eb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\senhancements\sinto\sindex-expr-opt\sbranch. -D 2022-10-17T14:29:04.031 +C Get\sthe\sindexed\sexpression\soptimization\sworking\sfor\svirtual\sgenerated\scolumns. +D 2022-10-17T14:30:01.606 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -561,7 +561,7 @@ F src/btmutex.c 6ffb0a22c19e2f9110be0964d0731d2ef1c67b5f7fabfbaeb7b9dabc4b7740ca F src/btree.c 74fc5f6a0577df703d6f98d0c51ee0d8d91d22dbc0ba86e42e056517e2b45576 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e -F src/build.c e9b3adf21cdae3c9ca9450ee8463f2094f133c23734b81fd371f23b3d5d345ca +F src/build.c 13bcc04821ad260ef00d87e0704424e0ae4e6cd66c7e384b4cedb379a6cb738b F src/callback.c 4cd7225b26a97f7de5fee5ae10464bed5a78f2adefe19534cc2095b3a8ca484a F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 428b47a2548c7c2c2f885189b42fdcc178fb03c276a2d58b3008b10da29373d5 @@ -706,7 +706,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c a1c42bab8e840fa2cc90f6caf0f7133c35972e2f93b5899a90036d85e665c107 +F src/where.c 5d687c1f910b9b52284e0f7881a4d9b0ea9e9902b222dcc38e07a02ebeea3550 F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 F src/wherecode.c 8ec5a413f12af06638dcca36d0954be2151eea6f293d3c67397cef6a90d6adf1 F src/whereexpr.c bf8c155212c886621d71c951053660de6fcc4ee907b17aa02da0a96a39aa9405 @@ -2033,8 +2033,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 462b3c7f39724dc814f55e7a225e7d0c48f81c524cdda797a66e9e198c35ce58 45752471521f8d4a6cad4bce40f907018acd403ffd3b8170020c34e4e0b6b91b -R 6f3970b0a66900429c4532002ac9cf64 +P 56ef97e64efb84176df570819474901d492209ff80ce4355ff896dea9d2b8a51 +R de79047dd54e7d5b7736aaaf7de5ad42 U drh -Z f2ec0a1b95a0b19c496d987488a36bd5 +Z 08d869d5cc79e1976c4600c81c421785 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ff66fa27b1..8e5d83ed47 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -56ef97e64efb84176df570819474901d492209ff80ce4355ff896dea9d2b8a51 \ No newline at end of file +8a510cb0880349370ad19b0852f270ca072bff7871f0dc272964af31c32a7c37 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 502826bfc8..8578a71275 100644 --- a/src/build.c +++ b/src/build.c @@ -4204,6 +4204,7 @@ void sqlite3CreateIndex( } if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){ pIndex->bHasVCol = 1; + pIndex->bHasExpr = 1; } } pIndex->aiColumn[i] = (i16)j; diff --git a/src/where.c b/src/where.c index c5a6438791..32daa6e80e 100644 --- a/src/where.c +++ b/src/where.c @@ -5413,12 +5413,23 @@ static SQLITE_NOINLINE void whereAddIndexExpr( ){ int i; IndexExpr *p; + Table *pTab; + assert( pIdx->bHasExpr ); + pTab = pIdx->pTable; for(i=0; inColumn; i++){ - if( pIdx->aiColumn[i]!=XN_EXPR ) continue; + Expr *pExpr; + int j = pIdx->aiColumn[i]; + if( j==XN_EXPR ){ + pExpr = pIdx->aColExpr->a[i].pExpr; + }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){ + pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]); + }else{ + continue; + } p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexExpr)); if( p==0 ) break; p->pIENext = pParse->pIdxExpr; - p->pExpr = sqlite3ExprDup(pParse->db, pIdx->aColExpr->a[i].pExpr, 0); + p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); p->iDataCur = pTabItem->iCursor; p->iIdxCur = iIdxCur; p->iIdxCol = i; From e70d458340146bf20cc48224b8ddd9a18120d3c0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 17 Oct 2022 14:46:39 +0000 Subject: [PATCH 13/65] Improved comments and function names. No logic changes. FossilOrigin-Name: 8f460b3b15bf4b88a224907d2f83e4ed6bf84d6b3f480008a1b187ea49c6ce1d --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 12 ++++++------ src/sqliteInt.h | 26 ++++++++++++++------------ src/where.c | 20 ++++++++++---------- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/manifest b/manifest index cf96d243eb..99d55d9f43 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Get\sthe\sindexed\sexpression\soptimization\sworking\sfor\svirtual\sgenerated\scolumns. -D 2022-10-17T14:30:01.606 +C Improved\scomments\sand\sfunction\snames.\s\sNo\slogic\schanges. +D 2022-10-17T14:46:39.146 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -569,7 +569,7 @@ F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5 F src/dbpage.c 5808e91bc27fa3981b028000f8fadfdc10ce9e59a34ce7dc4e035a69be3906ec F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e -F src/expr.c 4a13a0e5c30be801b0adc295ef74e0f1aa8c041aefdcb5d0d424337ecefa2806 +F src/expr.c ba67701bd7621ebba9c472fcc2dbd4f6444260530e694fa9d87281f9aedec93c F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 722f20779f5342a787922deded3628d8c74b5249cab04098cf17ee2f2aaff002 F src/func.c fe2a795ad647ce42054873ac91c43beb7b5d204892903a67f6e7e314379b9d4a @@ -624,7 +624,7 @@ F src/shell.c.in 2915eaf22bda89ad6533851a051de4773c249185360fe1fc7b4477b8f9063b2 F src/sqlite.h.in d9c8a6243fc0a1c270d69db33758e34b810af3462f9bc5b4af113b347e07c69d F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 5336beea1868d99d2f62e628dbea55e97267dbff8193291ab175e960c5df9141 -F src/sqliteInt.h 2a182a906ac614eb240a68abba8eaf4b018693fd2410ddaa133c08de00507e0a +F src/sqliteInt.h ed402c12a8b0920ae28cf79631d31490376ca3eed76b386b646712a1dda9e945 F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -706,7 +706,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 5d687c1f910b9b52284e0f7881a4d9b0ea9e9902b222dcc38e07a02ebeea3550 +F src/where.c 3ab52180ad3a4eea7a2061bd804850f443298adbdc9264642d0a28affe26fb4c F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 F src/wherecode.c 8ec5a413f12af06638dcca36d0954be2151eea6f293d3c67397cef6a90d6adf1 F src/whereexpr.c bf8c155212c886621d71c951053660de6fcc4ee907b17aa02da0a96a39aa9405 @@ -2033,8 +2033,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 56ef97e64efb84176df570819474901d492209ff80ce4355ff896dea9d2b8a51 -R de79047dd54e7d5b7736aaaf7de5ad42 +P 8a510cb0880349370ad19b0852f270ca072bff7871f0dc272964af31c32a7c37 +R 2b7b8043aec8092eea598ea28e3a1178 U drh -Z 08d869d5cc79e1976c4600c81c421785 +Z e241a4932bd8de7b16432b2f0cb5fca6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8e5d83ed47..6dd4259d17 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8a510cb0880349370ad19b0852f270ca072bff7871f0dc272964af31c32a7c37 \ No newline at end of file +8f460b3b15bf4b88a224907d2f83e4ed6bf84d6b3f480008a1b187ea49c6ce1d \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 4bff004119..30f9031e21 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4044,17 +4044,17 @@ static int exprCodeInlineFunction( } /* -** Check to see if pExpr is one of the indexed expression on pParse->pIdxExpr. +** Check to see if pExpr is one of the indexed expressions on pParse->pIdxExpr. ** If it is, then resolve the expression by reading from the index and -** return the register into which the value has been read. If there is -** no match, return negative. +** return the register into which the value has been read. If pExpr is +** not an indexed expression, then return negative. */ -static SQLITE_NOINLINE int sqlite3ExprIndexLookup( +static SQLITE_NOINLINE int sqlite3IndexedExprLookup( Parse *pParse, /* The parsing context */ Expr *pExpr, /* The expression to potentially bypass */ int target /* Where to store the result of the expression */ ){ - IndexExpr *p; + IndexedExpr *p; Vdbe *v; for(p=pParse->pIdxExpr; p; p=p->pIENext){ if( p->iDataCur<0 ) continue; @@ -4111,7 +4111,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ if( pParse->pIdxExpr!=0 && pExpr!=0 && !ExprHasProperty(pExpr, EP_Leaf) - && (r1 = sqlite3ExprIndexLookup(pParse, pExpr, target))>=0 + && (r1 = sqlite3IndexedExprLookup(pParse, pExpr, target))>=0 ){ return r1; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8b9bdf474a..0e02db8cc8 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1189,7 +1189,7 @@ typedef struct FuncDef FuncDef; typedef struct FuncDefHash FuncDefHash; typedef struct IdList IdList; typedef struct Index Index; -typedef struct IndexExpr IndexExpr; +typedef struct IndexedExpr IndexedExpr; typedef struct IndexSample IndexSample; typedef struct KeyClass KeyClass; typedef struct KeyInfo KeyInfo; @@ -2617,7 +2617,8 @@ struct Index { unsigned bNoQuery:1; /* Do not use this index to optimize queries */ unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */ unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */ - unsigned bHasExpr:1; /* This is an index on an expression */ + unsigned bHasExpr:1; /* Index contains an expression, either a literal + ** expression, or a reference to a VIRTUAL column */ #ifdef SQLITE_ENABLE_STAT4 int nSample; /* Number of elements in aSample[] */ int nSampleCol; /* Size of IndexSample.anEq[] and so on */ @@ -3566,21 +3567,22 @@ struct TriggerPrg { #endif /* -** If there is an index on an expression in scope such that the value -** of the expression pExpr can be read out of the index with cursor iCur -** at column iCol, then an instance of this object records that fact. +** For each index X that has as one of its arguments either an expression +** or the name of a virtual generated column, and if X is in scope such that +** the value of the expression can simply be read from the index, then +** there is an instance of this object on the Parse.pIdxExpr list. ** -** A linked list of these objects is attached to Parse and records all -** expressions that can be short-circuited by extracting a valid from -** an index. +** During code generation, while generating code to evaluate expressions, +** this list is consulted and if a matching expression is found, the value +** is read from the index rather than being recomputed. */ -struct IndexExpr { +struct IndexedExpr { Expr *pExpr; /* The expression contained in the index */ int iDataCur; /* The data cursor associated with the index */ int iIdxCur; /* The index cursor */ - int iIdxCol; /* The column of the index that contains pExpr */ + int iIdxCol; /* The index column that contains value of pExpr */ u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */ - IndexExpr *pIENext; /* Next in a list of all indexed expressions */ + IndexedExpr *pIENext; /* Next in a list of all indexed expressions */ }; /* @@ -3641,7 +3643,7 @@ struct Parse { int nLabelAlloc; /* Number of slots in aLabel */ int *aLabel; /* Space to hold the labels */ ExprList *pConstExpr;/* Constant expressions */ - IndexExpr *pIdxExpr; /* List of all expression in active indexes */ + IndexedExpr *pIdxExpr;/* List of expressions used by active indexes */ Token constraintName;/* Name of the constraint currently being parsed */ yDbMask writeMask; /* Start a write transaction on these databases */ yDbMask cookieMask; /* Bitmask of schema verified databases */ diff --git a/src/where.c b/src/where.c index 32daa6e80e..39bbf7d64c 100644 --- a/src/where.c +++ b/src/where.c @@ -5384,10 +5384,10 @@ static SQLITE_NOINLINE void whereCheckIfBloomFilterIsUseful( ** This is an sqlite3ParserAddCleanup() callback that is invoked to ** free the Parse->pIdxExpr list when the Parse object is destroyed. */ -static void whereIndexExprCleanup(sqlite3 *db, void *pObject){ +static void whereIndexedExprCleanup(sqlite3 *db, void *pObject){ Parse *pParse = (Parse*)pObject; while( pParse->pIdxExpr!=0 ){ - IndexExpr *p = pParse->pIdxExpr; + IndexedExpr *p = pParse->pIdxExpr; pParse->pIdxExpr = p->pIENext; sqlite3ExprDelete(db, p->pExpr); sqlite3DbFreeNN(db, p); @@ -5400,19 +5400,19 @@ static void whereIndexExprCleanup(sqlite3 *db, void *pObject){ ** number for the index and iDataCur is the cursor number for the corresponding ** table. ** -** This routine adds IndexExpr entries to the Parse->pIdxExpr field for +** This routine adds IndexedExpr entries to the Parse->pIdxExpr field for ** each of the expressions in the index so that the expression code generator ** will know to replace occurrences of the indexed expression with ** references to the corresponding column of the index. */ -static SQLITE_NOINLINE void whereAddIndexExpr( - Parse *pParse, /* Add IndexExpr entries to pParse->pIdxExpr */ +static SQLITE_NOINLINE void whereAddIndexedExpr( + Parse *pParse, /* Add IndexedExpr entries to pParse->pIdxExpr */ Index *pIdx, /* The index-on-expression that contains the expressions */ int iIdxCur, /* Cursor number for pIdx */ SrcItem *pTabItem /* The FROM clause entry for the table */ ){ int i; - IndexExpr *p; + IndexedExpr *p; Table *pTab; assert( pIdx->bHasExpr ); pTab = pIdx->pTable; @@ -5426,7 +5426,7 @@ static SQLITE_NOINLINE void whereAddIndexExpr( }else{ continue; } - p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexExpr)); + p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr)); if( p==0 ) break; p->pIENext = pParse->pIdxExpr; p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); @@ -5436,7 +5436,7 @@ static SQLITE_NOINLINE void whereAddIndexExpr( p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0; pParse->pIdxExpr = p; if( p->pIENext==0 ){ - sqlite3ParserAddCleanup(pParse, whereIndexExprCleanup, pParse); + sqlite3ParserAddCleanup(pParse, whereIndexedExprCleanup, pParse); } } } @@ -5987,7 +5987,7 @@ WhereInfo *sqlite3WhereBegin( }else{ iIndexCur = pParse->nTab++; if( pIx->bHasExpr ){ - whereAddIndexExpr(pParse, pIx, iIndexCur, pTabItem); + whereAddIndexedExpr(pParse, pIx, iIndexCur, pTabItem); } } pLevel->iIdxCur = iIndexCur; @@ -6386,7 +6386,7 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ last = pWInfo->iEndWhere; } if( pIdx->bHasExpr ){ - IndexExpr *p = pParse->pIdxExpr; + IndexedExpr *p = pParse->pIdxExpr; while( p ){ if( p->iIdxCur==pLevel->iIdxCur ){ p->iDataCur = -1; From 0467b01a1fb2de4f5a909d3a05681fa5fa1aafb3 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 17 Oct 2022 15:52:12 +0000 Subject: [PATCH 14/65] Rework ext/wasm/version-info.c to make it more useful for the upcoming dist build rules. FossilOrigin-Name: 36e197cb3d0cbb76e4c1381d77f7d8856e7391f2ef6671c13b9b6b0133315814 --- ext/wasm/GNUmakefile | 16 +++++++++++----- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 45ab3b8386..7d910ebdaa 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -125,9 +125,9 @@ else $(info Development build. Use '$(MAKE) release' for a smaller release build.) endif -version-json: version-json.c $(sqlite3.c) $(MAKEFILE) - $(CC) -O0 -I$(dir.top) -o $@ $(SQLITE_OPT) -DHAVE_MREMAP=0 $< $(sqlite3.c) -CLEAN_FILES := version-json +version-info: version-info.c $(sqlite3.c) $(MAKEFILE) + $(CC) -O0 -I$(dir.top) -o $@ $(SQLITE_OPT) $< $(sqlite3.c) +CLEAN_FILES := version-info EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api @@ -161,12 +161,12 @@ $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) echo "/* END FILE: $$i */"; \ done > $@ -$(sqlite3-api-build-version.js): version-json +$(sqlite3-api-build-version.js): version-info @echo "Making $@..." @{ \ echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \ echo -n ' sqlite3.version = '; \ - ./version-json; \ + ./version-info --json; \ echo ';'; \ echo '});'; \ } > $@ @@ -518,6 +518,12 @@ else include wasmfs.make endif +######################################################################## +# Create deliverables: TODO +#ifneq (,$(filter dist,$(MAKECMDGOALS))) +#include dist.make +#endif + ######################################################################## # Push files to public wasm-testing.sqlite.org server wasm-testing.include = *.wasm *.js *.html \ diff --git a/manifest b/manifest index f650226ca1..a4e6f65c4e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\suse\sof\salloca()\sin\swherePathSolver()\swhen\sSQLITE_USE_ALLOCA\sis\sdefined. -D 2022-10-17T10:15:41.927 +C Rework\sext/wasm/version-info.c\sto\smake\sit\smore\suseful\sfor\sthe\supcoming\sdist\sbuild\srules. +D 2022-10-17T15:52:12.372 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -473,7 +473,7 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0 -F ext/wasm/GNUmakefile ce1eb95ca32b23ce3400b26e99c23f6b2737a5356cb4eff2b8b364d7630a8cc9 +F ext/wasm/GNUmakefile 0fd09868726368d849c2cf03e6ac9884a07d236855c7802a89f0f8a16c034d10 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 @@ -2033,8 +2033,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 2ab3cf4d71b23a4c0b69f977828d82df7bbc080c29ae189e0d78d38efee50c96 -R fd1636fa451b5b8e84570a9195b2236a -U drh -Z 2743069ef130a7abdc131b5ac7f77275 +P 45752471521f8d4a6cad4bce40f907018acd403ffd3b8170020c34e4e0b6b91b +R d0d2c913cf0284c12f6d5ab66c60618d +U stephan +Z 389e498f7feafb90497b4f68916517e0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d362e0dc32..4db4924c5f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -45752471521f8d4a6cad4bce40f907018acd403ffd3b8170020c34e4e0b6b91b \ No newline at end of file +36e197cb3d0cbb76e4c1381d77f7d8856e7391f2ef6671c13b9b6b0133315814 \ No newline at end of file From cdc9ddc6ec28a475e20a86022de8f7d7d5331379 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 17 Oct 2022 15:53:16 +0000 Subject: [PATCH 15/65] Missing file-rename for the previous checkin. FossilOrigin-Name: e9b407a4d0a0fcd9f26d457beede19d41141327befe84be621681952be5d1e69 --- ext/wasm/{version-json.c => version-info.c} | 0 manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename ext/wasm/{version-json.c => version-info.c} (100%) diff --git a/ext/wasm/version-json.c b/ext/wasm/version-info.c similarity index 100% rename from ext/wasm/version-json.c rename to ext/wasm/version-info.c diff --git a/manifest b/manifest index a4e6f65c4e..1ca9745db6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rework\sext/wasm/version-info.c\sto\smake\sit\smore\suseful\sfor\sthe\supcoming\sdist\sbuild\srules. -D 2022-10-17T15:52:12.372 +C Missing\sfile-rename\sfor\sthe\sprevious\scheckin. +D 2022-10-17T15:53:16.486 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -533,7 +533,7 @@ F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9 F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3 F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494 -F ext/wasm/version-json.c 03c6fb4efefd7c5b14f618b36648e71da741e39059ea5059c39495fdceaed144 +F ext/wasm/version-info.c 03c6fb4efefd7c5b14f618b36648e71da741e39059ea5059c39495fdceaed144 w ext/wasm/version-json.c F ext/wasm/wasmfs.make 3cce1820006196de140f90f2da4b4ea657083fb5bfee7d125be43f7a85748c8f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 @@ -2033,8 +2033,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 45752471521f8d4a6cad4bce40f907018acd403ffd3b8170020c34e4e0b6b91b -R d0d2c913cf0284c12f6d5ab66c60618d +P 36e197cb3d0cbb76e4c1381d77f7d8856e7391f2ef6671c13b9b6b0133315814 +R 913b0f5c6deb44215505d33b5b2a96aa U stephan -Z 389e498f7feafb90497b4f68916517e0 +Z 279fbd3aa8e8b6ab1074595f5c42e719 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4db4924c5f..34165934d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -36e197cb3d0cbb76e4c1381d77f7d8856e7391f2ef6671c13b9b6b0133315814 \ No newline at end of file +e9b407a4d0a0fcd9f26d457beede19d41141327befe84be621681952be5d1e69 \ No newline at end of file From 8be89249012a556580737d9e7a6b1938bab9e02c Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 17 Oct 2022 16:09:33 +0000 Subject: [PATCH 16/65] Fix a potential call to strlen() with a null argument in the command-line shell following an OOM error. [forum:/forumpost/9c4f2ebe22|forum post 9c4f2ebe22]. FossilOrigin-Name: b6413a6dff8ac9b7088b1381afbbbf799e376455d11786530cc5fc825747ab53 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/shell.c.in | 4 +++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1ca9745db6..215cd1c292 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Missing\sfile-rename\sfor\sthe\sprevious\scheckin. -D 2022-10-17T15:53:16.486 +C Fix\sa\spotential\scall\sto\sstrlen()\swith\sa\snull\sargument\sin\sthe\scommand-line\sshell\nfollowing\san\sOOM\serror.\s[forum:/forumpost/9c4f2ebe22|forum\spost\s9c4f2ebe22]. +D 2022-10-17T16:09:33.721 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -533,7 +533,7 @@ F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9 F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3 F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494 -F ext/wasm/version-info.c 03c6fb4efefd7c5b14f618b36648e71da741e39059ea5059c39495fdceaed144 w ext/wasm/version-json.c +F ext/wasm/version-info.c 03c6fb4efefd7c5b14f618b36648e71da741e39059ea5059c39495fdceaed144 F ext/wasm/wasmfs.make 3cce1820006196de140f90f2da4b4ea657083fb5bfee7d125be43f7a85748c8f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 @@ -620,7 +620,7 @@ F src/random.c 546d6feb15ec69c1aafe9bb351a277cbb498fd5410e646add673acb805714960 F src/resolve.c efea4e5fbecfd6d0a9071b0be0d952620991673391b6ffaaf4c277b0bb674633 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c b795f31a326564ffc448bb26f863c64f0796b2a5e0585a3358aff7877b72ed82 -F src/shell.c.in 2915eaf22bda89ad6533851a051de4773c249185360fe1fc7b4477b8f9063b2c +F src/shell.c.in a4c0754470d4fcc2c3da2f0cda0363cecf4a84273d3cc3865325c2df06d5e56b F src/sqlite.h.in d9c8a6243fc0a1c270d69db33758e34b810af3462f9bc5b4af113b347e07c69d F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 5336beea1868d99d2f62e628dbea55e97267dbff8193291ab175e960c5df9141 @@ -2033,8 +2033,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 36e197cb3d0cbb76e4c1381d77f7d8856e7391f2ef6671c13b9b6b0133315814 -R 913b0f5c6deb44215505d33b5b2a96aa -U stephan -Z 279fbd3aa8e8b6ab1074595f5c42e719 +P e9b407a4d0a0fcd9f26d457beede19d41141327befe84be621681952be5d1e69 +R fd5bd78c383b3a5ac313c836d503f5ef +U drh +Z 6ca21d53ba6df71519b0f06bf84205e6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 34165934d5..0b5ebb0171 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e9b407a4d0a0fcd9f26d457beede19d41141327befe84be621681952be5d1e69 \ No newline at end of file +b6413a6dff8ac9b7088b1381afbbbf799e376455d11786530cc5fc825747ab53 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index a83aab58a1..1dbe349efa 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1990,7 +1990,9 @@ static int wsToEol(const char *z){ */ static void eqp_append(ShellState *p, int iEqpId, int p2, const char *zText){ EQPGraphRow *pNew; - i64 nText = strlen(zText); + i64 nText; + if( zText==0 ) return; + nText = strlen(zText); if( p->autoEQPtest ){ utf8_printf(p->out, "%d,%d,%s\n", iEqpId, p2, zText); } From 1b8c2467991886b970ab18011404ed12673b1df8 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 17 Oct 2022 16:47:59 +0000 Subject: [PATCH 17/65] Repair version-info.c after a local mishap caused all of the intended edits from [36e197cb3d0c]/[e9b407a4d0a0] to get deleted before checkin. Simplify version-info build (only requires sqlite3.h, not the library). FossilOrigin-Name: 6e511df500c63e27f932be9d601b641144562614dead99371477eca4594fb3fd --- ext/wasm/GNUmakefile | 13 ++++---- ext/wasm/version-info.c | 72 ++++++++++++++++++++++++++++++++++++----- manifest | 16 ++++----- manifest.uuid | 2 +- 4 files changed, 80 insertions(+), 23 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 7d910ebdaa..78f49bb8b0 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -125,9 +125,10 @@ else $(info Development build. Use '$(MAKE) release' for a smaller release build.) endif -version-info: version-info.c $(sqlite3.c) $(MAKEFILE) - $(CC) -O0 -I$(dir.top) -o $@ $(SQLITE_OPT) $< $(sqlite3.c) -CLEAN_FILES := version-info +version-info := $(dir.wasm)/version-info +$(version-info): $(dir.wasm)/version-info.c $(sqlite3.h) $(MAKEFILE) + $(CC) -O0 -I$(dir.top) -o $@ $< +CLEAN_FILES := $(version-info) EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api @@ -161,12 +162,12 @@ $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) echo "/* END FILE: $$i */"; \ done > $@ -$(sqlite3-api-build-version.js): version-info +$(sqlite3-api-build-version.js): $(version-info) @echo "Making $@..." @{ \ echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \ echo -n ' sqlite3.version = '; \ - ./version-info --json; \ + $(version-info) --json; \ echo ';'; \ echo '});'; \ } > $@ @@ -344,7 +345,7 @@ $(sqlite3.js): $(MAKEFILE) $(sqlite3.wasm.obj) \ chmod -x $(sqlite3.wasm) $(maybe-wasm-strip) $(sqlite3.wasm) @ls -la $@ $(sqlite3.wasm) - +$(sqlite3.wasm): $(sqlite3.js) CLEAN_FILES += $(sqlite3.js) $(sqlite3.wasm) all: $(sqlite3.js) wasm: $(sqlite3.js) diff --git a/ext/wasm/version-info.c b/ext/wasm/version-info.c index cb5083a40a..96c8e2dbee 100644 --- a/ext/wasm/version-info.c +++ b/ext/wasm/version-info.c @@ -12,15 +12,71 @@ ** This file simply outputs sqlite3 version information in JSON form, ** intended for embedding in the sqlite3 JS API build. */ -#include #include "sqlite3.h" +#include +#include + +static void usage(const char *zAppName){ + puts("Emits version info about the sqlite3 it is built against."); + printf("Usage: %s [--quote] --INFO-FLAG:\n\n", zAppName); + puts(" --version Emit SQLITE_VERSION (3.X.Y)"); + puts(" --version-number Emit SQLITE_VERSION_NUMBER (30XXYYZZ)"); + puts(" --source-id Emit SQLITE_SOURCE_ID"); + puts(" --json Emit all info in JSON form"); + puts("\nThe non-JSON formats may be modified by:\n"); + puts(" --quote Add double quotes around output."); +} + int main(int argc, char const * const * argv){ - if(argc || argv){/*unused*/} - printf("{\"libVersion\": \"%s\", " - "\"libVersionNumber\": %d, " - "\"sourceId\": \"%s\"}"/*missing newline is intentional*/, - SQLITE_VERSION, - SQLITE_VERSION_NUMBER, - SQLITE_SOURCE_ID); + int fJson = 0; + int fVersion = 0; + int fVersionNumber = 0; + int fSourceInfo = 0; + int fQuote = 0; + int nFlags = 0; + int i; + + for( i = 1; i < argc; ++i ){ + const char * zArg = argv[i]; + while('-'==*zArg) ++zArg; + if( 0==strcmp("version", zArg) ){ + fVersion = 1; + }else if( 0==strcmp("version-number", zArg) ){ + fVersionNumber = 1; + }else if( 0==strcmp("source-id", zArg) ){ + fSourceInfo = 1; + }else if( 0==strcmp("json", zArg) ){ + fJson = 1; + }else if( 0==strcmp("quote", zArg) ){ + fQuote = 1; + --nFlags; + }else{ + printf("Unhandled flag: %s\n", argv[i]); + usage(argv[0]); + return 1; + } + ++nFlags; + } + + if( 0==nFlags ) fJson = 1; + if( fJson ){ + printf("{\"libVersion\": \"%s\", " + "\"libVersionNumber\": %d, " + "\"sourceId\": \"%s\"}"/*missing newline is intentional*/, + SQLITE_VERSION, + SQLITE_VERSION_NUMBER, + SQLITE_SOURCE_ID); + }else{ + if(fQuote) printf("%c", '"'); + if( fVersion ){ + printf("%s", SQLITE_VERSION); + }else if( fVersionNumber ){ + printf("%d", SQLITE_VERSION_NUMBER); + }else if( fSourceInfo ){ + printf("%s", SQLITE_SOURCE_ID); + } + if(fQuote) printf("%c", '"'); + puts(""); + } return 0; } diff --git a/manifest b/manifest index 215cd1c292..b69cf38c6d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spotential\scall\sto\sstrlen()\swith\sa\snull\sargument\sin\sthe\scommand-line\sshell\nfollowing\san\sOOM\serror.\s[forum:/forumpost/9c4f2ebe22|forum\spost\s9c4f2ebe22]. -D 2022-10-17T16:09:33.721 +C Repair\sversion-info.c\safter\sa\slocal\smishap\scaused\sall\sof\sthe\sintended\sedits\sfrom\s[36e197cb3d0c]/[e9b407a4d0a0]\sto\sget\sdeleted\sbefore\scheckin.\sSimplify\sversion-info\sbuild\s(only\srequires\ssqlite3.h,\snot\sthe\slibrary). +D 2022-10-17T16:47:59.012 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -473,7 +473,7 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0 -F ext/wasm/GNUmakefile 0fd09868726368d849c2cf03e6ac9884a07d236855c7802a89f0f8a16c034d10 +F ext/wasm/GNUmakefile a483eb1baec9bf997261908ed56f34a1dfc44eb2353e438ec9b1d2a7045c1d50 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 @@ -533,7 +533,7 @@ F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9 F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3 F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494 -F ext/wasm/version-info.c 03c6fb4efefd7c5b14f618b36648e71da741e39059ea5059c39495fdceaed144 +F ext/wasm/version-info.c 5fa356d38859d71a0369b5c37e1935def7413fcc8a4e349a39d9052c1d0479f4 F ext/wasm/wasmfs.make 3cce1820006196de140f90f2da4b4ea657083fb5bfee7d125be43f7a85748c8f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 @@ -2033,8 +2033,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 e9b407a4d0a0fcd9f26d457beede19d41141327befe84be621681952be5d1e69 -R fd5bd78c383b3a5ac313c836d503f5ef -U drh -Z 6ca21d53ba6df71519b0f06bf84205e6 +P b6413a6dff8ac9b7088b1381afbbbf799e376455d11786530cc5fc825747ab53 +R 178294a2ffbab5bdb66a3de75a26d638 +U stephan +Z 39b6a8dbd3ac1d229c47b7711c3bc156 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0b5ebb0171..ccf652c86f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b6413a6dff8ac9b7088b1381afbbbf799e376455d11786530cc5fc825747ab53 \ No newline at end of file +6e511df500c63e27f932be9d601b641144562614dead99371477eca4594fb3fd \ No newline at end of file From e79a0943ed7d52b101d73c3dc1a769e0668dcecf Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 17 Oct 2022 17:34:41 +0000 Subject: [PATCH 18/65] Initial draft of archive generation for the wasm/js deliverables. FossilOrigin-Name: f6cee114c71e11ca1f508c8f60be5753871cbd4fd6c45ce397824bddbf00ffd9 --- ext/wasm/GNUmakefile | 7 +++-- ext/wasm/dist.make | 62 ++++++++++++++++++++++++++++++++++++++++++++ ext/wasm/fiddle.make | 8 +++--- ext/wasm/wasmfs.make | 20 +++----------- manifest | 17 ++++++------ manifest.uuid | 2 +- 6 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 ext/wasm/dist.make diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 78f49bb8b0..a683a91416 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -521,9 +521,9 @@ endif ######################################################################## # Create deliverables: TODO -#ifneq (,$(filter dist,$(MAKECMDGOALS))) -#include dist.make -#endif +ifneq (,$(filter dist,$(MAKECMDGOALS))) +include dist.make +endif ######################################################################## # Push files to public wasm-testing.sqlite.org server @@ -539,4 +539,3 @@ push: $(wasm-testing.include) $(wasm-testing.dest) ssh wasm-testing 'cd $(wasm-testing.dir) && bash .gzip' || \ echo "SSH failed: it's likely that stale content will be served via old gzip files." - diff --git a/ext/wasm/dist.make b/ext/wasm/dist.make new file mode 100644 index 0000000000..84abe393a2 --- /dev/null +++ b/ext/wasm/dist.make @@ -0,0 +1,62 @@ +#!/do/not/make +#^^^ help emacs select edit mode +# +# Intended to include'd by ./GNUmakefile. +# +# 'make dist' rules for creating a distribution archive of the WASM/JS +# pieces, noting that we only build a dist of the built files, not the +# numerous pieces required to build them. +####################################################################### +MAKEFILE.dist := $(lastword $(MAKEFILE_LIST)) + + +######################################################################## +# Chicken/egg situation: we need $(version-info) to get the version +# info for the archive name, but that binary may not yet be built, so +# we have to use a temporary name for the archive. +dist-name = sqlite-wasm-TEMP +dist-archive = $(dist-name).zip + +#ifeq (0,1) +# $(info WARNING *******************************************************************) +# $(info ** Be sure to create the desired build configuration before creating the) +# $(info ** distribution archive. Use one of the following targets to do so:) +# $(info ** o2: builds with -O2, resulting in the fastest builds) +# $(info ** oz: builds with -Oz, resulting in the smallest builds) +# $(info /WARNING *******************************************************************) +#endif + +demo-123.html := $(dir.wasm)/demo-123.html +demo-123-worker.html := $(dir.wasm)/demo-123-worker.html +demo-123.js := $(dir.wasm)/demo-123.js +demo-files := $(demo-123.js) $(demo-123.html) $(demo-123-worker.html) +README-dist := $(dir.wasm)/README-dist.txt +$(dist-archive): $(sqlite3.wasm) $(sqlite3.js) $(sqlite3-wasmfs.wasm) $(sqlite3-wasmfs.js) +#$(dist-archive): $(sqlite3.h) $(sqlite3.c) $(sqlite3-wasm.c) +$(dist-archive): $(MAKEFILE.dist) $(version-info) $(demo-files) $(README-dist) +$(dist-archive): oz + rm -fr $(dist-name) + mkdir -p $(dist-name)/main $(dist-name)/wasmfs + cp -p $(README-dist) $(dist-name)/README.txt + cp -p $(sqlite3.wasm) $(sqlite3.js) $(dist-name)/main + cp -p $(demo-files) $(dist-name)/main + cp -p $(sqlite3-wasmfs.wasm) $(sqlite3-wasmfs.js) $(dist-name)/wasmfs + for i in $(demo-123.js) $(demo-123.html); do \ + sed -e 's/\bsqlite3\.js\b/sqlite3-wasmfs.js/' $$i \ + > $(dist-name)/wasmfs/$${i##*/} || exit; \ + done + vnum=$$($(version-info) --version-number); \ + vdir=sqlite-wasm-$$vnum; \ + arc=$$vdir.zip; \ + rm -f $$arc; \ + mv $(dist-name) $$vdir; \ + zip -qr $$arc $$vdir; \ + rm -fr $$vdir; \ + ls -la $$arc; \ + unzip -l $$arc + +#$(shell $(version-info) --version-number) +dist: $(dist-archive) +clean-dist: + rm -f $(dist-archive) +clean: clean-dist diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index 585add4270..6f90024811 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -46,11 +46,11 @@ fiddle.EXPORTED_FUNCTIONS.in := \ EXPORTED_FUNCTIONS.api EXPORTED_FUNCTIONS.fiddle: $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle) - grep -h -v jaccwabyt $(fiddle.EXPORTED_FUNCTIONS.in) | sort -u > $@ + sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@ fiddle-module.js := $(dir.fiddle)/fiddle-module.js fiddle-module.wasm := $(subst .js,.wasm,$(fiddle-module.js)) -fiddle.cs := $(dir.top)/shell.c $(sqlite3-wasm.c) +fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c) SOAP.js := sqlite3-opfs-async-proxy.js $(dir.fiddle)/$(SOAP.js): $(SOAP.js) @@ -59,10 +59,10 @@ $(dir.fiddle)/$(SOAP.js): $(SOAP.js) $(eval $(call call-make-pre-js,fiddle-module)) $(fiddle-module.js): $(MAKEFILE) $(MAKEFILE.fiddle) \ EXPORTED_FUNCTIONS.fiddle EXPORTED_RUNTIME_METHODS.fiddle \ - $(fiddle.cs) $(pre-post-fiddle-module.deps) $(dir.fiddle)/$(SOAP.js) + $(fiddle.cses) $(pre-post-fiddle-module.deps) $(dir.fiddle)/$(SOAP.js) $(emcc.bin) -o $@ $(fiddle.emcc-flags) \ $(pre-post-common.flags) $(pre-post-fiddle-module.flags) \ - $(fiddle.cs) + $(fiddle.cses) $(maybe-wasm-strip) $(fiddle-module.wasm) gzip < $@ > $@.gz gzip < $(fiddle-module.wasm) > $(fiddle-module.wasm).gz diff --git a/ext/wasm/wasmfs.make b/ext/wasm/wasmfs.make index fa8320e585..ee7b9f12bc 100644 --- a/ext/wasm/wasmfs.make +++ b/ext/wasm/wasmfs.make @@ -9,7 +9,6 @@ MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST)) sqlite3-wasmfs.js := sqlite3-wasmfs.js sqlite3-wasmfs.wasm := sqlite3-wasmfs.wasm -sqlite3-wasmfs.wasm.c := $(dir.api)/sqlite3-wasm.c CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \ $(subst .js,.worker.js,$(sqlite3-wasmfs.js)) @@ -27,12 +26,6 @@ sqlite3-wasmfs.cflags += -pthread sqlite3-wasmfs.cflags += -I. -I.. -I$(dir.top) sqlite3-wasmfs.cflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS -sqlite3-wasmfs.extra.c := -ifeq (1,1) - # To get testing1.js to run with $(sqlite3-wasmfs.js) we need... - sqlite3-wasmfs.extra.c += $(jaccwabyt_test.c) -endif - ######################################################################## # emcc flags specific to building the final .js/.wasm file... sqlite3-wasmfs.jsflags := -fPIC @@ -42,12 +35,7 @@ sqlite3-wasmfs.jsflags += -sMODULARIZE sqlite3-wasmfs.jsflags += -sSTRICT_JS sqlite3-wasmfs.jsflags += -sDYNAMIC_EXECUTION=0 sqlite3-wasmfs.jsflags += -sNO_POLYFILL -ifeq (,$(sqlite3-wasmfs.extra.c)) - sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api -else - # need more exports for jaccwabyt test code... - sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api -endif +sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api sqlite3-wasmfs.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack # wasmMemory ==> for -sIMPORTED_MEMORY # allocateUTF8OnStack ==> wasmfs internals @@ -78,17 +66,17 @@ sqlite3-wasmfs.jsflags += $(sqlite3-wasmfs.fsflags) sqlite3-wasmfs.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint) $(eval $(call call-make-pre-js,sqlite3-wasmfs)) sqlite3-wasmfs.jsflags += $(pre-post-common.flags) $(pre-post-sqlite3-wasmfs.flags) -$(sqlite3-wasmfs.js): $(sqlite3-wasmfs.wasm.c) $(sqlite3-wasm.c) $(sqlite3-wasmfs.extra.c) \ +$(sqlite3-wasmfs.js): $(sqlite3-wasm.c) \ EXPORTED_FUNCTIONS.api $(MAKEFILE) $(MAKEFILE.wasmfs) \ $(pre-post-sqlite3-wasmfs.deps) @echo "Building $@ ..." $(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \ $(sqlite3-wasmfs.cflags) $(sqlite3-wasmfs.jsflags) \ - $(sqlite3-wasmfs.wasm.c) $(sqlite3-wasmfs.extra.c) + $(sqlite3-wasm.c) chmod -x $(sqlite3-wasmfs.wasm) $(maybe-wasm-strip) $(sqlite3-wasmfs.wasm) @ls -la $@ $(sqlite3-wasmfs.wasm) - +$(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.js) wasmfs: $(sqlite3-wasmfs.js) all: wasmfs diff --git a/manifest b/manifest index b69cf38c6d..c6570296a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Repair\sversion-info.c\safter\sa\slocal\smishap\scaused\sall\sof\sthe\sintended\sedits\sfrom\s[36e197cb3d0c]/[e9b407a4d0a0]\sto\sget\sdeleted\sbefore\scheckin.\sSimplify\sversion-info\sbuild\s(only\srequires\ssqlite3.h,\snot\sthe\slibrary). -D 2022-10-17T16:47:59.012 +C Initial\sdraft\sof\sarchive\sgeneration\sfor\sthe\swasm/js\sdeliverables. +D 2022-10-17T17:34:41.824 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -473,7 +473,7 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0 -F ext/wasm/GNUmakefile a483eb1baec9bf997261908ed56f34a1dfc44eb2353e438ec9b1d2a7045c1d50 +F ext/wasm/GNUmakefile 2fd83d7183bce3f9236fdd2dbe20a4ea37b1d7b26e1a422054ec63008319f065 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 @@ -503,7 +503,8 @@ F ext/wasm/demo-123.html 7c239c9951d1b113f9f532969ac039294cf1dcfee2b3ae0a2c1ed2b F ext/wasm/demo-123.js e0cbeb3495e14103763d5c49794a24d67cf3d78e0ed5b82843be70c0c2ee4b3b F ext/wasm/demo-kvvfs1.html 7d4f28873de67f51ac18c584b7d920825139866a96049a49c424d6f5a0ea5e7f F ext/wasm/demo-kvvfs1.js 105596bd2ccd0b1deb5fde8e99b536e8242d4bb5932fac0c8403ff3a6bc547e8 -F ext/wasm/fiddle.make 3f4efd62bc2a9c883bfcea52ae2755114a62d444d6d042df287f4aef301d6c6c +F ext/wasm/dist.make d7076e90f04396f1cc54cb41ee106451496179c10d54bbdebb65ae7b1ae12211 +F ext/wasm/fiddle.make b609dfde299b4523d7123b7e0cecaa1a0aff0dd984e62cea653aae91f5063c90 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 531859a471924a0ea48afa218e6877f0c164ca324d51e15843ed6ecc1c65c7ee F ext/wasm/fiddle/fiddle.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 @@ -534,7 +535,7 @@ F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d766 F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3 F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494 F ext/wasm/version-info.c 5fa356d38859d71a0369b5c37e1935def7413fcc8a4e349a39d9052c1d0479f4 -F ext/wasm/wasmfs.make 3cce1820006196de140f90f2da4b4ea657083fb5bfee7d125be43f7a85748c8f +F ext/wasm/wasmfs.make 9a51480d0a5ef33dd1c06c305379775302b735cb27737c2490ea449575ca5e25 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 @@ -2033,8 +2034,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 b6413a6dff8ac9b7088b1381afbbbf799e376455d11786530cc5fc825747ab53 -R 178294a2ffbab5bdb66a3de75a26d638 +P 6e511df500c63e27f932be9d601b641144562614dead99371477eca4594fb3fd +R ac89799bd8dcc9e62a5727e545f26c38 U stephan -Z 39b6a8dbd3ac1d229c47b7711c3bc156 +Z 4dda775375ae46314750ace83110f63b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ccf652c86f..03196c2b8b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6e511df500c63e27f932be9d601b641144562614dead99371477eca4594fb3fd \ No newline at end of file +f6cee114c71e11ca1f508c8f60be5753871cbd4fd6c45ce397824bddbf00ffd9 \ No newline at end of file From ce152a436923a4208f56205140abc6e10edb549c Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 17 Oct 2022 17:36:11 +0000 Subject: [PATCH 19/65] Add ext/wasm/README-dist.txt, intended to have been in the previous checkin. FossilOrigin-Name: c9080b6505b839cc0bb5bd25ce7df0daa91a0a303d037ffe6e77888c8584b932 --- ext/wasm/README-dist.txt | 26 ++++++++++++++++++++++++++ manifest | 11 ++++++----- manifest.uuid | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 ext/wasm/README-dist.txt diff --git a/ext/wasm/README-dist.txt b/ext/wasm/README-dist.txt new file mode 100644 index 0000000000..ecb906acdc --- /dev/null +++ b/ext/wasm/README-dist.txt @@ -0,0 +1,26 @@ +This is the README for the sqlite3 WASM/JS distribution. + +Main project page: https://sqlite.org + +TODO: link to main WASM/JS docs, once they are online + +This archive contains two related deliverables: + +- ./main contains the sqlite3.js and sqlite3.wasm file which make up + the standard sqlite3 WASM/JS build. + +- ./wasmfs contains a build of those files which includes the + Emscripten WASMFS[^1]. It offers an alternative approach + to accessing the browser-side Origin-Private FileSystem + but is less portable than the main build, so is provided + as a separate binary. + +Both directories contain small demonstration apps. Browsers will not +server WASM files from file:// URLs, so the demonstrations require a +web server and that server must include the following headers in its +response when serving the files: + + Cross-Origin-Opener-Policy: same-origin + Cross-Origin-Embedder-Policy: require-corp + +[^1]: https://emscripten.org diff --git a/manifest b/manifest index c6570296a3..412021640a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Initial\sdraft\sof\sarchive\sgeneration\sfor\sthe\swasm/js\sdeliverables. -D 2022-10-17T17:34:41.824 +C Add\sext/wasm/README-dist.txt,\sintended\sto\shave\sbeen\sin\sthe\sprevious\scheckin. +D 2022-10-17T17:36:11.919 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -474,6 +474,7 @@ F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865 F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0 F ext/wasm/GNUmakefile 2fd83d7183bce3f9236fdd2dbe20a4ea37b1d7b26e1a422054ec63008319f065 +F ext/wasm/README-dist.txt bc1fb4f90a28ad2ed0e555a637f393b9249d8d928ac509dad6293b7cae628ea4 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 @@ -2034,8 +2035,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 6e511df500c63e27f932be9d601b641144562614dead99371477eca4594fb3fd -R ac89799bd8dcc9e62a5727e545f26c38 +P f6cee114c71e11ca1f508c8f60be5753871cbd4fd6c45ce397824bddbf00ffd9 +R 94e4f6969f6fba48019898e2b4d88284 U stephan -Z 4dda775375ae46314750ace83110f63b +Z 0dd260cfe444ff6950e06a618165a6ba # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 03196c2b8b..f47af71200 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f6cee114c71e11ca1f508c8f60be5753871cbd4fd6c45ce397824bddbf00ffd9 \ No newline at end of file +c9080b6505b839cc0bb5bd25ce7df0daa91a0a303d037ffe6e77888c8584b932 \ No newline at end of file From 43fce6bb0d85d596615f9f71b040dfa5ef395d65 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 18 Oct 2022 10:27:06 +0000 Subject: [PATCH 20/65] Fix sqlite3VdbeRecordCompareWithSkip() so that it sorts the internal-use serial-type of 10 together with NULLs. dbsqlfuzz 5ff35e9d49a5fcca5051e23960ff2f483a538bab FossilOrigin-Name: 4fb77e96fa89a23a9365320c4190834edd6c09cfaf1ca30b34ce19b747ebbec0 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeaux.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 412021640a..afb62b8e86 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sext/wasm/README-dist.txt,\sintended\sto\shave\sbeen\sin\sthe\sprevious\scheckin. -D 2022-10-17T17:36:11.919 +C Fix\ssqlite3VdbeRecordCompareWithSkip()\sso\sthat\sit\ssorts\sthe\sinternal-use\nserial-type\sof\s10\stogether\swith\sNULLs.\ndbsqlfuzz\s5ff35e9d49a5fcca5051e23960ff2f483a538bab +D 2022-10-18T10:27:06.495 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -697,7 +697,7 @@ F src/vdbe.c 0c7cb1b934ad8611e14e7efaf2c3a95df7dd3f7964d63ea07fef42a23df86131 F src/vdbe.h 58675f47dcf3105bab182c3ad3726efd60ffd003e954386904ac9107d0d2b743 F src/vdbeInt.h 17b7461ffcf9ee760d1341731715a419f6b8c763089a7ece25c2e8098d702b3f F src/vdbeapi.c 1e8713d0b653acb43cd1bdf579c40e005c4844ea90f414f065946a83db3c27fb -F src/vdbeaux.c 6946c7082a0d61566794bd35253f0ccd013a9dba3f33488a23fd5360a5744e5b +F src/vdbeaux.c fe4e8d270582d5eb7c4d44222b74584d8e47c5e6ba90849416115ce5eb47d5a4 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 6cfed43758d57b6e3b99d9cdedfeccd86e45a07e427b22d8487cbdbebb6c522a F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -2035,8 +2035,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 f6cee114c71e11ca1f508c8f60be5753871cbd4fd6c45ce397824bddbf00ffd9 -R 94e4f6969f6fba48019898e2b4d88284 -U stephan -Z 0dd260cfe444ff6950e06a618165a6ba +P c9080b6505b839cc0bb5bd25ce7df0daa91a0a303d037ffe6e77888c8584b932 +R c6933aa36b3965399e80dc36fb15b922 +U drh +Z f66ba4d30fb256e3ce3a8281933b3c32 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f47af71200..82a1ebdb17 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c9080b6505b839cc0bb5bd25ce7df0daa91a0a303d037ffe6e77888c8584b932 \ No newline at end of file +4fb77e96fa89a23a9365320c4190834edd6c09cfaf1ca30b34ce19b747ebbec0 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 18bbcd2f97..67de532d80 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4691,7 +4691,7 @@ int sqlite3VdbeRecordCompareWithSkip( /* RHS is null */ else{ serial_type = aKey1[idx1]; - rc = (serial_type!=0); + rc = (serial_type!=0 && serial_type!=10); } if( rc!=0 ){ From 0e522c068a8ff85aaadc4e61ab57a4090908a2da Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 18 Oct 2022 13:27:31 +0000 Subject: [PATCH 21/65] Correct sort order for serial-type 10 entries in the database file. This is a continuation of [4fb77e96fa89a23a]. FossilOrigin-Name: 904b54625d985e742888e06ba792cab316b9ec9d6669d9cf509bac48030373ca --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index afb62b8e86..c13ee1adf0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\ssqlite3VdbeRecordCompareWithSkip()\sso\sthat\sit\ssorts\sthe\sinternal-use\nserial-type\sof\s10\stogether\swith\sNULLs.\ndbsqlfuzz\s5ff35e9d49a5fcca5051e23960ff2f483a538bab -D 2022-10-18T10:27:06.495 +C Correct\ssort\sorder\sfor\sserial-type\s10\sentries\sin\sthe\sdatabase\sfile.\s\sThis\nis\sa\scontinuation\sof\s[4fb77e96fa89a23a]. +D 2022-10-18T13:27:31.501 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -697,7 +697,7 @@ F src/vdbe.c 0c7cb1b934ad8611e14e7efaf2c3a95df7dd3f7964d63ea07fef42a23df86131 F src/vdbe.h 58675f47dcf3105bab182c3ad3726efd60ffd003e954386904ac9107d0d2b743 F src/vdbeInt.h 17b7461ffcf9ee760d1341731715a419f6b8c763089a7ece25c2e8098d702b3f F src/vdbeapi.c 1e8713d0b653acb43cd1bdf579c40e005c4844ea90f414f065946a83db3c27fb -F src/vdbeaux.c fe4e8d270582d5eb7c4d44222b74584d8e47c5e6ba90849416115ce5eb47d5a4 +F src/vdbeaux.c 6d0a75c1fbc7efea6924f6895ebceca664001464bc7ac56949d3c60aa5e498a0 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 6cfed43758d57b6e3b99d9cdedfeccd86e45a07e427b22d8487cbdbebb6c522a F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -2035,8 +2035,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 c9080b6505b839cc0bb5bd25ce7df0daa91a0a303d037ffe6e77888c8584b932 -R c6933aa36b3965399e80dc36fb15b922 +P 4fb77e96fa89a23a9365320c4190834edd6c09cfaf1ca30b34ce19b747ebbec0 +R 5c6e987358d9e0bba6df4dc33586711a U drh -Z f66ba4d30fb256e3ce3a8281933b3c32 +Z 8c0c9fb2c03809d55de676732eaf3a4b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 82a1ebdb17..250cad019b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4fb77e96fa89a23a9365320c4190834edd6c09cfaf1ca30b34ce19b747ebbec0 \ No newline at end of file +904b54625d985e742888e06ba792cab316b9ec9d6669d9cf509bac48030373ca \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 67de532d80..131740ac6c 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4585,7 +4585,7 @@ int sqlite3VdbeRecordCompareWithSkip( serial_type = aKey1[idx1]; testcase( serial_type==12 ); if( serial_type>=10 ){ - rc = +1; + rc = serial_type==10 ? -1 : +1; }else if( serial_type==0 ){ rc = -1; }else if( serial_type==7 ){ @@ -4610,7 +4610,7 @@ int sqlite3VdbeRecordCompareWithSkip( ** numbers). Types 10 and 11 are currently "reserved for future ** use", so it doesn't really matter what the results of comparing ** them to numberic values are. */ - rc = +1; + rc = serial_type==10 ? -1 : +1; }else if( serial_type==0 ){ rc = -1; }else{ From ac79fa1c785b4660761a0a98ec7f86d7568fd5ec Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 18 Oct 2022 15:02:08 +0000 Subject: [PATCH 22/65] Add new test file windowE.test, to test the window functions modules response to an inconsistent collation sequence. FossilOrigin-Name: 740a2eb0928d54fdf735a8e573c6a61a34dbd295b46e5b6ef39e957fd2623293 --- manifest | 13 ++++++----- manifest.uuid | 2 +- test/windowE.test | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 test/windowE.test diff --git a/manifest b/manifest index c13ee1adf0..cb6da43b72 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correct\ssort\sorder\sfor\sserial-type\s10\sentries\sin\sthe\sdatabase\sfile.\s\sThis\nis\sa\scontinuation\sof\s[4fb77e96fa89a23a]. -D 2022-10-18T13:27:31.501 +C Add\snew\stest\sfile\swindowE.test,\sto\stest\sthe\swindow\sfunctions\smodules\sresponse\sto\san\sinconsistent\scollation\ssequence. +D 2022-10-18T15:02:08.725 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1905,6 +1905,7 @@ F test/windowA.test 6d63dc1260daa17141a55007600581778523a8b420629f1282d2acfc36af F test/windowB.test f2fb42b864b0cf431c956407583e9478a74c3642bdf8737fdcb6ff4a40298b07 F test/windowC.test 6fd75f5bb2f1343d34e470e36e68f0ff638d8a42f6aa7d99471261b31a0d42f2 F test/windowD.test 65cf5a765fb8072450e8a0de2979ce7f09a38d87724fe1280c6444073e3da49b +F test/windowE.test 6ba0c8048e4cc02b942e56640f8fcd50fd7ca72c876656c40f6baf42e316684c F test/windowerr.tcl f5acd6fbc210d7b5546c0e879d157888455cd4a17a1d3f28f07c1c8a387019e0 F test/windowerr.test a8b752402109c15aa1c5efe1b93ccb0ce1ef84fa964ae1cd6684dd0b3cc1819b F test/windowfault.test 15094c1529424e62f798bc679e3fe9dfab6e8ba2f7dfe8c923b6248c31660a7c @@ -2035,8 +2036,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 4fb77e96fa89a23a9365320c4190834edd6c09cfaf1ca30b34ce19b747ebbec0 -R 5c6e987358d9e0bba6df4dc33586711a -U drh -Z 8c0c9fb2c03809d55de676732eaf3a4b +P 904b54625d985e742888e06ba792cab316b9ec9d6669d9cf509bac48030373ca +R 609c010622cb8a1edf242ffa07ea33a0 +U dan +Z 47ec91d5045ad14459bc2cd80292963b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 250cad019b..d617a968ca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -904b54625d985e742888e06ba792cab316b9ec9d6669d9cf509bac48030373ca \ No newline at end of file +740a2eb0928d54fdf735a8e573c6a61a34dbd295b46e5b6ef39e957fd2623293 \ No newline at end of file diff --git a/test/windowE.test b/test/windowE.test new file mode 100644 index 0000000000..f20bcdaaa8 --- /dev/null +++ b/test/windowE.test @@ -0,0 +1,58 @@ +# 2022 October 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix windowE + +proc custom {a b} { return [string compare $a $b] } +db collate custom custom + +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT COLLATE custom); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t1 VALUES(3, 'three'); + INSERT INTO t1 VALUES(4, 'four'); + INSERT INTO t1 VALUES(5, 'five'); + INSERT INTO t1 VALUES(6, 'six'); + CREATE INDEX t1b ON t1(b); +} + +do_execsql_test 1.1 { + SELECT * FROM t1 +} { + 1 one 2 two 3 three 4 four 5 five 6 six +} + +do_execsql_test 1.2 { + SELECT group_concat(a,',') OVER win FROM t1 + WINDOW win AS ( + ORDER BY b RANGE BETWEEN 1 PRECEDING AND 2 PRECEDING + ) +} { + 5 4 1 6 3 2 +} + +proc custom {a b} { return [string compare $b $a] } + +do_execsql_test 1.3 { + SELECT group_concat(a,',') OVER win FROM t1 + WINDOW win AS ( + ORDER BY b RANGE BETWEEN 1 PRECEDING AND 2 PRECEDING + ) +} { + 5 5,4 5,4,1 5,4,1,6 5,4,1,6,3 5,4,1,6,3,2 +} + +finish_test + From a331cf7e5792949ada1371bf61fdbf3b26e9d8d5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 18 Oct 2022 16:47:41 +0000 Subject: [PATCH 23/65] Fix the indexed expression resolver for generated columns so that it picks the correct table in a self-join. FossilOrigin-Name: 54c3eb085aca92da2b819f3532ee4750b377265f7e1e914600ea3c3d535efe51 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 20 +++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 7dd1de75d8..8307bc415b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\srecent\strunk\sfixes\sinto\sthe\sindex-expr-opt\sbranch. -D 2022-10-18T16:32:22.335 +C Fix\sthe\sindexed\sexpression\sresolver\sfor\sgenerated\scolumns\sso\sthat\sit\spicks\nthe\scorrect\stable\sin\sa\sself-join. +D 2022-10-18T16:47:41.814 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -571,7 +571,7 @@ F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5 F src/dbpage.c 5808e91bc27fa3981b028000f8fadfdc10ce9e59a34ce7dc4e035a69be3906ec F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e -F src/expr.c ba67701bd7621ebba9c472fcc2dbd4f6444260530e694fa9d87281f9aedec93c +F src/expr.c 74a947891247873696385bf910e60c60e50283bbc0e8ef90b571ac60bc4b6279 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 722f20779f5342a787922deded3628d8c74b5249cab04098cf17ee2f2aaff002 F src/func.c fe2a795ad647ce42054873ac91c43beb7b5d204892903a67f6e7e314379b9d4a @@ -2036,8 +2036,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 c7b9cc645b394a1b638a9a13ca83d321215aaa78d69ca70c6baa0ee692ed21bf 740a2eb0928d54fdf735a8e573c6a61a34dbd295b46e5b6ef39e957fd2623293 -R f7f5f954c4cc82eef2f394d97ecd28bc +P 6198ab4b871c464448ae303072bde0a810cac566a516cc29b1bf806fbd0a6c7b +R 51dcaf4cc6cc82ca16d600c0c30b38d8 U drh -Z 298a7ba276579f138f35bb1c8d732eed +Z c6035e9224ad1746d908acc7b5320c40 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 52c2ac163e..9e3658c558 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6198ab4b871c464448ae303072bde0a810cac566a516cc29b1bf806fbd0a6c7b \ No newline at end of file +54c3eb085aca92da2b819f3532ee4750b377265f7e1e914600ea3c3d535efe51 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 30f9031e21..c2e399f119 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4057,8 +4057,13 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup( IndexedExpr *p; Vdbe *v; for(p=pParse->pIdxExpr; p; p=p->pIENext){ - if( p->iDataCur<0 ) continue; - if( sqlite3ExprCompare(0, pExpr, p->pExpr, p->iDataCur)!=0 ) continue; + int iDataCur = p->iDataCur; + if( iDataCur<0 ) continue; + if( pParse->iSelfTab ){ + if( p->iDataCur!=pParse->iSelfTab-1 ) continue; + iDataCur = -1; + } + if( sqlite3ExprCompare(0, pExpr, p->pExpr, iDataCur)!=0 ) continue; v = pParse->pVdbe; assert( v!=0 ); if( p->bMaybeNullRow ){ @@ -4108,17 +4113,14 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ assert( target>0 && target<=pParse->nMem ); assert( v!=0 ); - if( pParse->pIdxExpr!=0 - && pExpr!=0 +expr_code_doover: + if( pExpr==0 ){ + op = TK_NULL; + }else if( pParse->pIdxExpr!=0 && !ExprHasProperty(pExpr, EP_Leaf) && (r1 = sqlite3IndexedExprLookup(pParse, pExpr, target))>=0 ){ return r1; - } - -expr_code_doover: - if( pExpr==0 ){ - op = TK_NULL; }else{ assert( !ExprHasVVAProperty(pExpr,EP_Immutable) ); op = pExpr->op; From 7a2a8cee5a8f8117a0960be062c3107900d335b2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 18 Oct 2022 20:27:02 +0000 Subject: [PATCH 24/65] Improved byte-code comments for the OP_Column opcodes used by the indexed expression optimization. FossilOrigin-Name: bf6d837fddbf74d5b3f40ad01ea4564edfac00b651d6f3f0e996cc5dc18bb06c --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 2 ++ src/sqliteInt.h | 3 +++ src/where.c | 3 +++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8307bc415b..dbc666f750 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sindexed\sexpression\sresolver\sfor\sgenerated\scolumns\sso\sthat\sit\spicks\nthe\scorrect\stable\sin\sa\sself-join. -D 2022-10-18T16:47:41.814 +C Improved\sbyte-code\scomments\sfor\sthe\sOP_Column\sopcodes\sused\sby\sthe\nindexed\sexpression\soptimization. +D 2022-10-18T20:27:02.327 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -571,7 +571,7 @@ F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5 F src/dbpage.c 5808e91bc27fa3981b028000f8fadfdc10ce9e59a34ce7dc4e035a69be3906ec F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e -F src/expr.c 74a947891247873696385bf910e60c60e50283bbc0e8ef90b571ac60bc4b6279 +F src/expr.c 3ac1d9e87c018f804d10ab9ffa8bf55efef79c376e7ca90d21ac4ef67bfa8f25 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 722f20779f5342a787922deded3628d8c74b5249cab04098cf17ee2f2aaff002 F src/func.c fe2a795ad647ce42054873ac91c43beb7b5d204892903a67f6e7e314379b9d4a @@ -626,7 +626,7 @@ F src/shell.c.in a4c0754470d4fcc2c3da2f0cda0363cecf4a84273d3cc3865325c2df06d5e56 F src/sqlite.h.in d9c8a6243fc0a1c270d69db33758e34b810af3462f9bc5b4af113b347e07c69d F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 5336beea1868d99d2f62e628dbea55e97267dbff8193291ab175e960c5df9141 -F src/sqliteInt.h ed402c12a8b0920ae28cf79631d31490376ca3eed76b386b646712a1dda9e945 +F src/sqliteInt.h 872ab50cc285de11f7fdc0ce1f0481018f14905e4e0b75da43d8cba5a03b8d8d F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -708,7 +708,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 3ab52180ad3a4eea7a2061bd804850f443298adbdc9264642d0a28affe26fb4c +F src/where.c cd5b21856c18ccf739f8b2eb29a2eb97ee69cf6381b10b783a6a2a9f57b99125 F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 F src/wherecode.c 8ec5a413f12af06638dcca36d0954be2151eea6f293d3c67397cef6a90d6adf1 F src/whereexpr.c bf8c155212c886621d71c951053660de6fcc4ee907b17aa02da0a96a39aa9405 @@ -2036,8 +2036,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 6198ab4b871c464448ae303072bde0a810cac566a516cc29b1bf806fbd0a6c7b -R 51dcaf4cc6cc82ca16d600c0c30b38d8 +P 54c3eb085aca92da2b819f3532ee4750b377265f7e1e914600ea3c3d535efe51 +R ae1b5d3a3c2ab2b867842bafa6837a36 U drh -Z c6035e9224ad1746d908acc7b5320c40 +Z cb3bd1c1a3ec2d75a54535d3d8da6ebd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9e3658c558..54e63697ea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -54c3eb085aca92da2b819f3532ee4750b377265f7e1e914600ea3c3d535efe51 \ No newline at end of file +bf6d837fddbf74d5b3f40ad01ea4564edfac00b651d6f3f0e996cc5dc18bb06c \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index c2e399f119..1a743ee5ce 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4074,6 +4074,7 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup( sqlite3VdbeAddOp3(v, OP_IfNullRow, p->iIdxCur, addr+3, target); VdbeCoverage(v); sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target); + VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol)); sqlite3VdbeGoto(v, 0); p = pParse->pIdxExpr; pParse->pIdxExpr = 0; @@ -4082,6 +4083,7 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup( sqlite3VdbeJumpHere(v, addr+2); }else{ sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target); + VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol)); } return target; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0e02db8cc8..a437cc0d25 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3583,6 +3583,9 @@ struct IndexedExpr { int iIdxCol; /* The index column that contains value of pExpr */ u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */ IndexedExpr *pIENext; /* Next in a list of all indexed expressions */ +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS + const char *zIdxName; /* Name of index, used only for bytecode comments */ +#endif }; /* diff --git a/src/where.c b/src/where.c index 39bbf7d64c..dccf493873 100644 --- a/src/where.c +++ b/src/where.c @@ -5434,6 +5434,9 @@ static SQLITE_NOINLINE void whereAddIndexedExpr( p->iIdxCur = iIdxCur; p->iIdxCol = i; p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0; +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS + p->zIdxName = pIdx->zName; +#endif pParse->pIdxExpr = p; if( p->pIENext==0 ){ sqlite3ParserAddCleanup(pParse, whereIndexedExprCleanup, pParse); From b5e2e6fcd39901f3280a4bbbfec7f41d4bcc48f8 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 18 Oct 2022 20:36:50 +0000 Subject: [PATCH 25/65] More work on the JS end-user deliverables. Add tool/stripccomments.c to support that. FossilOrigin-Name: 2156f0744acfe425457430a0f6a7e02de907de85edba81a6d4eef40293e561c8 --- ext/wasm/GNUmakefile | 42 ++++++-- ext/wasm/README-dist.txt | 8 +- ext/wasm/dist.make | 72 +++++++++---- manifest | 19 ++-- manifest.uuid | 2 +- tool/stripccomments.c | 228 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 331 insertions(+), 40 deletions(-) create mode 100644 tool/stripccomments.c diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index a683a91416..881eabfac9 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -1,11 +1,29 @@ ######################################################################## # This GNU makefile drives the build of the sqlite3 WASM # components. It is not part of the canonical build process. +# +# This build assumes a Linux platform and is not intended for +# client-level use. It is for the sqlite project's own development of +# the JS/WASM components. +# +# Primary targets: +# +# default, all = build in dev mode +# +# o0, o1, o2, o3, os, oz = full clean/rebuild with the -Ox level indicated +# by the target name. Rebuild is necessary for all components to get +# the desired optimization level. +# +# dist = create end user deliverables. Add dist-opt=oX to build with a +# specific optimization level, where oX is one of the above-listed +# o? target names. +# +# clean = clean up ######################################################################## SHELL := $(shell which bash 2>/dev/null) MAKEFILE := $(lastword $(MAKEFILE_LIST)) -all: -release: all +default: all +release: default # Emscripten SDK home dir and related binaries... EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/src/emsdk $(HOME)/emsdk)) @@ -46,7 +64,9 @@ dir.api := api dir.jacc := jaccwabyt dir.common := common dir.fiddle := fiddle +dir.tool := $(dir.top)/tool CLEAN_FILES := *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ +DISTCLEAN_FILES := ./-dummy emcc_enable_bigint ?= 1 sqlite3.c := $(dir.top)/sqlite3.c sqlite3.h := $(dir.top)/sqlite3.h @@ -113,8 +133,11 @@ emcc_opt_full := $(emcc_opt) -g3 $(sqlite3.c) $(sqlite3.h): $(MAKE) -C $(dir.top) sqlite3.c +.PHONY: clean distclean clean: -rm -f $(CLEAN_FILES) +distclean: clean + -rm -f $(DISTCLEAN_FILES) ifeq (release,$(filter release,$(MAKECMDGOALS))) ifeq (,$(wasm-strip)) @@ -128,7 +151,12 @@ endif version-info := $(dir.wasm)/version-info $(version-info): $(dir.wasm)/version-info.c $(sqlite3.h) $(MAKEFILE) $(CC) -O0 -I$(dir.top) -o $@ $< -CLEAN_FILES := $(version-info) +DISTCLEAN_FILES += $(version-info) + +stripccomments := $(dir.tool)/stripccomments +$(stripccomments): $(stripccomments).c $(MAKEFILE) + $(CC) -o $@ $< +DISTCLEAN_FILES += $(stripccomments) EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api @@ -480,11 +508,7 @@ push-fiddle: $(fiddle_files) # painful. .PHONY: o0 o1 o2 o3 os oz -o-xtra := -g3 -# ^^^ -g3 is important to keep higher -O levels from mangling (via -# minification), or outright removing, otherwise working code. - -o-xtra += -flto +o-xtra := -flto # ^^^^ -flto can have a considerably performance boost at -O0 but # doubles the build time and seems to have negligible effect on # higher optimization levels. @@ -515,7 +539,9 @@ PLATFORMS_WITH_NO_WASMFS := aarch64 # add any others here THIS_ARCH := $(shell /usr/bin/uname -m) ifneq (,$(filter $(THIS_ARCH),$(PLATFORMS_WITH_NO_WASMFS))) $(info This platform does not support the WASMFS build.) +HAVE_WASMFS := 0 else +HAVE_WASMFS := 1 include wasmfs.make endif diff --git a/ext/wasm/README-dist.txt b/ext/wasm/README-dist.txt index ecb906acdc..bbc82a1df8 100644 --- a/ext/wasm/README-dist.txt +++ b/ext/wasm/README-dist.txt @@ -15,10 +15,10 @@ This archive contains two related deliverables: but is less portable than the main build, so is provided as a separate binary. -Both directories contain small demonstration apps. Browsers will not -server WASM files from file:// URLs, so the demonstrations require a -web server and that server must include the following headers in its -response when serving the files: +Both directories contain small demonstration and test apps. Browsers +will not serve WASM files from file:// URLs, so the demo/test apps +require a web server and that server must include the following +headers in its response when serving the files: Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp diff --git a/ext/wasm/dist.make b/ext/wasm/dist.make index 84abe393a2..cb13b0bd92 100644 --- a/ext/wasm/dist.make +++ b/ext/wasm/dist.make @@ -9,51 +9,87 @@ ####################################################################### MAKEFILE.dist := $(lastword $(MAKEFILE_LIST)) +ifeq (0,$(HAVE_WASMFS)) +$(error The 'dist' target needs to be run on a WASMFS-capable platform.) +endif ######################################################################## # Chicken/egg situation: we need $(version-info) to get the version -# info for the archive name, but that binary may not yet be built, so -# we have to use a temporary name for the archive. +# info for the archive name, but that binary may not yet be built, and +# won't be built until we expand the dependencies. We have to use a +# temporary name for the archive. dist-name = sqlite-wasm-TEMP dist-archive = $(dist-name).zip - +.PHONY: $(dist-archive) +CLEAN_FILES += $(wildcard sqlite-wasm-*.zip) #ifeq (0,1) # $(info WARNING *******************************************************************) # $(info ** Be sure to create the desired build configuration before creating the) # $(info ** distribution archive. Use one of the following targets to do so:) +# $(info **) # $(info ** o2: builds with -O2, resulting in the fastest builds) # $(info ** oz: builds with -Oz, resulting in the smallest builds) # $(info /WARNING *******************************************************************) #endif +######################################################################## +# dist-opt must be the name of a target which triggers the +# build of the files to be packed into the dist archive. The +# intention is that it be one of (o0, o1, o2, o3, os, oz), each of +# which uses like-named -Ox optimization level flags. The o2 target +# provides the best overall runtime speeds. The oz target provides +# slightly slower speeds (roughly 10%) with significantly smaller WASM +# file sizes. Note that -O2 (the o2 target) results in faster binaries +# than both -O3 and -Os (the o3 and os targets) in all tests run to +# date. +dist-opt ?= oz + demo-123.html := $(dir.wasm)/demo-123.html demo-123-worker.html := $(dir.wasm)/demo-123-worker.html demo-123.js := $(dir.wasm)/demo-123.js -demo-files := $(demo-123.js) $(demo-123.html) $(demo-123-worker.html) +demo-files := $(demo-123.js) $(demo-123.html) $(demo-123-worker.html) \ + tester1.html tester1.js tester1-worker.html README-dist := $(dir.wasm)/README-dist.txt -$(dist-archive): $(sqlite3.wasm) $(sqlite3.js) $(sqlite3-wasmfs.wasm) $(sqlite3-wasmfs.js) -#$(dist-archive): $(sqlite3.h) $(sqlite3.c) $(sqlite3-wasm.c) -$(dist-archive): $(MAKEFILE.dist) $(version-info) $(demo-files) $(README-dist) -$(dist-archive): oz - rm -fr $(dist-name) - mkdir -p $(dist-name)/main $(dist-name)/wasmfs - cp -p $(README-dist) $(dist-name)/README.txt - cp -p $(sqlite3.wasm) $(sqlite3.js) $(dist-name)/main - cp -p $(demo-files) $(dist-name)/main - cp -p $(sqlite3-wasmfs.wasm) $(sqlite3-wasmfs.js) $(dist-name)/wasmfs - for i in $(demo-123.js) $(demo-123.html); do \ +dist-dir-main := $(dist-name)/main +dist-dir-wasmfs := $(dist-name)/wasmfs +######################################################################## +# $(dist-archive): create the end-user deliverable archive. +# +# Maintenance reminder: because $(dist-archive) depends on +# $(dist-opt), and $(dist-opt) will depend on clean, having any deps +# on $(dist-archive) which themselves may be cleaned up by the clean +# target will lead to grief in parallel builds (-j #). Thus +# $(dist-target)'s deps must be trimmed to non-generated files or +# files which are _not_ cleaned up by the clean target. +$(dist-archive): \ + $(stripccomments) $(version-info) \ + $(dist-opt) \ + $(MAKEFILE) $(MAKEFILE.dist) + @echo "Making end-user deliverables..." + @rm -fr $(dist-name) + @mkdir -p $(dist-dir-main) $(dist-dir-wasmfs) + @cp -p $(README-dist) $(dist-name)/README.txt + @cp -p $(sqlite3.wasm) $(dist-dir-main) + @$(stripccomments) -k -k < $(sqlite3.js) \ + > $(dist-dir-main)/$(notdir $(sqlite3.js)) + @cp -p $(demo-files) $(dist-dir-main) + @cp -p $(sqlite3-wasmfs.wasm) sqlite3-wasmfs.worker.js $(dist-dir-wasmfs) + @$(stripccomments) -k -k < $(sqlite3-wasmfs.js) \ + > $(dist-dir-wasmfs)/$(notdir $(sqlite3-wasmfs.js)) + @for i in $(demo-123.js) $(demo-123.html); do \ sed -e 's/\bsqlite3\.js\b/sqlite3-wasmfs.js/' $$i \ - > $(dist-name)/wasmfs/$${i##*/} || exit; \ + > $(dist-dir-wasmfs)/$${i##*/} || exit; \ done - vnum=$$($(version-info) --version-number); \ + @vnum=$$($(version-info) --version-number); \ vdir=sqlite-wasm-$$vnum; \ arc=$$vdir.zip; \ + echo "Making $$arc ..."; \ rm -f $$arc; \ mv $(dist-name) $$vdir; \ zip -qr $$arc $$vdir; \ rm -fr $$vdir; \ ls -la $$arc; \ - unzip -l $$arc + unzip -lv $$arc || echo "Missing unzip app? Not fatal." #$(shell $(version-info) --version-number) dist: $(dist-archive) diff --git a/manifest b/manifest index cb6da43b72..40f33190d9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\snew\stest\sfile\swindowE.test,\sto\stest\sthe\swindow\sfunctions\smodules\sresponse\sto\san\sinconsistent\scollation\ssequence. -D 2022-10-18T15:02:08.725 +C More\swork\son\sthe\sJS\send-user\sdeliverables.\sAdd\stool/stripccomments.c\sto\ssupport\sthat. +D 2022-10-18T20:36:50.562 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -473,8 +473,8 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0 -F ext/wasm/GNUmakefile 2fd83d7183bce3f9236fdd2dbe20a4ea37b1d7b26e1a422054ec63008319f065 -F ext/wasm/README-dist.txt bc1fb4f90a28ad2ed0e555a637f393b9249d8d928ac509dad6293b7cae628ea4 +F ext/wasm/GNUmakefile 279fd4589ba602e24d8e66ca795ec5a2275a0e329405e4e984e8ea0579339bae +F ext/wasm/README-dist.txt 170be2d47b4b52504ef09088ca2f143aab657de0f9ac04d3a68e366f40929c3d F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 @@ -504,7 +504,7 @@ F ext/wasm/demo-123.html 7c239c9951d1b113f9f532969ac039294cf1dcfee2b3ae0a2c1ed2b F ext/wasm/demo-123.js e0cbeb3495e14103763d5c49794a24d67cf3d78e0ed5b82843be70c0c2ee4b3b F ext/wasm/demo-kvvfs1.html 7d4f28873de67f51ac18c584b7d920825139866a96049a49c424d6f5a0ea5e7f F ext/wasm/demo-kvvfs1.js 105596bd2ccd0b1deb5fde8e99b536e8242d4bb5932fac0c8403ff3a6bc547e8 -F ext/wasm/dist.make d7076e90f04396f1cc54cb41ee106451496179c10d54bbdebb65ae7b1ae12211 +F ext/wasm/dist.make 1d59fafdfcf6fc5ee0f3351b21199585dba21afcf0518241789fd5d37a1c011d F ext/wasm/fiddle.make b609dfde299b4523d7123b7e0cecaa1a0aff0dd984e62cea653aae91f5063c90 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 531859a471924a0ea48afa218e6877f0c164ca324d51e15843ed6ecc1c65c7ee @@ -2007,6 +2007,7 @@ F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaa F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848 F tool/srcck1.c 371de5363b70154012955544f86fdee8f6e5326f F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 +F tool/stripccomments.c 20b8aabc4694d0d4af5566e42da1f1a03aff057689370326e9269a9ddcffdc37 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh 1612bd947750e21e7b47befad5f6b3825b06cce0705441f903bf35ced65ae9b9 F tool/varint.c 5d94cb5003db9dbbcbcc5df08d66f16071aee003 @@ -2036,8 +2037,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 904b54625d985e742888e06ba792cab316b9ec9d6669d9cf509bac48030373ca -R 609c010622cb8a1edf242ffa07ea33a0 -U dan -Z 47ec91d5045ad14459bc2cd80292963b +P 740a2eb0928d54fdf735a8e573c6a61a34dbd295b46e5b6ef39e957fd2623293 +R f3423b9e5fdd1b3c8749326c161b8bbf +U stephan +Z 8ed4b03e8c6243f1d25f4dc2d31715c7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d617a968ca..965ccd2dac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -740a2eb0928d54fdf735a8e573c6a61a34dbd295b46e5b6ef39e957fd2623293 \ No newline at end of file +2156f0744acfe425457430a0f6a7e02de907de85edba81a6d4eef40293e561c8 \ No newline at end of file diff --git a/tool/stripccomments.c b/tool/stripccomments.c new file mode 100644 index 0000000000..53933c0138 --- /dev/null +++ b/tool/stripccomments.c @@ -0,0 +1,228 @@ +/** + Strips C- and C++-style comments from stdin, sending the results to + stdout. It assumes that its input is legal C-like code, and does + only little error handling. + + It treats string literals as anything starting and ending with + matching double OR single quotes OR backticks (for use with + scripting languages which use those). It assumes that a quote + character within a string which uses the same quote type is escaped + by a backslash. It should not be used on any code which might + contain C/C++ comments inside heredocs, and similar constructs, as + it will strip those out. + + Usage: $0 [--keep-first|-k] < input > output + + The --keep-first (-k) flag tells it to retain the first comment in the + input stream (which is often a license or attribution block). It + may be given repeatedly, each one incrementing the number of + retained comments by one. + + License: Public Domain + Author: Stephan Beal (stephan@wanderinghorse.net) +*/ +#include +#include +#include + +#if 1 +#define MARKER(pfexp) \ + do{ printf("MARKER: %s:%d:\t",__FILE__,__LINE__); \ + printf pfexp; \ + } while(0) +#else +#define MARKER(exp) if(0) printf +#endif + +struct { + FILE * input; + FILE * output; + int rc; + int keepFirst; +} App = { + 0/*input*/, + 0/*output*/, + 0/*rc*/, + 0/*keepFirst*/ +}; + +void do_it_all(void){ + enum states { + S_NONE = 0 /* not in comment */, + S_SLASH1 = 1 /* slash - possibly comment prefix */, + S_CPP = 2 /* in C++ comment */, + S_C = 3 /* in C comment */ + }; + int ch, prev = EOF; + FILE * out = App.output; + int const slash = '/'; + int const star = '*'; + int line = 1; + int col = 0; + enum states state = S_NONE /* current state */; + int elide = 0 /* true if currently eliding output */; + int state3Col = -99 + /* huge kludge for odd corner case: */ + /*/ <--- here. state3Col marks the source column in which a C-style + comment starts, so that it can tell if star-slash inside a + C-style comment is the end of the comment or is the weird corner + case marked at the start of _this_ comment block. */; + for( ; EOF != (ch = fgetc(App.input)); prev = ch, + ++col){ + switch(state){ + case S_NONE: + if('\''==ch || '"'==ch || '`'==ch){ + /* Read string literal... + needed to properly catch comments in strings. */ + int const quote = ch, + startLine = line, startCol = col; + int ch2, escaped = 0, endOfString = 0; + fputc(ch, out); + for( ++col; !endOfString && EOF != (ch2 = fgetc(App.input)); + ++col ){ + switch(ch2){ + case '\\': escaped = !escaped; + break; + case '`': + case '\'': + case '"': + if(!escaped && quote == ch2) endOfString = 1; + escaped = 0; + break; + default: + escaped = 0; + break; + } + if('\n'==ch2){ + ++line; + col = 0; + } + fputc(ch2, out); + } + if(EOF == ch2){ + fprintf(stderr, "Unexpected EOF while reading %s literal " + "on line %d column %d.\n", + ('\''==ch) ? "char" : "string", + startLine, startCol); + App.rc = 1; + return; + } + break; + } + else if(slash == ch){ + /* MARKER(("state 0 ==> 1 @ %d:%d\n", line, col)); */ + state = S_SLASH1; + break; + } + fputc(ch, out); + break; + case S_SLASH1: /* 1 slash */ + /* MARKER(("SLASH1 @ %d:%d App.keepFirst=%d\n", + line, col, App.keepFirst)); */ + switch(ch){ + case '*': + /* Enter C comment */ + if(App.keepFirst>0){ + elide = 0; + --App.keepFirst; + }else{ + elide = 1; + } + /*MARKER(("state 1 ==> 3 @ %d:%d\n", line, col));*/ + state = S_C; + state3Col = col-1; + if(!elide){ + fputc(prev, out); + fputc(ch, out); + } + break; + case '/': + /* Enter C++ comment */ + if(App.keepFirst>0){ + elide = 0; + --App.keepFirst; + }else{ + elide = 1; + } + /*MARKER(("state 1 ==> 2 @ %d:%d\n", line, col));*/ + state = S_CPP; + if(!elide){ + fputc(prev, out); + fputc(ch, out); + } + break; + default: + /* It wasn't a comment after all. */ + state = S_NONE; + if(!elide){ + fputc(prev, out); + fputc(ch, out); + } + } + break; + case S_CPP: /* C++ comment */ + if('\n' == ch){ + /* MARKER(("state 2 ==> 0 @ %d:%d\n", line, col)); */ + state = S_NONE; + elide = 0; + } + if(!elide){ + fputc(ch, out); + } + break; + case S_C: /* C comment */ + if(!elide){ + fputc(ch, out); + } + if(slash == ch){ + if(star == prev){ + /* MARKER(("state 3 ==> 0 @ %d:%d\n", line, col)); */ + /* Corner case which breaks this: */ + /*/ <-- slash there */ + /* That shows up twice in a piece of 3rd-party + code i use. */ + /* And thus state3Col was introduced :/ */ + if(col!=state3Col+2){ + state = S_NONE; + elide = 0; + state3Col = -99; + } + } + } + break; + default: + assert(!"impossible!"); + break; + } + if('\n' == ch){ + ++line; + col = 0; + state3Col = -99; + } + } +} + +static void usage(char const *zAppName){ + fprintf(stderr, "Strips C- and C++-style comments from stdin and sends " + "the results to stdout.\n"); + fprintf(stderr, "Usage: %s [--keep-first|-k] < input > output\n", zAppName); +} + +int main( int argc, char const * const * argv ){ + int i; + for(i = 1; i < argc; ++i){ + char const * zArg = argv[i]; + while( '-'==*zArg ) ++zArg; + if( 0==strcmp(zArg,"k") + || 0==strcmp(zArg,"keep-first") ){ + ++App.keepFirst; + }else{ + usage(argv[0]); + return 1; + } + } + App.input = stdin; + App.output = stdout; + do_it_all(); + return App.rc ? 1 : 0; +} From 72ab36619233cdf216716f5f17541dfc78d60abd Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 18 Oct 2022 22:37:07 +0000 Subject: [PATCH 26/65] If a virtual column whose value is constant gets indexed, do not include that column in the IndexedExpr list. dbsqlfuzz 59ac17a99b9a5c4930ee71cc153c9428a0c0e794 FossilOrigin-Name: c21eb903f06a16d4fafa5f895be08414fa58e6a91c148030aec8676b40c2d66d --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index dbc666f750..d02cffb63f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sbyte-code\scomments\sfor\sthe\sOP_Column\sopcodes\sused\sby\sthe\nindexed\sexpression\soptimization. -D 2022-10-18T20:27:02.327 +C If\sa\svirtual\scolumn\swhose\svalue\sis\sconstant\sgets\sindexed,\sdo\snot\sinclude\nthat\scolumn\sin\sthe\sIndexedExpr\slist.\ndbsqlfuzz\s59ac17a99b9a5c4930ee71cc153c9428a0c0e794 +D 2022-10-18T22:37:07.303 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -708,7 +708,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c cd5b21856c18ccf739f8b2eb29a2eb97ee69cf6381b10b783a6a2a9f57b99125 +F src/where.c 5dcd88d080ad302da4278f55acce12fd1c1f91eff2bcbfa2c0806d33fa230a5f F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743 F src/wherecode.c 8ec5a413f12af06638dcca36d0954be2151eea6f293d3c67397cef6a90d6adf1 F src/whereexpr.c bf8c155212c886621d71c951053660de6fcc4ee907b17aa02da0a96a39aa9405 @@ -2036,8 +2036,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 54c3eb085aca92da2b819f3532ee4750b377265f7e1e914600ea3c3d535efe51 -R ae1b5d3a3c2ab2b867842bafa6837a36 +P bf6d837fddbf74d5b3f40ad01ea4564edfac00b651d6f3f0e996cc5dc18bb06c +R 4b10826dbdabc43e45460aaf0b235a26 U drh -Z cb3bd1c1a3ec2d75a54535d3d8da6ebd +Z be3c5dec512d6ceddfe2e2950bc8e7bf # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 54e63697ea..5b7598c5ff 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bf6d837fddbf74d5b3f40ad01ea4564edfac00b651d6f3f0e996cc5dc18bb06c \ No newline at end of file +c21eb903f06a16d4fafa5f895be08414fa58e6a91c148030aec8676b40c2d66d \ No newline at end of file diff --git a/src/where.c b/src/where.c index dccf493873..8c65dc7b02 100644 --- a/src/where.c +++ b/src/where.c @@ -5426,6 +5426,7 @@ static SQLITE_NOINLINE void whereAddIndexedExpr( }else{ continue; } + if( sqlite3ExprIsConstant(pExpr) ) continue; p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr)); if( p==0 ) break; p->pIENext = pParse->pIdxExpr; From 71de8e02416aa9a4ad90ac6958ff3fa025a33d2d Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 19 Oct 2022 01:07:30 +0000 Subject: [PATCH 27/65] Considerable wasm/js build cleanups and reworking. Remove wasmfs builds from the end-user deliverables and disable the wasmfs build by default, per /chat discussion, as it doubles our deliverable count for only marginal gain. Attempt to move the sqlite3.js/wasm files into subdirectories but rediscovered that that breaks loading in Worker mode because URI resolution of the wasm files differs depending on whether the main script is loaded from a script tag or a Worker. FossilOrigin-Name: 5b23e0675efdd2f1ea7b4f5836a579e8d6aa8a25b3f1a6a950520ad845ff01bb --- ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle | 15 --- ext/wasm/GNUmakefile | 155 +++++++++++++---------- ext/wasm/README-dist.txt | 28 ++-- ext/wasm/api/extern-post-js.js | 8 ++ ext/wasm/api/sqlite3-api-prologue.js | 1 - ext/wasm/api/sqlite3-wasm.c | 2 +- ext/wasm/dist.make | 31 ++--- ext/wasm/fiddle.make | 11 +- ext/wasm/index.html | 10 +- ext/wasm/sqlite3-worker1.js | 22 +++- ext/wasm/testing1.html | 36 ------ ext/wasm/wasmfs.make | 29 +++-- manifest | 32 +++-- manifest.uuid | 2 +- 14 files changed, 185 insertions(+), 197 deletions(-) delete mode 100644 ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle delete mode 100644 ext/wasm/testing1.html diff --git a/ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle b/ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle deleted file mode 100644 index 5e80f703ae..0000000000 --- a/ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle +++ /dev/null @@ -1,15 +0,0 @@ -FS -addFunction -allocateUTF8OnStack -ccall -cwrap -getValue -intArrayFromString -lengthBytesUTF8 -removeFunction -setValue -stackAlloc -stackRestore -stackSave -stringToUTF8Array -wasmMemory diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 881eabfac9..f461f8b46a 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -1,4 +1,4 @@ -######################################################################## +####################################################################### # This GNU makefile drives the build of the sqlite3 WASM # components. It is not part of the canonical build process. # @@ -22,8 +22,10 @@ ######################################################################## SHELL := $(shell which bash 2>/dev/null) MAKEFILE := $(lastword $(MAKEFILE_LIST)) +CLEAN_FILES := +DISTCLEAN_FILES := ./--dummy-- default: all -release: default +release: oz # Emscripten SDK home dir and related binaries... EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/src/emsdk $(HOME)/emsdk)) @@ -58,15 +60,50 @@ else endif dir.top := ../.. -# Reminder: some Emscripten flags require absolute paths -dir.wasm := $(patsubst %/,%,$(dir $(abspath $(MAKEFILE)))) +# Reminder: some Emscripten flags require absolute paths but we want +# relative paths for most stuff simply to reduce noise. The +# $(abspath...) GNU make function can transform relative paths to +# absolute. +dir.wasm := $(patsubst %/,%,$(dir $(MAKEFILE))) dir.api := api dir.jacc := jaccwabyt dir.common := common dir.fiddle := fiddle dir.tool := $(dir.top)/tool -CLEAN_FILES := *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ -DISTCLEAN_FILES := ./-dummy +######################################################################## +# MAINTENANCE REMINDER: the output .js and .wasm files of emcc must be +# in _this_ dir, rather than a subdir, or else parts of the generated +# code get confused and cannot load property. Specifically, when X.js +# loads X.wasm, whether or not X.js uses the correct path for X.wasm +# depends on how it's loaded: an HTML script tag will resolve it +# intuitively, whereas a Worker's call to importScripts() will not. +# That's a fundamental incompatibility with how URL resolution in +# JS happens between those two contexts. See: +# +# https://zzz.buzz/2017/03/14/relative-uris-in-web-development/ +# +# We unfortunately have no way, from Worker-initiated code, to +# automatically resolve the path from X.js to X.wasm. +# +# In case we ever find a solution to that which does not require +# duplicating the X.js files only to swap out the path to X.wasm for +# the loading-from-worker case... +# +# dir.dout = output dir for deliverables. +dir.dout := $(dir.wasm) +# dir.tmp = output dir for intermediary build files, as opposed to +# end-user deliverables. +dir.tmp := $(dir.wasm)/bld +#CLEAN_FILES += $(wildcard $(dir.dout)/*) $(wildcard $(dir.tmp)/*) +ifeq (,$(wildcard $(dir.dout))) + dir._tmp := $(shell mkdir -p $(dir.dout)) +endif +ifeq (,$(wildcard $(dir.tmp))) + dir._tmp := $(shell mkdir -p $(dir.tmp)) +endif + +cflags.common := -I. -I.. -I$(dir.top) +CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ emcc_enable_bigint ?= 1 sqlite3.c := $(dir.top)/sqlite3.c sqlite3.h := $(dir.top)/sqlite3.h @@ -149,6 +186,8 @@ else endif version-info := $(dir.wasm)/version-info +# ^^^^ NOT in $(dir.tmp) because we need it to survive the cleanup +# process for the dist build to work properly. $(version-info): $(dir.wasm)/version-info.c $(sqlite3.h) $(MAKEFILE) $(CC) -O0 -I$(dir.top) -o $@ $< DISTCLEAN_FILES += $(version-info) @@ -158,15 +197,16 @@ $(stripccomments): $(stripccomments).c $(MAKEFILE) $(CC) -o $@ $< DISTCLEAN_FILES += $(stripccomments) -EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api - -EXPORTED_FUNCTIONS.api: $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE) +EXPORTED_FUNCTIONS.api.in := $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api) +EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api +$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE) cat $(EXPORTED_FUNCTIONS.api.in) > $@ -CLEAN_FILES += EXPORTED_FUNCTIONS.api -sqlite3-license-version.js := sqlite3-license-version.js +sqlite3-license-version.js := $(dir.tmp)/sqlite3-license-version.js sqlite3-license-version-header.js := $(dir.api)/sqlite3-license-version-header.js -sqlite3-api-build-version.js := $(dir.api)/sqlite3-api-build-version.js +sqlite3-api-build-version.js := $(dir.tmp)/sqlite3-api-build-version.js +# sqlite3-api.jses = the list of JS files which make up $(sqlite3-api.js), in +# the order they need to be assembled. sqlite3-api.jses := $(sqlite3-license-version.js) sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js sqlite3-api.jses += $(dir.common)/whwasmutil.js @@ -178,10 +218,7 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js sqlite3-api.jses += $(dir.api)/sqlite3-api-opfs.js sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js -sqlite3-api.js := sqlite3-api.js -CLEAN_FILES += $(sqlite3-api.js) -CLEAN_FILES += $(sqlite3-license-version.js) -CLEAN_FILES += $(sqlite3-api-build-version.js) +sqlite3-api.js := $(dir.tmp)/sqlite3-api.js $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) @echo "Making $@..." @for i in $(sqlite3-api.jses); do \ @@ -190,7 +227,7 @@ $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) echo "/* END FILE: $$i */"; \ done > $@ -$(sqlite3-api-build-version.js): $(version-info) +$(sqlite3-api-build-version.js): $(version-info) $(MAKEFILE) @echo "Making $@..." @{ \ echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \ @@ -204,8 +241,7 @@ $(sqlite3-api-build-version.js): $(version-info) # --post-js and --pre-js are emcc flags we use to append/prepend JS to # the generated emscripten module file. pre-js.js := $(dir.api)/pre-js.js -post-js.js := post-js.js -CLEAN_FILES += $(post-js.js) +post-js.js := $(dir.tmp)/post-js.js post-jses := \ $(dir.api)/post-js-header.js \ $(sqlite3-api.js) \ @@ -222,7 +258,7 @@ extern-pre-js.js := $(dir.api)/extern-pre-js.js pre-post-common.flags := \ --post-js=$(post-js.js) \ --extern-post-js=$(extern-post-js.js) \ - --extern-pre-js=$(dir.wasm)/$(sqlite3-license-version.js) + --extern-pre-js=$(sqlite3-license-version.js) pre-post-jses.deps := $(post-js.js) \ $(extern-post-js.js) $(extern-pre-js.js) $(sqlite3-license-version.js) $(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) $(MAKEFILE) @@ -275,12 +311,11 @@ emcc.jsflags += -sMODULARIZE emcc.jsflags += -sSTRICT_JS emcc.jsflags += -sDYNAMIC_EXECUTION=0 emcc.jsflags += -sNO_POLYFILL -emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api +emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.api) emcc.exportedRuntimeMethods := \ - -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack + -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory # FS ==> stdio/POSIX I/O proxies # wasmMemory ==> required by our code for use with -sIMPORTED_MEMORY - # allocateUTF8OnStack => for kvvfs internals emcc.jsflags += $(emcc.exportedRuntimeMethods) emcc.jsflags += -sUSE_CLOSURE_COMPILER=0 emcc.jsflags += -sIMPORTED_MEMORY @@ -312,7 +347,7 @@ emcc.jsflags += -Wno-limited-postlink-optimizations emcc.jsflags += -sERROR_ON_UNDEFINED_SYMBOLS=0 emcc.jsflags += -sLLD_REPORT_UNDEFINED #emcc.jsflags += --allow-undefined -emcc.jsflags += --import-undefined +#emcc.jsflags += --import-undefined #emcc.jsflags += --unresolved-symbols=import-dynamic --experimental-pic #emcc.jsflags += --experimental-pic --unresolved-symbols=ingore-all --import-undefined #emcc.jsflags += --unresolved-symbols=ignore-all @@ -340,36 +375,22 @@ emcc.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint) # debugging info, _huge_. ######################################################################## -######################################################################## -# Maintenance reminder: the output .js and .wasm files of emcc must be -# in _this_ dir, rather than a subdir, or else parts of the generated -# code get confused and cannot load property (namely, the -# sqlite3.worker.js generated in conjunction with -sWASMFS). -sqlite3.js := sqlite3.js -sqlite3.wasm := sqlite3.wasm -sqlite3-wasm.o := $(dir.api)/sqlite3-wasm.o -$(sqlite3-wasm.o): emcc.cflags += $(SQLITE_OPT) -$(sqlite3-wasm.o): $(dir.top)/sqlite3.c +sqlite3.js := $(dir.dout)/sqlite3.js +sqlite3.wasm := $(dir.dout)/sqlite3.wasm sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c -######################################################################## -# call-wasm-c-compile sets up build rules -# for $1.o. $1 must be the name of a C file (with extension). -define call-wasm-c-compile -$(1).o := $$(subst .c,.o,$(1)) -sqlite3.wasm.obj += $$($(1).o) -$$($(1).o): $$(MAKEFILE) $(1) - $$(emcc.bin) $$(emcc_opt_full) $$(emcc.flags) $$(emcc.cflags) -c $(1) -o $$@ -CLEAN_FILES += $$($(1).o) -endef -$(foreach c,$(sqlite3-wasm.c),$(eval $(call call-wasm-c-compile,$(c)))) +# sqlite3-wasm.o vs sqlite3-wasm.c: building against the latter +# (predictably) results in a slightly faster binary, but we're close +# enough to the target speed requirements that the 500ms makes a +# difference. Thus we build all binaries against sqlite3-wasm.c +# instead of building a shared copy of sqlite3-wasm.o. $(eval $(call call-make-pre-js,sqlite3)) $(sqlite3.js): $(MAKEFILE) $(sqlite3.wasm.obj) \ - EXPORTED_FUNCTIONS.api \ + $(EXPORTED_FUNCTIONS.api) \ $(pre-post-sqlite3.deps) @echo "Building $@ ..." $(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \ $(emcc.jsflags) $(pre-post-common.flags) $(pre-post-sqlite3.flags) \ - $(sqlite3.wasm.obj) + $(cflags.common) $(SQLITE_OPT) $(sqlite3-wasm.c) chmod -x $(sqlite3.wasm) $(maybe-wasm-strip) $(sqlite3.wasm) @ls -la $@ $(sqlite3.wasm) @@ -417,7 +438,8 @@ speedtest1-common.eflags += -sINITIAL_MEMORY=128450560 speedtest1-common.eflags += -sSTRICT_JS speedtest1-common.eflags += -sMODULARIZE speedtest1-common.eflags += -Wno-limited-postlink-optimizations -speedtest1-common.eflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.speedtest1 +EXPORTED_FUNCTIONS.speedtest1 := $(abspath $(dir.tmp)/EXPORTED_FUNCTIONS.speedtest1) +speedtest1-common.eflags += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.speedtest1) speedtest1-common.eflags += $(emcc.exportedRuntimeMethods) speedtest1-common.eflags += -sALLOW_TABLE_GROWTH speedtest1-common.eflags += -sDYNAMIC_EXECUTION=0 @@ -444,31 +466,24 @@ speedtest1.exit-runtime1 := -sEXIT_RUNTIME=1 # -sEXIT_RUNTIME=1 but we need EXIT_RUNTIME=0 for the worker-based app # which runs speedtest1 multiple times. -EXPORTED_FUNCTIONS.speedtest1: EXPORTED_FUNCTIONS.api - { echo _wasm_main; cat EXPORTED_FUNCTIONS.api; } > $@ -CLEAN_FILES += EXPORTED_FUNCTIONS.speedtest1 -speedtest1.js := speedtest1.js +$(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api) + @echo "Making $@ ..." + @{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api); } > $@ +speedtest1.js := $(dir.dout)/speedtest1.js speedtest1.wasm := $(subst .js,.wasm,$(speedtest1.js)) -speedtest1.cflags := \ - -I. -I.. -I$(dir.top) \ - -DSQLITE_SPEEDTEST1_WASM -speedtest1.cs := $(speedtest1.c) $(sqlite3-wasm.c) -$(speedtest1.js): emcc.cflags+= -# speedtest1 notes re. sqlite3-wasm.o vs sqlite3-wasm.c: building against -# the latter (predictably) results in a slightly faster binary, but we're -# close enough to the target speed requirements that the 500ms makes a -# difference. +speedtest1.cflags := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM +speedtest1.cses := $(speedtest1.c) $(sqlite3-wasm.c) $(eval $(call call-make-pre-js,speedtest1)) -$(speedtest1.js): $(MAKEFILE) $(speedtest1.cs) \ +$(speedtest1.js): $(MAKEFILE) $(speedtest1.cses) \ $(pre-post-speedtest1.deps) \ - EXPORTED_FUNCTIONS.speedtest1 + $(EXPORTED_FUNCTIONS.speedtest1) @echo "Building $@ ..." $(emcc.bin) \ $(speedtest1.eflags) $(speedtest1-common.eflags) $(speedtest1.cflags) \ $(pre-post-speedtest1.flags) \ $(SQLITE_OPT) \ $(speedtest1.exit-runtime0) \ - -o $@ $(speedtest1.cs) -lm + -o $@ $(speedtest1.cses) -lm $(maybe-wasm-strip) $(speedtest1.wasm) ls -la $@ $(speedtest1.wasm) @@ -531,6 +546,13 @@ oz: clean include fiddle.make +ifneq (,$(filter wasmfs,$(MAKECMDGOALS))) +# wasmfs build disabled 2022-10-19 per /chat +# discussion. OPFS-over-wasmfs was initially a stopgap measure and a +# convenient point of comparison for the OPFS sqlite3_vfs's +# performance, but it currently doubles our deliverables for very +# little, if any, benefit. +# ######################################################################## # Some platforms do not support the WASMFS build. Raspberry Pi OS is one # of them. As such platforms are discovered, add their (uname -m) name @@ -544,9 +566,12 @@ else HAVE_WASMFS := 1 include wasmfs.make endif +endif +# /wasmfs +######################################################################## ######################################################################## -# Create deliverables: TODO +# Create deliverables: ifneq (,$(filter dist,$(MAKECMDGOALS))) include dist.make endif diff --git a/ext/wasm/README-dist.txt b/ext/wasm/README-dist.txt index bbc82a1df8..422f3f1e0c 100644 --- a/ext/wasm/README-dist.txt +++ b/ext/wasm/README-dist.txt @@ -4,23 +4,21 @@ Main project page: https://sqlite.org TODO: link to main WASM/JS docs, once they are online -This archive contains two related deliverables: +This archive contains the sqlite3.js and sqlite3.wasm file which make +up the sqlite3 WASM/JS build. -- ./main contains the sqlite3.js and sqlite3.wasm file which make up - the standard sqlite3 WASM/JS build. - -- ./wasmfs contains a build of those files which includes the - Emscripten WASMFS[^1]. It offers an alternative approach - to accessing the browser-side Origin-Private FileSystem - but is less portable than the main build, so is provided - as a separate binary. - -Both directories contain small demonstration and test apps. Browsers -will not serve WASM files from file:// URLs, so the demo/test apps -require a web server and that server must include the following -headers in its response when serving the files: +The jswasm directory contains both the main deliverables and small +demonstration and test apps. Browsers will not serve WASM files from +file:// URLs, so the demo/test apps require a web server and that +server must include the following headers in its response when serving +the files: Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp -[^1]: https://emscripten.org +The files named sqlite3*.js and sqlite3.wasm belong to the core +sqlite3 deliverables and the others are soley for demonstration and +may be discarded. They are not in separate directories from the main +deliverables because a quirk of URI resolution in JS code would then +require that sqlite3.js be duplicated and edited for Worker-loaded +operation. diff --git a/ext/wasm/api/extern-post-js.js b/ext/wasm/api/extern-post-js.js index 51e8d12b2b..7dba03b3a7 100644 --- a/ext/wasm/api/extern-post-js.js +++ b/ext/wasm/api/extern-post-js.js @@ -43,3 +43,11 @@ self.sqlite3InitModule.ready = originalInit.ready; //console.warn("Replaced sqlite3InitModule()"); })(); + +if(0){ + console.warn("self.location.href =",self.location.href); + if('undefined' !== typeof document){ + console.warn("document.currentScript.src =", + document?.currentScript?.src); + } +} diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 7d9ae96914..f8c0f024e6 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -1158,7 +1158,6 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( */ capi.sqlite3_web_db_export = function(pDb){ if(!pDb) toss('Invalid sqlite3* argument.'); - const wasm = wasm; if(!wasm.bigIntEnabled) toss('BigInt64 support is not enabled.'); const stack = wasm.pstack.pointer; let pOut; diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index 26771d5c9a..cda4e7ae2f 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -1007,7 +1007,7 @@ int sqlite3_wasm_init_wasmfs(const char *zMountPoint){ hypothetically suffice for the transient wasm-based virtual filesystem we're currently running in. */ const int rc = wasmfs_create_directory(zMountPoint, 0777, pOpfs); - emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc); + /*emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);*/ if(rc) return SQLITE_IOERR; } return pOpfs ? 0 : SQLITE_NOMEM; diff --git a/ext/wasm/dist.make b/ext/wasm/dist.make index cb13b0bd92..e19b361b19 100644 --- a/ext/wasm/dist.make +++ b/ext/wasm/dist.make @@ -9,10 +9,6 @@ ####################################################################### MAKEFILE.dist := $(lastword $(MAKEFILE_LIST)) -ifeq (0,$(HAVE_WASMFS)) -$(error The 'dist' target needs to be run on a WASMFS-capable platform.) -endif - ######################################################################## # Chicken/egg situation: we need $(version-info) to get the version # info for the archive name, but that binary may not yet be built, and @@ -33,7 +29,7 @@ CLEAN_FILES += $(wildcard sqlite-wasm-*.zip) #endif ######################################################################## -# dist-opt must be the name of a target which triggers the +# dist-build must be the name of a target which triggers the # build of the files to be packed into the dist archive. The # intention is that it be one of (o0, o1, o2, o3, os, oz), each of # which uses like-named -Ox optimization level flags. The o2 target @@ -42,7 +38,7 @@ CLEAN_FILES += $(wildcard sqlite-wasm-*.zip) # file sizes. Note that -O2 (the o2 target) results in faster binaries # than both -O3 and -Os (the o3 and os targets) in all tests run to # date. -dist-opt ?= oz +dist-build ?= oz demo-123.html := $(dir.wasm)/demo-123.html demo-123-worker.html := $(dir.wasm)/demo-123-worker.html @@ -50,36 +46,33 @@ demo-123.js := $(dir.wasm)/demo-123.js demo-files := $(demo-123.js) $(demo-123.html) $(demo-123-worker.html) \ tester1.html tester1.js tester1-worker.html README-dist := $(dir.wasm)/README-dist.txt -dist-dir-main := $(dist-name)/main -dist-dir-wasmfs := $(dist-name)/wasmfs +dist-dir-main := $(dist-name)/jswasm +dist.main.extras := \ + sqlite3-opfs-async-proxy.js \ + sqlite3-worker1.js \ + sqlite3-worker1-promiser.js + ######################################################################## # $(dist-archive): create the end-user deliverable archive. # # Maintenance reminder: because $(dist-archive) depends on -# $(dist-opt), and $(dist-opt) will depend on clean, having any deps +# $(dist-build), and $(dist-build) will depend on clean, having any deps # on $(dist-archive) which themselves may be cleaned up by the clean # target will lead to grief in parallel builds (-j #). Thus # $(dist-target)'s deps must be trimmed to non-generated files or # files which are _not_ cleaned up by the clean target. $(dist-archive): \ $(stripccomments) $(version-info) \ - $(dist-opt) \ + $(dist-build) \ $(MAKEFILE) $(MAKEFILE.dist) @echo "Making end-user deliverables..." @rm -fr $(dist-name) - @mkdir -p $(dist-dir-main) $(dist-dir-wasmfs) + @mkdir -p $(dist-dir-main) @cp -p $(README-dist) $(dist-name)/README.txt - @cp -p $(sqlite3.wasm) $(dist-dir-main) + @cp -p $(sqlite3.wasm) $(dist.main.extras) $(dist-dir-main) @$(stripccomments) -k -k < $(sqlite3.js) \ > $(dist-dir-main)/$(notdir $(sqlite3.js)) @cp -p $(demo-files) $(dist-dir-main) - @cp -p $(sqlite3-wasmfs.wasm) sqlite3-wasmfs.worker.js $(dist-dir-wasmfs) - @$(stripccomments) -k -k < $(sqlite3-wasmfs.js) \ - > $(dist-dir-wasmfs)/$(notdir $(sqlite3-wasmfs.js)) - @for i in $(demo-123.js) $(demo-123.html); do \ - sed -e 's/\bsqlite3\.js\b/sqlite3-wasmfs.js/' $$i \ - > $(dist-dir-wasmfs)/$${i##*/} || exit; \ - done @vnum=$$($(version-info) --version-number); \ vdir=sqlite-wasm-$$vnum; \ arc=$$vdir.zip; \ diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index 6f90024811..84cc6b298a 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -23,6 +23,7 @@ $(dir.top)/shell.c: $(SHELL_SRC) $(dir.top)/tool/mkshellc.tcl # /shell.c ######################################################################## +EXPORTED_FUNCTIONS.fiddle := $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle fiddle.emcc-flags = \ $(emcc.cflags) $(emcc_opt_full) \ --minify 0 \ @@ -35,17 +36,17 @@ fiddle.emcc-flags = \ -sWASM_BIGINT=$(emcc_enable_bigint) \ -sEXPORT_NAME=$(sqlite3.js.init-func) \ $(sqlite3.js.flags.--post-js) \ - -sEXPORTED_RUNTIME_METHODS=@$(dir.wasm)/EXPORTED_RUNTIME_METHODS.fiddle \ - -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.fiddle \ + $(emcc.exportedRuntimeMethods) \ + -sEXPORTED_FUNCTIONS=@$(abspath $(EXPORTED_FUNCTIONS.fiddle)) \ $(SQLITE_OPT) $(SHELL_OPT) \ -DSQLITE_SHELL_FIDDLE # -D_POSIX_C_SOURCE is needed for strdup() with emcc fiddle.EXPORTED_FUNCTIONS.in := \ EXPORTED_FUNCTIONS.fiddle.in \ - EXPORTED_FUNCTIONS.api + $(EXPORTED_FUNCTIONS.api) -EXPORTED_FUNCTIONS.fiddle: $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle) +$(EXPORTED_FUNCTIONS.fiddle): $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle) sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@ fiddle-module.js := $(dir.fiddle)/fiddle-module.js @@ -58,7 +59,7 @@ $(dir.fiddle)/$(SOAP.js): $(SOAP.js) $(eval $(call call-make-pre-js,fiddle-module)) $(fiddle-module.js): $(MAKEFILE) $(MAKEFILE.fiddle) \ - EXPORTED_FUNCTIONS.fiddle EXPORTED_RUNTIME_METHODS.fiddle \ + $(EXPORTED_FUNCTIONS.fiddle) \ $(fiddle.cses) $(pre-post-fiddle-module.deps) $(dir.fiddle)/$(SOAP.js) $(emcc.bin) -o $@ $(fiddle.emcc-flags) \ $(pre-post-common.flags) $(pre-post-fiddle-module.flags) \ diff --git a/ext/wasm/index.html b/ext/wasm/index.html index 663d4c9240..9fc475f1ed 100644 --- a/ext/wasm/index.html +++ b/ext/wasm/index.html @@ -34,8 +34,7 @@
  • Whether or not WASMFS/OPFS support is enabled on any given page may depend on build-time options which are off by - default because they currently (as of 2022-09-08) break - with Worker-based pages. + default.
  • @@ -68,7 +67,8 @@
  • speedtest1 ports (sqlite3's primary benchmarking tool)...
    • speedtest1: a main-thread WASM build of speedtest1.
    • -
    • speedtest1-wasmfs: a variant of speedtest1 built solely for the wasmfs/opfs feature.
    • +
    • speedtest1-kvvfs: speedtest1 with the kvvfs.
    • speedtest1-worker: an interactive Worker-thread variant of speedtest1.
    • speedtest1-worker-opfs: speedtest1-worker with the @@ -81,10 +81,10 @@
    • testing-worker1-promiser: tests for the Promise-based wrapper of the Worker-based API.
    • batch-runner: runs batches of SQL exported from speedtest1.
    • -
    • scratchpad-wasmfs-main: +
    • test-opfs-vfs (same with verbose output and sanity-checking tests) is an diff --git a/ext/wasm/sqlite3-worker1.js b/ext/wasm/sqlite3-worker1.js index 167c6a5c79..fef155e1f8 100644 --- a/ext/wasm/sqlite3-worker1.js +++ b/ext/wasm/sqlite3-worker1.js @@ -25,13 +25,29 @@ Worker-specific API needs to pass _this_ file (or equivalent) to the Worker constructor and then listen for an event in the form shown above in order to know when the module has completed initialization. + + This file accepts a couple of URL arguments to adjust how it loads + sqlite3.js: + + - `sqlite3.dir`, if set, treats the given directory name as the + directory from which `sqlite3.js` will be loaded. + - `sqlite3.js`, if set, is used as the URI to `sqlite3.js` and it + may contain path elements, e.g. `sqlite3.js=foo/bar/my-sqlite3.js`. + + By default is loads 'sqlite3.js'. */ "use strict"; (()=>{ const urlParams = new URL(self.location.href).searchParams; - importScripts(urlParams.has('wasmfs') - ? 'sqlite3-wasmfs.js' - : 'sqlite3.js'); + let theJs; + if(urlParams.has('sqlite3.js')){ + theJs = urlParams.get('sqlite3.js'); + }else if(urlParams.has('sqlite3.dir')){ + theJs = urlParams.get('sqlite3.dir')+'/sqlite3.js'; + }else{ + theJs = 'sqlite3.js'; + } + importScripts(theJs); sqlite3InitModule().then((sqlite3)=>{ sqlite3.capi.sqlite3_wasmfs_opfs_dir(); sqlite3.initWorker1API(); diff --git a/ext/wasm/testing1.html b/ext/wasm/testing1.html deleted file mode 100644 index bf73974ee7..0000000000 --- a/ext/wasm/testing1.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - sqlite3-api.js tests - - -
      sqlite3-api.js tests
      - -
      -
      -
      Initializing app...
      -
      - On a slow internet connection this may take a moment. If this - message displays for "a long time", intialization may have - failed and the JavaScript console may contain clues as to why. -
      -
      -
      Downloading...
      -
      - -
      -
      Most stuff on this page happens in the dev console.
      -
      -
      - - - - - - - diff --git a/ext/wasm/wasmfs.make b/ext/wasm/wasmfs.make index ee7b9f12bc..f27c9d631d 100644 --- a/ext/wasm/wasmfs.make +++ b/ext/wasm/wasmfs.make @@ -7,23 +7,24 @@ ######################################################################## MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST)) -sqlite3-wasmfs.js := sqlite3-wasmfs.js -sqlite3-wasmfs.wasm := sqlite3-wasmfs.wasm +# Maintenance reminder: these particular files cannot be built into a +# subdirectory because loading of the auxiliary +# sqlite3-wasmfs.worker.js file it creates fails if sqlite3-wasmfs.js +# is loaded from any directory other than the one in which the +# containing HTML lives. +dir.wasmfs := $(dir.wasm) +sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js +sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \ $(subst .js,.worker.js,$(sqlite3-wasmfs.js)) -######################################################################## -# emcc flags for .c/.o/.wasm. -sqlite3-wasmfs.flags = -#sqlite3-wasmfs.flags += -v # _very_ loud but also informative about what it's doing - ######################################################################## # emcc flags for .c/.o. sqlite3-wasmfs.cflags := sqlite3-wasmfs.cflags += -std=c99 -fPIC sqlite3-wasmfs.cflags += -pthread -sqlite3-wasmfs.cflags += -I. -I.. -I$(dir.top) +sqlite3-wasmfs.cflags += $(cflags.common) sqlite3-wasmfs.cflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS ######################################################################## @@ -35,7 +36,7 @@ sqlite3-wasmfs.jsflags += -sMODULARIZE sqlite3-wasmfs.jsflags += -sSTRICT_JS sqlite3-wasmfs.jsflags += -sDYNAMIC_EXECUTION=0 sqlite3-wasmfs.jsflags += -sNO_POLYFILL -sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api +sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api) sqlite3-wasmfs.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack # wasmMemory ==> for -sIMPORTED_MEMORY # allocateUTF8OnStack ==> wasmfs internals @@ -67,7 +68,7 @@ sqlite3-wasmfs.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint) $(eval $(call call-make-pre-js,sqlite3-wasmfs)) sqlite3-wasmfs.jsflags += $(pre-post-common.flags) $(pre-post-sqlite3-wasmfs.flags) $(sqlite3-wasmfs.js): $(sqlite3-wasm.c) \ - EXPORTED_FUNCTIONS.api $(MAKEFILE) $(MAKEFILE.wasmfs) \ + $(EXPORTED_FUNCTIONS.api) $(MAKEFILE) $(MAKEFILE.wasmfs) \ $(pre-post-sqlite3-wasmfs.deps) @echo "Building $@ ..." $(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \ @@ -84,22 +85,22 @@ all: wasmfs # speedtest1 for wasmfs. Re. sqlite3-wasm.o vs sqlite3-wasm.c: # building against the latter (predictably) results in a slightly # faster binary. -speedtest1-wasmfs.js := speedtest1-wasmfs.js +speedtest1-wasmfs.js := $(dir.wasmfs)/speedtest1-wasmfs.js speedtest1-wasmfs.wasm := $(subst .js,.wasm,$(speedtest1-wasmfs.js)) speedtest1-wasmfs.eflags := $(sqlite3-wasmfs.fsflags) speedtest1-wasmfs.eflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS $(eval $(call call-make-pre-js,speedtest1-wasmfs)) -$(speedtest1-wasmfs.js): $(speedtest1.cs) $(sqlite3-wasmfs.js) \ +$(speedtest1-wasmfs.js): $(speedtest1.cses) $(sqlite3-wasmfs.js) \ $(MAKEFILE) $(MAKEFILE.wasmfs) \ $(pre-post-speedtest1-wasmfs.deps) \ - EXPORTED_FUNCTIONS.speedtest1 + $(EXPORTED_FUNCTIONS.speedtest1) @echo "Building $@ ..." $(emcc.bin) \ $(speedtest1-wasmfs.eflags) $(speedtest1-common.eflags) \ $(pre-post-speedtest1-wasmfs.flags) \ $(speedtest1.cflags) \ $(sqlite3-wasmfs.cflags) \ - -o $@ $(speedtest1.cs) -lm + -o $@ $(speedtest1.cses) -lm $(maybe-wasm-strip) $(speedtest1-wasmfs.wasm) ls -la $@ $(speedtest1-wasmfs.wasm) diff --git a/manifest b/manifest index 40f33190d9..f50dd6aef7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\swork\son\sthe\sJS\send-user\sdeliverables.\sAdd\stool/stripccomments.c\sto\ssupport\sthat. -D 2022-10-18T20:36:50.562 +C Considerable\swasm/js\sbuild\scleanups\sand\sreworking.\sRemove\swasmfs\sbuilds\sfrom\sthe\send-user\sdeliverables\sand\sdisable\sthe\swasmfs\sbuild\sby\sdefault,\sper\s/chat\sdiscussion,\sas\sit\sdoubles\sour\sdeliverable\scount\sfor\sonly\smarginal\sgain.\sAttempt\sto\smove\sthe\ssqlite3.js/wasm\sfiles\sinto\ssubdirectories\sbut\srediscovered\sthat\sthat\sbreaks\sloading\sin\sWorker\smode\sbecause\sURI\sresolution\sof\sthe\swasm\sfiles\sdiffers\sdepending\son\swhether\sthe\smain\sscript\sis\sloaded\sfrom\sa\sscript\stag\sor\sa\sWorker. +D 2022-10-19T01:07:30.150 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -472,14 +472,13 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0 -F ext/wasm/GNUmakefile 279fd4589ba602e24d8e66ca795ec5a2275a0e329405e4e984e8ea0579339bae -F ext/wasm/README-dist.txt 170be2d47b4b52504ef09088ca2f143aab657de0f9ac04d3a68e366f40929c3d +F ext/wasm/GNUmakefile d5a39121aeb316562895889c6b27f9ec11e9cae2f844b23d5c7d04479a3bec2a +F ext/wasm/README-dist.txt 13438bafe5fab1eca223be91459e757e6e67248fc959b9ae0ffb5808fd0a1610 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 F ext/wasm/api/README.md 946398dd80bfd673f098b9d6ca3564e1fc77b03e660274d132f267c407b8703c -F ext/wasm/api/extern-post-js.js dfae3a5f621ae94f1fae671f8013ed6464355f11e2adda38ed8b10bf1929f337 +F ext/wasm/api/extern-post-js.js b3d14b7d5880e70caec2feae2ab2f31ccb3af67d200e4a9fd58dcc0c4b401bf1 F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1ecc5ba9e64ef90a8b @@ -488,11 +487,11 @@ F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383b F ext/wasm/api/sqlite3-api-glue.js 05eb701460bb72edbe3bf923bd51262551614612c37802fc597eabb4c6b83232 F ext/wasm/api/sqlite3-api-oo1.js 9a5f0c00d476c504f16dcd456e1743dbc2826ca3d10645dfa62663a39e3ed0d8 F ext/wasm/api/sqlite3-api-opfs.js 5a8ab3b76880c8ada8710ca9ba1ca5b160872edfd8bd5322e4f179a7f41cc616 -F ext/wasm/api/sqlite3-api-prologue.js a17b35814c6399a2e69c7836e5fd2eaa71f755ee51f96cb69d68cbf99985d45b +F ext/wasm/api/sqlite3-api-prologue.js f6ae0da8de61f8d550b0bb8e486e5edd38129005c2bb2a448f6bf30dbf8b723b F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8 F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 -F ext/wasm/api/sqlite3-wasm.c 4c131945ced4b08a694d287abcdb066b896d961ef79ee5241805ecc37e83d63a +F ext/wasm/api/sqlite3-wasm.c 84d410a2b9defdac85e6a421736307ff3a3eed3c1b0ae3b7b140edbc6ad81a8f F ext/wasm/batch-runner.html cf1a410c92bad50fcec2ddc71390b4e9df63a6ea1bef12a5163a66a0af4d78d9 F ext/wasm/batch-runner.js 5bae81684728b6be157d1f92b39824153f0fd019345b39f2ab8930f7ee2a57d8 F ext/wasm/common/SqliteTestUtil.js 647bf014bd30bdd870a7e9001e251d12fc1c9ec9ce176a1004b838a4b33c5c05 @@ -504,13 +503,13 @@ F ext/wasm/demo-123.html 7c239c9951d1b113f9f532969ac039294cf1dcfee2b3ae0a2c1ed2b F ext/wasm/demo-123.js e0cbeb3495e14103763d5c49794a24d67cf3d78e0ed5b82843be70c0c2ee4b3b F ext/wasm/demo-kvvfs1.html 7d4f28873de67f51ac18c584b7d920825139866a96049a49c424d6f5a0ea5e7f F ext/wasm/demo-kvvfs1.js 105596bd2ccd0b1deb5fde8e99b536e8242d4bb5932fac0c8403ff3a6bc547e8 -F ext/wasm/dist.make 1d59fafdfcf6fc5ee0f3351b21199585dba21afcf0518241789fd5d37a1c011d -F ext/wasm/fiddle.make b609dfde299b4523d7123b7e0cecaa1a0aff0dd984e62cea653aae91f5063c90 +F ext/wasm/dist.make 2015746f6cd37ed17fadb14dba45d41ac6db727917d04f9b9aa431a816c5e54d +F ext/wasm/fiddle.make a87250f6f973d9632818b9d2396c59e6542da180f8f10b164665a6fc04d239bc F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 531859a471924a0ea48afa218e6877f0c164ca324d51e15843ed6ecc1c65c7ee F ext/wasm/fiddle/fiddle.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715 -F ext/wasm/index.html d75b516236c6869568ff691b9b7ff61307d6436e059b5657dadc473b6f41e581 +F ext/wasm/index.html 47fd8be5f76b7e1123edb301b604bc751ba387498a597d8dc48bce24d1007c57 F ext/wasm/jaccwabyt/jaccwabyt.js 0d7f32817456a0f3937fcfd934afeb32154ca33580ab264dab6c285e6dbbd215 F ext/wasm/jaccwabyt/jaccwabyt.md 9aa6951b529a8b29f578ec8f0355713c39584c92cf1708f63ba0cf917cb5b68e F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e1029186d836d14b83845fbe06 @@ -524,7 +523,7 @@ F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d826 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5 F ext/wasm/sqlite3-opfs-async-proxy.js 206ce6bbc3c30ad51a37d9c25e3a2712e70b586e0f9a2cf8cb0b9619017c2671 F ext/wasm/sqlite3-worker1-promiser.js 307d7837420ca6a9d3780dfc81194f1c0715637e6d9540e935514086b96913d8 -F ext/wasm/sqlite3-worker1.js 466e9bd39409ab03f3e00999887aaffc11e95b416e2689596e3d7f1516673fdf +F ext/wasm/sqlite3-worker1.js 25b29ff23958883e0a772bc835f4f4eb7e1714d7310385ed27106525930c2530 F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5 F ext/wasm/test-opfs-vfs.js 56c3d725044c668fa7910451e96c1195d25ad95825f9ac79f747a7759d1973d0 F ext/wasm/tester1-worker.html 0af7a22025ff1da72a84765d64f8f221844a57c6e6e314acf3a30f176101fd3f @@ -532,11 +531,10 @@ F ext/wasm/tester1.html fde0e0bdeaaa2c39877c749dc86a8c1c306f771c3d75b89a6289a5ed F ext/wasm/tester1.js 8161dcc4b21902dadec2d3a5dc5700cab9c1641db0603e2ea56ea2a8de6cbab3 F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893 F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9dd8ae2cc8719b506b6e013e -F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3 F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494 F ext/wasm/version-info.c 5fa356d38859d71a0369b5c37e1935def7413fcc8a4e349a39d9052c1d0479f4 -F ext/wasm/wasmfs.make 9a51480d0a5ef33dd1c06c305379775302b735cb27737c2490ea449575ca5e25 +F ext/wasm/wasmfs.make ee0004813e16c283ff633e08b482008d56adf9b7d42f6c5612f7ab002b924f69 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 @@ -2037,8 +2035,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 740a2eb0928d54fdf735a8e573c6a61a34dbd295b46e5b6ef39e957fd2623293 -R f3423b9e5fdd1b3c8749326c161b8bbf +P 2156f0744acfe425457430a0f6a7e02de907de85edba81a6d4eef40293e561c8 +R ee0ece99cec342c109cdb62c53280a5b U stephan -Z 8ed4b03e8c6243f1d25f4dc2d31715c7 +Z 86621ae22c81858679965e272da6ace1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 965ccd2dac..38a86ebeb0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2156f0744acfe425457430a0f6a7e02de907de85edba81a6d4eef40293e561c8 \ No newline at end of file +5b23e0675efdd2f1ea7b4f5836a579e8d6aa8a25b3f1a6a950520ad845ff01bb \ No newline at end of file From cd0df83c156d12c89bcbe41420af51d83444855d Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 19 Oct 2022 04:44:58 +0000 Subject: [PATCH 28/65] Apply considerable acrobatics to get the JS/WASM deliverables building to and loadable from a directory other than the one which contains the app-level code. Requires an only-slightly-leaky abstraction of passing a URL argument when loading sqlite3.js but provides much greater flexibility in where the JS/WASM files are located. FossilOrigin-Name: 6d468dab9eb84d4548f68014959f02fe4f66455472ff24fe729382bb2972e3d1 --- ext/wasm/GNUmakefile | 17 +++++- ext/wasm/api/extern-post-js.js | 45 +++++++++++--- ext/wasm/api/pre-js.js | 44 +++++++++++++- ext/wasm/api/sqlite3-api-opfs.js | 14 ++++- ext/wasm/api/sqlite3-api-prologue.js | 16 ++++- .../{ => api}/sqlite3-opfs-async-proxy.js | 0 .../{ => api}/sqlite3-worker1-promiser.js | 19 +++++- ext/wasm/{ => api}/sqlite3-worker1.js | 10 ++-- ext/wasm/batch-runner.html | 2 +- ext/wasm/demo-123-worker.html | 6 +- ext/wasm/demo-123.html | 2 +- ext/wasm/demo-123.js | 21 ++++++- ext/wasm/demo-kvvfs1.html | 2 +- ext/wasm/fiddle.make | 6 +- ext/wasm/speedtest1-worker.html | 2 +- ext/wasm/speedtest1-worker.js | 7 ++- ext/wasm/speedtest1.html | 2 +- ext/wasm/test-opfs-vfs.html | 12 ++-- ext/wasm/test-opfs-vfs.js | 2 +- ext/wasm/tester1-worker.html | 2 +- ext/wasm/tester1.html | 2 +- ext/wasm/tester1.js | 25 +++++++- ext/wasm/testing-worker1-promiser.html | 2 +- ext/wasm/testing-worker1-promiser.js | 2 +- ext/wasm/testing2.js | 2 +- manifest | 60 +++++++++---------- manifest.uuid | 2 +- 27 files changed, 250 insertions(+), 76 deletions(-) rename ext/wasm/{ => api}/sqlite3-opfs-async-proxy.js (100%) rename ext/wasm/{ => api}/sqlite3-worker1-promiser.js (93%) rename ext/wasm/{ => api}/sqlite3-worker1.js (94%) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index f461f8b46a..f364e446bc 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -90,7 +90,7 @@ dir.tool := $(dir.top)/tool # the loading-from-worker case... # # dir.dout = output dir for deliverables. -dir.dout := $(dir.wasm) +dir.dout := $(dir.wasm)/jswasm # dir.tmp = output dir for intermediary build files, as opposed to # end-user deliverables. dir.tmp := $(dir.wasm)/bld @@ -218,6 +218,20 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js sqlite3-api.jses += $(dir.api)/sqlite3-api-opfs.js sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js +# "External" API files which are part of our distribution +# but not part of the sqlite3-api.js amalgamation. +SOAP.js := $(dir.api)/sqlite3-opfs-async-proxy.js +sqlite3-worker1.js := $(dir.api)/sqlite3-worker1.js +sqlite3-worker1-promiser.js := $(dir.api)/sqlite3-worker1-promiser.js +define CP_XAPI +sqlite3-api.ext.jses += $$(dir.dout)/$$(notdir $(1)) +$$(dir.dout)/$$(notdir $(1)): $(1) $$(MAKEFILE) + cp $$< $$@ +endef +$(foreach X,$(SOAP.js) $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js),\ + $(eval $(call CP_XAPI,$(X)))) +all: $(sqlite3-api.ext.jses) + sqlite3-api.js := $(dir.tmp)/sqlite3-api.js $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) @echo "Making $@..." @@ -384,6 +398,7 @@ sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c # difference. Thus we build all binaries against sqlite3-wasm.c # instead of building a shared copy of sqlite3-wasm.o. $(eval $(call call-make-pre-js,sqlite3)) +$(sqlite3.js): $(sqlite3.js): $(MAKEFILE) $(sqlite3.wasm.obj) \ $(EXPORTED_FUNCTIONS.api) \ $(pre-post-sqlite3.deps) diff --git a/ext/wasm/api/extern-post-js.js b/ext/wasm/api/extern-post-js.js index 7dba03b3a7..5f5f72d4b3 100644 --- a/ext/wasm/api/extern-post-js.js +++ b/ext/wasm/api/extern-post-js.js @@ -16,6 +16,27 @@ if(!originalInit){ throw new Error("Expecting self.sqlite3InitModule to be defined by the Emscripten build."); } + /** + We need to add some state which our custom Module.locateFile() + can see, but an Emscripten limitation currently prevents us from + attaching it to the sqlite3InitModule function object: + + https://github.com/emscripten-core/emscripten/issues/18071 + + The only current workaround is to temporarily stash this state + into the global scope and delete it when sqlite3InitModule() + is called. + */ + const initModuleState = self.sqlite3InitModuleState = Object.assign(Object.create(null),{ + moduleScript: self?.document?.currentScript, + isWorker: (!self.document && self.window !== self), + location: self.location, + urlParams: new URL(self.location.href).searchParams + }); + if(initModuleState.urlParams.has('sqlite3.dir')){ + initModuleState.sqlite3Dir = initModuleState.urlParams.get('sqlite3.dir') +'/'; + }; + self.sqlite3InitModule = (...args)=>{ //console.warn("Using replaced sqlite3InitModule()",self.location); return originalInit(...args).then((EmscriptenModule)=>{ @@ -32,6 +53,8 @@ Emscripten details. */ return EmscriptenModule; } + EmscriptenModule.sqlite3.scriptInfo = initModuleState; + //console.warn("sqlite3.scriptInfo =",EmscriptenModule.sqlite3.scriptInfo); const f = EmscriptenModule.sqlite3.asyncPostInit; delete EmscriptenModule.sqlite3.asyncPostInit; return f(); @@ -41,13 +64,19 @@ }); }; self.sqlite3InitModule.ready = originalInit.ready; - //console.warn("Replaced sqlite3InitModule()"); -})(); -if(0){ - console.warn("self.location.href =",self.location.href); - if('undefined' !== typeof document){ - console.warn("document.currentScript.src =", - document?.currentScript?.src); + if(self.sqlite3InitModuleState.moduleScript){ + const sim = self.sqlite3InitModuleState; + let src = sim.moduleScript.src.split('/'); + src.pop(); + sim.scriptDir = src.join('/') + '/'; } -} + if(0){ + console.warn("Replaced sqlite3InitModule()"); + console.warn("self.location.href =",self.location.href); + if('undefined' !== typeof document){ + console.warn("document.currentScript.src =", + document?.currentScript?.src); + } + } +})(); diff --git a/ext/wasm/api/pre-js.js b/ext/wasm/api/pre-js.js index b6630416dd..c07d0373cd 100644 --- a/ext/wasm/api/pre-js.js +++ b/ext/wasm/api/pre-js.js @@ -4,9 +4,49 @@ This file is intended to be prepended to the sqlite3.js build using Emscripten's --pre-js=THIS_FILE flag (or equivalent). */ + +// See notes in extern-post-js.js +const sqlite3InitModuleState = self.sqlite3InitModuleState || Object.create(null); +delete self.sqlite3InitModuleState; + +/** + This custom locateFile() tries to figure out where to load `path` + from. The intent is to provide a way for foo/bar/X.js loaded from a + Worker constructor or importScripts() to be able to resolve + foo/bar/X.wasm (in the latter case, with some help): + + 1) If URL param named the same as `path` is set, it is returned. + + 2) If sqlite3InitModuleState.sqlite3Dir is set, then (thatName + path) + is returned (note that it's assumed to end with '/'). + + 3) If this code is running in the main UI thread AND it was loaded + from a SCRIPT tag, the directory part of that URL is used + as the prefix. (This form of resolution unfortunately does not + function for scripts loaded via importScripts().) + + 4) If none of the above apply, (prefix+path) is returned. +*/ Module['locateFile'] = function(path, prefix) { - return prefix + path; -}; + let theFile; + const up = this.urlParams; + if(0){ + console.warn("locateFile(",arguments[0], ',', arguments[1],")", + 'self.location =',self.location, + 'sqlite3InitModuleState.scriptDir =',this.scriptDir, + 'up.entries() =',Array.from(up.entries())); + } + if(up.has(path)){ + theFile = up.get(path); + }else if(this.sqlite3Dir){ + theFile = this.sqlite3Dir + path; + }else if(this.scriptDir){ + theFile = this.scriptDir + path; + }else{ + theFile = prefix + path; + } + return theFile; +}.bind(sqlite3InitModuleState); /** Bug warning: this xInstantiateWasm bit must remain disabled diff --git a/ext/wasm/api/sqlite3-api-opfs.js b/ext/wasm/api/sqlite3-api-opfs.js index 98defe4fbc..9f53024548 100644 --- a/ext/wasm/api/sqlite3-api-opfs.js +++ b/ext/wasm/api/sqlite3-api-opfs.js @@ -98,6 +98,9 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){ options.proxyUri = callee.defaultProxyUri; } + if('function' === typeof options.proxyUri){ + options.proxyUri = options.proxyUri(); + } const thePromise = new Promise(function(promiseResolve, promiseReject_){ const loggers = { 0:console.error.bind(console), @@ -1092,9 +1095,18 @@ installOpfsVfs.defaultProxyUri = "sqlite3-opfs-async-proxy.js"; //console.warn("sqlite3.installOpfsVfs.defaultProxyUri =",sqlite3.installOpfsVfs.defaultProxyUri); self.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{ + if(sqlite3.scriptInfo && !sqlite3.scriptInfo.isWorker){ + return; + } try{ + let proxyJs = installOpfsVfs.defaultProxyUri; + if(sqlite3.scriptInfo.sqlite3Dir){ + installOpfsVfs.defaultProxyUri = + sqlite3.scriptInfo.sqlite3Dir + proxyJs; + //console.warn("installOpfsVfs.defaultProxyUri =",installOpfsVfs.defaultProxyUri); + } return installOpfsVfs().catch((e)=>{ - console.warn("Ignoring inability to install OPFS sqlite3_vfs:",e); + console.warn("Ignoring inability to install OPFS sqlite3_vfs:",e.message); }); }catch(e){ console.error("installOpfsVfs() exception:",e); diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index f8c0f024e6..3980e0ad42 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -1334,7 +1334,20 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( //while(lip.length) p = p.then(lip.shift()); //return p.then(()=>sqlite3); return Promise.all(lip).then(()=>sqlite3); - } + }, + /** + scriptInfo ideally gets injected into this object by the + infrastructure which assembles the JS/WASM module. It contains + state which must be collected before sqlite3ApiBootstrap() can + be declared. It is not necessarily available to any + sqlite3ApiBootstrap.initializers but "should" be in place (if + it's added at all) by the time that + sqlite3ApiBootstrap.initializersAsync is processed. + + This state is not part of the public API, only intended for use + with the sqlite3 API bootstrapping and wasm-loading process. + */ + scriptInfo: undefined }; try{ sqlite3ApiBootstrap.initializers.forEach((f)=>{ @@ -1410,3 +1423,4 @@ self.sqlite3ApiBootstrap.defaultConfig = Object.create(null); value which will be stored here. */ self.sqlite3ApiBootstrap.sqlite3 = undefined; + diff --git a/ext/wasm/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js similarity index 100% rename from ext/wasm/sqlite3-opfs-async-proxy.js rename to ext/wasm/api/sqlite3-opfs-async-proxy.js diff --git a/ext/wasm/sqlite3-worker1-promiser.js b/ext/wasm/api/sqlite3-worker1-promiser.js similarity index 93% rename from ext/wasm/sqlite3-worker1-promiser.js rename to ext/wasm/api/sqlite3-worker1-promiser.js index 71e2e33135..a77b0126df 100644 --- a/ext/wasm/sqlite3-worker1-promiser.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.js @@ -237,6 +237,23 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){ }; }/*sqlite3Worker1Promiser()*/; self.sqlite3Worker1Promiser.defaultConfig = { - worker: ()=>new Worker("sqlite3-worker1.js"+self.location.search), + worker: function(){ + let theJs = "sqlite3-worker1.js"; + if(this.currentScript){ + const src = this.currentScript.src.split('/'); + src.pop(); + theJs = src.join('/')+'/' + theJs; + //console.warn("promiser currentScript, theJs =",this.currentScript,theJs); + }else{ + //console.warn("promiser self.location =",self.location); + const urlParams = new URL(self.location.href).searchParams; + if(urlParams.has('sqlite3.dir')){ + theJs = urlParams.get('sqlite3.dir') + '/' + theJs; + } + } + return new Worker(theJs + self.location.search); + }.bind({ + currentScript: self?.document?.currentScript + }), onerror: (...args)=>console.error('worker1 promiser error',...args) }; diff --git a/ext/wasm/sqlite3-worker1.js b/ext/wasm/api/sqlite3-worker1.js similarity index 94% rename from ext/wasm/sqlite3-worker1.js rename to ext/wasm/api/sqlite3-worker1.js index fef155e1f8..bc860300bb 100644 --- a/ext/wasm/sqlite3-worker1.js +++ b/ext/wasm/api/sqlite3-worker1.js @@ -29,23 +29,21 @@ This file accepts a couple of URL arguments to adjust how it loads sqlite3.js: - - `sqlite3.dir`, if set, treats the given directory name as the - directory from which `sqlite3.js` will be loaded. - `sqlite3.js`, if set, is used as the URI to `sqlite3.js` and it may contain path elements, e.g. `sqlite3.js=foo/bar/my-sqlite3.js`. + - `sqlite3.dir`, if set, treats the given directory name as the + directory from which `sqlite3.js` will be loaded. By default is loads 'sqlite3.js'. */ "use strict"; (()=>{ const urlParams = new URL(self.location.href).searchParams; - let theJs; + let theJs = 'sqlite3.js'; if(urlParams.has('sqlite3.js')){ theJs = urlParams.get('sqlite3.js'); }else if(urlParams.has('sqlite3.dir')){ - theJs = urlParams.get('sqlite3.dir')+'/sqlite3.js'; - }else{ - theJs = 'sqlite3.js'; + theJs = urlParams.get('sqlite3.dir') + '/' + theJs; } importScripts(theJs); sqlite3InitModule().then((sqlite3)=>{ diff --git a/ext/wasm/batch-runner.html b/ext/wasm/batch-runner.html index e7a2b1e082..5258f9597e 100644 --- a/ext/wasm/batch-runner.html +++ b/ext/wasm/batch-runner.html @@ -69,7 +69,7 @@
      - + - + diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index 84cc6b298a..f669efd92c 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -53,14 +53,14 @@ fiddle-module.js := $(dir.fiddle)/fiddle-module.js fiddle-module.wasm := $(subst .js,.wasm,$(fiddle-module.js)) fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c) -SOAP.js := sqlite3-opfs-async-proxy.js -$(dir.fiddle)/$(SOAP.js): $(SOAP.js) +fiddle.SOAP.js := $(dir.fiddle)/$(notdir $(SOAP.js)) +$(fiddle.SOAP.js): $(SOAP.js) cp $< $@ $(eval $(call call-make-pre-js,fiddle-module)) $(fiddle-module.js): $(MAKEFILE) $(MAKEFILE.fiddle) \ $(EXPORTED_FUNCTIONS.fiddle) \ - $(fiddle.cses) $(pre-post-fiddle-module.deps) $(dir.fiddle)/$(SOAP.js) + $(fiddle.cses) $(pre-post-fiddle-module.deps) $(fiddle.SOAP.js) $(emcc.bin) -o $@ $(fiddle.emcc-flags) \ $(pre-post-common.flags) $(pre-post-fiddle-module.flags) \ $(fiddle.cses) diff --git a/ext/wasm/speedtest1-worker.html b/ext/wasm/speedtest1-worker.html index 2e9ea2c343..56b6913352 100644 --- a/ext/wasm/speedtest1-worker.html +++ b/ext/wasm/speedtest1-worker.html @@ -169,7 +169,7 @@ return str+a.join(' '); }; - const W = new Worker("speedtest1-worker.js"+self.location.search); + const W = new Worker("speedtest1-worker.js?sqlite3.dir=jswasm"); const mPost = function(msgType,payload){ W.postMessage({type: msgType, data: payload}); }; diff --git a/ext/wasm/speedtest1-worker.js b/ext/wasm/speedtest1-worker.js index 1f421b0b86..81a40e2b78 100644 --- a/ext/wasm/speedtest1-worker.js +++ b/ext/wasm/speedtest1-worker.js @@ -1,6 +1,11 @@ 'use strict'; (function(){ - importScripts('common/whwasmutil.js','speedtest1.js'); + let speedtestJs = 'speedtest1.js'; + const urlParams = new URL(self.location.href).searchParams; + if(urlParams.has('sqlite3.dir')){ + speedtestJs = urlParams.get('sqlite3.dir') + '/' + speedtestJs; + } + importScripts('common/whwasmutil.js', speedtestJs); /** If this environment contains OPFS, this function initializes it and returns the name of the dir on which OPFS is mounted, else it returns diff --git a/ext/wasm/speedtest1.html b/ext/wasm/speedtest1.html index 358d8ba79e..a53b24c6df 100644 --- a/ext/wasm/speedtest1.html +++ b/ext/wasm/speedtest1.html @@ -37,7 +37,7 @@ speedtest is running. Output will appear below when ready...
      - + + diff --git a/ext/wasm/test-opfs-vfs.js b/ext/wasm/test-opfs-vfs.js index 583871b7d1..e22acc0e3d 100644 --- a/ext/wasm/test-opfs-vfs.js +++ b/ext/wasm/test-opfs-vfs.js @@ -76,7 +76,7 @@ const tryOpfsVfs = async function(sqlite3){ log("Done!"); }/*tryOpfsVfs()*/; -importScripts('sqlite3.js'); +importScripts('jswasm/sqlite3.js'); self.sqlite3InitModule() .then((sqlite3)=>tryOpfsVfs(sqlite3)) .catch((e)=>{ diff --git a/ext/wasm/tester1-worker.html b/ext/wasm/tester1-worker.html index bb5de0762f..e127cffdca 100644 --- a/ext/wasm/tester1-worker.html +++ b/ext/wasm/tester1-worker.html @@ -24,7 +24,7 @@ ln.append(document.createTextNode(args.join(' '))); logTarget.append(ln); }; - const w = new Worker("tester1.js"); + const w = new Worker("tester1.js?sqlite3.dir=jswasm"); w.onmessage = function({data}){ switch(data.type){ case 'log': diff --git a/ext/wasm/tester1.html b/ext/wasm/tester1.html index 9cf0bee0a3..c163151278 100644 --- a/ext/wasm/tester1.html +++ b/ext/wasm/tester1.html @@ -16,7 +16,7 @@

      sqlite3 WASM/JS tester #1 (UI thread)

      - + diff --git a/ext/wasm/tester1.js b/ext/wasm/tester1.js index aef9d2301b..c8808c9137 100644 --- a/ext/wasm/tester1.js +++ b/ext/wasm/tester1.js @@ -65,7 +65,7 @@ }; const normalizeArgs = (args)=>args.map(mapToString); if( isUIThread() ){ - console.log("Running in UI thread."); + console.log("Running in the UI thread."); const logTarget = document.querySelector('#test-output'); logClass = function(cssClass,...args){ const ln = document.createElement('div'); @@ -74,7 +74,7 @@ logTarget.append(ln); }; }else{ /* Worker thread */ - console.log("Running Worker thread."); + console.log("Running in a Worker thread."); logClass = function(cssClass,...args){ postMessage({ type:'log', @@ -1428,7 +1428,26 @@ //////////////////////////////////////////////////////////////////////// log("Loading and initializing sqlite3 WASM module..."); if(!isUIThread()){ - importScripts("sqlite3.js"); + /* + If sqlite3.js is in a directory other than this script, in order + to get sqlite3.js to resolve sqlite3.wasm properly, we have to + explicitly tell it where sqlite3.js is being loaded from. We do + that by passing the `sqlite3.dir=theDirName` URL argument to + _this_ script. That URL argument will be seen by the JS/WASM + loader and it will adjust the sqlite3.wasm path accordingly. If + sqlite3.js/.wasm are in the same directory as this script then + that's not needed. + + URL arguments passed as part of the filename via importScripts() + are simply lost, and such scripts see the self.location of + _this_ script. + */ + let sqlite3Js = 'sqlite3.js'; + const urlParams = new URL(self.location.href).searchParams; + if(urlParams.has('sqlite3.dir')){ + sqlite3Js = urlParams.get('sqlite3.dir') + '/' + sqlite3Js; + } + importScripts(sqlite3Js); } self.sqlite3InitModule({ print: log, diff --git a/ext/wasm/testing-worker1-promiser.html b/ext/wasm/testing-worker1-promiser.html index 9af809d9ed..4b35ca82c0 100644 --- a/ext/wasm/testing-worker1-promiser.html +++ b/ext/wasm/testing-worker1-promiser.html @@ -28,7 +28,7 @@
      - + diff --git a/ext/wasm/testing-worker1-promiser.js b/ext/wasm/testing-worker1-promiser.js index 259d20fddc..855643b2d2 100644 --- a/ext/wasm/testing-worker1-promiser.js +++ b/ext/wasm/testing-worker1-promiser.js @@ -40,7 +40,7 @@ const promiserConfig = { worker: ()=>{ - const w = new Worker("sqlite3-worker1.js"); + const w = new Worker("jswasm/sqlite3-worker1.js"); w.onerror = (event)=>error("worker.onerror",event); return w; }, diff --git a/ext/wasm/testing2.js b/ext/wasm/testing2.js index 7163fe1204..5ea48db6b6 100644 --- a/ext/wasm/testing2.js +++ b/ext/wasm/testing2.js @@ -19,7 +19,7 @@ 'use strict'; (function(){ const T = self.SqliteTestUtil; - const SW = new Worker("sqlite3-worker1.js"); + const SW = new Worker("jswasm/sqlite3-worker1.js"); const DbState = { id: undefined }; diff --git a/manifest b/manifest index f50dd6aef7..f141d54ba2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Considerable\swasm/js\sbuild\scleanups\sand\sreworking.\sRemove\swasmfs\sbuilds\sfrom\sthe\send-user\sdeliverables\sand\sdisable\sthe\swasmfs\sbuild\sby\sdefault,\sper\s/chat\sdiscussion,\sas\sit\sdoubles\sour\sdeliverable\scount\sfor\sonly\smarginal\sgain.\sAttempt\sto\smove\sthe\ssqlite3.js/wasm\sfiles\sinto\ssubdirectories\sbut\srediscovered\sthat\sthat\sbreaks\sloading\sin\sWorker\smode\sbecause\sURI\sresolution\sof\sthe\swasm\sfiles\sdiffers\sdepending\son\swhether\sthe\smain\sscript\sis\sloaded\sfrom\sa\sscript\stag\sor\sa\sWorker. -D 2022-10-19T01:07:30.150 +C Apply\sconsiderable\sacrobatics\sto\sget\sthe\sJS/WASM\sdeliverables\sbuilding\sto\sand\sloadable\sfrom\sa\sdirectory\sother\sthan\sthe\sone\swhich\scontains\sthe\sapp-level\scode.\sRequires\san\sonly-slightly-leaky\sabstraction\sof\spassing\sa\sURL\sargument\swhen\sloading\ssqlite3.js\sbut\sprovides\smuch\sgreater\sflexibility\sin\swhere\sthe\sJS/WASM\sfiles\sare\slocated. +D 2022-10-19T04:44:58.210 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -472,39 +472,42 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile d5a39121aeb316562895889c6b27f9ec11e9cae2f844b23d5c7d04479a3bec2a +F ext/wasm/GNUmakefile e9686a03f201a16786783964d0f2fcf4d9af8a9aee6e3ce5b6c3ee5d7750842f F ext/wasm/README-dist.txt 13438bafe5fab1eca223be91459e757e6e67248fc959b9ae0ffb5808fd0a1610 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 F ext/wasm/api/README.md 946398dd80bfd673f098b9d6ca3564e1fc77b03e660274d132f267c407b8703c -F ext/wasm/api/extern-post-js.js b3d14b7d5880e70caec2feae2ab2f31ccb3af67d200e4a9fd58dcc0c4b401bf1 +F ext/wasm/api/extern-post-js.js 4bba34d8301f6058abd8ee24d2778b7360c5c3679217b38f5670e97a5ba7a3ec F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1ecc5ba9e64ef90a8b -F ext/wasm/api/pre-js.js 5b550904322d73127badd4347ca967ea525b901573559736f92d326ad9b7bb76 +F ext/wasm/api/pre-js.js 151e0616614a49f3db19ed544fa13b38c87c108959fbcd4029ea8399a562d94f F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383bd7ee0de0178b1b3e988588 F ext/wasm/api/sqlite3-api-glue.js 05eb701460bb72edbe3bf923bd51262551614612c37802fc597eabb4c6b83232 F ext/wasm/api/sqlite3-api-oo1.js 9a5f0c00d476c504f16dcd456e1743dbc2826ca3d10645dfa62663a39e3ed0d8 -F ext/wasm/api/sqlite3-api-opfs.js 5a8ab3b76880c8ada8710ca9ba1ca5b160872edfd8bd5322e4f179a7f41cc616 -F ext/wasm/api/sqlite3-api-prologue.js f6ae0da8de61f8d550b0bb8e486e5edd38129005c2bb2a448f6bf30dbf8b723b +F ext/wasm/api/sqlite3-api-opfs.js 22d60ba956e873b65e2e0591e239178082bd53a6d563c3c58db7dc03e562e8f7 +F ext/wasm/api/sqlite3-api-prologue.js bdcd1f636e5ef0622f99b753aff0d26cc250bcd3a17923771e335ec73059b073 F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8 F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 +F ext/wasm/api/sqlite3-opfs-async-proxy.js 206ce6bbc3c30ad51a37d9c25e3a2712e70b586e0f9a2cf8cb0b9619017c2671 w ext/wasm/sqlite3-opfs-async-proxy.js F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 F ext/wasm/api/sqlite3-wasm.c 84d410a2b9defdac85e6a421736307ff3a3eed3c1b0ae3b7b140edbc6ad81a8f -F ext/wasm/batch-runner.html cf1a410c92bad50fcec2ddc71390b4e9df63a6ea1bef12a5163a66a0af4d78d9 +F ext/wasm/api/sqlite3-worker1-promiser.js f0aa93db62903f4006428cbcd2209a765655ec69a0e57247baba0fc94d745987 w ext/wasm/sqlite3-worker1-promiser.js +F ext/wasm/api/sqlite3-worker1.js 59fd89ee42bc380a053a848d35806177c27eb82684ef152a34c65c7ce1b5d233 w ext/wasm/sqlite3-worker1.js +F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8 F ext/wasm/batch-runner.js 5bae81684728b6be157d1f92b39824153f0fd019345b39f2ab8930f7ee2a57d8 F ext/wasm/common/SqliteTestUtil.js 647bf014bd30bdd870a7e9001e251d12fc1c9ec9ce176a1004b838a4b33c5c05 F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/common/testing.css 53394885077edd3db22d2a0896192334dfc06fb3d1da0b646eb12a332d22f18e F ext/wasm/common/whwasmutil.js 50d2ede0b0fa01c1d467e1801fab79f5e46bb02bcbd2b0232e4fdc6090a47818 -F ext/wasm/demo-123-worker.html e50b51dc7271b9d3cc830cb7c2fba294d622f56b7acb199f7257d11195a63d49 -F ext/wasm/demo-123.html 7c239c9951d1b113f9f532969ac039294cf1dcfee2b3ae0a2c1ed2b3d59f8dfa -F ext/wasm/demo-123.js e0cbeb3495e14103763d5c49794a24d67cf3d78e0ed5b82843be70c0c2ee4b3b -F ext/wasm/demo-kvvfs1.html 7d4f28873de67f51ac18c584b7d920825139866a96049a49c424d6f5a0ea5e7f +F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed +F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508 +F ext/wasm/demo-123.js ebae30756585bca655b4ab2553ec9236a87c23ad24fc8652115dcedb06d28df6 +F ext/wasm/demo-kvvfs1.html c4a69d2ded9cabad3e2eea75cd2936d9a13002ab4f10b9f1bac6130a0dee84dd F ext/wasm/demo-kvvfs1.js 105596bd2ccd0b1deb5fde8e99b536e8242d4bb5932fac0c8403ff3a6bc547e8 F ext/wasm/dist.make 2015746f6cd37ed17fadb14dba45d41ac6db727917d04f9b9aa431a816c5e54d -F ext/wasm/fiddle.make a87250f6f973d9632818b9d2396c59e6542da180f8f10b164665a6fc04d239bc +F ext/wasm/fiddle.make e5a8966be370bf8592cdffb2520ad8c3bf6a64d08ea91c8ed17dc88624967697 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js 531859a471924a0ea48afa218e6877f0c164ca324d51e15843ed6ecc1c65c7ee F ext/wasm/fiddle/fiddle.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 @@ -515,24 +518,21 @@ F ext/wasm/jaccwabyt/jaccwabyt.md 9aa6951b529a8b29f578ec8f0355713c39584c92cf1708 F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e1029186d836d14b83845fbe06 F ext/wasm/scratchpad-wasmfs-main.js 1aa32c1035cf1440a226a28fefcbb5762fbbcb020ccbe5895f8736d701695c63 F ext/wasm/speedtest1-wasmfs.html bc28eb29b69a73864b8d7aae428448f8b7e1de81d8bfb9bba99541322054dbd0 -F ext/wasm/speedtest1-worker.html 17f5b3f0ddb361ea0fdfd58703e42d65b1564c297930ec5fff2cd267e6e252d9 -F ext/wasm/speedtest1-worker.js a9e3d052dd1d8016d6e9a641e596e6d99aec04ef8995d7ee9a85a9964eed771a -F ext/wasm/speedtest1.html e4cb5d722b494104fc1249e7c008ca018f820a784833c51004c958c71038c80f +F ext/wasm/speedtest1-worker.html 7b0cceab6a68b2883738e19f61d21620fe1244ba36c1b2e38d0efde57ecce86d +F ext/wasm/speedtest1-worker.js 3fce67c7d00c9fc42591835a2014520997630e51189f98ca47f706b55cdce8bc +F ext/wasm/speedtest1.html 00102689678b3c09ae6f5e4b3782e95f448e943a3491246e7be9ee349049bcaf F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5 -F ext/wasm/sqlite3-opfs-async-proxy.js 206ce6bbc3c30ad51a37d9c25e3a2712e70b586e0f9a2cf8cb0b9619017c2671 -F ext/wasm/sqlite3-worker1-promiser.js 307d7837420ca6a9d3780dfc81194f1c0715637e6d9540e935514086b96913d8 -F ext/wasm/sqlite3-worker1.js 25b29ff23958883e0a772bc835f4f4eb7e1714d7310385ed27106525930c2530 -F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5 -F ext/wasm/test-opfs-vfs.js 56c3d725044c668fa7910451e96c1195d25ad95825f9ac79f747a7759d1973d0 -F ext/wasm/tester1-worker.html 0af7a22025ff1da72a84765d64f8f221844a57c6e6e314acf3a30f176101fd3f -F ext/wasm/tester1.html fde0e0bdeaaa2c39877c749dc86a8c1c306f771c3d75b89a6289a5ed11243e9d -F ext/wasm/tester1.js 8161dcc4b21902dadec2d3a5dc5700cab9c1641db0603e2ea56ea2a8de6cbab3 -F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893 -F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9dd8ae2cc8719b506b6e013e +F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555e685bce3da8c3f +F ext/wasm/test-opfs-vfs.js 48fc59110e8775bb43c9be25b6d634fc07ebadab7da8fbd44889e8129c6e2548 +F ext/wasm/tester1-worker.html 048c341f124fdb61ca14dfd1bd1f78742490f208aa3bb1e84399f83f1e7e6a74 +F ext/wasm/tester1.html 66b71e2accdcbedae2593c72d2a69f906757707394dc014c2253102f0838cf57 +F ext/wasm/tester1.js 44d71175e2941bf1d7c27afa0c395fe81c83cbd74cd10e34e0688dd833042f1e +F ext/wasm/testing-worker1-promiser.html 88c6ff8a7be351abef219639cd684c5c3e0c649c1dc07b10a5bd59939e7bb4b5 +F ext/wasm/testing-worker1-promiser.js f68ffbbe1c6086e18ce7961b8fc2b40dd88db174f59052e228c06b07484945ca F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3 -F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494 +F ext/wasm/testing2.js 90dc901a54ecc319d09356de2f8c21f53e7f61f2914445e6b176e1bcad12ba8b F ext/wasm/version-info.c 5fa356d38859d71a0369b5c37e1935def7413fcc8a4e349a39d9052c1d0479f4 F ext/wasm/wasmfs.make ee0004813e16c283ff633e08b482008d56adf9b7d42f6c5612f7ab002b924f69 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x @@ -2035,8 +2035,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 2156f0744acfe425457430a0f6a7e02de907de85edba81a6d4eef40293e561c8 -R ee0ece99cec342c109cdb62c53280a5b +P 5b23e0675efdd2f1ea7b4f5836a579e8d6aa8a25b3f1a6a950520ad845ff01bb +R 120493b0bac13d94c837a00d100ef2e2 U stephan -Z 86621ae22c81858679965e272da6ace1 +Z 1f6ca89c3f0ab931ccb09f09451983aa # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 38a86ebeb0..cb6b4b3768 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5b23e0675efdd2f1ea7b4f5836a579e8d6aa8a25b3f1a6a950520ad845ff01bb \ No newline at end of file +6d468dab9eb84d4548f68014959f02fe4f66455472ff24fe729382bb2972e3d1 \ No newline at end of file From 3117dc60e30dc65455f23c0e7e4230dc6c635ae1 Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 19 Oct 2022 06:06:42 +0000 Subject: [PATCH 29/65] Update the dist rules for this evening's js/wasm build changes and include an index.html specifically for the subset of apps included in the dist archive. FossilOrigin-Name: a0ef0f32e96638b502b3951e524d590bdfb09dd39be453686b075102da67b7db --- ext/wasm/GNUmakefile | 18 ++++---- ext/wasm/README-dist.txt | 21 +++++----- ext/wasm/api/README.md | 6 +-- ext/wasm/dist.make | 89 +++++++++++++++++++++------------------- ext/wasm/index-dist.html | 82 ++++++++++++++++++++++++++++++++++++ ext/wasm/tester1.html | 4 +- manifest | 27 ++++++------ manifest.uuid | 2 +- 8 files changed, 167 insertions(+), 82 deletions(-) create mode 100644 ext/wasm/index-dist.html diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index f364e446bc..fdf1332e5c 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -185,17 +185,17 @@ else $(info Development build. Use '$(MAKE) release' for a smaller release build.) endif -version-info := $(dir.wasm)/version-info +bin.version-info := $(dir.wasm)/bin.version-info # ^^^^ NOT in $(dir.tmp) because we need it to survive the cleanup # process for the dist build to work properly. -$(version-info): $(dir.wasm)/version-info.c $(sqlite3.h) $(MAKEFILE) +$(bin.version-info): $(dir.wasm)/version-info.c $(sqlite3.h) $(MAKEFILE) $(CC) -O0 -I$(dir.top) -o $@ $< -DISTCLEAN_FILES += $(version-info) +DISTCLEAN_FILES += $(bin.version-info) -stripccomments := $(dir.tool)/stripccomments -$(stripccomments): $(stripccomments).c $(MAKEFILE) +bin.stripccomments := $(dir.tool)/stripccomments +$(bin.stripccomments): $(bin.stripccomments).c $(MAKEFILE) $(CC) -o $@ $< -DISTCLEAN_FILES += $(stripccomments) +DISTCLEAN_FILES += $(bin.stripccomments) EXPORTED_FUNCTIONS.api.in := $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api) EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api @@ -241,12 +241,12 @@ $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) echo "/* END FILE: $$i */"; \ done > $@ -$(sqlite3-api-build-version.js): $(version-info) $(MAKEFILE) +$(sqlite3-api-build-version.js): $(bin.version-info) $(MAKEFILE) @echo "Making $@..." @{ \ echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \ echo -n ' sqlite3.version = '; \ - $(version-info) --json; \ + $(bin.version-info) --json; \ echo ';'; \ echo '});'; \ } > $@ @@ -543,7 +543,7 @@ o-xtra := -flto # doubles the build time and seems to have negligible effect on # higher optimization levels. o0: clean - $(MAKE) -e "emcc_opt=-O0 $(o-xtra)" + $(MAKE) -e "emcc_opt=-O0" o1: clean $(MAKE) -e "emcc_opt=-O1 $(o-xtra)" o2: clean diff --git a/ext/wasm/README-dist.txt b/ext/wasm/README-dist.txt index 422f3f1e0c..c6fb2c5d1a 100644 --- a/ext/wasm/README-dist.txt +++ b/ext/wasm/README-dist.txt @@ -7,18 +7,17 @@ TODO: link to main WASM/JS docs, once they are online This archive contains the sqlite3.js and sqlite3.wasm file which make up the sqlite3 WASM/JS build. -The jswasm directory contains both the main deliverables and small -demonstration and test apps. Browsers will not serve WASM files from -file:// URLs, so the demo/test apps require a web server and that -server must include the following headers in its response when serving -the files: +The jswasm directory contains the core sqlite3 deliverables and the +top-level directory contains demonstration and test apps. Browsers +will not serve WASM files from file:// URLs, so the demo/test apps +require a web server and that server must include the following +headers in its response when serving the files: Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp -The files named sqlite3*.js and sqlite3.wasm belong to the core -sqlite3 deliverables and the others are soley for demonstration and -may be discarded. They are not in separate directories from the main -deliverables because a quirk of URI resolution in JS code would then -require that sqlite3.js be duplicated and edited for Worker-loaded -operation. +One simple way to get the demo apps up and running on Unix-style +systems is to install althttpd (https://sqlite.org/althttpd) and run: + + althttpd --enable-sab --page index.html + diff --git a/ext/wasm/api/README.md b/ext/wasm/api/README.md index dfb13c569f..6440eba996 100644 --- a/ext/wasm/api/README.md +++ b/ext/wasm/api/README.md @@ -64,12 +64,12 @@ browser client: thread via the Worker message-passing interface. Like OO API #1, this is an optional component, offering one of any number of potential implementations for such an API. - - `../sqlite3-worker1.js`\ + - `sqlite3-worker1.js`\ Is not part of the amalgamated sources and is intended to be loaded by a client Worker thread. It loads the sqlite3 module and runs the Worker #1 API which is implemented in `sqlite3-api-worker1.js`. - - `../sqlite3-worker1-promiser.js`\ + - `sqlite3-worker1-promiser.js`\ Is likewise not part of the amalgamated sources and provides a Promise-based interface into the Worker #1 API. This is a far user-friendlier way to interface with databases running @@ -78,7 +78,7 @@ browser client: is an sqlite3 VFS implementation which supports Google Chrome's Origin-Private FileSystem (OPFS) as a storage layer to provide persistent storage for database files in a browser. It requires... - - `../sqlite3-opfs-async-proxy.js`\ + - `sqlite3-opfs-async-proxy.js`\ is the asynchronous backend part of the OPFS proxy. It speaks directly to the (async) OPFS API and channels those results back to its synchronous counterpart. This file, because it must be diff --git a/ext/wasm/dist.make b/ext/wasm/dist.make index e19b361b19..13cab87669 100644 --- a/ext/wasm/dist.make +++ b/ext/wasm/dist.make @@ -10,14 +10,11 @@ MAKEFILE.dist := $(lastword $(MAKEFILE_LIST)) ######################################################################## -# Chicken/egg situation: we need $(version-info) to get the version +# Chicken/egg situation: we need $(bin.version-info) to get the version # info for the archive name, but that binary may not yet be built, and # won't be built until we expand the dependencies. We have to use a # temporary name for the archive. dist-name = sqlite-wasm-TEMP -dist-archive = $(dist-name).zip -.PHONY: $(dist-archive) -CLEAN_FILES += $(wildcard sqlite-wasm-*.zip) #ifeq (0,1) # $(info WARNING *******************************************************************) # $(info ** Be sure to create the desired build configuration before creating the) @@ -40,52 +37,58 @@ CLEAN_FILES += $(wildcard sqlite-wasm-*.zip) # date. dist-build ?= oz -demo-123.html := $(dir.wasm)/demo-123.html -demo-123-worker.html := $(dir.wasm)/demo-123-worker.html -demo-123.js := $(dir.wasm)/demo-123.js -demo-files := $(demo-123.js) $(demo-123.html) $(demo-123-worker.html) \ - tester1.html tester1.js tester1-worker.html -README-dist := $(dir.wasm)/README-dist.txt -dist-dir-main := $(dist-name)/jswasm -dist.main.extras := \ - sqlite3-opfs-async-proxy.js \ - sqlite3-worker1.js \ - sqlite3-worker1-promiser.js +dist-dir.top := $(dist-name) +dist-dir.jswasm := $(dist-dir.top)/$(notdir $(dir.dout)) +dist-dir.common := $(dist-dir.top)/common +dist.top.extras := \ + demo-123.html demo-123-worker.html demo-123.js \ + tester1.html tester1-worker.html tester1.js +dist.jswasm.extras := $(sqlite3-api.ext.jses) $(sqlite3.wasm) +dist.common.extras := $(wildcard $(dir.common)/*.css) +.PHONY: dist ######################################################################## -# $(dist-archive): create the end-user deliverable archive. +# dist: create the end-user deliverable archive. # -# Maintenance reminder: because $(dist-archive) depends on -# $(dist-build), and $(dist-build) will depend on clean, having any deps -# on $(dist-archive) which themselves may be cleaned up by the clean +# Maintenance reminder: because dist depends on $(dist-build), and +# $(dist-build) will depend on clean, having any deps on +# $(dist-archive) which themselves may be cleaned up by the clean # target will lead to grief in parallel builds (-j #). Thus # $(dist-target)'s deps must be trimmed to non-generated files or # files which are _not_ cleaned up by the clean target. -$(dist-archive): \ - $(stripccomments) $(version-info) \ +# +# Note that we require $(bin.version-info) in order to figure out the +# dist file's name, so cannot (without a recursive make) have the +# target name equal to the archive name. +dist: \ + $(bin.stripccomments) $(bin.version-info) \ $(dist-build) \ $(MAKEFILE) $(MAKEFILE.dist) @echo "Making end-user deliverables..." - @rm -fr $(dist-name) - @mkdir -p $(dist-dir-main) - @cp -p $(README-dist) $(dist-name)/README.txt - @cp -p $(sqlite3.wasm) $(dist.main.extras) $(dist-dir-main) - @$(stripccomments) -k -k < $(sqlite3.js) \ - > $(dist-dir-main)/$(notdir $(sqlite3.js)) - @cp -p $(demo-files) $(dist-dir-main) - @vnum=$$($(version-info) --version-number); \ - vdir=sqlite-wasm-$$vnum; \ - arc=$$vdir.zip; \ - echo "Making $$arc ..."; \ - rm -f $$arc; \ - mv $(dist-name) $$vdir; \ - zip -qr $$arc $$vdir; \ - rm -fr $$vdir; \ - ls -la $$arc; \ - unzip -lv $$arc || echo "Missing unzip app? Not fatal." + @rm -fr $(dist-dir.top) + @mkdir -p $(dist-dir.jswasm) $(dist-dir.common) + @cp -p $(dist.top.extras) $(dist-dir.top) + @cp -p README-dist.txt $(dist-dir.top)/README.txt + @cp -p index-dist.html $(dist-dir.top)/index.html + @cp -p $(dist.jswasm.extras) $(dist-dir.jswasm) + @$(bin.stripccomments) -k -k < $(sqlite3.js) \ + > $(dist-dir.jswasm)/$(notdir $(sqlite3.js)) + @cp -p $(dist.common.extras) $(dist-dir.common) + @vnum=$$($(bin.version-info) --version-number); \ + vdir=sqlite-wasm-$$vnum; \ + arczip=$$vdir.zip; \ + echo "Making $$arczip ..."; \ + rm -f $$arczip; \ + mv $(dist-dir.top) $$vdir; \ + zip -qr $$arczip $$vdir; \ + rm -fr $$vdir; \ + ls -la $$arczip; \ + unzip -lv $$arczip || echo "Missing unzip app? Not fatal." -#$(shell $(version-info) --version-number) -dist: $(dist-archive) -clean-dist: - rm -f $(dist-archive) -clean: clean-dist +# We need a separate `clean` rule to account for weirdness in +# a sub-make, where we get a copy of the $(dist-name) dir +# copied into the new $(dist-name) dir. +.PHONY: dist-clean +clean: dist-clean +dist-clean: + rm -fr $(dist-name) $(wildcard sqlite-wasm-*.zip) diff --git a/ext/wasm/index-dist.html b/ext/wasm/index-dist.html new file mode 100644 index 0000000000..ffb3127761 --- /dev/null +++ b/ext/wasm/index-dist.html @@ -0,0 +1,82 @@ + + + + + + + sqlite3 WASM Demo Page Index + + + +
      sqlite3 WASM demo pages
      +
      +
      Below is the list of demo pages for the sqlite3 WASM + builds. The intent is that this page be run + using the functional equivalent of:
      +
      althttpd -enable-sab -page index.html
      +
      and the individual pages be started in their own tab. + Warnings and Caveats: +
        +
      • Some of these pages require that the web server emit the + so-called + COOP + and + COEP + headers. althttpd requires the + -enable-sab flag for that. +
      • +
      +
      +
      The tests and demos... +
        +
      • Core-most tests +
          +
        • tester1: Core unit and + regression tests for the various APIs and surrounding + utility code.
        • +
        • tester1-worker: same thing + but running in a Worker.
        • +
        +
      • +
      • High-level apps and demos... +
          +
        • demo-123 provides a + no-nonsense example of adding sqlite3 support to a web + page in the UI thread.
        • +
        • demo-123-worker is + the same as demo-123 but loads and runs + sqlite3 from a Worker thread.
        • +
        +
      • +
      +
      + + + + diff --git a/ext/wasm/tester1.html b/ext/wasm/tester1.html index c163151278..0de679f34f 100644 --- a/ext/wasm/tester1.html +++ b/ext/wasm/tester1.html @@ -4,8 +4,8 @@ - - + + sqlite3 tester #1 (UI thread) - + diff --git a/ext/wasm/demo-kvvfs1.js b/ext/wasm/demo-jsstorage.js similarity index 100% rename from ext/wasm/demo-kvvfs1.js rename to ext/wasm/demo-jsstorage.js diff --git a/ext/wasm/testing-worker1-promiser.html b/ext/wasm/demo-worker1-promiser.html similarity index 96% rename from ext/wasm/testing-worker1-promiser.html rename to ext/wasm/demo-worker1-promiser.html index 4b35ca82c0..e99131e6c9 100644 --- a/ext/wasm/testing-worker1-promiser.html +++ b/ext/wasm/demo-worker1-promiser.html @@ -29,6 +29,6 @@
      - + diff --git a/ext/wasm/testing-worker1-promiser.js b/ext/wasm/demo-worker1-promiser.js similarity index 100% rename from ext/wasm/testing-worker1-promiser.js rename to ext/wasm/demo-worker1-promiser.js diff --git a/ext/wasm/testing2.html b/ext/wasm/demo-worker1.html similarity index 96% rename from ext/wasm/testing2.html rename to ext/wasm/demo-worker1.html index 25d5a9f5d8..c766ffd445 100644 --- a/ext/wasm/testing2.html +++ b/ext/wasm/demo-worker1.html @@ -1,3 +1,4 @@ + @@ -28,6 +29,6 @@
      - + diff --git a/ext/wasm/testing2.js b/ext/wasm/demo-worker1.js similarity index 99% rename from ext/wasm/testing2.js rename to ext/wasm/demo-worker1.js index 5ea48db6b6..2da80bc239 100644 --- a/ext/wasm/testing2.js +++ b/ext/wasm/demo-worker1.js @@ -13,7 +13,7 @@ A basic test script for sqlite3-worker1.js. Note that the wrapper interface demonstrated in - testing-worker1-promiser.js is much easier to use from client code, as it + demo-worker1-promiser.js is much easier to use from client code, as it lacks the message-passing acrobatics demonstrated in this file. */ 'use strict'; diff --git a/ext/wasm/dist.make b/ext/wasm/dist.make index bb553d1bd2..df3e236d7b 100644 --- a/ext/wasm/dist.make +++ b/ext/wasm/dist.make @@ -42,9 +42,14 @@ dist-dir.jswasm := $(dist-dir.top)/$(notdir $(dir.dout)) dist-dir.common := $(dist-dir.top)/common dist.top.extras := \ demo-123.html demo-123-worker.html demo-123.js \ - tester1.html tester1-worker.html tester1.js + tester1.html tester1-worker.html tester1.js \ + demo-jsstorage.html demo-jsstorage.js \ + demo-worker1.html demo-worker1.js \ + demo-worker1-promiser.html demo-worker1-promiser.js dist.jswasm.extras := $(sqlite3-api.ext.jses) $(sqlite3.wasm) -dist.common.extras := $(wildcard $(dir.common)/*.css) +dist.common.extras := \ + $(wildcard $(dir.common)/*.css) \ + $(dir.common)/SqliteTestUtil.js .PHONY: dist ######################################################################## diff --git a/ext/wasm/index-dist.html b/ext/wasm/index-dist.html index ffb3127761..6b038c82a9 100644 --- a/ext/wasm/index-dist.html +++ b/ext/wasm/index-dist.html @@ -55,10 +55,10 @@ regression tests for the various APIs and surrounding utility code.
    • tester1-worker: same thing - but running in a Worker.
    • + but running in a Worker.
  • -
  • High-level apps and demos... +
  • Higher-level apps and demos...
    • demo-123 provides a no-nonsense example of adding sqlite3 support to a web @@ -66,6 +66,14 @@
    • demo-123-worker is the same as demo-123 but loads and runs sqlite3 from a Worker thread.
    • +
    • demo-jsstorage: very basic + demo of using the key-value VFS for storing a persistent db + in JS localStorage or sessionStorage.
    • +
    • demo-worker1: + Worker-based wrapper of the OO API #1. Its Promise-based + wrapper is significantly easier to use, however.
    • +
    • demo-worker1-promiser: + a demo of the Promise-based wrapper of the Worker1 API.
  • diff --git a/ext/wasm/index.html b/ext/wasm/index.html index 9fc475f1ed..222105599c 100644 --- a/ext/wasm/index.html +++ b/ext/wasm/index.html @@ -59,9 +59,14 @@
  • demo-123-worker is the same as demo-123 but loads and runs sqlite3 from a Worker thread.
  • -
  • demo-kvvfs1: very basic +
  • demo-jsstorage: very basic demo of using the key-value VFS for storing a persistent db in JS localStorage or sessionStorage.
  • +
  • demo-worker1: + Worker-based wrapper of the OO API #1. Its Promise-based + wrapper is significantly easier to use, however.
  • +
  • demo-worker1-promiser: + a demo of the Promise-based wrapper of the Worker1 API.
  • speedtest1 ports (sqlite3's primary benchmarking tool)... @@ -77,9 +82,6 @@
  • The obligatory "misc." category...