1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Modifications to the malloc failure tests to test transient and persistent failures. (CVS 4321)

FossilOrigin-Name: e38ef81b85feb5bff2ad8448f3438ff0ab36571e
This commit is contained in:
danielk1977
2007-08-29 12:31:25 +00:00
parent 1fee73e74a
commit a1644fd863
40 changed files with 519 additions and 308 deletions

View File

@ -1,5 +1,5 @@
C Better\sasserts().\s\sBut\snow\ssome\sof\sthe\stests\sare\sbusted\sagain.\s(CVS\s4320) C Modifications\sto\sthe\smalloc\sfailure\stests\sto\stest\stransient\sand\spersistent\sfailures.\s(CVS\s4321)
D 2007-08-29T04:00:58 D 2007-08-29T12:31:26
F Makefile.in bfcc303429a5d9dcd552d807ee016c77427418c3 F Makefile.in bfcc303429a5d9dcd552d807ee016c77427418c3
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -81,29 +81,29 @@ F src/analyze.c a28b43a5f79bfa7616ab506bb917077242098469
F src/attach.c a52225c75b107be8c5bc144a2b6d20201be3f8f8 F src/attach.c a52225c75b107be8c5bc144a2b6d20201be3f8f8
F src/auth.c 083c1205b45e3f52291ec539d396b4fc557856b3 F src/auth.c 083c1205b45e3f52291ec539d396b4fc557856b3
F src/btmutex.c c04e67d99d949a12beb17209f307950f21313980 F src/btmutex.c c04e67d99d949a12beb17209f307950f21313980
F src/btree.c f9ea7d1e30d58cb1708aaa0c4c81a2761bd2bd13 F src/btree.c 7079a423e0da7eec5147d102202e2b51038002cd
F src/btree.h 7391b9e78ae441fe0fb3a6d3ae772770d35a4375 F src/btree.h 7391b9e78ae441fe0fb3a6d3ae772770d35a4375
F src/btreeInt.h 1fa6510aa8601dc0358a5240d191335236d3cf76 F src/btreeInt.h 1fa6510aa8601dc0358a5240d191335236d3cf76
F src/build.c 99b0b0c44ce7673c00d8c0c97ce536e3b796328b F src/build.c 915c4591ca7258b3144d53cd980bc3b4cc4a81e2
F src/callback.c a542236a68060caad378efa30006ca46cf77b1b2 F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131 F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
F src/date.c af235f38f50809abd0a96da3bb3e0cc32be6226e F src/date.c af235f38f50809abd0a96da3bb3e0cc32be6226e
F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1 F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 978afdceb2693ef58ec0040a43fe57afc6e4236c F src/expr.c 70660e0c5fc6375a03b3a7fc4eb6e66d96e5f6b1
F src/func.c aa8a3a8db571c46e5197664ddbc2784006ee5525 F src/func.c 4db632f1a81ed42a5a315136d3e90b7d8c76834c
F src/hash.c 2f322979071dd2bdba7503b5276d66f028744382 F src/hash.c 8fe2fa52bd17869c87748e42cff5b1e7fbf90822
F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e
F src/insert.c 633322aef1799f6604fa805e12488bc628570b0c F src/insert.c 633322aef1799f6604fa805e12488bc628570b0c
F src/journal.c 573911e274738b3fda813d4f0a6e319f8a9ecd36 F src/journal.c 573911e274738b3fda813d4f0a6e319f8a9ecd36
F src/legacy.c 7e1b1c57694e49cbadf561e2a7d9cd984dc743b5 F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35 F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c 8b31e2e0e961918fa045515459aee1c122d8c266 F src/loadext.c 8b31e2e0e961918fa045515459aee1c122d8c266
F src/main.c 58f71f9b0c583fbe74d13b6d3fdb509cac5871f3 F src/main.c 58f71f9b0c583fbe74d13b6d3fdb509cac5871f3
F src/malloc.c d4282f50964ab1ca31f504c97b7cf2fdb4d4195d F src/malloc.c baed31e12b774080a2ee4cb88fbc6a41e601f64a
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c afe2fbf6d7e8247c6c9f69c1481358b1cad60c08 F src/mem1.c afe2fbf6d7e8247c6c9f69c1481358b1cad60c08
F src/mem2.c 1a2ca756a285b5365d667841508cc1f98938b8d8 F src/mem2.c 2ba377e2f7d57ec36238456eb44371ac40aa0e94
F src/mutex.c 40e5ba09d56863895882a0204d93832e9960ea78 F src/mutex.c 40e5ba09d56863895882a0204d93832e9960ea78
F src/mutex.h 4d3babe3a691533ac980967d394da512140b5143 F src/mutex.h 4d3babe3a691533ac980967d394da512140b5143
F src/mutex_os2.c d47e9bd495583dd31263d8fe55160a31eb600a3c F src/mutex_os2.c d47e9bd495583dd31263d8fe55160a31eb600a3c
@ -120,30 +120,30 @@ F src/os_unix.c 89bf24aa2475048a7833c45c522e7c6a81b83bb8
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c 3ffd3aacff4cb69848284e29dcec0feff23b0752 F src/os_win.c 3ffd3aacff4cb69848284e29dcec0feff23b0752
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 97fd0bb853e01e6890ad9aae97e7f9155330ebdc F src/pager.c f9830adfd3752c860a4024da5b871df5af4ed8a4
F src/pager.h a9872db184613ae90ae80921f5fd956aa8f3522e F src/pager.h 1ac4468049348ec72df09d138fc1d7e3a9d0d3a6
F src/parse.y 2d2ce439dc6184621fb0b86f4fc5aca7f391a590 F src/parse.y 2d2ce439dc6184621fb0b86f4fc5aca7f391a590
F src/pragma.c 9b989506a1b7c8aecd6befb8235e2f57a4aba7e5 F src/pragma.c 9b989506a1b7c8aecd6befb8235e2f57a4aba7e5
F src/prepare.c 67df42078f348876edf6124aca2c615de5743d75 F src/prepare.c 1506fd279824b1f4bac97514966d0370101f9a6b
F src/printf.c 33d23a68e498006136ca9770579cf2d14a7ec68e F src/printf.c e8cb99691b8370d0b721e2618db0ad01550e9b98
F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da
F src/select.c 98c367bce3f38c5adfcc97de9ab5c79b0e5dc2b2 F src/select.c c8045b76f4c2ae95227de5997d1649e601181c76
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c ac29402b538515fa4697282387be9c1205e6e9eb F src/shell.c ac29402b538515fa4697282387be9c1205e6e9eb
F src/sqlite.h.in 679cfc7927f843cd30a7b7a0fa17173752939a36 F src/sqlite.h.in 1ef41c05bf64d580e77e6c57f8705cdf36f37be0
F src/sqlite3ext.h 9a26028378c288af500d8b94ed079666fed5806b F src/sqlite3ext.h 9a26028378c288af500d8b94ed079666fed5806b
F src/sqliteInt.h 8225c78e94177fa4f1052c4cf0f779838bf56c19 F src/sqliteInt.h 1dd9226a6f2f048222d5a5df38ab8cd26d8ece5d
F src/sqliteLimit.h 1bcbbdfa856f8b71b561abb31edb864b0eca1d12 F src/sqliteLimit.h 1bcbbdfa856f8b71b561abb31edb864b0eca1d12
F src/table.c c725e47f6f3092b9a7b569fc58e408e2173ee008 F src/table.c c725e47f6f3092b9a7b569fc58e408e2173ee008
F src/tclsqlite.c d76af53f45c9e9f7f7d39531fa4c7bee7d0adad6 F src/tclsqlite.c d76af53f45c9e9f7f7d39531fa4c7bee7d0adad6
F src/test1.c 8b20d1f05777ac480d3caf8d5f79ab7a543513fc F src/test1.c 8b20d1f05777ac480d3caf8d5f79ab7a543513fc
F src/test2.c 4f742e99ed1bea5c14692f627bdb59a146f30504 F src/test2.c 4ab230fbdc0decfa7422f6a052b609ba54f4dfac
F src/test3.c 637824fa560f9a4ffcec6b262febb0f57f400487 F src/test3.c de8f2a245d0adf4215487af8267c11ccca31e750
F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071 F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071
F src/test5.c 3a6a5717a149d7ca2e6d14f5be72cf7555d54dc4 F src/test5.c 3a6a5717a149d7ca2e6d14f5be72cf7555d54dc4
F src/test6.c a6223d9d938aba83f20611a2c01680d8043cd2f7 F src/test6.c a6223d9d938aba83f20611a2c01680d8043cd2f7
F src/test7.c a9d509d0e9ad214b4772696f49f6e61be26213d1 F src/test7.c a9d509d0e9ad214b4772696f49f6e61be26213d1
F src/test8.c a91b8d28341bbd168f5ba1ecad2be1008ddf15d1 F src/test8.c 88e033aefdf5d5522dff46655a14ea7360fb1d26
F src/test9.c b46c8fe02ac7cca1a7316436d8d38d50c66f4b2f F src/test9.c b46c8fe02ac7cca1a7316436d8d38d50c66f4b2f
F src/test_async.c f222bd196b55a2e73b1427400d5aa97841787167 F src/test_async.c f222bd196b55a2e73b1427400d5aa97841787167
F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436 F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
@ -151,7 +151,7 @@ F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c
F src/test_config.c f0b911bb615d93a192647e76910dce65cbbcf3ad F src/test_config.c f0b911bb615d93a192647e76910dce65cbbcf3ad
F src/test_hexio.c 82916f918687502658f02533b519c38cb180db6d F src/test_hexio.c 82916f918687502658f02533b519c38cb180db6d
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_malloc.c 5f5566bb799e72cb328df8933ef9fdb9d90d270e F src/test_malloc.c 9f26ba3469efc97f38100a899ca889d480778864
F src/test_md5.c 34599caee5b1c73dcf86ca31f55846fab8c19ef7 F src/test_md5.c 34599caee5b1c73dcf86ca31f55846fab8c19ef7
F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f
F src/test_server.c 319f6b1a99bab5f7149387442243d6e65a8ab4eb F src/test_server.c 319f6b1a99bab5f7149387442243d6e65a8ab4eb
@ -161,17 +161,17 @@ F src/trigger.c 724a77d54609a33bde90618934fbeddfcc729a10
F src/update.c e89b980b443d44b68bfc0b1746cdb6308e049ac9 F src/update.c e89b980b443d44b68bfc0b1746cdb6308e049ac9
F src/utf.c 4af6259d5906b5a1bf3035cc387c4d7907bdd56e F src/utf.c 4af6259d5906b5a1bf3035cc387c4d7907bdd56e
F src/util.c 3f9c0387b54f977726790f52ab92cd3d9379b367 F src/util.c 3f9c0387b54f977726790f52ab92cd3d9379b367
F src/vacuum.c 5ec133b69edf581a232af7e2b01f45c9f2b8be32 F src/vacuum.c 38745037c63246d1b0669038257890cf89fc4578
F src/vdbe.c f578e7f0905489ced1f05bc418dd51c0f79f9a04 F src/vdbe.c 9f2ef520614425016881234965b8146ac771d7dc
F src/vdbe.h 498e9ddade4baf70f2fc39e585670131dde07caa F src/vdbe.h 498e9ddade4baf70f2fc39e585670131dde07caa
F src/vdbeInt.h 630145b9bfaa19190ab491f52658a7db550f2247 F src/vdbeInt.h 630145b9bfaa19190ab491f52658a7db550f2247
F src/vdbeapi.c bdd0aea216744482dd1b7fab56de18ba5b6fbdf4 F src/vdbeapi.c 7737b6e07ea6547c6a83b2432832fe36309e2ce7
F src/vdbeaux.c 347d2c1d68f326c90c27660da86849c51134fe1d F src/vdbeaux.c 7cc1e0b33e4d5b8259fd12b7bd28c2180903146c
F src/vdbeblob.c d12ed95dac0992e1e372d079d76af047cc42f7c7 F src/vdbeblob.c d12ed95dac0992e1e372d079d76af047cc42f7c7
F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6 F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
F src/vdbemem.c 896fa3f8df9d2661eb15c7ce361857741b447268 F src/vdbemem.c de0f4df15900f274e8fe43753f59ab115255b788
F src/vtab.c 72e5347cca4d55e55e180015f4dc78736f852e14 F src/vtab.c 5b8d7ec77b9babba1b48072576bf30b43d543163
F src/where.c 2776a0caf8cbbfd6ec79cfb1cd9bc25074055e5e F src/where.c beade77e34619553fa425d52891b1b102f35c933
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/all.test 0b2117b4ccbb3dc88a5259d1735a04d20584b92b F test/all.test 0b2117b4ccbb3dc88a5259d1735a04d20584b92b
@ -212,9 +212,9 @@ F test/btree9.test 5d8711b241145b90f65dd1795d5dd8290846fa5e
F test/busy.test 0271c854738e23ad76e10d4096a698e5af29d211 F test/busy.test 0271c854738e23ad76e10d4096a698e5af29d211
F test/cache.test 3ff445c445742a7b6b9ba6e1d62a25263f9424b9 F test/cache.test 3ff445c445742a7b6b9ba6e1d62a25263f9424b9
F test/capi2.test 3c5066836cbaa9923bcc8282c010aa227bb5efd4 F test/capi2.test 3c5066836cbaa9923bcc8282c010aa227bb5efd4
F test/capi3.test e1b40aa127de9ecfcca707f359d68b993ef38b4c F test/capi3.test 6297cd1f8f2767f3d125e53dd39ce5ee9a8143ea
F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97 F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97
F test/capi3c.test 787ce050fd5e09e419c920f91c7f404e62e20cd8 F test/capi3c.test 9b324b73317d65d864c56c355a06a5b5cfbcd5a2
F test/cast.test c4780b58b569bab4947458195410ae8791ac216b F test/cast.test c4780b58b569bab4947458195410ae8791ac216b
F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184 F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184
F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04 F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04
@ -312,7 +312,7 @@ F test/icu.test e6bfae7f625c88fd14df6f540fe835bdfc1e4329
F test/in.test 369cb2aa1eab02296b4ec470732fe8c131260b1d F test/in.test 369cb2aa1eab02296b4ec470732fe8c131260b1d
F test/in2.test b1f447f4f0f67e9f83ff931e7e2e30873f9ea055 F test/in2.test b1f447f4f0f67e9f83ff931e7e2e30873f9ea055
F test/incrblob.test 7f95c929b719626443a996b105d2b0ff06f47818 F test/incrblob.test 7f95c929b719626443a996b105d2b0ff06f47818
F test/incrblob_err.test 9f88036c34bfd98d8b4990b25c7315c73094c4a4 F test/incrblob_err.test a25f71ad03eef61aa6b553dba5642c79b74e0e98
F test/incrvacuum.test 569347726ea5940c3359e3d8cabb3505595cb82f F test/incrvacuum.test 569347726ea5940c3359e3d8cabb3505595cb82f
F test/incrvacuum2.test 82397ceb5941cbe852fd29bb33fcdf5665bc80c2 F test/incrvacuum2.test 82397ceb5941cbe852fd29bb33fcdf5665bc80c2
F test/incrvacuum_ioerr.test cb331403b8dea3c5bae6163861ff25037b0df56a F test/incrvacuum_ioerr.test cb331403b8dea3c5bae6163861ff25037b0df56a
@ -345,19 +345,19 @@ F test/lock2.test 5f9557b775662c2a5ee435378f39e10d64f65cb3
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9 F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
F test/lock4.test 49e22396b9be6e047b3d35469f233be79153c9d5 F test/lock4.test 49e22396b9be6e047b3d35469f233be79153c9d5
F test/main.test e7212ce1023957c7209778cc87fa932bd79ba89a F test/main.test e7212ce1023957c7209778cc87fa932bd79ba89a
F test/malloc.test dbfaedfca734283182db18a64416cf037c33648f F test/malloc.test 52306f056e7359e68ed2e204f37f47a0e2020c57
F test/malloc2.test 96dfa6318d3b7bcd41d4fe7e24d35196d465bf58 F test/malloc2.test c1a74f46a3581b56df29ff46a4e1c99b41c44ad9
F test/malloc3.test 65d323508c7c4e1fb5569d03a11070b0259ad2fe F test/malloc3.test 95211d9b2394252cacf836c62fd3d405c58f73bd
F test/malloc4.test cf1e856fbc8ebde562838cb47adce0ebc2d4f7d2 F test/malloc4.test 18dace2c0013aa616abb17b71ebb29095dfce12d
F test/malloc5.test 9db9205a5d444e23043368f961f92641c7770199 F test/malloc5.test 9db9205a5d444e23043368f961f92641c7770199
F test/malloc6.test 3733b9bd4e039c3239f869c40edbb88172025e2e F test/malloc6.test 3733b9bd4e039c3239f869c40edbb88172025e2e
F test/malloc7.test dd66d8f82916becf1d29b6640e4f4855485570f8 F test/malloc7.test dd66d8f82916becf1d29b6640e4f4855485570f8
F test/malloc8.test 5ff95278bc73e815e295971afcdd175f6ba19258 F test/malloc8.test 5ff95278bc73e815e295971afcdd175f6ba19258
F test/malloc9.test fb99833476bc1a9b0b15573b9a56ae13af843ef9 F test/malloc9.test fb99833476bc1a9b0b15573b9a56ae13af843ef9
F test/mallocA.test f49b8df5e1d2a090830ef5a5f94174c3c930234b F test/mallocA.test bec59bb8c9837cea463d1e76e62d0ea5113c4292
F test/mallocB.test 56fd615f3fea97180132a89dd1dd2068852ef6a0 F test/mallocB.test 56fd615f3fea97180132a89dd1dd2068852ef6a0
F test/mallocC.test b6b83dea1c3820a70d50b0378481b71bda44bcb3 F test/mallocC.test 3c6385336c82c9c2249c6c28ed23f430e1d66bd3
F test/malloc_common.tcl b649c5fc558a137ddf4c69867c89e2e335b342ec F test/malloc_common.tcl 3c2fb94035e9085f8a687d724b6b61fdac8d961f
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8 F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893 F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217 F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217
@ -480,7 +480,7 @@ F test/vtab8.test e19fa4a538fcd1bb66c22825fa8f71618fb13583
F test/vtab9.test ea58d2b95d61955f87226381716b2d0b1d4e4f9b F test/vtab9.test ea58d2b95d61955f87226381716b2d0b1d4e4f9b
F test/vtabA.test 9cb6b1afead6fdd91bbdf1ca65c44ccfd9b10936 F test/vtabA.test 9cb6b1afead6fdd91bbdf1ca65c44ccfd9b10936
F test/vtab_alter.test 87617789086fd1767aa071e7805f1af7e1dac144 F test/vtab_alter.test 87617789086fd1767aa071e7805f1af7e1dac144
F test/vtab_err.test f63f4c96bcd403076d49393136fb4fd9e0c5b402 F test/vtab_err.test 71739e81853668857dd3bae05232c0dd6f5147cf
F test/vtab_shared.test d631d1f820c38c18939d53aab1fc35db5f0a8094 F test/vtab_shared.test d631d1f820c38c18939d53aab1fc35db5f0a8094
F test/where.test 1bcde8984c63747ac6d6bafcacd20fd6e8a223de F test/where.test 1bcde8984c63747ac6d6bafcacd20fd6e8a223de
F test/where2.test 3249d426b3fc7a106713d784e1628307fc308d2e F test/where2.test 3249d426b3fc7a106713d784e1628307fc308d2e
@ -567,7 +567,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 844d40b8379d3374130e2d94f6e32c2cda34e0ca P e8060f85e7871572e2a38dc96f03e6e1f34cc8fd
R cf2e80aed60a12c772fc5c9b86deea93 R 6d16792962565a302345db7d8e56e541
U drh U danielk1977
Z b6b3d6523c723ce59d75a6cacc6da8b8 Z 9b2b7f4f6f1c4dee7c46f90167d9dbc1

