$(TOP)/src/test4.c \
$(TOP)/src/test5.c \
$(TOP)/src/test6.c \
- $(TOP)/src/test_async.c \
$(TOP)/src/utf.c \
$(TOP)/src/util.c \
$(TOP)/src/vdbe.c \
libsqlite3.la $(LIBTCL)
testfixture$(TEXE): $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC)
- $(LTLINK) -DTCLSH=1 -DSQLITE_TEST=1 $(TEMP_STORE) \
- -o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
+ $(LTLINK) -DTCLSH=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 \
+ $(TEMP_STORE) -o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
libsqlite3.la $(LIBTCL)
$(TOP)/src/test4.c \
$(TOP)/src/test5.c \
$(TOP)/src/test6.c \
- $(TOP)/src/test_async.c \
$(TOP)/src/utf.c \
$(TOP)/src/util.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/md5.c \
$(TOP)/src/where.c
-# $(TOP)/src/test_async.c
-
# Header files used by all library source files.
#
HDR = \
$(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC)
- $(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
+ $(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 \
+ -o testfixture$(EXE) \
$(TESTSRC) $(TOP)/src/tclsqlite.c \
libsqlite3.a $(LIBTCL) $(THREADLIB)
-C Add\ssome\ssimple\stests\sand\sfixes\sfor\sshared-schema\slocking.\s(CVS\s2869)
-D 2006-01-06T13:00:29
-F Makefile.in 131285a3e97597dd7ed3eb23a1010c7d0685ae41
+C Change\sthe\sOS\sinterface\slayer\sto\suse\straditional\sdirect\sfunction\scall\nimplementations\sinstead\sof\sthe\smore\scomplicated\svirtual\sfunction\stable.\nOmit\sthe\sasynchronous\sI/O\sdemo.\s(CVS\s2870)
+D 2006-01-06T14:32:20
+F Makefile.in c79fbdaa264c6afcd435f2fb492551de5a8cf80d
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F VERSION b818cce180263e590a00ad4509a713892c3eecea
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
-F main.mk 27186ccd25ac0a49a0c0fae4b4e24db90b541bda
+F main.mk 00b93700cf43e68d2a7f82c693f991f40889ef86
F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512
F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
F mkopcodeh.awk 071dbba4eaf56c8d643baf4604a043af35683316
F src/analyze.c d821684cdb4d0403e327e4a3440a832e9e54fa3a
F src/attach.c 999104c56a60b88eab11ef9c8f40dedf1650b287
F src/auth.c cdec356a5cd8b217c346f816c5912221537fe87f
-F src/btree.c f34c1e8d93003cbd8cc579865e0c0db4f595b97e
+F src/btree.c f60d2b66d10f81dd343f0887054c91b40f8746d4
F src/btree.h f7ba8e2f9f387cca4978e1495504a0bf556dcbf2
F src/build.c 715ac7d49bbfcae5f3fdfd60885397b2133c283b
F src/callback.c 62066afd516f220575e81b1a1239ab92a2eae252
F src/complete.c df1681cef40dec33a286006981845f87b194e7a4
-F src/date.c bb079317bff6a2b78aba5c0d2ddae5f6f03acfb7
+F src/date.c 9a1fe548e31a9b14a43b88f711254a968929659d
F src/delete.c 2479a8419c76cd4c13f2181d399425ec215ceeb9
F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
F src/expr.c ed2a272c7afd63232ca04881159ce2366266e35d
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
F src/insert.c d167f9d41932ddaff9162f116e2abc514b0680b6
F src/legacy.c 59757d857ab95fcbb0ac27692d3201e35f093dd7
-F src/main.c 244a346ae0d1953c4c872b3429b8712b32f590a1
+F src/main.c b43ca57f8aed9b1cd08a7e0119c764d09a61d4be
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
-F src/os.c a1953975771e1afa161a96e720e58a6f77f946e4
-F src/os.h 907e939f30eb01555ad34f4f96cd9333bf0495ea
-F src/os_common.h d0b1f2f32926e9b6db7886a7f43008b596a9e926
+F src/os.c bdd3a2fd089777e7ad18b57c896f1141d5a0c1fd
+F src/os.h 6e61d5e901dfec761660707e892890f6760b5e63
+F src/os_common.h 78bcc34dded9b625b3c16d072b7e5b76d075a674
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
-F src/os_unix.c d99158f78926e9cc6a9b3e1a96fd6bf6d4205bfa
+F src/os_unix.c d220bf3721357581214f261f8c6028060930177d
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
-F src/os_win.c c774f888088ad8fa80e501feeaa083dc467eed78
+F src/os_win.c 3239b124d2400ed30d213053df43dc29405d018f
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c 07509ddb478f5a70f9ff53607ab8a44456c22811
+F src/pager.c f06b85eb1e43bb2e6a7a5108ac8346576b4b78fa
F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
F src/parse.y 58258759fabdd48f1d2561e276097290b1ea2680
-F src/pragma.c 4af4041a88d41421b8ff2e5574d82d7b9d1e35b1
+F src/pragma.c ae8b135531e7a4d692c60bd909c819d0b3fc588a
F src/prepare.c 48baea211104dfcfa59857a32d62c934f63a15ed
F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812
-F src/random.c ff5e9a8cad790e2a51cd4d2e7737dc8540e09d1d
+F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
F src/select.c a60e5c7fad9ce7adc78d9eb32a0a89dd5acd04fb
F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da
F src/sqlite.h.in ba3a29daa6a16e054191ccb384a981964e882a1d
F src/sqliteInt.h 9b89651a99687e25bdab1e4e33b7dcadcd890283
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
-F src/tclsqlite.c 6794d34f6ad3dc7dd25eecde887696e569f8efe1
-F src/test1.c 89e25646feceaf09e55c11ecba03ddcfd7cf7c0a
-F src/test2.c 36390cdfc70c08e5ee0b466d0654a117f398bbff
+F src/tclsqlite.c 42151e6c78502277be77b88c00535d53ce89b917
+F src/test1.c 8e62d29dbf511b603dee63af886c43fa83d5a680
+F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b
F src/test3.c 9742aa146eb750cab81c1d5605286c3a0eb88054
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
-F src/test6.c cb811391ec0b7c75f29e545d4820a9cf19f3637e
-F src/test_async.c 7b27d91e288503a568bfbc607b58dcfb74f09057
+F src/test6.c 2c195d0734f8b3517331f62c088bf6cede3818a5
F src/tokenize.c 7a3a3d3cc734f684a77c4dfd09eb46fcee25394c
F src/trigger.c 858c0a4974035b002fd2192399c6076ac7b75e1f
F src/update.c c72e9cbbc0adf8d728c1c39ace03d4adb29b5cfb
F src/utf.c b7bffac4260177ae7f83c01d025fe0f5ed70ce71
-F src/util.c f79eb05721e7b20d1d323f903ea866ed2670c2a4
-F src/vacuum.c fbfdd3967fd34e2f260fafed88dcbf3c10856b94
-F src/vdbe.c 4dab34666edca29b937180965ad32120e98c8054
+F src/util.c 23d70b1f7e88a603d4baf28ac9592d38f60f2605
+F src/vacuum.c a7301804d4f849da0ce9d869219c71c6d621c34e
+F src/vdbe.c 61f37ba6f30c3f1f5c27c9daee517c7e5949c5f9
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
F src/vdbeInt.h 9b78ba00cc006bff17e04a54ba3ded9fc7810a10
-F src/vdbeapi.c b270b680cbc5d20b5a1abfdb08339667985df94e
-F src/vdbeaux.c 7d55232a7e8c21899bbfc9ba3bd2469eb32faaf0
+F src/vdbeapi.c 7335569b1bad946ba53892384b4b1534e877b1ee
+F src/vdbeaux.c a4eea656afebc6161771ddfa7a9c91186a5d7888
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c deba8d6e3727643924b210a8c531a496c2b8d386
F src/where.c 3ec45076e7cce523aad34eaf9bd119237b56942a
F test/alter3.test 6e144ea3dcc395afcc28e794bb532be83dc8fdcb
F test/altermalloc.test 6e1f404ec021eb2ba6582e3c77b0a35cf206b7af
F test/analyze.test 2f55535aa335785db1a2f97d3f3831c16c09f8b0
-F test/async.test 522826f998b24328ce221971dc30ebbc7c0c4adc
F test/attach.test dae07fa1554b618b9cc4c7bc349b3bc1a532180e
F test/attach2.test 0e6a7c54343c85dd877a1e86073a05176043ed40
F test/attach3.test 63013383adc4380af69779f34f4af19bd49f7cbe
F test/conflict.test bc7b81670abfd6ca51cbcbf46ef23cd52784fafd
F test/corrupt.test 18c7a995b1af76a8c8600b996257f2c7b7bff083
F test/corrupt2.test 88342570828f2b8cbbd8369eff3891f5c0bdd5ba
-F test/crash.test 504a4eee0ce78f00d16a5a324e42964bd85164f5
+F test/crash.test 5f5f155393c5685b3842fef79b6fbafa55197d75
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F test/date.test 30ca15e608a45d868fd419c901795382efe27020
F test/default.test 252298e42a680146b1dd64f563b95bdf088d94fb
F test/insert3.test c67f0240b1c17e71fa2ed8bb6de064928f549f95
F test/interrupt.test cd24dc5bedd02325be4bfa5d6209fae01c465157
F test/intpkey.test af4fd826c4784ec5c93b444de07adea0254d0d30
-F test/ioerr.test c3f71a60be73404bc5ae344e171b505d9af49320
+F test/ioerr.test aca09f9b303e2e69a42b61298e6e659d92e5c532
F test/join.test db3802739fb695bdfa2e88805e3d64ec5ffbebd1
F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
F test/main.test b12f01d49a5c805a33fa6c0ef168691f63056e79
-F test/malloc.test a5ed721cf7d1b12602ede4f98c11b65ab1582cc0
+F test/malloc.test 6245418d1b6635a2095d9ed0f5e84e029990da06
F test/malloc2.test e6e321db96d6c94cb18bf82ad7215070c41e624e
F test/malloc3.test 9797d39eca7087a1022bcc0eb0b22215475c9698
F test/malloc4.test 2e29d155eb4b4808019ef47eeedfcbe9e09e0f05
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 0c4c45c36fe1c3c2980155ef5126a2ad53100d65
-R c892910cec71c19aeb323bc85b1a92ea
-U danielk1977
-Z 5e6321921a4935029ecd84d938104014
+P d054bed15aee3edef93cc84c83be443cdd489946
+R 9f9ead22d0bda9c720999a0d4a57571c
+U drh
+Z eaba12b8d678120171754da949bccb7f
-d054bed15aee3edef93cc84c83be443cdd489946
\ No newline at end of file
+2529c2e11fa1d345ec61f647e4f6fae20a7133d6
\ No newline at end of file
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.282 2006/01/06 13:00:29 danielk1977 Exp $
+** $Id: btree.c,v 1.283 2006/01/06 14:32:20 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
/* Try to find an existing Btree structure opened on zFilename. */
#ifndef SQLITE_OMIT_SHARED_CACHE
if( pTsd->useSharedData && zFilename && !isMemdb ){
- char *zFullPathname = sqlite3Os.xFullPathname(zFilename);
+ char *zFullPathname = sqlite3OsFullPathname(zFilename);
if( !zFullPathname ){
sqliteFree(p);
return SQLITE_NOMEM;
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: date.c,v 1.47 2005/12/09 20:02:05 drh Exp $
+** $Id: date.c,v 1.48 2006/01/06 14:32:20 drh Exp $
**
** NOTES:
**
return 0;
}else if( sqlite3StrICmp(zDate,"now")==0){
double r;
- sqlite3Os.xCurrentTime(&r);
+ sqlite3OsCurrentTime(&r);
p->rJD = r;
p->validJD = 1;
return 0;
x.validJD = 0;
computeJD(&x);
t = (x.rJD-2440587.5)*86400.0 + 0.5;
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
pTm = localtime(&t);
y.Y = pTm->tm_year + 1900;
y.M = pTm->tm_mon + 1;
y.h = pTm->tm_hour;
y.m = pTm->tm_min;
y.s = pTm->tm_sec;
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
y.validYMD = 1;
y.validHMS = 1;
y.validJD = 0;
}
#endif
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
strftime(zBuf, 20, zFormat, gmtime(&t));
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
}
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: main.c,v 1.316 2006/01/06 06:33:13 danielk1977 Exp $
+** $Id: main.c,v 1.317 2006/01/06 14:32:20 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
delay = timeout - prior;
if( delay<=0 ) return 0;
}
- sqlite3Os.xSleep(delay);
+ sqlite3OsSleep(delay);
return 1;
#else
int timeout = ((sqlite3 *)ptr)->busyTimeout;
if( (count+1)*1000 > timeout ){
return 0;
}
- sqlite3Os.xSleep(1000);
+ sqlite3OsSleep(1000);
return 1;
#endif
}
int sqlite3OsCheckReservedLock(OsFile *id){
return id->pMethod->xCheckReservedLock(id);
}
-struct sqlite3OsVtbl *sqlite3_os_switch(void){
- return &sqlite3Os;
-}
#define _SQLITE_OS_H_
/*
-** Figure out if we are dealing with Unix, Windows or MacOS.
-**
-** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
-** The MacOS build is designed to use CodeWarrior (tested with v8)
+** Figure out if we are dealing with Unix, Windows, or some other
+** operating system.
*/
-#if !defined(OS_UNIX) && !defined(OS_ALT)
+#if !defined(OS_UNIX) && !defined(OS_OTHER)
# define OS_OTHER 0
# ifndef OS_WIN
# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
# define TEMP_FILE_PREFIX "sqlite_"
#endif
+/*
+** Define the interfaces for Unix and for Windows.
+*/
+#if OS_UNIX
+#define sqlite3OsOpenReadWrite sqlite3UnixOpenReadWrite
+#define sqlite3OsOpenExclusive sqlite3UnixOpenExclusive
+#define sqlite3OsOpenReadOnly sqlite3UnixOpenReadOnly
+#define sqlite3OsDelete sqlite3UnixDelete
+#define sqlite3OsFileExists sqlite3UnixFileExists
+#define sqlite3OsFullPathname sqlite3UnixFullPathname
+#define sqlite3OsIsDirWritable sqlite3UnixIsDirWritable
+#define sqlite3OsSyncDirectory sqlite3UnixSyncDirectory
+#define sqlite3OsTempFileName sqlite3UnixTempFileName
+#define sqlite3OsRandomSeed sqlite3UnixRandomSeed
+#define sqlite3OsSleep sqlite3UnixSleep
+#define sqlite3OsCurrentTime sqlite3UnixCurrentTime
+#define sqlite3OsEnterMutex sqlite3UnixEnterMutex
+#define sqlite3OsLeaveMutex sqlite3UnixLeaveMutex
+#define sqlite3OsInMutex sqlite3UnixInMutex
+#define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData
+#define sqlite3OsMalloc sqlite3GenericMalloc
+#define sqlite3OsRealloc sqlite3GenericRealloc
+#define sqlite3OsFree sqlite3GenericFree
+#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
+#endif
+#if OS_WIN
+#define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite
+#define sqlite3OsOpenExclusive sqlite3WinOpenExclusive
+#define sqlite3OsOpenReadOnly sqlite3WinOpenReadOnly
+#define sqlite3OsDelete sqlite3WinDelete
+#define sqlite3OsFileExists sqlite3WinFileExists
+#define sqlite3OsFullPathname sqlite3WinFullPathname
+#define sqlite3OsIsDirWritable sqlite3WinIsDirWritable
+#define sqlite3OsSyncDirectory sqlite3WinSyncDirectory
+#define sqlite3OsTempFileName sqlite3WinTempFileName
+#define sqlite3OsRandomSeed sqlite3WinRandomSeed
+#define sqlite3OsSleep sqlite3WinSleep
+#define sqlite3OsCurrentTime sqlite3WinCurrentTime
+#define sqlite3OsEnterMutex sqlite3WinEnterMutex
+#define sqlite3OsLeaveMutex sqlite3WinLeaveMutex
+#define sqlite3OsInMutex sqlite3WinInMutex
+#define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData
+#define sqlite3OsMalloc sqlite3GenericMalloc
+#define sqlite3OsRealloc sqlite3GenericRealloc
+#define sqlite3OsFree sqlite3GenericFree
+#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
+#endif
+
+/*
+** If using an alternative OS interface, then we must have an "os_other.h"
+** header file available for that interface. Presumably the "os_other.h"
+** header file contains #defines similar to those above.
+*/
+#if OS_OTHER
+# include "os_other.h"
+#endif
+
+
+
/*
** Forward declarations
*/
#define SHARED_SIZE 510
/*
-** A single global instance of the following structure holds pointers to
-** the routines that SQLite uses to talk with the underlying operating
-** system. Modify this structure (before using any SQLite API!) to
-** accomodate perculiar operating system interfaces or behaviors.
-*/
-extern struct sqlite3OsVtbl {
- int (*xOpenReadWrite)(const char*, OsFile**, int*);
- int (*xOpenExclusive)(const char*, OsFile**, int);
- int (*xOpenReadOnly)(const char*, OsFile**);
-
- int (*xDelete)(const char*);
- int (*xFileExists)(const char*);
- char *(*xFullPathname)(const char*);
- int (*xIsDirWritable)(char*);
- int (*xSyncDirectory)(const char*);
- int (*xTempFileName)(char*);
-
- int (*xRandomSeed)(char*);
- int (*xSleep)(int ms);
- int (*xCurrentTime)(double*);
-
- void (*xEnterMutex)(void);
- void (*xLeaveMutex)(void);
- int (*xInMutex)(void);
- void *(*xThreadSpecificData)(int);
-
- void *(*xMalloc)(int);
- void *(*xRealloc)(void *, int);
- void (*xFree)(void *);
- int (*xAllocationSize)(void *);
-} sqlite3Os;
-
-/*
-** The following API routine returns a pointer to the sqlite3Os global
-** variable. It is probably easier just to reference the global variable
-** directly. This routine is provided for backwards compatibility with
-** an older interface design.
-*/
-struct sqlite3OsVtbl *sqlite3_os_switch(void);
-
-
-/*
-** The following are prototypes of convenience routines that simply
-** call the corresponding routines in the OsFile.pMethod virtual
-** function table.
+** Prototypes for operating system interface routines.
*/
int sqlite3OsClose(OsFile**);
int sqlite3OsOpenDirectory(OsFile*, const char*);
int sqlite3OsUnlock(OsFile*, int);
int sqlite3OsLockState(OsFile *id);
int sqlite3OsCheckReservedLock(OsFile *id);
+int sqlite3OsOpenReadWrite(const char*, OsFile**, int*);
+int sqlite3OsOpenExclusive(const char*, OsFile**, int);
+int sqlite3OsOpenReadOnly(const char*, OsFile**);
+int sqlite3OsDelete(const char*);
+int sqlite3OsFileExists(const char*);
+char *sqlite3OsFullPathname(const char*);
+int sqlite3OsIsDirWritable(char*);
+int sqlite3OsSyncDirectory(const char*);
+int sqlite3OsTempFileName(char*);
+int sqlite3OsRandomSeed(char*);
+int sqlite3OsSleep(int ms);
+int sqlite3OsCurrentTime(double*);
+void sqlite3OsEnterMutex(void);
+void sqlite3OsLeaveMutex(void);
+int sqlite3OsInMutex(void);
+void *sqlite3OsThreadSpecificData(int);
+void *sqlite3OsMalloc(int);
+void *sqlite3OsRealloc(void *, int);
+void sqlite3OsFree(void *);
+int sqlite3OsAllocationSize(void *);
#endif /* _SQLITE_OS_H_ */
#endif
/*
-** genericMalloc
-** genericRealloc
-** genericOsFree
-** genericAllocationSize
+** sqlite3GenericMalloc
+** sqlite3GenericRealloc
+** sqlite3GenericOsFree
+** sqlite3GenericAllocationSize
**
** Implementation of the os level dynamic memory allocation interface in terms
** of the standard malloc(), realloc() and free() found in many operating
** systems. No rocket science here.
*/
-static void *genericMalloc(int n){
+void *sqlite3GenericMalloc(int n){
char *p = (char *)malloc(n+8);
assert(n>0);
assert(sizeof(int)<=8);
}
return (void *)(p + 8);
}
-static void *genericRealloc(void *p, int n){
+void *sqlite3GenericRealloc(void *p, int n){
char *p2 = ((char *)p - 8);
assert(n>0);
p2 = realloc(p2, n+8);
}
return (void *)((char *)p2 + 8);
}
-static void genericFree(void *p){
+void sqlite3GenericFree(void *p){
assert(p);
free((void *)((char *)p - 8));
}
-static int genericAllocationSize(void *p){
+int sqlite3GenericAllocationSize(void *p){
return p ? *(int *)((char *)p - 8) : 0;
}
#include "sqliteInt.h"
#include "os.h"
#if OS_UNIX /* This file is used on unix only */
+
/*
** These #defines should enable >2GB file support on Posix if the
** underlying operating system supports it. If the OS lacks
#endif
};
+/*
+** Provide the ability to override some OS-layer functions during
+** testing. This is used to simulate OS crashes to verify that
+** commits are atomic even in the event of an OS crash.
+*/
+#ifdef SQLITE_CRASH_TEST
+ extern int sqlite3CrashTestEnable;
+ extern int sqlite3CrashOpenReadWrite(const char*, OsFile**, int*);
+ extern int sqlite3CrashOpenExclusive(const char*, OsFile**, int);
+ extern int sqlite3CrashOpenReadOnly(const char*, OsFile**, int);
+# define CRASH_TEST_OVERRIDE(X,A,B,C) \
+ if(sqlite3CrashTestEnable){ return X(A,B,C); }
+#else
+# define CRASH_TEST_OVERRIDE(X,A,B,C) /* no-op */
+#endif
+
/*
** Do not include any of the File I/O interface procedures if the
/*
** Delete the named file
*/
-static int unixDelete(const char *zFilename){
+int sqlite3UnixDelete(const char *zFilename){
unlink(zFilename);
return SQLITE_OK;
}
/*
** Return TRUE if the named file exists.
*/
-static int unixFileExists(const char *zFilename){
+int sqlite3UnixFileExists(const char *zFilename){
return access(zFilename, 0)==0;
}
** On failure, the function returns SQLITE_CANTOPEN and leaves
** *id and *pReadonly unchanged.
*/
-static int unixOpenReadWrite(
+int sqlite3UnixOpenReadWrite(
const char *zFilename,
OsFile **pId,
int *pReadonly
int rc;
unixFile f;
+ CRASH_TEST_OVERRIDE(sqlite3CrashOpenReadWrite, zFilename, pId, pReadonly);
assert( 0==*pId );
f.dirfd = -1;
SET_THREADID(&f);
}else{
*pReadonly = 0;
}
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
rc = findLockInfo(f.h, &f.pLock, &f.pOpen);
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
if( rc ){
close(f.h);
return SQLITE_NOMEM;
**
** On failure, return SQLITE_CANTOPEN.
*/
-static int unixOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
+int sqlite3UnixOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
int rc;
unixFile f;
+ CRASH_TEST_OVERRIDE(sqlite3CrashOpenExclusive, zFilename, pId, delFlag);
assert( 0==*pId );
if( access(zFilename, 0)==0 ){
return SQLITE_CANTOPEN;
if( f.h<0 ){
return SQLITE_CANTOPEN;
}
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
rc = findLockInfo(f.h, &f.pLock, &f.pOpen);
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
if( rc ){
close(f.h);
unlink(zFilename);
**
** On failure, return SQLITE_CANTOPEN.
*/
-static int unixOpenReadOnly(const char *zFilename, OsFile **pId){
+int sqlite3UnixOpenReadOnly(const char *zFilename, OsFile **pId){
int rc;
unixFile f;
+ CRASH_TEST_OVERRIDE(sqlite3CrashOpenReadOnly, zFilename, pId, 0);
assert( 0==*pId );
SET_THREADID(&f);
f.dirfd = -1;
if( f.h<0 ){
return SQLITE_CANTOPEN;
}
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
rc = findLockInfo(f.h, &f.pLock, &f.pOpen);
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
if( rc ){
close(f.h);
return SQLITE_NOMEM;
** Create a temporary file name in zBuf. zBuf must be big enough to
** hold at least SQLITE_TEMPNAME_SIZE characters.
*/
-static int unixTempFileName(char *zBuf){
+int sqlite3UnixTempFileName(char *zBuf){
static const char *azDirs[] = {
0,
"/var/tmp",
** Check that a given pathname is a directory and is writable
**
*/
-static int unixIsDirWritable(char *zBuf){
+int sqlite3UnixIsDirWritable(char *zBuf){
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
struct stat buf;
if( zBuf==0 ) return 0;
** before making changes to individual journals on a multi-database commit.
** The F_FULLFSYNC option is not needed here.
*/
-static int unixSyncDirectory(const char *zDirname){
+int sqlite3UnixSyncDirectory(const char *zDirname){
#ifdef SQLITE_DISABLE_DIRSYNC
return SQLITE_OK;
#else
assert( pFile );
if( CHECK_THREADID(pFile) ) return SQLITE_MISUSE;
- sqlite3Os.xEnterMutex(); /* Because pFile->pLock is shared across threads */
+ sqlite3OsEnterMutex(); /* Because pFile->pLock is shared across threads */
/* Check if a thread in this process holds such a lock */
if( pFile->pLock->locktype>SHARED_LOCK ){
}
}
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
TRACE3("TEST WR-LOCK %d %d\n", pFile->h, r);
return r;
/* If there is already a lock of this type or more restrictive on the
** OsFile, do nothing. Don't use the end_lock: exit path, as
- ** sqlite3Os.xEnterMutex() hasn't been called yet.
+ ** sqlite3OsEnterMutex() hasn't been called yet.
*/
if( pFile->locktype>=locktype ){
TRACE3("LOCK %d %s ok (already held)\n", pFile->h,
/* This mutex is needed because pFile->pLock is shared across threads
*/
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
/* If some thread using this PID has a lock via a different OsFile*
** handle that precludes the requested lock, return BUSY.
}
end_lock:
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
TRACE4("LOCK %d %s %s\n", pFile->h, locktypeName(locktype),
rc==SQLITE_OK ? "ok" : "failed");
return rc;
if( pFile->locktype<=locktype ){
return SQLITE_OK;
}
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
pLock = pFile->pLock;
assert( pLock->cnt!=0 );
if( pFile->locktype>SHARED_LOCK ){
pOpen->aPending = 0;
}
}
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
pFile->locktype = locktype;
return rc;
}
unixUnlock(*pId, NO_LOCK);
if( id->dirfd>=0 ) close(id->dirfd);
id->dirfd = -1;
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
/* Disable the sqlite3_release_memory() function */
assert( !pTsd->disableReleaseMemory );
/* Disable the sqlite3_release_memory() function */
pTsd->disableReleaseMemory = 0;
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
id->isOpen = 0;
TRACE2("CLOSE %-3d\n", id->h);
OpenCounter(-1);
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
-static char *unixFullPathname(const char *zRelative){
+char *sqlite3UnixFullPathname(const char *zRelative){
char *zFull = 0;
if( zRelative[0]=='/' ){
sqlite3SetString(&zFull, zRelative, (char*)0);
** is written into the buffer zBuf[256]. The calling function must
** supply a sufficiently large buffer.
*/
-static int unixRandomSeed(char *zBuf){
+int sqlite3UnixRandomSeed(char *zBuf){
/* We have to initialize zBuf to prevent valgrind from reporting
** errors. The reports issued by valgrind are incorrect - we would
** prefer that the randomness be increased by making use of the
/*
** Sleep for a little while. Return the amount of time slept.
*/
-static int unixSleep(int ms){
+int sqlite3UnixSleep(int ms){
#if defined(HAVE_USLEEP) && HAVE_USLEEP
usleep(ms*1000);
return ms;
** SQLite uses only a single Mutex. There is not much critical
** code and what little there is executes quickly and without blocking.
*/
-static void unixEnterMutex(){
+void sqlite3UnixEnterMutex(){
#ifdef SQLITE_UNIX_THREADS
pthread_mutex_lock(&mutex);
#endif
assert( !inMutex );
inMutex = 1;
}
-static void unixLeaveMutex(){
+void sqlite3UnixLeaveMutex(){
assert( inMutex );
inMutex = 0;
#ifdef SQLITE_UNIX_THREADS
** for use in an assert() to verify that the mutex is held or not held
** in certain routines.
*/
-static int unixInMutex(){
+int sqlite3UnixInMutex(){
return inMutex;
}
*/
#ifdef SQLITE_UNIX_THREADS
static void deleteTsd(void *pTsd){
- sqlite3Os.xFree(pTsd);
+ sqlite3OsFree(pTsd);
}
#endif
** Each subsequent call to this function from the thread returns the same
** pointer. The argument is ignored in this case.
*/
-static void *unixThreadSpecificData(int nByte){
+void *sqlite3UnixThreadSpecificData(int nByte){
#ifdef SQLITE_UNIX_THREADS
static pthread_key_t key;
static int keyInit = 0;
void *pTsd;
if( !keyInit ){
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
if( !keyInit ){
int rc;
rc = pthread_key_create(&key, deleteTsd);
}
keyInit = 1;
}
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
}
pTsd = pthread_getspecific(key);
if( !pTsd ){
- pTsd = sqlite3Os.xMalloc(nByte);
+ pTsd = sqlite3OsMalloc(nByte);
if( pTsd ){
memset(pTsd, 0, nByte);
pthread_setspecific(key, pTsd);
#else
static void *pTsd = 0;
if( !pTsd ){
- pTsd = sqlite3Os.xMalloc(nByte);
+ pTsd = sqlite3OsMalloc(nByte);
if( pTsd ){
memset(pTsd, 0, nByte);
}
/*
** The following variable, if set to a non-zero value, becomes the result
-** returned from sqlite3Os.xCurrentTime(). This is used for testing.
+** returned from sqlite3OsCurrentTime(). This is used for testing.
*/
#ifdef SQLITE_TEST
int sqlite3_current_time = 0;
** current time and date as a Julian Day number into *prNow and
** return 0. Return 1 if the time and date cannot be found.
*/
-static int unixCurrentTime(double *prNow){
+int sqlite3UnixCurrentTime(double *prNow){
#ifdef NO_GETTOD
time_t t;
time(&t);
return 0;
}
-/* Macro used to comment out routines that do not exists when there is
-** no disk I/O */
-#ifdef SQLITE_OMIT_DISKIO
-# define IF_DISKIO(X) 0
-#else
-# define IF_DISKIO(X) X
-#endif
-
-/*
-** This is the structure that defines all of the I/O routines.
-*/
-struct sqlite3OsVtbl sqlite3Os = {
- IF_DISKIO( unixOpenReadWrite ),
- IF_DISKIO( unixOpenExclusive ),
- IF_DISKIO( unixOpenReadOnly ),
- IF_DISKIO( unixDelete ),
- IF_DISKIO( unixFileExists ),
- IF_DISKIO( unixFullPathname ),
- IF_DISKIO( unixIsDirWritable ),
- IF_DISKIO( unixSyncDirectory ),
- IF_DISKIO( unixTempFileName ),
- unixRandomSeed,
- unixSleep,
- unixCurrentTime,
- unixEnterMutex,
- unixLeaveMutex,
- unixInMutex,
- unixThreadSpecificData,
- genericMalloc,
- genericRealloc,
- genericFree,
- genericAllocationSize
-};
-
-
-
#endif /* OS_UNIX */
/*
** Delete the named file
*/
-static int winDelete(const char *zFilename){
+int sqlite3WinDelete(const char *zFilename){
WCHAR *zWide = utf8ToUnicode(zFilename);
if( zWide ){
DeleteFileW(zWide);
/*
** Return TRUE if the named file exists.
*/
-static int winFileExists(const char *zFilename){
+int sqlite3WinFileExists(const char *zFilename){
int exists = 0;
WCHAR *zWide = utf8ToUnicode(zFilename);
if( zWide ){
** On failure, the function returns SQLITE_CANTOPEN and leaves
** *id and *pReadonly unchanged.
*/
-static int winOpenReadWrite(
+int sqlite3WinOpenReadWrite(
const char *zFilename,
OsFile **pId,
int *pReadonly
**
** On failure, return SQLITE_CANTOPEN.
*/
-static int winOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
+int sqlite3WinOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
winFile f;
HANDLE h;
int fileflags;
**
** On failure, return SQLITE_CANTOPEN.
*/
-static int winOpenReadOnly(const char *zFilename, OsFile **pId){
+int sqlite3WinOpenReadOnly(const char *zFilename, OsFile **pId){
winFile f;
HANDLE h;
WCHAR *zWide = utf8ToUnicode(zFilename);
** Create a temporary file name in zBuf. zBuf must be big enough to
** hold at least SQLITE_TEMPNAME_SIZE characters.
*/
-static int winTempFileName(char *zBuf){
+int sqlite3WinTempFileName(char *zBuf){
static char zChars[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
}
zBuf[j] = 0;
- if( !sqlite3Os.xFileExists(zBuf) ) break;
+ if( !sqlite3OsFileExists(zBuf) ) break;
}
TRACE2("TEMP FILENAME: %s\n", zBuf);
return SQLITE_OK;
** Sync the directory zDirname. This is a no-op on operating systems other
** than UNIX.
*/
-static int winSyncDirectory(const char *zDirname){
+int sqlite3WinSyncDirectory(const char *zDirname){
SimulateIOError(SQLITE_IOERR);
return SQLITE_OK;
}
** Check that a given pathname is a directory and is writable
**
*/
-static int winIsDirWritable(char *zDirname){
+int sqlite3WinIsDirWritable(char *zDirname){
int fileAttr;
WCHAR *zWide;
if( zDirname==0 ) return 0;
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
-static char *winFullPathname(const char *zRelative){
+char *sqlite3WinFullPathname(const char *zRelative){
char *zNotUsed;
char *zFull;
WCHAR *zWide;
}else{
*pNew = *pInit;
pNew->pMethod = &sqlite3WinIoMethod;
- *pId = pNew;
+ *pId = (OsFile*)pNew;
return SQLITE_OK;
}
}
** is written into the buffer zBuf[256]. The calling function must
** supply a sufficiently large buffer.
*/
-static int winRandomSeed(char *zBuf){
+int sqlite3WinRandomSeed(char *zBuf){
/* We have to initialize zBuf to prevent valgrind from reporting
** errors. The reports issued by valgrind are incorrect - we would
** prefer that the randomness be increased by making use of the
/*
** Sleep for a little while. Return the amount of time slept.
*/
-static int winSleep(int ms){
+int sqlite3WinSleep(int ms){
Sleep(ms);
return ms;
}
** SQLite uses only a single Mutex. There is not much critical
** code and what little there is executes quickly and without blocking.
*/
-static void winEnterMutex(){
+void sqlite3WinEnterMutex(){
#ifdef SQLITE_W32_THREADS
static int isInit = 0;
while( !isInit ){
assert( !inMutex );
inMutex = 1;
}
-static void winLeaveMutex(){
+void sqlite3WinLeaveMutex(){
assert( inMutex );
inMutex = 0;
#ifdef SQLITE_W32_THREADS
** for use in an assert() to verify that the mutex is held or not held
** in certain routines.
*/
-static int winInMutex(){
+int sqlite3WinInMutex(){
return inMutex;
}
** current time and date as a Julian Day number into *prNow and
** return 0. Return 1 if the time and date cannot be found.
*/
-static int winCurrentTime(double *prNow){
+int sqlite3WinCurrentTime(double *prNow){
FILETIME ft;
/* FILETIME structure is a 64-bit value representing the number of
100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
** Each subsequent call to this function from the thread returns the same
** pointer. The argument is ignored in this case.
*/
-static void *winThreadSpecificData(int nByte){
+void *sqlite3WinThreadSpecificData(int nByte){
static void *pTsd = 0;
static int key;
static int keyInit = 0;
if( !keyInit ){
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
if( !keyInit ){
key = TlsAlloc();
if( key==0xffffffff ){
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
return 0;
}
keyInit = 1;
}
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
}
pTsd = TlsGetValue(key);
if( !pTsd ){
- pTsd = sqlite3Os.xMalloc(nByte);
+ pTsd = sqlite3OsMalloc(nByte);
if( pTsd ){
memset(pTsd, 0, nByte);
TlsSetValue(key, pTsd);
}
return pTsd;
}
-
-/* Macro used to comment out routines that do not exists when there is
-** no disk I/O
-*/
-#ifdef SQLITE_OMIT_DISKIO
-# define IF_DISKIO(X) 0
-#else
-# define IF_DISKIO(X) X
-#endif
-
-/*
-** This is the structure that defines all of the I/O routines.
-*/
-struct sqlite3OsVtbl sqlite3Os = {
- IF_DISKIO( winOpenReadWrite ),
- IF_DISKIO( winOpenExclusive ),
- IF_DISKIO( winOpenReadOnly ),
- IF_DISKIO( winDelete ),
- IF_DISKIO( winFileExists ),
- IF_DISKIO( winFullPathname ),
- IF_DISKIO( winIsDirWritable ),
- IF_DISKIO( winSyncDirectory ),
- IF_DISKIO( winTempFileName ),
- winRandomSeed,
- winSleep,
- winCurrentTime,
- winEnterMutex,
- winLeaveMutex,
- winInMutex,
- winThreadSpecificData,
- genericMalloc,
- genericRealloc,
- genericFree,
- genericAllocationSize
-};
-
#endif /* OS_WIN */
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.230 2006/01/05 13:48:29 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.231 2006/01/06 14:32:20 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
if( pPager->journalOpen ){
sqlite3OsClose(&pPager->jfd);
pPager->journalOpen = 0;
- sqlite3Os.xDelete(pPager->zJournal);
+ sqlite3OsDelete(pPager->zJournal);
sqliteFree( pPager->aInJournal );
pPager->aInJournal = 0;
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
/* Open the master journal file exclusively in case some other process
** is running this routine also. Not that it makes too much difference.
*/
- rc = sqlite3Os.xOpenReadOnly(zMaster, &master);
+ rc = sqlite3OsOpenReadOnly(zMaster, &master);
if( rc!=SQLITE_OK ) goto delmaster_out;
master_open = 1;
rc = sqlite3OsFileSize(master, &nMasterJournal);
zJournal = zMasterJournal;
while( (zJournal-zMasterJournal)<nMasterJournal ){
- if( sqlite3Os.xFileExists(zJournal) ){
+ if( sqlite3OsFileExists(zJournal) ){
/* One of the journals pointed to by the master journal exists.
** Open it and check if it points at the master journal. If
** so, return without deleting the master journal file.
OsFile *journal = 0;
int c;
- rc = sqlite3Os.xOpenReadOnly(zJournal, &journal);
+ rc = sqlite3OsOpenReadOnly(zJournal, &journal);
if( rc!=SQLITE_OK ){
goto delmaster_out;
}
}
}
- sqlite3Os.xDelete(zMaster);
+ sqlite3OsDelete(zMaster);
delmaster_out:
if( zMasterJournal ){
*/
rc = readMasterJournal(pPager->jfd, &zMaster);
assert( rc!=SQLITE_DONE );
- if( rc!=SQLITE_OK || (zMaster && !sqlite3Os.xFileExists(zMaster)) ){
+ if( rc!=SQLITE_OK || (zMaster && !sqlite3OsFileExists(zMaster)) ){
sqliteFree(zMaster);
zMaster = 0;
if( rc==SQLITE_DONE ) rc = SQLITE_OK;
sqlite3_opentemp_count++; /* Used for testing and analysis only */
do{
cnt--;
- sqlite3Os.xTempFileName(zFile);
- rc = sqlite3Os.xOpenExclusive(zFile, pFd, 1);
+ sqlite3OsTempFileName(zFile);
+ rc = sqlite3OsOpenExclusive(zFile, pFd, 1);
}while( cnt>0 && rc!=SQLITE_OK && rc!=SQLITE_NOMEM );
return rc;
}
}else
#endif
{
- zFullPathname = sqlite3Os.xFullPathname(zFilename);
+ zFullPathname = sqlite3OsFullPathname(zFilename);
if( zFullPathname ){
- rc = sqlite3Os.xOpenReadWrite(zFullPathname, &fd, &readOnly);
+ rc = sqlite3OsOpenReadWrite(zFullPathname, &fd, &readOnly);
}
}
}else{
rc = sqlite3pager_opentemp(zTemp, &fd);
zFilename = zTemp;
- zFullPathname = sqlite3Os.xFullPathname(zFilename);
+ zFullPathname = sqlite3OsFullPathname(zFilename);
if( rc==SQLITE_OK ){
tempFile = 1;
}
sqlite3OsClose(&pPager->fd);
/* Temp files are automatically deleted by the OS
** if( pPager->tempFile ){
- ** sqlite3Os.xDelete(pPager->zFilename);
+ ** sqlite3OsDelete(pPager->zFilename);
** }
*/
*/
static int hasHotJournal(Pager *pPager){
if( !pPager->useJournal ) return 0;
- if( !sqlite3Os.xFileExists(pPager->zJournal) ) return 0;
+ if( !sqlite3OsFileExists(pPager->zJournal) ) return 0;
if( sqlite3OsCheckReservedLock(pPager->fd) ) return 0;
if( sqlite3pager_pagecount(pPager)==0 ){
- sqlite3Os.xDelete(pPager->zJournal);
+ sqlite3OsDelete(pPager->zJournal);
return 0;
}else{
return 1;
/* If the disableReleaseMemory memory flag is set, this operation is
** a no-op; zero bytes of memory are freed. The flag is set before
- ** malloc() is called while the global mutex (see sqlite3Os.xEnterMutex)
+ ** malloc() is called while the global mutex (see sqlite3OsEnterMutex)
** is held. Because some of the code invoked by this function may also
** try to obtain the mutex, proceding may cause a deadlock.
*/
** a write lock, so there is never any chance of two or more
** processes opening the journal at the same time.
*/
- rc = sqlite3Os.xOpenReadOnly(pPager->zJournal, &pPager->jfd);
+ rc = sqlite3OsOpenReadOnly(pPager->zJournal, &pPager->jfd);
if( rc!=SQLITE_OK ){
sqlite3OsUnlock(pPager->fd, NO_LOCK);
pPager->state = PAGER_UNLOCK;
rc = SQLITE_NOMEM;
goto failed_to_open_journal;
}
- rc = sqlite3Os.xOpenExclusive(pPager->zJournal, &pPager->jfd,
+ rc = sqlite3OsOpenExclusive(pPager->zJournal, &pPager->jfd,
pPager->tempFile);
pPager->journalOff = 0;
pPager->setMaster = 0;
** the system will get confused, we have a read-lock on the file and a
** mysterious journal has appeared in the filesystem.
*/
- sqlite3Os.xDelete(pPager->zJournal);
+ sqlite3OsDelete(pPager->zJournal);
}else{
sqlite3OsUnlock(pPager->fd, NO_LOCK);
pPager->state = PAGER_UNLOCK;
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
-** $Id: pragma.c,v 1.108 2006/01/05 11:34:34 danielk1977 Exp $
+** $Id: pragma.c,v 1.109 2006/01/06 14:32:20 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
}
}else{
- if( zRight[0] && !sqlite3Os.xIsDirWritable(zRight) ){
+ if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){
sqlite3ErrorMsg(pParse, "not a writable directory");
goto pragma_out;
}
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
**
-** $Id: random.c,v 1.14 2005/11/30 03:20:32 drh Exp $
+** $Id: random.c,v 1.15 2006/01/06 14:32:20 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
char k[256];
prng.j = 0;
prng.i = 0;
- sqlite3Os.xRandomSeed(k);
+ sqlite3OsRandomSeed(k);
for(i=0; i<256; i++){
prng.s[i] = i;
}
*/
void sqlite3Randomness(int N, void *pBuf){
unsigned char *zBuf = pBuf;
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
while( N-- ){
*(zBuf++) = randomByte();
}
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
}
*************************************************************************
** A TCL Interface to SQLite
**
-** $Id: tclsqlite.c,v 1.146 2006/01/06 03:29:58 drh Exp $
+** $Id: tclsqlite.c,v 1.147 2006/01/06 14:32:20 drh Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
extern int Sqlitetest4_Init(Tcl_Interp*);
extern int Sqlitetest5_Init(Tcl_Interp*);
extern int Sqlitetest6_Init(Tcl_Interp*);
- extern int Sqlitetestasync_Init(Tcl_Interp*);
extern int Md5_Init(Tcl_Interp*);
extern int Sqlitetestsse_Init(Tcl_Interp*);
Sqlitetest4_Init(interp);
Sqlitetest5_Init(interp);
Sqlitetest6_Init(interp);
- Sqlitetestasync_Init(interp);
Md5_Init(interp);
#ifdef SQLITE_SSE
Sqlitetestsse_Init(interp);
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test1.c,v 1.180 2006/01/05 15:50:07 drh Exp $
+** $Id: test1.c,v 1.181 2006/01/06 14:32:20 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
return TCL_ERROR;
}
- rc = sqlite3Os.xOpenReadWrite(Tcl_GetString(objv[1]), &pFile, &dummy);
+ rc = sqlite3OsOpenReadWrite(Tcl_GetString(objv[1]), &pFile, &dummy);
if( rc!=SQLITE_OK ){
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
return TCL_ERROR;
char zFile[SQLITE_TEMPNAME_SIZE];
int rc;
- rc = sqlite3Os.xTempFileName(zFile);
+ rc = sqlite3OsTempFileName(zFile);
if( rc!=SQLITE_OK ){
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
return TCL_ERROR;
Tcl_SetVar2(interp, "sqlite_options", "conflict", "1", TCL_GLOBAL_ONLY);
#endif
+#if OS_UNIX
+ Tcl_SetVar2(interp, "sqlite_options", "crashtest", "1", TCL_GLOBAL_ONLY);
+#else
+ Tcl_SetVar2(interp, "sqlite_options", "crashtest", "0", TCL_GLOBAL_ONLY);
+#endif
+
#ifdef SQLITE_OMIT_DATETIME_FUNCS
Tcl_SetVar2(interp, "sqlite_options", "datetime", "0", TCL_GLOBAL_ONLY);
#else
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test2.c,v 1.38 2005/11/30 03:20:32 drh Exp $
+** $Id: test2.c,v 1.39 2006/01/06 14:32:20 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
- rc = sqlite3Os.xOpenReadWrite(argv[2], &fd, &readOnly);
+ rc = sqlite3OsOpenReadWrite(argv[2], &fd, &readOnly);
if( rc ){
Tcl_AppendResult(interp, "open failed: ", errorName(rc), 0);
return TCL_ERROR;
#include "os.h"
#include "tcl.h"
-/*
-** A copy of the original sqlite3Os structure
-*/
-static struct sqlite3OsVtbl origOs;
-
/*
** crashFile is a subclass of OsFile that is taylored for the
** crash test module.
** Set the value of the two crash parameters.
*/
static void setCrashParams(int iDelay, char const *zFile){
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
assert( strlen(zFile)<sizeof(zCrashFile) );
strcpy(zCrashFile, zFile);
iCrashDelay = iDelay;
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
}
/*
static int crashRequired(char const *zPath){
int r;
int n;
- sqlite3Os.xEnterMutex();
+ sqlite3OsEnterMutex();
n = strlen(zCrashFile);
if( zCrashFile[n-1]=='*' ){
n--;
r = 1;
}
}
- sqlite3Os.xLeaveMutex();
+ sqlite3OsLeaveMutex();
return r;
}
return rc;
}
+/*
+** Set this global variable to 1 to enable crash testing.
+*/
+int sqlite3CrashTestEnable = 0;
+
/*
** The three functions used to open files. All that is required is to
** initialise the os_test.c specific fields and then call the corresponding
** os_unix.c function to really open the file.
*/
-static int crashOpenReadWrite(const char *zFilename, OsFile **pId,int *pRdonly){
+int sqlite3CrashOpenReadWrite(const char *zFilename, OsFile **pId,int *pRdonly){
OsFile *pBase = 0;
- int rc = origOs.xOpenReadWrite(zFilename, &pBase, pRdonly);
+ int rc;
+
+ sqlite3CrashTestEnable = 0;
+ rc = sqlite3OsOpenReadWrite(zFilename, &pBase, pRdonly);
+ sqlite3CrashTestEnable = 1;
if( !rc ){
initFile(pId, zFilename, pBase);
}
return rc;
}
-static int crashOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
+int sqlite3CrashOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
OsFile *pBase = 0;
- int rc = origOs.xOpenExclusive(zFilename, &pBase, delFlag);
+ int rc;
+
+ sqlite3CrashTestEnable = 0;
+ rc = sqlite3OsOpenExclusive(zFilename, &pBase, delFlag);
+ sqlite3CrashTestEnable = 1;
if( !rc ){
initFile(pId, zFilename, pBase);
}
return rc;
}
-static int crashOpenReadOnly(const char *zFilename, OsFile **pId){
+int sqlite3CrashOpenReadOnly(const char *zFilename, OsFile **pId, int NotUsed){
OsFile *pBase = 0;
- int rc = origOs.xOpenReadOnly(zFilename, &pBase);
+ int rc;
+
+ sqlite3CrashTestEnable = 0;
+ rc = sqlite3OsOpenReadOnly(zFilename, &pBase);
+ sqlite3CrashTestEnable = 1;
if( !rc ){
initFile(pId, zFilename, pBase);
}
return TCL_ERROR;
}
setCrashParams(delay, zFile);
- if( origOs.xOpenReadWrite==0 ){
- origOs = sqlite3Os;
- sqlite3Os.xOpenReadWrite = crashOpenReadWrite;
- sqlite3Os.xOpenExclusive = crashOpenExclusive;
- sqlite3Os.xOpenReadOnly = crashOpenReadOnly;
- }
+ sqlite3CrashTestEnable = 1;
return TCL_OK;
}
+++ /dev/null
-/*
-** 2005 December 14
-**
-** The author disclaims copyright to this source code. In place of
-** a legal notice, here is a blessing:
-**
-** May you do good and not evil.
-** May you find forgiveness for yourself and forgive others.
-** May you share freely, never taking more than you give.
-**
-*************************************************************************
-**
-** This file contains an example implementation of an asynchronous IO
-** backend for SQLite. It is used to test that the concept of asynchronous
-** IO in SQLite is valid.
-*/
-
-#include "sqliteInt.h"
-#include "os.h"
-
-#define MIN(x,y) ((x)<(y)?(x):(y))
-#define MAX(x,y) ((x)>(y)?(x):(y))
-
-typedef struct AsyncWrite AsyncWrite;
-typedef struct AsyncFile AsyncFile;
-
-/*
-** TODO:
-** * File locks...
-*/
-
-/*
-** THREAD SAFETY NOTES
-**
-** Basic rules:
-**
-** * Both read and write access to the global write-op queue must be
-** protected by the sqlite3Os mutex functions.
-** * The file handles from the underlying system are assumed not to
-** be thread safe.
-** * See the last paragraph under "sqlite3_async_flush() Threads" for
-** an assumption to do with file-handle synchronization by the Os.
-**
-** File system operations (invoked by SQLite thread):
-**
-** xOpenXXX (three versions)
-** xDelete
-** xFileExists
-**
-** Todo:
-** xSyncDirectory
-**
-** File handle operations (invoked by SQLite thread):
-**
-** The following operations add an entry to the global write-op list. They
-** prepare the entry, aquire the mutex momentarily while list pointers are
-** manipulated to insert the new entry, and release the mutex.
-**
-** asyncWrite, asyncClose, asyncTruncate, asyncSync,
-** asyncSetFullSync, asyncOpenDirectory.
-**
-** Read operations. Both of these read from both the underlying file and
-** the write-op list. So we grab the mutex for the whole call (even
-** while performing a blocking read on the file).
-**
-** asyncRead, asyncFileSize.
-**
-** These locking primitives become no-ops. Files are always opened for
-** exclusive access when using this IO backend:
-**
-** asyncLock, asyncUnlock, asyncLockState, asyncCheckReservedLock
-**
-** The sqlite3OsFileHandle() function is currently only used when
-** debugging the pager module. Unless sqlite3OsClose() is called on the
-** file (shouldn't be possible for other reasons), the underlying
-** implementations are safe to call without grabbing any mutex. So we just
-** go ahead and call it no matter what any other thread is doing.
-**
-** asyncFileHandle.
-**
-** Calling this method just manipulates the AsyncFile.iOffset variable.
-** Since this variable is never accessed by an sqlite3_async_flush() thread,
-** this function does not require the mutex. Actual calls to OsSeek() take
-** place just before OsWrite() or OsRead(), which are always protected by
-** the mutex.
-**
-** asyncSeek.
-**
-** sqlite3_async_flush() (any thread):
-**
-** A pseudo-mutex (a global boolean variable) is used to make sure only
-** one thread is inside the sqlite3_async_flush() thread at any one time.
-** If the variable is set when a thread enters _flush(), then it
-** immediately returns SQLITE_BUSY. Otherwise, it sets the variable,
-** executes the body of the function, and clears the variable just before
-** returning. Both read and write access to said global variable
-** (sqlite3_asyncIoBusy) is protected by sqlite3Os mutex, of course.
-**
-** Inside sqlite3_async_flush() is a loop that works like this:
-**
-** WHILE (write-op list is not empty)
-** Do IO operation at head of write-op list
-** Remove entry from head of write-op list
-** END WHILE
-**
-** The mutex is always obtained during the <write-op list is not empty>
-** test, and when the entry is removed from the head of the write-op
-** list. Sometimes it is held for the interim period (while the IO is
-** performed), and sometimes it is relinquished. It is relinquished if
-** (a) the IO op is an ASYNC_CLOSE or (b) when the file handle was
-** opened, two of the underlying systems handles were opened on the
-** same file-system entry.
-**
-** If condition (b) above is true, then one file-handle
-** (AsyncFile.pBaseRead) is used exclusively by sqlite threads to read the
-** file, the other (AsyncFile.pBaseWrite) by sqlite3_async_flush()
-** threads to perform write() operations. This means that read
-** operations are not blocked by asynchronous writes (although
-** asynchronous writes may still be blocked by reads).
-**
-** This assumes that the OS keeps two handles open on the same file
-** properly in sync. That is, any read operation that starts after a
-** write operation on the same file system entry has completed returns
-** data consistent with the write. We also assume that if one thread
-** reads a file while another is writing it all bytes other than the
-** ones actually being written contain valid data.
-**
-** If the above assumptions are not true, set the preprocessor symbol
-** SQLITE_ASYNC_TWO_FILEHANDLES to 0.
-*/
-
-#ifndef SQLITE_ASYNC_TWO_FILEHANDLES
-/* #define SQLITE_ASYNC_TWO_FILEHANDLES 0 */
-#define SQLITE_ASYNC_TWO_FILEHANDLES 1
-#endif
-
-/*
-** First and last elements of the global write-op list.
-**
-** Whenever an OsWrite(), OsSync(), OsTrunc() or OsClose() operation is
-** requested, instead of performing the file IO immediately, a new AsyncWrite
-** structure is allocated and added to the global linked list that starts at
-** sqlite3_asyncListFirst. The next time to sqlite3_async_flush() is called,
-** all operations are realised and the list elements deleted.
-*/
-static AsyncWrite *sqlite3_asyncListFirst = 0;
-static AsyncWrite *sqlite3_asyncListLast = 0;
-
-/* True after an IO error has occured */
-/* static int *sqlite3_asyncIoError = 0; */
-
-/* True if some thread is currently inside sqlite3_async_flush() */
-static int sqlite3_asyncIoBusy = 0;
-
-/* Possible values of AsyncWrite.op */
-#define ASYNC_WRITE 1
-#define ASYNC_SYNC 2
-#define ASYNC_TRUNCATE 3
-#define ASYNC_CLOSE 4
-#define ASYNC_OPENDIRECTORY 5
-#define ASYNC_SETFULLSYNC 6
-
-#define ASYNC_DELETE 7
-#define ASYNC_OPENEXCLUSIVE 8
-#define ASYNC_SYNCDIRECTORY 9
-
-/*
-** The interpretation of the iOffset and nByte variables varies depending
-** on the value of AsyncWrite.op:
-**
-** ASYNC_WRITE:
-** iOffset -> Offset in file to write to.
-** nByte -> Number of bytes of data to write (pointed to by zBuf).
-**
-** ASYNC_SYNC:
-** iOffset -> Unused.
-** nByte -> Value of "fullsync" flag to pass to sqlite3OsSync().
-**
-** ASYNC_TRUNCATE:
-** iOffset -> Size to truncate file to.
-** nByte -> Unused.
-**
-** ASYNC_CLOSE:
-** iOffset -> Unused.
-** nByte -> Unused.
-**
-** ASYNC_OPENDIRECTORY:
-** iOffset -> Unused.
-** nByte -> Number of bytes of zBuf points to (directory name).
-**
-** ASYNC_SETFULLSYNC:
-** iOffset -> Unused.
-** nByte -> New value for the full-sync flag.
-**
-**
-** ASYNC_DELETE:
-** iOffset -> Unused.
-** nByte -> Number of bytes of zBuf points to (file name).
-**
-** ASYNC_OPENEXCLUSIVE:
-** iOffset -> Value of "delflag".
-** nByte -> Number of bytes of zBuf points to (file name).
-**
-** 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
-** structure.
-*/
-struct AsyncWrite {
- AsyncFile *pFile; /* File to write data to or sync */
- int op; /* One of ASYNC_xxx etc. */
- i64 iOffset; /* See above */
- int nByte; /* See above */
- char *zBuf; /* Data to write to file (or NULL if op!=ASYNC_WRITE) */
- AsyncWrite *pNext; /* Next write operation (to any file) */
-};
-
-/*
-** The AsyncFile structure is a subclass of OsFile used for asynchronous IO.
-*/
-struct AsyncFile {
- IoMethod *pMethod; /* Must be first */
- i64 iOffset; /* Current seek() offset in file */
- OsFile *pBaseRead; /* Read handle to the underlying Os file */
- OsFile *pBaseWrite; /* Write handle to the underlying Os file */
-};
-
-/*
-** Add an entry to the end of the global write-op list. pWrite should point
-** to an AsyncWrite structure allocated using sqliteMalloc(). A future call
-** to sqlite3_async_flush() is responsible for calling sqliteFree().
-**
-** Once an AsyncWrite structure has been added to the list, it must not be
-** read or modified by the caller (in case another thread calls
-** sqlite3_async_flush() ).
-*/
-static void addAsyncWrite(AsyncWrite *pWrite){
- sqlite3Os.xEnterMutex();
- assert( !pWrite->pNext );
- if( sqlite3_asyncListLast ){
- assert( sqlite3_asyncListFirst );
- sqlite3_asyncListLast->pNext = pWrite;
- }else{
- sqlite3_asyncListFirst = pWrite;
- }
- sqlite3_asyncListLast = pWrite;
- sqlite3Os.xLeaveMutex();
-}
-
-/*
-** The caller should already hold the mutex when this is called.
-*/
-static void removeAsyncWrite(AsyncWrite *p){
- assert( p==sqlite3_asyncListFirst );
- assert( sqlite3_asyncListLast );
- if( sqlite3_asyncListFirst==sqlite3_asyncListLast ){
- assert( !sqlite3_asyncListFirst->pNext );
- sqlite3_asyncListLast = 0;
- }
- sqlite3_asyncListFirst = sqlite3_asyncListFirst->pNext;
-}
-
-/*
-** This is a utility function to allocate and populate a new AsyncWrite
-** structure and insert it (via addAsyncWrite() ) into the global list.
-*/
-static int addNewAsyncWrite(
- AsyncFile *pFile,
- int op,
- i64 iOffset,
- int nByte,
- const char *zByte
-){
- AsyncWrite *p = sqlite3Os.xMalloc(sizeof(AsyncWrite) + (zByte?nByte:0));
- if( !p ){
- return SQLITE_NOMEM;
- }
- p->op = op;
- p->iOffset = iOffset;
- p->nByte = nByte;
- p->pFile = pFile;
- p->pNext = 0;
- if( zByte ){
- p->zBuf = (char *)&p[1];
- memcpy(p->zBuf, zByte, nByte);
- }else{
- p->zBuf = 0;
- }
- addAsyncWrite(p);
- return SQLITE_OK;
-}
-
-/*
-** Close the file. This just adds an entry to the write-op list, the file is
-** not actually closed.
-*/
-static int asyncClose(OsFile **pId){
- return addNewAsyncWrite((AsyncFile *)*pId, ASYNC_CLOSE, 0, 0, 0);
-}
-
-/*
-** Implementation of sqlite3OsWrite() for asynchronous files. Instead of
-** writing to the underlying file, this function adds an entry to the end of
-** the global AsyncWrite list. Either SQLITE_OK or SQLITE_NOMEM may be
-** returned.
-*/
-static int asyncWrite(OsFile *id, const void *pBuf, int amt){
- AsyncFile *pFile = (AsyncFile *)id;
- int rc = addNewAsyncWrite(pFile, ASYNC_WRITE, pFile->iOffset, amt, pBuf);
- pFile->iOffset += (i64)amt;
- return rc;
-}
-
-/*
-** Truncate the file to nByte bytes in length. This just adds an entry to
-** the write-op list, no IO actually takes place.
-*/
-static int asyncTruncate(OsFile *id, i64 nByte){
- return addNewAsyncWrite((AsyncFile *)id, ASYNC_TRUNCATE, nByte, 0, 0);
-}
-
-/*
-** Open the directory identified by zName and associate it with the
-** specified file. This just adds an entry to the write-op list, the
-** directory is opened later by sqlite3_async_flush().
-*/
-static int asyncOpenDirectory(OsFile *id, const char *zName){
- AsyncFile *pFile = (AsyncFile *)id;
- return addNewAsyncWrite(pFile, ASYNC_OPENDIRECTORY, 0, strlen(zName)+1,zName);
-}
-
-/*
-** Sync the file. This just adds an entry to the write-op list, the
-** sync() is done later by sqlite3_async_flush().
-*/
-static int asyncSync(OsFile *id, int fullsync){
- return addNewAsyncWrite((AsyncFile *)id, ASYNC_SYNC, 0, fullsync, 0);
-}
-
-/*
-** Set (or clear) the full-sync flag on the underlying file. This operation
-** is queued and performed later by sqlite3_async_flush().
-*/
-static void asyncSetFullSync(OsFile *id, int value){
- addNewAsyncWrite((AsyncFile *)id, ASYNC_SETFULLSYNC, 0, value, 0);
-}
-
-/*
-** Read data from the file. First we read from the filesystem, then adjust
-** the contents of the buffer based on ASYNC_WRITE operations in the
-** write-op queue. Todo: Do we need to think about ASYNC_TRUNCATE in
-** this method as well?
-**
-** This method holds the mutex from start to finish.
-*/
-static int asyncRead(OsFile *id, void *obuf, int amt){
- int rc = SQLITE_OK;
- i64 filesize;
- int nRead;
- AsyncFile *pFile = (AsyncFile *)id;
-
- /* Grab the mutex for the duration of the call */
- sqlite3Os.xEnterMutex();
-
- if( pFile->pBaseRead ){
- rc = sqlite3OsFileSize(pFile->pBaseRead, &filesize);
- if( rc!=SQLITE_OK ){
- goto asyncread_out;
- }
- rc = sqlite3OsSeek(pFile->pBaseRead, pFile->iOffset);
- if( rc!=SQLITE_OK ){
- goto asyncread_out;
- }
- nRead = MIN(filesize - pFile->iOffset, amt);
- if( nRead>0 ){
- rc = sqlite3OsRead(((AsyncFile *)id)->pBaseRead, obuf, nRead);
- }
- }
-
- if( rc==SQLITE_OK ){
- AsyncWrite *p;
- i64 iOffset = pFile->iOffset; /* Current seek offset */
-
- for(p=sqlite3_asyncListFirst; p; p = p->pNext){
- if( p->pFile==pFile && p->op==ASYNC_WRITE ){
- int iBeginIn = (p->iOffset - iOffset);
- int iBeginOut = (iOffset - p->iOffset);
- int nCopy;
-
- if( iBeginIn<0 ) iBeginIn = 0;
- if( iBeginOut<0 ) iBeginOut = 0;
- nCopy = MIN(p->nByte-iBeginIn, amt-iBeginOut);
-
- if( nCopy>0 ){
- memcpy(&((char *)obuf)[iBeginOut], &p->zBuf[iBeginIn], nCopy);
- }
- }
- }
-
- pFile->iOffset += (i64)amt;
- }
-
-asyncread_out:
- sqlite3Os.xLeaveMutex();
- return rc;
-}
-
-/*
-** Seek to the specified offset. This just adjusts the AsyncFile.iOffset
-** variable - calling seek() on the underlying file is defered until the
-** next read() or write() operation.
-*/
-static int asyncSeek(OsFile *id, i64 offset){
- AsyncFile *pFile = (AsyncFile *)id;
- pFile->iOffset = offset;
- return SQLITE_OK;
-}
-
-/*
-** Read the size of the file. First we read the size of the file system
-** entry, then adjust for any ASYNC_WRITE or ASYNC_TRUNCATE operations
-** currently in the write-op list.
-**
-** This method holds the mutex from start to finish.
-*/
-int asyncFileSize(OsFile *id, i64 *pSize){
- int rc = SQLITE_OK;
- i64 s = 0;
- OsFile *pBase;
- sqlite3Os.xEnterMutex();
-
- /* Read the filesystem size from the base file. If pBaseRead is NULL, this
- ** means the file hasn't been opened yet. In this case all relevant data
- ** must be in the write-op queue anyway, so we can omit reading from the
- ** file-system.
- */
- pBase = ((AsyncFile *)id)->pBaseRead;
- if( pBase ){
- rc = sqlite3OsFileSize(pBase, &s);
- }
-
- if( rc==SQLITE_OK ){
- AsyncWrite *p;
- for(p=sqlite3_asyncListFirst; p; p = p->pNext){
- if( p->pFile==(AsyncFile *)id ){
- switch( p->op ){
- case ASYNC_WRITE:
- s = MAX(p->iOffset + (i64)(p->nByte), s);
- break;
- case ASYNC_TRUNCATE:
- s = MIN(s, p->nByte);
- break;
- }
- }
- }
- *pSize = s;
- }
- sqlite3Os.xLeaveMutex();
- return rc;
-}
-
-/*
-** Return the operating system file handle. This is only used for debugging
-** at the moment anyway.
-*/
-static int asyncFileHandle(OsFile *id){
- return sqlite3OsFileHandle(((AsyncFile *)id)->pBaseRead);
-}
-
-static int asyncLock(OsFile *id, int lockType){
- return SQLITE_OK;
-}
-static int asyncUnlock(OsFile *id, int lockType){
- return SQLITE_OK;
-}
-
-/*
-** This function is called when the pager layer first opens a database file
-** and is checking for a hot-journal.
-*/
-static int asyncCheckReservedLock(OsFile *id){
- return SQLITE_OK;
-}
-
-/*
-** This is broken. But sqlite3OsLockState() is only used for testing anyway.
-*/
-static int asyncLockState(OsFile *id){
- return SQLITE_OK;
-}
-
-/*
-** The three file-open functions for the underlying file system layer.
-*/
-static int (*xOrigOpenReadWrite)(const char*, OsFile**, int*) = 0;
-static int (*xOrigOpenExclusive)(const char*, OsFile**, int) = 0;
-static int (*xOrigOpenReadOnly)(const char*, OsFile**) = 0;
-
-/*
-** Pointers to the original versions of other overridden file-system
-** operations.
-*/
-static int (*xOrigDelete)(const char*) = 0;
-static int (*xOrigFileExists)(const char*) = 0;
-static int (*xOrigSyncDirectory)(const char*) = 0;
-
-static int asyncOpenFile(
- const char *zName,
- OsFile **pFile,
- OsFile *pBaseRead,
- int openSecondFile
-){
- int rc;
- AsyncFile *p;
- OsFile *pBaseWrite = 0;
-
- static IoMethod iomethod = {
- asyncClose,
- asyncOpenDirectory,
- asyncRead,
- asyncWrite,
- asyncSeek,
- asyncTruncate,
- asyncSync,
- asyncSetFullSync,
- asyncFileHandle,
- asyncFileSize,
- asyncLock,
- asyncUnlock,
- asyncLockState,
- asyncCheckReservedLock
- };
-
- if( openSecondFile && SQLITE_ASYNC_TWO_FILEHANDLES ){
- int dummy;
- rc = xOrigOpenReadWrite(zName, &pBaseWrite, &dummy);
- if( rc!=SQLITE_OK ){
- goto error_out;
- }
- }
-
- p = (AsyncFile *)sqlite3Os.xMalloc(sizeof(AsyncFile));
- if( !p ){
- rc = SQLITE_NOMEM;
- goto error_out;
- }
- memset(p, 0, sizeof(AsyncFile));
-
- p->pMethod = &iomethod;
- p->pBaseRead = pBaseRead;
- p->pBaseWrite = pBaseWrite;
-
- *pFile = (OsFile *)p;
- return SQLITE_OK;
-
-error_out:
- assert(!p);
- sqlite3OsClose(&pBaseRead);
- sqlite3OsClose(&pBaseWrite);
- *pFile = 0;
- return rc;
-}
-
-/*
-** The async-IO backends implementation of the three functions used to open
-** a file (xOpenExclusive, xOpenReadWrite and xOpenReadOnly). Most of the
-** work is done in function asyncOpenFile() - see above.
-*/
-static int asyncOpenExclusive(const char *z, OsFile **ppFile, int delFlag){
- int rc = asyncOpenFile(z, ppFile, 0, 0);
- if( rc==SQLITE_OK ){
- AsyncFile *pFile = (AsyncFile *)(*ppFile);
- int nByte = strlen(z)+1;
- i64 i = (i64)(delFlag);
- rc = addNewAsyncWrite(pFile, ASYNC_OPENEXCLUSIVE, i, nByte, z);
- if( rc!=SQLITE_OK ){
- sqlite3Os.xFree(pFile);
- *ppFile = 0;
- }
- }
- return rc;
-}
-static int asyncOpenReadOnly(const char *z, OsFile **ppFile){
- OsFile *pBase = 0;
- int rc = xOrigOpenReadOnly(z, &pBase);
- if( rc==SQLITE_OK ){
- rc = asyncOpenFile(z, ppFile, pBase, 0);
- }
- return rc;
-}
-static int asyncOpenReadWrite(const char *z, OsFile **ppFile, int *pReadOnly){
- OsFile *pBase = 0;
- int rc = xOrigOpenReadWrite(z, &pBase, pReadOnly);
- if( rc==SQLITE_OK ){
- rc = asyncOpenFile(z, ppFile, pBase, (*pReadOnly ? 0 : 1));
- }
- return rc;
-}
-
-/*
-** Implementation of sqlite3Os.xDelete. Add an entry to the end of the
-** write-op queue to perform the delete.
-*/
-static int asyncDelete(const char *z){
- return addNewAsyncWrite(0, ASYNC_DELETE, 0, strlen(z)+1, z);
-}
-
-/*
-** Implementation of sqlite3Os.xDelete. Add an entry to the end of the
-** write-op queue to perform the delete.
-*/
-static int asyncSyncDirectory(const char *z){
- return addNewAsyncWrite(0, ASYNC_SYNCDIRECTORY, 0, strlen(z)+1, z);
-}
-
-/*
-** Implementation of sqlite3Os.xFileExists. Return true if file 'z' exists
-** in the file system.
-**
-** This method holds the mutex from start to finish.
-*/
-static int asyncFileExists(const char *z){
- int ret;
- AsyncWrite *p;
- sqlite3Os.xEnterMutex();
-
- /* See if the real file system contains the specified file. */
- ret = xOrigFileExists(z);
-
- for(p=sqlite3_asyncListFirst; p; p = p->pNext){
- if( p->op==ASYNC_DELETE && 0==strcmp(p->zBuf, z) ){
- ret = 0;
- }else if( p->op==ASYNC_OPENEXCLUSIVE && 0==strcmp(p->zBuf, z) ){
- ret = 1;
- }
- }
-
- sqlite3Os.xLeaveMutex();
- return ret;
-}
-
-/*
-** The following routine is one of two exported symbols in this module (along
-** with sqlite3_async_flush(), see below). This routine should be called
-** once to enable the asynchronous IO features implemented in this file. If
-** the features are successfully enabled (or if they have already been
-** enabled) then SQLITE_OK is returned. Otherwise, SQLITE_MISUSE.
-*/
-int sqlite3_async_enable(void){
- if( xOrigOpenReadWrite==0 ){
- xOrigOpenReadWrite = sqlite3Os.xOpenReadWrite;
- xOrigOpenReadOnly = sqlite3Os.xOpenReadOnly;
- xOrigOpenExclusive = sqlite3Os.xOpenExclusive;
- xOrigDelete = sqlite3Os.xDelete;
- xOrigFileExists = sqlite3Os.xFileExists;
- xOrigSyncDirectory = sqlite3Os.xSyncDirectory;
-
- sqlite3Os.xOpenReadWrite = asyncOpenReadWrite;
- sqlite3Os.xOpenReadOnly = asyncOpenReadOnly;
- sqlite3Os.xOpenExclusive = asyncOpenExclusive;
- sqlite3Os.xDelete = asyncDelete;
- sqlite3Os.xFileExists = asyncFileExists;
- sqlite3Os.xSyncDirectory = asyncSyncDirectory;
- }
- return SQLITE_OK;
-}
-
-/*
-** This function is called externally to perform queued write and sync
-** operations. It returns when an IO error occurs or there are no more queued
-** operations to perform.
-*/
-int sqlite3_async_flush(void){
- AsyncWrite *p = 0;
- int rc = SQLITE_OK;
-
- /* Grab the mutex and set the sqlite3_asyncIoBusy flag to make sure this
- ** is the only thread performing an sqlite3_async_flush() at this time.
- ** Or, if some other thread is already inside this function, return
- ** SQLITE_BUSY to the caller.
- */
- sqlite3Os.xEnterMutex();
- if( sqlite3_asyncIoBusy ){
- sqlite3Os.xLeaveMutex();
- return SQLITE_BUSY;
- }
- sqlite3_asyncIoBusy = 1;
-
- while( (p = sqlite3_asyncListFirst) && rc==SQLITE_OK ){
- int isInsideMutex = 1;
-
- /* Right now this thread is holding the global mutex. Variable 'p' points
- ** to the first entry in the write-op queue. In the general case, we
- ** hold on to the mutex for the entire body of the loop.
- **
- ** However in the cases enumerated below, we relinquish the mutex,
- ** perform the IO, and then re-request the mutex before removing 'p' from
- ** the head of the write-op queue. The idea is to increase concurrency with
- ** sqlite threads.
- **
- ** * An ASYNC_CLOSE operation.
- ** * An ASYNC_OPENEXCLUSIVE operation. For this one, we relinquish
- ** the mutex, call the underlying xOpenExclusive() function, then
- ** re-aquire the mutex before seting the AsyncFile.pBaseRead
- ** variable.
- ** * ASYNC_SYNC and ASYNC_WRITE operations, if
- ** SQLITE_ASYNC_TWO_FILEHANDLES was set at compile time and two
- ** file-handles are open for the particular file being "synced".
- */
- OsFile *pBase = 0;
- if( p->pFile ){
- pBase = p->pFile->pBaseWrite;
- if(
- p->op==ASYNC_CLOSE ||
- p->op==ASYNC_OPENEXCLUSIVE ||
- (pBase && (p->op==ASYNC_SYNC || p->op==ASYNC_WRITE) )
- ){
- sqlite3Os.xLeaveMutex();
- isInsideMutex = 0;
- }
- if( !pBase ){
- pBase = p->pFile->pBaseRead;
- }
- }
-
- switch( p->op ){
- case ASYNC_WRITE:
- assert( pBase );
- rc = sqlite3OsSeek(pBase, p->iOffset);
- if( rc==SQLITE_OK ){
- rc = sqlite3OsWrite(pBase, (const void *)(p->zBuf), p->nByte);
- }
- break;
-
- case ASYNC_SYNC:
- assert( pBase );
- rc = sqlite3OsSync(pBase, p->nByte);
- break;
-
- case ASYNC_TRUNCATE:
- assert( pBase );
- rc = sqlite3OsTruncate(pBase, p->nByte);
- break;
-
- case ASYNC_CLOSE:
- sqlite3OsClose(&p->pFile->pBaseRead);
- sqlite3OsClose(&p->pFile->pBaseWrite);
- sqlite3Os.xFree(p->pFile);
- break;
-
- case ASYNC_OPENDIRECTORY:
- assert( pBase );
- sqlite3OsOpenDirectory(pBase, p->zBuf);
- break;
-
- case ASYNC_SETFULLSYNC:
- assert( pBase );
- sqlite3OsSetFullSync(pBase, p->nByte);
- break;
-
- case ASYNC_DELETE:
- rc = xOrigDelete(p->zBuf);
- break;
-
- case ASYNC_SYNCDIRECTORY:
- rc = xOrigSyncDirectory(p->zBuf);
- break;
-
- case ASYNC_OPENEXCLUSIVE: {
- AsyncFile *pFile = p->pFile;
- int delFlag = ((p->iOffset)?1:0);
- OsFile *pBase = 0;
- rc = xOrigOpenExclusive(p->zBuf, &pBase, delFlag);
-
- sqlite3Os.xEnterMutex();
- isInsideMutex = 1;
- if( rc==SQLITE_OK ){
- pFile->pBaseRead = pBase;
- }
- break;
- }
-
- default: assert(!"Illegal value for AsyncWrite.op");
- }
-
- /* If we didn't hang on to the mutex during the IO op, obtain it now
- ** so that the AsyncWrite structure can be safely removed from the
- ** global write-op queue.
- */
- if( !isInsideMutex ){
- sqlite3Os.xEnterMutex();
- }
- if( rc==SQLITE_OK ){
- removeAsyncWrite(p);
- sqlite3Os.xFree(p);
- }
- }
-
- /* Clear the io-busy flag and exit the mutex */
- assert( sqlite3_asyncIoBusy );
- sqlite3_asyncIoBusy = 0;
- sqlite3Os.xLeaveMutex();
-
- return rc;
-}
-
-/*
-** The following code defines a Tcl interface for testing the asynchronous
-** IO implementation in this file.
-*/
-#if defined(SQLITE_TEST) && defined(TCLSH)
-
-#include <tcl.h>
-
-/*
-** sqlite3_async_enable
-*/
-static int testAsyncEnable(
- void * clientData,
- Tcl_Interp *interp,
- int objc,
- Tcl_Obj *CONST objv[]
-){
- if( sqlite3_async_enable() ){
- Tcl_SetResult(interp, "sqlite3_async_enable() failed", TCL_STATIC);
- return TCL_ERROR;
- }
- return TCL_OK;
-}
-
-/*
-** This is the main proc for a thread spawned by the Tcl command
-** [sqlite3_async_flush -start]. The client data is a pointer to an integer
-** variable that will be set to non-zero when this thread should exit.
-*/
-static void testAsyncFlushThread(ClientData clientData){
- int *pStop = (int *)clientData;
- int rc = 0;
-
- /* Run in a loop until an IO error occurs or we are told to stop via
- ** the *pStop variable. Each iteration of the loop, call
- ** sqlite3_async_flush() and then sleep for a tenth of a second.
- */
- while( !(*pStop) && !rc ){
- rc = sqlite3_async_flush();
- assert( rc==SQLITE_OK );
- Tcl_Sleep(100);
- }
- if( rc==0 ){
- rc = sqlite3_async_flush();
- }
- Tcl_ExitThread(rc);
-}
-
-/*
-** sqlite3_async_flush
-** sqlite3_async_flush -start
-** sqlite3_async_flush -stop
-*/
-static int testAsyncFlush(
- void * clientData,
- Tcl_Interp *interp,
- int objc,
- Tcl_Obj *CONST objv[]
-){
- static Tcl_ThreadId thread_id = 0;
- static int stop = 0;
-
- assert(stop==0);
-
- if( objc!=1 && objc!=2 ){
- Tcl_WrongNumArgs(interp, 1, objv, "?-start | -stop?");
- return TCL_ERROR;
- }
-
- if( objc==2 ){
- char *zOpt = Tcl_GetString(objv[1]);
- if( 0==strcmp(zOpt, "-start") ){
- /* Unless it is already running, kick off the _flush() thread */
- if( thread_id ){
- Tcl_AppendResult(interp, "Thread has already started", 0);
- return TCL_ERROR;
- }else{
- int rc = Tcl_CreateThread(
- &thread_id,
- testAsyncFlushThread,
- &stop,
- TCL_THREAD_STACK_DEFAULT,
- TCL_THREAD_JOINABLE
- );
- if( rc!=TCL_OK ){
- Tcl_AppendResult(interp, "Tcl_CreateThread() failed", 0);
- return TCL_ERROR;
- }
- }
- }else if( 0==strcmp(zOpt, "-stop") ){
- int dummy;
- stop = 1;
- Tcl_JoinThread(thread_id, &dummy);
- stop = 0;
- thread_id = 0;
- }else{
- Tcl_AppendResult(interp, "Invalid option: \"", zOpt, "\"", 0);
- return TCL_ERROR;
- }
- }else if( sqlite3_async_flush() ){
- Tcl_SetResult(interp, "sqlite3_async_flush() failed", TCL_STATIC);
- return TCL_ERROR;
- }
- return TCL_OK;
-}
-
-int Sqlitetestasync_Init(Tcl_Interp *interp){
- Tcl_CreateObjCommand(interp,"sqlite3_async_enable",testAsyncEnable,0,0);
- Tcl_CreateObjCommand(interp,"sqlite3_async_flush",testAsyncFlush,0,0);
- return TCL_OK;
-}
-
-#endif
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.160 2006/01/06 06:33:13 danielk1977 Exp $
+** $Id: util.c,v 1.161 2006/01/06 14:32:20 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
** level (not in this file). The Os level interface is never accessed directly
** by code outside of this file.
**
-** sqlite3Os.xMalloc()
-** sqlite3Os.xRealloc()
-** sqlite3Os.xFree()
-** sqlite3Os.xAllocationSize()
+** sqlite3OsMalloc()
+** sqlite3OsRealloc()
+** sqlite3OsFree()
+** sqlite3OsAllocationSize()
**
** Functions sqlite3MallocRaw() and sqlite3Realloc() may invoke
-** sqlite3_release_memory() if a call to sqlite3Os.xMalloc() or
-** sqlite3Os.xRealloc() fails (or if the soft-heap-limit for the thread is
+** 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().
**
TESTALLOC_OFFSET_GUARD1(p) + sizeof(u32) * TESTALLOC_NGUARD \
)
#define TESTALLOC_OFFSET_GUARD2(p) ( \
- TESTALLOC_OFFSET_DATA(p) + sqlite3Os.xAllocationSize(p) - TESTALLOC_OVERHEAD \
+ TESTALLOC_OFFSET_DATA(p) + sqlite3OsAllocationSize(p) - TESTALLOC_OVERHEAD \
)
#define TESTALLOC_OFFSET_LINENUMBER(p) ( \
TESTALLOC_OFFSET_GUARD2(p) + sizeof(u32) * TESTALLOC_NGUARD \
}
/*
-** The argument is a pointer returned by sqlite3Os.xMalloc() or xRealloc().
+** 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.
*/
}
/*
-** The argument is a pointer returned by sqlite3Os.xMalloc() or Realloc(). The
+** 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.
*/
Tcl_Obj *pStack = Tcl_NewObj();
char *z;
u32 iLine;
- int nBytes = sqlite3Os.xAllocationSize(p) - TESTALLOC_OVERHEAD;
+ int nBytes = sqlite3OsAllocationSize(p) - TESTALLOC_OVERHEAD;
char *zAlloc = (char *)p;
int i;
#endif
/*
-** This is the test layer's wrapper around sqlite3Os.xMalloc().
+** This is the test layer's wrapper around sqlite3OsMalloc().
*/
static void * OSMALLOC(int n){
#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
#endif
if( !failMalloc() ){
u32 *p;
- p = (u32 *)sqlite3Os.xMalloc(n + TESTALLOC_OVERHEAD);
+ p = (u32 *)sqlite3OsMalloc(n + TESTALLOC_OVERHEAD);
assert(p);
sqlite3_nMalloc++;
applyGuards(p);
}
/*
-** This is the test layer's wrapper around sqlite3Os.xFree(). The argument is a
+** This is the test layer's wrapper around sqlite3OsFree(). The argument is a
** pointer to the space allocated for the application to use.
*/
void OSFREE(void *pFree){
u32 *p = (u32 *)getOsPointer(pFree); /* p points to Os level allocation */
checkGuards(p);
unlinkAlloc(p);
- sqlite3Os.xFree(p);
+ sqlite3OsFree(p);
sqlite3_nFree++;
}
/*
-** This is the test layer's wrapper around sqlite3Os.xRealloc().
+** This is the test layer's wrapper around sqlite3OsRealloc().
*/
void * OSREALLOC(void *pRealloc, int n){
#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
if( !failMalloc() ){
u32 *p = (u32 *)getOsPointer(pRealloc);
checkGuards(p);
- p = sqlite3Os.xRealloc(p, n + TESTALLOC_OVERHEAD);
+ p = sqlite3OsRealloc(p, n + TESTALLOC_OVERHEAD);
applyGuards(p);
relinkAlloc(p);
return (void *)(&p[TESTALLOC_NGUARD + 2*sizeof(void *)/sizeof(u32)]);
int OSSIZEOF(void *p){
if( p ){
u32 *pOs = (u32 *)getOsPointer(p);
- return sqlite3Os.xAllocationSize(pOs) - TESTALLOC_OVERHEAD;
+ return sqlite3OsAllocationSize(pOs) - TESTALLOC_OVERHEAD;
}
return 0;
}
#else
-/* Define macros to call the sqlite3Os.xXXX interface directly if
+/* Define macros to call the sqlite3OsXXX interface directly if
** the SQLITE_MEMDEBUG macro is not defined.
*/
-#define OSMALLOC(x) sqlite3Os.xMalloc(x)
-#define OSREALLOC(x,y) sqlite3Os.xRealloc(x,y)
-#define OSFREE(x) sqlite3Os.xFree(x)
-#define OSSIZEOF(x) sqlite3Os.xAllocationSize(x)
+#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
/*
** The handleSoftLimit() function is called before each call to
-** sqlite3Os.xMalloc() or xRealloc(). The parameter 'n' is the number of
+** sqlite3OsMalloc() or xRealloc(). The parameter 'n' is the number of
** extra bytes about to be allocated (for Realloc() this means the size of the
** new allocation less the size of the old allocation). If the extra allocation
** means that the total memory allocated to SQLite in this thread would exceed
/*
** Allocate and return N bytes of uninitialised memory by calling
-** sqlite3Os.xMalloc(). If the Malloc() call fails, attempt to free memory
+** sqlite3OsMalloc(). If the Malloc() call fails, attempt to free memory
** by calling sqlite3_release_memory().
*/
void *sqlite3MallocRaw(int n){
}
/*
-** Resize the allocation at p to n bytes by calling sqlite3Os.xRealloc(). The
+** 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().
*/
** Return a pointer to the SqliteTsd associated with the calling thread.
*/
SqliteTsd *sqlite3Tsd(){
- SqliteTsd *pTsd = sqlite3Os.xThreadSpecificData(sizeof(SqliteTsd));
+ SqliteTsd *pTsd = sqlite3OsThreadSpecificData(sizeof(SqliteTsd));
if( pTsd && !pTsd->isInit ){
pTsd->nSoftHeapLimit = -1;
#ifndef NDEBUG
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
-** $Id: vacuum.c,v 1.53 2005/12/09 20:02:06 drh Exp $
+** $Id: vacuum.c,v 1.54 2006/01/06 14:32:20 drh Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
do {
zTemp[nFilename] = '-';
randomName((unsigned char*)&zTemp[nFilename+1]);
- } while( sqlite3Os.xFileExists(zTemp) );
+ } while( sqlite3OsFileExists(zTemp) );
/* Before we even attach it, compile a DETACH statement for vacuum_db. This
** way, if malloc() fails we can detach the database without needing to
}
if( zTemp ){
- sqlite3Os.xDelete(zTemp);
+ sqlite3OsDelete(zTemp);
sqliteFree(zTemp);
}
sqliteFree( zSql );
** 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.512 2006/01/05 23:42:51 drh Exp $
+** $Id: vdbe.c,v 1.513 2006/01/06 14:32:20 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
}
sqlite3VdbePrintOp(p->trace, pc, pOp);
}
- if( p->trace==0 && pc==0 && sqlite3Os.xFileExists("vdbe_sqltrace") ){
+ if( p->trace==0 && pc==0 && sqlite3OsFileExists("vdbe_sqltrace") ){
sqlite3VdbePrintSql(p);
}
#endif
}
if( db->xProfile && !db->init.busy ){
double rNow;
- sqlite3Os.xCurrentTime(&rNow);
+ sqlite3OsCurrentTime(&rNow);
p->startTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0;
}
#endif
double rNow;
u64 elapseTime;
- sqlite3Os.xCurrentTime(&rNow);
+ sqlite3OsCurrentTime(&rNow);
elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime;
assert( p->nOp>0 );
assert( p->aOp[p->nOp-1].opcode==OP_Noop );
/* If we never rollback a statement transaction, then statement
** transactions are not needed. So change every OP_Statement
- ** opcode into an OP_Noop. This avoid a call to sqlite3Os.xOpenExclusive()
+ ** opcode into an OP_Noop. This avoid a call to sqlite3OsOpenExclusive()
** which can be expensive on some platforms.
*/
if( hasStatementBegin && !doesStatementRollback ){
#ifdef SQLITE_DEBUG
if( (p->db->flags & SQLITE_VdbeListing)!=0
- || sqlite3Os.xFileExists("vdbe_explain")
+ || sqlite3OsFileExists("vdbe_explain")
){
int i;
printf("VDBE Program Listing:\n");
sqlite3VdbePrintOp(stdout, i, &p->aOp[i]);
}
}
- if( sqlite3Os.xFileExists("vdbe_trace") ){
+ if( sqlite3OsFileExists("vdbe_trace") ){
p->trace = stdout;
}
#endif
if( !zMaster ){
return SQLITE_NOMEM;
}
- }while( sqlite3Os.xFileExists(zMaster) );
+ }while( sqlite3OsFileExists(zMaster) );
/* Open the master journal. */
- rc = sqlite3Os.xOpenExclusive(zMaster, &master, 0);
+ rc = sqlite3OsOpenExclusive(zMaster, &master, 0);
if( rc!=SQLITE_OK ){
sqliteFree(zMaster);
return rc;
rc = sqlite3OsWrite(master, zFile, strlen(zFile)+1);
if( rc!=SQLITE_OK ){
sqlite3OsClose(&master);
- sqlite3Os.xDelete(zMaster);
+ sqlite3OsDelete(zMaster);
sqliteFree(zMaster);
return rc;
}
if( rc!=SQLITE_OK ||
(needSync && (rc=sqlite3OsSync(master,0))!=SQLITE_OK) ){
sqlite3OsClose(&master);
- sqlite3Os.xDelete(zMaster);
+ sqlite3OsDelete(zMaster);
sqliteFree(zMaster);
return rc;
}
** doing this the directory is synced again before any individual
** transaction files are deleted.
*/
- rc = sqlite3Os.xDelete(zMaster);
+ rc = sqlite3OsDelete(zMaster);
assert( rc==SQLITE_OK );
sqliteFree(zMaster);
zMaster = 0;
- rc = sqlite3Os.xSyncDirectory(zMainFile);
+ rc = sqlite3OsSyncDirectory(zMainFile);
if( rc!=SQLITE_OK ){
/* This is not good. The master journal file has been deleted, but
** the directory sync failed. There is no completely safe course of
+++ /dev/null
-#
-# May you do good and not evil.
-# May you find forgiveness for yourself and forgive others.
-# May you share freely, never taking more than you give.
-#
-#***********************************************************************
-# This file runs all tests.
-#
-# $Id: async.test,v 1.1 2006/01/03 13:39:26 danielk1977 Exp $
-
-set testdir [file dirname $argv0]
-source $testdir/tester.tcl
-rename finish_test really_finish_test
-proc finish_test {} {}
-set ISQUICK 1
-
-if {[info exists ::tcl_platform(threaded)]} {
- set USE_THREAD 1
-} else {
- set USE_THREAD 0
-}
-
-set INCLUDE {
- select1.test
- select2.test
- select3.test
- select4.test
- insert.test
- insert2.test
- insert3.test
-}
-#set INCLUDE [lrange $INCLUDE 0 0]
-
-# Enable asynchronous IO.
-sqlite3_async_enable
-
-# set USE_THREAD 0
-if {$USE_THREAD} {
- sqlite3_async_flush -start
-} else {
- rename do_test really_do_test
- proc do_test {name args} {
- uplevel really_do_test async_io-$name $args
- sqlite3_async_flush
- }
-}
-
-foreach testfile [lsort -dictionary [glob $testdir/*.test]] {
- set tail [file tail $testfile]
- if {[lsearch -exact $INCLUDE $tail]<0} continue
- source $testfile
- catch {db close}
-# if {$sqlite_open_file_count>0} {
-# puts "$tail did not close all files: $sqlite_open_file_count"
-# incr nErr
-# lappend ::failList $tail
-# }
-}
-#source $testdir/misuse.test
-
-
-if {$USE_THREAD} {
- sqlite3_async_flush -stop
-} else {
- rename do_test {}
- rename really_do_test do_test
- puts "Warning: Tcl library was without --enable-threads."
- puts " Cannot test async IO properly."
- sqlite3_async_flush
-}
-
-set sqlite_open_file_count 0
-really_finish_test
-
# the modified I/O routines found in test6.c. These routines allow us
# to simulate the kind of file damage that occurs after a power failure.
#
-# $Id: crash.test,v 1.20 2005/11/26 00:25:04 drh Exp $
+# $Id: crash.test,v 1.21 2006/01/06 14:32:20 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !crashtest {
+ finish_test
+ return
+}
+
# set repeats 100
set repeats 10
# The tests in this file use special facilities that are only
# available in the SQLite test fixture.
#
-# $Id: ioerr.test,v 1.21 2005/08/20 13:47:42 drh Exp $
+# $Id: ioerr.test,v 1.22 2006/01/06 14:32:20 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Test IO errors when replaying two hot journals from a 2-file
# transaction. This test only runs on UNIX.
-if {$tcl_platform(platform)=="unix" && [file exists ./crashtest]
- && ![catch {sqlite3 -has-codec} r] && !$r} {
- do_ioerr_test ioerr-6 -tclprep {
- execsql {
- ATTACH 'test2.db' as aux;
- CREATE TABLE tx(a, b);
- CREATE TABLE aux.ty(a, b);
- }
- set rc [crashsql 2 test2.db-journal {
- ATTACH 'test2.db' as aux;
- PRAGMA cache_size = 10;
- BEGIN;
- CREATE TABLE aux.t2(a, b, c);
- CREATE TABLE t1(a, b, c);
- COMMIT;
- }]
- if {$rc!="1 {child process exited abnormally}"} {
- error "Wrong error message: $rc"
+ifcapable crashtest {
+ if {![catch {sqlite3 -has_codec} r] && !$r} {
+ do_ioerr_test ioerr-6 -tclprep {
+ execsql {
+ ATTACH 'test2.db' as aux;
+ CREATE TABLE tx(a, b);
+ CREATE TABLE aux.ty(a, b);
+ }
+ set rc [crashsql 2 test2.db-journal {
+ ATTACH 'test2.db' as aux;
+ PRAGMA cache_size = 10;
+ BEGIN;
+ CREATE TABLE aux.t2(a, b, c);
+ CREATE TABLE t1(a, b, c);
+ COMMIT;
+ }]
+ if {$rc!="1 {child process exited abnormally}"} {
+ error "Wrong error message: $rc"
+ }
+ } -sqlbody {
+ SELECT * FROM sqlite_master;
+ SELECT * FROM aux.sqlite_master;
}
- } -sqlbody {
- SELECT * FROM sqlite_master;
- SELECT * FROM aux.sqlite_master;
}
}
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
-# $Id: malloc.test,v 1.25 2005/12/06 12:53:01 danielk1977 Exp $
+# $Id: malloc.test,v 1.26 2006/01/06 14:32:20 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
}
# Test malloc errors when replaying two hot journals from a 2-file
-# transaction. This test only runs on UNIX.
-if {$tcl_platform(platform)=="unix"} {
+# transaction.
+ifcapable crashtest {
do_malloc_test 13 -tclprep {
set rc [crashsql 1 test2.db {
ATTACH 'test2.db' as aux;