Index: ext/fts3/fts3.c ================================================================== --- ext/fts3/fts3.c +++ ext/fts3/fts3.c @@ -3351,11 +3351,12 @@ assert( iCol>=0 && iCol<=p->nColumn+2 ); switch( iCol-p->nColumn ){ case 0: /* The special 'table-name' column */ - sqlite3_result_pointer(pCtx, pCsr, "fts3cursor"); + pCsr->iMagic = FTS3_CURSOR_MAGIC; + sqlite3_result_blob(pCtx, pCsr, 0, SQLITE_STATIC); break; case 1: /* The docid column */ sqlite3_result_int64(pCtx, pCsr->iPrevId); @@ -3570,12 +3571,17 @@ const char *zFunc, /* Function name */ sqlite3_value *pVal, /* argv[0] passed to function */ Fts3Cursor **ppCsr /* OUT: Store cursor handle here */ ){ int rc; - *ppCsr = (Fts3Cursor*)sqlite3_value_pointer(pVal, "fts3cursor"); - if( (*ppCsr)!=0 ){ + Fts3Cursor *pCur; + if( sqlite3_value_type(pVal)==SQLITE_BLOB + && sqlite3_value_bytes(pVal)==0 + && (pCur = (Fts3Cursor*)sqlite3_value_blob(pVal))!=0 + && pCur->iMagic==FTS3_CURSOR_MAGIC + ){ + *ppCsr = pCur; rc = SQLITE_OK; }else{ char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc); sqlite3_result_error(pContext, zErr, -1); sqlite3_free(zErr); Index: ext/fts3/fts3Int.h ================================================================== --- ext/fts3/fts3Int.h +++ ext/fts3/fts3Int.h @@ -288,17 +288,23 @@ ** by special insert command 'test-no-incr-doclist'. */ int bNoIncrDoclist; #endif }; +/* +** Magic number for cursors +*/ +#define FTS3_CURSOR_MAGIC 0x2f621809 + /* ** When the core wants to read from the virtual table, it creates a ** virtual table cursor (an instance of the following structure) using ** the xOpen method. Cursors are destroyed using the xClose method. */ struct Fts3Cursor { sqlite3_vtab_cursor base; /* Base class used by SQLite core */ + u32 iMagic; /* Magic number to prove identity */ i16 eSearch; /* Search strategy (see below) */ u8 isEof; /* True if at End Of Results */ u8 isRequireSeek; /* True if must seek pStmt to %_content row */ u8 bSeekStmt; /* True if pStmt is a seek */ sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */ Index: src/vdbeapi.c ================================================================== --- src/vdbeapi.c +++ src/vdbeapi.c @@ -173,11 +173,11 @@ if( ExpandBlob(p)!=SQLITE_OK ){ assert( p->flags==MEM_Null && p->z==0 ); return 0; } p->flags |= MEM_Blob; - return p->n ? p->z : 0; + return p->z; // p->n ? p->z : 0; }else{ return sqlite3_value_text(pVal); } } int sqlite3_value_bytes(sqlite3_value *pVal){