View File

@ -1 +1 @@
e8060f85e7871572e2a38dc96f03e6e1f34cc8fd e38ef81b85feb5bff2ad8448f3438ff0ab36571e

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** May you share freely, never taking more than you give.
** **
************************************************************************* *************************************************************************
** $Id: btree.c,v 1.416 2007/08/29 04:00:58 drh Exp $ ** $Id: btree.c,v 1.417 2007/08/29 12:31:26 danielk1977 Exp $
** **
** This file implements a external (disk-based) database using BTrees. ** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information. ** See the header comment on "btreeInt.h" for additional information.
@ -1212,7 +1212,8 @@ int sqlite3BtreeOpen(
pBt->pageSize = get2byte(&zDbHeader[16]); pBt->pageSize = get2byte(&zDbHeader[16]);
if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
|| ((pBt->pageSize-1)&pBt->pageSize)!=0 ){ || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
pBt->pageSize = sqlite3PagerSetPagesize(pBt->pPager, 0); pBt->pageSize = 0;
sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
pBt->maxEmbedFrac = 64; /* 25% */ pBt->maxEmbedFrac = 64; /* 25% */
pBt->minEmbedFrac = 32; /* 12.5% */ pBt->minEmbedFrac = 32; /* 12.5% */
pBt->minLeafFrac = 32; /* 12.5% */ pBt->minLeafFrac = 32; /* 12.5% */
@ -1242,7 +1243,7 @@ int sqlite3BtreeOpen(
} }
pBt->usableSize = pBt->pageSize - nReserve; pBt->usableSize = pBt->pageSize - nReserve;
assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */ assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */
sqlite3PagerSetPagesize(pBt->pPager, pBt->pageSize); sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO) #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
/* Add the new BtShared object to the linked list sharable BtShareds. /* Add the new BtShared object to the linked list sharable BtShareds.
@ -1488,6 +1489,7 @@ int sqlite3BtreeSyncDisabled(Btree *p){
** bytes per page is left unchanged. ** bytes per page is left unchanged.
*/ */
int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){
int rc = SQLITE_OK;
BtShared *pBt = p->pBt; BtShared *pBt = p->pBt;
sqlite3BtreeEnter(p); sqlite3BtreeEnter(p);
if( pBt->pageSizeFixed ){ if( pBt->pageSizeFixed ){
@ -1501,11 +1503,12 @@ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){
((pageSize-1)&pageSize)==0 ){ ((pageSize-1)&pageSize)==0 ){
assert( (pageSize & 7)==0 ); assert( (pageSize & 7)==0 );
assert( !pBt->pPage1 && !pBt->pCursor ); assert( !pBt->pPage1 && !pBt->pCursor );
pBt->pageSize = sqlite3PagerSetPagesize(pBt->pPager, pageSize); pBt->pageSize = pageSize;
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
} }
pBt->usableSize = pBt->pageSize - nReserve; pBt->usableSize = pBt->pageSize - nReserve;
sqlite3BtreeLeave(p); sqlite3BtreeLeave(p);
return SQLITE_OK; return rc;
} }
/* /*

View File

@ -22,7 +22,7 @@
** COMMIT ** COMMIT
** ROLLBACK ** ROLLBACK
** **
** $Id: build.c,v 1.440 2007/08/28 22:24:35 drh Exp $ ** $Id: build.c,v 1.441 2007/08/29 12:31:26 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@ -241,6 +241,7 @@ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
zSql = sqlite3VMPrintf(pParse->db, zFormat, ap); zSql = sqlite3VMPrintf(pParse->db, zFormat, ap);
va_end(ap); va_end(ap);
if( zSql==0 ){ if( zSql==0 ){
pParse->db->mallocFailed = 1;
return; /* A malloc must have failed */ return; /* A malloc must have failed */
} }
pParse->nested++; pParse->nested++;
@ -1562,9 +1563,13 @@ void sqlite3EndTable(
} }
#ifndef SQLITE_OMIT_FOREIGN_KEY #ifndef SQLITE_OMIT_FOREIGN_KEY
for(pFKey=p->pFKey; pFKey; pFKey=pFKey->pNextFrom){ for(pFKey=p->pFKey; pFKey; pFKey=pFKey->pNextFrom){
void *data;
int nTo = strlen(pFKey->zTo) + 1; int nTo = strlen(pFKey->zTo) + 1;
pFKey->pNextTo = sqlite3HashFind(&pSchema->aFKey, pFKey->zTo, nTo); pFKey->pNextTo = sqlite3HashFind(&pSchema->aFKey, pFKey->zTo, nTo);
sqlite3HashInsert(&pSchema->aFKey, pFKey->zTo, nTo, pFKey); data = sqlite3HashInsert(&pSchema->aFKey, pFKey->zTo, nTo, pFKey);
if( data==(void *)pFKey ){
db->mallocFailed = 1;
}
} }
#endif #endif
pParse->pNewTable = 0; pParse->pNewTable = 0;
@ -2383,7 +2388,10 @@ void sqlite3CreateIndex(
sqlite3_snprintf(sizeof(zBuf),zBuf,"_%d",n); sqlite3_snprintf(sizeof(zBuf),zBuf,"_%d",n);
zName = 0; zName = 0;
sqlite3SetString(&zName, "sqlite_autoindex_", pTab->zName, zBuf, (char*)0); sqlite3SetString(&zName, "sqlite_autoindex_", pTab->zName, zBuf, (char*)0);
if( zName==0 ) goto exit_create_index; if( zName==0 ){
db->mallocFailed = 1;
goto exit_create_index;
}
} }
/* Check for authorization to create an index. /* Check for authorization to create an index.

View File

@ -13,7 +13,7 @@
** This file contains functions used to access the internal hash tables ** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences. ** of user defined functions and collation sequences.
** **
** $Id: callback.c,v 1.22 2007/08/22 20:18:22 drh Exp $ ** $Id: callback.c,v 1.23 2007/08/29 12:31:26 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -363,9 +363,11 @@ Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
if( pBt ){ if( pBt ){
p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree); p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree);
}else{ }else{
p = (Schema *)sqlite3DbMallocZero(db,sizeof(Schema)); p = (Schema *)sqlite3MallocZero(sizeof(Schema));
} }
if( p && 0==p->file_format ){ if( !p ){
db->mallocFailed = 1;
}else if ( 0==p->file_format ){
sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0); sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&p->idxHash, SQLITE_HASH_STRING, 0); sqlite3HashInit(&p->idxHash, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&p->trigHash, SQLITE_HASH_STRING, 0); sqlite3HashInit(&p->trigHash, SQLITE_HASH_STRING, 0);

View File

@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and ** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite. ** for generating VDBE code that evaluates expressions in SQLite.
** **
** $Id: expr.c,v 1.308 2007/08/22 20:18:22 drh Exp $ ** $Id: expr.c,v 1.309 2007/08/29 12:31:26 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@ -221,13 +221,14 @@ static int codeCompare(
** is responsible for making sure the node eventually gets freed. ** is responsible for making sure the node eventually gets freed.
*/ */
Expr *sqlite3Expr( Expr *sqlite3Expr(
sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
int op, /* Expression opcode */ int op, /* Expression opcode */
Expr *pLeft, /* Left operand */ Expr *pLeft, /* Left operand */
Expr *pRight, /* Right operand */ Expr *pRight, /* Right operand */
const Token *pToken /* Argument token */ const Token *pToken /* Argument token */
){ ){
Expr *pNew; Expr *pNew;
pNew = sqlite3MallocZero( sizeof(Expr) ); pNew = sqlite3DbMallocZero(db, sizeof(Expr));
if( pNew==0 ){ if( pNew==0 ){
/* When malloc fails, delete pLeft and pRight. Expressions passed to /* When malloc fails, delete pLeft and pRight. Expressions passed to
** this function must always be allocated with sqlite3Expr() for this ** this function must always be allocated with sqlite3Expr() for this
@ -273,11 +274,7 @@ Expr *sqlite3PExpr(
Expr *pRight, /* Right operand */ Expr *pRight, /* Right operand */
const Token *pToken /* Argument token */ const Token *pToken /* Argument token */
){ ){
Expr *pNew = sqlite3Expr(op, pLeft, pRight, pToken); return sqlite3Expr(pParse->db, op, pLeft, pRight, pToken);
if( pNew==0 ){
pParse->db->mallocFailed = 1;
}
return pNew;
} }
/* /*
@ -297,12 +294,11 @@ Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){
int depth; int depth;
if( pParse->nested==0 ){ if( pParse->nested==0 ){
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken); sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken);
return sqlite3Expr(TK_NULL, 0, 0, 0); return sqlite3PExpr(pParse, TK_NULL, 0, 0, 0);
} }
if( v==0 ) return 0; if( v==0 ) return 0;
p = sqlite3Expr(TK_REGISTER, 0, 0, pToken); p = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, pToken);
if( p==0 ){ if( p==0 ){
pParse->db->mallocFailed = 1;
return 0; /* Malloc failed */ return 0; /* Malloc failed */
} }
depth = atoi((char*)&pToken->z[1]); depth = atoi((char*)&pToken->z[1]);
@ -322,7 +318,7 @@ Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
}else if( pRight==0 ){ }else if( pRight==0 ){
return pLeft; return pLeft;
}else{ }else{
Expr *p = sqlite3Expr(TK_AND, pLeft, pRight, 0); Expr *p = sqlite3Expr(db, TK_AND, pLeft, pRight, 0);
if( p==0 ){ if( p==0 ){
db->mallocFailed = 1; db->mallocFailed = 1;
} }
@ -1234,9 +1230,13 @@ static int lookupName(
}else{ }else{
z = sqlite3StrDup(zCol); z = sqlite3StrDup(zCol);
} }
if( z ){
sqlite3ErrorMsg(pParse, zErr, z); sqlite3ErrorMsg(pParse, zErr, z);
sqlite3_free(z); sqlite3_free(z);
pTopNC->nErr++; pTopNC->nErr++;
}else{
db->mallocFailed = 1;
}
} }
/* If a column from a table in pSrcList is referenced, then record /* If a column from a table in pSrcList is referenced, then record
@ -1668,7 +1668,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
VdbeComment((v, "# Init EXISTS result")); VdbeComment((v, "# Init EXISTS result"));
} }
sqlite3ExprDelete(pSel->pLimit); sqlite3ExprDelete(pSel->pLimit);
pSel->pLimit = sqlite3Expr(TK_INTEGER, 0, 0, &one); pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &one);
if( sqlite3Select(pParse, pSel, sop, iMem, 0, 0, 0, 0) ){ if( sqlite3Select(pParse, pSel, sop, iMem, 0, 0, 0, 0) ){
return; return;
} }

View File

@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope. ** All other code has file scope.
** **
** $Id: func.c,v 1.169 2007/08/23 02:47:53 drh Exp $ ** $Id: func.c,v 1.170 2007/08/29 12:31:26 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@ -234,6 +234,14 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
sqlite3_result_double(context, r); sqlite3_result_double(context, r);
} }
static void *contextMalloc(sqlite3_context *context, int nByte){
char *z = sqlite3_malloc(nByte);
if( !z && nByte>0 ){
sqlite3_result_error_nomem(context);
}
return z;
}
/* /*
** Implementation of the upper() and lower() SQL functions. ** Implementation of the upper() and lower() SQL functions.
*/ */
@ -247,7 +255,7 @@ static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
/* Verify that the call to _bytes() does not invalidate the _text() pointer */ /* Verify that the call to _bytes() does not invalidate the _text() pointer */
assert( z2==(char*)sqlite3_value_text(argv[0]) ); assert( z2==(char*)sqlite3_value_text(argv[0]) );
if( z2 ){ if( z2 ){
z1 = sqlite3_malloc(n+1); z1 = contextMalloc(context, n+1);
if( z1 ){ if( z1 ){
memcpy(z1, z2, n+1); memcpy(z1, z2, n+1);
for(i=0; z1[i]; i++){ for(i=0; z1[i]; i++){
@ -267,7 +275,7 @@ static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
/* Verify that the call to _bytes() does not invalidate the _text() pointer */ /* Verify that the call to _bytes() does not invalidate the _text() pointer */
assert( z2==(char*)sqlite3_value_text(argv[0]) ); assert( z2==(char*)sqlite3_value_text(argv[0]) );
if( z2 ){ if( z2 ){
z1 = sqlite3_malloc(n+1); z1 = contextMalloc(context, n+1);
if( z1 ){ if( z1 ){
memcpy(z1, z2, n+1); memcpy(z1, z2, n+1);
for(i=0; z1[i]; i++){ for(i=0; z1[i]; i++){
@ -332,7 +340,7 @@ static void randomBlob(
sqlite3_result_error_toobig(context); sqlite3_result_error_toobig(context);
return; return;
} }
p = sqlite3_malloc(n); p = contextMalloc(context, n);
if( p ){ if( p ){
sqlite3Randomness(n, p); sqlite3Randomness(n, p);
sqlite3_result_blob(context, (char*)p, n, sqlite3_free); sqlite3_result_blob(context, (char*)p, n, sqlite3_free);
@ -665,10 +673,8 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
sqlite3_result_error_toobig(context); sqlite3_result_error_toobig(context);
return; return;
} }
zText = (char *)sqlite3_malloc((2*nBlob)+4); zText = (char *)contextMalloc(context, (2*nBlob)+4);
if( !zText ){ if( zText ){
sqlite3_result_error(context, "out of memory", -1);
}else{
int i; int i;
for(i=0; i<nBlob; i++){ for(i=0; i<nBlob; i++){
zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F]; zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
@ -695,8 +701,8 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
sqlite3_result_error_toobig(context); sqlite3_result_error_toobig(context);
return; return;
} }
z = sqlite3_malloc( i+n+3 ); z = contextMalloc(context, i+n+3);
if( z==0 ) return; if( z ){
z[0] = '\''; z[0] = '\'';
for(i=0, j=1; zArg[i]; i++){ for(i=0, j=1; zArg[i]; i++){
z[j++] = zArg[i]; z[j++] = zArg[i];
@ -706,8 +712,8 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
} }
z[j++] = '\''; z[j++] = '\'';
z[j] = 0; z[j] = 0;
sqlite3_result_text(context, z, j, SQLITE_TRANSIENT); sqlite3_result_text(context, z, j, sqlite3_free);
sqlite3_free(z); }
} }
} }
} }
@ -732,8 +738,8 @@ static void hexFunc(
return; return;
} }
assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */ assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
z = zHex = sqlite3_malloc(n*2 + 1); z = zHex = contextMalloc(context, n*2 + 1);
if( zHex==0 ) return; if( zHex ){
for(i=0; i<n; i++, pBlob++){ for(i=0; i<n; i++, pBlob++){
unsigned char c = *pBlob; unsigned char c = *pBlob;
*(z++) = hexdigits[(c>>4)&0xf]; *(z++) = hexdigits[(c>>4)&0xf];
@ -742,6 +748,7 @@ static void hexFunc(
*z = 0; *z = 0;
sqlite3_result_text(context, zHex, n*2, sqlite3_free); sqlite3_result_text(context, zHex, n*2, sqlite3_free);
} }
}
/* /*
** The zeroblob(N) function returns a zero-filled blob of size N bytes. ** The zeroblob(N) function returns a zero-filled blob of size N bytes.
@ -798,7 +805,7 @@ static void replaceFunc(
assert( zRep==sqlite3_value_text(argv[2]) ); assert( zRep==sqlite3_value_text(argv[2]) );
nOut = nStr + 1; nOut = nStr + 1;
assert( nOut<SQLITE_MAX_LENGTH ); assert( nOut<SQLITE_MAX_LENGTH );
zOut = sqlite3_malloc((int)nOut); zOut = contextMalloc(context, (int)nOut);
if( zOut==0 ){ if( zOut==0 ){
return; return;
} }
@ -817,6 +824,7 @@ static void replaceFunc(
zOld = zOut; zOld = zOut;
zOut = sqlite3_realloc(zOut, (int)nOut); zOut = sqlite3_realloc(zOut, (int)nOut);
if( zOut==0 ){ if( zOut==0 ){
sqlite3_result_error_nomem(context);
sqlite3_free(zOld); sqlite3_free(zOld);
return; return;
} }
@ -873,7 +881,7 @@ static void trimFunc(
SQLITE_SKIP_UTF8(z); SQLITE_SKIP_UTF8(z);
} }
if( nChar>0 ){ if( nChar>0 ){
azChar = sqlite3_malloc( nChar*(sizeof(char*)+1) ); azChar = contextMalloc(context, nChar*(sizeof(char*)+1));
if( azChar==0 ){ if( azChar==0 ){
return; return;
} }
@ -1110,8 +1118,9 @@ static void test_auxdata(
sqlite3_value **argv sqlite3_value **argv
){ ){
int i; int i;
char *zRet = sqlite3MallocZero(nArg*2); char *zRet = contextMalloc(pCtx, nArg*2);
if( !zRet ) return; if( !zRet ) return;
memset(zRet, 0, nArg*2);
for(i=0; i<nArg; i++){ for(i=0; i<nArg; i++){
char const *z = (char*)sqlite3_value_text(argv[i]); char const *z = (char*)sqlite3_value_text(argv[i]);
if( z ){ if( z ){
@ -1125,9 +1134,12 @@ static void test_auxdata(
} }
}else{ }else{
zRet[i*2] = '0'; zRet[i*2] = '0';
zAux = sqlite3StrDup(z); zAux = contextMalloc(pCtx, strlen(z)+1);
if( zAux ){
strcpy(zAux, z);
sqlite3_set_auxdata(pCtx, i, zAux, free_test_auxdata); sqlite3_set_auxdata(pCtx, i, zAux, free_test_auxdata);
} }
}
zRet[i*2+1] = ' '; zRet[i*2+1] = ' ';
} }
} }

View File

@ -12,7 +12,7 @@
** This is the implementation of generic hash-tables ** This is the implementation of generic hash-tables
** used in SQLite. ** used in SQLite.
** **
** $Id: hash.c,v 1.21 2007/08/16 10:09:03 danielk1977 Exp $ ** $Id: hash.c,v 1.22 2007/08/29 12:31:26 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <assert.h> #include <assert.h>
@ -222,6 +222,14 @@ static void rehash(Hash *pH, int new_size){
int (*xHash)(const void*,int); /* The hash function */ int (*xHash)(const void*,int); /* The hash function */
assert( (new_size & (new_size-1))==0 ); assert( (new_size & (new_size-1))==0 );
/* There is a call to sqlite3_malloc() inside rehash(). If there is
** already an allocation at pH->ht, then if this malloc() fails it
** is benign (since failing to resize a hash table is a performance
** hit only, not a fatal error).
*/
sqlite3MallocBenignFailure(pH->htsize>0);
new_ht = (struct _ht *)sqlite3MallocZero( new_size*sizeof(struct _ht) ); new_ht = (struct _ht *)sqlite3MallocZero( new_size*sizeof(struct _ht) );
if( new_ht==0 ) return; if( new_ht==0 ) return;
if( pH->ht ) sqlite3_free(pH->ht); if( pH->ht ) sqlite3_free(pH->ht);

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be ** other files are for internal use by SQLite and should not be
** accessed by users of the library. ** accessed by users of the library.
** **
** $Id: legacy.c,v 1.21 2007/08/22 20:18:22 drh Exp $ ** $Id: legacy.c,v 1.22 2007/08/29 12:31:26 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -46,6 +46,8 @@ int sqlite3_exec(
int nCallback; int nCallback;
if( zSql==0 ) return SQLITE_OK; if( zSql==0 ) return SQLITE_OK;
sqlite3_mutex_enter(db->mutex);
while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){ while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){
int nCol; int nCol;
char **azVals = 0; char **azVals = 0;
@ -127,5 +129,6 @@ exec_out:
} }
assert( (rc&db->errMask)==rc ); assert( (rc&db->errMask)==rc );
sqlite3_mutex_leave(db->mutex);
return rc; return rc;
} }

View File

@ -12,7 +12,7 @@
** Memory allocation functions used throughout sqlite. ** Memory allocation functions used throughout sqlite.
** **
** **
** $Id: malloc.c,v 1.11 2007/08/24 03:51:34 drh Exp $ ** $Id: malloc.c,v 1.12 2007/08/29 12:31:26 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <stdarg.h> #include <stdarg.h>
@ -82,11 +82,9 @@ void *sqlite3MallocZero(unsigned n){
** the mallocFailed flag in the connection pointer. ** the mallocFailed flag in the connection pointer.
*/ */
void *sqlite3DbMallocZero(sqlite3 *db, unsigned n){ void *sqlite3DbMallocZero(sqlite3 *db, unsigned n){
void *p = sqlite3_malloc(n); void *p = sqlite3DbMallocRaw(db, n);
if( p ){ if( p ){
memset(p, 0, n); memset(p, 0, n);
}else if( db ){
db->mallocFailed = 1;
} }
return p; return p;
} }
@ -96,28 +94,40 @@ void *sqlite3DbMallocZero(sqlite3 *db, unsigned n){
** the mallocFailed flag in the connection pointer. ** the mallocFailed flag in the connection pointer.
*/ */
void *sqlite3DbMallocRaw(sqlite3 *db, unsigned n){ void *sqlite3DbMallocRaw(sqlite3 *db, unsigned n){
void *p = sqlite3_malloc(n); void *p = 0;
if( !db || db->mallocFailed==0 ){
p = sqlite3_malloc(n);
if( !p && db ){ if( !p && db ){
db->mallocFailed = 1; db->mallocFailed = 1;
} }
}
return p; return p;
} }
void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
void *pNew = 0;
if( db->mallocFailed==0 ){
pNew = sqlite3_realloc(p, n);
if( !pNew ){
db->mallocFailed = 1;
}
}
return pNew;
}
/* /*
** Attempt to reallocate p. If the reallocation fails, then free p ** Attempt to reallocate p. If the reallocation fails, then free p
** and set the mallocFailed flag in the database connection. ** and set the mallocFailed flag in the database connection.
*/ */
void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){ void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
void *pNew; void *pNew;
pNew = sqlite3_realloc(p, n); pNew = sqlite3DbRealloc(db, p, n);
if( !pNew ){ if( !pNew ){
sqlite3_free(p); sqlite3_free(p);
db->mallocFailed = 1;
} }
return pNew; return pNew;
} }
/* /*
** Make a copy of a string in memory obtained from sqliteMalloc(). These ** Make a copy of a string in memory obtained from sqliteMalloc(). These
** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This ** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This
@ -211,6 +221,11 @@ void sqlite3SetString(char **pz, ...){
** is set to SQLITE_NOMEM. ** is set to SQLITE_NOMEM.
*/ */
int sqlite3ApiExit(sqlite3* db, int rc){ int sqlite3ApiExit(sqlite3* db, int rc){
/* If the db handle is not NULL, then we must hold the connection handle
** mutex here. Otherwise the read (and possible write) of db->mallocFailed
** is unsafe, as is the call to sqlite3Error().
*/
assert( !db || sqlite3_mutex_held(db->mutex) );
if( db && db->mallocFailed ){ if( db && db->mallocFailed ){
sqlite3Error(db, SQLITE_NOMEM, 0); sqlite3Error(db, SQLITE_NOMEM, 0);
db->mallocFailed = 0; db->mallocFailed = 0;
@ -218,3 +233,4 @@ int sqlite3ApiExit(sqlite3* db, int rc){
} }
return rc & (db ? db->errMask : 0xff); return rc & (db ? db->errMask : 0xff);
} }

View File

@ -12,7 +12,7 @@
** This file contains the C functions that implement a memory ** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite. ** allocation subsystem for use by SQLite.
** **
** $Id: mem2.c,v 1.10 2007/08/24 04:15:00 drh Exp $ ** $Id: mem2.c,v 1.11 2007/08/29 12:31:26 danielk1977 Exp $
*/ */
/* /*
@ -139,6 +139,8 @@ static struct {
int iFail; /* Decrement and fail malloc when this is 1 */ int iFail; /* Decrement and fail malloc when this is 1 */
int iReset; /* When malloc fails set iiFail to this value */ int iReset; /* When malloc fails set iiFail to this value */
int iFailCnt; /* Number of failures */ int iFailCnt; /* Number of failures */
int iBenignFailCnt; /* Number of benign failures */
int iNextIsBenign; /* True if the next call to malloc may fail benignly */
/* /*
** sqlite3MallocDisallow() increments the following counter. ** sqlite3MallocDisallow() increments the following counter.
@ -247,6 +249,7 @@ static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){
*/ */
static void sqlite3MemsysFailed(void){ static void sqlite3MemsysFailed(void){
mem.iFailCnt = 0; mem.iFailCnt = 0;
mem.iBenignFailCnt = 0;
} }
/* /*
@ -261,6 +264,7 @@ void *sqlite3_malloc(int nByte){
int totalSize; int totalSize;
if( nByte<=0 ){ if( nByte<=0 ){
mem.iNextIsBenign = 0;
return 0; return 0;
} }
if( mem.mutex==0 ){ if( mem.mutex==0 ){
@ -282,6 +286,9 @@ void *sqlite3_malloc(int nByte){
sqlite3MemsysFailed(); /* A place to set a breakpoint */ sqlite3MemsysFailed(); /* A place to set a breakpoint */
} }
mem.iFailCnt++; mem.iFailCnt++;
if( mem.iNextIsBenign ){
mem.iBenignFailCnt++;
}
}else{ }else{
p = malloc(totalSize); p = malloc(totalSize);
mem.iFail--; mem.iFail--;
@ -329,6 +336,7 @@ void *sqlite3_malloc(int nByte){
p = (void*)pInt; p = (void*)pInt;
} }
sqlite3_mutex_leave(mem.mutex); sqlite3_mutex_leave(mem.mutex);
mem.iNextIsBenign = 0;
return p; return p;
} }
@ -475,16 +483,26 @@ void sqlite3_memdebug_dump(const char *zFilename){
** This routine returns the number of simulated failures that have ** This routine returns the number of simulated failures that have
** occurred since the previous call. ** occurred since the previous call.
*/ */
int sqlite3_memdebug_fail(int iFail, int iRepeat){ int sqlite3_memdebug_fail(int iFail, int iRepeat, int *piBenign){
int n = mem.iFailCnt; int n = mem.iFailCnt;
if( piBenign ){
*piBenign = mem.iBenignFailCnt;
}
mem.iFail = iFail+1; mem.iFail = iFail+1;
if( iRepeat>=0 ){ if( iRepeat>=0 ){
mem.iReset = iRepeat; mem.iReset = iRepeat;
} }
mem.iFailCnt = 0; mem.iFailCnt = 0;
mem.iBenignFailCnt = 0;
return n; return n;
} }
void sqlite3MallocBenignFailure(int isBenign){
if( isBenign ){
mem.iNextIsBenign = 1;
}
}
/* /*
** The following two routines are used to assert that no memory ** The following two routines are used to assert that no memory
** allocations occur between one call and the next. The use of ** allocations occur between one call and the next. The use of

View File

@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while ** file simultaneously, or one process from reading the database while
** another is writing. ** another is writing.
** **
** @(#) $Id: pager.c,v 1.379 2007/08/28 22:24:35 drh Exp $ ** @(#) $Id: pager.c,v 1.380 2007/08/29 12:31:27 danielk1977 Exp $
*/ */
#ifndef SQLITE_OMIT_DISKIO #ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h" #include "sqliteInt.h"
@ -699,6 +699,7 @@ static void pager_resize_hash_table(Pager *pPager, int N){
PgHdr **aHash, *pPg; PgHdr **aHash, *pPg;
assert( N>0 && (N&(N-1))==0 ); assert( N>0 && (N&(N-1))==0 );
pagerLeave(pPager); pagerLeave(pPager);
sqlite3MallocBenignFailure((int)pPager->aHash);
aHash = sqlite3MallocZero( sizeof(aHash[0])*N ); aHash = sqlite3MallocZero( sizeof(aHash[0])*N );
pagerEnter(pPager); pagerEnter(pPager);
if( aHash==0 ){ if( aHash==0 ){
@ -2266,22 +2267,32 @@ void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*,int)){
} }
/* /*
** Set the page size. Return the new size. If the suggest new page ** Set the page size to *pPageSize. If the suggest new page size is
** size is inappropriate, then an alternative page size is selected ** inappropriate, then an alternative page size is set to that
** and returned. ** value before returning.
*/ */
int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){ int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){
int rc = SQLITE_OK;
u16 pageSize = *pPageSize;
assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) ); assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) );
if( pageSize && !pPager->memDb && pPager->nRef==0 ){ if( pageSize && pageSize!=pPager->pageSize
&& !pPager->memDb && pPager->nRef==0
){
char *pNew = (char *)sqlite3_malloc(pageSize);
if( !pNew ){
rc = SQLITE_NOMEM;
}else{
pagerEnter(pPager); pagerEnter(pPager);
pager_reset(pPager); pager_reset(pPager);
pPager->pageSize = pageSize; pPager->pageSize = pageSize;
setSectorSize(pPager); setSectorSize(pPager);
pagerLeave(pPager);
sqlite3_free(pPager->pTmpSpace); sqlite3_free(pPager->pTmpSpace);
pPager->pTmpSpace = sqlite3_malloc(pageSize); pPager->pTmpSpace = pNew;
pagerLeave(pPager);
} }
return pPager->pageSize; }
*pPageSize = pPager->pageSize;
return rc;
} }
/* /*
@ -3276,7 +3287,7 @@ static int pagerSharedLock(Pager *pPager){
} }
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
pager_unlock(pPager); pager_unlock(pPager);
return SQLITE_BUSY; return (rc==SQLITE_NOMEM?rc:SQLITE_BUSY);
} }
pPager->journalOpen = 1; pPager->journalOpen = 1;
pPager->journalStarted = 0; pPager->journalStarted = 0;

View File

@ -13,7 +13,7 @@
** subsystem. The page cache subsystem reads and writes a file a page ** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback. ** at a time and provides a journal for rollback.
** **
** @(#) $Id: pager.h,v 1.63 2007/08/28 22:24:35 drh Exp $ ** @(#) $Id: pager.h,v 1.64 2007/08/29 12:31:27 danielk1977 Exp $
*/ */
#ifndef _PAGER_H_ #ifndef _PAGER_H_
@ -58,7 +58,7 @@ int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char *, int, int);
void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler); void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler);
void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int)); void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int));
void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int)); void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int));
int sqlite3PagerSetPagesize(Pager*, int); int sqlite3PagerSetPagesize(Pager*, u16*);
int sqlite3PagerMaxPageCount(Pager*, int); int sqlite3PagerMaxPageCount(Pager*, int);
int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
void sqlite3PagerSetCachesize(Pager*, int); void sqlite3PagerSetCachesize(Pager*, int);

