From: dan Date: Thu, 13 May 2010 06:19:37 +0000 (+0000) Subject: Modify the VFS in test_vfs.c to match the refactoring of the xShmXXX methods. X-Git-Tag: version-3.7.2~383^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7fd555a634bb9a609b0b3c1b1893216b44ee212a;p=thirdparty%2Fsqlite.git Modify the VFS in test_vfs.c to match the refactoring of the xShmXXX methods. FossilOrigin-Name: 25e72f81561575051c63e9bf5d2c8e76f9fcf5c6 --- diff --git a/manifest b/manifest index 360b1740a6..d14a522e36 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Fix\sfor\sthe\stest_devsym.c\stest\smodule\sfor\sthe\sVFS-SHM\srefactoring. -D 2010-05-12T18:30:36 +C Modify\sthe\sVFS\sin\stest_vfs.c\sto\smatch\sthe\srefactoring\sof\sthe\sxShmXXX\smethods. +D 2010-05-13T06:19:37 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -210,7 +207,7 @@ F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0 F src/test_server.c bbba05c144b5fc4b52ff650a4328027b3fa5fcc6 F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa F src/test_thread.c aa9919c885a1fe53eafc73492f0898ee6c0a0726 -F src/test_vfs.c 6e828b42e1b50ce923f9bde890f84f78f8cc8b74 +F src/test_vfs.c 3601f9b6d46cb6daf0697d60c76bf8e18b90b123 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/tokenize.c 25ceb0f0a746ea1d0f9553787f3f0a56853cfaeb F src/trigger.c 8927588cb9e6d47f933b53bfe74200fbb504100d @@ -817,14 +814,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P c74458127468f30b16715594c8d68e9d3c05d292 -R 5a9efacb9856d7f4bdde2f4883d79672 -U drh -Z 630d17e21b3111ffa913dd47b8968c39 ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFL6vPPoxKgR168RlERAj53AJkBapvtr+dRsf/F1XjNxRi5BCrThQCdFxa3 -EJzQfQYaZjLG21xvWiHqkgU= -=76NU ------END PGP SIGNATURE----- +P 49d62933759d4e160ee3a4dd2aa316a2f5bbb4e6 +R f8fd118199dfa730f3f5ccb6ad378e59 +U dan +Z b35bfe52883b808b3d9e1494afbcf52c diff --git a/manifest.uuid b/manifest.uuid index 0fda76004a..eb9623f6b8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -49d62933759d4e160ee3a4dd2aa316a2f5bbb4e6 \ No newline at end of file +25e72f81561575051c63e9bf5d2c8e76f9fcf5c6 \ No newline at end of file diff --git a/src/test_vfs.c b/src/test_vfs.c index af0c24b49a..ce4afa7622 100644 --- a/src/test_vfs.c +++ b/src/test_vfs.c @@ -16,18 +16,21 @@ #include "sqlite3.h" #include "sqliteInt.h" -#if 0 /* FIX THIS LATER */ - typedef struct Testvfs Testvfs; typedef struct TestvfsShm TestvfsShm; typedef struct TestvfsBuffer TestvfsBuffer; -typedef struct tvfs_file tvfs_file; -struct tvfs_file { - sqlite3_file base; /* Base class. Must be first */ - sqlite3_vfs *pVfs; /* the VFS */ - TestvfsShm *pShm; /* Shared memory segment */ - const char *zFilename; /* Filename */ - sqlite3_file *pReal; /* The real, underlying file descriptor */ +typedef struct TestvfsFile TestvfsFile; + +/* +** An open file handle. +*/ +struct TestvfsFile { + sqlite3_file base; /* Base class. Must be first */ + sqlite3_vfs *pVfs; /* The VFS */ + const char *zFilename; /* Filename as passed to xOpen() */ + sqlite3_file *pReal; /* The real, underlying file descriptor */ + Tcl_Obj *pShmId; /* Shared memory id for Tcl callbacks */ + TestvfsBuffer *pShm; /* Shared memory buffer */ }; @@ -44,6 +47,7 @@ struct Testvfs { int nScript; /* Number of elements in array apScript */ Tcl_Obj **apScript; /* Script to execute */ TestvfsBuffer *pBuffer; /* List of shared buffers */ + int isNoshm; }; /* @@ -57,20 +61,12 @@ struct TestvfsBuffer { TestvfsBuffer *pNext; /* Next in linked list of all buffers */ }; -/* -** A shared-memory handle returned by tvfsShmOpen(). -*/ -struct TestvfsShm { - Tcl_Obj *id; /* Name of this handle */ - TestvfsBuffer *pBuffer; /* Underlying buffer */ -}; - #define PARENTVFS(x) (((Testvfs *)((x)->pAppData))->pParent) /* -** Method declarations for tvfs_file. +** Method declarations for TestvfsFile. */ static int tvfsClose(sqlite3_file*); static int tvfsRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); @@ -135,7 +131,14 @@ static sqlite3_io_methods tvfs_io_methods = { ** Close an tvfs-file. */ static int tvfsClose(sqlite3_file *pFile){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; + if( p->pShmId ){ + Tcl_DecrRefCount(p->pShmId); + p->pShmId = 0; + } + if( pFile->pMethods ){ + ckfree((char *)pFile->pMethods); + } return sqlite3OsClose(p->pReal); } @@ -148,7 +151,7 @@ static int tvfsRead( int iAmt, sqlite_int64 iOfst ){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst); } @@ -161,7 +164,7 @@ static int tvfsWrite( int iAmt, sqlite_int64 iOfst ){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsWrite(p->pReal, zBuf, iAmt, iOfst); } @@ -169,7 +172,7 @@ static int tvfsWrite( ** Truncate an tvfs-file. */ static int tvfsTruncate(sqlite3_file *pFile, sqlite_int64 size){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsTruncate(p->pReal, size); } @@ -177,7 +180,7 @@ static int tvfsTruncate(sqlite3_file *pFile, sqlite_int64 size){ ** Sync an tvfs-file. */ static int tvfsSync(sqlite3_file *pFile, int flags){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsSync(p->pReal, flags); } @@ -185,7 +188,7 @@ static int tvfsSync(sqlite3_file *pFile, int flags){ ** Return the current file-size of an tvfs-file. */ static int tvfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsFileSize(p->pReal, pSize); } @@ -193,7 +196,7 @@ static int tvfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ ** Lock an tvfs-file. */ static int tvfsLock(sqlite3_file *pFile, int eLock){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsLock(p->pReal, eLock); } @@ -201,7 +204,7 @@ static int tvfsLock(sqlite3_file *pFile, int eLock){ ** Unlock an tvfs-file. */ static int tvfsUnlock(sqlite3_file *pFile, int eLock){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsUnlock(p->pReal, eLock); } @@ -209,7 +212,7 @@ static int tvfsUnlock(sqlite3_file *pFile, int eLock){ ** Check if another file-handle holds a RESERVED lock on an tvfs-file. */ static int tvfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsCheckReservedLock(p->pReal, pResOut); } @@ -217,7 +220,7 @@ static int tvfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){ ** File control method. For custom operations on an tvfs-file. */ static int tvfsFileControl(sqlite3_file *pFile, int op, void *pArg){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsFileControl(p->pReal, op, pArg); } @@ -225,7 +228,7 @@ static int tvfsFileControl(sqlite3_file *pFile, int op, void *pArg){ ** Return the sector-size in bytes for an tvfs-file. */ static int tvfsSectorSize(sqlite3_file *pFile){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsSectorSize(p->pReal); } @@ -233,7 +236,7 @@ static int tvfsSectorSize(sqlite3_file *pFile){ ** Return the device characteristic flags supported by an tvfs-file. */ static int tvfsDeviceCharacteristics(sqlite3_file *pFile){ - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; return sqlite3OsDeviceCharacteristics(p->pReal); } @@ -248,15 +251,28 @@ static int tvfsOpen( int *pOutFlags ){ int rc; - tvfs_file *p = (tvfs_file *)pFile; + TestvfsFile *p = (TestvfsFile *)pFile; p->pShm = 0; + p->pShmId = 0; p->zFilename = zName; p->pVfs = pVfs; p->pReal = (sqlite3_file *)&p[1]; rc = sqlite3OsOpen(PARENTVFS(pVfs), zName, p->pReal, flags, pOutFlags); if( p->pReal->pMethods ){ - pFile->pMethods = &tvfs_io_methods; + sqlite3_io_methods *pMethods; + pMethods = (sqlite3_io_methods *)ckalloc(sizeof(sqlite3_io_methods)); + memcpy(pMethods, &tvfs_io_methods, sizeof(sqlite3_io_methods)); + if( ((Testvfs *)pVfs->pAppData)->isNoshm ){ + pMethods->xShmOpen = 0; + pMethods->xShmGet = 0; + pMethods->xShmSize = 0; + pMethods->xShmRelease = 0; + pMethods->xShmClose = 0; + pMethods->xShmLock = 0; + } + pFile->pMethods = pMethods; } + return rc; } @@ -351,8 +367,8 @@ static int tvfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ return PARENTVFS(pVfs)->xCurrentTime(PARENTVFS(pVfs), pTimeOut); } -static void tvfsGrowBuffer(TestvfsShm *pShm, int reqSize, int *pNewSize){ - TestvfsBuffer *pBuffer = pShm->pBuffer; +static void tvfsGrowBuffer(TestvfsFile *pFd, int reqSize, int *pNewSize){ + TestvfsBuffer *pBuffer = pFd->pShm; if( reqSize>pBuffer->n ){ pBuffer->a = (u8 *)ckrealloc((char *)pBuffer->a, reqSize); memset(&pBuffer->a[pBuffer->n], 0x55, reqSize-pBuffer->n); @@ -421,14 +437,15 @@ static int tvfsResultCode(Testvfs *p, int *pRc){ static int tvfsShmOpen( sqlite3_file *pFileDes ){ - Testvfs *p = (Testvfs *)(pVfs->pAppData); + Testvfs *p; int rc = SQLITE_OK; /* Return code */ Tcl_Obj *pId = 0; /* Id for this connection */ TestvfsBuffer *pBuffer; /* Buffer to open connection to */ - TestvfsShm *pShm; /* New shm handle */ - tvfs_file *pFd; /* The file descriptor */ + TestvfsFile *pFd; /* The testvfs file structure */ - pFd = (tvfs_file*)pFileDes; + pFd = (TestvfsFile*)pFileDes; + p = (Testvfs *)pFd->pVfs->pAppData; + assert( pFd->pShmId==0 && pFd->pShm==0 ); /* Evaluate the Tcl script: ** @@ -447,82 +464,75 @@ static int tvfsShmOpen( pId = Tcl_GetObjResult(p->interp); } Tcl_IncrRefCount(pId); - - /* Allocate the TestvfsShm handle. */ - pShm = (TestvfsShm *)ckalloc(sizeof(TestvfsShm)); - memset(pShm, 0, sizeof(TestvfsShm)); - pShm->id = pId; + pFd->pShmId = pId; /* Search for a TestvfsBuffer. Create a new one if required. */ for(pBuffer=p->pBuffer; pBuffer; pBuffer=pBuffer->pNext){ - if( 0==strcmp(zName, pBuffer->zFile) ) break; + if( 0==strcmp(pFd->zFilename, pBuffer->zFile) ) break; } if( !pBuffer ){ - int nByte = sizeof(TestvfsBuffer) + strlen(zName) + 1; + int nByte = sizeof(TestvfsBuffer) + strlen(pFd->zFilename) + 1; pBuffer = (TestvfsBuffer *)ckalloc(nByte); memset(pBuffer, 0, nByte); pBuffer->zFile = (char *)&pBuffer[1]; - strcpy(pBuffer->zFile, zName); + strcpy(pBuffer->zFile, pFd->zFilename); pBuffer->pNext = p->pBuffer; p->pBuffer = pBuffer; } /* Connect the TestvfsBuffer to the new TestvfsShm handle and return. */ pBuffer->nRef++; - pShm->pBuffer = pBuffer; - *pp = (sqlite3_shm *)pShm; + pFd->pShm = pBuffer; return SQLITE_OK; } static int tvfsShmSize( - sqlite3_vfs *pVfs, - sqlite3_shm *pShmHandle, + sqlite3_file *pFile, int reqSize, int *pNewSize ){ int rc = SQLITE_OK; - Testvfs *p = (Testvfs *)(pVfs->pAppData); - TestvfsShm *pShm = (TestvfsShm *)pShmHandle; + TestvfsFile *pFd = (TestvfsFile *)pFile; + Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData); tvfsExecTcl(p, "xShmSize", - Tcl_NewStringObj(pShm->pBuffer->zFile, -1), pShm->id, 0 + Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, 0 ); tvfsResultCode(p, &rc); if( rc==SQLITE_OK ){ - tvfsGrowBuffer(pShm, reqSize, pNewSize); + tvfsGrowBuffer(pFd, reqSize, pNewSize); } return rc; } static int tvfsShmGet( - sqlite3_vfs *pVfs, - sqlite3_shm *pShmHandle, + sqlite3_file *pFile, int reqMapSize, int *pMapSize, void **pp ){ int rc = SQLITE_OK; - Testvfs *p = (Testvfs *)(pVfs->pAppData); - TestvfsShm *pShm = (TestvfsShm *)pShmHandle; + TestvfsFile *pFd = (TestvfsFile *)pFile; + Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData); tvfsExecTcl(p, "xShmGet", - Tcl_NewStringObj(pShm->pBuffer->zFile, -1), pShm->id, 0 + Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, 0 ); tvfsResultCode(p, &rc); if( rc==SQLITE_OK ){ - tvfsGrowBuffer(pShm, reqMapSize, pMapSize); - *pp = pShm->pBuffer->a; + tvfsGrowBuffer(pFd, reqMapSize, pMapSize); + *pp = pFd->pShm->a; } return rc; } -static int tvfsShmRelease(sqlite3_vfs *pVfs, sqlite3_shm *pShmHandle){ +static int tvfsShmRelease(sqlite3_file *pFile){ int rc = SQLITE_OK; - Testvfs *p = (Testvfs *)(pVfs->pAppData); - TestvfsShm *pShm = (TestvfsShm *)pShmHandle; + TestvfsFile *pFd = (TestvfsFile *)pFile; + Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData); tvfsExecTcl(p, "xShmRelease", - Tcl_NewStringObj(pShm->pBuffer->zFile, -1), pShm->id, 0 + Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, 0 ); tvfsResultCode(p, &rc); @@ -530,14 +540,13 @@ static int tvfsShmRelease(sqlite3_vfs *pVfs, sqlite3_shm *pShmHandle){ } static int tvfsShmLock( - sqlite3_vfs *pVfs, - sqlite3_shm *pShmHandle, + sqlite3_file *pFile, int desiredLock, int *gotLock ){ int rc = SQLITE_OK; - Testvfs *p = (Testvfs *)(pVfs->pAppData); - TestvfsShm *pShm = (TestvfsShm *)pShmHandle; + TestvfsFile *pFd = (TestvfsFile *)pFile; + Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData); char *zLock = ""; switch( desiredLock ){ @@ -549,7 +558,7 @@ static int tvfsShmLock( case SQLITE_SHM_UNLOCK: zLock = "UNLOCK"; break; } tvfsExecTcl(p, "xShmLock", - Tcl_NewStringObj(pShm->pBuffer->zFile, -1), pShm->id, + Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, Tcl_NewStringObj(zLock, -1) ); tvfsResultCode(p, &rc); @@ -561,21 +570,21 @@ static int tvfsShmLock( } static int tvfsShmClose( - sqlite3_vfs *pVfs, - sqlite3_shm *pShmHandle, + sqlite3_file *pFile, int deleteFlag ){ int rc = SQLITE_OK; - Testvfs *p = (Testvfs *)(pVfs->pAppData); - TestvfsShm *pShm = (TestvfsShm *)pShmHandle; - TestvfsBuffer *pBuffer = pShm->pBuffer; + TestvfsFile *pFd = (TestvfsFile *)pFile; + Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData); + TestvfsBuffer *pBuffer = pFd->pShm; + assert( pFd->pShmId && pFd->pShm ); #if 0 assert( (deleteFlag!=0)==(pBuffer->nRef==1) ); #endif tvfsExecTcl(p, "xShmClose", - Tcl_NewStringObj(pShm->pBuffer->zFile, -1), pShm->id, 0 + Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, 0 ); tvfsResultCode(p, &rc); @@ -587,8 +596,9 @@ static int tvfsShmClose( ckfree((char *)pBuffer->a); ckfree((char *)pBuffer); } - Tcl_DecrRefCount(pShm->id); - ckfree((char *)pShm); + Tcl_DecrRefCount(pFd->pShmId); + pFd->pShmId = 0; + pFd->pShm = 0; return rc; } @@ -702,10 +712,9 @@ static int testvfs_cmd( int objc, Tcl_Obj *CONST objv[] ){ - static sqlite3_vfs tvfs_vfs = { 2, /* iVersion */ - sizeof(tvfs_file), /* szOsFile */ + sizeof(TestvfsFile), /* szOsFile */ 0, /* mxPathname */ 0, /* pNext */ 0, /* zName */ @@ -779,14 +788,7 @@ static int testvfs_cmd( pVfs->mxPathname = p->pParent->mxPathname; pVfs->szOsFile += p->pParent->szOsFile; p->pVfs = pVfs; - if( isNoshm ){ - pVfs->xShmOpen = 0; - pVfs->xShmGet = 0; - pVfs->xShmSize = 0; - pVfs->xShmRelease = 0; - pVfs->xShmClose = 0; - pVfs->xShmLock = 0; - } + p->isNoshm = isNoshm; Tcl_CreateObjCommand(interp, zVfs, testvfs_obj_cmd, p, testvfs_obj_del); sqlite3_vfs_register(pVfs, 0); @@ -797,10 +799,9 @@ static int testvfs_cmd( Tcl_WrongNumArgs(interp, 1, objv, "?-noshm? VFSNAME SCRIPT"); return TCL_ERROR; } -#endif /* 0 */ int Sqlitetestvfs_Init(Tcl_Interp *interp){ - /* Tcl_CreateObjCommand(interp, "testvfs", testvfs_cmd, 0, 0); */ + Tcl_CreateObjCommand(interp, "testvfs", testvfs_cmd, 0, 0); return TCL_OK; }