From f1da17a3889a7023af6ebb0a10192b0bced6db74 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Tue, 21 Aug 2007 13:07:46 +0000 Subject: [PATCH] Fix some problems in the crash-test backend. (CVS 4256) FossilOrigin-Name: 5bced2392ad77aff0aa1ddea83f2ff9e3ffe28a8 --- manifest | 16 +++--- manifest.uuid | 2 +- src/os.c | 2 + src/test6.c | 148 ++++++++++++++++++++++++++++++++++---------------- 4 files changed, 111 insertions(+), 57 deletions(-) diff --git a/manifest b/manifest index 6d0174590d..9015d079db 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunnecessary\s#includes\sof\s"os.h".\s\sNew\smutex\simplementations.\s(CVS\s4255) -D 2007-08-21T10:44:16 +C Fix\ssome\sproblems\sin\sthe\scrash-test\sbackend.\s(CVS\s4256) +D 2007-08-21T13:07:47 F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -103,7 +103,7 @@ F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/mem1.c 30bf8be3846f92fdf88c490c5e5378512383bcbe F src/mem2.c 482f0aaf14e8ef1db64cb8c5b9a9bfe708297c92 F src/mutex.c 56bd91271f18300aa7da45608bd8956abe471d10 -F src/os.c dfe4718104a795c4a5e4cd927b6b00c24c004c58 +F src/os.c 89b93d67bc436c2d9df4b5d296f30a59144e55bb F src/os.h 399c89cafa93b9ef35c3dc70f77644d10936b535 F src/os_common.h a5c446d3b93f09f369d13bf217de4bed3437dd1c F src/os_os2.c 8769301bff502de642ad2634cedcb77d967ce199 @@ -135,7 +135,7 @@ F src/test2.c 4f742e99ed1bea5c14692f627bdb59a146f30504 F src/test3.c 2e4da0fe90a0aa8cf9276ea34cbe92e91dc1db07 F src/test4.c d97b87919dc3db1cc5fccc04a33f030d5940e1a9 F src/test5.c 81353afad5d795ae7155bffce1e4deef10ee8e22 -F src/test6.c 9a93a5538f4ec008e8471635889091b087328532 +F src/test6.c da83a0e49c03e8a25f4ce6e25c537c6617c14fc0 F src/test7.c 50f5aa04fd751528ad5ee50e9be9ecee6f0b574a F src/test8.c 4bf571b82e502094846ae06e30fe028f190aaaae F src/test9.c b46c8fe02ac7cca1a7316436d8d38d50c66f4b2f @@ -557,7 +557,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 6cf725d212d468cbd7c7cbc22ca5ab13f1d77939 -R bc41d2a41155d3978aad1298f4dc479f -U drh -Z 6fdad79122af6697e52d8395a5ab70ee +P fbbd5bda544ffec4e1b43407b12e546235dc7873 +R 0ca0858c81f7f856c15261fd84ff79c4 +U danielk1977 +Z d922b4212f9baf5077c8cc76317915f9 diff --git a/manifest.uuid b/manifest.uuid index 33169c481e..35465946bf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fbbd5bda544ffec4e1b43407b12e546235dc7873 \ No newline at end of file +5bced2392ad77aff0aa1ddea83f2ff9e3ffe28a8 \ No newline at end of file diff --git a/src/os.c b/src/os.c index 90dd4a39aa..f71ab56e65 100644 --- a/src/os.c +++ b/src/os.c @@ -233,6 +233,7 @@ int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){ pVfs->pNext = vfsList->pNext; pVfs->pNext = pVfs; } + assert(vfsList); sqlite3_mutex_leave(mutex); return SQLITE_OK; } @@ -244,6 +245,7 @@ int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){ sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); sqlite3_mutex_enter(mutex); vfsUnlink(pVfs); + assert(vfsList); sqlite3_mutex_leave(mutex); return SQLITE_OK; } diff --git a/src/test6.c b/src/test6.c index db20725ed4..0abf2353a9 100644 --- a/src/test6.c +++ b/src/test6.c @@ -126,7 +126,10 @@ struct CrashFile { sqlite3_file *pRealFile; /* Underlying "real" file handle */ char *zName; - /* Cache of the entire file. */ + /* Cache of the entire file. This is used to speed up OsRead() and + ** OsFileSize() calls. Although both could be done by traversing the + ** write-list, in practice this is impractically slow. + */ int iSize; /* Size of file in bytes */ int nData; /* Size of buffer allocated at zData */ u8 *zData; /* Buffer containing file contents */ @@ -303,7 +306,7 @@ static int writeListAppend( static int cfClose(sqlite3_file *pFile){ CrashFile *pCrash = (CrashFile *)pFile; writeListSync(pCrash, 0); - sqlite3OsCloseFree(pCrash->pRealFile); + sqlite3OsClose(pCrash->pRealFile); return SQLITE_OK; } @@ -454,8 +457,7 @@ static const sqlite3_io_methods CrashFileVtab = { ** Application data for the crash VFS */ struct crashAppData { - int (*xOpen)(void*,const char*,sqlite3_file*,int,int*); /* Original xOpen */ - void *pAppData; /* Original pAppData */ + sqlite3_vfs *pOrig; /* Wrapped vfs structure */ }; /* @@ -468,50 +470,78 @@ struct crashAppData { ** sqlite3_malloc(). The assumption here is (pVfs->szOsFile) is ** equal or greater than sizeof(CrashFile). */ -static int sqlite3CrashFileOpen( - sqlite3_vfs *pVfs, +static int cfOpen( + void *pAppData, const char *zName, sqlite3_file *pFile, int flags, int *pOutFlags ){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; int rc; - if( sqlite3CrashTestEnable ){ - CrashFile *pWrapper = (CrashFile *)pFile; - sqlite3_file *pReal; - assert(pVfs->szOsFile>=sizeof(CrashFile)); - memset(pWrapper, 0, sizeof(CrashFile)); - sqlite3CrashTestEnable = 0; - rc = sqlite3OsOpenMalloc(pVfs, zName, &pReal, flags, pOutFlags); - sqlite3CrashTestEnable = 1; - if( rc==SQLITE_OK ){ - i64 iSize; - pWrapper->pMethod = &CrashFileVtab; - pWrapper->zName = (char *)zName; - pWrapper->pRealFile = pReal; - rc = sqlite3OsFileSize(pReal, &iSize); - pWrapper->iSize = (int)iSize; + CrashFile *pWrapper = (CrashFile *)pFile; + sqlite3_file *pReal = &pWrapper[1]; + + memset(pWrapper, 0, sizeof(CrashFile)); + rc = sqlite3OsOpen(pVfs, zName, pReal, flags, pOutFlags); + + if( rc==SQLITE_OK ){ + i64 iSize; + pWrapper->pMethod = &CrashFileVtab; + pWrapper->zName = (char *)zName; + pWrapper->pRealFile = pReal; + rc = sqlite3OsFileSize(pReal, &iSize); + pWrapper->iSize = (int)iSize; + } + if( rc==SQLITE_OK ){ + pWrapper->nData = (4096 + pWrapper->iSize); + pWrapper->zData = (char *)sqlite3_malloc(pWrapper->nData); + if( pWrapper->zData ){ + memset(pWrapper->zData, 0, pWrapper->nData); + rc = sqlite3OsRead(pReal, pWrapper->zData, pWrapper->iSize, 0); + }else{ + rc = SQLITE_NOMEM; } - if( rc==SQLITE_OK ){ - pWrapper->nData = (4096 + pWrapper->iSize); - pWrapper->zData = (char *)sqlite3_malloc(pWrapper->nData); - if( pWrapper->zData ){ - memset(pWrapper->zData, 0, pWrapper->nData); - rc = sqlite3OsRead(pReal, pWrapper->zData, pWrapper->iSize, 0); - }else{ - rc = SQLITE_NOMEM; - } - } - if( rc!=SQLITE_OK && pWrapper->pMethod ){ - sqlite3OsClose(pFile); - } - }else{ - struct crashAppData *pData = (struct crashAppData*)pVfs->pAppData; - rc = pData->xOpen(pData->pAppData, zName, pFile, flags, pOutFlags); + } + if( rc!=SQLITE_OK && pWrapper->pMethod ){ + sqlite3OsClose(pFile); } return rc; } +static int cfDelete(void *pAppData, const char *zPath, int dirSync){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; + return pVfs->xDelete(pVfs->pAppData, zPath, dirSync); +} +static int cfAccess(void *pAppData, const char *zPath, int flags){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; + return pVfs->xAccess(pVfs->pAppData, zPath, flags); +} +static int cfGetTempName(void *pAppData, char *zBufOut){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; + return pVfs->xGetTempName(pVfs->pAppData, zBufOut); +} +static int cfFullPathname(void *pAppData, const char *zPath, char *zPathOut){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; + return pVfs->xFullPathname(pVfs->pAppData, zPath, zPathOut); +} +static void *cfDlOpen(void *pAppData, const char *zPath){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; + return pVfs->xDlOpen(pVfs->pAppData, zPath); +} +static int cfRandomness(void *pAppData, int nByte, char *zBufOut){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; + return pVfs->xRandomness(pVfs->pAppData, nByte, zBufOut); +} +static int cfSleep(void *pAppData, int nMicro){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; + return pVfs->xSleep(pVfs->pAppData, nMicro); +} +static int cfCurrentTime(void *pAppData, double *pTimeOut){ + sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData; + return pVfs->xCurrentTime(pVfs->pAppData, pTimeOut); +} + /* ** tclcmd: sqlite_crashparams ?OPTIONS? DELAY CRASHFILE ** @@ -540,20 +570,42 @@ static int crashParamsObjCmd( int iDelay; const char *zCrashFile; int nCrashFile; - static sqlite3_vfs crashVfs, *pOriginalVfs; static struct crashAppData appData; - if( pOriginalVfs==0 ){ - pOriginalVfs = sqlite3_vfs_find(0); - crashVfs = *pOriginalVfs; - crashVfs.xOpen = sqlite3CrashFileOpen; - crashVfs.vfsMutex = 0; - crashVfs.nRef = 0; - crashVfs.pAppData = &appData; - appData.xOpen = pOriginalVfs->xOpen; - appData.pAppData = pOriginalVfs->pAppData; + static sqlite3_vfs crashVfs = { + 1, /* iVersion */ + 0, /* szOsFile */ + 0, /* mxPathname */ + 0, /* nRef */ + 0, /* vfsMutex */ + 0, /* pNext */ + "crash", /* zName */ + 0, /* pAppData */ + + cfOpen, /* xOpen */ + cfDelete, /* xDelete */ + cfAccess, /* xAccess */ + cfGetTempName, /* xGetTempName */ + cfFullPathname, /* xFullPathname */ + cfDlOpen, /* xDlOpen */ + 0, /* xDlError */ + 0, /* xDlSym */ + 0, /* xDlClose */ + cfRandomness, /* xRandomness */ + cfSleep, /* xSleep */ + cfCurrentTime /* xCurrentTime */ + }; + + if( crashVfs.pAppData==0 ){ + sqlite3_vfs *pOriginalVfs = sqlite3_vfs_find(0); + crashVfs.xDlError = pOriginalVfs->xDlError; + crashVfs.xDlSym = pOriginalVfs->xDlSym; + crashVfs.xDlClose = pOriginalVfs->xDlClose; + crashVfs.mxPathname = pOriginalVfs->mxPathname; + crashVfs.pAppData = (void *)pOriginalVfs; + crashVfs.szOsFile = sizeof(CrashFile) + pOriginalVfs->szOsFile; sqlite3_vfs_release(pOriginalVfs); - sqlite3_vfs_unregister(pOriginalVfs); + /* sqlite3_vfs_unregister(pOriginalVfs); */ sqlite3_vfs_register(&crashVfs, 1); }