View File

@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema ** interface, and routines that contribute to loading the database schema
** from disk. ** from disk.
** **
** $Id: prepare.c,v 1.59 2007/08/29 00:33:07 drh Exp $ ** $Id: prepare.c,v 1.60 2007/08/29 12:31:27 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@ -182,7 +182,8 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
rc = sqlite3InitCallback(&initData, 3, (char **)azArg, 0); rc = sqlite3InitCallback(&initData, 3, (char **)azArg, 0);
if( rc ){ if( rc ){
sqlite3SafetyOn(db); sqlite3SafetyOn(db);
return initData.rc; rc = initData.rc;
goto error_out;
} }
pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName); pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
if( pTab ){ if( pTab ){
@ -204,7 +205,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){ if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
sqlite3BtreeLeave(pDb->pBt); sqlite3BtreeLeave(pDb->pBt);
return rc; goto error_out;
} }
/* Get the database meta information. /* Get the database meta information.
@ -233,7 +234,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
sqlite3BtreeCloseCursor(curMain); sqlite3BtreeCloseCursor(curMain);
sqlite3BtreeLeave(pDb->pBt); sqlite3BtreeLeave(pDb->pBt);
return rc; goto error_out;
} }
}else{ }else{
memset(meta, 0, sizeof(meta)); memset(meta, 0, sizeof(meta));
@ -329,6 +330,11 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
rc = SQLITE_OK; rc = SQLITE_OK;
} }
sqlite3BtreeLeave(pDb->pBt); sqlite3BtreeLeave(pDb->pBt);
error_out:
if( rc==SQLITE_NOMEM ){
db->mallocFailed = 1;
}
return rc; return rc;
} }
@ -422,6 +428,9 @@ static int schemaIsValid(sqlite3 *db){
} }
sqlite3BtreeCloseCursor(curTemp); sqlite3BtreeCloseCursor(curTemp);
} }
if( rc==SQLITE_NOMEM ){
db->mallocFailed = 1;
}
} }
return allOk; return allOk;
} }

View File

@ -789,7 +789,9 @@ static char *base_vprintf(
memcpy(sM.zText, sM.zBase, sM.nChar+1); memcpy(sM.zText, sM.zBase, sM.nChar+1);
} }
}else if( sM.nAlloc>sM.nChar+10 ){ }else if( sM.nAlloc>sM.nChar+10 ){
char *zNew = xRealloc(sM.zText, sM.nChar+1); char *zNew;
sqlite3MallocBenignFailure(1);
zNew = xRealloc(sM.zText, sM.nChar+1);
if( zNew ){ if( zNew ){
sM.zText = zNew; sM.zText = zNew;
} }

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite. ** to handle SELECT statements in SQLite.
** **
** $Id: select.c,v 1.356 2007/08/16 10:09:03 danielk1977 Exp $ ** $Id: select.c,v 1.357 2007/08/29 12:31:27 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -60,7 +60,7 @@ Select *sqlite3SelectNew(
memset(pNew, 0, sizeof(*pNew)); memset(pNew, 0, sizeof(*pNew));
} }
if( pEList==0 ){ if( pEList==0 ){
pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(TK_ALL,0,0,0), 0); pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0,0,0), 0);
} }
pNew->pEList = pEList; pNew->pEList = pEList;
pNew->pSrc = pSrc; pNew->pSrc = pSrc;
@ -1364,12 +1364,12 @@ static int prepSelectStmt(Parse *pParse, Select *p){
continue; continue;
} }
} }
pRight = sqlite3Expr(TK_ID, 0, 0, 0); pRight = sqlite3PExpr(pParse, TK_ID, 0, 0, 0);
if( pRight==0 ) break; if( pRight==0 ) break;
setQuotedToken(pParse, &pRight->token, zName); setQuotedToken(pParse, &pRight->token, zName);
if( zTabName && (longNames || pTabList->nSrc>1) ){ if( zTabName && (longNames || pTabList->nSrc>1) ){
Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, 0); Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, 0);
pExpr = sqlite3Expr(TK_DOT, pLeft, pRight, 0); pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
if( pExpr==0 ) break; if( pExpr==0 ) break;
setQuotedToken(pParse, &pLeft->token, zTabName); setQuotedToken(pParse, &pLeft->token, zTabName);
setToken(&pExpr->span, setToken(&pExpr->span,

View File

@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as ** the version number) and changes its name to "sqlite3.h" as
** part of the build process. ** part of the build process.
** **
** @(#) $Id: sqlite.h.in,v 1.246 2007/08/28 15:47:45 drh Exp $ ** @(#) $Id: sqlite.h.in,v 1.247 2007/08/29 12:31:28 danielk1977 Exp $
*/ */
#ifndef _SQLITE3_H_ #ifndef _SQLITE3_H_
#define _SQLITE3_H_ #define _SQLITE3_H_
@ -2414,6 +2414,7 @@ void sqlite3_result_double(sqlite3_context*, double);
void sqlite3_result_error(sqlite3_context*, const char*, int); void sqlite3_result_error(sqlite3_context*, const char*, int);
void sqlite3_result_error16(sqlite3_context*, const void*, int); void sqlite3_result_error16(sqlite3_context*, const void*, int);
void sqlite3_result_error_toobig(sqlite3_context*); void sqlite3_result_error_toobig(sqlite3_context*);
void sqlite3_result_error_nomem(sqlite3_context*);
void sqlite3_result_int(sqlite3_context*, int); void sqlite3_result_int(sqlite3_context*, int);
void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
void sqlite3_result_null(sqlite3_context*); void sqlite3_result_null(sqlite3_context*);

