]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Move error simulation code from the sqlite3_os_init() functions into a wrapper.
authordan <dan@noemail.net>
Mon, 17 Aug 2009 15:52:25 +0000 (15:52 +0000)
committerdan <dan@noemail.net>
Mon, 17 Aug 2009 15:52:25 +0000 (15:52 +0000)
FossilOrigin-Name: 67ad21abf88abb7a3e2eacddcaf1ab5d54149807

manifest
manifest.uuid
src/main.c
src/os.c
src/os.h
src/os_unix.c
src/os_win.c
src/test_init.c
test/init.test

index 244bcd7e4ccee58a5e0d3b1fcff3193458fb2b51..d286d7b9d027c2fc5f368c15e996227a74dda855 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C More\sdocumentation\sand\scomment\supdates\sfor\ssqlite3_initialize/shutdown\sinterface\schanges\sto\shandle\sfailures.
-D 2009-08-17T15:31:23
+C Move\serror\ssimulation\scode\sfrom\sthe\ssqlite3_os_init()\sfunctions\sinto\sa\swrapper.
+D 2009-08-17T15:52:26
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 0f7761c5d1c62ae7a841e3393ffaff1fa0f5c00a
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -126,7 +126,7 @@ F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0
 F src/legacy.c 303b4ffcf1ae652fcf5ef635846c563c254564f6
 F src/lempar.c 0c4d1ab0a5ef2b0381eb81a732c54f68f27a574d
 F src/loadext.c 0e88a335665db0b2fb4cece3e49dcb65d832635a
-F src/main.c cb283c9e98d50cb14b01d6b736c4336f7bf07189
+F src/main.c 1e87aa66fd43d4a11c9aa4ed1407d0894b359a52
 F src/malloc.c ae9fef00398ead775630cad97e228d527178eb3a
 F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
 F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270
@@ -141,12 +141,12 @@ F src/mutex_os2.c 6b5a74f812082a8483c3df05b47bbaac2424b9a0
 F src/mutex_unix.c aff26c77f698b552becfedfa677ad1036c42d790
 F src/mutex_w32.c b2c1481ee93b0ac7a8fa5346570fd173b6763fdb
 F src/notify.c 0127121816d8a861deb0dfd111b495346bf233db
-F src/os.c 5029ae6c88d1869ad9034008a9531658d53438e4
-F src/os.h fa3f4aa0119ff721a2da4b47ffd74406ac864c05
+F src/os.c 3855c23ceb2006795b29c78915ebf36717b06aad
+F src/os.h 00a1334a4eecee7f7bef79ac606b88d325119f21
 F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc
 F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5
-F src/os_unix.c aea2a5c1c07c47767b0961b670dc647aa4aefc4e
-F src/os_win.c a3e93d1b44a818ce9422e2e588984df1cb7e4819
+F src/os_unix.c 6895098a9e7bd5630fab59060da6397bebcf2ff9
+F src/os_win.c 58bb163f327e79726dd119344d908e4d98483c3f
 F src/pager.c a47be286477ed6c7b9a342dd53d4e4043f29d8c2
 F src/pager.h 11852d044c86cf5a9d6e34171fb0c4fcf1f6265f
 F src/parse.y 6c42631e72a3d14cde2bee85e79409066066d3df
@@ -185,7 +185,7 @@ F src/test_config.c 63d1b08809ca182ee75429573111b44735861c64
 F src/test_devsym.c 9f4bc2551e267ce7aeda195f3897d0f30c5228f4
 F src/test_func.c 26ac62d8ed7a9f45a1e05baffb1c1e55fe2a06f2
 F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
-F src/test_init.c ff7c0e055fb786f5b048df83b6dfb1624851a88b
+F src/test_init.c f6a5dfaf2fb52d697eec1c825a641e5893c339d2
 F src/test_journal.c dab49b7c47b53242f039c9563b18cafb67ebfe03
 F src/test_loadext.c 97dc8800e46a46ed002c2968572656f37e9c0dd9
 F src/test_malloc.c d054506b095d711e4e5575558dd576a2cbf035a2
@@ -409,7 +409,7 @@ F test/index.test cbf301cdb2da43e4eac636c3400c2439af1834ad
 F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
 F test/index3.test 727d55dceb9a4ec36675057bb5becfc265e28ca6
 F test/indexedby.test 946ca2628a521f4ced0520421a0788345abaf3dc
-F test/init.test 5768d2cfeb25df627d42de675ab6201a65c167fe
+F test/init.test 3f9e97948cf2335c08a5e3edc3df3a26cdaa76f2
 F test/insert.test aef273dd1cee84cc92407469e6bd1b3cdcb76908
 F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435
 F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30
@@ -746,7 +746,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
-P 904a371c6c9d3f20332b37767b06161fa0a78113
-R a9ed6e4e5323f07f7cab487d83cce5a4
-U shane
-Z f4248855d1755b89d2ad5c1a3e7e2a1a
+P 32509bc7339cd6a46cea4c243e3418546860cb2d
+R ee9f9682e4e218a87239394324f62b18
+U dan
+Z 435403f17ee49c9f5cf99c3836460b04
index eecbf63cfaac8a32f11e6e47bd1e22132cfbf37e..eb7ae681b9cf2d7cbb968db7b8a35db43a462bb8 100644 (file)
@@ -1 +1 @@
-32509bc7339cd6a46cea4c243e3418546860cb2d
\ No newline at end of file
+67ad21abf88abb7a3e2eacddcaf1ab5d54149807
\ No newline at end of file
index fe26386a0bfd9655fbea5dc0a4d7b4d2da78a913..54eae54a7f23730b9da5b5c6eb5a1c6faf0a02b0 100644 (file)
@@ -167,7 +167,7 @@ int sqlite3_initialize(void){
     }
     if( rc==SQLITE_OK ){
       sqlite3GlobalConfig.isPCacheInit = 1;
-      rc = sqlite3_os_init();
+      rc = sqlite3OsInit();
     }
     if( rc==SQLITE_OK ){
       sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, 
index a2b0325c6af0010a72bae0a828b189a4fc82cbb5..4adf1239678593b4694904b2ee0bb1db1fa304c2 100644 (file)
--- a/src/os.c
+++ b/src/os.c
@@ -190,6 +190,17 @@ int sqlite3OsCloseFree(sqlite3_file *pFile){
   return rc;
 }
 
+/*
+** This function is a wrapper around the OS specific implementation of
+** sqlite3_os_init(). The purpose of the wrapper is to provide the
+** ability to simulate a malloc failure, so that the handling of an
+** error in sqlite3_os_init() by the upper layers can be tested.
+*/
+int sqlite3OsInit(void){
+  DO_OS_MALLOC_TEST(0);
+  return sqlite3_os_init();
+}
+
 /*
 ** The list of all registered VFS implementations.
 */
index d483f3f52141e7680e9274cc91716a423b8bab27..7bc848f1275247972307f2f79902aeeedfd5ff23 100644 (file)
--- a/src/os.h
+++ b/src/os.h
 #define SHARED_FIRST      (PENDING_BYTE+2)
 #define SHARED_SIZE       510
 
+/*
+** Wrapper around OS specific sqlite3_os_init() function.
+*/
+int sqlite3OsInit(void);
+
 /* 
 ** Functions for accessing sqlite3_file methods 
 */
index 00bbb538c236fb293174e4f1ad553c536523ef17..cfaf2a2bdab5b1b6e266acc3e75553d441071b27 100644 (file)
@@ -5126,13 +5126,6 @@ int sqlite3_os_init(void){
   };
   unsigned int i;          /* Loop counter */
 
-#ifdef SQLITE_TEST
-  /* This block is used by test code only to simulate the effect on sqlite
-  ** of returning an error from within the sqlite3_os_init() function.  */
-  int sqlite3TestFailOsInit(void);
-  if( sqlite3TestFailOsInit() ){ return SQLITE_ERROR; }
-#endif
-
   /* Register all VFSes defined in the aVfs[] array */
   for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
     sqlite3_vfs_register(&aVfs[i], i==0);
index 220b123c8fb77c14310e8a1ebbfb027388e86898..5d8463728020f8bc496c442d4b1c796d42275966 100644 (file)
@@ -1883,13 +1883,6 @@ int sqlite3_os_init(void){
     winGetLastError    /* xGetLastError */
   };
 
-#ifdef SQLITE_TEST
-  /* This block is used by test code only to simulate the effect on sqlite
-  ** of returning an error from within the sqlite3_os_init() function.  */
-  int sqlite3TestFailOsInit(void);
-  if( sqlite3TestFailOsInit() ){ return SQLITE_ERROR; }
-#endif
-
   sqlite3_vfs_register(&winVfs, 1);
   return SQLITE_OK; 
 }
