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