Index: src/test8.c ================================================================== --- src/test8.c +++ src/test8.c @@ -11,11 +11,11 @@ ************************************************************************* ** Code for testing the virtual table interfaces. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test8.c,v 1.55 2007/08/29 12:31:28 danielk1977 Exp $ +** $Id: test8.c,v 1.56 2007/09/03 11:51:50 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include #include @@ -347,10 +347,15 @@ sqlite3_free(p->zLogName); sqlite3_free(p); return 0; } +typedef struct EchoModule EchoModule; +struct EchoModule { + Tcl_Interp *interp; +}; + /* ** This function is called to do the work of the xConnect() method - ** to allocate the required in-memory structures for a newly connected ** virtual table. */ @@ -368,11 +373,11 @@ /* Allocate the sqlite3_vtab/echo_vtab structure itself */ pVtab = sqlite3MallocZero( sizeof(*pVtab) ); if( !pVtab ){ return SQLITE_NOMEM; } - pVtab->interp = (Tcl_Interp *)pAux; + pVtab->interp = ((EchoModule *)pAux)->interp; pVtab->db = db; /* Allocate echo_vtab.zThis */ pVtab->zThis = sqlite3MPrintf(0, "%s", argv[2]); if( !pVtab->zThis ){ @@ -425,11 +430,11 @@ int argc, const char *const*argv, sqlite3_vtab **ppVtab, char **pzErr ){ int rc = SQLITE_OK; - appendToEchoModule((Tcl_Interp *)(pAux), "xCreate"); + appendToEchoModule(((EchoModule *)pAux)->interp, "xCreate"); rc = echoConstructor(db, pAux, argc, argv, ppVtab, pzErr); /* If there were two arguments passed to the module at the SQL level ** (i.e. "CREATE VIRTUAL TABLE tbl USING echo(arg1, arg2)"), then ** the second argument is used as a table name. Attempt to create @@ -460,11 +465,11 @@ void *pAux, int argc, const char *const*argv, sqlite3_vtab **ppVtab, char **pzErr ){ - appendToEchoModule((Tcl_Interp *)(pAux), "xConnect"); + appendToEchoModule(((EchoModule *)pAux)->interp, "xConnect"); return echoConstructor(db, pAux, argc, argv, ppVtab, pzErr); } /* ** Echo virtual table module xDisconnect method. @@ -1122,10 +1127,14 @@ */ static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){ *ppDb = (sqlite3*)sqlite3TextToPtr(zA); return TCL_OK; } + +static void moduleDestroy(void *p){ + sqlite3_free(p); +} /* ** Register the echo virtual table module. */ static int register_echo_module( @@ -1133,16 +1142,19 @@ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int objc, /* Number of arguments */ Tcl_Obj *CONST objv[] /* Command arguments */ ){ sqlite3 *db; + EchoModule *pMod; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "DB"); return TCL_ERROR; } if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; - sqlite3_create_module(db, "echo", &echoModule, (void *)interp); + pMod = sqlite3_malloc(sizeof(EchoModule)); + pMod->interp = interp; + sqlite3_create_module_v2(db, "echo", &echoModule, (void*)pMod, moduleDestroy); return TCL_OK; } /* ** Tcl interface to sqlite3_declare_vtab, invoked as follows from Tcl: