From 0e3d74761d4531a92d16cc068ebdf4caf4ad94ab Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 19 Jun 2004 17:33:07 +0000 Subject: [PATCH] Make sure VdbeFunc entries are initialized before trying to destroy them. Also, unrelated comment changes in build.c. (CVS 1643) FossilOrigin-Name: fc3b3a8fe86980db4de402bb8e85f8f739fc3883 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/build.c | 48 ++++++++++++++++++++++++++++++++++++------------ src/func.c | 19 +++++++++++++++++-- src/vdbeapi.c | 2 ++ test/func.test | 5 +---- 6 files changed, 66 insertions(+), 28 deletions(-) diff --git a/manifest b/manifest index a4ee70045f..acc00bd632 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\sthe\sDB_Locked\sand\sDB_Cookie\sflags.\s\sOther\sminor\scleanup.\s(CVS\s1642) -D 2004-06-19T16:06:11 +C Make\ssure\sVdbeFunc\sentries\sare\sinitialized\sbefore\strying\sto\sdestroy\sthem.\nAlso,\sunrelated\scomment\schanges\sin\sbuild.c.\s(CVS\s1643) +D 2004-06-19T17:33:07 F Makefile.in d69d53c543518c1572ee0a8e8723d7e00bdb2266 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -28,12 +28,12 @@ F src/attach.c 05102e2e8ac43ce639d07b47a99c7772a62420e6 F src/auth.c 60db23b98bb94c8b0178180faaf49dc116674217 F src/btree.c 0cf8a52a57a7eb13d50719114ee1fa353e89d7d3 F src/btree.h 32f96abef464cf8765b23ca669acfe90d191fcc5 -F src/build.c 09d8863a5dc174bac8bd3fc293a3e2519b9d7a49 +F src/build.c 2ed1f14a72ce94a2e4adf333272d67a49925304b F src/date.c b3e8b2bef1e3f2ce24e5b057203036defb18c3f1 F src/delete.c a5191011b7429dff939df631b8bdcc1714b8d7aa F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37 F src/expr.c 9ae0e55a230802da35a55fd6e87533cca0301af9 -F src/func.c 21985e3b20749a18fdf3ae77b455815f730be0b9 +F src/func.c e520c64e83b4a3fb93668552891124b453cc0eff F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb F src/insert.c 1428887f4a7515a7d34e82aaeb76297c79ba378b @@ -74,7 +74,7 @@ F src/vacuum.c fcb930215a3f6c50087300782555f61ad11dd80c F src/vdbe.c 3931b2e4dfb23c8808fb4efc4880dda08c8915ad F src/vdbe.h 9ad64674c4c7acd6744174cab5d34013413ef0d3 F src/vdbeInt.h d007ccada5e3043816097242a560ed6c7f6483ce -F src/vdbeapi.c 0ef00cd2a3764363e957f8e9c6bc90d12989ee3a +F src/vdbeapi.c 8a9421341e09b506a934132c9015f26362ae8c0e F src/vdbeaux.c d2d95f1b9341bd3861e5229cb24a821715824449 F src/vdbemem.c 9359c53386e070fea9f5403cab0c6f0cfe36496b F src/where.c 6507074d8ce3f78e7a4cd33f667f11e62020553e @@ -109,7 +109,7 @@ F test/enc.test e29a0d0558f4597ac1652a7bbac03b0e4ce17416 F test/enc2.test 57c847492afd46eef7a498fc3853fe909a40fef7 F test/expr.test b4e945265c4c697bf5213b72558914ba10a989cc F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7 -F test/func.test a680cac38851a49669eae6eee7dcf13057fae480 +F test/func.test c97954ad23bdbc58e2b73f264f6a006bae79f626 F test/hook.test c4102c672d67f8fb60ea459842805abcba69a747 F test/in.test b92a2df9162e1cbd33c6449a29a05e6955b1741a F test/index.test b6941dd532815f278042b85f79b1a6dc16c4d729 @@ -225,7 +225,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/version3.tcl af528563442e3039928f9018327a18157e53a44f F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 70680a34b4b617286d92730bd3042b8b569b3371 -R b1a9e75569a189850c5300b5594dbc5c +P 01f74b420c3f24918c066172e09cebbb22568faf +R 078b0d50f5c9020e229ba6d09ba2761f U drh -Z 1c5518adfc53e32ee655b3ffea101b0b +Z 71efb9400cf1f9d35d1444e4dd44098f diff --git a/manifest.uuid b/manifest.uuid index a34933ebcf..e6999a900c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -01f74b420c3f24918c066172e09cebbb22568faf \ No newline at end of file +fc3b3a8fe86980db4de402bb8e85f8f739fc3883 \ No newline at end of file diff --git a/src/build.c b/src/build.c index c2aac44c9b..35ddad2732 100644 --- a/src/build.c +++ b/src/build.c @@ -23,7 +23,7 @@ ** ROLLBACK ** PRAGMA ** -** $Id: build.c,v 1.226 2004/06/19 16:06:12 drh Exp $ +** $Id: build.c,v 1.227 2004/06/19 17:33:07 drh Exp $ */ #include "sqliteInt.h" #include @@ -62,6 +62,13 @@ void sqlite3FinishCoding(Parse *pParse){ v = sqlite3GetVdbe(pParse); if( v ){ sqlite3VdbeAddOp(v, OP_Halt, 0, 0); + + /* The cookie mask contains one bit for each database file open. + ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are + ** set for each database that is used. Generate code to start a + ** transaction on each used database and to verify the schema cookie + ** on each used database. + */ if( pParse->cookieMask!=0 ){ u32 mask; int iDb; @@ -221,8 +228,8 @@ void sqlite3UnlinkAndDeleteIndex(sqlite *db, Index *pIndex){ /* ** Erase all schema information from the in-memory hash tables of -** database connection. This routine is called to reclaim memory -** before the connection closes. It is also called during a rollback +** a sigle database. This routine is called to reclaim memory +** before the closes. It is also called during a rollback ** if there were schema changes during the transaction. ** ** If iDb<=0 then reset the internal schema tables for all database @@ -357,9 +364,10 @@ void sqlite3DeleteTable(sqlite *db, Table *pTable){ /* Delete the Table structure itself. */ for(i=0; inCol; i++){ - sqliteFree(pTable->aCol[i].zName); - sqliteFree(pTable->aCol[i].zDflt); - sqliteFree(pTable->aCol[i].zType); + Column *pCol = &pTable->aCol[i]; + sqliteFree(pCol->zName); + sqliteFree(pCol->zDflt); + sqliteFree(pCol->zType); } sqliteFree(pTable->zName); sqliteFree(pTable->aCol); @@ -379,7 +387,7 @@ static void sqliteUnlinkAndDeleteTable(sqlite *db, Table *p){ FKey *pF1, *pF2; int i = p->iDb; assert( db!=0 ); - pOld = sqlite3HashInsert(&db->aDb[i].tblHash, p->zName, strlen(p->zName)+1, 0); + pOld = sqlite3HashInsert(&db->aDb[i].tblHash, p->zName, strlen(p->zName)+1,0); assert( pOld==0 || pOld==p ); for(pF1=p->pFKey; pF1; pF1=pF1->pNextFrom){ int nTo = strlen(pF1->zTo) + 1; @@ -444,13 +452,29 @@ int findDb(sqlite3 *db, Token *pName){ return -1; } +/* The table or view or trigger name is passed to this routine via tokens +** pName1 and pName2. If the table name was fully qualified, for example: +** +** CREATE TABLE xxx.yyy (...); +** +** Then pName1 is set to "xxx" and pName2 "yyy". On the other hand if +** the table name is not fully qualified, i.e.: +** +** CREATE TABLE yyy(...); +** +** Then pName1 is set to "yyy" and pName2 is "". +** +** This routine sets the *ppUnqual pointer to point at the token (pName1 or +** pName2) that stores the unqualified table name. The index of the +** database "xxx" is returned. +*/ int sqlite3TwoPartName( - Parse *pParse, - Token *pName1, - Token *pName2, - Token **pUnqual + Parse *pParse, /* Parsing and code generating context */ + Token *pName1, /* The "xxx" in the name "xxx.yyy" */ + Token *pName2, /* The "yyy" in the name "xxx.yyy" */ + Token **pUnqual /* Write the unqualified object name here */ ){ - int iDb; + int iDb; /* Database holding the object */ sqlite3 *db = pParse->db; if( pName2 && pName2->n>0 ){ diff --git a/src/func.c b/src/func.c index 7e820c8c59..5b5f882fce 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.73 2004/06/19 15:40:23 drh Exp $ +** $Id: func.c,v 1.74 2004/06/19 17:33:07 drh Exp $ */ #include #include @@ -768,7 +768,9 @@ static void randStr(sqlite3_context *context, int argc, sqlite3_value **argv){ zBuf[n] = 0; sqlite3_result_text(context, zBuf, n, SQLITE_TRANSIENT); } +#endif /* SQLITE_TEST */ +#ifdef SQLITE_TEST /* ** The following two SQL functions are used to test returning a text ** result with a destructor. Function 'test_destructor' takes one argument @@ -810,7 +812,20 @@ static void test_destructor_count( ){ sqlite3_result_int(pCtx, test_destructor_count_var); } +#endif /* SQLITE_TEST */ +#ifdef SQLITE_TEST +/* +** Routines for testing the sqlite3_get_auxdata() and sqlite3_set_auxdata() +** interface. +** +** The test_auxdata() SQL function attempts to register each of its arguments +** as auxiliary data. If there are no prior registrations of aux data for +** that argument (meaning the argument is not a constant or this is its first +** call) then the result for that argument is 0. If there is a prior +** registration, the result for that argument is 1. The overall result +** is the individual argument results separated by spaces. +*/ static void free_test_auxdata(void *p) {sqliteFree(p);} static void test_auxdata( sqlite3_context *pCtx, @@ -840,7 +855,7 @@ static void test_auxdata( } sqlite3_result_text(pCtx, zRet, 2*nArg-1, free_test_auxdata); } -#endif +#endif /* SQLITE_TEST */ /* ** An instance of the following structure holds the context of a diff --git a/src/vdbeapi.c b/src/vdbeapi.c index b34b60fb4d..7be483463d 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -241,6 +241,8 @@ void sqlite3_set_auxdata( int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg; pCtx->pVdbeFunc = pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc); if( !pVdbeFunc ) return; + memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0, + sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux)); pVdbeFunc->nAux = iArg+1; pVdbeFunc->pFunc = pCtx->pFunc; } diff --git a/test/func.test b/test/func.test index a631526c9f..de8ab615ff 100644 --- a/test/func.test +++ b/test/func.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing built-in functions. # -# $Id: func.test,v 1.23 2004/06/19 00:16:31 drh Exp $ +# $Id: func.test,v 1.24 2004/06/19 17:33:08 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -436,6 +436,3 @@ do_test func-13.7 { finish_test - - -