View File

@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** Internal interface definitions for SQLite. ** Internal interface definitions for SQLite.
** **
** @(#) $Id: sqliteInt.h,v 1.604 2007/08/28 16:34:43 drh Exp $ ** @(#) $Id: sqliteInt.h,v 1.605 2007/08/29 12:31:28 danielk1977 Exp $
*/ */
#ifndef _SQLITEINT_H_ #ifndef _SQLITEINT_H_
#define _SQLITEINT_H_ #define _SQLITEINT_H_
@ -1542,6 +1542,7 @@ char *sqlite3StrNDup(const char*, int);
char *sqlite3DbStrDup(sqlite3*,const char*); char *sqlite3DbStrDup(sqlite3*,const char*);
char *sqlite3DbStrNDup(sqlite3*,const char*, int); char *sqlite3DbStrNDup(sqlite3*,const char*, int);
void *sqlite3DbReallocOrFree(sqlite3 *, void *, int); void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
void *sqlite3DbRealloc(sqlite3 *, void *, int);
char *sqlite3MPrintf(sqlite3*,const char*, ...); char *sqlite3MPrintf(sqlite3*,const char*, ...);
char *sqlite3VMPrintf(sqlite3*,const char*, va_list); char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
@ -1557,7 +1558,7 @@ void sqlite3DequoteExpr(sqlite3*, Expr*);
int sqlite3KeywordCode(const unsigned char*, int); int sqlite3KeywordCode(const unsigned char*, int);
int sqlite3RunParser(Parse*, const char*, char **); int sqlite3RunParser(Parse*, const char*, char **);
void sqlite3FinishCoding(Parse*); void sqlite3FinishCoding(Parse*);
Expr *sqlite3Expr(int, Expr*, Expr*, const Token*); Expr *sqlite3Expr(sqlite3*, int, Expr*, Expr*, const Token*);
Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
Expr *sqlite3RegisterExpr(Parse*,Token*); Expr *sqlite3RegisterExpr(Parse*,Token*);
Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
@ -1832,9 +1833,11 @@ void sqlite3Parser(void*, int, Token, Parse*);
#ifdef SQLITE_MEMDEBUG #ifdef SQLITE_MEMDEBUG
void sqlite3MallocDisallow(void); void sqlite3MallocDisallow(void);
void sqlite3MallocAllow(void); void sqlite3MallocAllow(void);
void sqlite3MallocBenignFailure(int);
#else #else
# define sqlite3MallocDisallow() # define sqlite3MallocDisallow()
# define sqlite3MallocAllow() # define sqlite3MallocAllow()
# define sqlite3MallocBenignFailure(x)
#endif #endif

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test2.c,v 1.50 2007/08/21 10:44:16 drh Exp $ ** $Id: test2.c,v 1.51 2007/08/29 12:31:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "tcl.h" #include "tcl.h"
@ -66,6 +66,7 @@ static int pager_open(
int argc, /* Number of arguments */ int argc, /* Number of arguments */
const char **argv /* Text of each argument */ const char **argv /* Text of each argument */
){ ){
u16 pageSize;
Pager *pPager; Pager *pPager;
int nPage; int nPage;
int rc; int rc;
@ -82,7 +83,8 @@ static int pager_open(
return TCL_ERROR; return TCL_ERROR;
} }
sqlite3PagerSetCachesize(pPager, nPage); sqlite3PagerSetCachesize(pPager, nPage);
sqlite3PagerSetPagesize(pPager, test_pagesize); pageSize = test_pagesize;
sqlite3PagerSetPagesize(pPager, &pageSize);
sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager); sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager);
Tcl_AppendResult(interp, zBuf, 0); Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK; return TCL_OK;

