]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Change the OS interface layer to use traditional direct function call
authordrh <drh@noemail.net>
Fri, 6 Jan 2006 14:32:19 +0000 (14:32 +0000)
committerdrh <drh@noemail.net>
Fri, 6 Jan 2006 14:32:19 +0000 (14:32 +0000)
implementations instead of the more complicated virtual function table.
Omit the asynchronous I/O demo. (CVS 2870)

FossilOrigin-Name: 2529c2e11fa1d345ec61f647e4f6fae20a7133d6

29 files changed:
Makefile.in
main.mk
manifest
manifest.uuid
src/btree.c
src/date.c
src/main.c
src/os.c
src/os.h
src/os_common.h
src/os_unix.c
src/os_win.c
src/pager.c
src/pragma.c
src/random.c
src/tclsqlite.c
src/test1.c
src/test2.c
src/test6.c
src/test_async.c [deleted file]
src/util.c
src/vacuum.c
src/vdbe.c
src/vdbeapi.c
src/vdbeaux.c
test/async.test [deleted file]
test/crash.test
test/ioerr.test
test/malloc.test

index fbfc51dc7c8d44b73741ac56dacfab0e35f1a152..e2a07b8bfb9621b614e18d9f06218df03a134c8d 100644 (file)
@@ -191,7 +191,6 @@ TESTSRC = \
   $(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 \
@@ -425,8 +424,8 @@ tclsqlite3: tclsqlite-shell.lo libsqlite3.la
                 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)
 
 
diff --git a/main.mk b/main.mk
index 4e33f9777227e8540fbde7ddb89ccab9bc41ec0b..af0120797e429df2672ab20c4a306d3447397580 100644 (file)
--- a/main.mk
+++ b/main.mk
@@ -133,15 +133,12 @@ TESTSRC = \
   $(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 = \
@@ -358,7 +355,8 @@ tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a
                $(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)
 
index d51cc5a3df7dc2d873bad01b9ba54ec5b9689477..0cbe62415375e9fd35bbe4c31aacfb3b12bbb80f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,6 +1,6 @@
-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
@@ -19,7 +19,7 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
 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
@@ -34,12 +34,12 @@ F src/alter.c e9deb3f4fd7c663a0d1f235d541bc5ea1f2cfa8b
 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
@@ -48,48 +48,47 @@ F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863
 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
@@ -100,7 +99,6 @@ F test/alter2.test cc0b8832e4e98605dbc26910efd4bb89abe59cb2
 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
@@ -140,7 +138,7 @@ F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638
 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
@@ -169,7 +167,7 @@ F test/insert2.test 5a20e1ace5fa0800b58d28284212290189b49aed
 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
@@ -184,7 +182,7 @@ F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107
 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
@@ -337,7 +335,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 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
index c891ff356a3d6bc7580e7571848b77285f44eb0b..c5cd3ab968782ea22c6c14a3b083e1e1b6abc2c3 100644 (file)
@@ -1 +1 @@
-d054bed15aee3edef93cc84c83be443cdd489946
\ No newline at end of file
+2529c2e11fa1d345ec61f647e4f6fae20a7133d6
\ No newline at end of file
index c1032f509601d73979c2b580e5c66dada1555fbd..378e6eb3b87247702c86543821f542be18a75f6c 100644 (file)
@@ -9,7 +9,7 @@
 **    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
@@ -1571,7 +1571,7 @@ int sqlite3BtreeOpen(
   /* 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;
index 18c1fe47be057579ddb606f7910f967c617fca20..40f3b1914ab02e52051f9a82bc4cf146b4dec3e7 100644 (file)
@@ -16,7 +16,7 @@
 ** 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:
 **
@@ -311,7 +311,7 @@ static int parseDateOrTime(const char *zDate, DateTime *p){
     return 0;
   }else if( sqlite3StrICmp(zDate,"now")==0){
     double r;
-    sqlite3Os.xCurrentTime(&r);
+    sqlite3OsCurrentTime(&r);
     p->rJD = r;
     p->validJD = 1;
     return 0;
@@ -409,7 +409,7 @@ static double localtimeOffset(DateTime *p){
   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;
@@ -417,7 +417,7 @@ static double localtimeOffset(DateTime *p){
   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;
@@ -942,9 +942,9 @@ static void currentTimeFunc(
   }
 #endif
 
-  sqlite3Os.xEnterMutex();
+  sqlite3OsEnterMutex();
   strftime(zBuf, 20, zFormat, gmtime(&t));
-  sqlite3Os.xLeaveMutex();
+  sqlite3OsLeaveMutex();
 
   sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
 }
index 6f4a2c07bfbb5cfe0e358a71179b8efcfea747c9..d9365d51af4f28c6b1d855f0b1f97123ef27bdff 100644 (file)
@@ -14,7 +14,7 @@
 ** 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"
@@ -336,14 +336,14 @@ static int sqliteDefaultBusyCallback(
     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
 }
index fcaf0a07d918324cc6e90dc52a1b9e2460288785..97036746a395fd2e1c38203c467e798bf832eebe 100644 (file)
--- a/src/os.c
+++ b/src/os.c
@@ -69,6 +69,3 @@ int sqlite3OsLockState(OsFile *id){
 int sqlite3OsCheckReservedLock(OsFile *id){
   return id->pMethod->xCheckReservedLock(id);
 }
-struct sqlite3OsVtbl *sqlite3_os_switch(void){
-  return &sqlite3Os;
-}
index 81e62c3092fab5318cd8dca90e4d0fc7b4f380a4..a132bc5e0441f7c357c928bc0c87e0640891fd32 100644 (file)
--- a/src/os.h
+++ b/src/os.h
 #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
 */
@@ -204,51 +261,7 @@ extern unsigned int sqlite3_pending_byte;
 #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*);
@@ -264,5 +277,25 @@ int sqlite3OsLock(OsFile*, int);
 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_ */
index cca9f5a9792e8ef273f3e80f01816f1d4f0b9345..a03b6218ed50af77ddc5e4bd51e9c41d9626d9d7 100644 (file)
@@ -124,16 +124,16 @@ int sqlite3_open_file_count = 0;
 #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);
@@ -142,7 +142,7 @@ static void *genericMalloc(int n){
   }
   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);
@@ -151,10 +151,10 @@ static void *genericRealloc(void *p, int n){
   }
   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;
 }
