/ Check-in [bf2e28dd]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Integration adjustments for the vtshim module.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | disposable-vtable
Files: files | file ages | folders
SHA1:bf2e28ddb292ef0b9a1262ec249aed3243dcfb20
User & Date: mistachkin 2013-06-20 00:20:39
Context
2013-06-20
01:27
The vtshim xCreate and xConnect functions need to store the pAux pointer into the newly created vtable object. Style fixes. check-in: 43913c7b user: mistachkin tags: disposable-vtable
00:20
Integration adjustments for the vtshim module. check-in: bf2e28dd user: mistachkin tags: disposable-vtable
2013-06-13
00:32
Add a prototype for an extension that sits in between the SQLite native code virtual table interface and a CLR IDisposable object. check-in: 10bba8d0 user: drh tags: disposable-vtable
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/vtshim.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** A shim that sits between the SQLite virtual table interface and
    14         -** managed memory of .NET
           14  +** runtimes with garbage collector based memory management.
    15     15   */
    16     16   #include "sqlite3ext.h"
    17     17   SQLITE_EXTENSION_INIT1
    18     18   #include <assert.h>
    19     19   #include <string.h>
    20     20   
    21     21   #ifndef SQLITE_OMIT_VIRTUALTABLE
................................................................................
    28     28   
    29     29   /* The vtshim_aux argument is the auxiliary parameter that is passed
    30     30   ** into sqlite3_create_module_v2().
    31     31   */
    32     32   struct vtshim_aux {
    33     33     void *pChildAux;              /* pAux for child virtual tables */
    34     34     void (*xChildDestroy)(void*); /* Destructor for pChildAux */
    35         -  const sqlite3_module *pMod;   /* Methods for child virtual tables */
           35  +  sqlite3_module *pMod;         /* Methods for child virtual tables */
    36     36     sqlite3 *db;                  /* The database to which we are attached */
    37         -  const char *zName;            /* Name of the module */
           37  +  char *zName;                  /* Name of the module */
    38     38     int bDisposed;                /* True if disposed */
    39     39     vtshim_vtab *pAllVtab;        /* List of all vtshim_vtab objects */
    40     40     sqlite3_module sSelf;         /* Methods used by this shim */
    41     41   };
    42     42   
    43     43   /* A vtshim virtual table object */
    44     44   struct vtshim_vtab {
................................................................................
   320    320   /* The destructor function for a disposible module */
   321    321   static void vtshimAuxDestructor(void *pXAux){
   322    322     vtshim_aux *pAux = (vtshim_aux*)pXAux;
   323    323     assert( pAux->pAllVtab==0 );
   324    324     if( !pAux->bDisposed && pAux->xChildDestroy ){
   325    325       pAux->xChildDestroy(pAux->pChildAux);
   326    326     }
          327  +  sqlite3_free(pAux->zName);
          328  +  sqlite3_free(pAux->pMod);
   327    329     sqlite3_free(pAux);
   328    330   }
          331  +
          332  +static int vtshimCopyModule(
          333  +  const sqlite3_module *pMod,   /* Source module to be copied */
          334  +  sqlite3_module **ppMod        /* Destination for copied module */
          335  +){
          336  +  sqlite3_module *p;
          337  +  if( !pMod || !ppMod ) return SQLITE_ERROR;
          338  +  p = sqlite3_malloc( sizeof(*p) );
          339  +  if( p==0 ) return SQLITE_NOMEM;
          340  +  memcpy(p, pMod, sizeof(*p));
          341  +  *ppMod = p;
          342  +  return SQLITE_OK;
          343  +}
   329    344   
   330    345   #ifdef _WIN32
   331    346   __declspec(dllexport)
   332    347   #endif
   333    348   void *sqlite3_create_disposable_module(
   334    349     sqlite3 *db,               /* SQLite connection to register module with */
   335    350     const char *zName,         /* Name of the module */
   336    351     const sqlite3_module *p,   /* Methods for the module */
   337    352     void *pClientData,         /* Client data for xCreate/xConnect */
   338    353     void(*xDestroy)(void*)     /* Module destructor function */
   339    354   ){
   340    355     vtshim_aux *pAux;
          356  +  sqlite3_module *pMod;
   341    357     int rc;
   342    358     pAux = sqlite3_malloc( sizeof(*pAux) );
   343    359     if( pAux==0 ){
   344    360       if( xDestroy ) xDestroy(pClientData);
   345    361       return 0;
          362  +  }
          363  +  rc = vtshimCopyModule(p, &pMod);
          364  +  if( rc!=SQLITE_OK ){
          365  +    sqlite3_free(pAux);
          366  +    return 0;
   346    367     }
   347    368     pAux->pChildAux = pClientData;
   348    369     pAux->xChildDestroy = xDestroy;
   349         -  pAux->pMod = p;
          370  +  pAux->pMod = pMod;
   350    371     pAux->db = db;
   351         -  pAux->zName = zName;
          372  +  pAux->zName = sqlite3_mprintf("%s", zName);
   352    373     pAux->bDisposed = 0;
   353    374     pAux->pAllVtab = 0;
   354         -  pAux->sSelf.iVersion = p->iVersion<=1 ? p->iVersion : 1;
          375  +  pAux->sSelf.iVersion = p->iVersion<=2 ? p->iVersion : 2;
   355    376     pAux->sSelf.xCreate = p->xCreate ? vtshimCreate : 0;
   356    377     pAux->sSelf.xConnect = p->xConnect ? vtshimConnect : 0;
   357    378     pAux->sSelf.xBestIndex = p->xBestIndex ? vtshimBestIndex : 0;
   358    379     pAux->sSelf.xDisconnect = p->xDisconnect ? vtshimDisconnect : 0;
   359    380     pAux->sSelf.xDestroy = p->xDestroy ? vtshimDestroy : 0;
   360    381     pAux->sSelf.xOpen = p->xOpen ? vtshimOpen : 0;
   361    382     pAux->sSelf.xClose = p->xClose ? vtshimClose : 0;
................................................................................
   367    388     pAux->sSelf.xUpdate = p->xUpdate ? vtshimUpdate : 0;
   368    389     pAux->sSelf.xBegin = p->xBegin ? vtshimBegin : 0;
   369    390     pAux->sSelf.xSync = p->xSync ? vtshimSync : 0;
   370    391     pAux->sSelf.xCommit = p->xCommit ? vtshimCommit : 0;
   371    392     pAux->sSelf.xRollback = p->xRollback ? vtshimRollback : 0;
   372    393     pAux->sSelf.xFindFunction = p->xFindFunction ? vtshimFindFunction : 0;
   373    394     pAux->sSelf.xRename = p->xRename ? vtshimRename : 0;
   374         -  if( p->iVersion>=1 ){
          395  +  if( p->iVersion>=2 ){
   375    396       pAux->sSelf.xSavepoint = p->xSavepoint ? vtshimSavepoint : 0;
   376    397       pAux->sSelf.xRelease = p->xRelease ? vtshimRelease : 0;
   377    398       pAux->sSelf.xRollbackTo = p->xRollbackTo ? vtshimRollbackTo : 0;
   378    399     }else{
   379    400       pAux->sSelf.xSavepoint = 0;
   380    401       pAux->sSelf.xRelease = 0;
   381    402       pAux->sSelf.xRollbackTo = 0;