View File

@ -13,9 +13,10 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test3.c,v 1.82 2007/08/24 16:08:29 drh Exp $ ** $Id: test3.c,v 1.83 2007/08/29 12:31:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "btreeInt.h"
#include "tcl.h" #include "tcl.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -530,6 +531,7 @@ static int btree_pager_stats(
return TCL_ERROR; return TCL_ERROR;
} }
pBt = sqlite3TextToPtr(argv[1]); pBt = sqlite3TextToPtr(argv[1]);
sqlite3_mutex_enter(pBt->pSqlite->mutex);
sqlite3BtreeEnter(pBt); sqlite3BtreeEnter(pBt);
a = sqlite3PagerStats(sqlite3BtreePager(pBt)); a = sqlite3PagerStats(sqlite3BtreePager(pBt));
for(i=0; i<11; i++){ for(i=0; i<11; i++){
@ -543,6 +545,7 @@ static int btree_pager_stats(
Tcl_AppendElement(interp, zBuf); Tcl_AppendElement(interp, zBuf);
} }
sqlite3BtreeLeave(pBt); sqlite3BtreeLeave(pBt);
sqlite3_mutex_leave(pBt->pSqlite->mutex);
return TCL_OK; return TCL_OK;
} }
@ -1493,7 +1496,11 @@ static int btree_set_cache_size(
} }
pBt = sqlite3TextToPtr(argv[1]); pBt = sqlite3TextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR; if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
sqlite3_mutex_enter(pBt->pSqlite->mutex);
sqlite3BtreeSetCacheSize(pBt, nCache); sqlite3BtreeSetCacheSize(pBt, nCache);
sqlite3_mutex_leave(pBt->pSqlite->mutex);
return TCL_OK; return TCL_OK;
} }

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test8.c,v 1.54 2007/08/25 13:37:49 danielk1977 Exp $ ** $Id: test8.c,v 1.55 2007/08/29 12:31:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "tcl.h" #include "tcl.h"
@ -361,6 +361,7 @@ static int echoConstructor(
sqlite3_vtab **ppVtab, sqlite3_vtab **ppVtab,
char **pzErr char **pzErr
){ ){
int rc;
int i; int i;
echo_vtab *pVtab; echo_vtab *pVtab;
@ -404,9 +405,10 @@ static int echoConstructor(
** structure. If an error occurs, delete the sqlite3_vtab structure and ** structure. If an error occurs, delete the sqlite3_vtab structure and
** return an error code. ** return an error code.
*/ */
if( echoDeclareVtab(pVtab, db) ){ rc = echoDeclareVtab(pVtab, db);
if( rc!=SQLITE_OK ){
echoDestructor((sqlite3_vtab *)pVtab); echoDestructor((sqlite3_vtab *)pVtab);
return SQLITE_ERROR; return rc;
} }
/* Success. Set *ppVtab and return */ /* Success. Set *ppVtab and return */
@ -646,8 +648,15 @@ static int echoFilter(
** If the third argument, doFree, is true, then sqlite3_free() is ** If the third argument, doFree, is true, then sqlite3_free() is
** also called to free the buffer pointed to by zAppend. ** also called to free the buffer pointed to by zAppend.
*/ */
static void string_concat(char **pzStr, char *zAppend, int doFree){ static void string_concat(char **pzStr, char *zAppend, int doFree, int *pRc){
char *zIn = *pzStr; char *zIn = *pzStr;
if( !zAppend && doFree && *pRc==SQLITE_OK ){
*pRc = SQLITE_NOMEM;
}
if( *pRc!=SQLITE_OK ){
sqlite3_free(zIn);
zIn = 0;
}else{
if( zIn ){ if( zIn ){
char *zTemp = zIn; char *zTemp = zIn;
zIn = sqlite3_mprintf("%s%s", zIn, zAppend); zIn = sqlite3_mprintf("%s%s", zIn, zAppend);
@ -655,6 +664,10 @@ static void string_concat(char **pzStr, char *zAppend, int doFree){
}else{ }else{
zIn = sqlite3_mprintf("%s", zAppend); zIn = sqlite3_mprintf("%s", zAppend);
} }
if( !zIn ){
*pRc = SQLITE_NOMEM;
}
}
*pzStr = zIn; *pzStr = zIn;
if( doFree ){ if( doFree ){
sqlite3_free(zAppend); sqlite3_free(zAppend);
@ -709,6 +722,9 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
useCost = 1; useCost = 1;
} else { } else {
zQuery = sqlite3_mprintf("SELECT count(*) FROM %Q", pVtab->zTableName); zQuery = sqlite3_mprintf("SELECT count(*) FROM %Q", pVtab->zTableName);
if( !zQuery ){
return SQLITE_NOMEM;
}
rc = sqlite3_prepare(pVtab->db, zQuery, -1, &pStmt, 0); rc = sqlite3_prepare(pVtab->db, zQuery, -1, &pStmt, 0);
sqlite3_free(zQuery); sqlite3_free(zQuery);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
@ -723,6 +739,9 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
} }
zQuery = sqlite3_mprintf("SELECT rowid, * FROM %Q", pVtab->zTableName); zQuery = sqlite3_mprintf("SELECT rowid, * FROM %Q", pVtab->zTableName);
if( !zQuery ){
return SQLITE_NOMEM;
}
for(ii=0; ii<pIdxInfo->nConstraint; ii++){ for(ii=0; ii<pIdxInfo->nConstraint; ii++){
const struct sqlite3_index_constraint *pConstraint; const struct sqlite3_index_constraint *pConstraint;
struct sqlite3_index_constraint_usage *pUsage; struct sqlite3_index_constraint_usage *pUsage;
@ -759,7 +778,7 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
} else { } else {
zNew = sqlite3_mprintf(" %s %s %s ?", zSep, zCol, zOp); zNew = sqlite3_mprintf(" %s %s %s ?", zSep, zCol, zOp);
} }
string_concat(&zQuery, zNew, 1); string_concat(&zQuery, zNew, 1, &rc);
zSep = "AND"; zSep = "AND";
pUsage->argvIndex = ++nArg; pUsage->argvIndex = ++nArg;
@ -779,7 +798,7 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
zCol = "rowid"; zCol = "rowid";
} }
zNew = sqlite3_mprintf(" ORDER BY %s %s", zCol, zDir); zNew = sqlite3_mprintf(" ORDER BY %s %s", zCol, zDir);
string_concat(&zQuery, zNew, 1); string_concat(&zQuery, zNew, 1, &rc);
pIdxInfo->orderByConsumed = 1; pIdxInfo->orderByConsumed = 1;
} }
@ -787,7 +806,7 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
appendToEchoModule(pVtab->interp, zQuery); appendToEchoModule(pVtab->interp, zQuery);
if( !zQuery ){ if( !zQuery ){
return SQLITE_NOMEM; return rc;
} }
pIdxInfo->idxNum = hashString(zQuery); pIdxInfo->idxNum = hashString(zQuery);
pIdxInfo->idxStr = zQuery; pIdxInfo->idxStr = zQuery;
@ -843,26 +862,32 @@ int echoUpdate(
if( nData>1 && sqlite3_value_type(apData[0])==SQLITE_INTEGER ){ if( nData>1 && sqlite3_value_type(apData[0])==SQLITE_INTEGER ){
char *zSep = " SET"; char *zSep = " SET";
z = sqlite3_mprintf("UPDATE %Q", pVtab->zTableName); z = sqlite3_mprintf("UPDATE %Q", pVtab->zTableName);
if( !z ){
rc = SQLITE_NOMEM;
}
bindArgOne = (apData[1] && sqlite3_value_type(apData[1])==SQLITE_INTEGER); bindArgOne = (apData[1] && sqlite3_value_type(apData[1])==SQLITE_INTEGER);
bindArgZero = 1; bindArgZero = 1;
if( bindArgOne ){ if( bindArgOne ){
string_concat(&z, " SET rowid=?1 ", 0); string_concat(&z, " SET rowid=?1 ", 0, &rc);
zSep = ","; zSep = ",";
} }
for(i=2; i<nData; i++){ for(i=2; i<nData; i++){
if( apData[i]==0 ) continue; if( apData[i]==0 ) continue;
string_concat(&z, sqlite3_mprintf( string_concat(&z, sqlite3_mprintf(
"%s %Q=?%d", zSep, pVtab->aCol[i-2], i), 1); "%s %Q=?%d", zSep, pVtab->aCol[i-2], i), 1, &rc);
zSep = ","; zSep = ",";
} }
string_concat(&z, sqlite3_mprintf(" WHERE rowid=?%d", nData), 1); string_concat(&z, sqlite3_mprintf(" WHERE rowid=?%d", nData), 1, &rc);
} }
/* If apData[0] is an integer and nData==1 then do a DELETE */ /* If apData[0] is an integer and nData==1 then do a DELETE */
else if( nData==1 && sqlite3_value_type(apData[0])==SQLITE_INTEGER ){ else if( nData==1 && sqlite3_value_type(apData[0])==SQLITE_INTEGER ){
z = sqlite3_mprintf("DELETE FROM %Q WHERE rowid = ?1", pVtab->zTableName); z = sqlite3_mprintf("DELETE FROM %Q WHERE rowid = ?1", pVtab->zTableName);
if( !z ){
rc = SQLITE_NOMEM;
}
bindArgZero = 1; bindArgZero = 1;
} }
@ -873,24 +898,27 @@ int echoUpdate(
char *zValues = 0; char *zValues = 0;
zInsert = sqlite3_mprintf("INSERT INTO %Q (", pVtab->zTableName); zInsert = sqlite3_mprintf("INSERT INTO %Q (", pVtab->zTableName);
if( !zInsert ){
rc = SQLITE_NOMEM;
}
if( sqlite3_value_type(apData[1])==SQLITE_INTEGER ){ if( sqlite3_value_type(apData[1])==SQLITE_INTEGER ){
bindArgOne = 1; bindArgOne = 1;
zValues = sqlite3_mprintf("?"); zValues = sqlite3_mprintf("?");
string_concat(&zInsert, "rowid", 0); string_concat(&zInsert, "rowid", 0, &rc);
} }
assert((pVtab->nCol+2)==nData); assert((pVtab->nCol+2)==nData);
for(ii=2; ii<nData; ii++){ for(ii=2; ii<nData; ii++){
string_concat(&zInsert, string_concat(&zInsert,
sqlite3_mprintf("%s%Q", zValues?", ":"", pVtab->aCol[ii-2]), 1); sqlite3_mprintf("%s%Q", zValues?", ":"", pVtab->aCol[ii-2]), 1, &rc);
string_concat(&zValues, string_concat(&zValues,
sqlite3_mprintf("%s?%d", zValues?", ":"", ii), 1); sqlite3_mprintf("%s?%d", zValues?", ":"", ii), 1, &rc);
} }
string_concat(&z, zInsert, 1); string_concat(&z, zInsert, 1, &rc);
string_concat(&z, ") VALUES(", 0); string_concat(&z, ") VALUES(", 0, &rc);
string_concat(&z, zValues, 1); string_concat(&z, zValues, 1, &rc);
string_concat(&z, ")", 0); string_concat(&z, ")", 0, &rc);
} }
/* Anything else is an error */ /* Anything else is an error */
@ -899,7 +927,9 @@ int echoUpdate(
return SQLITE_ERROR; return SQLITE_ERROR;
} }
if( rc==SQLITE_OK ){
rc = sqlite3_prepare(db, z, -1, &pStmt, 0); rc = sqlite3_prepare(db, z, -1, &pStmt, 0);
}
assert( rc!=SQLITE_OK || pStmt ); assert( rc!=SQLITE_OK || pStmt );
sqlite3_free(z); sqlite3_free(z);
if( rc==SQLITE_OK ) { if( rc==SQLITE_OK ) {
@ -935,43 +965,50 @@ static int echoTransactionCall(sqlite3_vtab *tab, const char *zCall){
appendToEchoModule(pVtab->interp, zCall); appendToEchoModule(pVtab->interp, zCall);
appendToEchoModule(pVtab->interp, z); appendToEchoModule(pVtab->interp, z);
sqlite3_free(z); sqlite3_free(z);
return SQLITE_OK; return (z?SQLITE_OK:SQLITE_NOMEM);
} }
static int echoBegin(sqlite3_vtab *tab){ static int echoBegin(sqlite3_vtab *tab){
int rc;
echo_vtab *pVtab = (echo_vtab *)tab; echo_vtab *pVtab = (echo_vtab *)tab;
Tcl_Interp *interp = pVtab->interp; Tcl_Interp *interp = pVtab->interp;
const char *zVal; const char *zVal;
echoTransactionCall(tab, "xBegin"); rc = echoTransactionCall(tab, "xBegin");
if( rc==SQLITE_OK ){
/* Check if the $::echo_module_begin_fail variable is defined. If it is, /* Check if the $::echo_module_begin_fail variable is defined. If it is,
** and it is set to the name of the real table underlying this virtual ** and it is set to the name of the real table underlying this virtual
** echo module table, then cause this xSync operation to fail. ** echo module table, then cause this xSync operation to fail.
*/ */
zVal = Tcl_GetVar(interp, "echo_module_begin_fail", TCL_GLOBAL_ONLY); zVal = Tcl_GetVar(interp, "echo_module_begin_fail", TCL_GLOBAL_ONLY);
if( zVal && 0==strcmp(zVal, pVtab->zTableName) ){ if( zVal && 0==strcmp(zVal, pVtab->zTableName) ){
return SQLITE_ERROR; rc = SQLITE_ERROR;
} }
return SQLITE_OK; }
return rc;
} }
static int echoSync(sqlite3_vtab *tab){ static int echoSync(sqlite3_vtab *tab){
int rc;
echo_vtab *pVtab = (echo_vtab *)tab; echo_vtab *pVtab = (echo_vtab *)tab;
Tcl_Interp *interp = pVtab->interp; Tcl_Interp *interp = pVtab->interp;
const char *zVal; const char *zVal;
echoTransactionCall(tab, "xSync"); rc = echoTransactionCall(tab, "xSync");
if( rc==SQLITE_OK ){
/* Check if the $::echo_module_sync_fail variable is defined. If it is, /* Check if the $::echo_module_sync_fail variable is defined. If it is,
** and it is set to the name of the real table underlying this virtual ** and it is set to the name of the real table underlying this virtual
** echo module table, then cause this xSync operation to fail. ** echo module table, then cause this xSync operation to fail.
*/ */
zVal = Tcl_GetVar(interp, "echo_module_sync_fail", TCL_GLOBAL_ONLY); zVal = Tcl_GetVar(interp, "echo_module_sync_fail", TCL_GLOBAL_ONLY);
if( zVal && 0==strcmp(zVal, pVtab->zTableName) ){ if( zVal && 0==strcmp(zVal, pVtab->zTableName) ){
return -1; rc = -1;
} }
return SQLITE_OK; }
return rc;
} }
static int echoCommit(sqlite3_vtab *tab){ static int echoCommit(sqlite3_vtab *tab){
sqlite3MallocBenignFailure(1);
return echoTransactionCall(tab, "xCommit"); return echoTransactionCall(tab, "xCommit");
} }
static int echoRollback(sqlite3_vtab *tab){ static int echoRollback(sqlite3_vtab *tab){

View File

@ -13,7 +13,7 @@
** This file contains code used to implement test interfaces to the ** This file contains code used to implement test interfaces to the
** memory allocation subsystem. ** memory allocation subsystem.
** **
** $Id: test_malloc.c,v 1.5 2007/08/24 03:51:34 drh Exp $ ** $Id: test_malloc.c,v 1.6 2007/08/29 12:31:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "tcl.h" #include "tcl.h"
@ -245,7 +245,12 @@ static int test_memdebug_dump(
/* /*
** Usage: sqlite3_memdebug_fail COUNTER ?REPEAT? ** Usage: sqlite3_memdebug_fail COUNTER ?OPTIONS?
**
** where options are:
**
** -repeat <boolean>
** -benigncnt <varname>
** **
** Arrange for a simulated malloc() failure after COUNTER successes. ** Arrange for a simulated malloc() failure after COUNTER successes.
** If REPEAT is 1 then all subsequent malloc()s fail. If REPEAT is ** If REPEAT is 1 then all subsequent malloc()s fail. If REPEAT is
@ -263,23 +268,56 @@ static int test_memdebug_fail(
int objc, int objc,
Tcl_Obj *CONST objv[] Tcl_Obj *CONST objv[]
){ ){
int ii;
int iFail; int iFail;
int iRepeat; int iRepeat = -1;
int iBenignCnt;
Tcl_Obj *pBenignCnt = 0;
int nFail = 0; int nFail = 0;
if( objc!=3 && objc!=2 ){
Tcl_WrongNumArgs(interp, 1, objv, "COUNTER ?REPEAT?"); if( objc<2 ){
Tcl_WrongNumArgs(interp, 1, objv, "COUNTER ?OPTIONS?");
return TCL_ERROR; return TCL_ERROR;
} }
if( Tcl_GetIntFromObj(interp, objv[1], &iFail) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[1], &iFail) ) return TCL_ERROR;
if( objc==3 ){
if( Tcl_GetIntFromObj(interp, objv[2], &iRepeat) ) return TCL_ERROR; for(ii=2; ii<objc; ii+=2){
int nOption;
char *zOption = Tcl_GetStringFromObj(objv[ii], &nOption);
char *zErr = 0;
if( nOption>1 && strncmp(zOption, "-repeat", nOption)==0 ){
if( ii==(objc-1) ){
zErr = "option requires an argument: ";
}else{ }else{
iRepeat = -1; if( Tcl_GetIntFromObj(interp, objv[ii+1], &iRepeat) ){
return TCL_ERROR;
} }
}
}else if( nOption>1 && strncmp(zOption, "-benigncnt", nOption)==0 ){
if( ii==(objc-1) ){
zErr = "option requires an argument: ";
}else{
pBenignCnt = objv[ii+1];
}
}else{
zErr = "unknown option: ";
}
if( zErr ){
Tcl_AppendResult(interp, zErr, zOption, 0);
return TCL_ERROR;
}
}
#ifdef SQLITE_MEMDEBUG #ifdef SQLITE_MEMDEBUG
{ {
extern int sqlite3_memdebug_fail(int,int); extern int sqlite3_memdebug_fail(int,int,int*);
nFail = sqlite3_memdebug_fail(iFail, iRepeat); nFail = sqlite3_memdebug_fail(iFail, iRepeat, &iBenignCnt);
if( pBenignCnt ){
Tcl_ObjSetVar2(interp, pBenignCnt, 0, Tcl_NewIntObj(iBenignCnt), 0);
}
} }
#endif #endif
Tcl_SetObjResult(interp, Tcl_NewIntObj(nFail)); Tcl_SetObjResult(interp, Tcl_NewIntObj(nFail));

View File

@ -14,7 +14,7 @@
** Most of the code in this file may be omitted by defining the ** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro. ** SQLITE_OMIT_VACUUM macro.
** **
** $Id: vacuum.c,v 1.72 2007/08/24 11:43:37 drh Exp $ ** $Id: vacuum.c,v 1.73 2007/08/29 12:31:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "vdbeInt.h" #include "vdbeInt.h"
@ -25,6 +25,9 @@
*/ */
static int execSql(sqlite3 *db, const char *zSql){ static int execSql(sqlite3 *db, const char *zSql){
sqlite3_stmt *pStmt; sqlite3_stmt *pStmt;
if( !zSql ){
return SQLITE_NOMEM;
}
if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){ if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
return sqlite3_errcode(db); return sqlite3_errcode(db);
} }

View File

@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** commenting and indentation practices when changing or adding code.
** **
** $Id: vdbe.c,v 1.646 2007/08/28 23:28:08 drh Exp $ ** $Id: vdbe.c,v 1.647 2007/08/29 12:31:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@ -2637,7 +2637,8 @@ case OP_VerifyCookie: { /* no-push */
iMeta = 0; iMeta = 0;
} }
if( rc==SQLITE_OK && iMeta!=pOp->p2 ){ if( rc==SQLITE_OK && iMeta!=pOp->p2 ){
sqlite3SetString(&p->zErrMsg, "database schema has changed", (char*)0); sqlite3_free(p->zErrMsg);
p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
/* If the schema-cookie from the database file matches the cookie /* If the schema-cookie from the database file matches the cookie
** stored with the in-memory representation of the schema, do ** stored with the in-memory representation of the schema, do
** not reload the schema from the database file. ** not reload the schema from the database file.

View File

@ -234,6 +234,13 @@ void sqlite3_result_error_toobig(sqlite3_context *pCtx){
sqlite3VdbeMemSetZeroBlob(&pCtx->s, SQLITE_MAX_LENGTH+1); sqlite3VdbeMemSetZeroBlob(&pCtx->s, SQLITE_MAX_LENGTH+1);
} }
/* An SQLITE_NOMEM error. */
void sqlite3_result_error_nomem(sqlite3_context *pCtx){
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
sqlite3VdbeMemSetNull(&pCtx->s);
pCtx->isError = 1;
pCtx->s.db->mallocFailed = 1;
}
/* /*
** Execute the statement pStmt, either until a row of data is ready, the ** Execute the statement pStmt, either until a row of data is ready, the

View File

@ -115,15 +115,13 @@ static void resizeOpArray(Vdbe *p, int N){
VdbeOp *pNew; VdbeOp *pNew;
int nNew = N + 100*(!runMode); int nNew = N + 100*(!runMode);
int oldSize = p->nOpAlloc; int oldSize = p->nOpAlloc;
pNew = sqlite3_realloc(p->aOp, nNew*sizeof(Op)); pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
if( pNew ){ if( pNew ){
p->nOpAlloc = nNew; p->nOpAlloc = nNew;
p->aOp = pNew; p->aOp = pNew;
if( nNew>oldSize ){ if( nNew>oldSize ){
memset(&p->aOp[oldSize], 0, (nNew-oldSize)*sizeof(Op)); memset(&p->aOp[oldSize], 0, (nNew-oldSize)*sizeof(Op));
} }
}else{
p->db->mallocFailed = 1;
} }
} }
} }

View File

@ -260,9 +260,7 @@ int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
if( pMem->flags & MEM_Short ){ if( pMem->flags & MEM_Short ){
pMem->z = pMem->zShort; pMem->z = pMem->zShort;
} }
if( ctx.isError ){ rc = (ctx.isError?SQLITE_ERROR:SQLITE_OK);
rc = SQLITE_ERROR;
}
} }
return rc; return rc;
} }

View File

@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** This file contains code used to help implement virtual tables. ** This file contains code used to help implement virtual tables.
** **
** $Id: vtab.c,v 1.54 2007/08/24 03:51:34 drh Exp $ ** $Id: vtab.c,v 1.55 2007/08/29 12:31:29 danielk1977 Exp $
*/ */
#ifndef SQLITE_OMIT_VIRTUALTABLE #ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h" #include "sqliteInt.h"
@ -296,6 +296,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
int nName = strlen(zName) + 1; int nName = strlen(zName) + 1;
pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab); pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
if( pOld ){ if( pOld ){
db->mallocFailed = 1;
assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */ assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
return; return;
} }

View File

@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting ** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer". ** indices, you might also think of this module as the "query optimizer".
** **
** $Id: where.c,v 1.257 2007/08/16 11:36:15 danielk1977 Exp $ ** $Id: where.c,v 1.258 2007/08/29 12:31:29 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -791,7 +791,7 @@ static void exprAnalyze(
for(i=0; i<2; i++){ for(i=0; i<2; i++){
Expr *pNewExpr; Expr *pNewExpr;
int idxNew; int idxNew;
pNewExpr = sqlite3Expr(ops[i], sqlite3ExprDup(db, pExpr->pLeft), pNewExpr = sqlite3Expr(db, ops[i], sqlite3ExprDup(db, pExpr->pLeft),
sqlite3ExprDup(db, pList->a[i].pExpr), 0); sqlite3ExprDup(db, pList->a[i].pExpr), 0);
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
exprAnalyze(pSrc, pWC, idxNew); exprAnalyze(pSrc, pWC, idxNew);
@ -858,7 +858,7 @@ static void exprAnalyze(
} }
assert( pLeft!=0 ); assert( pLeft!=0 );
pDup = sqlite3ExprDup(db, pLeft); pDup = sqlite3ExprDup(db, pLeft);
pNew = sqlite3Expr(TK_IN, pDup, 0, 0); pNew = sqlite3Expr(db, TK_IN, pDup, 0, 0);
if( pNew ){ if( pNew ){
int idxNew; int idxNew;
transferJoinMarkings(pNew, pExpr); transferJoinMarkings(pNew, pExpr);
@ -934,7 +934,7 @@ or_not_possible:
prereqColumn = exprTableUsage(pMaskSet, pLeft); prereqColumn = exprTableUsage(pMaskSet, pLeft);
if( (prereqExpr & prereqColumn)==0 ){ if( (prereqExpr & prereqColumn)==0 ){
Expr *pNewExpr; Expr *pNewExpr;
pNewExpr = sqlite3Expr(TK_MATCH, 0, sqlite3ExprDup(db, pRight), 0); pNewExpr = sqlite3Expr(db, TK_MATCH, 0, sqlite3ExprDup(db, pRight), 0);
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
pNewTerm = &pWC->a[idxNew]; pNewTerm = &pWC->a[idxNew];
pNewTerm->prereqRight = prereqExpr; pNewTerm->prereqRight = prereqExpr;

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The # This file implements regression tests for SQLite library. The
# focus of this script testing the callback-free C/C++ API. # focus of this script testing the callback-free C/C++ API.
# #
# $Id: capi3.test,v 1.53 2007/08/25 13:37:49 danielk1977 Exp $ # $Id: capi3.test,v 1.54 2007/08/29 12:31:29 danielk1977 Exp $
# #
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
@ -754,7 +754,7 @@ if {[info command sqlite3_memdebug_fail]!=""} {
do_test capi3-10-1 { do_test capi3-10-1 {
sqlite3 db test.db sqlite3 db test.db
set DB [sqlite3_connection_pointer db] set DB [sqlite3_connection_pointer db]
sqlite3_memdebug_fail 0 0 sqlite3_memdebug_fail 0
catchsql { catchsql {
select * from sqlite_master; select * from sqlite_master;
} }
@ -768,7 +768,7 @@ if {[info command sqlite3_memdebug_fail]!=""} {
} {out of memory} } {out of memory}
} }
db close db close
sqlite3_memdebug_fail -1 0 sqlite3_memdebug_fail -1
} }
# The following tests - capi3-11.* - test that a COMMIT or ROLLBACK # The following tests - capi3-11.* - test that a COMMIT or ROLLBACK

View File

@ -13,7 +13,7 @@
# This is a copy of the capi3.test file that has been adapted to # This is a copy of the capi3.test file that has been adapted to
# test the new sqlite3_prepare_v2 interface. # test the new sqlite3_prepare_v2 interface.
# #
# $Id: capi3c.test,v 1.10 2007/08/25 13:37:49 danielk1977 Exp $ # $Id: capi3c.test,v 1.11 2007/08/29 12:31:29 danielk1977 Exp $
# #
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
@ -749,7 +749,7 @@ if {[info command sqlite3_memdebug_fail]!=""} {
do_test capi3c-10-1 { do_test capi3c-10-1 {
sqlite3 db test.db sqlite3 db test.db
set DB [sqlite3_connection_pointer db] set DB [sqlite3_connection_pointer db]
sqlite3_memdebug_fail 0 0 sqlite3_memdebug_fail 0
catchsql { catchsql {
select * from sqlite_master; select * from sqlite_master;
} }
@ -763,7 +763,7 @@ if {[info command sqlite3_memdebug_fail]!=""} {
} {out of memory} } {out of memory}
} }
db close db close
sqlite3_memdebug_fail -1 0 sqlite3_memdebug_fail -1
} }
# The following tests - capi3c-11.* - test that a COMMIT or ROLLBACK # The following tests - capi3c-11.* - test that a COMMIT or ROLLBACK

View File

@ -9,7 +9,7 @@
# #
#*********************************************************************** #***********************************************************************
# #
# $Id: incrblob_err.test,v 1.5 2007/08/27 23:48:24 drh Exp $ # $Id: incrblob_err.test,v 1.6 2007/08/29 12:31:29 danielk1977 Exp $
# #
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
@ -79,7 +79,7 @@ do_malloc_test 3 -tclprep {
error "out of memory" error "out of memory"
} }
} }
sqlite3_memdebug_fail -1 0 sqlite3_memdebug_fail -1
do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep { do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep {
CREATE TABLE blobs(k, v BLOB); CREATE TABLE blobs(k, v BLOB);

View File

@ -16,7 +16,7 @@
# to see what happens in the library if a malloc were to really fail # to see what happens in the library if a malloc were to really fail
# due to an out-of-memory situation. # due to an out-of-memory situation.
# #
# $Id: malloc.test,v 1.44 2007/08/22 20:18:22 drh Exp $ # $Id: malloc.test,v 1.45 2007/08/29 12:31:29 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -215,7 +215,8 @@ if {$::sqlite_options(utf16)} {
sqlite3_column_int $::STMT 0 sqlite3_column_int $::STMT 0
sqlite3_column_text16 $::STMT 1 sqlite3_column_text16 $::STMT 1
sqlite3_column_double $::STMT 1 sqlite3_column_double $::STMT 1
sqlite3_reset $::STMT set rc [sqlite3_reset $::STMT]
if {$rc eq "SQLITE_NOMEM"} {error "out of memory"}
sqlite3_bind_text16 $::STMT 1 $::bomstr 60 sqlite3_bind_text16 $::STMT 1 $::bomstr 60
#catch {sqlite3_finalize $::STMT} #catch {sqlite3_finalize $::STMT}
#if {[lindex [sqlite_malloc_stat] 2]<=0} { #if {[lindex [sqlite_malloc_stat] 2]<=0} {

View File

@ -16,7 +16,7 @@
# Recovery from malloc() failures is automatic. But we keep these # Recovery from malloc() failures is automatic. But we keep these
# tests around because you can never have too many test cases. # tests around because you can never have too many test cases.
# #
# $Id: malloc2.test,v 1.6 2007/08/22 22:04:37 drh Exp $ # $Id: malloc2.test,v 1.7 2007/08/29 12:31:29 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -65,7 +65,7 @@ proc do_malloc2_test {tn args} {
# Run the SQL. Malloc number $::n is set to fail. A malloc() failure # Run the SQL. Malloc number $::n is set to fail. A malloc() failure
# may or may not be reported. # may or may not be reported.
sqlite3_memdebug_fail $::n 1 sqlite3_memdebug_fail $::n -repeat 1
do_test malloc2-$tn.$::n.2 { do_test malloc2-$tn.$::n.2 {
set res [catchsql [string trim $::mallocopts(-sql)]] set res [catchsql [string trim $::mallocopts(-sql)]]
set rc [expr { set rc [expr {
@ -80,7 +80,7 @@ proc do_malloc2_test {tn args} {
# If $::n is greater than the number of malloc() calls required to # If $::n is greater than the number of malloc() calls required to
# execute the SQL, then this test is finished. Break out of the loop. # execute the SQL, then this test is finished. Break out of the loop.
set nFail [sqlite3_memdebug_fail -1 -1] set nFail [sqlite3_memdebug_fail -1]
if {$nFail==0} break if {$nFail==0} break
# Nothing should work now, because the allocator should refuse to # Nothing should work now, because the allocator should refuse to

View File

@ -13,7 +13,7 @@
# correctly. The emphasis of these tests are the _prepare(), _step() and # correctly. The emphasis of these tests are the _prepare(), _step() and
# _finalize() calls. # _finalize() calls.
# #
# $Id: malloc3.test,v 1.11 2007/08/22 22:04:37 drh Exp $ # $Id: malloc3.test,v 1.12 2007/08/29 12:31:29 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -560,7 +560,7 @@ proc run_test {arglist {pcstart 0} {iFailStart 1}} {
set ::rollback_hook_count 0 set ::rollback_hook_count 0
set ac [sqlite3_get_autocommit $::DB] ;# Auto-Commit set ac [sqlite3_get_autocommit $::DB] ;# Auto-Commit
sqlite3_memdebug_fail $iFail 1 sqlite3_memdebug_fail $iFail -repeat 1
set rc [catch {db eval [lindex $v 1]} msg] ;# True error occurs set rc [catch {db eval [lindex $v 1]} msg] ;# True error occurs
set nac [sqlite3_get_autocommit $::DB] ;# New Auto-Commit set nac [sqlite3_get_autocommit $::DB] ;# New Auto-Commit
@ -575,7 +575,7 @@ proc run_test {arglist {pcstart 0} {iFailStart 1}} {
} {1} } {1}
} }
set nFail [sqlite3_memdebug_fail -1 -1] set nFail [sqlite3_memdebug_fail -1]
if {$rc == 0} { if {$rc == 0} {
# Successful execution of sql. Our "mallocs-until-failure" # Successful execution of sql. Our "mallocs-until-failure"
# count should be greater than 0. Otherwise a malloc() failed # count should be greater than 0. Otherwise a malloc() failed
@ -639,7 +639,7 @@ db cache size 0
run_test $::run_test_script 9 1 run_test $::run_test_script 9 1
# run_test [lrange $::run_test_script 0 3] 0 63 # run_test [lrange $::run_test_script 0 3] 0 63
sqlite3_memdebug_fail -1 -1 sqlite3_memdebug_fail -1
db close db close
finish_test finish_test

View File

@ -12,7 +12,7 @@
# This file contains tests to ensure that the library handles malloc() failures # This file contains tests to ensure that the library handles malloc() failures
# correctly. The emphasis in this file is on sqlite3_column_XXX() APIs. # correctly. The emphasis in this file is on sqlite3_column_XXX() APIs.
# #
# $Id: malloc4.test,v 1.5 2007/08/23 02:47:53 drh Exp $ # $Id: malloc4.test,v 1.6 2007/08/29 12:31:29 danielk1977 Exp $
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# NOTES ON EXPECTED BEHAVIOUR # NOTES ON EXPECTED BEHAVIOUR
@ -51,7 +51,7 @@ proc do_stmt_test {id sql} {
} {1} } {1}
# Set the Nth malloc() to fail. # Set the Nth malloc() to fail.
sqlite3_memdebug_fail $n 1 sqlite3_memdebug_fail $n -repeat 1
# Test malloc failure in the _name(), _name16(), decltype() and # Test malloc failure in the _name(), _name16(), decltype() and
# decltype16() APIs. Calls that occur after the malloc() failure should # decltype16() APIs. Calls that occur after the malloc() failure should

View File

@ -10,7 +10,7 @@
#*********************************************************************** #***********************************************************************
# This file contains additional out-of-memory checks (see malloc.tcl). # This file contains additional out-of-memory checks (see malloc.tcl).
# #
# $Id: mallocA.test,v 1.3 2007/08/22 22:04:37 drh Exp $ # $Id: mallocA.test,v 1.4 2007/08/29 12:31:29 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -41,19 +41,19 @@ db close
file copy test.db test.db.bu file copy test.db test.db.bu
do_malloc_test 1 -testdb test.db.bu -sqlbody { do_malloc_test mallocA-1 -testdb test.db.bu -sqlbody {
ANALYZE ANALYZE
} }
do_malloc_test 2 -testdb test.db.bu -sqlbody { do_malloc_test mallocA-2 -testdb test.db.bu -sqlbody {
REINDEX; REINDEX;
} }
do_malloc_test 3 -testdb test.db.bu -sqlbody { do_malloc_test mallocA-3 -testdb test.db.bu -sqlbody {
REINDEX t1; REINDEX t1;
} }
do_malloc_test 4 -testdb test.db.bu -sqlbody { do_malloc_test mallocA-4 -testdb test.db.bu -sqlbody {
REINDEX main.t1; REINDEX main.t1;
} }
do_malloc_test 5 -testdb test.db.bu -sqlbody { do_malloc_test mallocA-5 -testdb test.db.bu -sqlbody {
REINDEX nocase; REINDEX nocase;
} }

View File

@ -12,7 +12,7 @@
# This file tests aspects of the malloc failure while parsing # This file tests aspects of the malloc failure while parsing
# CREATE TABLE statements in auto_vacuum mode. # CREATE TABLE statements in auto_vacuum mode.
# #
# $Id: mallocC.test,v 1.3 2007/08/22 22:04:37 drh Exp $ # $Id: mallocC.test,v 1.4 2007/08/29 12:31:29 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -61,7 +61,7 @@ proc do_mallocC_test {tn args} {
# Run the SQL. Malloc number $::n is set to fail. A malloc() failure # Run the SQL. Malloc number $::n is set to fail. A malloc() failure
# may or may not be reported. # may or may not be reported.
sqlite3_memdebug_fail $::n 1 sqlite3_memdebug_fail $::n -repeat 1
do_test mallocC-$tn.$::n.1 { do_test mallocC-$tn.$::n.1 {
set res [catchsql [string trim $::mallocopts(-sql)]] set res [catchsql [string trim $::mallocopts(-sql)]]
set rc [expr { set rc [expr {
@ -76,7 +76,7 @@ proc do_mallocC_test {tn args} {
# If $::n is greater than the number of malloc() calls required to # If $::n is greater than the number of malloc() calls required to
# execute the SQL, then this test is finished. Break out of the loop. # execute the SQL, then this test is finished. Break out of the loop.
set nFail [sqlite3_memdebug_fail -1 -1] set nFail [sqlite3_memdebug_fail -1]
if {$nFail==0} { if {$nFail==0} {
break break
} }

View File

@ -42,12 +42,23 @@ proc do_malloc_test {tn args} {
set start 1 set start 1
} }
foreach ::iRepeat {0 1} {
set ::go 1 set ::go 1
for {set ::n $start} {$::go && $::n < 50000} {incr ::n} { for {set ::n $start} {$::go && $::n < 50000} {incr ::n} {
do_test $tn.$::n {
# Remove all traces of database files test.db and test2.db from the files # If $::iRepeat is 0, then the malloc() failure is transient - it
# system. Then open (empty database) "test.db" with the handle [db]. # fails and then subsequent calls succeed. If $::iRepeat is 1,
# then the failure is persistent - once malloc() fails it keeps
# failing.
#
set zRepeat "transient"
if {$::iRepeat} {set zRepeat "persistent"}
do_test ${tn}.${zRepeat}.${::n} {
# Remove all traces of database files test.db and test2.db
# from the file-system. Then open (empty database) "test.db"
# with the handle [db].
# #
catch {db close} catch {db close}
catch {file delete -force test.db} catch {file delete -force test.db}
@ -68,10 +79,10 @@ proc do_malloc_test {tn args} {
execsql $::mallocopts(-sqlprep) execsql $::mallocopts(-sqlprep)
} }
# Now set the ${::n}th malloc() to fail and execute the -tclbody and # Now set the ${::n}th malloc() to fail and execute the -tclbody
# -sqlbody scripts. # and -sqlbody scripts.
# #
sqlite3_memdebug_fail $::n 1 sqlite3_memdebug_fail $::n -repeat $::iRepeat
set ::mallocbody {} set ::mallocbody {}
if {[info exists ::mallocopts(-tclbody)]} { if {[info exists ::mallocopts(-tclbody)]} {
append ::mallocbody "$::mallocopts(-tclbody)\n" append ::mallocbody "$::mallocopts(-tclbody)\n"
@ -79,19 +90,29 @@ proc do_malloc_test {tn args} {
if {[info exists ::mallocopts(-sqlbody)]} { if {[info exists ::mallocopts(-sqlbody)]} {
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}" append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
} }
set v [catch $::mallocbody msg]
set failFlag [sqlite3_memdebug_fail -1 0]
set go [expr {$failFlag>0}]
# The following block sets local variables as follows:
#
# isFail - True if an error (any error) was reported by sqlite.
# nFail - The total number of simulated malloc() failures.
# nBenign - The number of benign simulated malloc() failures.
#
set isFail [catch $::mallocbody msg]
set nFail [sqlite3_memdebug_fail -1 -benigncnt nBenign]
#puts "isFail=$isFail nFail=$nFail nBenign=$nBenign msg=$msg"
if {$failFlag==0} { # If one or more mallocs failed, run this loop body again.
if {$v} { #
set go [expr {$nFail>0}]
if {($nFail-$nBenign)==0} {
if {$isFail} {
set v2 $msg set v2 $msg
} else { } else {
set v 1 set isFail 1
set v2 1 set v2 1
} }
} elseif {!$v} { } elseif {!$isFail} {
set v2 $msg set v2 $msg
} elseif {[info command db]=="" || [db errorcode]==7 } elseif {[info command db]=="" || [db errorcode]==7
|| $msg=="out of memory"} { || $msg=="out of memory"} {
@ -99,12 +120,13 @@ proc do_malloc_test {tn args} {
} else { } else {
set v2 $msg set v2 $msg
} }
lappend v $v2 lappend isFail $v2
} {1 1} } {1 1}
if {[info exists ::mallocopts(-cleanup)]} { if {[info exists ::mallocopts(-cleanup)]} {
catch [list uplevel #0 $::mallocopts(-cleanup)] msg catch [list uplevel #0 $::mallocopts(-cleanup)] msg
} }
} }
}
unset ::mallocopts unset ::mallocopts
} }

View File

@ -9,7 +9,7 @@
# #
#*********************************************************************** #***********************************************************************
# #
# $Id: vtab_err.test,v 1.6 2007/08/25 13:37:49 danielk1977 Exp $ # $Id: vtab_err.test,v 1.7 2007/08/29 12:31:29 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -58,6 +58,6 @@ do_malloc_test vtab_err-2 -tclprep {
COMMIT; COMMIT;
} }
sqlite3_memdebug_fail -1 0 sqlite3_memdebug_fail -1
finish_test finish_test