-C Enhancements\sand\ssmoke\stesting\sof\sthe\snew\smemory\sallocation\ssubsystem.\nHave\snot\syet\scut\sit\sover\sto\sthe\score,\sthough.\s(CVS\s4230)
-D 2007-08-15T20:41:29
+C Half-way\sthrough\sa\smajor\srefactoring\sof\sthe\smemory\sallocation.\nI\shave\snot\seven\sattempted\sto\scompile\sso\sI\sam\scertain\sthere\sare\ncountless\serrors.\s(CVS\s4231)
+D 2007-08-16T04:30:39
F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.def a96c1d0d39362b763d2ddba220a32da41a15c4b4
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
-F src/alter.c 24c81ed6734304326922d42430567d1ee368c81d
-F src/analyze.c 8d345472e0f4e44fc88f5cf489c16dcb77904525
-F src/attach.c ba628db0c2b6a362f036d017bf1196cdfe4ebb37
+F src/alter.c 27b0c0d371a825f9a8b7198a3f3f94c2e027f25e
+F src/analyze.c e2bbd2510b4009bc9839e32ceac21ac1bd711f37
+F src/attach.c a52225c75b107be8c5bc144a2b6d20201be3f8f8
F src/auth.c 5ea90bc93dfea46e9fe4bf531e14c7cd98219ecb
-F src/btree.c be3f7d6d20f65c997f2f67d5b31d63aa74de6845
+F src/btree.c 1f7c009817a03a3cbf4f78d4d373543d89ebc890
F src/btree.h 1d527bf61ed176f980c34999d5793a0fd45dcf8c
F src/btreeInt.h ac1ab1fb624ffbe571786cd2bd9559f9ae336355
-F src/build.c 59fd5782a728686148a6d30a5df283c177d22c1f
-F src/callback.c 9c12535669a638f90a67e10440b99c7b93c0fbf4
+F src/build.c a25bf9d25623c7730bc58922e0e84204ad98c968
+F src/callback.c 5680c2b84177e52c54b42e94291d30b4b6ed2126
F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
-F src/date.c 6049db7d5a8fdf2c677ff7d58fa31d4f6593c988
-F src/delete.c 5c0d89b3ef7d48fe1f5124bfe8341f982747fe29
+F src/date.c 6c6ae019e78fec543988c8d907fa9524dc2c2934
+F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
-F src/expr.c 9bc05ed44feb04b585c72162fbb30d89b268feb6
-F src/func.c 28daebcddce30030f167afb3a7ed881a043b98b0
-F src/hash.c 67b23e14f0257b69a3e8aa663e4eeadc1a2b6fd5
-F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
-F src/insert.c ca135e919c2a9241e83e8dd74316677fdd54fb6f
-F src/legacy.c 388c71ad7fbcd898ba1bcbfc98a3ac954bfa5d01
+F src/expr.c 002266066377f542e776448e04816d2a887d7dc3
+F src/func.c bd94a8aabeecc741df71afba856133738f1c1638
+F src/hash.c 05ebefb85d77caed0454408ee1e069702d289bff
+F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e
+F src/insert.c bca11ad7b7ab4a1ba4808b6e0a6fd842923f88bb
+F src/legacy.c 6013a7cb7da1b72550b3d35d4fc598b3c3e5b8c1
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
-F src/loadext.c 6c24ee62adfe7fbfb2f2dd43ff18e5534b19010f
-F src/main.c f12d230c1226d3f43c1f4595af1c25ccbe3017c7
-F src/malloc.c 3850ab4a2edfb190ffee353c5674ebd8c6b4ccc7
+F src/loadext.c aa1c6e584d39cc241226ec9390387bc2d4a23e8f
+F src/main.c 7850774e64fc1f804a3f91a8a66ba4215e9fa05b
+F src/malloc.c bec719bda3db0ea797b03c5e6536b125d0e618ff
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 6d4b9efe51242fcc63d410fb326824f1208b3d4e
F src/mem2.c d0ba3b23da2e95bced1818ade8a8a2dc9526111c
F src/os_os2.h e5f17dd69333632bbc3112881ea407c37d245eb3
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
-F src/os_unix.c 05ad65c32b4937fd47b17b472955aa5dfc438074
+F src/os_unix.c 67601899b573c8a7a23aee9d3eeeb7aa724501ee
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c d868d5f9e95ec9c1b9e2a30c54c996053db6dddd
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c 05ea9dcbc4de4e9d9ca332ca1f8a9ba65fe2cbf5
+F src/pager.c ddb0279c4030128b2f06cdd02b68ae266a8f4fe7
F src/pager.h 94110a5570dca30d54a883e880a3633b2e4c05ae
-F src/parse.y ad2ce25665be7f7303137f774a4e3e72e0d036ff
-F src/pragma.c 7914a6b9ea05f158800116dfcae11e52ab8e39c4
-F src/prepare.c 3257b63db949aee338a16ad23e09df8d56c1c36f
-F src/printf.c 9b3048d270e8bb2f8b910b491ac3aadece6cfab2
+F src/parse.y 4934dc7e7a679f71359420de11aae7c281a73151
+F src/pragma.c 9ecc2bcd790fc1723a5f78ff46493ce4d2b77ced
+F src/prepare.c 237ed8ce0509da9e28a4773b96ec4c44015b970e
+F src/printf.c 326386450a8fa31853503b3a8cc758d72d41fc7e
F src/random.c 6119474a6f6917f708c1dee25b9a8e519a620e88
-F src/select.c 3b167744fc375bddfddcef87feb18f5171737677
+F src/select.c 4df152ea0cd13b37cc4e41c56cad7c8ed2d9718c
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c ac29402b538515fa4697282387be9c1205e6e9eb
F src/sqlite.h.in 165913eb3426fbaa8a2a51d87f84593bfe5bee15
F src/sqlite3ext.h a27bedc222df5e5f0f458ac99726d0483b953a91
-F src/sqliteInt.h fc9f6e8d916e182c04983a089c4ce4057fac5003
+F src/sqliteInt.h acdc2d5b997504c3b1d1cc7ac31ec064f23c26b5
F src/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa
F src/table.c a8de75bcedf84d4060d804264b067ab3b1a3561d
F src/tclsqlite.c 0606c4f31711492eb4d7480a981eebb80914f3d9
-F src/test1.c 94bd41c24a4d8d782e39c1275421511587d8b293
+F src/test1.c b5b36bdf40a78e351cb0def7bc900991adcc4c4f
F src/test2.c 5c3edc610852a8f67990cd08c5d5dbb79e3f8db9
-F src/test3.c a280931fb40222b7c90da45eea926459beee8904
-F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25
-F src/test5.c c40a4cf43266c1c6da7bcb737d294304a177e6cc
-F src/test6.c 4d812a5ea1fe08693f4189bfc974b341102a3bea
-F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3
-F src/test8.c 27a61c60f736066646a9e9ca21acdfdf0f3ea11e
+F src/test3.c 497ed07038ea79ab683b0beba6a39c89540ce632
+F src/test4.c d22cb3ab4f9fdfd0a595b70d5328cee923b7322c
+F src/test5.c 27f3aa4eebfec94769d199f85212708ec77536c7
+F src/test6.c b0aea6299100bee055ff9d8f30d87e393384e607
+F src/test7.c 91d914c2c2b2806157213f41f4185ad3a4970c07
+F src/test8.c 95c9e0639e555768e15f88c87ae805c10340d8c2
F src/test9.c c0f38f7795cc51d37db6c63874d90f40f10d0f0e
-F src/test_async.c 9d326ceda4306bcab252b8f7e8e480ed45d7ccb6
+F src/test_async.c 871ffbe4a520be74b403aca87aa622ebdb690232
F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
F src/test_btree.c 882d59acad48bab3b1fe3daf3645059b590cfc79
F src/test_config.c 26389b032216e0fb2b544ff48a5e9101bd7b1fb4
-F src/test_hexio.c 14c007252285c6dabcec4a28fcf08e9177e85178
+F src/test_hexio.c 82916f918687502658f02533b519c38cb180db6d
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_malloc.c d9ba6be85f9c4a439b19f6e0a72d91c369d72c63
F src/test_md5.c d9f828765b242ff86f58cd879259c3da4eaede02
-F src/test_schema.c 89c526e4b1e9a8fb540550f6ebc69242bf57d3ce
+F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f
F src/test_server.c 76c0baf509abe65ca6e5c7974ab0097cfdd8b833
-F src/test_tclvar.c ea4500a60d663f7fdf18fd3210efc112e0c6e7f0
-F src/tokenize.c e959754c67bbd0cf0b03520f7344a536a7ac2915
-F src/trigger.c 355cdf7019dfa5468bf531347f7568283a288746
-F src/update.c 6b10becb6235ea314ed245fbfbf8b38755e3166e
-F src/utf.c 68873142d65d686e59af4886073c0a67a1230171
-F src/util.c 9e81d417fc60bd2fe156f8f2317aa4845bc6cc90
-F src/vacuum.c 8bd895d29e7074e78d4e80f948e35ddc9cf2beef
-F src/vdbe.c cf973bd1af5fbda845b0f759bb06eb19ff42e215
+F src/test_tclvar.c 51f69f526ed4a044dc7c13c7badccd33cb41132b
+F src/tokenize.c 418842048447c6d0889fd2e0b414288615d28aaa
+F src/trigger.c f29b1d40a329f33dd683b500cc5d493f2acb9558
+F src/update.c b20d7730bfe46367a8d3f540a0b0632840c82fec
+F src/utf.c e2212080d74559a1a351ab4d235b97f522132995
+F src/util.c c831d17623ffb0e09a3710f8f679eeeb42a423c2
+F src/vacuum.c f45bd9d3aad8d68bb3b85cf89d7a797be5075fde
+F src/vdbe.c dd6f17be86fde2ca07d4b065ed79815a617615cd
F src/vdbe.h 001c5b257567c1d3de7feb2203aac71d0d7b16a3
-F src/vdbeInt.h c3514903cad9e36d6b3242be20261351d09db56c
-F src/vdbeapi.c 220b81132abaf0f620edb8da48799a77daef12a7
-F src/vdbeaux.c 8e6dbe3dac3bdd7d37c87ba553059b5251ba07e5
-F src/vdbeblob.c bb30b3e387c35ba869949494b2736aff97159470
-F src/vdbefifo.c 3ca8049c561d5d67cbcb94dc909ae9bb68c0bf8f
-F src/vdbemem.c ca4d3994507cb0a9504820293af69f5c778b4abd
-F src/vtab.c 60dc6d881c3049ec0e9f780e6beb953dbd78673d
-F src/where.c c7e13b81ff8777e402d047a695fbf322e67c89e1
+F src/vdbeInt.h 0629275fd265cf1ba039c08e1d41c91258f02f64
+F src/vdbeapi.c fce4ee6ab2cb8fd209f53b8a9261603c82993b8c
+F src/vdbeaux.c e59e50659a5e19298e6b3e21e7ae309d43607305
+F src/vdbeblob.c cf9ee3c7d9977cbd896f8b118da4fb4268637f4f
+F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
+F src/vdbemem.c 59fde3ec6178bee1e6200a524c2cf5937cfe33ab
+F src/vtab.c ea2557202d0e6d01dc810be9007a63e1ef357820
+F src/where.c 366bfb2b03b1b1fa63dc6a1b14f86509fe0d12ed
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/all.test 56bc526a6cbb262c5b678dd606de8c92ae39705e
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 9e506656720fb3a3205b8cc398152272ce56f6f3
-R 1bc235d902bd5b92ca3cb78565b1c6fd
+P 1dad2c0a1f00596b13b02ccef664bd2346a677a4
+R b936ef9b9840b7af9fe0cf357a16be54
U drh
-Z 15d4eec20da6957d2d37ec345d76fef8
+Z 75f9460fb314adda683774e2c83526fd
-1dad2c0a1f00596b13b02ccef664bd2346a677a4
\ No newline at end of file
+deb7ecd65f7b83eaf0ba610eeef3b0ede61db1c3
\ No newline at end of file
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
-** $Id: alter.c,v 1.27 2007/06/27 17:09:24 danielk1977 Exp $
+** $Id: alter.c,v 1.28 2007/08/16 04:30:39 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
}else{
tmp = zWhere;
zWhere = sqlite3MPrintf("%s OR name=%Q", zWhere, pTrig->name);
- sqliteFree(tmp);
+ sqlite3_free(tmp);
}
}
}
#endif
int isVirtualRename = 0; /* True if this is a v-table with an xRename() */
- if( sqlite3MallocFailed() ) goto exit_rename_table;
+ if( db->mallocFailed ) goto exit_rename_table;
assert( pSrc->nSrc==1 );
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
zDb = db->aDb[iDb].zName;
/* Get a NULL terminated version of the new table name. */
- zName = sqlite3NameFromToken(pName);
+ zName = sqlite3NameFromToken(db, pName);
if( !zName ) goto exit_rename_table;
/* Check that a table or index named 'zName' does not already exist
"sql = sqlite_rename_trigger(sql, %Q), "
"tbl_name = %Q "
"WHERE %s;", zName, zName, zWhere);
- sqliteFree(zWhere);
+ sqlite3_free(zWhere);
}
#endif
exit_rename_table:
sqlite3SrcListDelete(pSrc);
- sqliteFree(zName);
+ sqlite3_free(zName);
}
char *zCol; /* Null-terminated column definition */
Column *pCol; /* The new column */
Expr *pDflt; /* Default value for the new column */
+ sqlite3 *db; /* The database connection; */
if( pParse->nErr ) return;
pNew = pParse->pNewTable;
assert( pNew );
- iDb = sqlite3SchemaToIndex(pParse->db, pNew->pSchema);
- zDb = pParse->db->aDb[iDb].zName;
+ db = pParse->db;
+ iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
+ zDb = db->aDb[iDb].zName;
zTab = pNew->zName;
pCol = &pNew->aCol[pNew->nCol-1];
pDflt = pCol->pDflt;
- pTab = sqlite3FindTable(pParse->db, zTab, zDb);
+ pTab = sqlite3FindTable(db, zTab, zDb);
assert( pTab );
#ifndef SQLITE_OMIT_AUTHORIZATION
if( pDflt ){
sqlite3_value *pVal;
if( sqlite3ValueFromExpr(pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
- /* malloc() has failed */
+ db->mallocFailed = 1;
return;
}
if( !pVal ){
}
/* Modify the CREATE TABLE statement. */
- zCol = sqliteStrNDup((char*)pColDef->z, pColDef->n);
+ zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
if( zCol ){
char *zEnd = &zCol[pColDef->n-1];
while( (zEnd>zCol && *zEnd==';') || isspace(*(unsigned char *)zEnd) ){
zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,
zTab
);
- sqliteFree(zCol);
+ sqlite3_free(zCol);
}
/* If the default value of the new column is NULL, then set the file
int iDb;
int i;
int nAlloc;
+ sqlite3 *db = pParse->db;
/* Look up the table being altered. */
assert( pParse->pNewTable==0 );
- if( sqlite3MallocFailed() ) goto exit_begin_add_column;
+ if( db->mallocFailed ) goto exit_begin_add_column;
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
if( !pTab ) goto exit_begin_add_column;
}
assert( pTab->addColOffset>0 );
- iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
+ iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
/* Put a copy of the Table struct in Parse.pNewTable for the
** sqlite3AddColumn() function and friends to modify.
*/
- pNew = (Table *)sqliteMalloc(sizeof(Table));
+ pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
if( !pNew ) goto exit_begin_add_column;
pParse->pNewTable = pNew;
pNew->nRef = 1;
assert( pNew->nCol>0 );
nAlloc = (((pNew->nCol-1)/8)*8)+8;
assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
- pNew->aCol = (Column *)sqliteMalloc(sizeof(Column)*nAlloc);
- pNew->zName = sqliteStrDup(pTab->zName);
+ pNew->aCol = (Column*)sqlite3_malloc(sizeof(Column)*nAlloc);
+ pNew->zName = sqlite3DbStrDup(db, pTab->zName);
if( !pNew->aCol || !pNew->zName ){
+ db->mallocFailed = 1;
goto exit_begin_add_column;
}
memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
for(i=0; i<pNew->nCol; i++){
Column *pCol = &pNew->aCol[i];
- pCol->zName = sqliteStrDup(pCol->zName);
+ pCol->zName = sqlite3DbStrDup(db, pCol->zName);
pCol->zColl = 0;
pCol->zType = 0;
pCol->pDflt = 0;
}
- pNew->pSchema = pParse->db->aDb[iDb].pSchema;
+ pNew->pSchema = db->aDb[iDb].pSchema;
pNew->addColOffset = pTab->addColOffset;
pNew->nRef = 1;
sqlite3BeginWriteOperation(pParse, 0, iDb);
v = sqlite3GetVdbe(pParse);
if( !v ) goto exit_begin_add_column;
- sqlite3ChangeCookie(pParse->db, v, iDb);
+ sqlite3ChangeCookie(db, v, iDb);
exit_begin_add_column:
sqlite3SrcListDelete(pSrc);
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
-** @(#) $Id: analyze.c,v 1.19 2007/06/20 13:37:31 drh Exp $
+** @(#) $Id: analyze.c,v 1.20 2007/08/16 04:30:39 drh Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"
if( iDb>=0 ){
analyzeDatabase(pParse, iDb);
}else{
- z = sqlite3NameFromToken(pName1);
+ z = sqlite3NameFromToken(db, pName1);
pTab = sqlite3LocateTable(pParse, z, 0);
- sqliteFree(z);
+ sqlite3_free(z);
if( pTab ){
analyzeTable(pParse, pTab);
}
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
if( iDb>=0 ){
zDb = db->aDb[iDb].zName;
- z = sqlite3NameFromToken(pTableName);
+ z = sqlite3NameFromToken(db, pTableName);
if( z ){
pTab = sqlite3LocateTable(pParse, z, zDb);
- sqliteFree(z);
+ sqlite3_free(z);
if( pTab ){
analyzeTable(pParse, pTab);
}
sqlite3SafetyOff(db);
rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
sqlite3SafetyOn(db);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
return rc;
}
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
-** $Id: attach.c,v 1.60 2007/05/09 20:31:30 drh Exp $
+** $Id: attach.c,v 1.61 2007/08/16 04:30:39 drh Exp $
*/
#include "sqliteInt.h"
for(i=0; i<db->nDb; i++){
char *z = db->aDb[i].zName;
if( z && zName && sqlite3StrICmp(z, zName)==0 ){
- sqlite3_snprintf(sizeof(zErr), zErr, "database %s is already in use", zName);
+ sqlite3_snprintf(sizeof(zErr), zErr,
+ "database %s is already in use", zName);
goto attach_error;
}
}
** hash tables.
*/
if( db->aDb==db->aDbStatic ){
- aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
+ aNew = sqlite3_malloc( sizeof(db->aDb[0])*3 );
if( aNew==0 ){
+ db->mallocFailed = 1;
return;
}
memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
}else{
- aNew = sqliteRealloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
+ aNew = sqlite3_realloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
if( aNew==0 ){
+ db->mallocFailed = 1;
return;
}
}
*/
rc = sqlite3BtreeFactory(db, zFile, 0, SQLITE_DEFAULT_CACHE_SIZE, &aNew->pBt);
if( rc==SQLITE_OK ){
- aNew->pSchema = sqlite3SchemaGet(aNew->pBt);
+ aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
if( !aNew->pSchema ){
rc = SQLITE_NOMEM;
}else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
}
sqlite3PagerLockingMode(sqlite3BtreePager(aNew->pBt), db->dfltLockMode);
}
- aNew->zName = sqliteStrDup(zName);
+ aNew->zName = sqlite3DbStrDup(db, zName);
aNew->safety_level = 3;
#if SQLITE_HAS_CODEC
switch( t ){
case SQLITE_INTEGER:
case SQLITE_FLOAT:
- zErrDyn = sqliteStrDup("Invalid key value");
+ zErrDyn = sqlite3DbStrDup(db, "Invalid key value");
rc = SQLITE_ERROR;
break;
sqlite3ResetInternalSchema(db, 0);
db->nDb = iDb;
if( rc==SQLITE_NOMEM ){
- sqlite3FailedMalloc();
+ db->mallocFailed = 1;
sqlite3_snprintf(sizeof(zErr),zErr, "out of memory");
}else{
sqlite3_snprintf(sizeof(zErr),zErr, "unable to open database: %s", zFile);
/* Return an error if we get here */
if( zErrDyn ){
sqlite3_result_error(context, zErrDyn, -1);
- sqliteFree(zErrDyn);
+ sqlite3_free(zErrDyn);
}else{
zErr[sizeof(zErr)-1] = 0;
sqlite3_result_error(context, zErr, -1);
sqlite3* db = pParse->db;
#ifndef SQLITE_OMIT_AUTHORIZATION
- assert( sqlite3MallocFailed() || pAuthArg );
+ assert( db->mallocFailed || pAuthArg );
if( pAuthArg ){
- char *zAuthArg = sqlite3NameFromToken(&pAuthArg->span);
+ char *zAuthArg = sqlite3NameFromToken(db, &pAuthArg->span);
if( !zAuthArg ){
goto attach_end;
}
rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
- sqliteFree(zAuthArg);
+ sqlite3_free(zAuthArg);
if(rc!=SQLITE_OK ){
goto attach_end;
}
sqlite3ExprCode(pParse, pDbname);
sqlite3ExprCode(pParse, pKey);
- assert( v || sqlite3MallocFailed() );
+ assert( v || db->mallocFailed );
if( v ){
sqlite3VdbeAddOp(v, OP_Function, 0, nFunc);
pFunc = sqlite3FindFunction(db, zFunc, strlen(zFunc), nFunc, SQLITE_UTF8,0);
zDb = pFix->zDb;
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
if( pItem->zDatabase==0 ){
- pItem->zDatabase = sqliteStrDup(zDb);
+ pItem->zDatabase = sqlite3DbStrDup(pFix->pParse->db, zDb);
}else if( sqlite3StrICmp(pItem->zDatabase,zDb)!=0 ){
sqlite3ErrorMsg(pFix->pParse,
"%s %T cannot reference objects in database %s",
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.396 2007/08/13 14:56:44 drh Exp $
+** $Id: btree.c,v 1.397 2007/08/16 04:30:39 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
** with table iTable, allocate one and link it into the list.
*/
if( !pLock ){
- pLock = (BtLock *)sqliteMalloc(sizeof(BtLock));
+ pLock = (BtLock *)sqlite3MallocZero(sizeof(BtLock));
if( !pLock ){
return SQLITE_NOMEM;
}
BtLock *pLock = *ppIter;
if( pLock->pBtree==p ){
*ppIter = pLock->pNext;
- sqliteFree(pLock);
+ sqlite3_free(pLock);
}else{
ppIter = &pLock->pNext;
}
** Invalidate the overflow page-list cache for cursor pCur, if any.
*/
static void invalidateOverflowCache(BtCursor *pCur){
- sqliteFree(pCur->aOverflow);
+ sqlite3_free(pCur->aOverflow);
pCur->aOverflow = 0;
}
** data.
*/
if( rc==SQLITE_OK && 0==pCur->pPage->intKey){
- void *pKey = sqliteMalloc(pCur->nKey);
+ void *pKey = sqlite3_malloc(pCur->nKey);
if( pKey ){
rc = sqlite3BtreeKey(pCur, 0, pCur->nKey, pKey);
if( rc==SQLITE_OK ){
pCur->pKey = pKey;
}else{
- sqliteFree(pKey);
+ sqlite3_free(pKey);
}
}else{
rc = SQLITE_NOMEM;
** Clear the current cursor position.
*/
static void clearCursorPosition(BtCursor *pCur){
- sqliteFree(pCur->pKey);
+ sqlite3_free(pCur->pKey);
pCur->pKey = 0;
pCur->eState = CURSOR_INVALID;
}
pCur->eState = CURSOR_INVALID;
rc = sqlite3BtreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skip);
if( rc==SQLITE_OK ){
- sqliteFree(pCur->pKey);
+ sqlite3_free(pCur->pKey);
pCur->pKey = 0;
assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
}
assert( pPage->pBt!=0 );
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
assert( pPage->nOverflow==0 );
- temp = sqliteMalloc( pPage->pBt->pageSize );
+ temp = sqlite3_malloc( pPage->pBt->pageSize );
if( temp==0 ) return SQLITE_NOMEM;
data = pPage->aData;
hdr = pPage->hdrOffset;
data[hdr+7] = 0;
addr = cellOffset+2*nCell;
memset(&data[addr], 0, brk-addr);
- sqliteFree(temp);
+ sqlite3_free(temp);
return SQLITE_OK;
}
#endif
#endif
- p = sqliteMalloc(sizeof(Btree));
+ p = sqlite3MallocZero(sizeof(Btree));
if( !p ){
return SQLITE_NOMEM;
}
if( pTsdro->useSharedData && zFilename && !isMemdb ){
char *zFullPathname = sqlite3OsFullPathname(zFilename);
if( !zFullPathname ){
- sqliteFree(p);
+ sqlite3_free(p);
return SQLITE_NOMEM;
}
for(pBt=pTsdro->pBtree; pBt; pBt=pBt->pNext){
p->pBt = pBt;
*ppBtree = p;
pBt->nRef++;
- sqliteFree(zFullPathname);
+ sqlite3_free(zFullPathname);
return SQLITE_OK;
}
}
- sqliteFree(zFullPathname);
+ sqlite3_free(zFullPathname);
}
#endif
assert( sizeof(u16)==2 );
assert( sizeof(Pgno)==4 );
- pBt = sqliteMalloc( sizeof(*pBt) );
+ pBt = sqlite3MallocZero( sizeof(*pBt) );
if( pBt==0 ){
rc = SQLITE_NOMEM;
goto btree_open_out;
if( pBt && pBt->pPager ){
sqlite3PagerClose(pBt->pPager);
}
- sqliteFree(pBt);
- sqliteFree(p);
+ sqlite3_free(pBt);
+ sqlite3_free(p);
*ppBtree = 0;
}
return rc;
** this handle.
*/
sqlite3BtreeRollback(p);
- sqliteFree(p);
+ sqlite3_free(p);
#ifndef SQLITE_OMIT_SHARED_CACHE
/* If there are still other outstanding references to the shared-btree
if( pBt->xFreeSchema && pBt->pSchema ){
pBt->xFreeSchema(pBt->pSchema);
}
- sqliteFree(pBt->pSchema);
- sqliteFree(pBt);
+ sqlite3_free(pBt->pSchema);
+ sqlite3_free(pBt);
return SQLITE_OK;
}
return SQLITE_READONLY;
}
}
- pCur = sqliteMalloc( sizeof(*pCur) );
+ pCur = sqlite3MallocZero( sizeof(*pCur) );
if( pCur==0 ){
rc = SQLITE_NOMEM;
goto create_cursor_exception;
create_cursor_exception:
if( pCur ){
releasePage(pCur->pPage);
- sqliteFree(pCur);
+ sqlite3_free(pCur);
}
unlockBtreeIfUnused(pBt);
return rc;
releasePage(pCur->pPage);
unlockBtreeIfUnused(pBt);
invalidateOverflowCache(pCur);
- sqliteFree(pCur);
+ sqlite3_free(pCur);
return SQLITE_OK;
}
*/
if( pCur->isIncrblobHandle && !pCur->aOverflow ){
int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
- pCur->aOverflow = (Pgno *)sqliteMalloc(sizeof(Pgno)*nOvfl);
+ pCur->aOverflow = (Pgno *)sqlite3MallocZero(sizeof(Pgno)*nOvfl);
if( nOvfl && !pCur->aOverflow ){
rc = SQLITE_NOMEM;
}
if( available>=nCellKey ){
c = pCur->xCompare(pCur->pArg, nCellKey, pCellKey, nKey, pKey);
}else{
- pCellKey = sqliteMallocRaw( nCellKey );
+ pCellKey = sqlite3_malloc( nCellKey );
if( pCellKey==0 ) return SQLITE_NOMEM;
rc = sqlite3BtreeKey(pCur, 0, nCellKey, (void *)pCellKey);
c = pCur->xCompare(pCur->pArg, nCellKey, pCellKey, nKey, pKey);
- sqliteFree(pCellKey);
+ sqlite3_free(pCellKey);
if( rc ) return rc;
}
}
/*
** Allocate space for memory structures
*/
- apCell = sqliteMallocRaw(
+ apCell = sqlite3_malloc(
nMaxCells*sizeof(u8*) /* apCell */
+ nMaxCells*sizeof(int) /* szCell */
+ ROUND8(sizeof(MemPage))*NB /* aCopy */
** Cleanup before returning.
*/
balance_cleanup:
- sqliteFree(apCell);
+ sqlite3_free(apCell);
for(i=0; i<nOld; i++){
releasePage(apOld[i]);
}
assert( pPage->nCell==0 );
pBt = pPage->pBt;
mxCellPerPage = MX_CELL(pBt);
- apCell = sqliteMallocRaw( mxCellPerPage*(sizeof(u8*)+sizeof(int)) );
+ apCell = sqlite3_malloc( mxCellPerPage*(sizeof(u8*)+sizeof(int)) );
if( apCell==0 ) return SQLITE_NOMEM;
szCell = (int*)&apCell[mxCellPerPage];
if( pPage->leaf ){
releasePage(pChild);
}
end_shallow_balance:
- sqliteFree(apCell);
+ sqlite3_free(apCell);
return rc;
}
assert( pPage->isInit );
rc = sqlite3PagerWrite(pPage->pDbPage);
if( rc ) return rc;
- newCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
+ newCell = sqlite3_malloc( MX_CELL_SIZE(pBt) );
if( newCell==0 ) return SQLITE_NOMEM;
rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
if( rc ) goto end_insert;
moveToRoot(pCur);
}
end_insert:
- sqliteFree(newCell);
+ sqlite3_free(newCell);
return rc;
}
pNext = findCell(leafCur.pPage, leafCur.idx);
szNext = cellSizePtr(leafCur.pPage, pNext);
assert( MX_CELL_SIZE(pBt)>=szNext+4 );
- tempCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
+ tempCell = sqlite3_malloc( MX_CELL_SIZE(pBt) );
if( tempCell==0 ){
rc = SQLITE_NOMEM;
}
dropCell(leafCur.pPage, leafCur.idx, szNext);
rc = balance(leafCur.pPage, 0);
}
- sqliteFree(tempCell);
+ sqlite3_free(tempCell);
sqlite3BtreeReleaseTempCursor(&leafCur);
}else{
TRACE(("DELETE: table=%d delete from leaf %d\n",
char *zOld = pCheck->zErrMsg;
pCheck->zErrMsg = 0;
sqlite3SetString(&pCheck->zErrMsg, zOld, "\n", zMsg1, zMsg2, (char*)0);
- sqliteFree(zOld);
+ sqlite3_free(zOld);
}else{
sqlite3SetString(&pCheck->zErrMsg, zMsg1, zMsg2, (char*)0);
}
- sqliteFree(zMsg2);
+ sqlite3_free(zMsg2);
}
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
*/
data = pPage->aData;
hdr = pPage->hdrOffset;
- hit = sqliteMalloc( usableSize );
+ hit = sqlite3MallocZero( usableSize );
if( hit ){
memset(hit, 1, get2byte(&data[hdr+5]));
nCell = get2byte(&data[hdr+3]);
cnt, data[hdr+7], iPage);
}
}
- sqliteFree(hit);
+ sqlite3_free(hit);
releasePage(pPage);
return depth+1;
nRef = sqlite3PagerRefcount(pBt->pPager);
if( lockBtreeWithRetry(p)!=SQLITE_OK ){
- return sqliteStrDup("Unable to acquire a read lock on the database");
+ return sqlite3StrDup("Unable to acquire a read lock on the database");
}
sCheck.pBt = pBt;
sCheck.pPager = pBt->pPager;
unlockBtreeIfUnused(pBt);
return 0;
}
- sCheck.anRef = sqliteMallocRaw( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) );
+ sCheck.anRef = sqlite3_malloc( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) );
if( !sCheck.anRef ){
unlockBtreeIfUnused(pBt);
*pnErr = 1;
/* Clean up and report errors.
*/
- sqliteFree(sCheck.anRef);
+ sqlite3_free(sCheck.anRef);
*pnErr = sCheck.nErr;
return sCheck.zErrMsg;
}
**
** Just before the shared-btree is closed, the function passed as the
** xFree argument when the memory allocation was made is invoked on the
-** blob of allocated memory. This function should not call sqliteFree()
+** blob of allocated memory. This function should not call sqlite3_free()
** on the memory, the btree layer does that.
*/
void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
BtShared *pBt = p->pBt;
if( !pBt->pSchema ){
- pBt->pSchema = sqliteMalloc(nBytes);
+ pBt->pSchema = sqlite3MallocZero(nBytes);
pBt->xFreeSchema = xFree;
}
return pBt->pSchema;
** COMMIT
** ROLLBACK
**
-** $Id: build.c,v 1.433 2007/07/02 19:31:27 drh Exp $
+** $Id: build.c,v 1.434 2007/08/16 04:30:39 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
}
nBytes = sizeof(TableLock) * (pParse->nTableLock+1);
- pParse->aTableLock = sqliteReallocOrFree(pParse->aTableLock, nBytes);
+ pParse->aTableLock =
+ sqlite3DbReallocOrFree(pParse->db, pParse->aTableLock, nBytes);
if( pParse->aTableLock ){
p = &pParse->aTableLock[pParse->nTableLock++];
p->iDb = iDb;
sqlite3 *db;
Vdbe *v;
- if( sqlite3MallocFailed() ) return;
+ db = pParse->db;
+ if( db->mallocFailed ) return;
if( pParse->nested ) return;
if( !pParse->pVdbe ){
if( pParse->rc==SQLITE_OK && pParse->nErr ){
/* Begin by generating some termination code at the end of the
** vdbe program
*/
- db = pParse->db;
v = sqlite3GetVdbe(pParse);
if( v ){
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
/* Get the VDBE program ready for execution
*/
- if( v && pParse->nErr==0 && !sqlite3MallocFailed() ){
+ if( v && pParse->nErr==0 && !db->mallocFailed ){
#ifdef SQLITE_DEBUG
FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
sqlite3VdbeTrace(v, trace);
zSql = sqlite3VMPrintf(zFormat, ap);
va_end(ap);
if( zSql==0 ){
+ pParse->db->mallocFailed = 1;
return; /* A malloc must have failed */
}
pParse->nested++;
memcpy(saveBuf, &pParse->nVar, SAVE_SZ);
memset(&pParse->nVar, 0, SAVE_SZ);
sqlite3RunParser(pParse, zSql, 0);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
pParse->nested--;
}
** Reclaim the memory used by an index
*/
static void freeIndex(Index *p){
- sqliteFree(p->zColAff);
- sqliteFree(p);
+ sqlite3_free(p->zColAff);
+ sqlite3_free(p);
}
/*
for(i=j=2; i<db->nDb; i++){
struct Db *pDb = &db->aDb[i];
if( pDb->pBt==0 ){
- sqliteFree(pDb->zName);
+ sqlite3_free(pDb->zName);
pDb->zName = 0;
continue;
}
db->nDb = j;
if( db->nDb<=2 && db->aDb!=db->aDbStatic ){
memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
- sqliteFree(db->aDb);
+ sqlite3_free(db->aDb);
db->aDb = db->aDbStatic;
}
}
assert( pTable!=0 );
if( (pCol = pTable->aCol)!=0 ){
for(i=0; i<pTable->nCol; i++, pCol++){
- sqliteFree(pCol->zName);
+ sqlite3_free(pCol->zName);
sqlite3ExprDelete(pCol->pDflt);
- sqliteFree(pCol->zType);
- sqliteFree(pCol->zColl);
+ sqlite3_free(pCol->zType);
+ sqlite3_free(pCol->zColl);
}
- sqliteFree(pTable->aCol);
+ sqlite3_free(pTable->aCol);
}
pTable->aCol = 0;
pTable->nCol = 0;
pNextFKey = pFKey->pNextFrom;
assert( sqlite3HashFind(&pTable->pSchema->aFKey,
pFKey->zTo, strlen(pFKey->zTo)+1)!=pFKey );
- sqliteFree(pFKey);
+ sqlite3_free(pFKey);
}
#endif
/* Delete the Table structure itself.
*/
sqliteResetColumnNames(pTable);
- sqliteFree(pTable->zName);
- sqliteFree(pTable->zColAff);
+ sqlite3_free(pTable->zName);
+ sqlite3_free(pTable->zColAff);
sqlite3SelectDelete(pTable->pSelect);
#ifndef SQLITE_OMIT_CHECK
sqlite3ExprDelete(pTable->pCheck);
#endif
sqlite3VtabClear(pTable);
- sqliteFree(pTable);
+ sqlite3_free(pTable);
}
/*
** are not \000 terminated and are not persistent. The returned string
** is \000 terminated and is persistent.
*/
-char *sqlite3NameFromToken(Token *pName){
+char *sqlite3NameFromToken(sqlite3 *db, Token *pName){
char *zName;
if( pName ){
- zName = sqliteStrNDup((char*)pName->z, pName->n);
+ zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n);
sqlite3Dequote(zName);
}else{
zName = 0;
Db *pDb; /* A database whose name space is being searched */
char *zName; /* Name we are searching for */
- zName = sqlite3NameFromToken(pName);
+ zName = sqlite3NameFromToken(db, pName);
if( zName ){
n = strlen(zName);
for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
break;
}
}
- sqliteFree(zName);
+ sqlite3_free(zName);
}
return i;
}
if( !OMIT_TEMPDB && isTemp ) iDb = 1;
pParse->sNameToken = *pName;
- zName = sqlite3NameFromToken(pName);
+ zName = sqlite3NameFromToken(db, pName);
if( zName==0 ) return;
if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
goto begin_table_error;
}
}
- pTable = sqliteMalloc( sizeof(Table) );
+ pTable = sqlite3MallocZero( sizeof(Table) );
if( pTable==0 ){
+ db->mallocFailed = 1;
pParse->rc = SQLITE_NOMEM;
pParse->nErr++;
goto begin_table_error;
/* If an error occurs, we jump here */
begin_table_error:
- sqliteFree(zName);
+ sqlite3_free(zName);
return;
}
sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
return;
}
- z = sqlite3NameFromToken(pName);
+ z = sqlite3NameFromToken(pParse->db, pName);
if( z==0 ) return;
for(i=0; i<p->nCol; i++){
if( STRICMP(z, p->aCol[i].zName) ){
sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
- sqliteFree(z);
+ sqlite3_free(z);
return;
}
}
if( (p->nCol & 0x7)==0 ){
Column *aNew;
- aNew = sqliteRealloc( p->aCol, (p->nCol+8)*sizeof(p->aCol[0]));
+ aNew = sqlite3_realloc( p->aCol, (p->nCol+8)*sizeof(p->aCol[0]));
if( aNew==0 ){
- sqliteFree(z);
+ pParse->db->mallocFailed = 1;
+ sqlite3_free(z);
return;
}
p->aCol = aNew;
i = p->nCol-1;
if( i<0 ) return;
pCol = &p->aCol[i];
- sqliteFree(pCol->zType);
- pCol->zType = sqlite3NameFromToken(pType);
+ sqlite3_free(pCol->zType);
+ pCol->zType = sqlite3NameFromToken(pParse->db, pType);
pCol->affinity = sqlite3AffinityType(pType);
}
pCol->zName);
}else{
Expr *pCopy;
+ sqlite3 *db = pParse->db;
sqlite3ExprDelete(pCol->pDflt);
- pCol->pDflt = pCopy = sqlite3ExprDup(pExpr);
+ pCol->pDflt = pCopy = sqlite3ExprDup(db, pExpr);
if( pCopy ){
- sqlite3TokenCopy(&pCopy->span, &pExpr->span);
+ sqlite3TokenCopy(db, &pCopy->span, &pExpr->span);
}
}
}
){
#ifndef SQLITE_OMIT_CHECK
Table *pTab = pParse->pNewTable;
+ sqlite3 *db = pParse->db;
if( pTab && !IN_DECLARE_VTAB ){
/* The CHECK expression must be duplicated so that tokens refer
** to malloced space and not the (ephemeral) text of the CREATE TABLE
** statement */
- pTab->pCheck = sqlite3ExprAnd(pTab->pCheck, sqlite3ExprDup(pCheckExpr));
+ pTab->pCheck = sqlite3ExprAnd(db, pTab->pCheck,
+ sqlite3ExprDup(db, pCheckExpr));
}
#endif
sqlite3ExprDelete(pCheckExpr);
if( sqlite3LocateCollSeq(pParse, zType, nType) ){
Index *pIdx;
- p->aCol[i].zColl = sqliteStrNDup(zType, nType);
+ p->aCol[i].zColl = sqlite3DbStrNDup(pParse->db, zType, nType);
/* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
** then an index may have been created on this column before the
zEnd = "\n)";
}
n += 35 + 6*p->nCol;
- zStmt = sqliteMallocRaw( n );
+ zStmt = sqlite3_malloc( n );
if( zStmt==0 ) return 0;
sqlite3_snprintf(n, zStmt,
!OMIT_TEMPDB&&isTemp ? "CREATE TEMP TABLE ":"CREATE TABLE ");
sqlite3 *db = pParse->db;
int iDb;
- if( (pEnd==0 && pSelect==0) || pParse->nErr || sqlite3MallocFailed() ) {
+ if( (pEnd==0 && pSelect==0) || pParse->nErr || db->mallocFailed ) {
return;
}
p = pParse->pNewTable;
p->zName,
zStmt
);
- sqliteFree(zStmt);
+ sqlite3_free(zStmt);
sqlite3ChangeCookie(db, v, iDb);
#ifndef SQLITE_OMIT_AUTOINCREMENT
pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, strlen(p->zName)+1,p);
if( pOld ){
assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
+ db->mallocFailed = 1;
return;
}
#ifndef SQLITE_OMIT_FOREIGN_KEY
DbFixer sFix;
Token *pName;
int iDb;
+ sqlite3 *db = pParse->db;
if( pParse->nVar>0 ){
sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
return;
}
sqlite3TwoPartName(pParse, pName1, pName2, &pName);
- iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
+ iDb = sqlite3SchemaToIndex(db, p->pSchema);
if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName)
&& sqlite3FixSelect(&sFix, pSelect)
){
** allocated rather than point to the input string - which means that
** they will persist after the current sqlite3_exec() call returns.
*/
- p->pSelect = sqlite3SelectDup(pSelect);
+ p->pSelect = sqlite3SelectDup(db, pSelect);
sqlite3SelectDelete(pSelect);
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
return;
}
- if( !pParse->db->init.busy ){
+ if( !db->init.busy ){
sqlite3ViewGetColumnNames(pParse, p);
}
Select *pSel; /* Copy of the SELECT that implements the view */
int nErr = 0; /* Number of errors encountered */
int n; /* Temporarily holds the number of cursors assigned */
+ sqlite3 *db = pParse->db; /* Database connection for malloc errors */
assert( pTable );
** statement that defines the view.
*/
assert( pTable->pSelect );
- pSel = sqlite3SelectDup(pTable->pSelect);
+ pSel = sqlite3SelectDup(db, pTable->pSelect);
if( pSel ){
n = pParse->nTab;
sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
sqlite3 *db = pParse->db;
int iDb;
- if( pParse->nErr || sqlite3MallocFailed() ){
+ if( pParse->nErr || db->mallocFailed ){
goto exit_drop_table;
}
assert( pName->nSrc==1 );
nByte += strlen(pToCol->a[i].zName) + 1;
}
}
- pFKey = sqliteMalloc( nByte );
- if( pFKey==0 ) goto fk_end;
+ pFKey = sqlite3DbMallocZero(pParse->db, nByte );
+ if( pFKey==0 ){
+ goto fk_end;
+ }
pFKey->pFrom = p;
pFKey->pNextFrom = p->pFKey;
z = (char*)&pFKey[1];
pFKey = 0;
fk_end:
- sqliteFree(pFKey);
+ sqlite3_free(pFKey);
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
sqlite3ExprListDelete(pFromCol);
sqlite3ExprListDelete(pToCol);
int tnum; /* Root page of index */
Vdbe *v; /* Generate code into this virtual machine */
KeyInfo *pKey; /* KeyInfo for index */
- int iDb = sqlite3SchemaToIndex(pParse->db, pIndex->pSchema);
+ sqlite3 *db = pParse->db; /* The database connection */
+ int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
#ifndef SQLITE_OMIT_AUTHORIZATION
if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
- pParse->db->aDb[iDb].zName ) ){
+ db->aDb[iDb].zName ) ){
return;
}
#endif
sqlite3VdbeAddOp(v, OP_IsUnique, iIdx, addr2);
sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort,
"indexed columns are not unique", P3_STATIC);
- assert( sqlite3MallocFailed() || addr2==sqlite3VdbeCurrentAddr(v) );
+ assert( db->mallocFailed || addr2==sqlite3VdbeCurrentAddr(v) );
}
sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, 0);
sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1);
int nExtra = 0;
char *zExtra;
- if( pParse->nErr || sqlite3MallocFailed() || IN_DECLARE_VTAB ){
+ if( pParse->nErr || db->mallocFailed || IN_DECLARE_VTAB ){
goto exit_create_index;
}
** own name.
*/
if( pName ){
- zName = sqlite3NameFromToken(pName);
+ zName = sqlite3NameFromToken(db, pName);
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
if( zName==0 ) goto exit_create_index;
if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
*/
nName = strlen(zName);
nCol = pList->nExpr;
- pIndex = sqliteMalloc(
+ pIndex = sqlite3DbMallocZero(db,
sizeof(Index) + /* Index structure */
sizeof(int)*nCol + /* Index.aiColumn */
sizeof(int)*(nCol+1) + /* Index.aiRowEst */
nName + 1 + /* Index.zName */
nExtra /* Collation sequence names */
);
- if( sqlite3MallocFailed() ) goto exit_create_index;
+ if( db->mallocFailed ){
+ goto exit_create_index;
+ }
pIndex->azColl = (char**)(&pIndex[1]);
pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]);
pIndex->aiRowEst = (unsigned *)(&pIndex->aiColumn[nCol]);
pIndex->zName, strlen(pIndex->zName)+1, pIndex);
if( p ){
assert( p==pIndex ); /* Malloc must have failed */
+ db->mallocFailed = 1;
goto exit_create_index;
}
db->flags |= SQLITE_InternChanges;
zStmt
);
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
- sqliteFree(zStmt);
+ sqlite3_free(zStmt);
/* Fill the index with data and reparse the schema. Code an OP_Expire
** to invalidate all pre-compiled statements.
}
sqlite3ExprListDelete(pList);
sqlite3SrcListDelete(pTblName);
- sqliteFree(zName);
+ sqlite3_free(zName);
return;
}
sqlite3 *db = pParse->db;
int iDb;
- if( pParse->nErr || sqlite3MallocFailed() ){
+ if( pParse->nErr || db->mallocFailed ){
goto exit_drop_index;
}
assert( pName->nSrc==1 );
** pointer if the array was resized.
*/
void *sqlite3ArrayAllocate(
+ sqlite3 *db, /* Connection to notify of malloc failures */
void *pArray, /* Array of objects. Might be reallocated */
int szEntry, /* Size of each object in the array */
int initSize, /* Suggested initial allocation, in elements */
void *pNew;
int newSize;
newSize = (*pnAlloc)*2 + initSize;
- pNew = sqliteRealloc(pArray, newSize*szEntry);
+ pNew = sqlite3_realloc(pArray, newSize*szEntry);
if( pNew==0 ){
+ db->mallocFailed = 1;
*pIdx = -1;
return pArray;
}
**
** A new IdList is returned, or NULL if malloc() fails.
*/
-IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){
+IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
int i;
if( pList==0 ){
- pList = sqliteMalloc( sizeof(IdList) );
+ pList = sqlite3DbMallocZero(db, sizeof(IdList) );
if( pList==0 ) return 0;
pList->nAlloc = 0;
}
pList->a = sqlite3ArrayAllocate(
+ db,
pList->a,
sizeof(pList->a[0]),
5,
sqlite3IdListDelete(pList);
return 0;
}
- pList->a[i].zName = sqlite3NameFromToken(pToken);
+ pList->a[i].zName = sqlite3NameFromToken(db, pToken);
return pList;
}
int i;
if( pList==0 ) return;
for(i=0; i<pList->nId; i++){
- sqliteFree(pList->a[i].zName);
+ sqlite3_free(pList->a[i].zName);
}
- sqliteFree(pList->a);
- sqliteFree(pList);
+ sqlite3_free(pList->a);
+ sqlite3_free(pList);
}
/*
**
** In other words, if call like this:
**
-** sqlite3SrcListAppend(A,B,0);
+** sqlite3SrcListAppend(D,A,B,0);
**
** Then B is a table name and the database name is unspecified. If called
** like this:
**
-** sqlite3SrcListAppend(A,B,C);
+** sqlite3SrcListAppend(D,A,B,C);
**
** Then C is the table name and B is the database name.
*/
-SrcList *sqlite3SrcListAppend(SrcList *pList, Token *pTable, Token *pDatabase){
+SrcList *sqlite3SrcListAppend(
+ sqlite3 *db, /* Connection to notify of malloc failures */
+ SrcList *pList, /* Append to this SrcList. NULL creates a new SrcList */
+ Token *pTable, /* Table to append */
+ Token *pDatabase /* Database of the table */
+){
struct SrcList_item *pItem;
if( pList==0 ){
- pList = sqliteMalloc( sizeof(SrcList) );
+ pList = sqlite3DbMallocZero(db, sizeof(SrcList) );
if( pList==0 ) return 0;
pList->nAlloc = 1;
}
if( pList->nSrc>=pList->nAlloc ){
SrcList *pNew;
pList->nAlloc *= 2;
- pNew = sqliteRealloc(pList,
+ pNew = sqlite3_realloc(pList,
sizeof(*pList) + (pList->nAlloc-1)*sizeof(pList->a[0]) );
if( pNew==0 ){
+ db->mallocFailed = 1;
sqlite3SrcListDelete(pList);
return 0;
}
pDatabase = pTable;
pTable = pTemp;
}
- pItem->zName = sqlite3NameFromToken(pTable);
- pItem->zDatabase = sqlite3NameFromToken(pDatabase);
+ pItem->zName = sqlite3NameFromToken(db, pTable);
+ pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
pItem->iCursor = -1;
pItem->isPopulated = 0;
pList->nSrc++;
void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
int i;
struct SrcList_item *pItem;
- assert(pList || sqlite3MallocFailed() );
+ assert(pList || pParse->db->mallocFailed );
if( pList ){
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
if( pItem->iCursor>=0 ) break;
struct SrcList_item *pItem;
if( pList==0 ) return;
for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
- sqliteFree(pItem->zDatabase);
- sqliteFree(pItem->zName);
- sqliteFree(pItem->zAlias);
+ sqlite3_free(pItem->zDatabase);
+ sqlite3_free(pItem->zName);
+ sqlite3_free(pItem->zAlias);
sqlite3DeleteTable(pItem->pTab);
sqlite3SelectDelete(pItem->pSelect);
sqlite3ExprDelete(pItem->pOn);
sqlite3IdListDelete(pItem->pUsing);
}
- sqliteFree(pList);
+ sqlite3_free(pList);
}
/*
** term added.
*/
SrcList *sqlite3SrcListAppendFromTerm(
+ Parse *pParse, /* Parsing context */
SrcList *p, /* The left part of the FROM clause already seen */
Token *pTable, /* Name of the table to add to the FROM clause */
Token *pDatabase, /* Name of the database containing pTable */
IdList *pUsing /* The USING clause of a join */
){
struct SrcList_item *pItem;
- p = sqlite3SrcListAppend(p, pTable, pDatabase);
+ sqlite3 *db = pParse->db;
+ p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
if( p==0 || p->nSrc==0 ){
sqlite3ExprDelete(pOn);
sqlite3IdListDelete(pUsing);
}
pItem = &p->a[p->nSrc-1];
if( pAlias && pAlias->n ){
- pItem->zAlias = sqlite3NameFromToken(pAlias);
+ pItem->zAlias = sqlite3NameFromToken(db, pAlias);
}
pItem->pSelect = pSubquery;
pItem->pOn = pOn;
int i;
if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return;
- if( pParse->nErr || sqlite3MallocFailed() ) return;
+ if( pParse->nErr || db->mallocFailed ) return;
if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ) return;
v = sqlite3GetVdbe(pParse);
Vdbe *v;
if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return;
- if( pParse->nErr || sqlite3MallocFailed() ) return;
+ if( pParse->nErr || db->mallocFailed ) return;
if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ) return;
v = sqlite3GetVdbe(pParse);
Vdbe *v;
if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return;
- if( pParse->nErr || sqlite3MallocFailed() ) return;
+ if( pParse->nErr || db->mallocFailed ) return;
if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ) return;
v = sqlite3GetVdbe(pParse);
assert( pName1->z );
pColl = sqlite3FindCollSeq(db, ENC(db), (char*)pName1->z, pName1->n, 0);
if( pColl ){
- char *zColl = sqliteStrNDup((const char *)pName1->z, pName1->n);
+ char *zColl = sqlite3DbStrNDup(db, (const char *)pName1->z, pName1->n);
if( zColl ){
reindexDatabases(pParse, zColl);
- sqliteFree(zColl);
+ sqlite3_free(zColl);
}
return;
}
}
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
if( iDb<0 ) return;
- z = sqlite3NameFromToken(pObjName);
+ z = sqlite3NameFromToken(db, pObjName);
if( z==0 ) return;
zDb = db->aDb[iDb].zName;
pTab = sqlite3FindTable(db, z, zDb);
if( pTab ){
reindexTable(pParse, pTab, 0);
- sqliteFree(z);
+ sqlite3_free(z);
return;
}
pIndex = sqlite3FindIndex(db, z, zDb);
- sqliteFree(z);
+ sqlite3_free(z);
if( pIndex ){
sqlite3BeginWriteOperation(pParse, 0, iDb);
sqlite3RefillIndex(pParse, pIndex, -1);
** with OP_OpenRead or OP_OpenWrite to access database index pIdx.
**
** If successful, a pointer to the new structure is returned. In this case
-** the caller is responsible for calling sqliteFree() on the returned
+** the caller is responsible for calling sqlite3_free() on the returned
** pointer. If an error occurs (out of memory or missing collation
** sequence), NULL is returned and the state of pParse updated to reflect
** the error.
int i;
int nCol = pIdx->nColumn;
int nBytes = sizeof(KeyInfo) + (nCol-1)*sizeof(CollSeq*) + nCol;
- KeyInfo *pKey = (KeyInfo *)sqliteMalloc(nBytes);
+ KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZer(pParse->db, nBytes);
if( pKey ){
pKey->aSortOrder = (u8 *)&(pKey->aColl[nCol]);
}
if( pParse->nErr ){
- sqliteFree(pKey);
+ sqlite3_free(pKey);
pKey = 0;
}
return pKey;
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
-** $Id: callback.c,v 1.18 2007/05/07 09:32:45 danielk1977 Exp $
+** $Id: callback.c,v 1.19 2007/08/16 04:30:39 drh Exp $
*/
#include "sqliteInt.h"
assert( !db->xCollNeeded || !db->xCollNeeded16 );
if( nName<0 ) nName = strlen(zName);
if( db->xCollNeeded ){
- char *zExternal = sqliteStrNDup(zName, nName);
+ char *zExternal = sqlite3DbStrNDup(db, zName, nName);
if( !zExternal ) return;
db->xCollNeeded(db->pCollNeededArg, db, (int)ENC(db), zExternal);
- sqliteFree(zExternal);
+ sqlite3_free(zExternal);
}
#ifndef SQLITE_OMIT_UTF16
if( db->xCollNeeded16 ){
pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
if( 0==pColl && create ){
- pColl = sqliteMalloc( 3*sizeof(*pColl) + nName + 1 );
+ pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 );
if( pColl ){
CollSeq *pDel = 0;
pColl[0].zName = (char*)&pColl[3];
** return the pColl pointer to be deleted (because it wasn't added
** to the hash table).
*/
- assert( !pDel || (sqlite3MallocFailed() && pDel==pColl) );
+ assert( !pDel || (db->mallocFailed && pDel==pColl) );
if( pDel ){
- sqliteFree(pDel);
+ sqlite3_free(pDel);
pColl = 0;
}
}
** new entry to the hash table and return it.
*/
if( createFlag && bestmatch<6 &&
- (pBest = sqliteMalloc(sizeof(*pBest)+nName))!=0 ){
+ (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName))!=0 ){
pBest->nArg = nArg;
pBest->pNext = pFirst;
pBest->iPrefEnc = enc;
memcpy(pBest->zName, zName, nName);
pBest->zName[nName] = 0;
if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){
- sqliteFree(pBest);
+ sqlite3_free(pBest);
return 0;
}
}
/*
** Free all resources held by the schema structure. The void* argument points
-** at a Schema struct. This function does not call sqliteFree() on the
+** at a Schema struct. This function does not call sqlite3_free() on the
** pointer itself, it just cleans up subsiduary resources (i.e. the contents
** of the schema hash tables).
*/
** Find and return the schema associated with a BTree. Create
** a new one if necessary.
*/
-Schema *sqlite3SchemaGet(Btree *pBt){
+Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
Schema * p;
if( pBt ){
p = (Schema *)sqlite3BtreeSchema(pBt,sizeof(Schema),sqlite3SchemaFree);
}else{
- p = (Schema *)sqliteMalloc(sizeof(Schema));
+ p = (Schema *)sqlite3DbMallocZero(db,sizeof(Schema));
}
if( p && 0==p->file_format ){
sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0);
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: date.c,v 1.66 2007/05/08 21:56:00 drh Exp $
+** $Id: date.c,v 1.67 2007/08/16 04:30:40 drh Exp $
**
** SQLite processes all times and dates as Julian Day numbers. The
** dates and times are stored as the number of days since noon
sqlite3_result_error_toobig(context);
return;
}else{
- z = sqliteMalloc( n );
+ z = sqlite3_malloc( n );
if( z==0 ) return;
}
computeJD(&x);
z[j] = 0;
sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
if( z!=zBuf ){
- sqliteFree(z);
+ sqlite3_free(z);
}
}
** This file contains C code routines that are called by the parser
** in order to generate code for DELETE FROM statements.
**
-** $Id: delete.c,v 1.129 2007/04/16 15:06:25 danielk1977 Exp $
+** $Id: delete.c,v 1.130 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#endif
sContext.pParse = 0;
- if( pParse->nErr || sqlite3MallocFailed() ){
+ db = pParse->db;
+ if( pParse->nErr || db->mallocFailed ){
goto delete_from_cleanup;
}
- db = pParse->db;
assert( pTabList->nSrc==1 );
/* Locate the table which we want to delete. This table has to be
** a ephemeral table.
*/
if( isView ){
- Select *pView = sqlite3SelectDup(pTab->pSelect);
+ Select *pView = sqlite3SelectDup(db, pTab->pSelect);
sqlite3Select(pParse, pView, SRT_EphemTab, iCur, 0, 0, 0, 0);
sqlite3SelectDelete(pView);
}
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
-** $Id: expr.c,v 1.303 2007/08/07 17:13:04 drh Exp $
+** $Id: expr.c,v 1.304 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/*
** Construct a new expression node and return a pointer to it. Memory
-** for this node is obtained from sqliteMalloc(). The calling function
+** for this node is obtained from sqlite3_malloc(). The calling function
** is responsible for making sure the node eventually gets freed.
*/
-Expr *sqlite3Expr(int op, Expr *pLeft, Expr *pRight, const Token *pToken){
+Expr *sqlite3Expr(
+ int op, /* Expression opcode */
+ Expr *pLeft, /* Left operand */
+ Expr *pRight, /* Right operand */
+ const Token *pToken /* Argument token */
+){
Expr *pNew;
- pNew = sqliteMalloc( sizeof(Expr) );
+ pNew = sqlite3MallocZero( sizeof(Expr) );
if( pNew==0 ){
/* When malloc fails, delete pLeft and pRight. Expressions passed to
** this function must always be allocated with sqlite3Expr() for this
}
/*
-** Works like sqlite3Expr() but frees its pLeft and pRight arguments
-** if it fails due to a malloc problem.
+** Works like sqlite3Expr() except that it takes an extra Parse*
+** argument and notifies the associated connection object if malloc fails.
*/
-Expr *sqlite3ExprOrFree(int op, Expr *pLeft, Expr *pRight, const Token *pToken){
+Expr *sqlite3PExpr(
+ Parse *pParse, /* Parsing context */
+ int op, /* Expression opcode */
+ Expr *pLeft, /* Left operand */
+ Expr *pRight, /* Right operand */
+ const Token *pToken /* Argument token */
+){
Expr *pNew = sqlite3Expr(op, pLeft, pRight, pToken);
if( pNew==0 ){
sqlite3ExprDelete(pLeft);
sqlite3ExprDelete(pRight);
+ pParse->db->mallocFailed = 1;
}
return pNew;
}
if( v==0 ) return 0;
p = sqlite3Expr(TK_REGISTER, 0, 0, pToken);
if( p==0 ){
+ pParse->db->mallocFailed = 1;
return 0; /* Malloc failed */
}
depth = atoi((char*)&pToken->z[1]);
** Join two expressions using an AND operator. If either expression is
** NULL, then just return the other expression.
*/
-Expr *sqlite3ExprAnd(Expr *pLeft, Expr *pRight){
+Expr *sqlite3ExprAnd(sqlite *db, Expr *pLeft, Expr *pRight){
if( pLeft==0 ){
return pRight;
}else if( pRight==0 ){
return pLeft;
}else{
- return sqlite3Expr(TK_AND, pLeft, pRight, 0);
+ Expr *p = sqlite3Expr(TK_AND, pLeft, pRight, 0);
+ if( p==0 ){
+ db->mallocFailed = 1;
+ }
}
}
void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
assert( pRight!=0 );
assert( pLeft!=0 );
- if( !sqlite3MallocFailed() && pRight->z && pLeft->z ){
+ if( pRight->z && pLeft->z ){
assert( pLeft->dyn==0 || pLeft->z[pLeft->n]==0 );
if( pLeft->dyn==0 && pRight->dyn==0 ){
pExpr->span.z = pLeft->z;
** Construct a new expression node for a function with multiple
** arguments.
*/
-Expr *sqlite3ExprFunction(ExprList *pList, Token *pToken){
+Expr *sqlite3ExprFunction(Parse *pParse, ExprList *pList, Token *pToken){
Expr *pNew;
assert( pToken );
- pNew = sqliteMalloc( sizeof(Expr) );
+ pNew = sqlite3DbMallocZero(pParse->db, sizeof(Expr) );
if( pNew==0 ){
sqlite3ExprListDelete(pList); /* Avoid leaking memory when malloc fails */
return 0;
*/
void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
Token *pToken;
+ sqlite3 *db = pParse->db;
+
if( pExpr==0 ) return;
pToken = &pExpr->token;
assert( pToken->n>=1 );
pExpr->iTable = ++pParse->nVar;
if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
- pParse->apVarExpr = sqliteReallocOrFree(pParse->apVarExpr,
- pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) );
+ pParse->apVarExpr =
+ sqlite3DbReallocOrFree(
+ db,
+ pParse->apVarExpr,
+ pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0])
+ );
}
- if( !sqlite3MallocFailed() ){
+ if( !db->mallocFailed ){
assert( pParse->apVarExpr!=0 );
pParse->apVarExpr[pParse->nVarExpr++] = pExpr;
}
*/
void sqlite3ExprDelete(Expr *p){
if( p==0 ) return;
- if( p->span.dyn ) sqliteFree((char*)p->span.z);
- if( p->token.dyn ) sqliteFree((char*)p->token.z);
+ if( p->span.dyn ) sqlite3_free((char*)p->span.z);
+ if( p->token.dyn ) sqlite3_free((char*)p->token.z);
sqlite3ExprDelete(p->pLeft);
sqlite3ExprDelete(p->pRight);
sqlite3ExprListDelete(p->pList);
sqlite3SelectDelete(p->pSelect);
- sqliteFree(p);
+ sqlite3_free(p);
}
/*
** The Expr.token field might be a string literal that is quoted.
** If so, remove the quotation marks.
*/
-void sqlite3DequoteExpr(Expr *p){
+void sqlite3DequoteExpr(sqlite3 *db, Expr *p){
if( ExprHasAnyProperty(p, EP_Dequoted) ){
return;
}
ExprSetProperty(p, EP_Dequoted);
if( p->token.dyn==0 ){
- sqlite3TokenCopy(&p->token, &p->token);
+ sqlite3TokenCopy(db, &p->token, &p->token);
}
sqlite3Dequote((char*)p->token.z);
}
**
** Any tables that the SrcList might point to are not duplicated.
*/
-Expr *sqlite3ExprDup(Expr *p){
+Expr *sqlite3ExprDup(sqlite *db, Expr *p){
Expr *pNew;
if( p==0 ) return 0;
- pNew = sqliteMallocRaw( sizeof(*p) );
+ pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
if( pNew==0 ) return 0;
memcpy(pNew, p, sizeof(*pNew));
if( p->token.z!=0 ){
- pNew->token.z = (u8*)sqliteStrNDup((char*)p->token.z, p->token.n);
+ pNew->token.z = (u8*)sqlite3DbStrNDup(db, (char*)p->token.z, p->token.n);
pNew->token.dyn = 1;
}else{
assert( pNew->token.z==0 );
}
pNew->span.z = 0;
- pNew->pLeft = sqlite3ExprDup(p->pLeft);
- pNew->pRight = sqlite3ExprDup(p->pRight);
- pNew->pList = sqlite3ExprListDup(p->pList);
- pNew->pSelect = sqlite3SelectDup(p->pSelect);
+ pNew->pLeft = sqlite3ExprDup(db, p->pLeft);
+ pNew->pRight = sqlite3ExprDup(db, p->pRight);
+ pNew->pList = sqlite3ExprListDup(db, p->pList);
+ pNew->pSelect = sqlite3SelectDup(db, p->pSelect);
return pNew;
}
-void sqlite3TokenCopy(Token *pTo, Token *pFrom){
- if( pTo->dyn ) sqliteFree((char*)pTo->z);
+void sqlite3TokenCopy(sqlite3 *db, Token *pTo, Token *pFrom){
+ if( pTo->dyn ) sqlite3_free((char*)pTo->z);
if( pFrom->z ){
pTo->n = pFrom->n;
- pTo->z = (u8*)sqliteStrNDup((char*)pFrom->z, pFrom->n);
+ pTo->z = (u8*)sqlite3DbStrNDup(db, (char*)pFrom->z, pFrom->n);
pTo->dyn = 1;
}else{
pTo->z = 0;
}
}
-ExprList *sqlite3ExprListDup(ExprList *p){
+ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p){
ExprList *pNew;
struct ExprList_item *pItem, *pOldItem;
int i;
if( p==0 ) return 0;
- pNew = sqliteMalloc( sizeof(*pNew) );
+ pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
if( pNew==0 ) return 0;
pNew->nExpr = pNew->nAlloc = p->nExpr;
- pNew->a = pItem = sqliteMalloc( p->nExpr*sizeof(p->a[0]) );
+ pNew->a = pItem = sqlite3DbMallocRaw(db, p->nExpr*sizeof(p->a[0]) );
if( pItem==0 ){
- sqliteFree(pNew);
+ sqlite3_free(pNew);
return 0;
}
pOldItem = p->a;
for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
Expr *pNewExpr, *pOldExpr;
- pItem->pExpr = pNewExpr = sqlite3ExprDup(pOldExpr = pOldItem->pExpr);
+ pItem->pExpr = pNewExpr = sqlite3ExprDup(db, pOldExpr = pOldItem->pExpr);
if( pOldExpr->span.z!=0 && pNewExpr ){
/* Always make a copy of the span for top-level expressions in the
** expression list. The logic in SELECT processing that determines
** the names of columns in the result set needs this information */
- sqlite3TokenCopy(&pNewExpr->span, &pOldExpr->span);
+ sqlite3TokenCopy(db, &pNewExpr->span, &pOldExpr->span);
}
assert( pNewExpr==0 || pNewExpr->span.z!=0
|| pOldExpr->span.z==0
- || sqlite3MallocFailed() );
- pItem->zName = sqliteStrDup(pOldItem->zName);
+ || db->mallocFailed );
+ pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
pItem->sortOrder = pOldItem->sortOrder;
pItem->isAgg = pOldItem->isAgg;
pItem->done = 0;
*/
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) \
|| !defined(SQLITE_OMIT_SUBQUERY)
-SrcList *sqlite3SrcListDup(SrcList *p){
+SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p){
SrcList *pNew;
int i;
int nByte;
if( p==0 ) return 0;
nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0);
- pNew = sqliteMallocRaw( nByte );
+ pNew = sqlite3DbMallocRaw(db, nByte );
if( pNew==0 ) return 0;
pNew->nSrc = pNew->nAlloc = p->nSrc;
for(i=0; i<p->nSrc; i++){
struct SrcList_item *pNewItem = &pNew->a[i];
struct SrcList_item *pOldItem = &p->a[i];
Table *pTab;
- pNewItem->zDatabase = sqliteStrDup(pOldItem->zDatabase);
- pNewItem->zName = sqliteStrDup(pOldItem->zName);
- pNewItem->zAlias = sqliteStrDup(pOldItem->zAlias);
+ pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
+ pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
+ pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
pNewItem->jointype = pOldItem->jointype;
pNewItem->iCursor = pOldItem->iCursor;
pNewItem->isPopulated = pOldItem->isPopulated;
if( pTab ){
pTab->nRef++;
}
- pNewItem->pSelect = sqlite3SelectDup(pOldItem->pSelect);
- pNewItem->pOn = sqlite3ExprDup(pOldItem->pOn);
- pNewItem->pUsing = sqlite3IdListDup(pOldItem->pUsing);
+ pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect);
+ pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn);
+ pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
pNewItem->colUsed = pOldItem->colUsed;
}
return pNew;
}
-IdList *sqlite3IdListDup(IdList *p){
+IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
IdList *pNew;
int i;
if( p==0 ) return 0;
- pNew = sqliteMallocRaw( sizeof(*pNew) );
+ pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
if( pNew==0 ) return 0;
pNew->nId = pNew->nAlloc = p->nId;
- pNew->a = sqliteMallocRaw( p->nId*sizeof(p->a[0]) );
+ pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
if( pNew->a==0 ){
- sqliteFree(pNew);
+ sqlite3_free(pNew);
return 0;
}
for(i=0; i<p->nId; i++){
struct IdList_item *pNewItem = &pNew->a[i];
struct IdList_item *pOldItem = &p->a[i];
- pNewItem->zName = sqliteStrDup(pOldItem->zName);
+ pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
pNewItem->idx = pOldItem->idx;
}
return pNew;
}
-Select *sqlite3SelectDup(Select *p){
+Select *sqlite3SelectDup(sqlite3 *db, Select *p){
Select *pNew;
if( p==0 ) return 0;
- pNew = sqliteMallocRaw( sizeof(*p) );
+ pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
if( pNew==0 ) return 0;
pNew->isDistinct = p->isDistinct;
- pNew->pEList = sqlite3ExprListDup(p->pEList);
- pNew->pSrc = sqlite3SrcListDup(p->pSrc);
- pNew->pWhere = sqlite3ExprDup(p->pWhere);
- pNew->pGroupBy = sqlite3ExprListDup(p->pGroupBy);
- pNew->pHaving = sqlite3ExprDup(p->pHaving);
- pNew->pOrderBy = sqlite3ExprListDup(p->pOrderBy);
+ pNew->pEList = sqlite3ExprListDup(db, p->pEList);
+ pNew->pSrc = sqlite3SrcListDup(db, p->pSrc);
+ pNew->pWhere = sqlite3ExprDup(db, p->pWhere);
+ pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy);
+ pNew->pHaving = sqlite3ExprDup(db, p->pHaving);
+ pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy);
pNew->op = p->op;
- pNew->pPrior = sqlite3SelectDup(p->pPrior);
- pNew->pLimit = sqlite3ExprDup(p->pLimit);
- pNew->pOffset = sqlite3ExprDup(p->pOffset);
+ pNew->pPrior = sqlite3SelectDup(db, p->pPrior);
+ pNew->pLimit = sqlite3ExprDup(db, p->pLimit);
+ pNew->pOffset = sqlite3ExprDup(db, p->pOffset);
pNew->iLimit = -1;
pNew->iOffset = -1;
pNew->isResolved = p->isResolved;
return pNew;
}
#else
-Select *sqlite3SelectDup(Select *p){
+Select *sqlite3SelectDup(sqlite3 *db, Select *p){
assert( p==0 );
return 0;
}
** Add a new element to the end of an expression list. If pList is
** initially NULL, then create a new expression list.
*/
-ExprList *sqlite3ExprListAppend(ExprList *pList, Expr *pExpr, Token *pName){
+ExprList *sqlite3ExprListAppend(
+ Parse *pParse, /* Parsing context */
+ ExprList *pList, /* List to which to append. Might be NULL */
+ Expr *pExpr, /* Expression to be appended */
+ Token *pName /* AS keyword for the expression */
+){
+ sqlite3 *db = pParse->db;
if( pList==0 ){
- pList = sqliteMalloc( sizeof(ExprList) );
+ pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
if( pList==0 ){
goto no_mem;
}
if( pList->nAlloc<=pList->nExpr ){
struct ExprList_item *a;
int n = pList->nAlloc*2 + 4;
- a = sqliteRealloc(pList->a, n*sizeof(pList->a[0]));
+ a = sqlite3_realloc(pList->a, n*sizeof(pList->a[0]));
if( a==0 ){
goto no_mem;
}
if( pExpr || pName ){
struct ExprList_item *pItem = &pList->a[pList->nExpr++];
memset(pItem, 0, sizeof(*pItem));
- pItem->zName = sqlite3NameFromToken(pName);
+ pItem->zName = sqlite3NameFromToken(db, pName);
pItem->pExpr = pExpr;
}
return pList;
no_mem:
/* Avoid leaking memory if malloc has failed. */
+ db->mallocFailed = 1;
sqlite3ExprDelete(pExpr);
sqlite3ExprListDelete(pList);
return 0;
assert( pList->nExpr<=pList->nAlloc );
for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
sqlite3ExprDelete(pItem->pExpr);
- sqliteFree(pItem->zName);
+ sqlite3_free(pItem->zName);
}
- sqliteFree(pList->a);
- sqliteFree(pList);
+ sqlite3_free(pList->a);
+ sqlite3_free(pList);
}
/*
NameContext *pTopNC = pNC; /* First namecontext in the list */
assert( pColumnToken && pColumnToken->z ); /* The Z in X.Y.Z cannot be NULL */
- zDb = sqlite3NameFromToken(pDbToken);
- zTab = sqlite3NameFromToken(pTableToken);
- zCol = sqlite3NameFromToken(pColumnToken);
- if( sqlite3MallocFailed() ){
+ zDb = sqlite3NameFromToken(db, pDbToken);
+ zTab = sqlite3NameFromToken(db, pTableToken);
+ zCol = sqlite3NameFromToken(db, pColumnToken);
+ if( db->mallocFailed ){
goto lookupname_end;
}
pOrig = pEList->a[j].pExpr;
if( !pNC->allowAgg && ExprHasProperty(pOrig, EP_Agg) ){
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
- sqliteFree(zCol);
+ sqlite3_free(zCol);
return 2;
}
pDup = sqlite3ExprDup(pOrig);
pDup->pColl = pExpr->pColl;
pDup->flags |= EP_ExpCollate;
}
- if( pExpr->span.dyn ) sqliteFree((char*)pExpr->span.z);
- if( pExpr->token.dyn ) sqliteFree((char*)pExpr->token.z);
+ if( pExpr->span.dyn ) sqlite3_free((char*)pExpr->span.z);
+ if( pExpr->token.dyn ) sqlite3_free((char*)pExpr->token.z);
memcpy(pExpr, pDup, sizeof(*pExpr));
- sqliteFree(pDup);
+ sqlite3_free(pDup);
cnt = 1;
pMatch = 0;
assert( zTab==0 && zDb==0 );
** fields are not changed in any context.
*/
if( cnt==0 && zTab==0 && pColumnToken->z[0]=='"' ){
- sqliteFree(zCol);
+ sqlite3_free(zCol);
return 0;
}
}else if( zTab ){
sqlite3SetString(&z, zTab, ".", zCol, (char*)0);
}else{
- z = sqliteStrDup(zCol);
+ z = sqlite3StrDup(zCol);
}
sqlite3ErrorMsg(pParse, zErr, z);
- sqliteFree(z);
+ sqlite3_free(z);
pTopNC->nErr++;
}
lookupname_end:
/* Clean up and return
*/
- sqliteFree(zDb);
- sqliteFree(zTab);
+ sqlite3_free(zDb);
+ sqlite3_free(zTab);
sqlite3ExprDelete(pExpr->pLeft);
pExpr->pLeft = 0;
sqlite3ExprDelete(pExpr->pRight);
pExpr->pRight = 0;
pExpr->op = TK_COLUMN;
lookupname_end_2:
- sqliteFree(zCol);
+ sqlite3_free(zCol);
if( cnt==1 ){
assert( pNC!=0 );
sqlite3AuthRead(pParse, pExpr, pNC->pSrcList);
int mem = pParse->nMem++;
sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0);
testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0);
- assert( testAddr>0 || sqlite3MallocFailed() );
+ assert( testAddr>0 || pParse->db->mallocFailed );
sqlite3VdbeAddOp(v, OP_MemInt, 1, mem);
}
** text z[0..n-1] on the stack.
*/
static void codeInteger(Vdbe *v, const char *z, int n){
- assert( z || sqlite3MallocFailed() );
+ assert( z || v==0 || sqlite3DbOfVdbe(v)->mallocFailed );
if( z ){
int i;
if( sqlite3GetInt32(z, &i) ){
}else{
codeInteger(v, z, p->n+1);
}
- sqliteFree(z);
+ sqlite3_free(z);
break;
}
/* Fall through into TK_NOT */
const char *zId;
int constMask = 0;
int i;
- u8 enc = ENC(pParse->db);
+ sqlite3 *db = pParse->db;
+ u8 enc = ENC(db);
CollSeq *pColl = 0;
+
zId = (char*)pExpr->token.z;
nId = pExpr->token.n;
pDef = sqlite3FindFunction(pParse->db, zId, nId, nExpr, enc, 0);
** for function overloading. But we use the B term in "glob(B,A)".
*/
if( nExpr>=2 && (pExpr->flags & EP_InfixFunc) ){
- pDef = sqlite3VtabOverloadFunction(pDef, nExpr, pList->a[1].pExpr);
+ pDef = sqlite3VtabOverloadFunction(db, pDef, nExpr, pList->a[1].pExpr);
}else if( nExpr>0 ){
- pDef = sqlite3VtabOverloadFunction(pDef, nExpr, pList->a[0].pExpr);
+ pDef = sqlite3VtabOverloadFunction(db, pDef, nExpr, pList->a[0].pExpr);
}
#endif
for(i=0; i<nExpr && i<32; i++){
** Add a new element to the pAggInfo->aCol[] array. Return the index of
** the new element. Return a negative number if malloc fails.
*/
-static int addAggInfoColumn(AggInfo *pInfo){
+static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
int i;
pInfo->aCol = sqlite3ArrayAllocate(
+ db,
pInfo->aCol,
sizeof(pInfo->aCol[0]),
3,
** Add a new element to the pAggInfo->aFunc[] array. Return the index of
** the new element. Return a negative number if malloc fails.
*/
-static int addAggInfoFunc(AggInfo *pInfo){
+static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
int i;
pInfo->aFunc = sqlite3ArrayAllocate(
+ db,
pInfo->aFunc,
sizeof(pInfo->aFunc[0]),
3,
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: func.c,v 1.163 2007/07/26 06:50:06 danielk1977 Exp $
+** $Id: func.c,v 1.164 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
sqlite3_result_error_toobig(context);
return;
}
- p = sqliteMalloc(n);
+ p = sqlite3_malloc(n);
if( p ){
sqlite3Randomness(n, p);
- sqlite3_result_blob(context, (char*)p, n, sqlite3FreeX);
+ sqlite3_result_blob(context, (char*)p, n, sqlite3_free);
}
}
sqlite3_result_error_toobig(context);
return;
}
- zText = (char *)sqliteMalloc((2*nBlob)+4);
+ zText = (char *)sqlite3_malloc((2*nBlob)+4);
if( !zText ){
sqlite3_result_error(context, "out of memory", -1);
}else{
zText[0] = 'X';
zText[1] = '\'';
sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
- sqliteFree(zText);
+ sqlite3_free(zText);
}
break;
}
sqlite3_result_error_toobig(context);
return;
}
- z = sqliteMalloc( i+n+3 );
+ z = sqlite3_malloc( i+n+3 );
if( z==0 ) return;
z[0] = '\'';
for(i=0, j=1; zArg[i]; i++){
z[j++] = '\'';
z[j] = 0;
sqlite3_result_text(context, z, j, SQLITE_TRANSIENT);
- sqliteFree(z);
+ sqlite3_free(z);
}
}
}
char *zVal = (char *)p;
assert(zVal);
zVal--;
- sqliteFree(zVal);
+ sqlite3_free(zVal);
test_destructor_count_var--;
}
static void test_destructor(
** 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 free_test_auxdata(void *p) {sqlite3_free(p);}
static void test_auxdata(
sqlite3_context *pCtx,
int nArg,
}
}else{
zRet[i*2] = '0';
- zAux = sqliteStrDup(z);
+ zAux = sqlite3StrDup(z);
sqlite3_set_auxdata(pCtx, i, zAux, free_test_auxdata);
}
zRet[i*2+1] = ' ';
** This is the implementation of generic hash-tables
** used in SQLite.
**
-** $Id: hash.c,v 1.19 2007/03/31 03:59:24 drh Exp $
+** $Id: hash.c,v 1.20 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include <assert.h>
pNew->count = 0;
pNew->htsize = 0;
pNew->ht = 0;
- pNew->xMalloc = sqlite3MallocX;
- pNew->xFree = sqlite3FreeX;
}
/* Remove all entries from a hash table. Reclaim all memory.
assert( pH!=0 );
elem = pH->first;
pH->first = 0;
- if( pH->ht ) pH->xFree(pH->ht);
+ if( pH->ht ) sqlite3_free(pH->ht);
pH->ht = 0;
pH->htsize = 0;
while( elem ){
HashElem *next_elem = elem->next;
if( pH->copyKey && elem->pKey ){
- pH->xFree(elem->pKey);
+ sqlite3_free(elem->pKey);
}
- pH->xFree(elem);
+ sqlite3_free(elem);
elem = next_elem;
}
pH->count = 0;
/* Resize the hash table so that it cantains "new_size" buckets.
** "new_size" must be a power of 2. The hash table might fail
-** to resize if sqliteMalloc() fails.
+** to resize if sqlite3_malloc() fails.
*/
static void rehash(Hash *pH, int new_size){
struct _ht *new_ht; /* The new hash table */
int (*xHash)(const void*,int); /* The hash function */
assert( (new_size & (new_size-1))==0 );
- new_ht = (struct _ht *)pH->xMalloc( new_size*sizeof(struct _ht) );
+ new_ht = (struct _ht *)sqlite3_malloc( new_size*sizeof(struct _ht) );
if( new_ht==0 ) return;
- if( pH->ht ) pH->xFree(pH->ht);
+ if( pH->ht ) sqlite3_free(pH->ht);
pH->ht = new_ht;
pH->htsize = new_size;
xHash = hashFunction(pH->keyClass);
pEntry->chain = 0;
}
if( pH->copyKey ){
- pH->xFree(elem->pKey);
+ sqlite3_free(elem->pKey);
}
- pH->xFree( elem );
+ sqlite3_free( elem );
pH->count--;
if( pH->count<=0 ){
assert( pH->first==0 );
return old_data;
}
if( data==0 ) return 0;
- new_elem = (HashElem*)pH->xMalloc( sizeof(HashElem) );
+ new_elem = (HashElem*)sqlite3_malloc( sizeof(HashElem) );
if( new_elem==0 ) return data;
if( pH->copyKey && pKey!=0 ){
- new_elem->pKey = pH->xMalloc( nKey );
+ new_elem->pKey = sqlite3_malloc( nKey );
if( new_elem->pKey==0 ){
- pH->xFree(new_elem);
+ sqlite3_free(new_elem);
return data;
}
memcpy((void*)new_elem->pKey, pKey, nKey);
if( pH->htsize==0 ){
pH->count = 0;
if( pH->copyKey ){
- pH->xFree(new_elem->pKey);
+ sqlite3_free(new_elem->pKey);
}
- pH->xFree(new_elem);
+ sqlite3_free(new_elem);
return data;
}
}
** This is the header file for the generic hash-table implemenation
** used in SQLite.
**
-** $Id: hash.h,v 1.9 2006/02/14 10:48:39 danielk1977 Exp $
+** $Id: hash.h,v 1.10 2007/08/16 04:30:40 drh Exp $
*/
#ifndef _SQLITE_HASH_H_
#define _SQLITE_HASH_H_
char keyClass; /* SQLITE_HASH_INT, _POINTER, _STRING, _BINARY */
char copyKey; /* True if copy of key made on insert */
int count; /* Number of entries in this table */
- HashElem *first; /* The first element of the array */
- void *(*xMalloc)(int); /* malloc() function to use */
- void (*xFree)(void *); /* free() function to use */
int htsize; /* Number of buckets in the hash table */
+ HashElem *first; /* The first element of the array */
struct _ht { /* the hash table */
int count; /* Number of entries with this hash */
HashElem *chain; /* Pointer to first entry with this hash */
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
-** $Id: insert.c,v 1.188 2007/07/23 19:39:47 drh Exp $
+** $Id: insert.c,v 1.189 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
*/
int n;
Table *pTab = pIdx->pTable;
- pIdx->zColAff = (char *)sqliteMalloc(pIdx->nColumn+1);
+ sqlite3 *db = sqlite3DbOfVdbe(v);
+ pIdx->zColAff = (char *)sqlite3DbMallocZero(db, pIdx->nColumn+1);
if( !pIdx->zColAff ){
return;
}
if( !pTab->zColAff ){
char *zColAff;
int i;
+ sqlite3 *db = sqlite3DbOfVdbe(v);
- zColAff = (char *)sqliteMalloc(pTab->nCol+1);
+ zColAff = (char *)sqlite3DbMallocZero(db, pTab->nCol+1);
if( !zColAff ){
return;
}
int triggers_exist = 0; /* True if there are FOR EACH ROW triggers */
#endif
- if( pParse->nErr || sqlite3MallocFailed() ){
+ db = pParse->db;
+ if( pParse->nErr || db->mallocFailed ){
goto insert_cleanup;
}
- db = pParse->db;
/* Locate the table into which we will be inserting new information.
*/
/* Resolve the expressions in the SELECT statement and execute it. */
rc = sqlite3Select(pParse, pSelect, SRT_Subroutine, iInsertBlock,0,0,0,0);
- if( rc || pParse->nErr || sqlite3MallocFailed() ){
+ if( rc || pParse->nErr || db->mallocFailed ){
goto insert_cleanup;
}
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: legacy.c,v 1.18 2007/05/04 13:15:56 drh Exp $
+** $Id: legacy.c,v 1.19 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
nCallback = 0;
nCol = sqlite3_column_count(pStmt);
- azCols = sqliteMalloc(2*nCol*sizeof(const char *) + 1);
+ azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char *) + 1);
if( azCols==0 ){
goto exec_out;
}
}
}
- sqliteFree(azCols);
+ sqlite3_free(azCols);
azCols = 0;
}
exec_out:
if( pStmt ) sqlite3_finalize(pStmt);
- if( azCols ) sqliteFree(azCols);
+ if( azCols ) sqlite3_free(azCols);
rc = sqlite3ApiExit(0, rc);
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
/* Append the new shared library handle to the db->aExtension array. */
db->nExtension++;
- aHandle = sqliteMalloc(sizeof(handle)*db->nExtension);
+ aHandle = sqlite3DbMallocZero(db, sizeof(handle)*db->nExtension);
if( aHandle==0 ){
return SQLITE_NOMEM;
}
if( db->nExtension>0 ){
memcpy(aHandle, db->aExtension, sizeof(handle)*(db->nExtension-1));
}
- sqliteFree(db->aExtension);
+ sqlite3_free(db->aExtension);
db->aExtension = aHandle;
db->aExtension[db->nExtension-1] = handle;
for(i=0; i<db->nExtension; i++){
sqlite3OsDlclose(db->aExtension[i]);
}
- sqliteFree(db->aExtension);
+ sqlite3_free(db->aExtension);
}
/*
}
if( i==nAutoExtension ){
nAutoExtension++;
- aAutoExtension = sqlite3Realloc( aAutoExtension,
+ aAutoExtension = sqlite3_realloc( aAutoExtension,
nAutoExtension*sizeof(aAutoExtension[0]) );
if( aAutoExtension==0 ){
nAutoExtension = 0;
*/
void sqlite3_reset_auto_extension(void){
sqlite3OsEnterMutex();
- sqliteFree(aAutoExtension);
+ sqlite3_free(aAutoExtension);
aAutoExtension = 0;
nAutoExtension = 0;
sqlite3OsLeaveMutex();
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: main.c,v 1.379 2007/08/15 13:04:54 drh Exp $
+** $Id: main.c,v 1.380 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
FuncDef *pFunc, *pNext;
for(pFunc = (FuncDef*)sqliteHashData(i); pFunc; pFunc=pNext){
pNext = pFunc->pNext;
- sqliteFree(pFunc);
+ sqlite3_free(pFunc);
}
}
pColl[j].xDel(pColl[j].pUser);
}
}
- sqliteFree(pColl);
+ sqlite3_free(pColl);
}
sqlite3HashClear(&db->aCollSeq);
#ifndef SQLITE_OMIT_VIRTUALTABLE
if( pMod->xDestroy ){
pMod->xDestroy(pMod->pAux);
}
- sqliteFree(pMod);
+ sqlite3_free(pMod);
}
sqlite3HashClear(&db->aModule);
#endif
** the same sqliteMalloc() as the one that allocates the database
** structure?
*/
- sqliteFree(db->aDb[1].pSchema);
- sqliteFree(db);
+ sqlite3_free(db->aDb[1].pSchema);
+ sqlite3_free(db);
sqlite3ReleaseThreadData();
return SQLITE_OK;
}
if( db->activeVdbeCnt ){
sqlite3Error(db, SQLITE_BUSY,
"Unable to delete/modify user-function due to active statements");
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
return SQLITE_BUSY;
}else{
sqlite3ExpirePreparedStatements(db);
void (*xFinal)(sqlite3_context*)
){
int rc;
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal);
return sqlite3ApiExit(db, rc);
){
int rc;
char *zFunc8;
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
zFunc8 = sqlite3Utf16to8(zFunctionName, -1);
rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal);
- sqliteFree(zFunc8);
+ sqlite3_free(zFunc8);
return sqlite3ApiExit(db, rc);
}
*/
const char *sqlite3_errmsg(sqlite3 *db){
const char *z;
- assert( !sqlite3MallocFailed() );
if( !db ){
return sqlite3ErrStr(SQLITE_NOMEM);
}
+ assert( !db->mallocFailed );
if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){
return sqlite3ErrStr(SQLITE_MISUSE);
}
};
const void *z;
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
if( !db ){
return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);
}
** passed to this function, we assume a malloc() failed during sqlite3_open().
*/
int sqlite3_errcode(sqlite3 *db){
- if( !db || sqlite3MallocFailed() ){
+ if( !db || db->mallocFailed ){
return SQLITE_NOMEM;
}
if( sqlite3SafetyCheck(db) ){
int rc;
CollSeq *pColl;
- assert( !sqlite3MallocFailed() );
-
/* Allocate the sqlite data structure */
- db = sqliteMalloc( sizeof(sqlite3) );
+ db = sqlite3MallocZero( sizeof(sqlite3) );
if( db==0 ) goto opendb_out;
db->errMask = 0xff;
db->priorNewRowid = 0;
createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0) ||
(db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0))==0
){
- assert( sqlite3MallocFailed() );
+ assert( db->mallocFailed );
db->magic = SQLITE_MAGIC_CLOSED;
goto opendb_out;
}
db->magic = SQLITE_MAGIC_CLOSED;
goto opendb_out;
}
- db->aDb[0].pSchema = sqlite3SchemaGet(db->aDb[0].pBt);
- db->aDb[1].pSchema = sqlite3SchemaGet(0);
+ db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
+ db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
/* The default safety_level for the main database is 'full'; for the temp
#endif
db->magic = SQLITE_MAGIC_OPEN;
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
goto opendb_out;
}
}
#ifdef SQLITE_ENABLE_FTS1
- if( !sqlite3MallocFailed() ){
+ if( !db->mallocFailed ){
extern int sqlite3Fts1Init(sqlite3*);
rc = sqlite3Fts1Init(db);
}
#endif
#ifdef SQLITE_ENABLE_FTS2
- if( !sqlite3MallocFailed() && rc==SQLITE_OK ){
+ if( !db->mallocFailed && rc==SQLITE_OK ){
extern int sqlite3Fts2Init(sqlite3*);
rc = sqlite3Fts2Init(db);
}
#endif
#ifdef SQLITE_ENABLE_ICU
- if( !sqlite3MallocFailed() && rc==SQLITE_OK ){
+ if( !db->mallocFailed && rc==SQLITE_OK ){
extern int sqlite3IcuInit(sqlite3*);
rc = sqlite3IcuInit(db);
}
int(*xCompare)(void*,int,const void*,int,const void*)
){
int rc;
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
rc = createCollation(db, zName, enc, pCtx, xCompare, 0);
return sqlite3ApiExit(db, rc);
}
void(*xDel)(void*)
){
int rc;
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
rc = createCollation(db, zName, enc, pCtx, xCompare, xDel);
return sqlite3ApiExit(db, rc);
}
){
int rc = SQLITE_OK;
char *zName8;
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
zName8 = sqlite3Utf16to8(zName, -1);
if( zName8 ){
rc = createCollation(db, zName8, enc, pCtx, xCompare, 0);
- sqliteFree(zName8);
+ sqlite3_free(zName8);
}
return sqlite3ApiExit(db, rc);
}
rc = SQLITE_ERROR;
}
sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg);
- sqliteFree(zErrMsg);
+ sqlite3_free(zErrMsg);
return sqlite3ApiExit(db, rc);
}
#endif
** Memory allocation functions used throughout sqlite.
**
**
-** $Id: malloc.c,v 1.4 2007/08/08 01:04:52 drh Exp $
+** $Id: malloc.c,v 1.5 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <stdarg.h>
#include <ctype.h>
-/*
-** MALLOC WRAPPER ARCHITECTURE
-**
-** The sqlite code accesses dynamic memory allocation/deallocation by invoking
-** the following six APIs (which may be implemented as macros).
-**
-** sqlite3Malloc()
-** sqlite3MallocRaw()
-** sqlite3Realloc()
-** sqlite3ReallocOrFree()
-** sqlite3Free()
-** sqlite3AllocSize()
-**
-** The function sqlite3FreeX performs the same task as sqlite3Free and is
-** guaranteed to be a real function. The same holds for sqlite3MallocX
-**
-** The above APIs are implemented in terms of the functions provided in the
-** operating-system interface. The OS interface is never accessed directly
-** by code outside of this file.
-**
-** sqlite3OsMalloc()
-** sqlite3OsRealloc()
-** sqlite3OsFree()
-** sqlite3OsAllocationSize()
-**
-** Functions sqlite3MallocRaw() and sqlite3Realloc() may invoke
-** sqlite3_release_memory() if a call to sqlite3OsMalloc() or
-** sqlite3OsRealloc() fails (or if the soft-heap-limit for the thread is
-** exceeded). Function sqlite3Malloc() usually invokes
-** sqlite3MallocRaw().
-**
-** MALLOC TEST WRAPPER ARCHITECTURE
-**
-** The test wrapper provides extra test facilities to ensure the library
-** does not leak memory and handles the failure of the underlying OS level
-** allocation system correctly. It is only present if the library is
-** compiled with the SQLITE_MEMDEBUG macro set.
-**
-** * Guardposts to detect overwrites.
-** * Ability to cause a specific Malloc() or Realloc() to fail.
-** * Audit outstanding memory allocations (i.e check for leaks).
-*/
-
-#define MAX(x,y) ((x)>(y)?(x):(y))
-
-#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
/*
** Set the soft heap-size limit for the current thread. Passing a negative
** value indicates no limit.
int sqlite3_release_memory(int n){
return sqlite3PagerReleaseMemory(n);
}
-#else
-/* If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, then define a version
-** of sqlite3_release_memory() to be used by other code in this file.
-** This is done for no better reason than to reduce the number of
-** pre-processor #ifndef statements.
-*/
-#define sqlite3_release_memory(x) 0 /* 0 == no memory freed */
-#endif
-
-#ifdef SQLITE_MEMDEBUG
-/*--------------------------------------------------------------------------
-** Begin code for memory allocation system test layer.
-**
-** Memory debugging is turned on by defining the SQLITE_MEMDEBUG macro.
-**
-** SQLITE_MEMDEBUG==1 -> Fence-posting only (thread safe)
-** SQLITE_MEMDEBUG==2 -> Fence-posting + linked list of allocations (not ts)
-** SQLITE_MEMDEBUG==3 -> Above + backtraces (not thread safe, req. glibc)
-*/
-/* Figure out whether or not to store backtrace() information for each malloc.
-** The backtrace() function is only used if SQLITE_MEMDEBUG is set to 2 or
-** greater and glibc is in use. If we don't want to use backtrace(), then just
-** define it as an empty macro and set the amount of space reserved to 0.
-*/
-#if defined(__GLIBC__) && SQLITE_MEMDEBUG>2
- extern int backtrace(void **, int);
- #define TESTALLOC_STACKSIZE 128
- #define TESTALLOC_STACKFRAMES ((TESTALLOC_STACKSIZE-8)/sizeof(void*))
-#else
- #define backtrace(x, y)
- #define TESTALLOC_STACKSIZE 0
- #define TESTALLOC_STACKFRAMES 0
-#endif
/*
-** Number of 32-bit guard words. This should probably be a multiple of
-** 2 since on 64-bit machines we want the value returned by sqliteMalloc()
-** to be 8-byte aligned.
-*/
-#ifndef TESTALLOC_NGUARD
-# define TESTALLOC_NGUARD 2
-#endif
-
-/*
-** Size reserved for storing file-name along with each malloc()ed blob.
-*/
-#define TESTALLOC_FILESIZE 64
-
-/*
-** Size reserved for storing the user string. Each time a Malloc() or Realloc()
-** call succeeds, up to TESTALLOC_USERSIZE bytes of the string pointed to by
-** sqlite3_malloc_id are stored along with the other test system metadata.
-*/
-#define TESTALLOC_USERSIZE 64
-const char *sqlite3_malloc_id = 0;
-
-/*
-** Blocks used by the test layer have the following format:
-**
-** <sizeof(void *) pNext pointer>
-** <sizeof(void *) pPrev pointer>
-** <TESTALLOC_NGUARD 32-bit guard words>
-** <The application level allocation>
-** <TESTALLOC_NGUARD 32-bit guard words>
-** <32-bit line number>
-** <TESTALLOC_FILESIZE bytes containing null-terminated file name>
-** <TESTALLOC_STACKSIZE bytes of backtrace() output>
+** Allocate and zero memory.
*/
-
-#define TESTALLOC_OFFSET_GUARD1(p) (sizeof(void *) * 2)
-#define TESTALLOC_OFFSET_DATA(p) ( \
- TESTALLOC_OFFSET_GUARD1(p) + sizeof(u32) * TESTALLOC_NGUARD \
-)
-#define TESTALLOC_OFFSET_GUARD2(p) ( \
- TESTALLOC_OFFSET_DATA(p) + sqlite3OsAllocationSize(p) - TESTALLOC_OVERHEAD \
-)
-#define TESTALLOC_OFFSET_LINENUMBER(p) ( \
- TESTALLOC_OFFSET_GUARD2(p) + sizeof(u32) * TESTALLOC_NGUARD \
-)
-#define TESTALLOC_OFFSET_FILENAME(p) ( \
- TESTALLOC_OFFSET_LINENUMBER(p) + sizeof(u32) \
-)
-#define TESTALLOC_OFFSET_USER(p) ( \
- TESTALLOC_OFFSET_FILENAME(p) + TESTALLOC_FILESIZE \
-)
-#define TESTALLOC_OFFSET_STACK(p) ( \
- TESTALLOC_OFFSET_USER(p) + TESTALLOC_USERSIZE + 8 - \
- (TESTALLOC_OFFSET_USER(p) % 8) \
-)
-
-#define TESTALLOC_OVERHEAD ( \
- sizeof(void *)*2 + /* pPrev and pNext pointers */ \
- TESTALLOC_NGUARD*sizeof(u32)*2 + /* Guard words */ \
- sizeof(u32) + TESTALLOC_FILESIZE + /* File and line number */ \
- TESTALLOC_USERSIZE + /* User string */ \
- TESTALLOC_STACKSIZE /* backtrace() stack */ \
-)
-
-
-/*
-** For keeping track of the number of mallocs and frees. This
-** is used to check for memory leaks. The iMallocFail and iMallocReset
-** values are used to simulate malloc() failures during testing in
-** order to verify that the library correctly handles an out-of-memory
-** condition.
-*/
-int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */
-int sqlite3_nFree; /* Number of sqliteFree() calls */
-int sqlite3_memUsed; /* TODO Total memory obtained from malloc */
-int sqlite3_memMax; /* TODO Mem usage high-water mark */
-int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */
-int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */
-
-void *sqlite3_pFirst = 0; /* Pointer to linked list of allocations */
-int sqlite3_nMaxAlloc = 0; /* High water mark of ThreadData.nAlloc */
-int sqlite3_mallocDisallowed = 0; /* assert() in sqlite3Malloc() if set */
-int sqlite3_isFail = 0; /* True if all malloc calls should fail */
-const char *sqlite3_zFile = 0; /* Filename to associate debug info with */
-int sqlite3_iLine = 0; /* Line number for debug info */
-int sqlite3_mallocfail_trace = 0; /* Print a msg on malloc fail if true */
-
-/*
-** Check for a simulated memory allocation failure. Return true if
-** the failure should be simulated. Return false to proceed as normal.
-*/
-int sqlite3TestMallocFail(){
- if( sqlite3_isFail ){
- return 1;
- }
- if( sqlite3_iMallocFail>=0 ){
- sqlite3_iMallocFail--;
- if( sqlite3_iMallocFail==0 ){
- sqlite3_iMallocFail = sqlite3_iMallocReset;
- sqlite3_isFail = 1;
- if( sqlite3_mallocfail_trace ){
- sqlite3DebugPrintf("###_malloc_fails_###\n");
- }
- return 1;
- }
- }
- return 0;
-}
-
-/*
-** The argument is a pointer returned by sqlite3OsMalloc() or xRealloc().
-** assert() that the first and last (TESTALLOC_NGUARD*4) bytes are set to the
-** values set by the applyGuards() function.
-*/
-static void checkGuards(u32 *p)
-{
- int i;
- char *zAlloc = (char *)p;
- char *z;
-
- /* First set of guard words */
- z = &zAlloc[TESTALLOC_OFFSET_GUARD1(p)];
- for(i=0; i<TESTALLOC_NGUARD; i++){
- assert(((u32 *)z)[i]==0xdead1122);
- }
-
- /* Second set of guard words */
- z = &zAlloc[TESTALLOC_OFFSET_GUARD2(p)];
- for(i=0; i<TESTALLOC_NGUARD; i++){
- u32 guard = 0;
- memcpy(&guard, &z[i*sizeof(u32)], sizeof(u32));
- assert(guard==0xdead3344);
- }
-}
-
-/*
-** The argument is a pointer returned by sqlite3OsMalloc() or Realloc(). The
-** first and last (TESTALLOC_NGUARD*4) bytes are set to known values for use as
-** guard-posts.
-*/
-static void applyGuards(u32 *p)
-{
- int i;
- char *z;
- char *zAlloc = (char *)p;
-
- /* First set of guard words */
- z = &zAlloc[TESTALLOC_OFFSET_GUARD1(p)];
- for(i=0; i<TESTALLOC_NGUARD; i++){
- ((u32 *)z)[i] = 0xdead1122;
- }
-
- /* Second set of guard words */
- z = &zAlloc[TESTALLOC_OFFSET_GUARD2(p)];
- for(i=0; i<TESTALLOC_NGUARD; i++){
- static const int guard = 0xdead3344;
- memcpy(&z[i*sizeof(u32)], &guard, sizeof(u32));
- }
-
- /* Line number */
- z = &((char *)z)[TESTALLOC_NGUARD*sizeof(u32)]; /* Guard words */
- z = &zAlloc[TESTALLOC_OFFSET_LINENUMBER(p)];
- memcpy(z, &sqlite3_iLine, sizeof(u32));
-
- /* File name */
- z = &zAlloc[TESTALLOC_OFFSET_FILENAME(p)];
- strncpy(z, sqlite3_zFile, TESTALLOC_FILESIZE);
- z[TESTALLOC_FILESIZE - 1] = '\0';
-
- /* User string */
- z = &zAlloc[TESTALLOC_OFFSET_USER(p)];
- z[0] = 0;
- if( sqlite3_malloc_id ){
- strncpy(z, sqlite3_malloc_id, TESTALLOC_USERSIZE);
- z[TESTALLOC_USERSIZE-1] = 0;
- }
-
- /* backtrace() stack */
- z = &zAlloc[TESTALLOC_OFFSET_STACK(p)];
- backtrace((void **)z, TESTALLOC_STACKFRAMES);
-
- /* Sanity check to make sure checkGuards() is working */
- checkGuards(p);
-}
-
-/*
-** The argument is a malloc()ed pointer as returned by the test-wrapper.
-** Return a pointer to the Os level allocation.
-*/
-static void *getOsPointer(void *p)
-{
- char *z = (char *)p;
- return (void *)(&z[-1 * TESTALLOC_OFFSET_DATA(p)]);
-}
-
-
-#if SQLITE_MEMDEBUG>1
-/*
-** The argument points to an Os level allocation. Link it into the threads list
-** of allocations.
-*/
-static void linkAlloc(void *p){
- void **pp = (void **)p;
- pp[0] = 0;
- pp[1] = sqlite3_pFirst;
- if( sqlite3_pFirst ){
- ((void **)sqlite3_pFirst)[0] = p;
- }
- sqlite3_pFirst = p;
-}
-
-/*
-** The argument points to an Os level allocation. Unlinke it from the threads
-** list of allocations.
-*/
-static void unlinkAlloc(void *p)
-{
- void **pp = (void **)p;
- if( p==sqlite3_pFirst ){
- assert(!pp[0]);
- assert(!pp[1] || ((void **)(pp[1]))[0]==p);
- sqlite3_pFirst = pp[1];
- if( sqlite3_pFirst ){
- ((void **)sqlite3_pFirst)[0] = 0;
- }
- }else{
- void **pprev = pp[0];
- void **pnext = pp[1];
- assert(pprev);
- assert(pprev[1]==p);
- pprev[1] = (void *)pnext;
- if( pnext ){
- assert(pnext[0]==p);
- pnext[0] = (void *)pprev;
- }
- }
-}
-
-/*
-** Pointer p is a pointer to an OS level allocation that has just been
-** realloc()ed. Set the list pointers that point to this entry to it's new
-** location.
-*/
-static void relinkAlloc(void *p)
-{
- void **pp = (void **)p;
- if( pp[0] ){
- ((void **)(pp[0]))[1] = p;
- }else{
- sqlite3_pFirst = p;
- }
- if( pp[1] ){
- ((void **)(pp[1]))[0] = p;
- }
-}
-#else
-#define linkAlloc(x)
-#define relinkAlloc(x)
-#define unlinkAlloc(x)
-#endif
-
-/*
-** This function sets the result of the Tcl interpreter passed as an argument
-** to a list containing an entry for each currently outstanding call made to
-** sqliteMalloc and friends by the current thread. Each list entry is itself a
-** list, consisting of the following (in order):
-**
-** * The number of bytes allocated
-** * The __FILE__ macro at the time of the sqliteMalloc() call.
-** * The __LINE__ macro ...
-** * The value of the sqlite3_malloc_id variable ...
-** * The output of backtrace() (if available) ...
-**
-** Todo: We could have a version of this function that outputs to stdout,
-** to debug memory leaks when Tcl is not available.
-*/
-#if defined(TCLSH) && defined(SQLITE_DEBUG) && SQLITE_MEMDEBUG>1
-#include <tcl.h>
-int sqlite3OutstandingMallocs(Tcl_Interp *interp){
- void *p;
- Tcl_Obj *pRes = Tcl_NewObj();
- Tcl_IncrRefCount(pRes);
-
-
- for(p=sqlite3_pFirst; p; p=((void **)p)[1]){
- Tcl_Obj *pEntry = Tcl_NewObj();
- Tcl_Obj *pStack = Tcl_NewObj();
- char *z;
- u32 iLine;
- int nBytes = sqlite3OsAllocationSize(p) - TESTALLOC_OVERHEAD;
- char *zAlloc = (char *)p;
- int i;
-
- Tcl_ListObjAppendElement(0, pEntry, Tcl_NewIntObj(nBytes));
-
- z = &zAlloc[TESTALLOC_OFFSET_FILENAME(p)];
- Tcl_ListObjAppendElement(0, pEntry, Tcl_NewStringObj(z, -1));
-
- z = &zAlloc[TESTALLOC_OFFSET_LINENUMBER(p)];
- memcpy(&iLine, z, sizeof(u32));
- Tcl_ListObjAppendElement(0, pEntry, Tcl_NewIntObj(iLine));
-
- z = &zAlloc[TESTALLOC_OFFSET_USER(p)];
- Tcl_ListObjAppendElement(0, pEntry, Tcl_NewStringObj(z, -1));
-
- z = &zAlloc[TESTALLOC_OFFSET_STACK(p)];
- for(i=0; i<TESTALLOC_STACKFRAMES; i++){
- char zHex[128];
- sqlite3_snprintf(sizeof(zHex), zHex, "%p", ((void **)z)[i]);
- Tcl_ListObjAppendElement(0, pStack, Tcl_NewStringObj(zHex, -1));
- }
-
- Tcl_ListObjAppendElement(0, pEntry, pStack);
- Tcl_ListObjAppendElement(0, pRes, pEntry);
- }
-
- Tcl_ResetResult(interp);
- Tcl_SetObjResult(interp, pRes);
- Tcl_DecrRefCount(pRes);
- return TCL_OK;
-}
-#endif
-
-/*
-** This is the test layer's wrapper around sqlite3OsMalloc().
-*/
-static void * OSMALLOC(int n){
- sqlite3OsEnterMutex();
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
- sqlite3_nMaxAlloc =
- MAX(sqlite3_nMaxAlloc, sqlite3ThreadDataReadOnly()->nAlloc);
-#endif
- assert( !sqlite3_mallocDisallowed );
- if( !sqlite3TestMallocFail() ){
- u32 *p;
- p = (u32 *)sqlite3OsMalloc(n + TESTALLOC_OVERHEAD);
- assert(p);
- sqlite3_nMalloc++;
- applyGuards(p);
- linkAlloc(p);
- sqlite3OsLeaveMutex();
- return (void *)(&p[TESTALLOC_NGUARD + 2*sizeof(void *)/sizeof(u32)]);
- }
- sqlite3OsLeaveMutex();
- return 0;
-}
-
-static int OSSIZEOF(void *p){
+void *sqlite3MallocZero(unsigned n){
+ void *p = sqlite3_malloc(n);
if( p ){
- u32 *pOs = (u32 *)getOsPointer(p);
- return sqlite3OsAllocationSize(pOs) - TESTALLOC_OVERHEAD;
- }
- return 0;
-}
-
-/*
-** This is the test layer's wrapper around sqlite3OsFree(). The argument is a
-** pointer to the space allocated for the application to use.
-*/
-static void OSFREE(void *pFree){
- u32 *p; /* Pointer to the OS-layer allocation */
- sqlite3OsEnterMutex();
- p = (u32 *)getOsPointer(pFree);
- checkGuards(p);
- unlinkAlloc(p);
- memset(pFree, 0x55, OSSIZEOF(pFree));
- sqlite3OsFree(p);
- sqlite3_nFree++;
- sqlite3OsLeaveMutex();
-}
-
-/*
-** This is the test layer's wrapper around sqlite3OsRealloc().
-*/
-static void * OSREALLOC(void *pRealloc, int n){
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
- sqlite3_nMaxAlloc =
- MAX(sqlite3_nMaxAlloc, sqlite3ThreadDataReadOnly()->nAlloc);
-#endif
- assert( !sqlite3_mallocDisallowed );
- if( !sqlite3TestMallocFail() ){
- u32 *p = (u32 *)getOsPointer(pRealloc);
- checkGuards(p);
- p = sqlite3OsRealloc(p, n + TESTALLOC_OVERHEAD);
- applyGuards(p);
- relinkAlloc(p);
- return (void *)(&p[TESTALLOC_NGUARD + 2*sizeof(void *)/sizeof(u32)]);
- }
- return 0;
-}
-
-static void OSMALLOC_FAILED(){
- sqlite3_isFail = 0;
-}
-
-#else
-/* Define macros to call the sqlite3OsXXX interface directly if
-** the SQLITE_MEMDEBUG macro is not defined.
-*/
-#define OSMALLOC(x) sqlite3OsMalloc(x)
-#define OSREALLOC(x,y) sqlite3OsRealloc(x,y)
-#define OSFREE(x) sqlite3OsFree(x)
-#define OSSIZEOF(x) sqlite3OsAllocationSize(x)
-#define OSMALLOC_FAILED()
-
-#endif /* SQLITE_MEMDEBUG */
-/*
-** End code for memory allocation system test layer.
-**--------------------------------------------------------------------------*/
-
-/*
-** This routine is called when we are about to allocate n additional bytes
-** of memory. If the new allocation will put is over the soft allocation
-** limit, then invoke sqlite3_release_memory() to try to release some
-** memory before continuing with the allocation.
-**
-** This routine also makes sure that the thread-specific-data (TSD) has
-** be allocated. If it has not and can not be allocated, then return
-** false. The updateMemoryUsedCount() routine below will deallocate
-** the TSD if it ought to be.
-**
-** If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, this routine is
-** a no-op
-*/
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
-static int enforceSoftLimit(int n){
- ThreadData *pTsd = sqlite3ThreadData();
- if( pTsd==0 ){
- return 0;
- }
- assert( pTsd->nAlloc>=0 );
- if( n>0 && pTsd->nSoftHeapLimit>0 ){
- while( pTsd->nAlloc+n>pTsd->nSoftHeapLimit && sqlite3_release_memory(n) ){}
- }
- return 1;
-}
-#else
-# define enforceSoftLimit(X) 1
-#endif
-
-/*
-** Update the count of total outstanding memory that is held in
-** thread-specific-data (TSD). If after this update the TSD is
-** no longer being used, then deallocate it.
-**
-** If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, this routine is
-** a no-op
-*/
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
-static void updateMemoryUsedCount(int n){
- ThreadData *pTsd = sqlite3ThreadData();
- if( pTsd ){
- pTsd->nAlloc += n;
- assert( pTsd->nAlloc>=0 );
- if( pTsd->nAlloc==0 && pTsd->nSoftHeapLimit==0 ){
- sqlite3ReleaseThreadData();
- }
- }
-}
-#else
-#define updateMemoryUsedCount(x) /* no-op */
-#endif
-
-/*
-** Allocate and return N bytes of uninitialised memory by calling
-** sqlite3OsMalloc(). If the Malloc() call fails, attempt to free memory
-** by calling sqlite3_release_memory().
-*/
-void *sqlite3MallocRaw(int n, int doMemManage){
- void *p = 0;
- if( n>0 && !sqlite3MallocFailed() && (!doMemManage || enforceSoftLimit(n)) ){
- while( (p = OSMALLOC(n))==0 && sqlite3_release_memory(n) ){}
- if( !p ){
- sqlite3FailedMalloc();
- OSMALLOC_FAILED();
- }else if( doMemManage ){
- updateMemoryUsedCount(OSSIZEOF(p));
- }
+ memset(p, 0, n);
}
return p;
}
/*
-** Resize the allocation at p to n bytes by calling sqlite3OsRealloc(). The
-** pointer to the new allocation is returned. If the Realloc() call fails,
-** attempt to free memory by calling sqlite3_release_memory().
+** Allocate and zero memory. If the allocation fails, make
+** the mallocFailed flag in the connection pointer.
*/
-void *sqlite3Realloc(void *p, int n){
- if( sqlite3MallocFailed() ){
- return 0;
- }
-
- if( !p ){
- return sqlite3Malloc(n, 1);
+void *sqlite3DbMallocZero(sqlite3 *db, unsigned n){
+ void *p = sqlite3_malloc(n);
+ if( p ){
+ memset(p, 0, n);
}else{
- void *np = 0;
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
- int origSize = OSSIZEOF(p);
-#endif
- if( enforceSoftLimit(n - origSize) ){
- while( (np = OSREALLOC(p, n))==0 && sqlite3_release_memory(n) ){}
- if( !np ){
- sqlite3FailedMalloc();
- OSMALLOC_FAILED();
- }else{
- updateMemoryUsedCount(OSSIZEOF(np) - origSize);
- }
- }
- return np;
+ db->mallocFailed = 1;
}
+ return p;
}
/*
-** Free the memory pointed to by p. p must be either a NULL pointer or a
-** value returned by a previous call to sqlite3Malloc() or sqlite3Realloc().
+** Allocate and zero memory. If the allocation fails, make
+** the mallocFailed flag in the connection pointer.
*/
-void sqlite3FreeX(void *p){
- if( p ){
- updateMemoryUsedCount(0 - OSSIZEOF(p));
- OSFREE(p);
+void *sqlite3DbMallocRaw(sqlite3 *db, unsigned n){
+ void *p = sqlite3_malloc(n);
+ if( !p ){
+ db->mallocFailed = 1;
}
+ return p;
}
/*
-** A version of sqliteMalloc() that is always a function, not a macro.
-** Currently, this is used only to alloc to allocate the parser engine.
+** Attempt to reallocate p. If the reallocation fails, then free p
+** and set the mallocFailed flag in the database connection.
*/
-void *sqlite3MallocX(int n){
- return sqliteMalloc(n);
-}
-
-/*
-** sqlite3Malloc
-** sqlite3ReallocOrFree
-**
-** These two are implemented as wrappers around sqlite3MallocRaw(),
-** sqlite3Realloc() and sqlite3Free().
-*/
-void *sqlite3Malloc(int n, int doMemManage){
- void *p = sqlite3MallocRaw(n, doMemManage);
- if( p ){
- memset(p, 0, n);
- }
- return p;
-}
-void *sqlite3ReallocOrFree(void *p, int n){
+void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
void *pNew;
- pNew = sqlite3Realloc(p, n);
+ pNew = sqlite3_realloc(p, n);
if( !pNew ){
sqlite3FreeX(p);
+ db->mallocFailed = 1;
}
return pNew;
}
-/*
-** sqlite3ThreadSafeMalloc() and sqlite3ThreadSafeFree() are used in those
-** rare scenarios where sqlite may allocate memory in one thread and free
-** it in another. They are exactly the same as sqlite3Malloc() and
-** sqlite3Free() except that:
-**
-** * The allocated memory is not included in any calculations with
-** respect to the soft-heap-limit, and
-**
-** * sqlite3ThreadSafeMalloc() must be matched with ThreadSafeFree(),
-** not sqlite3Free(). Calling sqlite3Free() on memory obtained from
-** ThreadSafeMalloc() will cause an error somewhere down the line.
-*/
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
-void *sqlite3ThreadSafeMalloc(int n){
- (void)ENTER_MALLOC;
- return sqlite3Malloc(n, 0);
-}
-void sqlite3ThreadSafeFree(void *p){
- (void)ENTER_MALLOC;
- if( p ){
- OSFREE(p);
- }
-}
-#endif
-
-
-/*
-** Return the number of bytes allocated at location p. p must be either
-** a NULL pointer (in which case 0 is returned) or a pointer returned by
-** sqlite3Malloc(), sqlite3Realloc() or sqlite3ReallocOrFree().
-**
-** The number of bytes allocated does not include any overhead inserted by
-** any malloc() wrapper functions that may be called. So the value returned
-** is the number of bytes that were available to SQLite using pointer p,
-** regardless of how much memory was actually allocated.
-*/
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
-int sqlite3AllocSize(void *p){
- return OSSIZEOF(p);
-}
-#endif
/*
** Make a copy of a string in memory obtained from sqliteMalloc(). These
/*
** This function must be called before exiting any API function (i.e.
-** returning control to the user) that has called sqlite3Malloc or
-** sqlite3Realloc.
+** returning control to the user) that has called sqlite3_malloc or
+** sqlite3_realloc.
**
** The returned value is normally a copy of the second argument to this
** function. However, if a malloc() failure has occured since the previous
** then the connection error-code (the value returned by sqlite3_errcode())
** is set to SQLITE_NOMEM.
*/
-int sqlite3MallocHasFailed = 0;
int sqlite3ApiExit(sqlite3* db, int rc){
- if( sqlite3MallocFailed() ){
- sqlite3MallocHasFailed = 0;
- sqlite3OsLeaveMutex();
+ if( db->mallocFailed ){
sqlite3Error(db, SQLITE_NOMEM, 0);
+ db->mallocFailed = 0;
rc = SQLITE_NOMEM;
}
return rc & (db ? db->errMask : 0xff);
}
-/*
-** Set the "malloc has failed" condition to true for this thread.
-*/
-void sqlite3FailedMalloc(){
- if( !sqlite3MallocFailed() ){
- sqlite3OsEnterMutex();
- assert( sqlite3MallocHasFailed==0 );
- sqlite3MallocHasFailed = 1;
- }
-}
-
#ifdef SQLITE_MEMDEBUG
/*
** This function sets a flag in the thread-specific-data structure that will
** cause an assert to fail if sqliteMalloc() or sqliteRealloc() is called.
*/
void sqlite3MallocDisallow(){
+#if 0
assert( sqlite3_mallocDisallowed>=0 );
sqlite3_mallocDisallowed++;
+#endif
}
/*
** by sqlite3MallocDisallow().
*/
void sqlite3MallocAllow(){
+#if 0
assert( sqlite3_mallocDisallowed>0 );
sqlite3_mallocDisallowed--;
+#endif
}
#endif
** openKey structures) into lockInfo and openCnt structures. Access to
** these hash tables must be protected by a mutex.
*/
-static Hash lockHash = {SQLITE_HASH_BINARY, 0, 0, 0,
- sqlite3ThreadSafeMalloc, sqlite3ThreadSafeFree, 0, 0};
-static Hash openHash = {SQLITE_HASH_BINARY, 0, 0, 0,
- sqlite3ThreadSafeMalloc, sqlite3ThreadSafeFree, 0, 0};
+static Hash lockHash = {SQLITE_HASH_BINARY, 0, 0, 0, 0, 0};
+static Hash openHash = {SQLITE_HASH_BINARY, 0, 0, 0, 0, 0};
#ifdef SQLITE_ENABLE_LOCKING_STYLE
/*
pLock->nRef--;
if( pLock->nRef==0 ){
sqlite3HashInsert(&lockHash, &pLock->key, sizeof(pLock->key), 0);
- sqlite3ThreadSafeFree(pLock);
+ sqlite3_free(pLock);
}
}
if( pOpen->nRef==0 ){
sqlite3HashInsert(&openHash, &pOpen->key, sizeof(pOpen->key), 0);
free(pOpen->aPending);
- sqlite3ThreadSafeFree(pOpen);
+ sqlite3_free(pOpen);
}
}
pLock = (struct lockInfo*)sqlite3HashFind(&lockHash, &key1, sizeof(key1));
if( pLock==0 ){
struct lockInfo *pOld;
- pLock = sqlite3ThreadSafeMalloc( sizeof(*pLock) );
+ pLock = sqlite3_malloc( sizeof(*pLock) );
if( pLock==0 ){
rc = 1;
goto exit_findlockinfo;
pOld = sqlite3HashInsert(&lockHash, &pLock->key, sizeof(key1), pLock);
if( pOld!=0 ){
assert( pOld==pLock );
- sqlite3ThreadSafeFree(pLock);
+ sqlite3_free(pLock);
rc = 1;
goto exit_findlockinfo;
}
pOpen = (struct openCnt*)sqlite3HashFind(&openHash, &key2, sizeof(key2));
if( pOpen==0 ){
struct openCnt *pOld;
- pOpen = sqlite3ThreadSafeMalloc( sizeof(*pOpen) );
+ pOpen = sqlite3_malloc( sizeof(*pOpen) );
if( pOpen==0 ){
releaseLockInfo(pLock);
rc = 1;
pOld = sqlite3HashInsert(&openHash, &pOpen->key, sizeof(key2), pOpen);
if( pOld!=0 ){
assert( pOld==pOpen );
- sqlite3ThreadSafeFree(pOpen);
+ sqlite3_free(pOpen);
releaseLockInfo(pLock);
rc = 1;
goto exit_findlockinfo;
pFile->isOpen = 0;
OSTRACE2("CLOSE %-3d\n", pFile->h);
OpenCounter(-1);
- sqlite3ThreadSafeFree(id);
+ sqlite3_free(id);
return SQLITE_OK;
}
/* free the AFP locking structure */
if (id->lockingContext != NULL) {
if (((afpLockingContext *)id->lockingContext)->filePath != NULL)
- sqlite3ThreadSafeFree(((afpLockingContext*)id->lockingContext)->filePath);
- sqlite3ThreadSafeFree(id->lockingContext);
+ sqlite3_free(((afpLockingContext*)id->lockingContext)->filePath);
+ sqlite3_free(id->lockingContext);
}
if( id->dirfd>=0 ) close(id->dirfd);
id->isOpen = 0;
OSTRACE2("CLOSE %-3d\n", id->h);
OpenCounter(-1);
- sqlite3ThreadSafeFree(id);
+ sqlite3_free(id);
*pId = 0;
return SQLITE_OK;
}
id->isOpen = 0;
OSTRACE2("CLOSE %-3d\n", id->h);
OpenCounter(-1);
- sqlite3ThreadSafeFree(id);
+ sqlite3_free(id);
*pId = 0;
return SQLITE_OK;
}
/* free the dotlock locking structure */
if (id->lockingContext != NULL) {
if (((dotlockLockingContext *)id->lockingContext)->lockPath != NULL)
- sqlite3ThreadSafeFree( ( (dotlockLockingContext *)
+ sqlite3_free( ( (dotlockLockingContext *)
id->lockingContext)->lockPath);
- sqlite3ThreadSafeFree(id->lockingContext);
+ sqlite3_free(id->lockingContext);
}
if( id->dirfd>=0 ) close(id->dirfd);
id->isOpen = 0;
OSTRACE2("CLOSE %-3d\n", id->h);
OpenCounter(-1);
- sqlite3ThreadSafeFree(id);
+ sqlite3_free(id);
*pId = 0;
return SQLITE_OK;
}
id->isOpen = 0;
OSTRACE2("CLOSE %-3d\n", id->h);
OpenCounter(-1);
- sqlite3ThreadSafeFree(id);
+ sqlite3_free(id);
*pId = 0;
return SQLITE_OK;
}
if( zRelative[0]=='/' ){
sqlite3SetString(&zFull, zRelative, (char*)0);
}else{
- char *zBuf = sqliteMalloc(5000);
+ char *zBuf = sqlite3_malloc(5000);
if( zBuf==0 ){
return 0;
}
f.dirfd = -1;
f.h = h;
SET_THREADID(&f);
- pNew = sqlite3ThreadSafeMalloc( sizeof(unixFile) );
+ pNew = sqlite3_malloc( sizeof(unixFile) );
if( pNew==0 ){
close(h);
sqlite3OsEnterMutex();
int nFilename;
pNew->pMethod = &sqlite3AFPLockingUnixIoMethod;
pNew->lockingContext =
- sqlite3ThreadSafeMalloc(sizeof(afpLockingContext));
+ sqlite3_malloc(sizeof(afpLockingContext));
nFilename = strlen(zFilename)+1;
((afpLockingContext *)pNew->lockingContext)->filePath =
- sqlite3ThreadSafeMalloc(nFilename);
+ sqlite3_malloc(nFilename);
memcpy(((afpLockingContext *)pNew->lockingContext)->filePath,
zFilename, nFilename);
srandomdev();
** the dotlockLockingContext */
int nFilename;
pNew->pMethod = &sqlite3DotlockLockingUnixIoMethod;
- pNew->lockingContext = sqlite3ThreadSafeMalloc(
+ pNew->lockingContext = sqlite3_malloc(
sizeof(dotlockLockingContext));
nFilename = strlen(zFilename) + 6;
((dotlockLockingContext *)pNew->lockingContext)->lockPath =
- sqlite3ThreadSafeMalloc( nFilename );
+ sqlite3_malloc( nFilename );
sqlite3_snprintf(nFilename,
((dotlockLockingContext *)pNew->lockingContext)->lockPath,
"%s.lock", zFilename);
f.dirfd = -1;
f.h = h;
SET_THREADID(&f);
- pNew = sqlite3ThreadSafeMalloc( sizeof(unixFile) );
+ pNew = sqlite3_malloc( sizeof(unixFile) );
if( pNew==0 ){
close(h);
sqlite3OsEnterMutex();
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.356 2007/08/15 17:08:46 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.357 2007/08/16 04:30:40 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
static void pager_resize_hash_table(Pager *pPager, int N){
PgHdr **aHash, *pPg;
assert( N>0 && (N&(N-1))==0 );
- aHash = sqliteMalloc( sizeof(aHash[0])*N );
+ aHash = sqlite3MallocZero( sizeof(aHash[0])*N );
if( aHash==0 ){
/* Failure to rehash is not an error. It is only a performance hit. */
return;
}
- sqliteFree(pPager->aHash);
+ sqlite3_free(pPager->aHash);
pPager->nHash = N;
pPager->aHash = aHash;
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
/*
** When this is called the journal file for pager pPager must be open.
** The master journal file name is read from the end of the file and
-** written into memory obtained from sqliteMalloc(). *pzMaster is
+** written into memory obtained from sqlite3_malloc(). *pzMaster is
** set to point at the memory and SQLITE_OK returned. The caller must
-** sqliteFree() *pzMaster.
+** sqlite3_free() *pzMaster.
**
** If no master journal file name is present *pzMaster is set to 0 and
** SQLITE_OK returned.
rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8);
if( rc!=SQLITE_OK || memcmp(aMagic, aJournalMagic, 8) ) return rc;
- *pzMaster = (char *)sqliteMalloc(len+1);
+ *pzMaster = (char *)sqlite3MallocZero(len+1);
if( !*pzMaster ){
return SQLITE_NOMEM;
}
rc = sqlite3OsRead(pJrnl, *pzMaster, len, szJ-16-len);
if( rc!=SQLITE_OK ){
- sqliteFree(*pzMaster);
+ sqlite3_free(*pzMaster);
*pzMaster = 0;
return rc;
}
** definitely roll back, so just return SQLITE_OK and report a (nul)
** master-journal filename.
*/
- sqliteFree(*pzMaster);
+ sqlite3_free(*pzMaster);
*pzMaster = 0;
}else{
(*pzMaster)[len] = '\0';
IOTRACE(("PGFREE %p %d\n", pPager, pPg->pgno));
PAGER_INCR(sqlite3_pager_pgfree_count);
pNext = pPg->pNextAll;
- sqliteFree(pPg);
+ sqlite3_free(pPg);
}
pPager->pStmt = 0;
pPager->pFirst = 0;
pPager->pLast = 0;
pPager->pAll = 0;
pPager->nHash = 0;
- sqliteFree(pPager->aHash);
+ sqlite3_free(pPager->aHash);
pPager->nPage = 0;
pPager->aHash = 0;
pPager->nRef = 0;
rc = sqlite3OsDelete(pPager->zJournal);
}
}
- sqliteFree( pPager->aInJournal );
+ sqlite3_free( pPager->aInJournal );
pPager->aInJournal = 0;
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
pPg->inJournal = 0;
char *zMasterPtr = 0;
/* Load the entire master journal file into space obtained from
- ** sqliteMalloc() and pointed to by zMasterJournal.
+ ** sqlite3_malloc() and pointed to by zMasterJournal.
*/
- zMasterJournal = (char *)sqliteMalloc(nMasterJournal);
+ zMasterJournal = (char *)sqlite3_malloc(nMasterJournal);
if( !zMasterJournal ){
rc = SQLITE_NOMEM;
goto delmaster_out;
}
c = zMasterPtr!=0 && strcmp(zMasterPtr, zMaster)==0;
- sqliteFree(zMasterPtr);
+ sqlite3_free(zMasterPtr);
if( c ){
/* We have a match. Do not delete the master journal file. */
goto delmaster_out;
delmaster_out:
if( zMasterJournal ){
- sqliteFree(zMasterJournal);
+ sqlite3_free(zMasterJournal);
}
if( master_open ){
sqlite3OsClose(&master);
rc = readMasterJournal(pPager->jfd, &zMaster);
assert( rc!=SQLITE_DONE );
if( rc!=SQLITE_OK || (zMaster && !sqlite3OsFileExists(zMaster)) ){
- sqliteFree(zMaster);
+ sqlite3_free(zMaster);
zMaster = 0;
if( rc==SQLITE_DONE ) rc = SQLITE_OK;
goto end_playback;
if( rc==SQLITE_OK ){
rc = pager_delmaster(zMaster);
}
- sqliteFree(zMaster);
+ sqlite3_free(zMaster);
}
/* The Pager.sectorSize variable may have been updated while rolling
/* We used to test if malloc() had already failed before proceeding.
** But the way this function is used in SQLite means that can never
** happen. Furthermore, if the malloc-failed flag is already set,
- ** either the call to sqliteStrDup() or sqliteMalloc() below will
+ ** either the call to sqlite3StrDup() or sqlite3_malloc() below will
** fail shortly and SQLITE_NOMEM returned anyway.
*/
*ppPager = 0;
#ifndef SQLITE_OMIT_MEMORYDB
if( strcmp(zFilename,":memory:")==0 ){
memDb = 1;
- zFullPathname = sqliteStrDup("");
+ zFullPathname = sqlite3StrDup("");
}else
#endif
{
*/
if( zFullPathname ){
nameLen = strlen(zFullPathname);
- pPager = sqliteMalloc( sizeof(*pPager) + nameLen*3 + 30 );
+ pPager = sqlite3MallocZero( sizeof(*pPager) + nameLen*3 + 30 );
if( pPager && rc==SQLITE_OK ){
- pPager->pTmpSpace = (char *)sqliteMallocRaw(SQLITE_DEFAULT_PAGE_SIZE);
+ pPager->pTmpSpace = (char *)sqlite3_malloc(SQLITE_DEFAULT_PAGE_SIZE);
}
}
*/
if( !pPager || !zFullPathname || !pPager->pTmpSpace || rc!=SQLITE_OK ){
sqlite3OsClose(&fd);
- sqliteFree(zFullPathname);
- sqliteFree(pPager);
+ sqlite3_free(zFullPathname);
+ sqlite3_free(pPager);
return ((rc==SQLITE_OK)?SQLITE_NOMEM:rc);
}
for(i=nameLen; i>0 && pPager->zDirectory[i-1]!='/'; i--){}
if( i>0 ) pPager->zDirectory[i-1] = 0;
memcpy(pPager->zJournal, zFullPathname,nameLen);
- sqliteFree(zFullPathname);
+ sqlite3_free(zFullPathname);
memcpy(&pPager->zJournal[nameLen], "-journal",sizeof("-journal"));
pPager->fd = fd;
/* pPager->journalOpen = 0; */
if( !pPager->memDb && pPager->nRef==0 ){
pager_reset(pPager);
pPager->pageSize = pageSize;
- pPager->pTmpSpace = sqlite3ReallocOrFree(pPager->pTmpSpace, pageSize);
+ sqlite3_free(pPager->pTmpSpace);
+ pPager->pTmpSpace = sqlite3_malloc(pageSize);
}
return pPager->pageSize;
}
** Clear a PgHistory block
*/
static void clearHistory(PgHistory *pHist){
- sqliteFree(pHist->pOrig);
- sqliteFree(pHist->pStmt);
+ sqlite3_free(pHist->pOrig);
+ sqlite3_free(pHist->pStmt);
pHist->pOrig = 0;
pHist->pStmt = 0;
}
PAGER_INCR(sqlite3_pager_pgfree_count);
unlinkPage(pPg);
makeClean(pPg);
- sqliteFree(pPg);
+ sqlite3_free(pPg);
pPager->nPage--;
}
}
if( pPager->journalOpen ){
sqlite3OsClose(&pPager->jfd);
}
- sqliteFree(pPager->aInJournal);
+ sqlite3_free(pPager->aInJournal);
if( pPager->stmtOpen ){
sqlite3OsClose(&pPager->stfd);
}
pTmp->pNext = pPager->pNext;
}
#endif
- sqliteFree(pPager->aHash);
- sqliteFree(pPager->pTmpSpace);
- sqliteFree(pPager);
+ sqlite3_free(pPager->aHash);
+ sqlite3_free(pPager->pTmpSpace);
+ sqlite3_free(pPager);
return SQLITE_OK;
}
/*
** This function is called to free superfluous dynamically allocated memory
** held by the pager system. Memory in use by any SQLite pager allocated
-** by the current thread may be sqliteFree()ed.
+** by the current thread may be sqlite3_free()ed.
**
** nReq is the number of bytes of memory required. Once this much has
** been released, the function returns. A negative value for nReq means
nReleased += sqliteAllocSize(pPg);
IOTRACE(("PGFREE %p %d *\n", pPager, pPg->pgno));
PAGER_INCR(sqlite3_pager_pgfree_count);
- sqliteFree(pPg);
+ sqlite3_free(pPg);
}
if( rc!=SQLITE_OK ){
goto pager_allocate_out;
}
}
- pPg = sqliteMallocRaw( sizeof(*pPg) + pPager->pageSize
+ pPg = sqlite3_malloc( sizeof(*pPg) + pPager->pageSize
+ sizeof(u32) + pPager->nExtra
+ MEMDB*sizeof(PgHistory) );
if( pPg==0 ){
assert( pPager->useJournal );
assert( pPager->aInJournal==0 );
sqlite3PagerPagecount(pPager);
- pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 );
+ pPager->aInJournal = sqlite3MallocZero( pPager->dbSize/8 + 1 );
if( pPager->aInJournal==0 ){
rc = SQLITE_NOMEM;
goto failed_to_open_journal;
return rc;
failed_to_open_journal:
- sqliteFree(pPager->aInJournal);
+ sqlite3_free(pPager->aInJournal);
pPager->aInJournal = 0;
return rc;
}
assert( pPager->origDbSize==0 );
assert( pPager->aInJournal==0 );
sqlite3PagerPagecount(pPager);
- pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 );
+ pPager->aInJournal = sqlite3MallocZero( pPager->dbSize/8 + 1 );
if( !pPager->aInJournal ){
rc = SQLITE_NOMEM;
}else{
PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
PAGERTRACE3("JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
assert( pHist->pOrig==0 );
- pHist->pOrig = sqliteMallocRaw( pPager->pageSize );
+ pHist->pOrig = sqlite3_malloc( pPager->pageSize );
if( pHist->pOrig ){
memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize);
}
if( MEMDB ){
PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
assert( pHist->pStmt==0 );
- pHist->pStmt = sqliteMallocRaw( pPager->pageSize );
+ pHist->pStmt = sqlite3_malloc( pPager->pageSize );
if( pHist->pStmt ){
memcpy(pHist->pStmt, PGHDR_TO_DATA(pPg), pPager->pageSize);
}
return SQLITE_OK;
}
assert( pPager->journalOpen );
- pPager->aInStmt = sqliteMalloc( pPager->dbSize/8 + 1 );
+ pPager->aInStmt = sqlite3MallocZero( pPager->dbSize/8 + 1 );
if( pPager->aInStmt==0 ){
/* sqlite3OsLock(pPager->fd, SHARED_LOCK); */
return SQLITE_NOMEM;
stmt_begin_failed:
if( pPager->aInStmt ){
- sqliteFree(pPager->aInStmt);
+ sqlite3_free(pPager->aInStmt);
pPager->aInStmt = 0;
}
return rc;
PAGERTRACE2("STMT-COMMIT %d\n", PAGERID(pPager));
if( !MEMDB ){
/* sqlite3OsTruncate(pPager->stfd, 0); */
- sqliteFree( pPager->aInStmt );
+ sqlite3_free( pPager->aInStmt );
pPager->aInStmt = 0;
}else{
for(pPg=pPager->pStmt; pPg; pPg=pNext){
assert( pHist->inStmt );
pHist->inStmt = 0;
pHist->pPrevStmt = pHist->pNextStmt = 0;
- sqliteFree(pHist->pStmt);
+ sqlite3_free(pHist->pStmt);
pHist->pStmt = 0;
}
}
pHist = PGHDR_TO_HIST(pPg, pPager);
if( pHist->pStmt ){
memcpy(PGHDR_TO_DATA(pPg), pHist->pStmt, pPager->pageSize);
- sqliteFree(pHist->pStmt);
+ sqlite3_free(pHist->pStmt);
pHist->pStmt = 0;
}
}
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
-** @(#) $Id: parse.y,v 1.231 2007/06/20 12:18:31 drh Exp $
+** @(#) $Id: parse.y,v 1.232 2007/08/16 04:30:40 drh Exp $
*/
// All token codes are small integers with #defines that begin with "TK_"
ccons ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,X);}
ccons ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);}
ccons ::= DEFAULT MINUS term(X). {
- Expr *p = sqlite3Expr(TK_UMINUS, X, 0, 0);
+ Expr *p = sqlite3PExpr(pParse, TK_UMINUS, X, 0, 0);
sqlite3AddDefaultValue(pParse,p);
}
ccons ::= DEFAULT id(X). {
- Expr *p = sqlite3Expr(TK_STRING, 0, 0, &X);
+ Expr *p = sqlite3PExpr(pParse, TK_STRING, 0, 0, &X);
sqlite3AddDefaultValue(pParse,p);
}
%endif SQLITE_OMIT_COMPOUND_SELECT
oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
- A = sqlite3SelectNew(W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset);
+ A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset);
}
// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
sclp(A) ::= selcollist(X) COMMA. {A = X;}
sclp(A) ::= . {A = 0;}
selcollist(A) ::= sclp(P) expr(X) as(Y). {
- A = sqlite3ExprListAppend(P,X,Y.n?&Y:0);
+ A = sqlite3ExprListAppend(pParse,P,X,Y.n?&Y:0);
}
selcollist(A) ::= sclp(P) STAR. {
- A = sqlite3ExprListAppend(P, sqlite3Expr(TK_ALL, 0, 0, 0), 0);
+ Expr *p = sqlite3Expr(pParse, TK_ALL, 0, 0, 0);
+ A = sqlite3ExprListAppend(pParse, P, p, 0);
}
selcollist(A) ::= sclp(P) nm(X) DOT STAR. {
- Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0);
- Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &X);
- A = sqlite3ExprListAppend(P, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0);
+ Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
+ Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
+ Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
+ A = sqlite3ExprListAppend(pParse,P, pDot, 0);
}
// An option "AS <id>" phrase that can follow one of the expressions that
// A complete FROM clause.
//
-from(A) ::= . {A = sqliteMalloc(sizeof(*A));}
-from(A) ::= FROM seltablist(X). {
+from(A) ::= . {A = sqlite3DbMallocZero(pParse->db, sizeof(*A));}
+from(A) ::= FROM seltablist(X). {
A = X;
sqlite3SrcListShiftJoinType(A);
}
}
stl_prefix(A) ::= . {A = 0;}
seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). {
- A = sqlite3SrcListAppendFromTerm(X,&Y,&D,&Z,0,N,U);
+ A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U);
}
%ifndef SQLITE_OMIT_SUBQUERY
seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
as(Z) on_opt(N) using_opt(U). {
- A = sqlite3SrcListAppendFromTerm(X,0,0,&Z,S,N,U);
+ A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U);
}
// A seltablist_paren nonterminal represents anything in a FROM that
seltablist_paren(A) ::= select(S). {A = S;}
seltablist_paren(A) ::= seltablist(F). {
sqlite3SrcListShiftJoinType(F);
- A = sqlite3SelectNew(0,F,0,0,0,0,0,0,0);
+ A = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0);
}
%endif SQLITE_OMIT_SUBQUERY
%type fullname {SrcList*}
%destructor fullname {sqlite3SrcListDelete($$);}
-fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(0,&X,&Y);}
+fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(pParse->db,0,&X,&Y);}
%type joinop {int}
%type joinop2 {int}
orderby_opt(A) ::= . {A = 0;}
orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
- A = sqlite3ExprListAppend(X,Y,0);
+ A = sqlite3ExprListAppend(pParse,X,Y,0);
if( A ) A->a[A->nExpr-1].sortOrder = Z;
}
sortlist(A) ::= sortitem(Y) sortorder(Z). {
- A = sqlite3ExprListAppend(0,Y,0);
+ A = sqlite3ExprListAppend(pParse,0,Y,0);
if( A && A->a ) A->a[0].sortOrder = Z;
}
sortitem(A) ::= expr(X). {A = X;}
%destructor setlist {sqlite3ExprListDelete($$);}
setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
- {A = sqlite3ExprListAppend(Z,Y,&X);}
-setlist(A) ::= nm(X) EQ expr(Y). {A = sqlite3ExprListAppend(0,Y,&X);}
+ {A = sqlite3ExprListAppend(pParse,Z,Y,&X);}
+setlist(A) ::= nm(X) EQ expr(Y).
+ {A = sqlite3ExprListAppend(pParse,0,Y,&X);}
////////////////////////// The INSERT command /////////////////////////////////
//
%type itemlist {ExprList*}
%destructor itemlist {sqlite3ExprListDelete($$);}
-itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqlite3ExprListAppend(X,Y,0);}
-itemlist(A) ::= expr(X). {A = sqlite3ExprListAppend(0,X,0);}
+itemlist(A) ::= itemlist(X) COMMA expr(Y).
+ {A = sqlite3ExprListAppend(pParse,X,Y,0);}
+itemlist(A) ::= expr(X).
+ {A = sqlite3ExprListAppend(pParse,0,X,0);}
%type inscollist_opt {IdList*}
%destructor inscollist_opt {sqlite3IdListDelete($$);}
inscollist_opt(A) ::= . {A = 0;}
inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
-inscollist(A) ::= inscollist(X) COMMA nm(Y). {A = sqlite3IdListAppend(X,&Y);}
-inscollist(A) ::= nm(Y). {A = sqlite3IdListAppend(0,&Y);}
+inscollist(A) ::= inscollist(X) COMMA nm(Y).
+ {A = sqlite3IdListAppend(pParse->db,X,&Y);}
+inscollist(A) ::= nm(Y).
+ {A = sqlite3IdListAppend(pParse->db,0,&Y);}
/////////////////////////// Expression Processing /////////////////////////////
//
expr(A) ::= term(X). {A = X;}
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); }
-term(A) ::= NULL(X). {A = sqlite3Expr(@X, 0, 0, &X);}
-expr(A) ::= ID(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);}
-expr(A) ::= JOIN_KW(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);}
+term(A) ::= NULL(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);}
+expr(A) ::= ID(X). {A = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);}
+expr(A) ::= JOIN_KW(X). {A = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);}
expr(A) ::= nm(X) DOT nm(Y). {
- Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &X);
- Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &Y);
- A = sqlite3Expr(TK_DOT, temp1, temp2, 0);
+ Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
+ Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Y);
+ A = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
}
expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
- Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &X);
- Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &Y);
- Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &Z);
- Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
- A = sqlite3Expr(TK_DOT, temp1, temp4, 0);
+ Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
+ Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Y);
+ Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Z);
+ Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
+ A = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
}
-term(A) ::= INTEGER|FLOAT|BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
-term(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);}
+term(A) ::= INTEGER|FLOAT|BLOB(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);}
+term(A) ::= STRING(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);}
expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);}
expr(A) ::= VARIABLE(X). {
Token *pToken = &X;
- Expr *pExpr = A = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
+ Expr *pExpr = A = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken);
sqlite3ExprAssignVarNumber(pParse, pExpr);
}
expr(A) ::= expr(E) COLLATE id(C). {
}
%ifndef SQLITE_OMIT_CAST
expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). {
- A = sqlite3Expr(TK_CAST, E, 0, &T);
+ A = sqlite3PExpr(pParse, TK_CAST, E, 0, &T);
sqlite3ExprSpan(A,&X,&Y);
}
%endif SQLITE_OMIT_CAST
if( Y && Y->nExpr>SQLITE_MAX_FUNCTION_ARG ){
sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X);
}
- A = sqlite3ExprFunction(Y, &X);
+ A = sqlite3ExprFunction(pParse, Y, &X);
sqlite3ExprSpan(A,&X,&E);
if( D && A ){
A->flags |= EP_Distinct;
}
}
expr(A) ::= ID(X) LP STAR RP(E). {
- A = sqlite3ExprFunction(0, &X);
+ A = sqlite3ExprFunction(pParse, 0, &X);
sqlite3ExprSpan(A,&X,&E);
}
term(A) ::= CTIME_KW(OP). {
/* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
** treated as functions that return constants */
- A = sqlite3ExprFunction(0,&OP);
+ A = sqlite3ExprFunction(pParse, 0,&OP);
if( A ){
A->op = TK_CONST_FUNC;
A->span = OP;
}
}
-expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
-expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
-expr(A) ::= expr(X) LT|GT|GE|LE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
-expr(A) ::= expr(X) EQ|NE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
+expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
+expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
+expr(A) ::= expr(X) LT|GT|GE|LE(OP) expr(Y).
+ {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
+expr(A) ::= expr(X) EQ|NE(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
expr(A) ::= expr(X) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y).
- {A = sqlite3Expr(@OP, X, Y, 0);}
-expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
-expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
-expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
+ {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
+expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y).{A = sqlite3PExpr(pParse,@OP,X,Y,0);}
+expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y).
+ {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
+expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
%type likeop {struct LikeOp}
likeop(A) ::= LIKE_KW(X). {A.eOperator = X; A.not = 0;}
likeop(A) ::= NOT LIKE_KW(X). {A.eOperator = X; A.not = 1;}
escape(X) ::= . [ESCAPE] {X = 0;}
expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE_KW] {
ExprList *pList;
- pList = sqlite3ExprListAppend(0, Y, 0);
- pList = sqlite3ExprListAppend(pList, X, 0);
+ pList = sqlite3ExprListAppend(pParse,0, Y, 0);
+ pList = sqlite3ExprListAppend(pParse,pList, X, 0);
if( E ){
- pList = sqlite3ExprListAppend(pList, E, 0);
+ pList = sqlite3ExprListAppend(pParse,pList, E, 0);
}
- A = sqlite3ExprFunction(pList, &OP.eOperator);
- if( OP.not ) A = sqlite3Expr(TK_NOT, A, 0, 0);
+ A = sqlite3ExprFunction(pParse, pList, &OP.eOperator);
+ if( OP.not ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
sqlite3ExprSpan(A, &X->span, &Y->span);
if( A ) A->flags |= EP_InfixFunc;
}
expr(A) ::= expr(X) ISNULL|NOTNULL(E). {
- A = sqlite3Expr(@E, X, 0, 0);
+ A = sqlite3PExpr(pParse, @E, X, 0, 0);
sqlite3ExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) IS NULL(E). {
- A = sqlite3Expr(TK_ISNULL, X, 0, 0);
+ A = sqlite3PExpr(pParse, TK_ISNULL, X, 0, 0);
sqlite3ExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) NOT NULL(E). {
- A = sqlite3Expr(TK_NOTNULL, X, 0, 0);
+ A = sqlite3PExpr(pParse, TK_NOTNULL, X, 0, 0);
sqlite3ExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) IS NOT NULL(E). {
- A = sqlite3Expr(TK_NOTNULL, X, 0, 0);
+ A = sqlite3PExpr(pParse, TK_NOTNULL, X, 0, 0);
sqlite3ExprSpan(A,&X->span,&E);
}
expr(A) ::= NOT|BITNOT(B) expr(X). {
- A = sqlite3Expr(@B, X, 0, 0);
+ A = sqlite3PExpr(pParse, @B, X, 0, 0);
sqlite3ExprSpan(A,&B,&X->span);
}
expr(A) ::= MINUS(B) expr(X). [UMINUS] {
- A = sqlite3Expr(TK_UMINUS, X, 0, 0);
+ A = sqlite3PExpr(pParse, TK_UMINUS, X, 0, 0);
sqlite3ExprSpan(A,&B,&X->span);
}
expr(A) ::= PLUS(B) expr(X). [UPLUS] {
- A = sqlite3Expr(TK_UPLUS, X, 0, 0);
+ A = sqlite3PExpr(pParse, TK_UPLUS, X, 0, 0);
sqlite3ExprSpan(A,&B,&X->span);
}
%type between_op {int}
between_op(A) ::= BETWEEN. {A = 0;}
between_op(A) ::= NOT BETWEEN. {A = 1;}
expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
- ExprList *pList = sqlite3ExprListAppend(0, X, 0);
- pList = sqlite3ExprListAppend(pList, Y, 0);
- A = sqlite3Expr(TK_BETWEEN, W, 0, 0);
+ ExprList *pList = sqlite3ExprListAppend(pParse,0, X, 0);
+ pList = sqlite3ExprListAppend(pParse,pList, Y, 0);
+ A = sqlite3PExpr(pParse, TK_BETWEEN, W, 0, 0);
if( A ){
A->pList = pList;
}else{
sqlite3ExprListDelete(pList);
}
- if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
+ if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
sqlite3ExprSpan(A,&W->span,&Y->span);
}
%ifndef SQLITE_OMIT_SUBQUERY
in_op(A) ::= IN. {A = 0;}
in_op(A) ::= NOT IN. {A = 1;}
expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] {
- A = sqlite3Expr(TK_IN, X, 0, 0);
+ A = sqlite3PExpr(pParse, TK_IN, X, 0, 0);
if( A ){
A->pList = Y;
sqlite3ExprSetHeight(A);
}else{
sqlite3ExprListDelete(Y);
}
- if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
+ if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
sqlite3ExprSpan(A,&X->span,&E);
}
expr(A) ::= LP(B) select(X) RP(E). {
- A = sqlite3Expr(TK_SELECT, 0, 0, 0);
+ A = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
if( A ){
A->pSelect = X;
sqlite3ExprSetHeight(A);
sqlite3ExprSpan(A,&B,&E);
}
expr(A) ::= expr(X) in_op(N) LP select(Y) RP(E). [IN] {
- A = sqlite3Expr(TK_IN, X, 0, 0);
+ A = sqlite3PExpr(pParse, TK_IN, X, 0, 0);
if( A ){
A->pSelect = Y;
sqlite3ExprSetHeight(A);
}else{
sqlite3SelectDelete(Y);
}
- if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
+ if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
sqlite3ExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) in_op(N) nm(Y) dbnm(Z). [IN] {
- SrcList *pSrc = sqlite3SrcListAppend(0,&Y,&Z);
- A = sqlite3Expr(TK_IN, X, 0, 0);
+ SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&Y,&Z);
+ A = sqlite3PExpr(pParse, TK_IN, X, 0, 0);
if( A ){
A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
sqlite3ExprSetHeight(A);
}else{
sqlite3SrcListDelete(pSrc);
}
- if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
+ if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
sqlite3ExprSpan(A,&X->span,Z.z?&Z:&Y);
}
expr(A) ::= EXISTS(B) LP select(Y) RP(E). {
- Expr *p = A = sqlite3Expr(TK_EXISTS, 0, 0, 0);
+ Expr *p = A = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
if( p ){
p->pSelect = Y;
sqlite3ExprSpan(p,&B,&E);
/* CASE expressions */
expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
- A = sqlite3Expr(TK_CASE, X, Z, 0);
+ A = sqlite3PExpr(pParse, TK_CASE, X, Z, 0);
if( A ){
A->pList = Y;
sqlite3ExprSetHeight(A);
%type case_exprlist {ExprList*}
%destructor case_exprlist {sqlite3ExprListDelete($$);}
case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). {
- A = sqlite3ExprListAppend(X, Y, 0);
- A = sqlite3ExprListAppend(A, Z, 0);
+ A = sqlite3ExprListAppend(pParse,X, Y, 0);
+ A = sqlite3ExprListAppend(pParse,A, Z, 0);
}
case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
- A = sqlite3ExprListAppend(0, Y, 0);
- A = sqlite3ExprListAppend(A, Z, 0);
+ A = sqlite3ExprListAppend(pParse,0, Y, 0);
+ A = sqlite3ExprListAppend(pParse,A, Z, 0);
}
%type case_else {Expr*}
%destructor case_else {sqlite3ExprDelete($$);}
exprlist(A) ::= nexprlist(X). {A = X;}
exprlist(A) ::= . {A = 0;}
-nexprlist(A) ::= nexprlist(X) COMMA expr(Y). {A = sqlite3ExprListAppend(X,Y,0);}
-nexprlist(A) ::= expr(Y). {A = sqlite3ExprListAppend(0,Y,0);}
+nexprlist(A) ::= nexprlist(X) COMMA expr(Y).
+ {A = sqlite3ExprListAppend(pParse,X,Y,0);}
+nexprlist(A) ::= expr(Y).
+ {A = sqlite3ExprListAppend(pParse,0,Y,0);}
///////////////////////////// The CREATE INDEX command ///////////////////////
//
cmd ::= CREATE(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D)
ON nm(Y) LP idxlist(Z) RP(E). {
- sqlite3CreateIndex(pParse, &X, &D, sqlite3SrcListAppend(0,&Y,0), Z, U,
+ sqlite3CreateIndex(pParse, &X, &D,
+ sqlite3SrcListAppend(pParse->db,0,&Y,0), Z, U,
&S, &E, SQLITE_SO_ASC, NE);
}
idxlist(A) ::= idxlist(X) COMMA idxitem(Y) collate(C) sortorder(Z). {
Expr *p = 0;
if( C.n>0 ){
- p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
+ p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)C.z, C.n);
}
- A = sqlite3ExprListAppend(X, p, &Y);
+ A = sqlite3ExprListAppend(pParse,X, p, &Y);
sqlite3ExprListCheckLength(pParse, A, SQLITE_MAX_COLUMN, "index");
if( A ) A->a[A->nExpr-1].sortOrder = Z;
}
idxlist(A) ::= idxitem(Y) collate(C) sortorder(Z). {
Expr *p = 0;
if( C.n>0 ){
- p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
+ p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)C.z, C.n);
}
- A = sqlite3ExprListAppend(0, p, &Y);
+ A = sqlite3ExprListAppend(pParse,0, p, &Y);
sqlite3ExprListCheckLength(pParse, A, SQLITE_MAX_COLUMN, "index");
if( A ) A->a[A->nExpr-1].sortOrder = Z;
}
%destructor trigger_cmd {sqlite3DeleteTriggerStep($$);}
// UPDATE
trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
- { A = sqlite3TriggerUpdateStep(&X, Y, Z, R); }
+ { A = sqlite3TriggerUpdateStep(pParse->db, &X, Y, Z, R); }
// INSERT
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F)
VALUES LP itemlist(Y) RP.
- {A = sqlite3TriggerInsertStep(&X, F, Y, 0, R);}
+ {A = sqlite3TriggerInsertStep(pParse->db, &X, F, Y, 0, R);}
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S).
- {A = sqlite3TriggerInsertStep(&X, F, 0, S, R);}
+ {A = sqlite3TriggerInsertStep(pParse->db, &X, F, 0, S, R);}
// DELETE
trigger_cmd(A) ::= DELETE FROM nm(X) where_opt(Y).
- {A = sqlite3TriggerDeleteStep(&X, Y);}
+ {A = sqlite3TriggerDeleteStep(pParse->db, &X, Y);}
// SELECT
-trigger_cmd(A) ::= select(X). {A = sqlite3TriggerSelectStep(X); }
+trigger_cmd(A) ::= select(X). {A = sqlite3TriggerSelectStep(pParse->db, X); }
// The special RAISE expression that may occur in trigger programs
expr(A) ::= RAISE(X) LP IGNORE RP(Y). {
- A = sqlite3Expr(TK_RAISE, 0, 0, 0);
+ A = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
if( A ){
A->iColumn = OE_Ignore;
sqlite3ExprSpan(A, &X, &Y);
}
}
expr(A) ::= RAISE(X) LP raisetype(T) COMMA nm(Z) RP(Y). {
- A = sqlite3Expr(TK_RAISE, 0, 0, &Z);
+ A = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &Z);
if( A ) {
A->iColumn = T;
sqlite3ExprSpan(A, &X, &Y);
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
-** $Id: pragma.c,v 1.142 2007/06/26 10:38:55 danielk1977 Exp $
+** $Id: pragma.c,v 1.143 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
return;
}
- zLeft = sqlite3NameFromToken(pId);
+ zLeft = sqlite3NameFromToken(db, pId);
if( !zLeft ) return;
if( minusFlag ){
- zRight = sqlite3MPrintf("-%T", pValue);
+ zRight = sqlite3MPrintf(db, "-%T", pValue);
}else{
- zRight = sqlite3NameFromToken(pValue);
+ zRight = sqlite3NameFromToken(db, pValue);
}
zDb = ((iDb>0)?pDb->zName:0);
){
invalidateTempStorage(pParse);
}
- sqliteFree(sqlite3_temp_directory);
+ sqlite3_free(sqlite3_temp_directory);
if( zRight[0] ){
sqlite3_temp_directory = zRight;
zRight = 0;
#endif
}
pragma_out:
- sqliteFree(zLeft);
- sqliteFree(zRight);
+ sqlite3_free(zLeft);
+ sqlite3_free(zRight);
}
#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */
** interface, and routines that contribute to loading the database schema
** from disk.
**
-** $Id: prepare.c,v 1.52 2007/08/13 14:41:19 danielk1977 Exp $
+** $Id: prepare.c,v 1.53 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
** that the database is corrupt.
*/
static void corruptSchema(InitData *pData, const char *zExtra){
- if( !sqlite3MallocFailed() ){
+ if( !pData->db->mallocFailed ){
sqlite3SetString(pData->pzErrMsg, "malformed database schema",
zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
}
pData->rc = SQLITE_OK;
DbClearProperty(db, iDb, DB_Empty);
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
corruptSchema(pData, 0);
return SQLITE_NOMEM;
}
if( SQLITE_OK!=rc ){
pData->rc = rc;
if( rc==SQLITE_NOMEM ){
- sqlite3FailedMalloc();
+ db->mallocFailed = 1;
}else if( rc!=SQLITE_INTERRUPT ){
corruptSchema(pData, zErr);
}
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
if( rc==SQLITE_ABORT ) rc = initData.rc;
sqlite3SafetyOn(db);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
#ifndef SQLITE_OMIT_ANALYZE
if( rc==SQLITE_OK ){
sqlite3AnalysisLoad(db, iDb);
#endif
sqlite3BtreeCloseCursor(curMain);
}
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
/* sqlite3SetString(pzErrMsg, "out of memory", (char*)0); */
rc = SQLITE_NOMEM;
sqlite3ResetInternalSchema(db, 0);
int i;
/* Assert that malloc() has not failed */
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
assert( ppStmt );
*ppStmt = 0;
if( nBytes>SQLITE_MAX_SQL_LENGTH ){
return SQLITE_TOOBIG;
}
- zSqlCopy = sqlite3StrNDup(zSql, nBytes);
+ zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
if( zSqlCopy ){
sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg);
- sqliteFree(zSqlCopy);
+ sqlite3_free(zSqlCopy);
}
sParse.zTail = &zSql[nBytes];
}else{
sqlite3RunParser(&sParse, zSql, &zErrMsg);
}
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
sParse.rc = SQLITE_NOMEM;
}
if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
if( sParse.rc==SQLITE_SCHEMA ){
sqlite3ResetInternalSchema(db, 0);
}
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
sParse.rc = SQLITE_NOMEM;
}
if( pzTail ){
if( saveSqlFlag ){
sqlite3VdbeSetSql(sParse.pVdbe, zSql, sParse.zTail - zSql);
}
- if( rc!=SQLITE_OK || sqlite3MallocFailed() ){
+ if( rc!=SQLITE_OK || db->mallocFailed ){
sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
assert(!(*ppStmt));
}else{
if( zErrMsg ){
sqlite3Error(db, rc, "%s", zErrMsg);
- sqliteFree(zErrMsg);
+ sqlite3_free(zErrMsg);
}else{
sqlite3Error(db, rc, 0);
}
int chars_parsed = sqlite3Utf8CharLen(zSql8, zTail8-zSql8);
*pzTail = (u8 *)zSql + sqlite3Utf16ByteLen(zSql, chars_parsed);
}
- sqliteFree(zSql8);
+ sqlite3_free(zSql8);
return sqlite3ApiExit(db, rc);
}
needQuote = !isnull && xtype==etSQLESCAPE2;
n += i + 1 + needQuote*2;
if( n>etBUFSIZE ){
- bufpt = zExtra = sqliteMalloc( n );
+ bufpt = zExtra = sqlite3_malloc( n );
if( bufpt==0 ) return -1;
}else{
bufpt = buf;
static void mout(void *arg, const char *zNewText, int nNewChar){
struct sgMprintf *pM = (struct sgMprintf*)arg;
pM->nTotal += nNewChar;
- if( pM->nChar + nNewChar + 1 > pM->nAlloc ){
- if( pM->xRealloc==0 ){
- nNewChar = pM->nAlloc - pM->nChar - 1;
- }else{
- int nAlloc = pM->nChar + nNewChar*2 + 1;
- if( pM->zText==pM->zBase ){
- pM->zText = pM->xRealloc(0, nAlloc);
- if( pM->zText && pM->nChar ){
- memcpy(pM->zText, pM->zBase, pM->nChar);
- }
+ if( pM->zText ){
+ if( pM->nChar + nNewChar + 1 > pM->nAlloc ){
+ if( pM->xRealloc==0 ){
+ nNewChar = pM->nAlloc - pM->nChar - 1;
}else{
- char *zNew;
- zNew = pM->xRealloc(pM->zText, nAlloc);
- if( zNew ){
- pM->zText = zNew;
+ int nAlloc = pM->nChar + nNewChar*2 + 1;
+ if( pM->zText==pM->zBase ){
+ pM->zText = pM->xRealloc(0, nAlloc);
+ if( pM->zText==0 ){
+ return;
+ }else if( pM->nChar ){
+ memcpy(pM->zText, pM->zBase, pM->nChar);
+ }
}else{
- return;
+ char *zNew;
+ zNew = pM->xRealloc(pM->zText, nAlloc);
+ if( zNew ){
+ pM->zText = zNew;
+ }else{
+ pM->xRealloc(pM->zText, 0);
+ pM->zText = 0;
+ return;
+ }
}
+ pM->nAlloc = nAlloc;
}
- pM->nAlloc = nAlloc;
}
- }
- if( pM->zText ){
if( nNewChar>0 ){
memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
pM->nChar += nNewChar;
** Realloc that is a real function, not a macro.
*/
static void *printf_realloc(void *old, int size){
- return sqliteRealloc(old,size);
+ return sqlite3_realloc(old,size);
}
/*
** Print into memory obtained from sqliteMalloc(). Use the internal
** %-conversion extensions.
*/
-char *sqlite3VMPrintf(const char *zFormat, va_list ap){
+char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
+ char *z;
char zBase[SQLITE_PRINT_BUF_SIZE];
- return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
+ z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
+ if( z==0 && db!=0 ){
+ db->mallocFailed = 1;
+ }
+ return z;
}
/*
** Print into memory obtained from sqliteMalloc(). Use the internal
** %-conversion extensions.
*/
-char *sqlite3MPrintf(const char *zFormat, ...){
+char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
va_list ap;
char *z;
char zBase[SQLITE_PRINT_BUF_SIZE];
va_start(ap, zFormat);
z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
va_end(ap);
+ if( z==0 && db!=0 ){
+ db->mallocFailed = 1;
+ }
return z;
}
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.354 2007/07/18 18:17:12 drh Exp $
+** $Id: select.c,v 1.355 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
** structure.
*/
Select *sqlite3SelectNew(
+ Parse *pParse, /* Parsing context */
ExprList *pEList, /* which columns to include in the result */
SrcList *pSrc, /* the FROM clause -- which tables to scan */
Expr *pWhere, /* the WHERE clause */
){
Select *pNew;
Select standin;
- pNew = sqliteMalloc( sizeof(*pNew) );
+ sqlite3 *db = pParse->db;
+ pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
assert( !pOffset || pLimit ); /* Can't have OFFSET without LIMIT. */
if( pNew==0 ){
pNew = &standin;
memset(pNew, 0, sizeof(*pNew));
}
if( pEList==0 ){
- pEList = sqlite3ExprListAppend(0, sqlite3Expr(TK_ALL,0,0,0), 0);
+ pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(TK_ALL,0,0,0), 0);
}
pNew->pEList = pEList;
pNew->pSrc = pSrc;
void sqlite3SelectDelete(Select *p){
if( p ){
clearSelect(p);
- sqliteFree(p);
+ sqlite3_free(p);
}
}
/*
** Create an expression node for an identifier with the name of zName
*/
-Expr *sqlite3CreateIdExpr(const char *zName){
+Expr *sqlite3CreateIdExpr(Parse *pParse, const char *zName){
Token dummy;
setToken(&dummy, zName);
- return sqlite3Expr(TK_ID, 0, 0, &dummy);
+ return sqlite3PExpr(pParse, TK_ID, 0, 0, &dummy);
}
** zCol column to be equal in the two tables pTab1 and pTab2.
*/
static void addWhereTerm(
+ Parse *pParse, /* Parsing context */
const char *zCol, /* Name of the column */
const Table *pTab1, /* First table */
const char *zAlias1, /* Alias for first table. May be NULL */
Expr *pE2a, *pE2b, *pE2c;
Expr *pE;
- pE1a = sqlite3CreateIdExpr(zCol);
- pE2a = sqlite3CreateIdExpr(zCol);
+ pE1a = sqlite3CreateIdExpr(pParse, zCol);
+ pE2a = sqlite3CreateIdExpr(pParse, zCol);
if( zAlias1==0 ){
zAlias1 = pTab1->zName;
}
- pE1b = sqlite3CreateIdExpr(zAlias1);
+ pE1b = sqlite3CreateIdExpr(pParse, zAlias1);
if( zAlias2==0 ){
zAlias2 = pTab2->zName;
}
- pE2b = sqlite3CreateIdExpr(zAlias2);
- pE1c = sqlite3ExprOrFree(TK_DOT, pE1b, pE1a, 0);
- pE2c = sqlite3ExprOrFree(TK_DOT, pE2b, pE2a, 0);
- pE = sqlite3ExprOrFree(TK_EQ, pE1c, pE2c, 0);
+ pE2b = sqlite3CreateIdExpr(pParse, zAlias2);
+ pE1c = sqlite3PExpr(pParse, TK_DOT, pE1b, pE1a, 0);
+ pE2c = sqlite3PExpr(pParse, TK_DOT, pE2b, pE2a, 0);
+ pE = sqlite3DbExpr(pParse, TK_EQ, pE1c, pE2c, 0);
if( pE ){
ExprSetProperty(pE, EP_FromJoin);
pE->iRightJoinTable = iRightJoinTable;
}
- pE = sqlite3ExprAnd(*ppExpr, pE);
+ pE = sqlite3ExprAnd(pParse->db,*ppExpr, pE);
if( pE ){
*ppExpr = pE;
}
*/
if( pRight->pOn ){
setJoinExpr(pRight->pOn, pRight->iCursor);
- p->pWhere = sqlite3ExprAnd(p->pWhere, pRight->pOn);
+ p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
pRight->pOn = 0;
}
int i;
nExpr = pList->nExpr;
- pInfo = sqliteMalloc( sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
+ pInfo = sqlite3DbMallocZero(db, sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
if( pInfo ){
pInfo->aSortOrder = (u8*)&pInfo->aColl[nExpr];
pInfo->nField = nExpr;
#endif
assert( v!=0 );
- if( pParse->colNamesSet || v==0 || sqlite3MallocFailed() ) return;
+ if( pParse->colNamesSet || v==0 || db->mallocFailed ) return;
pParse->colNamesSet = 1;
fullNames = (db->flags & SQLITE_FullColNames)!=0;
shortNames = (db->flags & SQLITE_ShortColNames)!=0;
int i, j;
ExprList *pEList;
Column *aCol, *pCol;
+ sqlite3 *db = pParse->db;
while( pSelect->pPrior ) pSelect = pSelect->pPrior;
if( prepSelectStmt(pParse, pSelect) ){
if( sqlite3SelectResolve(pParse, pSelect, 0) ){
return 0;
}
- pTab = sqliteMalloc( sizeof(Table) );
+ pTab = sqlite3DbMallocZero(db, sizeof(Table) );
if( pTab==0 ){
return 0;
}
pTab->nRef = 1;
- pTab->zName = zTabName ? sqliteStrDup(zTabName) : 0;
+ pTab->zName = zTabName ? sqlite3DbStrDup(db, zTabName) : 0;
pEList = pSelect->pEList;
pTab->nCol = pEList->nExpr;
assert( pTab->nCol>0 );
- pTab->aCol = aCol = sqliteMalloc( sizeof(pTab->aCol[0])*pTab->nCol );
+ pTab->aCol = aCol = sqlite3DbMallocZero(db, sizeof(pTab->aCol[0])*pTab->nCol);
for(i=0, pCol=aCol; i<pTab->nCol; i++, pCol++){
Expr *p, *pR;
char *zType;
assert( p->pRight==0 || p->pRight->token.z==0 || p->pRight->token.z[0]!=0 );
if( (zName = pEList->a[i].zName)!=0 ){
/* If the column contains an "AS <name>" phrase, use <name> as the name */
- zName = sqliteStrDup(zName);
+ zName = sqlite3DbStrDup(db, zName);
}else if( p->op==TK_DOT
&& (pR=p->pRight)!=0 && pR->token.z && pR->token.z[0] ){
/* For columns of the from A.B use B as the name */
- zName = sqlite3MPrintf("%T", &pR->token);
+ zName = sqlite3MPrintf(db, "%T", &pR->token);
}else if( p->span.z && p->span.z[0] ){
/* Use the original text of the column expression as its name */
- zName = sqlite3MPrintf("%T", &p->span);
+ zName = sqlite3MPrintf(db, "%T", &p->span);
}else{
/* If all else fails, make up a name */
- zName = sqlite3MPrintf("column%d", i+1);
+ zName = sqlite3MPrintf(db, "column%d", i+1);
}
sqlite3Dequote(zName);
- if( sqlite3MallocFailed() ){
- sqliteFree(zName);
+ if( db->mallocFailed ){
+ sqlite3_free(zName);
sqlite3DeleteTable(pTab);
return 0;
}
*/
memset(&sNC, 0, sizeof(sNC));
sNC.pSrcList = pSelect->pSrc;
- zType = sqliteStrDup(columnType(&sNC, p, 0, 0, 0));
+ zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0));
pCol->zType = zType;
pCol->affinity = sqlite3ExprAffinity(p);
pColl = sqlite3ExprCollSeq(pParse, p);
if( pColl ){
- pCol->zColl = sqliteStrDup(pColl->zName);
+ pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
}
}
pTab->iPKey = -1;
SrcList *pTabList;
ExprList *pEList;
struct SrcList_item *pFrom;
+ sqlite3 *db = pParse->db;
- if( p==0 || p->pSrc==0 || sqlite3MallocFailed() ){
+ if( p==0 || p->pSrc==0 || db->mallocFailed ){
return 1;
}
pTabList = p->pSrc;
** in the inner view.
*/
if( pFrom->pSelect==0 ){
- pFrom->pSelect = sqlite3SelectDup(pTab->pSelect);
+ pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect);
}
}
#endif
(pE->op!=TK_DOT || pE->pRight==0 || pE->pRight->op!=TK_ALL) ){
/* This particular expression does not need to be expanded.
*/
- pNew = sqlite3ExprListAppend(pNew, a[k].pExpr, 0);
+ pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr, 0);
if( pNew ){
pNew->a[pNew->nExpr-1].zName = a[k].zName;
}else{
int tableSeen = 0; /* Set to 1 when TABLE matches */
char *zTName; /* text of name of TABLE */
if( pE->op==TK_DOT && pE->pLeft ){
- zTName = sqlite3NameFromToken(&pE->pLeft->token);
+ zTName = sqlite3NameFromToken(db, &pE->pLeft->token);
}else{
zTName = 0;
}
pExpr->span.dyn = 0;
}
if( longNames ){
- pNew = sqlite3ExprListAppend(pNew, pExpr, &pExpr->span);
+ pNew = sqlite3ExprListAppend(pParse, pNew, pExpr, &pExpr->span);
}else{
- pNew = sqlite3ExprListAppend(pNew, pExpr, &pRight->token);
+ pNew = sqlite3ExprListAppend(pParse, pNew, pExpr, &pRight->token);
}
}
}
}
rc = 1;
}
- sqliteFree(zTName);
+ sqlite3_free(zTName);
}
}
sqlite3ExprListDelete(pEList);
sqlite3ErrorMsg(pParse, "too many columns in result set");
rc = SQLITE_ERROR;
}
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
rc = SQLITE_NOMEM;
}
return rc;
int nErr = 0;
int i, j;
ExprList *pEList;
+ sqlite3 *db = pParse->db;
if( pSelect==0 || pOrderBy==0 ) return 1;
if( mustComplete ){
if( !mustComplete ) continue;
iCol--;
}
- if( iCol<0 && (zLabel = sqlite3NameFromToken(&pE->token))!=0 ){
+ if( iCol<0 && (zLabel = sqlite3NameFromToken(db, &pE->token))!=0 ){
for(j=0, pItem=pEList->a; j<pEList->nExpr; j++, pItem++){
char *zName;
int isMatch;
if( pItem->zName ){
- zName = sqlite3StrDup(pItem->zName);
+ zName = sqlite3DbStrDup(db, pItem->zName);
}else{
- zName = sqlite3NameFromToken(&pItem->pExpr->token);
+ zName = sqlite3NameFromToken(db, &pItem->pExpr->token);
}
isMatch = zName && sqlite3StrICmp(zName, zLabel)==0;
- sqliteFree(zName);
+ sqlite3_free(zName);
if( isMatch ){
iCol = j;
break;
}
}
- sqliteFree(zLabel);
+ sqlite3_free(zLabel);
}
if( iCol>=0 ){
pE->op = TK_COLUMN;
assert( p->pRightmost==p );
nKeyCol = nCol + (pOrderBy ? pOrderBy->nExpr : 0);
- pKeyInfo = sqliteMalloc(sizeof(*pKeyInfo)+nKeyCol*(sizeof(CollSeq*) + 1));
+ pKeyInfo = sqlite3DbMallocZero(pParse->db,
+ sizeof(*pKeyInfo)+nKeyCol*(sizeof(CollSeq*) + 1));
if( !pKeyInfo ){
rc = SQLITE_NOMEM;
goto multi_select_end;
generateSortTail(pParse, p, v, p->pEList->nExpr, eDest, iParm);
}
- sqliteFree(pKeyInfo);
+ sqlite3_free(pKeyInfo);
}
multi_select_end:
#endif /* SQLITE_OMIT_COMPOUND_SELECT */
#ifndef SQLITE_OMIT_VIEW
+/* Forward Declarations */
+static void substExprList(sqlite3*, ExprList*, int, ExprList*);
+static void substSelect(sqlite3*, Select *, int, ExprList *);
+
/*
** Scan through the expression pExpr. Replace every reference to
** a column in table number iTable with a copy of the iColumn-th
** changes to pExpr so that it refers directly to the source table
** of the subquery rather the result set of the subquery.
*/
-static void substExprList(ExprList*,int,ExprList*); /* Forward Decl */
-static void substSelect(Select *, int, ExprList *); /* Forward Decl */
-static void substExpr(Expr *pExpr, int iTable, ExprList *pEList){
+static void substExpr(
+ sqlite3 *db, /* Report malloc errors to this connection */
+ Expr *pExpr, /* Expr in which substitution occurs */
+ int iTable, /* Table to be substituted */
+ ExprList *pEList /* Substitute expressions */
+){
if( pExpr==0 ) return;
if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
if( pExpr->iColumn<0 ){
assert( pNew!=0 );
pExpr->op = pNew->op;
assert( pExpr->pLeft==0 );
- pExpr->pLeft = sqlite3ExprDup(pNew->pLeft);
+ pExpr->pLeft = sqlite3ExprDup(db, pNew->pLeft);
assert( pExpr->pRight==0 );
- pExpr->pRight = sqlite3ExprDup(pNew->pRight);
+ pExpr->pRight = sqlite3ExprDup(db, pNew->pRight);
assert( pExpr->pList==0 );
- pExpr->pList = sqlite3ExprListDup(pNew->pList);
+ pExpr->pList = sqlite3ExprListDup(db, pNew->pList);
pExpr->iTable = pNew->iTable;
pExpr->pTab = pNew->pTab;
pExpr->iColumn = pNew->iColumn;
pExpr->iAgg = pNew->iAgg;
- sqlite3TokenCopy(&pExpr->token, &pNew->token);
- sqlite3TokenCopy(&pExpr->span, &pNew->span);
- pExpr->pSelect = sqlite3SelectDup(pNew->pSelect);
+ sqlite3TokenCopy(db, &pExpr->token, &pNew->token);
+ sqlite3TokenCopy(db, &pExpr->span, &pNew->span);
+ pExpr->pSelect = sqlite3SelectDup(db, pNew->pSelect);
pExpr->flags = pNew->flags;
}
}else{
- substExpr(pExpr->pLeft, iTable, pEList);
- substExpr(pExpr->pRight, iTable, pEList);
- substSelect(pExpr->pSelect, iTable, pEList);
- substExprList(pExpr->pList, iTable, pEList);
+ substExpr(db, pExpr->pLeft, iTable, pEList);
+ substExpr(db, pExpr->pRight, iTable, pEList);
+ substSelect(db, pExpr->pSelect, iTable, pEList);
+ substExprList(db, pExpr->pList, iTable, pEList);
}
}
-static void substExprList(ExprList *pList, int iTable, ExprList *pEList){
+static void substExprList(
+ sqlite3 *db, /* Report malloc errors here */
+ ExprList *pList, /* List to scan and in which to make substitutes */
+ int iTable, /* Table to be substituted */
+ ExprList *pEList /* Substitute values */
+){
int i;
if( pList==0 ) return;
for(i=0; i<pList->nExpr; i++){
- substExpr(pList->a[i].pExpr, iTable, pEList);
+ substExpr(db, pList->a[i].pExpr, iTable, pEList);
}
}
-static void substSelect(Select *p, int iTable, ExprList *pEList){
+static void substSelect(
+ sqlite3 *db, /* Report malloc errors here */
+ Select *p, /* SELECT statement in which to make substitutions */
+ int iTable, /* Table to be replaced */
+ ExprList *pEList /* Substitute values */
+){
if( !p ) return;
- substExprList(p->pEList, iTable, pEList);
- substExprList(p->pGroupBy, iTable, pEList);
- substExprList(p->pOrderBy, iTable, pEList);
- substExpr(p->pHaving, iTable, pEList);
- substExpr(p->pWhere, iTable, pEList);
- substSelect(p->pPrior, iTable, pEList);
+ substExprList(db, p->pEList, iTable, pEList);
+ substExprList(db, p->pGroupBy, iTable, pEList);
+ substExprList(db, p->pOrderBy, iTable, pEList);
+ substExpr(db, p->pHaving, iTable, pEList);
+ substExpr(db, p->pWhere, iTable, pEList);
+ substSelect(db, p->pPrior, iTable, pEList);
}
#endif /* !defined(SQLITE_OMIT_VIEW) */
** the subquery before this routine runs.
*/
static int flattenSubquery(
+ sqlite3 *db, /* Database connection */
Select *p, /* The parent or outer SELECT statement */
int iFrom, /* Index in p->pSrc->a[] of the inner subquery */
int isAgg, /* True if outer SELECT uses aggregate functions */
int jointype = pSubitem->jointype;
sqlite3DeleteTable(pSubitem->pTab);
- sqliteFree(pSubitem->zDatabase);
- sqliteFree(pSubitem->zName);
- sqliteFree(pSubitem->zAlias);
+ sqlite3_free(pSubitem->zDatabase);
+ sqlite3_free(pSubitem->zName);
+ sqlite3_free(pSubitem->zAlias);
if( nSubSrc>1 ){
int extra = nSubSrc - 1;
for(i=1; i<nSubSrc; i++){
- pSrc = sqlite3SrcListAppend(pSrc, 0, 0);
+ pSrc = sqlite3SrcListAppend(db, pSrc, 0, 0);
}
p->pSrc = pSrc;
for(i=pSrc->nSrc-1; i-extra>=iFrom; i--){
for(i=0; i<pList->nExpr; i++){
Expr *pExpr;
if( pList->a[i].zName==0 && (pExpr = pList->a[i].pExpr)->span.z!=0 ){
- pList->a[i].zName = sqliteStrNDup((char*)pExpr->span.z, pExpr->span.n);
+ pList->a[i].zName =
+ sqlite3DbStrNDup(db, (char*)pExpr->span.z, pExpr->span.n);
}
}
substExprList(p->pEList, iParent, pSub->pEList);
substExprList(p->pOrderBy, iParent, pSub->pEList);
}
if( pSub->pWhere ){
- pWhere = sqlite3ExprDup(pSub->pWhere);
+ pWhere = sqlite3ExprDup(db, pSub->pWhere);
}else{
pWhere = 0;
}
p->pHaving = p->pWhere;
p->pWhere = pWhere;
substExpr(p->pHaving, iParent, pSub->pEList);
- p->pHaving = sqlite3ExprAnd(p->pHaving, sqlite3ExprDup(pSub->pHaving));
+ p->pHaving = sqlite3ExprAnd(db, p->pHaving,
+ sqlite3ExprDup(db, pSub->pHaving));
assert( p->pGroupBy==0 );
- p->pGroupBy = sqlite3ExprListDup(pSub->pGroupBy);
+ p->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy);
}else{
substExpr(p->pWhere, iParent, pSub->pEList);
- p->pWhere = sqlite3ExprAnd(p->pWhere, pWhere);
+ p->pWhere = sqlite3ExprAnd(db, p->pWhere, pWhere);
}
/* The flattened query is distinct if either the inner or the
CollSeq *pColl = pE->pColl;
int flags = pE->flags & EP_ExpCollate;
sqlite3ExprDelete(pE);
- pE = pOrderBy->a[i].pExpr = sqlite3ExprDup(pEList->a[iCol-1].pExpr);
+ pE = sqlite3ExprDup(pParse->db, pEList->a[iCol-1].pExpr);
+ pOrderBy->a[i].pExpr = pE;
if( pColl && flags ){
pE->pColl = pColl;
pE->flags |= flags;
}
}
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
return SQLITE_NOMEM;
}
int addrSortIndex; /* Address of an OP_OpenEphemeral instruction */
AggInfo sAggInfo; /* Information used by aggregate queries */
int iEnd; /* Address of the end of the query */
+ sqlite3 *db; /* The database connection */
- if( p==0 || sqlite3MallocFailed() || pParse->nErr ){
+ db = pParse->db;
+ if( p==0 || db->mallocFailed || pParse->nErr ){
return 1;
}
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
*/
#ifndef SQLITE_OMIT_VIEW
if( pParent && pParentAgg &&
- flattenSubquery(pParent, parentTab, *pParentAgg, isAgg) ){
+ flattenSubquery(db, pParent, parentTab, *pParentAgg, isAgg) ){
if( isAgg ) *pParentAgg = 1;
goto select_end;
}
goto select_end;
}
}
- if( sqlite3MallocFailed() ) goto select_end;
+ if( db->mallocFailed ) goto select_end;
/* Processing for aggregates with GROUP BY is very different and
** much more complex tha aggregates without a GROUP BY.
generateColumnNames(pParse, pTabList, pEList);
}
- sqliteFree(sAggInfo.aCol);
- sqliteFree(sAggInfo.aFunc);
+ sqlite3_free(sAggInfo.aCol);
+ sqlite3_free(sAggInfo.aFunc);
return rc;
}
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.586 2007/08/15 13:04:54 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.587 2007/08/16 04:30:40 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
int errMask; /* & result codes with this before returning */
u8 autoCommit; /* The auto-commit flag. */
u8 temp_store; /* 1: file 2: memory 0: default */
+ u8 mallocFailed; /* True if we have seen a malloc failure */
int nTable; /* Number of tables in the database */
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
i64 lastRowid; /* ROWID of most recent insert (see above) */
int sqlite3StrNICmp(const char *, const char *, int);
int sqlite3IsNumber(const char*, int*, u8);
-void *sqlite3Malloc(int,int);
-void *sqlite3MallocRaw(int,int);
-void *sqlite3Realloc(void*,int);
+void *sqlite3MallocZero(unsigned);
+void *sqlite3DbMallocZero(sqlite3*, unsigned);
+void *sqlite3DbMallocRaw(sqlite3*, unsigned);
+void *sqlite3ReallocOrFree(sqlite3*,void*,int);
char *sqlite3StrDup(const char*);
char *sqlite3StrNDup(const char*, int);
-# define sqlite3CheckMemory(a,b)
-void *sqlite3ReallocOrFree(void*,int);
-void sqlite3FreeX(void*);
-void *sqlite3MallocX(int);
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
- int sqlite3AllocSize(void *);
-#endif
+char *sqlite3DbStrDup(sqlite3*,const char*);
+char *sqlite3DbStrNDup(sqlite3*,const char*, int);
-char *sqlite3MPrintf(const char*, ...);
-char *sqlite3VMPrintf(const char*, va_list);
+char *sqlite3MPrintf(sqlite3*,const char*, ...);
+char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
void sqlite3DebugPrintf(const char*, ...);
void *sqlite3TextToPtr(const char*);
void sqlite3ErrorMsg(Parse*, const char*, ...);
void sqlite3ErrorClear(Parse*);
void sqlite3Dequote(char*);
-void sqlite3DequoteExpr(Expr*);
+void sqlite3DequoteExpr(sqlite3*, Expr*);
int sqlite3KeywordCode(const unsigned char*, int);
int sqlite3RunParser(Parse*, const char*, char **);
void sqlite3FinishCoding(Parse*);
Expr *sqlite3Expr(int, Expr*, Expr*, const Token*);
-Expr *sqlite3ExprOrFree(int, Expr*, Expr*, const Token*);
+Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
Expr *sqlite3RegisterExpr(Parse*,Token*);
-Expr *sqlite3ExprAnd(Expr*, Expr*);
+Expr *sqlite3ExprAnd(sqlite*,Expr*, Expr*);
void sqlite3ExprSpan(Expr*,Token*,Token*);
-Expr *sqlite3ExprFunction(ExprList*, Token*);
+Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
void sqlite3ExprAssignVarNumber(Parse*, Expr*);
void sqlite3ExprDelete(Expr*);
-ExprList *sqlite3ExprListAppend(ExprList*,Expr*,Token*);
+ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*,Token*);
void sqlite3ExprListDelete(ExprList*);
int sqlite3Init(sqlite3*, char**);
int sqlite3InitCallback(void*, int, char**, char**);
void sqlite3DropTable(Parse*, SrcList*, int, int);
void sqlite3DeleteTable(Table*);
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
-void *sqlite3ArrayAllocate(void*,int,int,int*,int*,int*);
-IdList *sqlite3IdListAppend(IdList*, Token*);
+void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*);
+IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
int sqlite3IdListIndex(IdList*,const char*);
-SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
-SrcList *sqlite3SrcListAppendFromTerm(SrcList*, Token*, Token*, Token*,
+SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
+SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, Token*,
Select*, Expr*, IdList*);
void sqlite3SrcListShiftJoinType(SrcList*);
void sqlite3SrcListAssignCursors(Parse*, SrcList*);
Token*, int, int);
void sqlite3DropIndex(Parse*, SrcList*, int);
int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
-Select *sqlite3SelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
- int,Expr*,Expr*);
+Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
+ Expr*,ExprList*,int,Expr*,Expr*);
void sqlite3SelectDelete(Select*);
Table *sqlite3SrcListLookup(Parse*, SrcList*);
int sqlite3IsReadOnly(Parse*, Table*, int);
void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
void sqlite3Vacuum(Parse*);
int sqlite3RunVacuum(char**, sqlite3*);
-char *sqlite3NameFromToken(Token*);
+char *sqlite3NameFromToken(sqlite3*, Token*);
int sqlite3ExprCompare(Expr*, Expr*);
-int sqliteFuncId(Token*);
int sqlite3ExprResolveNames(NameContext *, Expr *);
int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int, int);
void sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
void sqlite3BeginWriteOperation(Parse*, int, int);
-Expr *sqlite3ExprDup(Expr*);
-void sqlite3TokenCopy(Token*, Token*);
-ExprList *sqlite3ExprListDup(ExprList*);
-SrcList *sqlite3SrcListDup(SrcList*);
-IdList *sqlite3IdListDup(IdList*);
-Select *sqlite3SelectDup(Select*);
+Expr *sqlite3ExprDup(sqlite3*,Expr*);
+void sqlite3TokenCopy(sqlite3*,Token*, Token*);
+ExprList *sqlite3ExprListDup(sqlite3*,ExprList*);
+SrcList *sqlite3SrcListDup(sqlite3*,SrcList*);
+IdList *sqlite3IdListDup(sqlite3*,IdList*);
+Select *sqlite3SelectDup(sqlite3*,Select*);
FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
void sqlite3RegisterBuiltinFunctions(sqlite3*);
void sqlite3RegisterDateTimeFunctions(sqlite3*);
int, int);
void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
void sqlite3DeleteTriggerStep(TriggerStep*);
- TriggerStep *sqlite3TriggerSelectStep(Select*);
- TriggerStep *sqlite3TriggerInsertStep(Token*, IdList*, ExprList*,Select*,int);
- TriggerStep *sqlite3TriggerUpdateStep(Token*, ExprList*, Expr*, int);
- TriggerStep *sqlite3TriggerDeleteStep(Token*, Expr*);
+ TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*);
+ TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
+ ExprList*,Select*,int);
+ TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, int);
+ TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
void sqlite3DeleteTrigger(Trigger*);
void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
#else
int sqlite3Utf8To8(unsigned char*);
#endif
-#ifdef SQLITE_MEMDEBUG
- void sqlite3MallocDisallow(void);
- void sqlite3MallocAllow(void);
- int sqlite3TestMallocFail(void);
-#else
- #define sqlite3TestMallocFail() 0
- #define sqlite3MallocDisallow()
- #define sqlite3MallocAllow()
-#endif
+/*
+** FIX ME: create these routines
+*/
+#define sqlite3MallocDisallow()
+#define sqlite3MallocAllow()
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
- void *sqlite3ThreadSafeMalloc(int);
- void sqlite3ThreadSafeFree(void *);
-#else
- #define sqlite3ThreadSafeMalloc sqlite3MallocX
- #define sqlite3ThreadSafeFree sqlite3FreeX
-#endif
#ifdef SQLITE_OMIT_VIRTUALTABLE
# define sqlite3VtabClear(X)
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test1.c,v 1.259 2007/08/08 12:11:21 drh Exp $
+** $Id: test1.c,v 1.260 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
zResult = sqlite3MPrintf("%z%s%s", zResult, argv[1], argv[i]);
}
Tcl_AppendResult(interp, zResult, 0);
- sqliteFree(zResult);
+ sqlite3_free(zResult);
return TCL_OK;
}
char *zStr;
int n = 0;
zStr = sqlite3MPrintf("%s%n", argv[1], &n);
- sqliteFree(zStr);
+ sqlite3_free(zStr);
Tcl_SetObjResult(interp, Tcl_NewIntObj(n));
return TCL_OK;
}
if( p->nUsed + n + 2 > p->nAlloc ){
char *zNew;
p->nAlloc = p->nAlloc*2 + n + 200;
- zNew = sqliteRealloc(p->z, p->nAlloc);
+ zNew = sqlite3_realloc(p->z, p->nAlloc);
if( zNew==0 ){
- sqliteFree(p->z);
+ sqlite3_free(p->z);
memset(p, 0, sizeof(*p));
return;
}
(char*)sqlite3_value_text(argv[0]),
execFuncCallback, &x, 0);
sqlite3_result_text(context, x.z, x.nUsed, SQLITE_TRANSIENT);
- sqliteFree(x.z);
+ sqlite3_free(x.z);
}
/*
** because it is not tested anywhere else. */
if( rc==SQLITE_OK ){
sqlite3_value *pVal;
-#ifdef SQLITE_MEMDEBUG
+#ifdef 0
if( sqlite3_iMallocFail>0 ){
sqlite3_iMallocFail++;
}
return TCL_OK;
}
-/*
-** Usage: sqlite_malloc_fail N ?REPEAT-INTERVAL?
-**
-** Rig sqliteMalloc() to fail on the N-th call and every REPEAT-INTERVAL call
-** after that. If REPEAT-INTERVAL is 0 or is omitted, then only a single
-** malloc will fail. If REPEAT-INTERVAL is 1 then all mallocs after the
-** first failure will continue to fail on every call. If REPEAT-INTERVAL is
-** 2 then every other malloc will fail. And so forth.
-**
-** Turn off this mechanism and reset the sqlite3ThreadData()->mallocFailed
-** variable if N==0.
-*/
-#ifdef SQLITE_MEMDEBUG
-static int sqlite_malloc_fail(
- void *NotUsed,
- Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
- int argc, /* Number of arguments */
- char **argv /* Text of each argument */
-){
- int n;
- int rep;
- if( argc!=2 && argc!=3 ){
- Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " N\"", 0);
- return TCL_ERROR;
- }
- if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
- if( argc==3 ){
- if( Tcl_GetInt(interp, argv[2], &rep) ) return TCL_ERROR;
- }else{
- rep = 0;
- }
- sqlite3_iMallocFail = n;
- sqlite3_iMallocReset = rep;
- return TCL_OK;
-}
-#endif
-
-/*
-** Usage: sqlite_malloc_stat
-**
-** Return the number of prior calls to sqliteMalloc() and sqliteFree().
-*/
-#ifdef SQLITE_MEMDEBUG
-static int sqlite_malloc_stat(
- void *NotUsed,
- Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
- int argc, /* Number of arguments */
- char **argv /* Text of each argument */
-){
- char zBuf[200];
- sprintf(zBuf, "%d %d %d", sqlite3_nMalloc,sqlite3_nFree,sqlite3_iMallocFail);
- Tcl_AppendResult(interp, zBuf, 0);
- return TCL_OK;
-}
-
-/*
-** This function implements a Tcl command that may be invoked using any of
-** the four forms enumerated below.
-**
-** sqlite_malloc_outstanding
-** Return a summary of all unfreed blocks of memory allocated by the
-** current thread. See comments above function sqlite3OutstandingMallocs()
-** in util.c for a description of the returned value.
-**
-** sqlite_malloc_outstanding -bytes
-** Return the total amount of unfreed memory (in bytes) allocated by
-** this thread.
-**
-** sqlite_malloc_outstanding -maxbytes
-** Return the maximum amount of dynamic memory in use at one time
-** by this thread.
-**
-** sqlite_malloc_outstanding -clearmaxbytes
-** Set the value returned by [sqlite_malloc_outstanding -maxbytes]
-** to the current value of [sqlite_malloc_outstanding -bytes].
-*/
-static int sqlite_malloc_outstanding(
- ClientData clientData,
- Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
- int objc, /* Number of arguments */
- Tcl_Obj *CONST objv[] /* Command arguments */
-){
- extern int sqlite3OutstandingMallocs(Tcl_Interp *interp);
-
-#if defined(SQLITE_DEBUG) && defined(SQLITE_MEMDEBUG) && SQLITE_MEMDEBUG>1
- if( objc==2 ){
- const char *zArg = Tcl_GetString(objv[1]);
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
- ThreadData const *pTd = sqlite3ThreadDataReadOnly();
- if( 0==strcmp(zArg, "-bytes") ){
- Tcl_SetObjResult(interp, Tcl_NewIntObj(pTd->nAlloc));
- }else if( 0==strcmp(zArg, "-clearmaxbytes") ){
- sqlite3_nMaxAlloc = pTd->nAlloc;
- }else
-#endif
- if( 0==strcmp(zArg, "-maxbytes") ){
- Tcl_SetObjResult(interp, Tcl_NewWideIntObj(sqlite3_nMaxAlloc));
- }else{
- Tcl_AppendResult(interp, "bad option \"", zArg,
- "\": must be -bytes, -maxbytes or -clearmaxbytes", 0
- );
- return TCL_ERROR;
- }
-
- return TCL_OK;
- }
-
- if( objc!=1 ){
- Tcl_WrongNumArgs(interp, 1, objv, "?-bytes?");
- return TCL_ERROR;
- }
-
- return sqlite3OutstandingMallocs(interp);
-#else
- return TCL_OK;
-#endif
-}
-#endif
-
/*
** Usage: sqlite3_enable_shared_cache BOOLEAN
**
{ "sqlite3_create_aggregate", (Tcl_CmdProc*)test_create_aggregate },
{ "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func },
{ "sqlite_abort", (Tcl_CmdProc*)sqlite_abort },
-#ifdef SQLITE_MEMDEBUG
- { "sqlite_malloc_fail", (Tcl_CmdProc*)sqlite_malloc_fail },
- { "sqlite_malloc_stat", (Tcl_CmdProc*)sqlite_malloc_stat },
-#endif
{ "sqlite_bind", (Tcl_CmdProc*)test_bind },
{ "breakpoint", (Tcl_CmdProc*)test_breakpoint },
{ "sqlite3_key", (Tcl_CmdProc*)test_key },
{ "add_test_collate", test_collate, 0 },
{ "add_test_collate_needed", test_collate_needed, 0 },
{ "add_test_function", test_function, 0 },
-#endif
-#ifdef SQLITE_MEMDEBUG
- { "sqlite_malloc_outstanding", sqlite_malloc_outstanding, 0},
#endif
{ "sqlite3_test_errstr", test_errstr, 0 },
{ "tcl_variable_type", tcl_variable_type, 0 },
Tcl_LinkVar(interp, "sqlite_last_needed_collation",
(char*)&pzNeededCollation, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
#endif
-#ifdef SQLITE_MEMDEBUG
- {
- extern char *sqlite3_malloc_id;
- extern int sqlite3_mallocfail_trace;
- Tcl_LinkVar(interp, "sqlite_malloc_id",
- (char*)&sqlite3_malloc_id, TCL_LINK_STRING);
- Tcl_LinkVar(interp, "sqlite3_mallocfail_trace",
- (char*)&sqlite3_mallocfail_trace, TCL_LINK_INT);
- }
-#endif
#if OS_WIN
Tcl_LinkVar(interp, "sqlite_os_type",
(char*)&sqlite3_os_type, TCL_LINK_INT);
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test3.c,v 1.75 2007/05/17 14:45:13 danielk1977 Exp $
+** $Id: test3.c,v 1.76 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
}
pBt = sqlite3TextToPtr(argv[1]);
nRoot = argc-2;
- aRoot = (int*)malloc( sizeof(int)*(argc-2) );
+ aRoot = (int*)sqlite3_malloc( sizeof(int)*(argc-2) );
for(i=0; i<argc-2; i++){
if( Tcl_GetInt(interp, argv[i+2], &aRoot[i]) ) return TCL_ERROR;
}
#else
zResult = 0;
#endif
- free((void*)aRoot);
+ sqlite3_free((void*)aRoot);
if( zResult ){
Tcl_AppendResult(interp, zResult, 0);
sqliteFree(zResult);
sqlite3_snprintf(sizeof(zBuf2),zBuf2, "%llu", n);
Tcl_AppendResult(interp, zBuf2, 0);
}else{
- zBuf = malloc( n+1 );
+ zBuf = sqlite3_malloc( n+1 );
rc = sqlite3BtreeKey(pCur, 0, n, zBuf);
if( rc ){
Tcl_AppendResult(interp, errorName(rc), 0);
}
zBuf[n] = 0;
Tcl_AppendResult(interp, zBuf, 0);
- free(zBuf);
+ sqlite3_free(zBuf);
}
return SQLITE_OK;
}
}else{
n = atoi(argv[2]);
}
- zBuf = malloc( n+1 );
+ zBuf = sqlite3_malloc( n+1 );
rc = sqlite3BtreeData(pCur, 0, n, zBuf);
if( rc ){
Tcl_AppendResult(interp, errorName(rc), 0);
}
zBuf[n] = 0;
Tcl_AppendResult(interp, zBuf, 0);
- free(zBuf);
+ sqlite3_free(zBuf);
return SQLITE_OK;
}
*************************************************************************
** Code for testing the the SQLite library in a multithreaded environment.
**
-** $Id: test4.c,v 1.17 2006/02/23 21:43:56 drh Exp $
+** $Id: test4.c,v 1.18 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
}
threadset[i].busy = 1;
sqliteFree(threadset[i].zFilename);
- threadset[i].zFilename = sqliteStrDup(argv[2]);
+ threadset[i].zFilename = sqlite3StrDup(argv[2]);
threadset[i].opnum = 1;
threadset[i].completed = 0;
rc = pthread_create(&x, 0, thread_main, &threadset[i]);
thread_wait(&threadset[i]);
threadset[i].xOp = do_compile;
sqliteFree(threadset[i].zArg);
- threadset[i].zArg = sqliteStrDup(argv[2]);
+ threadset[i].zArg = sqlite3StrDup(argv[2]);
threadset[i].opnum++;
return TCL_OK;
}
** is used for testing the SQLite routines for converting between
** the various supported unicode encodings.
**
-** $Id: test5.c,v 1.16 2007/05/08 20:37:40 drh Exp $
+** $Id: test5.c,v 1.17 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
if( enc_from==SQLITE_UTF8 ){
z = Tcl_GetString(objv[1]);
if( objc==5 ){
- z = sqliteStrDup(z);
+ z = sqlite3StrDup(z);
}
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
}else{
z = (char*)Tcl_GetByteArrayFromObj(objv[1], &len);
if( objc==5 ){
char *zTmp = z;
- z = sqliteMalloc(len);
+ z = sqlite3_malloc(len);
memcpy(z, zTmp, len);
}
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
rc = sqlite3OsTruncate(pFile->pRealFile, pWrite->iOffset);
}
*ppPtr = pWrite->pNext;
- sqliteFree(pWrite);
+ sqlite3_free(pWrite);
break;
}
case 2: { /* Do nothing */
sqlite3_int64 iFirst = (pWrite->iOffset%g.iSectorSize);
sqlite3_int64 iLast = (pWrite->iOffset+pWrite->nBuf-1)%g.iSectorSize;
- zGarbage = sqliteMalloc(g.iSectorSize);
+ zGarbage = sqlite3_malloc(g.iSectorSize);
if( zGarbage ){
sqlite3_int64 i;
for(i=iFirst; rc==SQLITE_OK && i<=iLast; i++){
pFile->pRealFile, i*g.iSectorSize, zGarbage, g.iSectorSize
);
}
- sqliteFree(zGarbage);
+ sqlite3_free(zGarbage);
}else{
rc = SQLITE_NOMEM;
}
assert((zBuf && nBuf) || (!nBuf && !zBuf));
- pNew = (WriteBuffer *)sqliteMalloc(sizeof(WriteBuffer) + nBuf);
+ pNew = (WriteBuffer *)sqlite3_malloc(sizeof(WriteBuffer) + nBuf);
pNew->iOffset = iOffset;
pNew->nBuf = nBuf;
pNew->pFile = (CrashFile *)pFile;
CrashFile *pWrapper = (CrashFile *)pFile;
int rc = SQLITE_NOMEM;
sqlite3_file *pReal;
- pReal = (sqlite3_file *)sqliteMalloc(pVfs->szOsFile);
+ pReal = (sqlite3_file *)sqlite3_malloc(pVfs->szOsFile);
if( pReal ){
pWrapper->pMethod = &CrashFileVtab;
pWrapper->zName = zName;
if( rc==SQLITE_OK ){
pWrapper->pRealFile = pFile;
}else{
- sqliteFree(pReal);
+ sqlite3_free(pReal);
}
}
return rc;
sqlite3_file **ppWrapper
){
CrashFile *pWrapper;
- pWrapper = (CrashFile *)sqliteMalloc(sizeof(CrashFile)+strlen(zName)+1);
+ pWrapper = (CrashFile *)sqlite3_malloc(sizeof(CrashFile)+strlen(zName)+1);
if( !pWrapper ){
return SQLITE_NOMEM;
}
** Code for testing the client/server version of the SQLite library.
** Derived from test4.c.
**
-** $Id: test7.c,v 1.4 2006/03/22 22:10:08 drh Exp $
+** $Id: test7.c,v 1.5 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
}
threadset[i].busy = 1;
sqliteFree(threadset[i].zFilename);
- threadset[i].zFilename = sqliteStrDup(argv[2]);
+ threadset[i].zFilename = sqlite3StrDup(argv[2]);
threadset[i].opnum = 1;
threadset[i].completed = 0;
rc = pthread_create(&x, 0, client_main, &threadset[i]);
client_wait(&threadset[i]);
threadset[i].xOp = do_compile;
sqliteFree(threadset[i].zArg);
- threadset[i].zArg = sqliteStrDup(argv[2]);
+ threadset[i].zArg = sqlite3StrDup(argv[2]);
threadset[i].opnum++;
return TCL_OK;
}
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test8.c,v 1.48 2007/07/20 00:35:59 drh Exp $
+** $Id: test8.c,v 1.49 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
** code otherwise.
**
** If successful, the number of columns is written to *pnCol. *paCol is
-** set to point at sqliteMalloc()'d space containing the array of
-** nCol column names. The caller is responsible for calling sqliteFree
+** set to point at sqlite3_malloc()'d space containing the array of
+** nCol column names. The caller is responsible for calling sqlite3_free
** on *paCol.
*/
static int getColumnNames(
** of the result set of the compiled SELECT will be the same as
** the column names of table <tbl>.
*/
- zSql = sqlite3MPrintf("SELECT * FROM %Q", zTab);
+ zSql = sqlite3_mprintf("SELECT * FROM %Q", zTab);
if( !zSql ){
rc = SQLITE_NOMEM;
goto out;
}
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
if( rc==SQLITE_OK ){
int ii;
for(ii=0; ii<nCol; ii++){
nBytes += (strlen(sqlite3_column_name(pStmt, ii)) + 1);
}
- aCol = (char **)sqliteMalloc(nBytes);
+ aCol = (char **)sqlite3_malloc(nBytes);
if( !aCol ){
rc = SQLITE_NOMEM;
goto out;
char *zSql;
/* Allocate space for the index array */
- aIndex = (int *)sqliteMalloc(sizeof(int) * nCol);
+ aIndex = (int *)sqlite3_malloc(sizeof(int) * nCol);
if( !aIndex ){
rc = SQLITE_NOMEM;
goto get_index_array_out;
goto get_index_array_out;
}
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
/* For each index, figure out the left-most column and set the
** corresponding entry in aIndex[] to 1.
goto get_index_array_out;
}
rc = sqlite3_prepare(db, zSql, -1, &pStmt2, 0);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
if( pStmt2 && sqlite3_step(pStmt2)==SQLITE_ROW ){
int cid = sqlite3_column_int(pStmt2, 1);
assert( cid>=0 && cid<nCol );
}
}
if( rc!=SQLITE_OK ){
- sqliteFree(aIndex);
+ sqlite3_free(aIndex);
aIndex = 0;
}
*paIndex = aIndex;
*/
static int echoDestructor(sqlite3_vtab *pVtab){
echo_vtab *p = (echo_vtab*)pVtab;
- sqliteFree(p->aIndex);
- sqliteFree(p->aCol);
- sqliteFree(p->zThis);
- sqliteFree(p->zTableName);
- sqliteFree(p->zLogName);
- sqliteFree(p);
+ sqlite3_free(p->aIndex);
+ sqlite3_free(p->aCol);
+ sqlite3_free(p->zThis);
+ sqlite3_free(p->zTableName);
+ sqlite3_free(p->zLogName);
+ sqlite3_free(p);
return 0;
}
echo_vtab *pVtab;
/* Allocate the sqlite3_vtab/echo_vtab structure itself */
- pVtab = sqliteMalloc( sizeof(*pVtab) );
+ pVtab = sqlite3_malloc( sizeof(*pVtab) );
if( !pVtab ){
return SQLITE_NOMEM;
}
dequoteString(pVtab->zTableName);
if( pVtab->zTableName && pVtab->zTableName[0]=='*' ){
char *z = sqlite3MPrintf("%s%s", argv[2], &(pVtab->zTableName[1]));
- sqliteFree(pVtab->zTableName);
+ sqlite3_free(pVtab->zTableName);
pVtab->zTableName = z;
pVtab->isPattern = 1;
}
pVtab->zLogName = sqlite3MPrintf("%s", argv[4]);
zSql = sqlite3MPrintf("CREATE TABLE %Q(logmsg)", pVtab->zLogName);
rc = sqlite3_exec(db, zSql, 0, 0, 0);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
}
return rc;
char *zSql;
zSql = sqlite3MPrintf("DROP TABLE %Q", p->zLogName);
rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
}
if( rc==SQLITE_OK ){
*/
static int echoOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
echo_cursor *pCur;
- pCur = sqliteMalloc(sizeof(echo_cursor));
+ pCur = sqlite3_malloc(sizeof(echo_cursor));
*ppCursor = (sqlite3_vtab_cursor *)pCur;
return (pCur ? SQLITE_OK : SQLITE_NOMEM);
}
echo_cursor *pCur = (echo_cursor *)cur;
sqlite3_stmt *pStmt = pCur->pStmt;
pCur->pStmt = 0;
- sqliteFree(pCur);
+ sqlite3_free(pCur);
rc = sqlite3_finalize(pStmt);
return rc;
}
p->zTableName, zNewName, &p->zTableName[nThis]
);
rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
- sqliteFree(zSql);
+ sqlite3_free(zSql);
}
return rc;
**
**
** For an ASYNC_WRITE operation, zBuf points to the data to write to the file.
-** This space is sqliteMalloc()d along with the AsyncWrite structure in a
-** single blob, so is deleted when sqliteFree() is called on the parent
+** This space is sqlite3_malloc()d along with the AsyncWrite structure in a
+** single blob, so is deleted when sqlite3_free() is called on the parent
** structure.
*/
struct AsyncWrite {
/*
** Add an entry to the end of the global write-op list. pWrite should point
-** to an AsyncWrite structure allocated using sqlite3OsMalloc(). The writer
-** thread will call sqlite3OsFree() to free the structure after the specified
+** to an AsyncWrite structure allocated using sqlite3_malloc(). The writer
+** thread will call sqlite3_free() to free the structure after the specified
** operation has been completed.
**
** Once an AsyncWrite structure has been added to the list, it becomes the
if( op!=ASYNC_CLOSE && async.ioError ){
return async.ioError;
}
- p = sqlite3OsMalloc(sizeof(AsyncWrite) + (zByte?nByte:0));
+ p = sqlite3_malloc(sizeof(AsyncWrite) + (zByte?nByte:0));
if( !p ){
return SQLITE_NOMEM;
}
n = strlen(zName);
for(i=n-1; i>=0 && zName[i]!='/'; i--){}
- p = (AsyncFile *)sqlite3OsMalloc(sizeof(AsyncFile) + n - i);
+ p = (AsyncFile *)sqlite3_malloc(sizeof(AsyncFile) + n - i);
if( !p ){
rc = SQLITE_NOMEM;
goto error_out;
i64 i = (i64)(delFlag);
rc = addNewAsyncWrite(pFile, ASYNC_OPENEXCLUSIVE, i, nByte, z);
if( rc!=SQLITE_OK ){
- sqlite3OsFree(pFile);
+ sqlite3_free(pFile);
*ppFile = 0;
}
}
ASYNC_TRACE(("CLOSE %s\n", p->pFile->zName));
sqlite3OsClose(&p->pFile->pBaseWrite);
sqlite3OsClose(&p->pFile->pBaseRead);
- sqlite3OsFree(p->pFile);
+ sqlite3_free(p->pFile);
break;
case ASYNC_OPENDIRECTORY:
async.pQueueLast = 0;
}
async.pQueueFirst = p->pNext;
- sqlite3OsFree(p);
+ sqlite3_free(p);
assert( holdingMutex );
/* An IO error has occured. We cannot report the error back to the
** with historical versions of the "binary" command. So it seems
** easier and safer to build our own mechanism.
**
-** $Id: test_hexio.c,v 1.3 2007/05/10 17:23:12 drh Exp $
+** $Id: test_hexio.c,v 1.4 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
if( Tcl_GetIntFromObj(interp, objv[2], &offset) ) return TCL_ERROR;
if( Tcl_GetIntFromObj(interp, objv[3], &amt) ) return TCL_ERROR;
zFile = Tcl_GetString(objv[1]);
- zBuf = malloc( amt*2+1 );
+ zBuf = sqlite3_malloc( amt*2+1 );
if( zBuf==0 ){
return TCL_ERROR;
}
}
binToHex(zBuf, got);
Tcl_AppendResult(interp, zBuf, 0);
- free(zBuf);
+ sqlite3_free(zBuf);
return TCL_OK;
}
if( Tcl_GetIntFromObj(interp, objv[2], &offset) ) return TCL_ERROR;
zFile = Tcl_GetString(objv[1]);
zIn = (const unsigned char *)Tcl_GetStringFromObj(objv[3], &nIn);
- aOut = malloc( nIn/2 );
+ aOut = sqlite3_malloc( nIn/2 );
if( aOut==0 ){
return TCL_ERROR;
}
}
fseek(out, offset, SEEK_SET);
written = fwrite(aOut, 1, nOut, out);
- free(aOut);
+ sqlite3_free(aOut);
fclose(out);
Tcl_SetObjResult(interp, Tcl_NewIntObj(written));
return TCL_OK;
return TCL_ERROR;
}
zIn = (const unsigned char *)Tcl_GetStringFromObj(objv[1], &nIn);
- aOut = malloc( nIn/2 );
+ aOut = sqlite3_malloc( nIn/2 );
if( aOut==0 ){
return TCL_ERROR;
}
memset(aNum, 0, sizeof(aNum));
memcpy(&aNum[4-nOut], aOut, nOut);
}
- free(aOut);
+ sqlite3_free(aOut);
val = (aNum[0]<<24) | (aNum[1]<<16) | (aNum[2]<<8) | aNum[3];
Tcl_SetObjResult(interp, Tcl_NewIntObj(val));
return TCL_OK;
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test_schema.c,v 1.12 2007/06/27 16:26:07 danielk1977 Exp $
+** $Id: test_schema.c,v 1.13 2007/08/16 04:30:40 drh Exp $
*/
/* The code in this file defines a sqlite3 virtual-table module that
#ifdef SQLITE_TEST
#include "sqliteInt.h"
#include "tcl.h"
- #define MALLOC(x) sqliteMallocRaw(x)
- #define FREE(x) sqliteFree(x)
#else
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
- #define MALLOC(x) malloc(x)
- #define FREE(x) free(x)
#endif
#include <stdlib.h>
** Table destructor for the schema module.
*/
static int schemaDestroy(sqlite3_vtab *pVtab){
- FREE(pVtab);
+ sqlite3_free(pVtab);
return 0;
}
char **pzErr
){
int rc = SQLITE_NOMEM;
- schema_vtab *pVtab = MALLOC(sizeof(schema_vtab));
+ schema_vtab *pVtab = sqlite3_malloc(sizeof(schema_vtab));
if( pVtab ){
memset(pVtab, 0, sizeof(schema_vtab));
pVtab->db = db;
static int schemaOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
int rc = SQLITE_NOMEM;
schema_cursor *pCur;
- pCur = MALLOC(sizeof(schema_cursor));
+ pCur = sqlite3_malloc(sizeof(schema_cursor));
if( pCur ){
memset(pCur, 0, sizeof(schema_cursor));
*ppCursor = (sqlite3_vtab_cursor *)pCur;
sqlite3_finalize(pCur->pDbList);
sqlite3_finalize(pCur->pTableList);
sqlite3_finalize(pCur->pColumnList);
- FREE(pCur);
+ sqlite3_free(pCur);
return SQLITE_OK;
}
** The emphasis of this file is a virtual table that provides
** access to TCL variables.
**
-** $Id: test_tclvar.c,v 1.11 2007/06/27 16:26:07 danielk1977 Exp $
+** $Id: test_tclvar.c,v 1.12 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
tclvar_vtab *pVtab;
static const char zSchema[] =
"CREATE TABLE whatever(name TEXT, arrayname TEXT, value TEXT)";
- pVtab = sqliteMalloc( sizeof(*pVtab) );
+ pVtab = sqlite3_malloc( sizeof(*pVtab) );
if( pVtab==0 ) return SQLITE_NOMEM;
*ppVtab = &pVtab->base;
pVtab->interp = (Tcl_Interp *)pAux;
** methods are identical. */
static int tclvarDisconnect(sqlite3_vtab *pVtab){
- sqliteFree(pVtab);
+ sqlite3_free(pVtab);
return SQLITE_OK;
}
/* The xDisconnect and xDestroy methods are also the same */
*/
static int tclvarOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
tclvar_cursor *pCur;
- pCur = sqliteMalloc(sizeof(tclvar_cursor));
+ pCur = sqlite3_malloc(sizeof(tclvar_cursor));
*ppCursor = &pCur->base;
return SQLITE_OK;
}
if( pCur->pList2 ){
Tcl_DecrRefCount(pCur->pList2);
}
- sqliteFree(pCur);
+ sqlite3_free(pCur);
return SQLITE_OK;
}
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
-** $Id: tokenize.c,v 1.131 2007/07/23 19:31:17 drh Exp $
+** $Id: tokenize.c,v 1.132 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
** Run the parser on the given SQL string. The parser structure is
** passed in. An SQLITE_ status code is returned. If an error occurs
** and pzErrMsg!=NULL then an error message might be written into
-** memory obtained from malloc() and *pzErrMsg made to point to that
+** memory obtained from sqlite3_malloc() and *pzErrMsg made to point to that
** error message. Or maybe not.
*/
int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
}
pParse->rc = SQLITE_OK;
i = 0;
- pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3MallocX);
+ pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3_malloc);
if( pEngine==0 ){
return SQLITE_NOMEM;
}
assert( pParse->nVarExprAlloc==0 );
assert( pParse->apVarExpr==0 );
pParse->zTail = pParse->zSql = zSql;
- while( !sqlite3MallocFailed() && zSql[i]!=0 ){
+ while( !db->mallocFailed && zSql[i]!=0 ){
assert( i>=0 );
pParse->sLastToken.z = (u8*)&zSql[i];
assert( pParse->sLastToken.dyn==0 );
}
case TK_ILLEGAL: {
if( pzErrMsg ){
- sqliteFree(*pzErrMsg);
+ sqlite3_free(*pzErrMsg);
*pzErrMsg = sqlite3MPrintf("unrecognized token: \"%T\"",
&pParse->sLastToken);
}
}
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
}
- sqlite3ParserFree(pEngine, sqlite3FreeX);
- if( sqlite3MallocFailed() ){
+ sqlite3ParserFree(pEngine, sqlite3_free);
+ if( db->mallocFailed ){
pParse->rc = SQLITE_NOMEM;
}
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
if( pzErrMsg && *pzErrMsg==0 ){
*pzErrMsg = pParse->zErrMsg;
}else{
- sqliteFree(pParse->zErrMsg);
+ sqlite3_free(pParse->zErrMsg);
}
pParse->zErrMsg = 0;
if( !nErr ) nErr++;
}
#ifndef SQLITE_OMIT_SHARED_CACHE
if( pParse->nested==0 ){
- sqliteFree(pParse->aTableLock);
+ sqlite3_free(pParse->aTableLock);
pParse->aTableLock = 0;
pParse->nTableLock = 0;
}
}
sqlite3DeleteTrigger(pParse->pNewTrigger);
- sqliteFree(pParse->apVarExpr);
+ sqlite3_free(pParse->apVarExpr);
if( nErr>0 && (pParse->rc==SQLITE_OK || pParse->rc==SQLITE_DONE) ){
pParse->rc = SQLITE_ERROR;
}
TriggerStep * pTmp = pTriggerStep;
pTriggerStep = pTriggerStep->pNext;
- if( pTmp->target.dyn ) sqliteFree((char*)pTmp->target.z);
+ if( pTmp->target.dyn ) sqlite3_free((char*)pTmp->target.z);
sqlite3ExprDelete(pTmp->pWhere);
sqlite3ExprListDelete(pTmp->pExprList);
sqlite3SelectDelete(pTmp->pSelect);
sqlite3IdListDelete(pTmp->pIdList);
- sqliteFree(pTmp);
+ sqlite3_free(pTmp);
}
}
** If sqlite3SrcListLookup() returns 0, indicating the table does not
** exist, the error is caught by the block below.
*/
- if( !pTableName || sqlite3MallocFailed() ){
+ if( !pTableName || db->mallocFailed ){
goto trigger_cleanup;
}
pTab = sqlite3SrcListLookup(pParse, pTableName);
}
/* Ensure the table name matches database name and that the table exists */
- if( sqlite3MallocFailed() ) goto trigger_cleanup;
+ if( db->mallocFailed ) goto trigger_cleanup;
assert( pTableName->nSrc==1 );
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&
sqlite3FixSrcList(&sFix, pTableName) ){
/* Check that the trigger name is not reserved and that no trigger of the
** specified name exists */
- zName = sqlite3NameFromToken(pName);
+ zName = sqlite3NameFromToken(db, pName);
if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
goto trigger_cleanup;
}
}
/* Build the Trigger object */
- pTrigger = (Trigger*)sqliteMalloc(sizeof(Trigger));
+ pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
if( pTrigger==0 ) goto trigger_cleanup;
pTrigger->name = zName;
zName = 0;
- pTrigger->table = sqliteStrDup(pTableName->a[0].zName);
+ pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
pTrigger->pSchema = db->aDb[iDb].pSchema;
pTrigger->pTabSchema = pTab->pSchema;
pTrigger->op = op;
pTrigger->tr_tm = tr_tm==TK_BEFORE ? TRIGGER_BEFORE : TRIGGER_AFTER;
- pTrigger->pWhen = sqlite3ExprDup(pWhen);
- pTrigger->pColumns = sqlite3IdListDup(pColumns);
- sqlite3TokenCopy(&pTrigger->nameToken,pName);
+ pTrigger->pWhen = sqlite3ExprDup(db, pWhen);
+ pTrigger->pColumns = sqlite3IdListDup(db, pColumns);
+ sqlite3TokenCopy(db, &pTrigger->nameToken,pName);
assert( pParse->pNewTrigger==0 );
pParse->pNewTrigger = pTrigger;
trigger_cleanup:
- sqliteFree(zName);
+ sqlite3_free(zName);
sqlite3SrcListDelete(pTableName);
sqlite3IdListDelete(pColumns);
sqlite3ExprDelete(pWhen);
pDel = sqlite3HashInsert(&db->aDb[iDb].pSchema->trigHash,
pTrig->name, strlen(pTrig->name), pTrig);
if( pDel ){
- assert( sqlite3MallocFailed() && pDel==pTrig );
+ assert( db->mallocFailed && pDel==pTrig );
goto triggerfinish_cleanup;
}
n = strlen(pTrig->table) + 1;
/*
** Make a copy of all components of the given trigger step. This has
** the effect of copying all Expr.token.z values into memory obtained
-** from sqliteMalloc(). As initially created, the Expr.token.z values
+** from sqlite3_malloc(). As initially created, the Expr.token.z values
** all point to the input string that was fed to the parser. But that
** string is ephemeral - it will go away as soon as the sqlite3_exec()
** call that started the parser exits. This routine makes a persistent
** copy of all the Expr.token.z strings so that the TriggerStep structure
** will be valid even after the sqlite3_exec() call returns.
*/
-static void sqlitePersistTriggerStep(TriggerStep *p){
+static void sqlitePersistTriggerStep(sqlite3 *db, TriggerStep *p){
if( p->target.z ){
- p->target.z = (u8*)sqliteStrNDup((char*)p->target.z, p->target.n);
+ p->target.z = (u8*)sqlite3DbStrNDup(db, (char*)p->target.z, p->target.n);
p->target.dyn = 1;
}
if( p->pSelect ){
- Select *pNew = sqlite3SelectDup(p->pSelect);
+ Select *pNew = sqlite3SelectDup(db, p->pSelect);
sqlite3SelectDelete(p->pSelect);
p->pSelect = pNew;
}
if( p->pWhere ){
- Expr *pNew = sqlite3ExprDup(p->pWhere);
+ Expr *pNew = sqlite3ExprDup(db, p->pWhere);
sqlite3ExprDelete(p->pWhere);
p->pWhere = pNew;
}
if( p->pExprList ){
- ExprList *pNew = sqlite3ExprListDup(p->pExprList);
+ ExprList *pNew = sqlite3ExprListDup(db, p->pExprList);
sqlite3ExprListDelete(p->pExprList);
p->pExprList = pNew;
}
if( p->pIdList ){
- IdList *pNew = sqlite3IdListDup(p->pIdList);
+ IdList *pNew = sqlite3IdListDup(db, p->pIdList);
sqlite3IdListDelete(p->pIdList);
p->pIdList = pNew;
}
** The parser calls this routine when it finds a SELECT statement in
** body of a TRIGGER.
*/
-TriggerStep *sqlite3TriggerSelectStep(Select *pSelect){
- TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
+TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
+ TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
if( pTriggerStep==0 ) {
sqlite3SelectDelete(pSelect);
return 0;
pTriggerStep->op = TK_SELECT;
pTriggerStep->pSelect = pSelect;
pTriggerStep->orconf = OE_Default;
- sqlitePersistTriggerStep(pTriggerStep);
+ sqlitePersistTriggerStep(db, pTriggerStep);
return pTriggerStep;
}
** body of a trigger.
*/
TriggerStep *sqlite3TriggerInsertStep(
+ sqlite3 *db, /* The database connection */
Token *pTableName, /* Name of the table into which we insert */
IdList *pColumn, /* List of columns in pTableName to insert into */
ExprList *pEList, /* The VALUE clause: a list of values to be inserted */
Select *pSelect, /* A SELECT statement that supplies values */
int orconf /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
){
- TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
+ TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
assert(pEList == 0 || pSelect == 0);
assert(pEList != 0 || pSelect != 0);
pTriggerStep->pIdList = pColumn;
pTriggerStep->pExprList = pEList;
pTriggerStep->orconf = orconf;
- sqlitePersistTriggerStep(pTriggerStep);
+ sqlitePersistTriggerStep(db, pTriggerStep);
}else{
sqlite3IdListDelete(pColumn);
sqlite3ExprListDelete(pEList);
- sqlite3SelectDup(pSelect);
+ sqlite3SelectDelete(pSelect);
}
return pTriggerStep;
** sees an UPDATE statement inside the body of a CREATE TRIGGER.
*/
TriggerStep *sqlite3TriggerUpdateStep(
+ sqlite3 *db, /* The database connection */
Token *pTableName, /* Name of the table to be updated */
ExprList *pEList, /* The SET clause: list of column and new values */
Expr *pWhere, /* The WHERE clause */
int orconf /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
){
- TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
+ TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
if( pTriggerStep==0 ){
sqlite3ExprListDelete(pEList);
sqlite3ExprDelete(pWhere);
pTriggerStep->pExprList = pEList;
pTriggerStep->pWhere = pWhere;
pTriggerStep->orconf = orconf;
- sqlitePersistTriggerStep(pTriggerStep);
+ sqlitePersistTriggerStep(db, pTriggerStep);
return pTriggerStep;
}
** a pointer to that trigger step. The parser calls this routine when it
** sees a DELETE statement inside the body of a CREATE TRIGGER.
*/
-TriggerStep *sqlite3TriggerDeleteStep(Token *pTableName, Expr *pWhere){
- TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
+TriggerStep *sqlite3TriggerDeleteStep(
+ sqlite3 *db, /* Database connection */
+ Token *pTableName, /* The table from which rows are deleted */
+ Expr *pWhere /* The WHERE clause */
+){
+ TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
if( pTriggerStep==0 ){
sqlite3ExprDelete(pWhere);
return 0;
pTriggerStep->target = *pTableName;
pTriggerStep->pWhere = pWhere;
pTriggerStep->orconf = OE_Default;
- sqlitePersistTriggerStep(pTriggerStep);
+ sqlitePersistTriggerStep(db, pTriggerStep);
return pTriggerStep;
}
void sqlite3DeleteTrigger(Trigger *pTrigger){
if( pTrigger==0 ) return;
sqlite3DeleteTriggerStep(pTrigger->step_list);
- sqliteFree(pTrigger->name);
- sqliteFree(pTrigger->table);
+ sqlite3_free(pTrigger->name);
+ sqlite3_free(pTrigger->table);
sqlite3ExprDelete(pTrigger->pWhen);
sqlite3IdListDelete(pTrigger->pColumns);
- if( pTrigger->nameToken.dyn ) sqliteFree((char*)pTrigger->nameToken.z);
- sqliteFree(pTrigger);
+ if( pTrigger->nameToken.dyn ) sqlite3_free((char*)pTrigger->nameToken.z);
+ sqlite3_free(pTrigger);
}
/*
int nName;
sqlite3 *db = pParse->db;
- if( sqlite3MallocFailed() ) goto drop_trigger_cleanup;
+ if( db->mallocFailed ) goto drop_trigger_cleanup;
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
goto drop_trigger_cleanup;
}
assert( iDb<pParse->db->nDb );
sDb.z = (u8*)pParse->db->aDb[iDb].zName;
sDb.n = strlen((char*)sDb.z);
- pSrc = sqlite3SrcListAppend(0, &sDb, &pStep->target);
+ pSrc = sqlite3SrcListAppend(pParse->db, 0, &sDb, &pStep->target);
} else {
- pSrc = sqlite3SrcListAppend(0, &pStep->target, 0);
+ pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
}
return pSrc;
}
TriggerStep * pTriggerStep = pStepList;
int orconf;
Vdbe *v = pParse->pVdbe;
+ sqlite3 *db = pParse->db;
assert( pTriggerStep!=0 );
assert( v!=0 );
pParse->trigStack->orconf = orconf;
switch( pTriggerStep->op ){
case TK_SELECT: {
- Select *ss = sqlite3SelectDup(pTriggerStep->pSelect);
+ Select *ss = sqlite3SelectDup(db, pTriggerStep->pSelect);
if( ss ){
sqlite3SelectResolve(pParse, ss, 0);
sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
pSrc = targetSrcList(pParse, pTriggerStep);
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
sqlite3Update(pParse, pSrc,
- sqlite3ExprListDup(pTriggerStep->pExprList),
- sqlite3ExprDup(pTriggerStep->pWhere), orconf);
+ sqlite3ExprListDup(db, pTriggerStep->pExprList),
+ sqlite3ExprDup(db, pTriggerStep->pWhere), orconf);
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
break;
}
pSrc = targetSrcList(pParse, pTriggerStep);
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
sqlite3Insert(pParse, pSrc,
- sqlite3ExprListDup(pTriggerStep->pExprList),
- sqlite3SelectDup(pTriggerStep->pSelect),
- sqlite3IdListDup(pTriggerStep->pIdList), orconf);
+ sqlite3ExprListDup(db, pTriggerStep->pExprList),
+ sqlite3SelectDup(db, pTriggerStep->pSelect),
+ sqlite3IdListDup(db, pTriggerStep->pIdList), orconf);
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
break;
}
SrcList *pSrc;
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
pSrc = targetSrcList(pParse, pTriggerStep);
- sqlite3DeleteFrom(pParse, pSrc, sqlite3ExprDup(pTriggerStep->pWhere));
+ sqlite3DeleteFrom(pParse, pSrc,
+ sqlite3ExprDup(db, pTriggerStep->pWhere));
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
break;
}
/* code the WHEN clause */
endTrigger = sqlite3VdbeMakeLabel(pParse->pVdbe);
- whenExpr = sqlite3ExprDup(p->pWhen);
+ whenExpr = sqlite3ExprDup(pParse->db, p->pWhen);
if( sqlite3ExprResolveNames(&sNC, whenExpr) ){
pParse->trigStack = trigStackEntry.pNext;
sqlite3ExprDelete(whenExpr);
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
-** $Id: update.c,v 1.138 2007/06/25 16:29:34 danielk1977 Exp $
+** $Id: update.c,v 1.139 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
int oldIdx = -1; /* index of trigger "old" temp table */
sContext.pParse = 0;
- if( pParse->nErr || sqlite3MallocFailed() ){
+ db = pParse->db;
+ if( pParse->nErr || db->mallocFailed ){
goto update_cleanup;
}
- db = pParse->db;
assert( pTabList->nSrc==1 );
/* Locate the table which we want to update.
if( sqlite3ViewGetColumnNames(pParse, pTab) ){
goto update_cleanup;
}
- aXRef = sqliteMallocRaw( sizeof(int) * pTab->nCol );
+ aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
if( aXRef==0 ) goto update_cleanup;
for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
if( i<pIdx->nColumn ) nIdx++;
}
if( nIdxTotal>0 ){
- apIdx = sqliteMallocRaw( sizeof(Index*) * nIdx + nIdxTotal );
+ apIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx + nIdxTotal );
if( apIdx==0 ) goto update_cleanup;
aIdxUsed = (char*)&apIdx[nIdx];
}
*/
if( isView ){
Select *pView;
- pView = sqlite3SelectDup(pTab->pSelect);
+ pView = sqlite3SelectDup(db, pTab->pSelect);
sqlite3Select(pParse, pView, SRT_EphemTab, iCur, 0, 0, 0, 0);
sqlite3SelectDelete(pView);
}
update_cleanup:
sqlite3AuthContextPop(&sContext);
- sqliteFree(apIdx);
- sqliteFree(aXRef);
+ sqlite3_free(apIdx);
+ sqlite3_free(aXRef);
sqlite3SrcListDelete(pTabList);
sqlite3ExprListDelete(pChanges);
sqlite3ExprDelete(pWhere);
int ephemTab; /* Table holding the result of the SELECT */
int i; /* Loop counter */
int addr; /* Address of top of loop */
+ sqlite3 *db = pParse->db; /* Database connection */
/* Construct the SELECT statement that will find the new values for
** all updated rows.
*/
- pEList = sqlite3ExprListAppend(0, sqlite3CreateIdExpr("_rowid_"), 0);
+ pEList = sqlite3ExprListAppend(pParse, 0,
+ sqlite3CreateIdExpr(pParse, "_rowid_"), 0);
if( pRowid ){
- pEList = sqlite3ExprListAppend(pEList, sqlite3ExprDup(pRowid), 0);
+ pEList = sqlite3ExprListAppend(pParse, pEList,
+ sqlite3ExprDup(db, pRowid), 0);
}
assert( pTab->iPKey<0 );
for(i=0; i<pTab->nCol; i++){
if( aXRef[i]>=0 ){
- pExpr = sqlite3ExprDup(pChanges->a[aXRef[i]].pExpr);
+ pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr);
}else{
- pExpr = sqlite3CreateIdExpr(pTab->aCol[i].zName);
+ pExpr = sqlite3CreateIdExpr(pParse, pTab->aCol[i].zName);
}
- pEList = sqlite3ExprListAppend(pEList, pExpr, 0);
+ pEList = sqlite3ExprListAppend(pParse, pEList, pExpr, 0);
}
- pSelect = sqlite3SelectNew(pEList, pSrc, pWhere, 0, 0, 0, 0, 0, 0);
+ pSelect = sqlite3SelectNew(pParse, pEList, pSrc, pWhere, 0, 0, 0, 0, 0, 0);
/* Create the ephemeral table into which the update results will
** be stored.
** This file contains routines used to translate between UTF-8,
** UTF-16, UTF-16BE, and UTF-16LE.
**
-** $Id: utf.c,v 1.53 2007/08/07 17:04:59 drh Exp $
+** $Id: utf.c,v 1.54 2007/08/16 04:30:40 drh Exp $
**
** Notes on UTF-8:
**
** desiredEnc. It is an error if the string is already of the desired
** encoding, or if *pMem does not contain a string value.
*/
-int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
+int sqlite3VdbeMemTranslate(sqlite3 *db, Mem *pMem, u8 desiredEnc){
unsigned char zShort[NBFS]; /* Temporary short output buffer */
int len; /* Maximum length of output string in bytes */
unsigned char *zOut; /* Output buffer */
** byte past the end.
**
** Variable zOut is set to point at the output buffer. This may be space
- ** obtained from malloc(), or Mem.zShort, if it large enough and not in
- ** use, or the zShort array on the stack (see above).
+ ** obtained from sqlite3_malloc(), or Mem.zShort, if it large enough and
+ ** not in use, or the zShort array on the stack (see above).
*/
zIn = (u8*)pMem->z;
zTerm = &zIn[pMem->n];
if( len>NBFS ){
- zOut = sqliteMallocRaw(len);
+ zOut = sqlite3DbMallocRaw(db, len);
if( !zOut ) return SQLITE_NOMEM;
}else{
zOut = zShort;
#ifndef SQLITE_OMIT_UTF16
/*
** Convert a UTF-16 string in the native encoding into a UTF-8 string.
-** Memory to hold the UTF-8 string is obtained from malloc and must be
-** freed by the calling function.
+** Memory to hold the UTF-8 string is obtained from sqlite3_malloc and must
+** be freed by the calling function.
**
** NULL is returned if there is an allocation error.
*/
-char *sqlite3Utf16to8(const void *z, int nByte){
+char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte){
Mem m;
memset(&m, 0, sizeof(m));
- sqlite3VdbeMemSetStr(&m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC);
- sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8);
- assert( (m.flags & MEM_Term)!=0 || sqlite3MallocFailed() );
- assert( (m.flags & MEM_Str)!=0 || sqlite3MallocFailed() );
- return (m.flags & MEM_Dyn)!=0 ? m.z : sqliteStrDup(m.z);
+ sqlite3VdbeMemSetStr(db, &m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC);
+ sqlite3VdbeChangeEncoding(db, &m, SQLITE_UTF8);
+ assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
+ assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
+ return (m.flags & MEM_Dyn)!=0 ? m.z : sqlite3DbStrDup(db, m.z);
}
/*
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.207 2007/06/26 00:37:28 drh Exp $
+** $Id: util.c,v 1.208 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
** binary value has been obtained from malloc and must be freed by
** the calling routine.
*/
-void *sqlite3HexToBlob(const char *z){
+void *sqlite3HexToBlob(sqlite3 *db, const char *z){
char *zBlob;
int i;
int n = strlen(z);
if( n%2 ) return 0;
- zBlob = (char *)sqliteMalloc(n/2);
+ zBlob = (char *)sqlite3DbMallocRaw(db, n/2);
if( zBlob ){
for(i=0; i<n; i+=2){
zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]);
return 1;
}
}
-
-/*
-** Return a pointer to the ThreadData associated with the calling thread.
-*/
-ThreadData *sqlite3ThreadData(){
- ThreadData *p = (ThreadData*)sqlite3OsThreadSpecificData(1);
- if( !p ){
- sqlite3FailedMalloc();
- }
- return p;
-}
-
-/*
-** Return a pointer to the ThreadData associated with the calling thread.
-** If no ThreadData has been allocated to this thread yet, return a pointer
-** to a substitute ThreadData structure that is all zeros.
-*/
-const ThreadData *sqlite3ThreadDataReadOnly(){
- static const ThreadData zeroData = {0}; /* Initializer to silence warnings
- ** from broken compilers */
- const ThreadData *pTd = sqlite3OsThreadSpecificData(0);
- return pTd ? pTd : &zeroData;
-}
-
-/*
-** Check to see if the ThreadData for this thread is all zero. If it
-** is, then deallocate it.
-*/
-void sqlite3ReleaseThreadData(){
- sqlite3OsThreadSpecificData(-1);
-}
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
-** $Id: vacuum.c,v 1.69 2007/03/27 16:19:52 danielk1977 Exp $
+** $Id: vacuum.c,v 1.70 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
pTemp = db->aDb[db->nDb-1].pBt;
sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain),
sqlite3BtreeGetReserve(pMain));
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
rc = SQLITE_NOMEM;
goto end_of_vacuum;
}
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
-** $Id: vdbe.c,v 1.639 2007/07/26 06:50:06 danielk1977 Exp $
+** $Id: vdbe.c,v 1.640 2007/08/16 04:30:40 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
if(((P)->flags&(MEM_Str|MEM_Blob))==0 && sqlite3VdbeMemStringify(P,enc)) \
{ goto no_mem; }
-/*
-** Convert the given stack entity into a string that has been obtained
-** from sqliteMalloc(). This is different from Stringify() above in that
-** Stringify() will use the NBFS bytes of static string space if the string
-** will fit but this routine always mallocs for space.
-** Return non-zero if we run out of memory.
-*/
-#define Dynamicify(P,enc) sqlite3VdbeMemDynamicify(P)
-
/*
** The header of a record consists of a sequence variable-length integers.
** These integers are almost always small and are encoded as a single byte.
if( p->apCsr[iCur] ){
sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
}
- p->apCsr[iCur] = pCx = sqliteMalloc( sizeof(Cursor) );
+ p->apCsr[iCur] = pCx = sqlite3MallocZero( sizeof(Cursor) );
if( pCx ){
pCx->iDb = iDb;
}
** looks like a number, convert it into a number. If it does not
** look like a number, leave it alone.
*/
-static void applyNumericAffinity(Mem *pRec){
+static void applyNumericAffinity(sqlite3 *db, Mem *pRec){
if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
int realnum;
- sqlite3VdbeMemNulTerminate(pRec);
+ sqlite3VdbeMemNulTerminate(db, pRec);
if( (pRec->flags&MEM_Str)
&& sqlite3IsNumber(pRec->z, &realnum, pRec->enc) ){
i64 value;
- sqlite3VdbeChangeEncoding(pRec, SQLITE_UTF8);
+ sqlite3VdbeChangeEncoding(db, pRec, SQLITE_UTF8);
if( !realnum && sqlite3Atoi64(pRec->z, &value) ){
sqlite3VdbeMemRelease(pRec);
pRec->u.i = value;
** SQLITE_AFF_NONE:
** No-op. pRec is unchanged.
*/
-static void applyAffinity(Mem *pRec, char affinity, u8 enc){
+static void applyAffinity(
+ sqlite3 *db, /* Report malloc() errors to this db connection */
+ Mem *pRec, /* The value to apply affinity to */
+ char affinity, /* The affinity to be applied */
+ u8 enc /* Use this text encoding */
+){
if( affinity==SQLITE_AFF_TEXT ){
/* Only attempt the conversion to TEXT if there is an integer or real
** representation (blob and NULL do not get converted) but no string
** representation.
*/
if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
- sqlite3VdbeMemStringify(pRec, enc);
+ sqlite3VdbeMemStringify(db, pRec, enc);
}
pRec->flags &= ~(MEM_Real|MEM_Int);
}else if( affinity!=SQLITE_AFF_NONE ){
assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
|| affinity==SQLITE_AFF_NUMERIC );
- applyNumericAffinity(pRec);
+ applyNumericAffinity(db, pRec);
if( pRec->flags & MEM_Real ){
sqlite3VdbeIntegerAffinity(pRec);
}
** return SQLITE_BUSY.
**
** If an error occurs, an error message is written to memory obtained
-** from sqliteMalloc() and p->zErrMsg is made to point to that memory.
+** from sqlite3_malloc() and p->zErrMsg is made to point to that memory.
** The error code is stored in p->rc and this routine returns SQLITE_ERROR.
**
** If the callback ever returns non-zero, then the program exits
for(pc=p->pc; rc==SQLITE_OK; pc++){
assert( pc>=0 && pc<p->nOp );
assert( pTos<=&p->aStack[pc] );
- if( sqlite3MallocFailed() ) goto no_mem;
+ if( db->mallocFailed ) goto no_mem;
#ifdef VDBE_PROFILE
origPc = pc;
start = hwtime();
pTos++;
sqlite3VdbeMemSetStr(pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC);
if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, encoding) ) goto no_mem;
- if( SQLITE_OK!=sqlite3VdbeMemDynamicify(pTos) ) goto no_mem;
+ if( SQLITE_OK!=sqlite3VdbeMemDynamicify(db, pTos) ) goto no_mem;
pTos->flags &= ~(MEM_Dyn);
pTos->flags |= MEM_Static;
if( pOp->p3type==P3_DYNAMIC ){
- sqliteFree(pOp->p3);
+ sqlite3_free(pOp->p3);
}
pOp->p3type = P3_DYNAMIC;
pOp->p3 = pTos->z;
char *zBlob = sqlite3HexToBlob(pOp->p3);
if( !zBlob ) goto no_mem;
if( pOp->p3type==P3_DYNAMIC ){
- sqliteFree(pOp->p3);
+ sqlite3_free(pOp->p3);
}
pOp->p3 = zBlob;
pOp->p3type = P3_DYNAMIC;
}else{
if( pOp->p3type==P3_DYNAMIC ){
- sqliteFree(pOp->p3);
+ sqlite3_free(pOp->p3);
}
pOp->p3type = P3_STATIC;
pOp->p3 = "";
** any element of the stack is NULL, then the result is NULL.
**
** When P1==1, this routine makes a copy of the top stack element
-** into memory obtained from sqliteMalloc().
+** into memory obtained from sqlite3_malloc().
*/
case OP_Concat: { /* same as TK_CONCAT */
char *zNew;
if( nByte+2>SQLITE_MAX_LENGTH ){
goto too_big;
}
- zNew = sqliteMallocRaw( nByte+2 );
+ zNew = sqlite3DbMallocRaw(db, nByte+2 );
if( zNew==0 ) goto no_mem;
j = 0;
pTerm = &pTos[1-nField];
if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
(*ctx.pFunc->xFunc)(&ctx, n, apVal);
if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
/* Even though a malloc() has failed, the implementation of the
** user function may have called an sqlite3_result_XXX() function
** to return a value. The following call releases any resources
aType = pC->aType;
if( aType==0 ){
- pC->aType = aType = sqliteMallocRaw( 2*nField*sizeof(aType) );
+ pC->aType = aType = sqlite3DbMallocRaw(db, 2*nField*sizeof(aType) );
}
if( aType==0 ){
goto no_mem;
/* Allocate space for the new record. */
if( nByte>sizeof(zTemp) ){
- zNewRecord = sqliteMallocRaw(nByte);
+ zNewRecord = sqlite3DbMallocRaw(db, nByte);
if( !zNewRecord ){
goto no_mem;
}
assert( pTos->flags & (MEM_Blob|MEM_Str) );
}
if( pC->pseudoTable ){
- sqliteFree(pC->pData);
+ sqlite3_free(pC->pData);
pC->iKey = iKey;
pC->nData = pTos->n;
if( pTos->flags & MEM_Dyn ){
pC->pData = pTos->z;
pTos->flags = MEM_Null;
}else{
- pC->pData = sqliteMallocRaw( pC->nData+2 );
+ pC->pData = sqlite3_malloc( pC->nData+2 );
if( !pC->pData ) goto no_mem;
memcpy(pC->pData, pTos->z, pC->nData);
pC->pData[pC->nData] = 0;
pTos->flags = MEM_Blob | MEM_Short;
pTos->z = pTos->zShort;
}else{
- char *z = sqliteMallocRaw( n );
+ char *z = sqlite3_malloc( n );
if( z==0 ) goto no_mem;
pTos->flags = MEM_Blob | MEM_Dyn;
pTos->xDel = 0;
sqlite3SafetyOff(db);
assert( db->init.busy==0 );
db->init.busy = 1;
- assert( !sqlite3MallocFailed() );
+ assert( !db->mallocFailed );
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
if( rc==SQLITE_ABORT ) rc = initData.rc;
- sqliteFree(zSql);
+ sqlite3_free(zSql);
db->init.busy = 0;
sqlite3SafetyOn(db);
if( rc==SQLITE_NOMEM ){
- sqlite3FailedMalloc();
goto no_mem;
}
break;
if( (pTos[-nRoot].flags & MEM_Int)==0 ) break;
}
assert( nRoot>0 );
- aRoot = sqliteMallocRaw( sizeof(int)*(nRoot+1) );
+ aRoot = sqlite3_malloc( sizeof(int)*(nRoot+1) );
if( aRoot==0 ) goto no_mem;
j = pOp->p1;
assert( j>=0 && j<p->nMem );
}
pTos->enc = SQLITE_UTF8;
sqlite3VdbeChangeEncoding(pTos, encoding);
- sqliteFree(aRoot);
+ sqlite3_free(aRoot);
break;
}
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
case OP_FifoWrite: { /* no-push */
assert( pTos>=p->aStack );
sqlite3VdbeMemIntegerify(pTos);
- sqlite3VdbeFifoPush(&p->sFifo, pTos->u.i);
+ if( sqlite3VdbeFifoPush(&p->sFifo, pTos->u.i)==SQLITE_NOMEM ){
+ goto nomem;
+ }
assert( (pTos->flags & MEM_Dyn)==0 );
pTos--;
break;
/* FIX ME: This should be allocated as part of the vdbe at compile-time */
if( i>=p->contextStackDepth ){
p->contextStackDepth = i+1;
- p->contextStack = sqliteReallocOrFree(p->contextStack,
+ p->contextStack = sqlite3ReallocOrFree(db, p->contextStack,
sizeof(Context)*(i+1));
if( p->contextStack==0 ) goto no_mem;
}
ctx.s.xDel = 0;
ctx.isError = 0;
ctx.pColl = 0;
+ ctx.db = db;
if( ctx.pFunc->needCollSeq ){
assert( pOp>p->aOp );
assert( pOp[-1].p3type==P3_COLLSEQ );
pCur->pVtabCursor = pVtabCursor;
pCur->pModule = pVtabCursor->pVtab->pModule;
}else{
+ db->mallocFailed = 1;
pModule->xClose(pVtabCursor);
}
}
/* Jump to here if a malloc() fails.
*/
no_mem:
+ db->mallocFailed = 1;
sqlite3SetString(&p->zErrMsg, "out of memory", (char*)0);
rc = SQLITE_NOMEM;
goto vdbe_halt;
*/
abort_due_to_error:
if( p->zErrMsg==0 ){
- if( sqlite3MallocFailed() ) rc = SQLITE_NOMEM;
+ if( db->mallocFailed ) rc = SQLITE_NOMEM;
sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0);
}
goto vdbe_halt;
Mem *pMem; /* Memory cell used to store aggregate context */
u8 isError; /* Set to true for an error */
CollSeq *pColl; /* Collating sequence */
+ sqlite3 *db; /* Database connection */
};
/*
/*
** Function prototypes
*/
+sqlite3 *sqlite3DbOfVdbe(Vdbe*);
void sqlite3VdbeFreeCursor(Vdbe *, Cursor*);
void sqliteVdbePopStack(Vdbe*,int);
int sqlite3VdbeCursorMoveto(Cursor*);
int rc;
/* Assert that malloc() has not failed */
- assert( !sqlite3MallocFailed() );
+ db = p->db;
+ assert( !db->mallocFailed );
if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
return SQLITE_MISUSE;
rc = SQLITE_ERROR;
goto end_of_step;
}
- db = p->db;
if( sqlite3SafetyOn(db) ){
p->rc = SQLITE_MISUSE;
return SQLITE_MISUSE;
pMem->z = pMem->zShort;
memset(pMem->z, 0, nByte);
}else{
- pMem->z = sqliteMalloc( nByte );
+ pMem->z = sqlite3DbMallocZero(p->db, nByte);
}
}
}
pVdbeFunc = pCtx->pVdbeFunc;
if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
- pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
- if( !pVdbeFunc ) goto failed;
+ pVdbeFunc = sqlite3_realloc(pVdbeFunc, nMalloc);
+ if( !pVdbeFunc ){
+ pCtx->db->mallocFailed = 1;
+ goto failed;
+ }
pCtx->pVdbeFunc = pVdbeFunc;
memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0,
sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux));
int sqlite3_vdbe_addop_trace = 0;
#endif
+/*
+** Return the database connection associated with a VDBE
+*/
+sqlite3 *sqlite3DbOfVdbe(Vdbe *p){
+ return p->db;
+}
+
/*
** Create a new virtual database engine.
*/
Vdbe *sqlite3VdbeCreate(sqlite3 *db){
Vdbe *p;
- p = sqliteMalloc( sizeof(Vdbe) );
+ p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
if( p==0 ) return 0;
p->db = db;
if( db->pVdbe ){
void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n){
if( p==0 ) return;
assert( p->zSql==0 );
- p->zSql = sqlite3StrNDup(z, n);
+ p->zSql = sqlite3DbStrNDup(p->db, z, n);
}
/*
VdbeOp *pNew;
int nNew = N + 100*(!runMode);
int oldSize = p->nOpAlloc;
- pNew = sqliteRealloc(p->aOp, nNew*sizeof(Op));
+ pNew = sqlite_realloc(p->aOp, nNew*sizeof(Op));
if( pNew ){
p->nOpAlloc = nNew;
p->aOp = pNew;
if( nNew>oldSize ){
memset(&p->aOp[oldSize], 0, (nNew-oldSize)*sizeof(Op));
}
+ }else{
+ p->db->mallocFailed = 1;
}
}
}
assert( p->magic==VDBE_MAGIC_INIT );
if( p->nOpAlloc<=i ){
resizeOpArray(p, i+1);
- if( sqlite3MallocFailed() ){
+ if( p->db->mallocFailed ){
return 0;
}
}
assert( p->magic==VDBE_MAGIC_INIT );
if( i>=p->nLabelAlloc ){
p->nLabelAlloc = p->nLabelAlloc*2 + 10;
- p->aLabel = sqliteReallocOrFree(p->aLabel,
+ p->aLabel = sqlite3ReallocOrFree(p->db, p->aLabel,
p->nLabelAlloc*sizeof(p->aLabel[0]));
}
if( p->aLabel ){
assert( -1-pOp->p2<p->nLabel );
pOp->p2 = aLabel[-1-pOp->p2];
}
- sqliteFree(p->aLabel);
+ sqlite3_free(p->aLabel);
p->aLabel = 0;
*pMaxFuncArgs = nMaxArgs;
int addr;
assert( p->magic==VDBE_MAGIC_INIT );
resizeOpArray(p, p->nOp + nOp);
- if( sqlite3MallocFailed() ){
+ if( p->db->mallocFailed ){
return 0;
}
addr = p->nOp;
*/
static void freeEphemeralFunction(FuncDef *pDef){
if( pDef && (pDef->flags & SQLITE_FUNC_EPHEM)!=0 ){
- sqliteFree(pDef);
+ sqlite3_free(pDef);
}
}
case P3_DYNAMIC:
case P3_KEYINFO:
case P3_KEYINFO_HANDOFF: {
- sqliteFree(p3);
+ sqlite3_free(p3);
break;
}
case P3_MPRINTF: {
VdbeFunc *pVdbeFunc = (VdbeFunc *)p3;
freeEphemeralFunction(pVdbeFunc->pFunc);
sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
- sqliteFree(pVdbeFunc);
+ sqlite3_free(pVdbeFunc);
break;
}
case P3_FUNCDEF: {
** few minor changes to the program.
**
** If n>=0 then the P3 operand is dynamic, meaning that a copy of
-** the string is made into memory obtained from sqliteMalloc().
+** the string is made into memory obtained from sqlite3_malloc().
** A value of n==0 means copy bytes of zP3 up to and including the
** first null byte. If n>0 then copy n+1 bytes of zP3.
**
** If n==P3_KEYINFO it means that zP3 is a pointer to a KeyInfo structure.
** A copy is made of the KeyInfo structure into memory obtained from
-** sqliteMalloc, to be freed when the Vdbe is finalized.
+** sqlite3_malloc, to be freed when the Vdbe is finalized.
** n==P3_KEYINFO_HANDOFF indicates that zP3 points to a KeyInfo structure
-** stored in memory that the caller has obtained from sqliteMalloc. The
+** stored in memory that the caller has obtained from sqlite3_malloc. The
** caller should not free the allocation, it will be freed when the Vdbe is
** finalized.
**
void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
Op *pOp;
assert( p==0 || p->magic==VDBE_MAGIC_INIT );
- if( p==0 || p->aOp==0 || sqlite3MallocFailed() ){
+ if( p==0 || p->aOp==0 || p->db->mallocFailed ){
if (n != P3_KEYINFO) {
freeP3(n, (void*)*(char**)&zP3);
}
nField = ((KeyInfo*)zP3)->nField;
nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
- pKeyInfo = sqliteMallocRaw( nByte );
+ pKeyInfo = sqlite3_malloc( nByte );
pOp->p3 = (char*)pKeyInfo;
if( pKeyInfo ){
unsigned char *aSortOrder;
}
pOp->p3type = P3_KEYINFO;
}else{
+ p->db->mallocFailed = 1;
pOp->p3type = P3_NOTUSED;
}
}else if( n==P3_KEYINFO_HANDOFF ){
pOp->p3type = n;
}else{
if( n==0 ) n = strlen(zP3);
- pOp->p3 = sqliteStrNDup(zP3, n);
+ pOp->p3 = sqlite3DbStrNDup(p->db, zP3, n);
pOp->p3type = P3_DYNAMIC;
}
}
void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
va_list ap;
assert( p->nOp>0 || p->aOp==0 );
- assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 || sqlite3MallocFailed() );
+ assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 || p->db->mallocFailed );
va_start(ap, zFormat);
sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(zFormat, ap), P3_DYNAMIC);
va_end(ap);
*/
VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
assert( p->magic==VDBE_MAGIC_INIT );
- assert( (addr>=0 && addr<p->nOp) || sqlite3MallocFailed() );
+ assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
return ((addr>=0 && addr<p->nOp)?(&p->aOp[addr]):0);
}
if( isExplain ){
nStack = 10;
}
- p->aStack = sqliteMalloc(
+ p->aStack = sqlite3DbMallocZer(db,
nStack*sizeof(p->aStack[0]) /* aStack */
+ nArg*sizeof(Mem*) /* apArg */
+ nVar*sizeof(Mem) /* aVar */
+ nMem*sizeof(Mem) /* aMem */
+ nCursor*sizeof(Cursor*) /* apCsr */
);
- if( !sqlite3MallocFailed() ){
+ if( !db->mallocFailed ){
p->aMem = &p->aStack[nStack];
p->nMem = nMem;
p->aVar = &p->aMem[nMem];
p->inVtabMethod = 0;
}
#endif
- sqliteFree(pCx->pData);
- sqliteFree(pCx->aType);
- sqliteFree(pCx);
+ sqlite3_free(pCx->pData);
+ sqlite3_free(pCx->aType);
+ sqlite3_free(pCx);
}
/*
for(i=0; i<p->contextStackTop; i++){
sqlite3VdbeFifoClear(&p->contextStack[i].sFifo);
}
- sqliteFree(p->contextStack);
+ sqlite3_free(p->contextStack);
}
p->contextStack = 0;
p->contextStackDepth = 0;
p->contextStackTop = 0;
- sqliteFree(p->zErrMsg);
+ sqlite3_free(p->zErrMsg);
p->zErrMsg = 0;
p->resOnStack = 0;
}
Mem *pColName;
int n;
releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
- sqliteFree(p->aColName);
+ sqlite3_free(p->aColName);
n = nResColumn*COLNAME_N;
p->nResColumn = nResColumn;
- p->aColName = pColName = (Mem*)sqliteMalloc( sizeof(Mem)*n );
+ p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n );
if( p->aColName==0 ) return;
while( n-- > 0 ){
(pColName++)->flags = MEM_Null;
**
** If N==P3_STATIC it means that zName is a pointer to a constant static
** string and we can just copy the pointer. If it is P3_DYNAMIC, then
-** the string is freed using sqliteFree() when the vdbe is finished with
+** the string is freed using sqlite3_free() when the vdbe is finished with
** it. Otherwise, N bytes of zName are copied.
*/
int sqlite3VdbeSetColName(Vdbe *p, int idx, int var, const char *zName, int N){
Mem *pColName;
assert( idx<p->nResColumn );
assert( var<COLNAME_N );
- if( sqlite3MallocFailed() ) return SQLITE_NOMEM;
+ if( p->db->mallocFailed ) return SQLITE_NOMEM;
assert( p->aColName!=0 );
pColName = &(p->aColName[idx+var*p->nResColumn]);
if( N==P3_DYNAMIC || N==P3_STATIC ){
/* Select a master journal file name */
do {
u32 random;
- sqliteFree(zMaster);
+ sqlite3_free(zMaster);
sqlite3Randomness(sizeof(random), &random);
zMaster = sqlite3MPrintf("%s-mj%08X", zMainFile, random&0x7fffffff);
if( !zMaster ){
/* Open the master journal. */
rc = sqlite3OsOpenExclusive(zMaster, &master, 0);
if( rc!=SQLITE_OK ){
- sqliteFree(zMaster);
+ sqlite3_free(zMaster);
return rc;
}
if( rc!=SQLITE_OK ){
sqlite3OsClose(&master);
sqlite3OsDelete(zMaster);
- sqliteFree(zMaster);
+ sqlite3_free(zMaster);
return rc;
}
}
(needSync && (rc=sqlite3OsSync(master,0))!=SQLITE_OK) ){
sqlite3OsClose(&master);
sqlite3OsDelete(zMaster);
- sqliteFree(zMaster);
+ sqlite3_free(zMaster);
return rc;
}
#endif
}
sqlite3OsClose(&master);
if( rc!=SQLITE_OK ){
- sqliteFree(zMaster);
+ sqlite3_free(zMaster);
return rc;
}
** transaction files are deleted.
*/
rc = sqlite3OsDelete(zMaster);
- sqliteFree(zMaster);
+ sqlite3_free(zMaster);
zMaster = 0;
if( rc ){
return rc;
**
*/
- if( sqlite3MallocFailed() ){
+ if( p->db->mallocFailed ){
p->rc = SQLITE_NOMEM;
}
if( p->magic!=VDBE_MAGIC_RUN ){
Op *pOp = &p->aOp[i];
freeP3(pOp->p3type, pOp->p3);
}
- sqliteFree(p->aOp);
+ sqlite3_free(p->aOp);
}
releaseMemArray(p->aVar, p->nVar);
- sqliteFree(p->aLabel);
- sqliteFree(p->aStack);
+ sqlite3_free(p->aLabel);
+ sqlite3_free(p->aStack);
releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
- sqliteFree(p->aColName);
- sqliteFree(p->zSql);
+ sqlite3_free(p->aColName);
+ sqlite3_free(p->zSql);
p->magic = VDBE_MAGIC_DEAD;
- sqliteFree(p);
+ sqlite3_free(p);
}
/*
**
** This file contains code used to implement incremental BLOB I/O.
**
-** $Id: vdbeblob.c,v 1.11 2007/06/27 00:36:14 drh Exp $
+** $Id: vdbeblob.c,v 1.12 2007/08/16 04:30:41 drh Exp $
*/
#include "sqliteInt.h"
if( sParse.zErrMsg ){
sqlite3_snprintf(sizeof(zErr), zErr, "%s", sParse.zErrMsg);
}
- sqliteFree(sParse.zErrMsg);
+ sqlite3_free(sParse.zErrMsg);
rc = SQLITE_ERROR;
sqlite3SafetyOff(db);
goto blob_open_out;
** and offset cache without causing any IO.
*/
sqlite3VdbeChangeP2(v, 5, pTab->nCol+1);
- if( !sqlite3MallocFailed() ){
+ if( !db->mallocFailed ){
sqlite3VdbeMakeReady(v, 1, 0, 1, 0);
}
}
rc = sqlite3SafetyOff(db);
- if( rc!=SQLITE_OK || sqlite3MallocFailed() ){
+ if( rc!=SQLITE_OK || db->mallocFailed ){
goto blob_open_out;
}
rc = SQLITE_ERROR;
goto blob_open_out;
}
- pBlob = (Incrblob *)sqliteMalloc(sizeof(Incrblob));
- if( sqlite3MallocFailed() ){
- sqliteFree(pBlob);
+ pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
+ if( db->mallocFailed ){
+ sqlite3_free(pBlob);
goto blob_open_out;
}
pBlob->flags = flags;
blob_open_out:
zErr[sizeof(zErr)-1] = '\0';
- if( rc!=SQLITE_OK || sqlite3MallocFailed() ){
+ if( rc!=SQLITE_OK || db->mallocFailed ){
sqlite3_finalize((sqlite3_stmt *)v);
}
sqlite3Error(db, rc, (rc==SQLITE_OK?0:zErr));
int sqlite3_blob_close(sqlite3_blob *pBlob){
Incrblob *p = (Incrblob *)pBlob;
sqlite3_stmt *pStmt = p->pStmt;
- sqliteFree(p);
+ sqlite3_free(p);
return sqlite3_finalize(pStmt);
}
if( nEntry>32767 ){
nEntry = 32767;
}
- pPage = sqliteMallocRaw( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
+ pPage = sqlite3_malloc( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
if( pPage ){
pPage->nSlot = nEntry;
pPage->iWrite = 0;
pFifo->nEntry--;
if( pPage->iRead>=pPage->iWrite ){
pFifo->pFirst = pPage->pNext;
- sqliteFree(pPage);
+ sqlite3_free(pPage);
if( pFifo->nEntry==0 ){
assert( pFifo->pLast==pPage );
pFifo->pLast = 0;
FifoPage *pPage, *pNextPage;
for(pPage=pFifo->pFirst; pPage; pPage=pNextPage){
pNextPage = pPage->pNext;
- sqliteFree(pPage);
+ sqlite3_free(pPage);
}
sqlite3VdbeFifoInit(pFifo);
}
** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
** P if required.
*/
-#define expandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
+#define expandBlob(D,P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(D,P):0)
/*
** If pMem is an object with a valid string representation, this routine
**
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
*/
-int sqlite3VdbeMemDynamicify(Mem *pMem){
+int sqlite3VdbeMemDynamicify(sqlite3 *db, Mem *pMem){
int n;
u8 *z;
- expandBlob(pMem);
+ expandBlob(db, pMem);
if( (pMem->flags & (MEM_Ephem|MEM_Static|MEM_Short))==0 ){
return SQLITE_OK;
}
assert( (pMem->flags & MEM_Dyn)==0 );
n = pMem->n;
assert( pMem->flags & (MEM_Str|MEM_Blob) );
- z = sqliteMallocRaw( n+2 );
+ z = sqlite3_malloc( n+2 );
if( z==0 ){
return SQLITE_NOMEM;
}
** blob stored in dynamically allocated space.
*/
#ifndef SQLITE_OMIT_INCRBLOB
-int sqlite3VdbeMemExpandBlob(Mem *pMem){
+int sqlite3VdbeMemExpandBlob(sqlite3 *db, Mem *pMem){
if( pMem->flags & MEM_Zero ){
char *pNew;
int nByte;
assert( (pMem->flags & MEM_Blob)!=0 );
nByte = pMem->n + pMem->u.i;
if( nByte<=0 ) nByte = 1;
- pNew = sqliteMalloc(nByte);
- if( pNew==0 ){
+ pNew = sqlite3_malloc(nByte);
+ if( pNew==0 ){
+ if( db ) db->mallocFailed = 1;
return SQLITE_NOMEM;
}
memcpy(pNew, pMem->z, pMem->n);
**
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
*/
-int sqlite3VdbeMemMakeWriteable(Mem *pMem){
+int sqlite3VdbeMemMakeWriteable(sqlite3 *db, Mem *pMem){
int n;
u8 *z;
- expandBlob(pMem);
+ expandBlob(db, pMem);
if( (pMem->flags & (MEM_Ephem|MEM_Static))==0 ){
return SQLITE_OK;
}
z = (u8*)pMem->zShort;
pMem->flags |= MEM_Short|MEM_Term;
}else{
- z = sqliteMallocRaw( n+2 );
+ z = sqlite3_malloc( n+2 );
if( z==0 ){
+ db->mallocFailed = 1;
return SQLITE_NOMEM;
}
pMem->flags |= MEM_Dyn|MEM_Term;
/*
** Make sure the given Mem is \u0000 terminated.
*/
-int sqlite3VdbeMemNulTerminate(Mem *pMem){
+int sqlite3VdbeMemNulTerminate(sqlite3 *db, Mem *pMem){
if( (pMem->flags & MEM_Term)!=0 || (pMem->flags & MEM_Str)==0 ){
return SQLITE_OK; /* Nothing to do */
}
return sqlite3VdbeMemMakeWriteable(pMem);
}else{
char *z;
- sqlite3VdbeMemExpandBlob(pMem);
- z = sqliteMalloc(pMem->n+2);
-
- if( !z ) return SQLITE_NOMEM;
+ sqlite3VdbeMemExpandBlob(db, pMem);
+ z = sqlite3_malloc(pMem->n+2);
+ if( !z ){
+ db->mallocFailed = 1;
+ return SQLITE_NOMEM;
+ }
memcpy(z, pMem->z, pMem->n);
z[pMem->n] = 0;
z[pMem->n+1] = 0;
if( pMem->xDel ){
pMem->xDel(pMem->z);
}else{
- sqliteFree(pMem->z);
+ sqlite3_free(pMem->z);
}
pMem->xDel = 0;
pMem->z = z;
ctx.isError = 0;
pFunc->xFinalize(&ctx);
if( pMem->z && pMem->z!=pMem->zShort ){
- sqliteFree( pMem->z );
+ sqlite3_free( pMem->z );
}
*pMem = ctx.s;
if( pMem->flags & MEM_Short ){
p->xDel((void *)p->z);
}
}else{
- sqliteFree(p->z);
+ sqlite3_free(p->z);
}
p->z = 0;
p->xDel = 0;
** to read from the disk) then the pMem is left in an inconsistent state.
*/
int sqlite3VdbeMemFromBtree(
+ sqlite3 *db, /* Database connect to report malloc errors to */
BtCursor *pCur, /* Cursor pointing at record to retrieve. */
int offset, /* Offset from the start of data to return bytes from. */
int amt, /* Number of bytes to return. */
}else{
int rc;
if( amt>NBFS-2 ){
- zData = (char *)sqliteMallocRaw(amt+2);
+ zData = (char *)sqlite3_malloc(amt+2);
if( !zData ){
+ db->mallocFailed = 1;
return SQLITE_NOMEM;
}
pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
if( amt>NBFS-2 ){
assert( zData!=pMem->zShort );
assert( pMem->flags & MEM_Dyn );
- sqliteFree(zData);
+ sqlite3_free(zData);
} else {
assert( zData==pMem->zShort );
assert( pMem->flags & MEM_Short );
** If that is the case, then the result must be aligned on an even byte
** boundary.
*/
-const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
+const void *sqlite3ValueText(sqlite3 *db, sqlite3_value* pVal, u8 enc){
if( !pVal ) return 0;
assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
}
assert( (MEM_Blob>>3) == MEM_Str );
pVal->flags |= (pVal->flags & MEM_Blob)>>3;
- expandBlob(pVal);
+ expandBlob(db, pVal);
if( pVal->flags&MEM_Str ){
sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED);
if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&(int)pVal->z) ){
assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
- if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){
+ if( sqlite3VdbeMemMakeWriteable(db, pVal)!=SQLITE_OK ){
return 0;
}
}
- sqlite3VdbeMemNulTerminate(pVal);
+ sqlite3VdbeMemNulTerminate(db, pVal);
}else{
assert( (pVal->flags&MEM_Blob)==0 );
- sqlite3VdbeMemStringify(pVal, enc);
+ sqlite3VdbeMemStringify(db, pVal, enc);
assert( 0==(1&(int)pVal->z) );
}
- assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || sqlite3MallocFailed() );
+ assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || db->mallocFailed );
if( pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) ){
return pVal->z;
}else{
/*
** Create a new sqlite3_value object.
*/
-sqlite3_value *sqlite3ValueNew(void){
- Mem *p = sqliteMalloc(sizeof(*p));
+sqlite3_value *sqlite3ValueNew(sqlite3 *db){
+ Mem *p = sqlite3_malloc(sizeof(*p));
if( p ){
p->flags = MEM_Null;
p->type = SQLITE_NULL;
+ }else{
+ db->mallocFailed = 1;
}
return p;
}
** cannot be converted to a value, then *ppVal is set to NULL.
*/
int sqlite3ValueFromExpr(
- Expr *pExpr,
- u8 enc,
- u8 affinity,
- sqlite3_value **ppVal
+ sqlite3 *db, /* Report malloc() errors here */
+ Expr *pExpr, /* The expression to evaluate */
+ u8 enc, /* Encoding to use */
+ u8 affinity, /* Affinity to use */
+ sqlite3_value **ppVal /* Write the new value here */
){
int op;
char *zVal = 0;
op = pExpr->op;
if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
- zVal = sqliteStrNDup((char*)pExpr->token.z, pExpr->token.n);
- pVal = sqlite3ValueNew();
+ zVal = sqlite3StrNDup((char*)pExpr->token.z, pExpr->token.n);
+ pVal = sqlite3ValueNew(db);
if( !zVal || !pVal ) goto no_mem;
sqlite3Dequote(zVal);
- sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, sqlite3FreeX);
+ sqlite3ValueSetStr(db, pVal, -1, zVal, SQLITE_UTF8, sqlite3FreeX);
if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc);
}else{
else if( op==TK_BLOB ){
int nVal;
pVal = sqlite3ValueNew();
- zVal = sqliteStrNDup((char*)pExpr->token.z+1, pExpr->token.n-1);
+ zVal = sqlite3StrNDup((char*)pExpr->token.z+1, pExpr->token.n-1);
if( !zVal || !pVal ) goto no_mem;
sqlite3Dequote(zVal);
nVal = strlen(zVal)/2;
sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(zVal), nVal, 0, sqlite3FreeX);
- sqliteFree(zVal);
+ sqlite3_free(zVal);
}
#endif
return SQLITE_OK;
no_mem:
- sqliteFree(zVal);
+ db->mallocFailed = 1;
+ sqlite3_free(zVal);
sqlite3ValueFree(pVal);
*ppVal = 0;
return SQLITE_NOMEM;
** Change the string value of an sqlite3_value object
*/
void sqlite3ValueSetStr(
- sqlite3_value *v,
- int n,
- const void *z,
- u8 enc,
- void (*xDel)(void*)
+ sqlite3 *db, /* Report malloc errors here */
+ sqlite3_value *v, /* Value to be set */
+ int n, /* Length of string z */
+ const void *z, /* Text of the new string */
+ u8 enc, /* Encoding to use */
+ void (*xDel)(void*) /* Destructor for the string */
){
- if( v ) sqlite3VdbeMemSetStr((Mem *)v, z, n, enc, xDel);
+ if( v ) sqlite3VdbeMemSetStr(db, (Mem *)v, z, n, enc, xDel);
}
/*
void sqlite3ValueFree(sqlite3_value *v){
if( !v ) return;
sqlite3ValueSetStr(v, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
- sqliteFree(v);
+ sqlite3_free(v);
}
/*
*************************************************************************
** This file contains code used to help implement virtual tables.
**
-** $Id: vtab.c,v 1.48 2007/06/26 10:38:55 danielk1977 Exp $
+** $Id: vtab.c,v 1.49 2007/08/16 04:30:41 drh Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
void (*xDestroy)(void *) /* Module destructor function */
) {
int nName = strlen(zName);
- Module *pMod = (Module *)sqliteMallocRaw(sizeof(Module) + nName + 1);
+ Module *pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
if( pMod ){
char *zCopy = (char *)(&pMod[1]);
memcpy(zCopy, zName, nName+1);
if( pMod && pMod->xDestroy ){
pMod->xDestroy(pMod->pAux);
}
- sqliteFree(pMod);
+ sqlite3_free(pMod);
sqlite3ResetInternalSchema(db, 0);
}
return sqlite3ApiExit(db, SQLITE_OK);
if( p->azModuleArg ){
int i;
for(i=0; i<p->nModuleArg; i++){
- sqliteFree(p->azModuleArg[i]);
+ sqlite3_free(p->azModuleArg[i]);
}
- sqliteFree(p->azModuleArg);
+ sqlite3_free(p->azModuleArg);
}
}
** string will be freed automatically when the table is
** deleted.
*/
-static void addModuleArgument(Table *pTable, char *zArg){
+static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
int i = pTable->nModuleArg++;
int nBytes = sizeof(char *)*(1+pTable->nModuleArg);
char **azModuleArg;
- azModuleArg = sqliteRealloc(pTable->azModuleArg, nBytes);
+ azModuleArg = sqlite3_realloc(pTable->azModuleArg, nBytes);
if( azModuleArg==0 ){
int j;
for(j=0; j<i; j++){
- sqliteFree(pTable->azModuleArg[j]);
+ sqlite3_free(pTable->azModuleArg[j]);
}
- sqliteFree(zArg);
- sqliteFree(pTable->azModuleArg);
+ sqlite3_free(zArg);
+ sqlite3_free(pTable->azModuleArg);
pTable->nModuleArg = 0;
+ db->mallocFailed = 1;
}else{
azModuleArg[i] = zArg;
azModuleArg[i+1] = 0;
){
int iDb; /* The database the table is being created in */
Table *pTable; /* The new virtual table */
+ sqlite3 *db; /* Database connection */
#ifndef SQLITE_OMIT_SHARED_CACHE
if( sqlite3ThreadDataReadOnly()->useSharedData ){
if( pTable==0 || pParse->nErr ) return;
assert( 0==pTable->pIndex );
- iDb = sqlite3SchemaToIndex(pParse->db, pTable->pSchema);
+ db = pParse->db;
+ iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
assert( iDb>=0 );
pTable->isVirtual = 1;
pTable->nModuleArg = 0;
- addModuleArgument(pTable, sqlite3NameFromToken(pModuleName));
- addModuleArgument(pTable, sqlite3StrDup(pParse->db->aDb[iDb].zName));
- addModuleArgument(pTable, sqlite3StrDup(pTable->zName));
+ addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
+ addModuleArgument(db, pTable, sqlite3DbStrDup(db, db->aDb[iDb].zName));
+ addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
pParse->sNameToken.n = pModuleName->z + pModuleName->n - pName1->z;
#ifndef SQLITE_OMIT_AUTHORIZATION
if( pParse->sArg.z && pParse->pNewTable ){
const char *z = (const char*)pParse->sArg.z;
int n = pParse->sArg.n;
- addModuleArgument(pParse->pNewTable, sqliteStrNDup(z, n));
+ sqlite3 *db = pParse->db;
+ addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
}
}
pTab->zName,
zStmt
);
- sqliteFree(zStmt);
+ sqlite3_free(zStmt);
v = sqlite3GetVdbe(pParse);
sqlite3ChangeCookie(db, v, iDb);
rc = rc2;
}
db->pVTab = 0;
- sqliteFree(zModuleName);
+ sqlite3_free(zModuleName);
/* If everything went according to plan, loop through the columns
** of the table to see if any of them contain the token "hidden".
if( rc!=SQLITE_OK ){
sqlite3ErrorMsg(pParse, "%s", zErr);
}
- sqliteFree(zErr);
+ sqlite3_free(zErr);
}
return rc;
if( (db->nVTrans%ARRAY_INCR)==0 ){
sqlite3_vtab **aVTrans;
int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
- aVTrans = sqliteRealloc((void *)db->aVTrans, nBytes);
+ aVTrans = sqlite3_realloc((void *)db->aVTrans, nBytes);
if( !aVTrans ){
+ db->mallocFailed = 1;
return SQLITE_NOMEM;
}
memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
**
** If an error occurs, *pzErr is set to point an an English language
** description of the error and an SQLITE_XXX error code is returned.
-** In this case the caller must call sqliteFree() on *pzErr.
+** In this case the caller must call sqlite3_free() on *pzErr.
*/
int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
int rc = SQLITE_OK;
db->pVTab = 0;
} else {
sqlite3Error(db, SQLITE_ERROR, zErr);
- sqliteFree(zErr);
+ sqlite3_free(zErr);
rc = SQLITE_ERROR;
}
sParse.declareVtab = 0;
if( x ) x(pVtab);
sqlite3VtabUnlock(db, pVtab);
}
- sqliteFree(db->aVTrans);
+ sqlite3_free(db->aVTrans);
db->nVTrans = 0;
db->aVTrans = 0;
}
** SQLITE_FUNC_EPHEM flag.
*/
FuncDef *sqlite3VtabOverloadFunction(
+ sqlite3 *db, /* Database connection for reporting malloc problems */
FuncDef *pDef, /* Function to possibly overload */
int nArg, /* Number of arguments to the function */
Expr *pExpr /* First argument to the function */
/* Call the xFuncFunction method on the virtual table implementation
** to see if the implementation wants to overload this function
*/
- zLowerName = sqlite3StrDup(pDef->zName);
- for(z=(unsigned char*)zLowerName; *z; z++){
- *z = sqlite3UpperToLower[*z];
+ zLowerName = sqlite3DbStrDup(db, pDef->zName);
+ if( zLowerName ){
+ for(z=(unsigned char*)zLowerName; *z; z++){
+ *z = sqlite3UpperToLower[*z];
+ }
+ rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xFunc, &pArg);
+ sqlite3_free(zLowerName);
}
- rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xFunc, &pArg);
- sqliteFree(zLowerName);
if( rc==0 ){
return pDef;
}
/* Create a new ephemeral function definition for the overloaded
** function */
- pNew = sqliteMalloc( sizeof(*pNew) + strlen(pDef->zName) );
+ pNew = sqlite3DbMallocZero(db, sizeof(*pNew) + strlen(pDef->zName) );
if( pNew==0 ){
return pDef;
}
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
-** $Id: where.c,v 1.254 2007/07/30 14:40:48 danielk1977 Exp $
+** $Id: where.c,v 1.255 2007/08/16 04:30:41 drh Exp $
*/
#include "sqliteInt.h"
}
}
if( pWC->a!=pWC->aStatic ){
- sqliteFree(pWC->a);
+ sqlite3_free(pWC->a);
}
}
int idx;
if( pWC->nTerm>=pWC->nSlot ){
WhereTerm *pOld = pWC->a;
- pWC->a = sqliteMalloc( sizeof(pWC->a[0])*pWC->nSlot*2 );
+ pWC->a = sqlite3_malloc( sizeof(pWC->a[0])*pWC->nSlot*2 );
if( pWC->a==0 ){
+ pWC->pParse->db->mallocFailed = 1;
if( flags & TERM_DYNAMIC ){
sqlite3ExprDelete(p);
}
}
memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
if( pOld!=pWC->aStatic ){
- sqliteFree(pOld);
+ sqlite3_free(pOld);
}
pWC->nSlot *= 2;
}
(pColl->type!=SQLITE_COLL_NOCASE || !noCase) ){
return 0;
}
- sqlite3DequoteExpr(pRight);
+ sqlite3DequoteExpr(db, pRight);
z = (char *)pRight->token.z;
for(cnt=0; (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2]; cnt++){}
if( cnt==0 || 255==(u8)z[cnt] ){
int nPattern;
int isComplete;
int op;
+ sqlite3 *db = pWC->pParse->db;
- if( sqlite3MallocFailed() ) return;
+ if( db->mallocFailed ) return;
prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft);
op = pExpr->op;
if( op==TK_IN ){
Expr *pDup;
if( pTerm->leftCursor>=0 ){
int idxNew;
- pDup = sqlite3ExprDup(pExpr);
- if( sqlite3MallocFailed() ){
+ pDup = sqlite3ExprDup(db, pExpr);
+ if( db->mallocFailed ){
sqlite3ExprDelete(pDup);
return;
}
for(i=0; i<2; i++){
Expr *pNewExpr;
int idxNew;
- pNewExpr = sqlite3Expr(ops[i], sqlite3ExprDup(pExpr->pLeft),
- sqlite3ExprDup(pList->a[i].pExpr), 0);
+ pNewExpr = sqlite3Expr(ops[i], sqlite3ExprDup(db, pExpr->pLeft),
+ sqlite3ExprDup(db, pList->a[i].pExpr), 0);
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
exprAnalyze(pSrc, pWC, idxNew);
pTerm = &pWC->a[idxTerm];
Expr *pLeft = 0;
for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0 && ok; i--, pOrTerm++){
if( (pOrTerm->flags & TERM_OR_OK)==0 ) continue;
- pDup = sqlite3ExprDup(pOrTerm->pExpr->pRight);
- pList = sqlite3ExprListAppend(pList, pDup, 0);
+ pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight);
+ pList = sqlite3ExprListAppend(pWC->pParse, pList, pDup, 0);
pLeft = pOrTerm->pExpr->pLeft;
}
assert( pLeft!=0 );
- pDup = sqlite3ExprDup(pLeft);
+ pDup = sqlite3ExprDup(db, pLeft);
pNew = sqlite3Expr(TK_IN, pDup, 0, 0);
if( pNew ){
int idxNew;
/* Add constraints to reduce the search space on a LIKE or GLOB
** operator.
*/
- if( isLikeOrGlob(pWC->pParse->db, pExpr, &nPattern, &isComplete) ){
+ if( isLikeOrGlob(db, pExpr, &nPattern, &isComplete) ){
Expr *pLeft, *pRight;
Expr *pStr1, *pStr2;
Expr *pNewExpr1, *pNewExpr2;
pLeft = pExpr->pList->a[1].pExpr;
pRight = pExpr->pList->a[0].pExpr;
- pStr1 = sqlite3Expr(TK_STRING, 0, 0, 0);
+ pStr1 = sqlite3PExpr(pParse, TK_STRING, 0, 0, 0);
if( pStr1 ){
- sqlite3TokenCopy(&pStr1->token, &pRight->token);
+ sqlite3TokenCopy(db, &pStr1->token, &pRight->token);
pStr1->token.n = nPattern;
pStr1->flags = EP_Dequoted;
}
- pStr2 = sqlite3ExprDup(pStr1);
+ pStr2 = sqlite3ExprDup(db, pStr1);
if( pStr2 ){
assert( pStr2->token.dyn );
++*(u8*)&pStr2->token.z[nPattern-1];
}
- pNewExpr1 = sqlite3Expr(TK_GE, sqlite3ExprDup(pLeft), pStr1, 0);
+ pNewExpr1 = sqlite3PExpr(pParse, TK_GE, sqlite3ExprDup(db,pLeft), pStr1, 0);
idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC);
exprAnalyze(pSrc, pWC, idxNew1);
- pNewExpr2 = sqlite3Expr(TK_LT, sqlite3ExprDup(pLeft), pStr2, 0);
+ pNewExpr2 = sqlite3PExpr(pParse, TK_LT, sqlite3ExprDup(db,pLeft), pStr2, 0);
idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
exprAnalyze(pSrc, pWC, idxNew2);
pTerm = &pWC->a[idxTerm];
prereqColumn = exprTableUsage(pMaskSet, pLeft);
if( (prereqExpr & prereqColumn)==0 ){
Expr *pNewExpr;
- pNewExpr = sqlite3Expr(TK_MATCH, 0, sqlite3ExprDup(pRight), 0);
+ pNewExpr = sqlite3Expr(TK_MATCH, 0, sqlite3ExprDup(db, pRight), 0);
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
pNewTerm = &pWC->a[idxNew];
pNewTerm->prereqRight = prereqExpr;
/* Allocate the sqlite3_index_info structure
*/
- pIdxInfo = sqliteMalloc( sizeof(*pIdxInfo)
+ pIdxInfo = sqlite3_malloc( sizeof(*pIdxInfo)
+ (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
+ sizeof(*pIdxOrderBy)*nOrderBy );
if( pIdxInfo==0 ){
+ pParse->db->mallocFailed = 1;
sqlite3ErrorMsg(pParse, "out of memory");
return 0.0;
}
TRACE_IDX_OUTPUTS(pIdxInfo);
if( rc!=SQLITE_OK ){
if( rc==SQLITE_NOMEM ){
- sqlite3FailedMalloc();
+ pParse->db->mallocFailed = 1;
}else {
sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
}
pLevel->nxt = sqlite3VdbeMakeLabel(v);
}
pLevel->nIn++;
- pLevel->aInLoop = sqliteReallocOrFree(pLevel->aInLoop,
+ pLevel->aInLoop = sqlite3DbReallocOrFree(pParse->db, pLevel->aInLoop,
sizeof(pLevel->aInLoop[0])*pLevel->nIn);
pIn = pLevel->aInLoop;
if( pIn ){
*/
sqlite3_free(pInfo->idxStr);
}
- sqliteFree(pInfo);
+ sqlite3_free(pInfo);
}
}
- sqliteFree(pWInfo);
+ sqlite3_free(pWInfo);
}
}
WhereLevel *pLevel; /* A single level in the pWInfo list */
int iFrom; /* First unused FROM clause element */
int andFlags; /* AND-ed combination of all wc.a[].flags */
+ sqlite3 *db; /* Database connection */
/* The number of tables in the FROM clause is limited by the number of
** bits in a Bitmask
/* Allocate and initialize the WhereInfo structure that will become the
** return value.
*/
- pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
- if( sqlite3MallocFailed() ){
+ db = pParse->db;
+ pWInfo = sqlite3DbMallocZero(db,
+ sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
+ if( db->mallocFailed ){
goto whereBeginNoMem;
}
pWInfo->nLevel = pTabList->nSrc;
createMask(&maskSet, pTabList->a[i].iCursor);
}
exprAnalyzeAll(pTabList, &wc);
- if( sqlite3MallocFailed() ){
+ if( db->mallocFailed ){
goto whereBeginNoMem;
}
sqlite3VdbeAddOp(v, OP_Next, pIn->iCur, pIn->topAddr);
sqlite3VdbeJumpHere(v, pIn->topAddr-1);
}
- sqliteFree(pLevel->aInLoop);
+ sqlite3_free(pLevel->aInLoop);
}
sqlite3VdbeResolveLabel(v, pLevel->brk);
if( pLevel->iLeftJoin ){