1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Make sure VdbeFunc entries are initialized before trying to destroy them.

Also, unrelated comment changes in build.c. (CVS 1643)

FossilOrigin-Name: fc3b3a8fe86980db4de402bb8e85f8f739fc3883
This commit is contained in:
drh
2004-06-19 17:33:07 +00:00
parent 124b27e654
commit 0e3d74761d
6 changed files with 66 additions and 28 deletions

View File

@@ -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 <ctype.h>
@@ -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; i<pTable->nCol; 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 ){

View File

@@ -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 <ctype.h>
#include <math.h>
@@ -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

View File

@@ -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;
}