index 2f90e3d47bac801c536bfe9260f6646c705dd9b2..1d74a884f6bb87978c63bc7087685b344e02dc98 100644 (file)
@@ -15,6 +15,7 @@
 #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
@@ -88,6 +89,22 @@ struct unixFile {
 #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
@@ -564,7 +581,7 @@ exit_findlockinfo:
 /*
 ** Delete the named file
 */
-static int unixDelete(const char *zFilename){
+int sqlite3UnixDelete(const char *zFilename){
   unlink(zFilename);
   return SQLITE_OK;
 }
@@ -572,7 +589,7 @@ static int unixDelete(const char *zFilename){
 /*
 ** Return TRUE if the named file exists.
 */
-static int unixFileExists(const char *zFilename){
+int sqlite3UnixFileExists(const char *zFilename){
   return access(zFilename, 0)==0;
 }
 
@@ -592,7 +609,7 @@ static int allocateUnixFile(unixFile *pInit, OsFile **pId);
 ** 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
@@ -600,6 +617,7 @@ static int unixOpenReadWrite(
   int rc;
   unixFile f;
 
+  CRASH_TEST_OVERRIDE(sqlite3CrashOpenReadWrite, zFilename, pId, pReadonly);
   assert( 0==*pId );
   f.dirfd = -1;
   SET_THREADID(&f);
@@ -619,9 +637,9 @@ static int unixOpenReadWrite(
   }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;
@@ -646,10 +664,11 @@ static int unixOpenReadWrite(
 **
 ** 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;
@@ -662,9 +681,9 @@ static int unixOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
   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);
@@ -685,10 +704,11 @@ static int unixOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
 **
 ** 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;
@@ -696,9 +716,9 @@ static int unixOpenReadOnly(const char *zFilename, OsFile **pId){
   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;
@@ -756,7 +776,7 @@ char *sqlite3_temp_directory = 0;
 ** 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",
@@ -796,7 +816,7 @@ static int unixTempFileName(char *zBuf){
 ** 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;
@@ -982,7 +1002,7 @@ static int unixSync(OsFile *id, int dataOnly){
 ** 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
@@ -1035,7 +1055,7 @@ static int unixCheckReservedLock(OsFile *id){
 
   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 ){
@@ -1056,7 +1076,7 @@ static int unixCheckReservedLock(OsFile *id){
     }
   }
   
-  sqlite3Os.xLeaveMutex();
+  sqlite3OsLeaveMutex();
   TRACE3("TEST WR-LOCK %d %d\n", pFile->h, r);
 
   return r;
@@ -1157,7 +1177,7 @@ static int unixLock(OsFile *id, int locktype){
 
   /* 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,
@@ -1173,7 +1193,7 @@ static int unixLock(OsFile *id, int locktype){
 
   /* 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.
@@ -1285,7 +1305,7 @@ static int unixLock(OsFile *id, int locktype){
   }
 
 end_lock:
-  sqlite3Os.xLeaveMutex();
+  sqlite3OsLeaveMutex();
   TRACE4("LOCK    %d %s %s\n", pFile->h, locktypeName(locktype), 
       rc==SQLITE_OK ? "ok" : "failed");
   return rc;
@@ -1317,7 +1337,7 @@ static int unixUnlock(OsFile *id, int locktype){
   if( pFile->locktype<=locktype ){
     return SQLITE_OK;
   }
-  sqlite3Os.xEnterMutex();
+  sqlite3OsEnterMutex();
   pLock = pFile->pLock;
   assert( pLock->cnt!=0 );
   if( pFile->locktype>SHARED_LOCK ){
@@ -1378,7 +1398,7 @@ static int unixUnlock(OsFile *id, int locktype){
       pOpen->aPending = 0;
     }
   }
-  sqlite3Os.xLeaveMutex();
+  sqlite3OsLeaveMutex();
   pFile->locktype = locktype;
   return rc;
 }
@@ -1394,7 +1414,7 @@ static int unixClose(OsFile **pId){
   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 );
@@ -1426,7 +1446,7 @@ static int unixClose(OsFile **pId){
   /* Disable the sqlite3_release_memory() function */
   pTsd->disableReleaseMemory = 0;
 
-  sqlite3Os.xLeaveMutex();
+  sqlite3OsLeaveMutex();
   id->isOpen = 0;
   TRACE2("CLOSE   %-3d\n", id->h);
   OpenCounter(-1);
@@ -1441,7 +1461,7 @@ static int unixClose(OsFile **pId){
 ** 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);
@@ -1537,7 +1557,7 @@ static int allocateUnixFile(unixFile *pInit, OsFile **pId){
 ** 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
@@ -1571,7 +1591,7 @@ static int unixRandomSeed(char *zBuf){
 /*
 ** 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;
@@ -1597,14 +1617,14 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 ** 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
@@ -1618,7 +1638,7 @@ static void unixLeaveMutex(){
 ** 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;
 }
 
@@ -1632,7 +1652,7 @@ static int unixInMutex(){
 */
 #ifdef SQLITE_UNIX_THREADS
 static void deleteTsd(void *pTsd){
-  sqlite3Os.xFree(pTsd);
+  sqlite3OsFree(pTsd);
 }
 #endif
 
@@ -1644,14 +1664,14 @@ static void deleteTsd(void *pTsd){
 ** 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);
@@ -1660,12 +1680,12 @@ static void *unixThreadSpecificData(int nByte){
       }
       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);
@@ -1675,7 +1695,7 @@ static void *unixThreadSpecificData(int nByte){
 #else
   static void *pTsd = 0;
   if( !pTsd ){
-    pTsd = sqlite3Os.xMalloc(nByte);
+    pTsd = sqlite3OsMalloc(nByte);
     if( pTsd ){
       memset(pTsd, 0, nByte);
     }
@@ -1686,7 +1706,7 @@ static void *unixThreadSpecificData(int 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;
@@ -1697,7 +1717,7 @@ 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);
@@ -1716,40 +1736,4 @@ static int unixCurrentTime(double *prNow){
   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 */
index 108315ed58fb8efd578b3d4105fe83b816813826..4f969e42344dd8203a47ce71ad2d43171376f476 100644 (file)
@@ -139,7 +139,7 @@ static char *unicodeToUtf8(const WCHAR *zWideFilename){
 /*
 ** Delete the named file
 */
-static int winDelete(const char *zFilename){
+int sqlite3WinDelete(const char *zFilename){
   WCHAR *zWide = utf8ToUnicode(zFilename);
   if( zWide ){
     DeleteFileW(zWide);
@@ -154,7 +154,7 @@ static int winDelete(const char *zFilename){
 /*
 ** 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 ){
@@ -182,7 +182,7 @@ int allocateWinFile(winFile *pInit, OsFile **pId);
 ** 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
@@ -266,7 +266,7 @@ static int winOpenReadWrite(
 **
 ** 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;
@@ -315,7 +315,7 @@ static int winOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
 **
 ** 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);
@@ -384,7 +384,7 @@ char *sqlite3_temp_directory = 0;
 ** 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"
@@ -417,7 +417,7 @@ static int winTempFileName(char *zBuf){
       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; 
@@ -525,7 +525,7 @@ static int winSync(OsFile *id, int dataOnly){
 ** 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;
 }
@@ -595,7 +595,7 @@ static int unlockReadLock(winFile *pFile){
 ** 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;
@@ -817,7 +817,7 @@ static int winUnlock(OsFile *id, int locktype){
 ** 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;
@@ -906,7 +906,7 @@ int allocateWinFile(winFile *pInit, OsFile **pId){
   }else{
     *pNew = *pInit;
     pNew->pMethod = &sqlite3WinIoMethod;
-    *pId = pNew;
+    *pId = (OsFile*)pNew;
     return SQLITE_OK;
   }
 }
@@ -923,7 +923,7 @@ int allocateWinFile(winFile *pInit, OsFile **pId){
 ** 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
@@ -944,7 +944,7 @@ static int winRandomSeed(char *zBuf){
 /*
 ** Sleep for a little while.  Return the amount of time slept.
 */
-static int winSleep(int ms){
+int sqlite3WinSleep(int ms){
   Sleep(ms);
   return ms;
 }
@@ -965,7 +965,7 @@ static int inMutex = 0;
 ** 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 ){
@@ -982,7 +982,7 @@ static void winEnterMutex(){
   assert( !inMutex );
   inMutex = 1;
 }
-static void winLeaveMutex(){
+void sqlite3WinLeaveMutex(){
   assert( inMutex );
   inMutex = 0;
 #ifdef SQLITE_W32_THREADS
@@ -996,7 +996,7 @@ static void winLeaveMutex(){
 ** 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;
 }
 
@@ -1014,7 +1014,7 @@ 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 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). 
@@ -1039,26 +1039,26 @@ static int winCurrentTime(double *prNow){
 ** 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);
@@ -1066,40 +1066,4 @@ static void *winThreadSpecificData(int nByte){
   }
   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 */
index bb979cad721958c6f3a06129a5796ab103b8a2ca..e41833ce8f0738729051f032e633d12167a24b20 100644 (file)
@@ -18,7 +18,7 @@
 ** 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"
@@ -934,7 +934,7 @@ static int pager_unwritelock(Pager *pPager){
   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){
@@ -1110,7 +1110,7 @@ static int pager_delmaster(const char *zMaster){
   /* 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);
@@ -1133,7 +1133,7 @@ static int pager_delmaster(const char *zMaster){
 
     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.
@@ -1141,7 +1141,7 @@ static int pager_delmaster(const char *zMaster){
         OsFile *journal = 0;
         int c;
 
-        rc = sqlite3Os.xOpenReadOnly(zJournal, &journal);
+        rc = sqlite3OsOpenReadOnly(zJournal, &journal);
         if( rc!=SQLITE_OK ){
           goto delmaster_out;
         }
@@ -1163,7 +1163,7 @@ static int pager_delmaster(const char *zMaster){
     }
   }
   
-  sqlite3Os.xDelete(zMaster);
+  sqlite3OsDelete(zMaster);
 
 delmaster_out:
   if( zMasterJournal ){
@@ -1304,7 +1304,7 @@ static int pager_playback(Pager *pPager){
   */
   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;
@@ -1585,8 +1585,8 @@ static int sqlite3pager_opentemp(char *zFile, OsFile **pFd){
   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;
 }
@@ -1646,15 +1646,15 @@ int sqlite3pager_open(
     }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;
     }
@@ -2082,7 +2082,7 @@ int sqlite3pager_close(Pager *pPager){
   sqlite3OsClose(&pPager->fd);
   /* Temp files are automatically deleted by the OS
   ** if( pPager->tempFile ){
-  **   sqlite3Os.xDelete(pPager->zFilename);
+  **   sqlite3OsDelete(pPager->zFilename);
   ** }
   */
 
@@ -2352,10 +2352,10 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){
 */
 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;
@@ -2462,7 +2462,7 @@ int sqlite3pager_release_memory(int nReq){
 
   /* 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. 
   */
@@ -2613,7 +2613,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
        ** 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;
@@ -2843,7 +2843,7 @@ static int pager_open_journal(Pager *pPager){
     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;
@@ -2887,7 +2887,7 @@ failed_to_open_journal:
     ** 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;
index 413ac8b23d906d9a1fcb34dd22b89d2d9a1ef09f..a869657ae2f163ae3a4c2ba0a6e90da89e6d6773 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** 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"
@@ -396,7 +396,7 @@ void sqlite3Pragma(
         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;
       }
index 7f38ef0ec7c4a10e9af8e0abc5852677eda8aaad..cad6d166def01d1fb8cfde26549f68b57e85f952 100644 (file)
@@ -15,7 +15,7 @@
 ** 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"
@@ -63,7 +63,7 @@ static int randomByte(){
     char k[256];
     prng.j = 0;
     prng.i = 0;
-    sqlite3Os.xRandomSeed(k);
+    sqlite3OsRandomSeed(k);
     for(i=0; i<256; i++){
       prng.s[i] = i;
     }
@@ -92,9 +92,9 @@ static int randomByte(){
 */
 void sqlite3Randomness(int N, void *pBuf){
   unsigned char *zBuf = pBuf;
-  sqlite3Os.xEnterMutex();
+  sqlite3OsEnterMutex();
   while( N-- ){
     *(zBuf++) = randomByte();
   }
-  sqlite3Os.xLeaveMutex();
+  sqlite3OsLeaveMutex();
 }
index 53a195fa555d8fd8365493cdef29413b07e4785a..c4b22027c07e1e48ae8361a1a550e99c98a51995 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** 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 */
 
@@ -2151,7 +2151,6 @@ int TCLSH_MAIN(int argc, char **argv){
     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*);
 
@@ -2161,7 +2160,6 @@ int TCLSH_MAIN(int argc, char **argv){
     Sqlitetest4_Init(interp);
     Sqlitetest5_Init(interp);
     Sqlitetest6_Init(interp);
-    Sqlitetestasync_Init(interp);
     Md5_Init(interp);
 #ifdef SQLITE_SSE
     Sqlitetestsse_Init(interp);
index f960ef746c9336aca9668d6e57fd978955e3f998..a7e29fb374a983bddadf8599847d7daaabb1fe59 100644 (file)
@@ -13,7 +13,7 @@
 ** 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"
@@ -2599,7 +2599,7 @@ static int test_sqlite3OsOpenReadWrite(
     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;
@@ -2727,7 +2727,7 @@ static int test_sqlite3OsTempFileName(
   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;
@@ -3106,6 +3106,12 @@ static void set_options(Tcl_Interp *interp){
   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
index b7b1c487eec0d2a4a8b72cfcadbde82b5a9fa813..bb0cc18435bb9a498357e7eb827ac7037131e431 100644 (file)
@@ -13,7 +13,7 @@
 ** 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"
@@ -532,7 +532,7 @@ static int fake_big_file(
     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;
index d8f510ecc68b81e2ab97120e490c63d48248b037..95b5190b66d37bc8d675d77d340754b6f5545dcd 100644 (file)
 #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.
@@ -65,11 +60,11 @@ static char zCrashFile[500];
 ** 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();
 }
 
 /*
@@ -79,7 +74,7 @@ static void setCrashParams(int iDelay, char const *zFile){
 static int crashRequired(char const *zPath){
   int r;
   int n;
-  sqlite3Os.xEnterMutex();
+  sqlite3OsEnterMutex();
   n = strlen(zCrashFile);
   if( zCrashFile[n-1]=='*' ){
     n--;
@@ -93,7 +88,7 @@ static int crashRequired(char const *zPath){
       r = 1;
     }
   }
-  sqlite3Os.xLeaveMutex();
+  sqlite3OsLeaveMutex();
   return r;
 }
 
@@ -387,30 +382,47 @@ static int crashFileSize(OsFile *id, i64 *pSize){
   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);
   }
@@ -518,12 +530,7 @@ static int crashParamsObjCmd(
     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;
 }
 
diff --git a/src/test_async.c b/src/test_async.c
deleted file mode 100644 (file)
index e8d9ad1..0000000
+++ /dev/null
@@ -1,919 +0,0 @@
-/*
-** 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
index 82fe9ecf01dd895b687cac7fe97a20b6b91ad4c1..a37b68938ee6c6cd54e8f4e94ba6bc8f1ca3c17e 100644 (file)
@@ -14,7 +14,7 @@
 ** 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().
 **
@@ -154,7 +154,7 @@ const char *sqlite3_malloc_id = 0;
   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 \
@@ -214,7 +214,7 @@ static int failMalloc(){
 }
 
 /*
-** 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.
 */
@@ -240,7 +240,7 @@ static void checkGuards(u32 *p)
 }
 
 /*
-** 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.
 */
@@ -396,7 +396,7 @@ int sqlite3OutstandingMallocs(Tcl_Interp *interp){
     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;
 
@@ -431,7 +431,7 @@ int sqlite3OutstandingMallocs(Tcl_Interp *interp){
 #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
@@ -440,7 +440,7 @@ static void * OSMALLOC(int n){
 #endif
   if( !failMalloc() ){
     u32 *p;
-    p = (u32 *)sqlite3Os.xMalloc(n + TESTALLOC_OVERHEAD);
+    p = (u32 *)sqlite3OsMalloc(n + TESTALLOC_OVERHEAD);
     assert(p);
     sqlite3_nMalloc++;
     applyGuards(p);
@@ -451,19 +451,19 @@ static void * OSMALLOC(int n){
 }
 
 /*
-** 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
@@ -473,7 +473,7 @@ void * OSREALLOC(void *pRealloc, int n){
   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)]);
@@ -488,19 +488,19 @@ void OSMALLOC_FAILED(){
 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
@@ -510,7 +510,7 @@ int OSSIZEOF(void *p){
 
 /*
 ** 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
@@ -534,7 +534,7 @@ static void handleSoftLimit(int n){
 
 /*
 ** 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){
@@ -558,7 +558,7 @@ 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().
 */
@@ -1305,7 +1305,7 @@ void *sqlite3TextToPtr(const char *z){
 ** 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
index 4f8e3231881be2882c61a9b4443ba1241cb32a8e..5af673a48b162db5baee3d0fbec94be3dbd35203 100644 (file)
@@ -14,7 +14,7 @@
 ** 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"
@@ -148,7 +148,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   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
@@ -333,7 +333,7 @@ end_of_vacuum:
   }
 
   if( zTemp ){
-    sqlite3Os.xDelete(zTemp);
+    sqlite3OsDelete(zTemp);
     sqliteFree(zTemp);
   }
   sqliteFree( zSql );
index 0f27a520ba686181ee246bac64a741f11cd094cf..83615842cc6d437d3cc45dd5ac513285cae9a6c0 100644 (file)
@@ -43,7 +43,7 @@
 ** 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"
@@ -429,7 +429,7 @@ int sqlite3VdbeExec(
       }
       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
index b0a1c612a5f021e2ef61a805ca4bd7ba4720f5aa..9537ac66967794144fa6dad1dbb7193c34bff1fd 100644 (file)
@@ -193,7 +193,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){
     }
     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
@@ -230,7 +230,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){
     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 );
index f606647d0530aad94921e4541ce73954594d379e..5967533ddd72ea54b35ac41ad80a453bd322b9f2 100644 (file)
@@ -273,7 +273,7 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs, int *pMaxStack){
 
   /* 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 ){
@@ -759,7 +759,7 @@ void sqlite3VdbeMakeReady(
 
 #ifdef SQLITE_DEBUG
   if( (p->db->flags & SQLITE_VdbeListing)!=0
-    || sqlite3Os.xFileExists("vdbe_explain")
+    || sqlite3OsFileExists("vdbe_explain")
   ){
     int i;
     printf("VDBE Program Listing:\n");
@@ -768,7 +768,7 @@ void sqlite3VdbeMakeReady(
       sqlite3VdbePrintOp(stdout, i, &p->aOp[i]);
     }
   }
-  if( sqlite3Os.xFileExists("vdbe_trace") ){
+  if( sqlite3OsFileExists("vdbe_trace") ){
     p->trace = stdout;
   }
 #endif
@@ -982,10 +982,10 @@ static int vdbeCommit(sqlite3 *db){
       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;
@@ -1009,7 +1009,7 @@ static int vdbeCommit(sqlite3 *db){
         rc = sqlite3OsWrite(master, zFile, strlen(zFile)+1);
         if( rc!=SQLITE_OK ){
           sqlite3OsClose(&master);
-          sqlite3Os.xDelete(zMaster);
+          sqlite3OsDelete(zMaster);
           sqliteFree(zMaster);
           return rc;
         }
@@ -1025,7 +1025,7 @@ static int vdbeCommit(sqlite3 *db){
     if( rc!=SQLITE_OK ||
           (needSync && (rc=sqlite3OsSync(master,0))!=SQLITE_OK) ){
       sqlite3OsClose(&master);
-      sqlite3Os.xDelete(zMaster);
+      sqlite3OsDelete(zMaster);
       sqliteFree(zMaster);
       return rc;
     }
@@ -1057,11 +1057,11 @@ static int vdbeCommit(sqlite3 *db){
     ** 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
diff --git a/test/async.test b/test/async.test
deleted file mode 100644 (file)
index 43835bc..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#
-#    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
-
index 76ca0969ffd1d97bc7d1d1a0545075857b63f925..6ce9bc00513d8ee6ab0d31c09b8f6b7e48dbf57c 100644 (file)
 # 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
 
index e8aca20da37953bc758de50c9f2a1a9d9876ceb5..9184460697725ccefb9edaecc067dec00b87d059 100644 (file)
@@ -15,7 +15,7 @@
 # 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
@@ -133,28 +133,29 @@ do_ioerr_test ioerr-5 -sqlprep {
 
 # 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;
   }
 } 
 
index 31098310e8cb339b387c30922754ea8b1882c31b..1ca17850cb76173bc617d5c812614e7d931bf1a4 100644 (file)
@@ -14,7 +14,7 @@
 # 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
@@ -340,8 +340,8 @@ do_malloc_test 12 -tclbody {
 } 
 
 # 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;