index a8b8ce0d50fe31b8c54769348829c17a9546a4f8..c5be6376bd649475e61ac51bbab45f8786efd9ca 100644 (file)
@@ -40,7 +40,6 @@ static struct Wrapped {
   int mutex_fail;              /* True to fail mutex subsystem inialization */
   int pcache_init;             /* True if pcache subsystem is initalized */
   int pcache_fail;             /* True to fail pcache subsystem inialization */
-  int osinit_fail;             /* True to fail OS subsystem inialization */
 } wrapped;
 
 static int wrMemInit(void *pAppData){
@@ -196,8 +195,6 @@ static int init_wrapper_install(
       wrapped.mutex_fail = 1;
     }else if( strcmp(z, "pcache")==0 ){
       wrapped.pcache_fail = 1;
-    }else if( strcmp(z, "os")==0 ){
-      wrapped.osinit_fail = 1;
     }else{
       Tcl_AppendResult(interp, "Unknown argument: \"", z, "\"");
       return TCL_ERROR;
@@ -239,7 +236,6 @@ static int init_wrapper_clear(
   wrapped.mem_fail = 0;
   wrapped.mutex_fail = 0;
   wrapped.pcache_fail = 0;
-  wrapped.osinit_fail = 0;
   return TCL_OK;
 }
 
@@ -266,18 +262,11 @@ static int init_wrapper_query(
   if( wrapped.pcache_init ){
     Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("pcache", -1));
   }
-  if( sqlite3GlobalConfig.isInit ){
-    Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("os", -1));
-  }
 
   Tcl_SetObjResult(interp, pRet);
   return TCL_OK;
 }
 
-int sqlite3TestFailOsInit(void){
-  return (wrapped.mem.xMalloc && wrapped.osinit_fail);
-}
-
 int Sqlitetest_init_Init(Tcl_Interp *interp){
   static struct {
      char *zName;
index b68ebbcbafbb8d2e39fdc72d5b288592adbb6f35..efd6b4ce78a6eefffdd1190431a96383462d4920 100644 (file)
@@ -9,6 +9,11 @@
 #
 #***********************************************************************
 #
+# This file implements regression tests for SQLite library.  The
+# focus of this file is testing the effects of a failure in 
+# sqlite3_initialize().
+#
+#
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -16,11 +21,10 @@ source $testdir/tester.tcl
 db close
 
 foreach {t failed rc started} {
-  1.1 {}       SQLITE_OK    {mutex mem pcache os}
+  1.1 {}       SQLITE_OK    {mutex mem pcache}
   1.2 {mutex}  SQLITE_ERROR {}
   1.3 {mem}    SQLITE_ERROR {mutex}
   1.4 {pcache} SQLITE_ERROR {mutex mem}
-  1.5 {os}     SQLITE_ERROR {mutex mem pcache}
 } {
   do_test init-$t.1 {
     eval init_wrapper_install $failed
@@ -45,12 +49,31 @@ foreach {t failed rc started} {
   } SQLITE_OK
   do_test init-$t.7 {
     init_wrapper_query
-  } {mutex mem pcache os}
+  } {mutex mem pcache}
   do_test init-$t.8 {
     init_wrapper_uninstall
   } {}
 }
 
+source $testdir/malloc_common.tcl
+if {$MEMDEBUG} {
+  do_malloc_test init-2 -tclprep {
+    db close
+    init_wrapper_install
+  } -tclbody {
+    set rc [sqlite3_initialize]
+    if {[string match "SQLITE*NOMEM" $rc]} {error "out of memory"}
+  } -cleanup {
+    set zRepeat "transient"
+    if {$::iRepeat} {set zRepeat "persistent"}
+    do_test init-2.$zRepeat.$::n.x {
+      init_wrapper_clear
+      sqlite3_initialize
+    } SQLITE_OK
+    init_wrapper_uninstall
+  }
+}
+
 autoinstall_test_functions
 finish_test