SQLite4
Check-in [56335097b1]
Not logged in

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

Overview
Comment:Change the API for binding strings and blobs so that the destructor now carries an extra argument which can be used as the sqlite4_env pointer, thus allowing functions like sqlite4_free() to be used as a string or blob destructor.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 56335097b187b038c4ee64a65a33ddbd904242bf
User & Date: drh 2013-02-13 12:28:13
Context
2013-02-14
15:32
Fold in Peter Reid's fixes and enhancements to the sqlite4_num object. check-in: 8ede88c1df user: drh tags: trunk
2013-02-13
12:28
Change the API for binding strings and blobs so that the destructor now carries an extra argument which can be used as the sqlite4_env pointer, thus allowing functions like sqlite4_free() to be used as a string or blob destructor. check-in: 56335097b1 user: drh tags: trunk
2013-02-11
18:33
Fix the data decoder so that it correctly handles +Inf and -Inf. check-in: c04b47fd62 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

    75     75           len = sqlite4GetToken(zCsr, &token);
    76     76         } while( token==TK_SPACE );
    77     77         assert( len>0 );
    78     78       } while( token!=TK_LP && token!=TK_USING );
    79     79   
    80     80       zRet = sqlite4MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql, 
    81     81          zTableName, tname.z+tname.n);
    82         -    sqlite4_result_text(context, zRet, -1, SQLITE4_TRANSIENT);
           82  +    sqlite4_result_text(context, zRet, -1, SQLITE4_TRANSIENT, 0);
    83     83       sqlite4DbFree(db, zRet);
    84     84     }
    85     85   }
    86     86   
    87     87   /*
    88     88   ** This C function implements an SQL user function that is used by SQL code
    89     89   ** generated by the ALTER TABLE ... RENAME command to modify the definition
................................................................................
   138    138           zInput = &z[n];
   139    139         }
   140    140         sqlite4DbFree(db, zParent);
   141    141       }
   142    142     }
   143    143   
   144    144     zResult = sqlite4MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput), 
   145         -  sqlite4_result_text(context, zResult, -1, SQLITE4_TRANSIENT);
          145  +  sqlite4_result_text(context, zResult, -1, SQLITE4_TRANSIENT, 0);
   146    146     sqlite4DbFree(db, zOutput);
   147    147     sqlite4DbFree(db, zResult);
   148    148   }
   149    149   #endif
   150    150   
   151    151   #ifndef SQLITE4_OMIT_TRIGGER
   152    152   /* This function is used by SQL generated to implement the
................................................................................
   216    216       } while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
   217    217   
   218    218       /* Variable tname now contains the token that is the old table-name
   219    219       ** in the CREATE TRIGGER statement.
   220    220       */
   221    221       zRet = sqlite4MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql, 
   222    222          zTableName, tname.z+tname.n);
   223         -    sqlite4_result_text(context, zRet, -1, SQLITE4_TRANSIENT);
          223  +    sqlite4_result_text(context, zRet, -1, SQLITE4_TRANSIENT, 0);
   224    224       sqlite4DbFree(db, zRet);
   225    225     }
   226    226   }
   227    227   #endif   /* !SQLITE4_OMIT_TRIGGER */
   228    228   
   229    229   /*
   230    230   ** Register built-in functions used to help implement ALTER TABLE

Changes to src/callback.c.

    28     28       db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
    29     29       sqlite4DbFree(db, zExternal);
    30     30     }
    31     31   #ifndef SQLITE4_OMIT_UTF16
    32     32     if( db->xCollNeeded16 ){
    33     33       char const *zExternal;
    34     34       sqlite4_value *pTmp = sqlite4ValueNew(db);
    35         -    sqlite4ValueSetStr(pTmp, -1, zName, SQLITE4_UTF8, SQLITE4_STATIC);
           35  +    sqlite4ValueSetStr(pTmp, -1, zName, SQLITE4_UTF8, SQLITE4_STATIC, 0);
    36     36       zExternal = sqlite4ValueText(pTmp, SQLITE4_UTF16NATIVE);
    37     37       if( zExternal ){
    38     38         db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
    39     39       }
    40     40       sqlite4ValueFree(pTmp);
    41     41     }
    42     42   #endif

Changes to src/complete.c.

   265    265     int rc = SQLITE4_NOMEM;
   266    266   
   267    267   #ifndef SQLITE4_OMIT_AUTOINIT
   268    268     rc = sqlite4_initialize(0);
   269    269     if( rc ) return rc;
   270    270   #endif
   271    271     pVal = sqlite4ValueNew(0);
   272         -  sqlite4ValueSetStr(pVal, -1, zSql, SQLITE4_UTF16NATIVE, SQLITE4_STATIC);
          272  +  sqlite4ValueSetStr(pVal, -1, zSql, SQLITE4_UTF16NATIVE, SQLITE4_STATIC, 0);
   273    273     zSql8 = sqlite4ValueText(pVal, SQLITE4_UTF8);
   274    274     if( zSql8 ){
   275    275       rc = sqlite4_complete(zSql8);
   276    276     }else{
   277    277       rc = SQLITE4_NOMEM;
   278    278     }
   279    279     sqlite4ValueFree(pVal);
   280    280     return sqlite4ApiExit(0, rc);
   281    281   }
   282    282   #endif /* SQLITE4_OMIT_UTF16 */
   283    283   #endif /* SQLITE4_OMIT_COMPLETE */

Changes to src/date.c.

   810    810   ){
   811    811     DateTime x;
   812    812     if( isDate(context, argc, argv, &x)==0 ){
   813    813       char zBuf[100];
   814    814       computeYMD_HMS(&x);
   815    815       sqlite4_snprintf(zBuf,sizeof(zBuf), "%04d-%02d-%02d %02d:%02d:%02d",
   816    816                        x.Y, x.M, x.D, x.h, x.m, (int)(x.s));
   817         -    sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT);
          817  +    sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT, 0);
   818    818     }
   819    819   }
   820    820   
   821    821   /*
   822    822   **    time( TIMESTRING, MOD, MOD, ...)
   823    823   **
   824    824   ** Return HH:MM:SS
................................................................................
   829    829     sqlite4_value **argv
   830    830   ){
   831    831     DateTime x;
   832    832     if( isDate(context, argc, argv, &x)==0 ){
   833    833       char zBuf[100];
   834    834       computeHMS(&x);
   835    835       sqlite4_snprintf(zBuf,sizeof(zBuf), "%02d:%02d:%02d", x.h, x.m, (int)x.s);
   836         -    sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT);
          836  +    sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT, 0);
   837    837     }
   838    838   }
   839    839   
   840    840   /*
   841    841   **    date( TIMESTRING, MOD, MOD, ...)
   842    842   **
   843    843   ** Return YYYY-MM-DD
................................................................................
   848    848     sqlite4_value **argv
   849    849   ){
   850    850     DateTime x;
   851    851     if( isDate(context, argc, argv, &x)==0 ){
   852    852       char zBuf[100];
   853    853       computeYMD(&x);
   854    854       sqlite4_snprintf(zBuf,sizeof(zBuf), "%04d-%02d-%02d", x.Y, x.M, x.D);
   855         -    sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT);
          855  +    sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT, 0);
   856    856     }
   857    857   }
   858    858   
   859    859   /*
   860    860   **    strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
   861    861   **
   862    862   ** Return a string described by FORMAT.  Conversions as follows:
................................................................................
   996    996           }
   997    997           default:   z[j++] = '%'; break;
   998    998         }
   999    999       }
  1000   1000     }
  1001   1001     z[j] = 0;
  1002   1002     sqlite4_result_text(context, z, -1,
  1003         -                      z==zBuf ? SQLITE4_TRANSIENT : SQLITE4_DYNAMIC);
         1003  +                      z==zBuf ? SQLITE4_TRANSIENT : SQLITE4_DYNAMIC, 0);
  1004   1004   }
  1005   1005   
  1006   1006   /*
  1007   1007   ** current_time()
  1008   1008   **
  1009   1009   ** This function returns the same value as time('now').
  1010   1010   */
................................................................................
  1083   1083     sqlite4_mutex_enter(sqlite4MutexAlloc(SQLITE4_MUTEX_STATIC_MASTER));
  1084   1084     pTm = gmtime(&t);
  1085   1085     if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
  1086   1086     sqlite4_mutex_leave(sqlite4MutexAlloc(SQLITE4_MUTEX_STATIC_MASTER));
  1087   1087   #endif
  1088   1088     if( pTm ){
  1089   1089       strftime(zBuf, 20, zFormat, &sNow);
  1090         -    sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT);
         1090  +    sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT, 0);
  1091   1091     }
  1092   1092   }
  1093   1093   #endif
  1094   1094   
  1095   1095   /*
  1096   1096   ** This function registered all of the above C functions as SQL
  1097   1097   ** functions.  This should be the only routine in this file with

Changes to src/fts5.c.

  3392   3392       if( zErr==0 ){
  3393   3393         zErr = sqlite4MPrintf(db, "error parsing expression: %d", rc);
  3394   3394       }
  3395   3395       goto fts5_parse_expr_out;
  3396   3396     }
  3397   3397   
  3398   3398     fts5PrintExpr(db, azCol, pExpr, &zRet);
  3399         -  sqlite4_result_text(pCtx, zRet, -1, SQLITE4_TRANSIENT);
         3399  +  sqlite4_result_text(pCtx, zRet, -1, SQLITE4_TRANSIENT, 0);
  3400   3400     fts5ExpressionFree(db, pExpr);
  3401   3401     sqlite4_free(sqlite4_db_env(db), zRet);
  3402   3402   
  3403   3403    fts5_parse_expr_out:
  3404   3404     if( p ) pTok->xDestroy(p);
  3405   3405     sqlite4DbFree(db, azCol);
  3406   3406     sqlite4_finalize(pStmt);
................................................................................
  3419   3419     int rc = sqlite4_create_function(
  3420   3420         db, "fts5_parse_expr", 3, SQLITE4_UTF8, 0, fts5_parse_expr, 0, 0
  3421   3421     );
  3422   3422     if( rc!=SQLITE4_OK ) return rc;
  3423   3423   #endif
  3424   3424     return sqlite4InitFts5Func(db);
  3425   3425   }
  3426         -

Changes to src/fts5func.c.

    45     45   struct Fts5RankCtx {
    46     46     sqlite4 *db;
    47     47     double *aAvgdl;                 /* Average document size of each field */
    48     48     int nPhrase;                    /* Number of phrases in query */
    49     49     double *aIdf;                   /* IDF weights for each phrase in query */
    50     50   };
    51     51   
    52         -static void fts5RankFreeCtx(void *pCtx){
           52  +static void fts5RankFreeCtx(void *pNotUsed, void *pCtx){
    53     53     if( pCtx ){
    54     54       Fts5RankCtx *p = (Fts5RankCtx *)pCtx;
    55     55       sqlite4DbFree(p->db, p);
    56     56     }
    57     57   }
    58     58   
    59     59   #define BM25_EXPLAIN  0x01
................................................................................
   132    132     if( p==0 ){
   133    133       int nPhrase;                  /* Number of phrases in query expression */
   134    134       int nByte;                    /* Number of bytes of data to allocate */
   135    135   
   136    136       sqlite4_mi_phrase_count(pCtx, &nPhrase);
   137    137       nByte = sizeof(Fts5RankCtx) + (nPhrase+nField) * sizeof(double);
   138    138       p = (Fts5RankCtx *)sqlite4DbMallocZero(db, nByte);
   139         -    sqlite4_set_auxdata(pCtx, 0, (void *)p, fts5RankFreeCtx);
          139  +    sqlite4_set_auxdata(pCtx, 0, (void *)p, fts5RankFreeCtx, 0);
   140    140       p = sqlite4_get_auxdata(pCtx, 0);
   141    141   
   142    142       if( !p ){
   143    143         rc = SQLITE4_NOMEM;
   144    144       }else{
   145    145         int N;                      /* Total number of docs in collection */
   146    146         int ni;                     /* Number of docs with phrase i */
................................................................................
   266    266     }
   267    267   
   268    268     if( rc==SQLITE4_OK ){
   269    269       if( bExplain ){
   270    270         zExplain = sqlite4MAppendf(
   271    271             db, zExplain, "%s</table><b>overall rank=%.2f</b>", zExplain, rank
   272    272         );
   273         -      sqlite4_result_text(pCtx, zExplain, -1, SQLITE4_TRANSIENT);
          273  +      sqlite4_result_text(pCtx, zExplain, -1, SQLITE4_TRANSIENT, 0);
   274    274       }else{
   275    275         sqlite4_result_double(pCtx, rank);
   276    276       }
   277    277     }else{
   278    278       sqlite4_result_error_code(pCtx, rc);
   279    279     }
   280    280     sqlite4DbFree(db, zExplain);
................................................................................
   589    589           if( rc==SQLITE4_OK ){
   590    590             fts5SnippetImprove(pCtx, nTok, nSz, &aSnip[i]);
   591    591             rc = fts5SnippetText(
   592    592                 pCtx, &aSnip[i], &text, nTok, zStart, zEnd, zEllipses
   593    593             );
   594    594           }
   595    595         }
   596         -      sqlite4_result_text(pCtx, text.zOut, text.nOut, SQLITE4_TRANSIENT);
          596  +      sqlite4_result_text(pCtx, text.zOut, text.nOut, SQLITE4_TRANSIENT, 0);
   597    597         sqlite4DbFree(sqlite4_context_db_handle(pCtx), text.zOut);
   598    598         break;
   599    599       }
   600    600     }
   601    601   
   602    602     if( rc!=SQLITE4_OK ){
   603    603       sqlite4_result_error_code(pCtx, rc);
................................................................................
   666    666       void *p = SQLITE4_INT_TO_PTR(aRank[i].mask);
   667    667       const char *z = aRank[i].zName;
   668    668       rc = sqlite4_create_mi_function(db, z, -1, SQLITE4_UTF8, p, fts5Rank, 0);
   669    669     }
   670    670   
   671    671     return rc;
   672    672   }
   673         -

Changes to src/func.c.

    71     71     switch( sqlite4_value_type(argv[0]) ){
    72     72       case SQLITE4_INTEGER: z = "integer"; break;
    73     73       case SQLITE4_TEXT:    z = "text";    break;
    74     74       case SQLITE4_FLOAT:   z = "real";    break;
    75     75       case SQLITE4_BLOB:    z = "blob";    break;
    76     76       default:             z = "null";    break;
    77     77     }
    78         -  sqlite4_result_text(context, z, -1, SQLITE4_STATIC);
           78  +  sqlite4_result_text(context, z, -1, SQLITE4_STATIC, 0);
    79     79   }
    80     80   
    81     81   
    82     82   /*
    83     83   ** Implementation of the length() function
    84     84   */
    85     85   static void lengthFunc(
................................................................................
   240    240       while( *z && p1 ){
   241    241         SQLITE4_SKIP_UTF8(z);
   242    242         p1--;
   243    243       }
   244    244       for(z2=z; *z2 && p2; p2--){
   245    245         SQLITE4_SKIP_UTF8(z2);
   246    246       }
   247         -    sqlite4_result_text(context, (char*)z, (int)(z2-z), SQLITE4_TRANSIENT);
          247  +    sqlite4_result_text(context, (char*)z, (int)(z2-z), SQLITE4_TRANSIENT, 0);
   248    248     }else{
   249    249       if( p1+p2>len ){
   250    250         p2 = len-p1;
   251    251         if( p2<0 ) p2 = 0;
   252    252       }
   253         -    sqlite4_result_blob(context, (char*)&z[p1], (int)p2, SQLITE4_TRANSIENT);
          253  +    sqlite4_result_blob(context, (char*)&z[p1], (int)p2, SQLITE4_TRANSIENT, 0);
   254    254     }
   255    255   }
   256    256   
   257    257   /*
   258    258   ** Implementation of the round() function
   259    259   */
   260    260   #ifndef SQLITE4_OMIT_FLOATING_POINT
................................................................................
   332    332     assert( z2==(char*)sqlite4_value_text(argv[0]) );
   333    333     if( z2 ){
   334    334       z1 = contextMalloc(context, ((i64)n)+1);
   335    335       if( z1 ){
   336    336         for(i=0; i<n; i++){
   337    337           z1[i] = (char)sqlite4Toupper(z2[i]);
   338    338         }
   339         -      sqlite4_result_text(context, z1, n, SQLITE4_DYNAMIC);
          339  +      sqlite4_result_text(context, z1, n, SQLITE4_DYNAMIC, 0);
   340    340       }
   341    341     }
   342    342   }
   343    343   static void lowerFunc(sqlite4_context *context, int argc, sqlite4_value **argv){
   344    344     char *z1;
   345    345     const char *z2;
   346    346     int i, n;
................................................................................
   351    351     assert( z2==(char*)sqlite4_value_text(argv[0]) );
   352    352     if( z2 ){
   353    353       z1 = contextMalloc(context, ((i64)n)+1);
   354    354       if( z1 ){
   355    355         for(i=0; i<n; i++){
   356    356           z1[i] = sqlite4Tolower(z2[i]);
   357    357         }
   358         -      sqlite4_result_text(context, z1, n, SQLITE4_DYNAMIC);
          358  +      sqlite4_result_text(context, z1, n, SQLITE4_DYNAMIC, 0);
   359    359       }
   360    360     }
   361    361   }
   362    362   
   363    363   
   364    364   #if 0  /* This function is never used. */
   365    365   /*
................................................................................
   430    430     n = sqlite4_value_int(argv[0]);
   431    431     if( n<1 ){
   432    432       n = 1;
   433    433     }
   434    434     p = contextMalloc(context, n);
   435    435     if( p ){
   436    436       sqlite4_randomness(sqlite4_context_env(context), n, p);
   437         -    sqlite4_result_blob(context, (char*)p, n, SQLITE4_DYNAMIC);
          437  +    sqlite4_result_blob(context, (char*)p, n, SQLITE4_DYNAMIC, 0);
   438    438     }
   439    439   }
   440    440   
   441    441   /*
   442    442   ** Implementation of the last_insert_rowid() SQL function.  The return
   443    443   ** value is the same as the sqlite4_last_insert_rowid() API function.
   444    444   */
................................................................................
   750    750     sqlite4_context *context,
   751    751     int NotUsed,
   752    752     sqlite4_value **NotUsed2
   753    753   ){
   754    754     UNUSED_PARAMETER2(NotUsed, NotUsed2);
   755    755     /* IMP: R-48699-48617 This function is an SQL wrapper around the
   756    756     ** sqlite4_libversion() C-interface. */
   757         -  sqlite4_result_text(context, sqlite4_libversion(), -1, SQLITE4_STATIC);
          757  +  sqlite4_result_text(context, sqlite4_libversion(), -1, SQLITE4_STATIC, 0);
   758    758   }
   759    759   
   760    760   /*
   761    761   ** Implementation of the sqlite_source_id() function. The result is a string
   762    762   ** that identifies the particular version of the source code used to build
   763    763   ** SQLite.
   764    764   */
................................................................................
   766    766     sqlite4_context *context,
   767    767     int NotUsed,
   768    768     sqlite4_value **NotUsed2
   769    769   ){
   770    770     UNUSED_PARAMETER2(NotUsed, NotUsed2);
   771    771     /* IMP: R-24470-31136 This function is an SQL wrapper around the
   772    772     ** sqlite4_sourceid() C interface. */
   773         -  sqlite4_result_text(context, sqlite4_sourceid(), -1, SQLITE4_STATIC);
          773  +  sqlite4_result_text(context, sqlite4_sourceid(), -1, SQLITE4_STATIC, 0);
   774    774   }
   775    775   
   776    776   /*
   777    777   ** Implementation of the sqlite_log() function.  This is a wrapper around
   778    778   ** sqlite4_log().  The return value is NULL.  The function exists purely for
   779    779   ** its side-effects.
   780    780   */
................................................................................
   826    826     int n;
   827    827     assert( argc==1 );
   828    828     UNUSED_PARAMETER(argc);
   829    829     /* IMP: R-04922-24076 The sqlite_compileoption_get() SQL function
   830    830     ** is a wrapper around the sqlite4_compileoption_get() C/C++ function.
   831    831     */
   832    832     n = sqlite4_value_int(argv[0]);
   833         -  sqlite4_result_text(context, sqlite4_compileoption_get(n), -1, SQLITE4_STATIC);
          833  +  sqlite4_result_text(context, sqlite4_compileoption_get(n), -1,
          834  +                      SQLITE4_STATIC, 0);
   834    835   }
   835    836   #endif /* SQLITE4_OMIT_COMPILEOPTION_DIAGS */
   836    837   
   837    838   /* Array for converting from half-bytes (nybbles) into ASCII hex
   838    839   ** digits. */
   839    840   static const char hexdigits[] = {
   840    841     '0', '1', '2', '3', '4', '5', '6', '7',
................................................................................
   873    874             zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
   874    875             zText[(i*2)+3] = hexdigits[(zBlob[i])&0x0F];
   875    876           }
   876    877           zText[(nBlob*2)+2] = '\'';
   877    878           zText[(nBlob*2)+3] = '\0';
   878    879           zText[0] = 'x';
   879    880           zText[1] = '\'';
   880         -        sqlite4_result_text(context, zText, -1, SQLITE4_TRANSIENT);
          881  +        sqlite4_result_text(context, zText, -1, SQLITE4_TRANSIENT, 0);
   881    882           sqlite4_free(sqlite4_context_env(context), zText);
   882    883         }
   883    884         break;
   884    885       }
   885    886       case SQLITE4_TEXT: {
   886    887         int i,j;
   887    888         u64 n;
................................................................................
   897    898             z[j++] = zArg[i];
   898    899             if( zArg[i]=='\'' ){
   899    900               z[j++] = '\'';
   900    901             }
   901    902           }
   902    903           z[j++] = '\'';
   903    904           z[j] = 0;
   904         -        sqlite4_result_text(context, z, j, SQLITE4_DYNAMIC);
          905  +        sqlite4_result_text(context, z, j, SQLITE4_DYNAMIC, 0);
   905    906         }
   906    907         break;
   907    908       }
   908    909       default: {
   909    910         assert( sqlite4_value_type(argv[0])==SQLITE4_NULL );
   910         -      sqlite4_result_text(context, "NULL", 4, SQLITE4_STATIC);
          911  +      sqlite4_result_text(context, "NULL", 4, SQLITE4_STATIC, 0);
   911    912         break;
   912    913       }
   913    914     }
   914    915   }
   915    916   
   916    917   /*
   917    918   ** The hex() function.  Interpret the argument as a blob.  Return
................................................................................
   934    935     if( zHex ){
   935    936       for(i=0; i<n; i++, pBlob++){
   936    937         unsigned char c = *pBlob;
   937    938         *(z++) = hexdigits[(c>>4)&0xf];
   938    939         *(z++) = hexdigits[c&0xf];
   939    940       }
   940    941       *z = 0;
   941         -    sqlite4_result_text(context, zHex, n*2, SQLITE4_DYNAMIC);
          942  +    sqlite4_result_text(context, zHex, n*2, SQLITE4_DYNAMIC, 0);
   942    943     }
   943    944   }
   944    945   
   945    946   /*
   946    947   ** The zeroblob(N) function returns a zero-filled blob of size N bytes.
   947    948   */
   948    949   static void zeroblobFunc(
................................................................................
  1043   1044       }
  1044   1045     }
  1045   1046     assert( j+nStr-i+1==nOut );
  1046   1047     memcpy(&zOut[j], &zStr[i], nStr-i);
  1047   1048     j += nStr - i;
  1048   1049     assert( j<=nOut );
  1049   1050     zOut[j] = 0;
  1050         -  sqlite4_result_text(context, (char*)zOut, j, SQLITE4_DYNAMIC);
         1051  +  sqlite4_result_text(context, (char*)zOut, j, SQLITE4_DYNAMIC, 0);
  1051   1052   }
  1052   1053   
  1053   1054   /*
  1054   1055   ** Implementation of the TRIM(), LTRIM(), and RTRIM() functions.
  1055   1056   ** The userdata is 0x1 for left trim, 0x2 for right trim, 0x3 for both.
  1056   1057   */
  1057   1058   static void trimFunc(
................................................................................
  1127   1128           nIn -= len;
  1128   1129         }
  1129   1130       }
  1130   1131       if( zCharSet ){
  1131   1132         sqlite4_free(sqlite4_context_env(context), azChar);
  1132   1133       }
  1133   1134     }
  1134         -  sqlite4_result_text(context, (char*)zIn, nIn, SQLITE4_TRANSIENT);
         1135  +  sqlite4_result_text(context, (char*)zIn, nIn, SQLITE4_TRANSIENT, 0);
  1135   1136   }
  1136   1137   
  1137   1138   
  1138   1139   /* IMP: R-25361-16150 This function is omitted from SQLite by default. It
  1139   1140   ** is only available if the SQLITE4_SOUNDEX compile-time option is used
  1140   1141   ** when SQLite is built.
  1141   1142   */
................................................................................
  1182   1183           prevcode = 0;
  1183   1184         }
  1184   1185       }
  1185   1186       while( j<4 ){
  1186   1187         zResult[j++] = '0';
  1187   1188       }
  1188   1189       zResult[j] = 0;
  1189         -    sqlite4_result_text(context, zResult, 4, SQLITE4_TRANSIENT);
         1190  +    sqlite4_result_text(context, zResult, 4, SQLITE4_TRANSIENT, 0);
  1190   1191     }else{
  1191   1192       /* IMP: R-64894-50321 The string "?000" is returned if the argument
  1192   1193       ** is NULL or contains no ASCII alphabetic characters. */
  1193         -    sqlite4_result_text(context, "?000", 4, SQLITE4_STATIC);
         1194  +    sqlite4_result_text(context, "?000", 4, SQLITE4_STATIC, 0);
  1194   1195     }
  1195   1196   }
  1196   1197   #endif /* SQLITE4_SOUNDEX */
  1197   1198   
  1198   1199   #if 0 /*ndef SQLITE4_OMIT_LOAD_EXTENSION*/
  1199   1200   /*
  1200   1201   ** A function that loads a shared-library extension then returns NULL.
................................................................................
  1414   1415     if( pAccum ){
  1415   1416       if( pAccum->tooBig ){
  1416   1417         sqlite4_result_error_toobig(context);
  1417   1418       }else if( pAccum->mallocFailed ){
  1418   1419         sqlite4_result_error_nomem(context);
  1419   1420       }else{    
  1420   1421         sqlite4_result_text(context, sqlite4StrAccumFinish(pAccum), -1, 
  1421         -                          SQLITE4_DYNAMIC);
         1422  +                          SQLITE4_DYNAMIC, 0);
  1422   1423       }
  1423   1424     }
  1424   1425   }
  1425   1426   
  1426   1427   /*
  1427   1428   ** This routine does per-connection function registration.  Most
  1428   1429   ** of the built-in functions above are part of the global function set.

Changes to src/main.c.

    25     25   #ifdef SQLITE4_ENABLE_ICU
    26     26   # include "sqliteicu.h"
    27     27   #endif
    28     28   
    29     29   /*
    30     30   ** Dummy function used as a unique symbol for SQLITE4_DYNAMIC
    31     31   */
    32         -void sqlite4_dynamic(void *p){ (void)p; }
           32  +void sqlite4_dynamic(void *pArg,void *p){ (void)pArg; (void)p; }
    33     33   
    34     34   #ifndef SQLITE4_AMALGAMATION
    35     35   /* IMPLEMENTATION-OF: R-46656-45156 The sqlite4_version[] string constant
    36     36   ** contains the text of SQLITE4_VERSION macro. 
    37     37   */
    38     38   const char sqlite4_version[] = SQLITE4_VERSION;
    39     39   #endif
................................................................................
  1263   1263     sqlite4_mutex_enter(db->mutex);
  1264   1264     if( db->mallocFailed ){
  1265   1265       z = (void *)outOfMem;
  1266   1266     }else{
  1267   1267       z = sqlite4_value_text16(db->pErr);
  1268   1268       if( z==0 ){
  1269   1269         sqlite4ValueSetStr(db->pErr, -1, sqlite4ErrStr(db->errCode),
  1270         -           SQLITE4_UTF8, SQLITE4_STATIC);
         1270  +           SQLITE4_UTF8, SQLITE4_STATIC, 0);
  1271   1271         z = sqlite4_value_text16(db->pErr);
  1272   1272       }
  1273   1273       /* A malloc() may have failed within the call to sqlite4_value_text16()
  1274   1274       ** above. If this is the case, then the db->mallocFailed flag needs to
  1275   1275       ** be cleared before returning. Do this directly, instead of via
  1276   1276       ** sqlite4ApiExit(), to avoid setting the database handle error message.
  1277   1277       */

Changes to src/shell.c.

   317    317     int argc,
   318    318     sqlite4_value **argv
   319    319   ){
   320    320     assert( 0==argc );
   321    321     assert( zShellStatic );
   322    322     UNUSED_PARAMETER(argc);
   323    323     UNUSED_PARAMETER(argv);
   324         -  sqlite4_result_text(context, zShellStatic, -1, SQLITE4_STATIC);
          324  +  sqlite4_result_text(context, zShellStatic, -1, SQLITE4_STATIC, 0);
   325    325   }
   326    326   
   327    327   
   328    328   /*
   329    329   ** This routine reads a line of text from FILE in, stores
   330    330   ** the text in memory obtained from malloc() and returns a pointer
   331    331   ** to the text.  NULL is returned at end of file, or if malloc()
................................................................................
  1803   1803             int k;
  1804   1804             for(z=azCol[i], j=1, k=0; z[j]; j++){
  1805   1805               if( z[j]=='"' ){ j++; if( z[j]==0 ) break; }
  1806   1806               z[k++] = z[j];
  1807   1807             }
  1808   1808             z[k] = 0;
  1809   1809           }
  1810         -        sqlite4_bind_text(pStmt, i+1, azCol[i], -1, SQLITE4_STATIC);
         1810  +        sqlite4_bind_text(pStmt, i+1, azCol[i], -1, SQLITE4_STATIC, 0);
  1811   1811         }
  1812   1812         sqlite4_step(pStmt);
  1813   1813         rc = sqlite4_reset(pStmt);
  1814   1814         free(zLine);
  1815   1815         if( rc!=SQLITE4_OK ){
  1816   1816           fprintf(stderr,"Error: %s\n", sqlite4_errmsg(db));
  1817   1817           zCommit = "ROLLBACK";
................................................................................
  2168   2168       zSql = sqlite4_mprintf(0, "%z ORDER BY 1", zSql);
  2169   2169       rc = sqlite4_prepare(p->db, zSql, -1, &pStmt, 0);
  2170   2170       sqlite4_free(0, zSql);
  2171   2171       if( rc ) return rc;
  2172   2172       nRow = nAlloc = 0;
  2173   2173       azResult = 0;
  2174   2174       if( nArg>1 ){
  2175         -      sqlite4_bind_text(pStmt, 1, azArg[1], -1, SQLITE4_TRANSIENT);
         2175  +      sqlite4_bind_text(pStmt, 1, azArg[1], -1, SQLITE4_TRANSIENT, 0);
  2176   2176       }else{
  2177         -      sqlite4_bind_text(pStmt, 1, "%", -1, SQLITE4_STATIC);
         2177  +      sqlite4_bind_text(pStmt, 1, "%", -1, SQLITE4_STATIC, 0);
  2178   2178       }
  2179   2179       while( sqlite4_step(pStmt)==SQLITE4_ROW ){
  2180   2180         if( nRow>=nAlloc ){
  2181   2181           char **azNew;
  2182   2182           int n = nAlloc*2 + 10;
  2183   2183           azNew = sqlite4_realloc(0, azResult, sizeof(azResult[0])*n);
  2184   2184           if( azNew==0 ){

Changes to src/sqlite.h.in.

  1829   1829   ** [error code] if anything goes wrong.
  1830   1830   ** ^[SQLITE4_RANGE] is returned if the parameter
  1831   1831   ** index is out of range.  ^[SQLITE4_NOMEM] is returned if malloc() fails.
  1832   1832   **
  1833   1833   ** See also: [sqlite4_bind_parameter_count()],
  1834   1834   ** [sqlite4_bind_parameter_name()], and [sqlite4_bind_parameter_index()].
  1835   1835   */
  1836         -int sqlite4_bind_blob(sqlite4_stmt*, int, const void*, int n, void(*)(void*));
         1836  +int sqlite4_bind_blob(sqlite4_stmt*, int, const void*, int n, 
         1837  +                      void(*)(void*,void*),void*);
  1837   1838   int sqlite4_bind_double(sqlite4_stmt*, int, double);
  1838   1839   int sqlite4_bind_int(sqlite4_stmt*, int, int);
  1839   1840   int sqlite4_bind_int64(sqlite4_stmt*, int, sqlite4_int64);
  1840   1841   int sqlite4_bind_null(sqlite4_stmt*, int);
  1841         -int sqlite4_bind_text(sqlite4_stmt*, int, const char*, int n, void(*)(void*));
  1842         -int sqlite4_bind_text16(sqlite4_stmt*, int, const void*, int, void(*)(void*));
         1842  +int sqlite4_bind_text(sqlite4_stmt*, int, const char*, int n,
         1843  +                      void(*)(void*,void*),void*);
         1844  +int sqlite4_bind_text16(sqlite4_stmt*, int, const void*, int,
         1845  +                        void(*)(void*,void*),void*);
  1843   1846   int sqlite4_bind_value(sqlite4_stmt*, int, const sqlite4_value*);
  1844   1847   int sqlite4_bind_zeroblob(sqlite4_stmt*, int, int n);
  1845   1848   
  1846   1849   /*
  1847   1850   ** CAPIREF: Number Of SQL Parameters
  1848   1851   **
  1849   1852   ** ^This routine can be used to find the number of [SQL parameters]
................................................................................
  2660   2663   ** expressions that are constant at compile time. This includes literal
  2661   2664   ** values and [parameters].)^
  2662   2665   **
  2663   2666   ** These routines must be called from the same thread in which
  2664   2667   ** the SQL function is running.
  2665   2668   */
  2666   2669   void *sqlite4_get_auxdata(sqlite4_context*, int N);
  2667         -void sqlite4_set_auxdata(sqlite4_context*, int N, void*, void (*)(void*));
         2670  +void sqlite4_set_auxdata(sqlite4_context*, int N, void*,
         2671  +                         void (*)(void*,void*),void*);
  2668   2672   
  2669   2673   
  2670   2674   /*
  2671   2675   ** CAPIREF: Constants Defining Special Destructor Behavior
  2672   2676   **
  2673   2677   ** These are special values for the destructor that is passed in as the
  2674   2678   ** final argument to routines like [sqlite4_result_blob()].  ^If the destructor
................................................................................
  2677   2681   ** SQLITE4_TRANSIENT value means that the content will likely change in
  2678   2682   ** the near future and that SQLite should make its own private copy of
  2679   2683   ** the content before returning.
  2680   2684   **
  2681   2685   ** The typedef is necessary to work around problems in certain
  2682   2686   ** C++ compilers.  See ticket #2191.
  2683   2687   */
  2684         -typedef void (*sqlite4_destructor_type)(void*);
  2685         -void sqlite4_dynamic(void*);
         2688  +typedef void (*sqlite4_destructor_type)(void*,void*);
         2689  +void sqlite4_dynamic(void*,void*);
  2686   2690   #define SQLITE4_STATIC      ((sqlite4_destructor_type)0)
  2687   2691   #define SQLITE4_TRANSIENT   ((sqlite4_destructor_type)-1)
  2688   2692   #define SQLITE4_DYNAMIC     (sqlite4_dynamic)
  2689   2693   
  2690   2694   
  2691   2695   /*
  2692   2696   ** CAPIREF: Setting The Result Of An SQL Function
................................................................................
  2794   2798   ** [unprotected sqlite4_value] object is required, so either
  2795   2799   ** kind of [sqlite4_value] object can be used with this interface.
  2796   2800   **
  2797   2801   ** If these routines are called from within the different thread
  2798   2802   ** than the one containing the application-defined function that received
  2799   2803   ** the [sqlite4_context] pointer, the results are undefined.
  2800   2804   */
  2801         -void sqlite4_result_blob(sqlite4_context*, const void*, int, void(*)(void*));
         2805  +void sqlite4_result_blob(sqlite4_context*, const void*, int,
         2806  +                         void(*)(void*,void*),void*);
  2802   2807   void sqlite4_result_double(sqlite4_context*, double);
  2803   2808   void sqlite4_result_error(sqlite4_context*, const char*, int);
  2804   2809   void sqlite4_result_error16(sqlite4_context*, const void*, int);
  2805   2810   void sqlite4_result_error_toobig(sqlite4_context*);
  2806   2811   void sqlite4_result_error_nomem(sqlite4_context*);
  2807   2812   void sqlite4_result_error_code(sqlite4_context*, int);
  2808   2813   void sqlite4_result_int(sqlite4_context*, int);
  2809   2814   void sqlite4_result_int64(sqlite4_context*, sqlite4_int64);
  2810   2815   void sqlite4_result_null(sqlite4_context*);
  2811         -void sqlite4_result_text(sqlite4_context*, const char*, int, void(*)(void*));
  2812         -void sqlite4_result_text16(sqlite4_context*, const void*, int, void(*)(void*));
  2813         -void sqlite4_result_text16le(sqlite4_context*, const void*, int,void(*)(void*));
  2814         -void sqlite4_result_text16be(sqlite4_context*, const void*, int,void(*)(void*));
         2816  +void sqlite4_result_text(sqlite4_context*, const char*, int,
         2817  +                         void(*)(void*,void*),void*);
         2818  +void sqlite4_result_text16(sqlite4_context*, const void*, int,
         2819  +                           void(*)(void*,void*),void*);
         2820  +void sqlite4_result_text16le(sqlite4_context*, const void*, int,
         2821  +                             void(*)(void*,void*),void*);
         2822  +void sqlite4_result_text16be(sqlite4_context*, const void*, int,
         2823  +                             void(*)(void*,void*),void*);
  2815   2824   void sqlite4_result_value(sqlite4_context*, sqlite4_value*);
  2816   2825   void sqlite4_result_zeroblob(sqlite4_context*, int n);
  2817   2826   
  2818   2827   /*
  2819   2828   ** CAPIREF: Define New Collating Sequences
  2820   2829   **
  2821   2830   ** ^This function adds, removes, or modifies a [collation] associated

Changes to src/sqliteInt.h.

  2962   2962   # define sqlite4FileSuffix3(X,Y)
  2963   2963   #endif
  2964   2964   u8 sqlite4GetBoolean(const char *z);
  2965   2965   
  2966   2966   const void *sqlite4ValueText(sqlite4_value*, u8);
  2967   2967   int sqlite4ValueBytes(sqlite4_value*, u8);
  2968   2968   void sqlite4ValueSetStr(sqlite4_value*, int, const void *,u8, 
  2969         -                        void(*)(void*));
         2969  +                        void(*)(void*,void*),void*);
  2970   2970   void sqlite4ValueFree(sqlite4_value*);
  2971   2971   sqlite4_value *sqlite4ValueNew(sqlite4 *);
  2972   2972   char *sqlite4Utf16to8(sqlite4 *, const void*, int, u8);
  2973   2973   #ifdef SQLITE4_ENABLE_STAT3
  2974   2974   char *sqlite4Utf8to16(sqlite4 *, u8, char *, int, int *);
  2975   2975   #endif
  2976   2976   int sqlite4ValueFromExpr(sqlite4 *, Expr *, u8, u8, sqlite4_value **);

Changes to src/tclsqlite.c.

   502    502       u8 *data;
   503    503       const char *zType = (pVar->typePtr ? pVar->typePtr->name : "");
   504    504       char c = zType[0];
   505    505       if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){
   506    506         /* Only return a BLOB type if the Tcl variable is a bytearray and
   507    507         ** has no string representation. */
   508    508         data = Tcl_GetByteArrayFromObj(pVar, &n);
   509         -      sqlite4_result_blob(context, data, n, SQLITE4_TRANSIENT);
          509  +      sqlite4_result_blob(context, data, n, SQLITE4_TRANSIENT, 0);
   510    510       }else if( c=='b' && strcmp(zType,"boolean")==0 ){
   511    511         Tcl_GetIntFromObj(0, pVar, &n);
   512    512         sqlite4_result_int(context, n);
   513    513       }else if( c=='d' && strcmp(zType,"double")==0 ){
   514    514         double r;
   515    515         Tcl_GetDoubleFromObj(0, pVar, &r);
   516    516         sqlite4_result_double(context, r);
................................................................................
   517    517       }else if( (c=='w' && strcmp(zType,"wideInt")==0) ||
   518    518             (c=='i' && strcmp(zType,"int")==0) ){
   519    519         Tcl_WideInt v;
   520    520         Tcl_GetWideIntFromObj(0, pVar, &v);
   521    521         sqlite4_result_int64(context, v);
   522    522       }else{
   523    523         data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
   524         -      sqlite4_result_text(context, (char *)data, n, SQLITE4_TRANSIENT);
          524  +      sqlite4_result_text(context, (char *)data, n, SQLITE4_TRANSIENT, 0);
   525    525       }
   526    526     }
   527    527   }
   528    528   
   529    529   #ifndef SQLITE4_OMIT_AUTHORIZATION
   530    530   /*
   531    531   ** This is the authentication function.  It appends the authentication
................................................................................
   844    844           char c = zType[0];
   845    845           if( zVar[0]=='@' ||
   846    846              (c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0) ){
   847    847             /* Load a BLOB type if the Tcl variable is a bytearray and
   848    848             ** it has no string representation or the host
   849    849             ** parameter name begins with "@". */
   850    850             data = Tcl_GetByteArrayFromObj(pVar, &n);
   851         -          sqlite4_bind_blob(pStmt, i, data, n, SQLITE4_STATIC);
          851  +          sqlite4_bind_blob(pStmt, i, data, n, SQLITE4_STATIC, 0);
   852    852             Tcl_IncrRefCount(pVar);
   853    853             pPreStmt->apParm[iParm++] = pVar;
   854    854           }else if( c=='b' && strcmp(zType,"boolean")==0 ){
   855    855             Tcl_GetIntFromObj(interp, pVar, &n);
   856    856             sqlite4_bind_int(pStmt, i, n);
   857    857           }else if( c=='d' && strcmp(zType,"double")==0 ){
   858    858             double r;
................................................................................
   861    861           }else if( (c=='w' && strcmp(zType,"wideInt")==0) ||
   862    862                 (c=='i' && strcmp(zType,"int")==0) ){
   863    863             Tcl_WideInt v;
   864    864             Tcl_GetWideIntFromObj(interp, pVar, &v);
   865    865             sqlite4_bind_int64(pStmt, i, v);
   866    866           }else{
   867    867             data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
   868         -          sqlite4_bind_text(pStmt, i, (char *)data, n, SQLITE4_STATIC);
          868  +          sqlite4_bind_text(pStmt, i, (char *)data, n, SQLITE4_STATIC, 0);
   869    869             Tcl_IncrRefCount(pVar);
   870    870             pPreStmt->apParm[iParm++] = pVar;
   871    871           }
   872    872         }else{
   873    873           sqlite4_bind_null(pStmt, i);
   874    874         }
   875    875       }
................................................................................
  1666   1666         for(i=0; i<nCol; i++){
  1667   1667           /* check for null data, if so, bind as null */
  1668   1668           if( (nNull>0 && strcmp(azCol[i], zNull)==0)
  1669   1669             || strlen30(azCol[i])==0 
  1670   1670           ){
  1671   1671             sqlite4_bind_null(pStmt, i+1);
  1672   1672           }else{
  1673         -          sqlite4_bind_text(pStmt, i+1, azCol[i], -1, SQLITE4_STATIC);
         1673  +          sqlite4_bind_text(pStmt, i+1, azCol[i], -1, SQLITE4_STATIC, 0);
  1674   1674           }
  1675   1675         }
  1676   1676         sqlite4_step(pStmt);
  1677   1677         rc = sqlite4_reset(pStmt);
  1678   1678         free(zLine);
  1679   1679         if( rc!=SQLITE4_OK ){
  1680   1680           Tcl_AppendResult(interp,"Error: ", sqlite4_errmsg(pDb->db), 0);
................................................................................
  2799   2799   static void md5finalize(sqlite4_context *context){
  2800   2800     MD5Context *p;
  2801   2801     unsigned char digest[16];
  2802   2802     char zBuf[33];
  2803   2803     p = sqlite4_aggregate_context(context, sizeof(*p));
  2804   2804     MD5Final(digest,p);
  2805   2805     MD5DigestToBase16(digest, zBuf);
  2806         -  sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT);
         2806  +  sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT, 0);
  2807   2807   }
  2808   2808   int Md5_Register(sqlite4 *db){
  2809   2809     int rc = sqlite4_create_function(db, "md5sum", -1, SQLITE4_UTF8, 0, 0, 
  2810   2810                                    md5step, md5finalize);
  2811   2811     sqlite4_overload_function(db, "md5sum", -1);  /* To exercise this API */
  2812   2812     return rc;
  2813   2813   }

Changes to src/utf.c.

   470    470   **
   471    471   ** NULL is returned if there is an allocation error.
   472    472   */
   473    473   char *sqlite4Utf16to8(sqlite4 *db, const void *z, int nByte, u8 enc){
   474    474     Mem m;
   475    475     memset(&m, 0, sizeof(m));
   476    476     m.db = db;
   477         -  sqlite4VdbeMemSetStr(&m, z, nByte, enc, SQLITE4_STATIC);
          477  +  sqlite4VdbeMemSetStr(&m, z, nByte, enc, SQLITE4_STATIC, 0);
   478    478     sqlite4VdbeChangeEncoding(&m, SQLITE4_UTF8);
   479    479     if( db->mallocFailed ){
   480    480       sqlite4VdbeMemRelease(&m);
   481    481       m.z = 0;
   482    482     }
   483    483     assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
   484    484     assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
................................................................................
   498    498   ** flag set.
   499    499   */
   500    500   #ifdef SQLITE4_ENABLE_STAT3
   501    501   char *sqlite4Utf8to16(sqlite4 *db, u8 enc, char *z, int n, int *pnOut){
   502    502     Mem m;
   503    503     memset(&m, 0, sizeof(m));
   504    504     m.db = db;
   505         -  sqlite4VdbeMemSetStr(&m, z, n, SQLITE4_UTF8, SQLITE4_STATIC);
          505  +  sqlite4VdbeMemSetStr(&m, z, n, SQLITE4_UTF8, SQLITE4_STATIC, 0);
   506    506     if( sqlite4VdbeMemTranslate(&m, enc) ){
   507    507       assert( db->mallocFailed );
   508    508       return 0;
   509    509     }
   510    510     assert( m.z==m.zMalloc );
   511    511     *pnOut = m.n;
   512    512     return m.z;

Changes to src/util.c.

   128    128       db->errCode = err_code;
   129    129       if( zFormat ){
   130    130         char *z;
   131    131         va_list ap;
   132    132         va_start(ap, zFormat);
   133    133         z = sqlite4VMPrintf(db, zFormat, ap);
   134    134         va_end(ap);
   135         -      sqlite4ValueSetStr(db->pErr, -1, z, SQLITE4_UTF8, SQLITE4_DYNAMIC);
          135  +      sqlite4ValueSetStr(db->pErr, -1, z, SQLITE4_UTF8, SQLITE4_DYNAMIC, 0);
   136    136       }else{
   137         -      sqlite4ValueSetStr(db->pErr, 0, 0, SQLITE4_UTF8, SQLITE4_STATIC);
          137  +      sqlite4ValueSetStr(db->pErr, 0, 0, SQLITE4_UTF8, SQLITE4_STATIC, 0);
   138    138       }
   139    139     }
   140    140   }
   141    141   
   142    142   /*
   143    143   ** Add an error message to pParse->zErrMsg and increment pParse->nErr.
   144    144   ** The following formatting characters are allowed:

Changes to src/vdbe.c.

   880    880   case OP_String8: {         /* same as TK_STRING, out2-prerelease */
   881    881     assert( pOp->p4.z!=0 );
   882    882     pOp->opcode = OP_String;
   883    883     pOp->p1 = sqlite4Strlen30(pOp->p4.z);
   884    884   
   885    885   #ifndef SQLITE4_OMIT_UTF16
   886    886     if( encoding!=SQLITE4_UTF8 ){
   887         -    rc = sqlite4VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE4_UTF8, SQLITE4_STATIC);
          887  +    rc = sqlite4VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE4_UTF8,
          888  +                              SQLITE4_STATIC, 0);
   888    889       if( rc==SQLITE4_TOOBIG ) goto too_big;
   889    890       if( SQLITE4_OK!=sqlite4VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
   890    891       assert( pOut->zMalloc==pOut->z );
   891    892       assert( pOut->flags & MEM_Dyn );
   892    893       pOut->zMalloc = 0;
   893    894       pOut->flags |= MEM_Static;
   894    895       pOut->flags &= ~MEM_Dyn;
................................................................................
   946    947   /* Opcode: Blob P1 P2 * P4
   947    948   **
   948    949   ** P4 points to a blob of data P1 bytes long.  Store this
   949    950   ** blob in register P2.
   950    951   */
   951    952   case OP_Blob: {                /* out2-prerelease */
   952    953     assert( pOp->p1 <= SQLITE4_MAX_LENGTH );
   953         -  sqlite4VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
          954  +  sqlite4VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0, 0);
   954    955     pOut->enc = encoding;
   955    956     UPDATE_MAX_BLOBSIZE(pOut);
   956    957     break;
   957    958   }
   958    959   
   959    960   /* Opcode: Variable P1 P2 * P4 *
   960    961   **
................................................................................
  2253   2254   
  2254   2255     if( rc ){
  2255   2256       sqlite4DbFree(db, aRec);
  2256   2257     }else{
  2257   2258       if( nSeq ){
  2258   2259         memcpy(&aRec[nRec], &aSeq[sizeof(aSeq)-nSeq], nSeq);
  2259   2260       }
  2260         -    rc = sqlite4VdbeMemSetStr(pOut, (char *)aRec, nRec+nSeq, 0, SQLITE4_DYNAMIC);
         2261  +    rc = sqlite4VdbeMemSetStr(pOut, (char *)aRec, nRec+nSeq, 0,
         2262  +                              SQLITE4_DYNAMIC, 0);
  2261   2263       REGISTER_TRACE(pOp->p3, pOut);
  2262   2264       UPDATE_MAX_BLOBSIZE(pOut);
  2263   2265     }
  2264   2266   
  2265   2267     break;
  2266   2268   }
  2267   2269   
................................................................................
  2343   2345       aRec = 0;
  2344   2346       rc = sqlite4VdbeEncodeKey(db, 
  2345   2347           pData0, pC->pKeyInfo->nField, pC->iRoot, pC->pKeyInfo, &aRec, &nRec, 0
  2346   2348       );
  2347   2349       if( rc ){
  2348   2350         sqlite4DbFree(db, aRec);
  2349   2351       }else{
  2350         -      rc = sqlite4VdbeMemSetStr(pKeyOut, (char *)aRec, nRec, 0, SQLITE4_DYNAMIC);
         2352  +      rc = sqlite4VdbeMemSetStr(pKeyOut, (char *)aRec, nRec, 0,
         2353  +                                SQLITE4_DYNAMIC, 0);
  2351   2354         REGISTER_TRACE(keyReg, pKeyOut);
  2352   2355         UPDATE_MAX_BLOBSIZE(pKeyOut);
  2353   2356       }
  2354   2357     }
  2355   2358   
  2356   2359     /* If P3 is not 0, compute the data rescord */
  2357   2360     if( rc==SQLITE4_OK && pOp->p3 ){
................................................................................
  2359   2362       pOut = &aMem[pOp->p3];
  2360   2363       memAboutToChange(p, pOut);
  2361   2364       aRec = 0;
  2362   2365       rc = sqlite4VdbeEncodeData(db, pData0, nField, &aRec, &nRec);
  2363   2366       if( rc ){
  2364   2367         sqlite4DbFree(db, aRec);
  2365   2368       }else{
  2366         -      rc = sqlite4VdbeMemSetStr(pOut, (char *)aRec, nRec, 0, SQLITE4_DYNAMIC);
         2369  +      rc = sqlite4VdbeMemSetStr(pOut, (char *)aRec, nRec, 0, SQLITE4_DYNAMIC,0);
  2367   2370         REGISTER_TRACE(pOp->p3, pOut);
  2368   2371         UPDATE_MAX_BLOBSIZE(pOut);
  2369   2372       }
  2370   2373     }
  2371   2374     break;
  2372   2375   }
  2373   2376   
................................................................................
  3517   3520   
  3518   3521     pIn3 = &aMem[pOp->p3];
  3519   3522     if( (pIn3->flags & MEM_Blob) 
  3520   3523      && pIn3->n==nKey && 0==memcmp(pIn3->z, aKey, nKey) 
  3521   3524     ){
  3522   3525       pc = pOp->p2-1;
  3523   3526     }else{
  3524         -    sqlite4VdbeMemSetStr(pIn3, (const char*)aKey, nKey, 0, SQLITE4_TRANSIENT);
         3527  +    sqlite4VdbeMemSetStr(pIn3, (const char*)aKey, nKey, 0, SQLITE4_TRANSIENT,0);
  3525   3528     }
  3526   3529   
  3527   3530     break;
  3528   3531   };
  3529   3532   
  3530   3533   /* Opcode: SorterData P1 P2 * * *
  3531   3534   **
................................................................................
  3584   3587       rc = sqlite4KVCursorKey(pCrsr, &pData, &nData);
  3585   3588     }else{
  3586   3589       rc = sqlite4KVCursorData(pCrsr, 0, -1, &pData, &nData);
  3587   3590     }
  3588   3591     if( rc==SQLITE4_OK && nData>db->aLimit[SQLITE4_LIMIT_LENGTH] ){
  3589   3592       goto too_big;
  3590   3593     }
  3591         -  sqlite4VdbeMemSetStr(pOut, (const char*)pData, nData, 0, SQLITE4_TRANSIENT);
         3594  +  sqlite4VdbeMemSetStr(pOut, (const char*)pData, nData, 0, SQLITE4_TRANSIENT,0);
  3592   3595     pOut->enc = SQLITE4_UTF8;  /* In case the blob is ever cast to text */
  3593   3596     UPDATE_MAX_BLOBSIZE(pOut);
  3594   3597     break;
  3595   3598   }
  3596   3599   
  3597   3600   /* Opcode: Rowid P1 P2 * * *
  3598   3601   **
................................................................................
  4105   4108   
  4106   4109     CHECK_FOR_INTERRUPT;
  4107   4110     pIn1 = &aMem[pOp->p1];
  4108   4111     pOut = &aMem[pOp->p3];
  4109   4112     if( (pIn1->flags & MEM_RowSet)
  4110   4113      && (aKey = sqlite4RowSetRead(pIn1->u.pRowSet, &nKey))
  4111   4114     ){
  4112         -    rc = sqlite4VdbeMemSetStr(pOut, (char const *)aKey, nKey, 0, SQLITE4_TRANSIENT);
         4115  +    rc = sqlite4VdbeMemSetStr(pOut, (char const *)aKey, nKey, 0,
         4116  +                              SQLITE4_TRANSIENT, 0);
  4113   4117       sqlite4RowSetNext(pIn1->u.pRowSet);
  4114   4118     }else{
  4115   4119       /* The RowSet is empty */
  4116   4120       sqlite4VdbeMemSetNull(pIn1);
  4117   4121       pc = pOp->p2 - 1;
  4118   4122     }
  4119   4123   

Changes to src/vdbe.h.

   200    200     int sqlite4VdbeAssertMayAbort(Vdbe *, int);
   201    201     void sqlite4VdbeTrace(Vdbe*,FILE*);
   202    202   #endif
   203    203   void sqlite4VdbeResetStepResult(Vdbe*);
   204    204   void sqlite4VdbeRewind(Vdbe*);
   205    205   int sqlite4VdbeReset(Vdbe*);
   206    206   void sqlite4VdbeSetNumCols(Vdbe*,int);
   207         -int sqlite4VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
          207  +int sqlite4VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*,void*));
   208    208   void sqlite4VdbeCountChanges(Vdbe*);
   209    209   sqlite4 *sqlite4VdbeDb(Vdbe*);
   210    210   void sqlite4VdbeSetSql(Vdbe*, const char *z, int n);
   211    211   void sqlite4VdbeSwap(Vdbe*,Vdbe*);
   212    212   VdbeOp *sqlite4VdbeTakeOpArray(Vdbe*, int*, int*);
   213    213   sqlite4_value *sqlite4VdbeGetValue(Vdbe*, int, u8);
   214    214   void sqlite4VdbeSetVarmask(Vdbe*, int);

Changes to src/vdbeInt.h.

   145    145     u16 flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
   146    146     u8  type;           /* One of SQLITE4_NULL, SQLITE4_TEXT, SQLITE4_INTEGER, etc */
   147    147     u8  enc;            /* SQLITE4_UTF8, SQLITE4_UTF16BE, SQLITE4_UTF16LE */
   148    148   #ifdef SQLITE4_DEBUG
   149    149     Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
   150    150     void *pFiller;      /* So that sizeof(Mem) is a multiple of 8 */
   151    151   #endif
   152         -  void (*xDel)(void *);  /* If not null, call this function to delete Mem.z */
          152  +  void (*xDel)(void*,void*); /* Function to delete Mem.z */
          153  +  void *pDelArg;             /* First argument to xDel() */
   153    154     char *zMalloc;      /* Dynamic buffer allocated by sqlite4_malloc() */
   154    155   };
   155    156   
   156    157   /* One or more of the following flags are set to indicate the validOK
   157    158   ** representations of the value stored in the Mem struct.
   158    159   **
   159    160   ** If the MEM_Null flag is set, then the value is an SQL NULL value.
................................................................................
   213    214   ** invocations.
   214    215   */
   215    216   struct VdbeFunc {
   216    217     FuncDef *pFunc;               /* The definition of the function */
   217    218     int nAux;                     /* Number of entries allocated for apAux[] */
   218    219     struct AuxData {
   219    220       void *pAux;                   /* Aux data for the i-th argument */
   220         -    void (*xDelete)(void *);      /* Destructor for the aux data */
          221  +    void (*xDelete)(void*,void*); /* Destructor for the aux data */
          222  +    void *pDeleteArg;             /* First argument to xDelete */
   221    223     } apAux[1];                   /* One slot for each function argument */
   222    224   };
   223    225   
   224    226   /*
   225    227   ** The "context" argument for a installable function.  A pointer to an
   226    228   ** instance of this structure is the first argument to the routines used
   227    229   ** implement the SQL functions.
................................................................................
   394    396   int sqlite4VdbeHalt(Vdbe*);
   395    397   int sqlite4VdbeChangeEncoding(Mem *, int);
   396    398   int sqlite4VdbeMemTooBig(Mem*);
   397    399   int sqlite4VdbeMemCopy(Mem*, const Mem*);
   398    400   void sqlite4VdbeMemShallowCopy(Mem*, const Mem*, int);
   399    401   void sqlite4VdbeMemMove(Mem*, Mem*);
   400    402   int sqlite4VdbeMemNulTerminate(Mem*);
   401         -int sqlite4VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
          403  +int sqlite4VdbeMemSetStr(Mem*, const char*, int, u8,
          404  +                         void(*)(void*,void*),void*);
   402    405   void sqlite4VdbeMemSetInt64(Mem*, i64);
   403    406   #ifdef SQLITE4_OMIT_FLOATING_POINT
   404    407   # define sqlite4VdbeMemSetDouble sqlite4VdbeMemSetInt64
   405    408   #else
   406    409     void sqlite4VdbeMemSetDouble(Mem*, double);
   407    410   #endif
   408    411   void sqlite4VdbeMemSetNull(Mem*);

Changes to src/vdbeapi.c.

   185    185   ** the function result.
   186    186   **
   187    187   ** The setStrOrError() funtion calls sqlite4VdbeMemSetStr() to store the
   188    188   ** result as a string or blob but if the string or blob is too large, it
   189    189   ** then sets the error code to SQLITE4_TOOBIG
   190    190   */
   191    191   static void setResultStrOrError(
   192         -  sqlite4_context *pCtx,  /* Function context */
   193         -  const char *z,          /* String pointer */
   194         -  int n,                  /* Bytes in string, or negative */
   195         -  u8 enc,                 /* Encoding of z.  0 for BLOBs */
   196         -  void (*xDel)(void*)     /* Destructor function */
          192  +  sqlite4_context *pCtx,     /* Function context */
          193  +  const char *z,             /* String pointer */
          194  +  int n,                     /* Bytes in string, or negative */
          195  +  u8 enc,                    /* Encoding of z.  0 for BLOBs */
          196  +  void (*xDel)(void*,void*), /* Destructor function */
          197  +  void *pDelArg              /* First argument to xDel() */
   197    198   ){
   198    199     if( xDel==SQLITE4_DYNAMIC ){
   199    200       assert( sqlite4MemdebugHasType(z, MEMTYPE_HEAP) );
   200    201       assert( sqlite4MemdebugNoType(z, ~MEMTYPE_HEAP) );
   201    202       sqlite4MemdebugSetType((char*)z, MEMTYPE_DB | MEMTYPE_HEAP);
   202    203     }
   203         -  if( sqlite4VdbeMemSetStr(&pCtx->s, z, n, enc, xDel)==SQLITE4_TOOBIG ){
          204  +  if( sqlite4VdbeMemSetStr(&pCtx->s, z, n, enc, xDel,pDelArg)==SQLITE4_TOOBIG ){
   204    205       sqlite4_result_error_toobig(pCtx);
   205    206     }
   206    207   }
   207    208   void sqlite4_result_blob(
   208    209     sqlite4_context *pCtx, 
   209    210     const void *z, 
   210    211     int n, 
   211         -  void (*xDel)(void *)
          212  +  void (*xDel)(void*,void*),
          213  +  void *pDelArg
   212    214   ){
   213    215     assert( n>=0 );
   214    216     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   215         -  setResultStrOrError(pCtx, z, n, 0, xDel);
          217  +  setResultStrOrError(pCtx, z, n, 0, xDel, pDelArg);
   216    218   }
   217    219   void sqlite4_result_double(sqlite4_context *pCtx, double rVal){
   218    220     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   219    221     sqlite4VdbeMemSetDouble(&pCtx->s, rVal);
   220    222   }
   221    223   void sqlite4_result_error(sqlite4_context *pCtx, const char *z, int n){
   222    224     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   223    225     pCtx->isError = SQLITE4_ERROR;
   224         -  sqlite4VdbeMemSetStr(&pCtx->s, z, n, SQLITE4_UTF8, SQLITE4_TRANSIENT);
          226  +  sqlite4VdbeMemSetStr(&pCtx->s, z, n, SQLITE4_UTF8, SQLITE4_TRANSIENT, 0);
   225    227   }
   226    228   #ifndef SQLITE4_OMIT_UTF16
   227    229   void sqlite4_result_error16(sqlite4_context *pCtx, const void *z, int n){
   228    230     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   229    231     pCtx->isError = SQLITE4_ERROR;
   230         -  sqlite4VdbeMemSetStr(&pCtx->s, z, n, SQLITE4_UTF16NATIVE, SQLITE4_TRANSIENT);
          232  +  sqlite4VdbeMemSetStr(&pCtx->s, z, n, SQLITE4_UTF16NATIVE,SQLITE4_TRANSIENT,0);
   231    233   }
   232    234   #endif
   233    235   void sqlite4_result_int(sqlite4_context *pCtx, int iVal){
   234    236     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   235    237     sqlite4VdbeMemSetInt64(&pCtx->s, (i64)iVal);
   236    238   }
   237    239   void sqlite4_result_int64(sqlite4_context *pCtx, i64 iVal){
................................................................................
   242    244     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   243    245     sqlite4VdbeMemSetNull(&pCtx->s);
   244    246   }
   245    247   void sqlite4_result_text(
   246    248     sqlite4_context *pCtx, 
   247    249     const char *z, 
   248    250     int n,
   249         -  void (*xDel)(void *)
          251  +  void (*xDel)(void*,void*),
          252  +  void *pDelArg
   250    253   ){
   251    254     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   252         -  setResultStrOrError(pCtx, z, n, SQLITE4_UTF8, xDel);
          255  +  setResultStrOrError(pCtx, z, n, SQLITE4_UTF8, xDel, pDelArg);
   253    256   }
   254    257   #ifndef SQLITE4_OMIT_UTF16
   255    258   void sqlite4_result_text16(
   256    259     sqlite4_context *pCtx, 
   257    260     const void *z, 
   258    261     int n, 
   259         -  void (*xDel)(void *)
          262  +  void (*xDel)(void*,void*),
          263  +  void *pDelArg
   260    264   ){
   261    265     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   262         -  setResultStrOrError(pCtx, z, n, SQLITE4_UTF16NATIVE, xDel);
          266  +  setResultStrOrError(pCtx, z, n, SQLITE4_UTF16NATIVE, xDel, pDelArg);
   263    267   }
   264    268   void sqlite4_result_text16be(
   265    269     sqlite4_context *pCtx, 
   266    270     const void *z, 
   267    271     int n, 
   268         -  void (*xDel)(void *)
          272  +  void (*xDel)(void*,void*),
          273  +  void *pDelArg
   269    274   ){
   270    275     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   271         -  setResultStrOrError(pCtx, z, n, SQLITE4_UTF16BE, xDel);
          276  +  setResultStrOrError(pCtx, z, n, SQLITE4_UTF16BE, xDel, pDelArg);
   272    277   }
   273    278   void sqlite4_result_text16le(
   274    279     sqlite4_context *pCtx, 
   275    280     const void *z, 
   276    281     int n, 
   277         -  void (*xDel)(void *)
          282  +  void (*xDel)(void*,void*),
          283  +  void *pDelArg
   278    284   ){
   279    285     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   280         -  setResultStrOrError(pCtx, z, n, SQLITE4_UTF16LE, xDel);
          286  +  setResultStrOrError(pCtx, z, n, SQLITE4_UTF16LE, xDel, pDelArg);
   281    287   }
   282    288   #endif /* SQLITE4_OMIT_UTF16 */
   283    289   void sqlite4_result_value(sqlite4_context *pCtx, sqlite4_value *pValue){
   284    290     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   285    291     sqlite4VdbeMemCopy(&pCtx->s, pValue);
   286    292   }
   287    293   void sqlite4_result_zeroblob(sqlite4_context *pCtx, int n){
................................................................................
   288    294     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   289    295     sqlite4VdbeMemSetZeroBlob(&pCtx->s, n);
   290    296   }
   291    297   void sqlite4_result_error_code(sqlite4_context *pCtx, int errCode){
   292    298     pCtx->isError = errCode;
   293    299     if( pCtx->s.flags & MEM_Null ){
   294    300       sqlite4VdbeMemSetStr(&pCtx->s, sqlite4ErrStr(errCode), -1, 
   295         -                         SQLITE4_UTF8, SQLITE4_STATIC);
          301  +                         SQLITE4_UTF8, SQLITE4_STATIC, 0);
   296    302     }
   297    303   }
   298    304   
   299    305   /* Force an SQLITE4_TOOBIG error. */
   300    306   void sqlite4_result_error_toobig(sqlite4_context *pCtx){
   301    307     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   302    308     pCtx->isError = SQLITE4_TOOBIG;
   303    309     sqlite4VdbeMemSetStr(&pCtx->s, "string or blob too big", -1, 
   304         -                       SQLITE4_UTF8, SQLITE4_STATIC);
          310  +                       SQLITE4_UTF8, SQLITE4_STATIC, 0);
   305    311   }
   306    312   
   307    313   /* An SQLITE4_NOMEM error. */
   308    314   void sqlite4_result_error_nomem(sqlite4_context *pCtx){
   309    315     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   310    316     sqlite4VdbeMemSetNull(&pCtx->s);
   311    317     pCtx->isError = SQLITE4_NOMEM;
................................................................................
   587    593   ** argument to the user-function defined by pCtx. Any previous value is
   588    594   ** deleted by calling the delete function specified when it was set.
   589    595   */
   590    596   void sqlite4_set_auxdata(
   591    597     sqlite4_context *pCtx, 
   592    598     int iArg, 
   593    599     void *pAux, 
   594         -  void (*xDelete)(void*)
          600  +  void (*xDelete)(void*,void*),
          601  +  void *pDeleteArg
   595    602   ){
   596    603     struct AuxData *pAuxData;
   597    604     VdbeFunc *pVdbeFunc;
   598    605     if( iArg<0 ) goto failed;
   599    606   
   600    607     assert( sqlite4_mutex_held(pCtx->s.db->mutex) );
   601    608     pVdbeFunc = pCtx->pVdbeFunc;
................................................................................
   610    617       memset(&pVdbeFunc->apAux[nAux], 0, sizeof(struct AuxData)*(iArg+1-nAux));
   611    618       pVdbeFunc->nAux = iArg+1;
   612    619       pVdbeFunc->pFunc = pCtx->pFunc;
   613    620     }
   614    621   
   615    622     pAuxData = &pVdbeFunc->apAux[iArg];
   616    623     if( pAuxData->pAux && pAuxData->xDelete ){
   617         -    pAuxData->xDelete(pAuxData->pAux);
          624  +    pAuxData->xDelete(pAuxData->pDeleteArg, pAuxData->pAux);
   618    625     }
   619    626     pAuxData->pAux = pAux;
   620    627     pAuxData->xDelete = xDelete;
          628  +  pAuxData->pDeleteArg = pDeleteArg;
   621    629     return;
   622    630   
   623    631   failed:
   624    632     if( xDelete ){
   625         -    xDelete(pAux);
          633  +    xDelete(pDeleteArg, pAux);
   626    634     }
   627    635   }
   628    636   
   629    637   #ifndef SQLITE4_OMIT_DEPRECATED
   630    638   /*
   631    639   ** Return the number of times the Step function of a aggregate has been 
   632    640   ** called.
................................................................................
  1004   1012     return SQLITE4_OK;
  1005   1013   }
  1006   1014   
  1007   1015   /*
  1008   1016   ** Bind a text or BLOB value.
  1009   1017   */
  1010   1018   static int bindText(
  1011         -  sqlite4_stmt *pStmt,   /* The statement to bind against */
  1012         -  int i,                 /* Index of the parameter to bind */
  1013         -  const void *zData,     /* Pointer to the data to be bound */
  1014         -  int nData,             /* Number of bytes of data to be bound */
  1015         -  void (*xDel)(void*),   /* Destructor for the data */
  1016         -  u8 encoding            /* Encoding for the data */
         1019  +  sqlite4_stmt *pStmt,       /* The statement to bind against */
         1020  +  int i,                     /* Index of the parameter to bind */
         1021  +  const void *zData,         /* Pointer to the data to be bound */
         1022  +  int nData,                 /* Number of bytes of data to be bound */
         1023  +  void (*xDel)(void*,void*), /* Destructor for the data */
         1024  +  void *pDelArg,             /* First argument to xDel() */
         1025  +  u8 encoding                /* Encoding for the data */
  1017   1026   ){
  1018   1027     Vdbe *p = (Vdbe *)pStmt;
  1019   1028     Mem *pVar;
  1020   1029     int rc;
  1021   1030   
  1022   1031     rc = vdbeUnbind(p, i);
  1023   1032     if( rc==SQLITE4_OK ){
  1024   1033       if( zData!=0 ){
  1025   1034         pVar = &p->aVar[i-1];
  1026         -      rc = sqlite4VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
         1035  +      rc = sqlite4VdbeMemSetStr(pVar, zData, nData, encoding, xDel, pDelArg);
  1027   1036         if( rc==SQLITE4_OK && encoding!=0 ){
  1028   1037           rc = sqlite4VdbeChangeEncoding(pVar, ENC(p->db));
  1029   1038         }
  1030   1039         sqlite4Error(p->db, rc, 0);
  1031   1040         rc = sqlite4ApiExit(p->db, rc);
  1032   1041       }
  1033   1042       sqlite4_mutex_leave(p->db->mutex);
  1034   1043     }else if( xDel!=SQLITE4_STATIC && xDel!=SQLITE4_TRANSIENT ){
  1035         -    xDel((void*)zData);
         1044  +    xDel(pDelArg, (void*)zData);
  1036   1045     }
  1037   1046     return rc;
  1038   1047   }
  1039   1048   
  1040   1049   
  1041   1050   /*
  1042   1051   ** Bind a blob value to an SQL statement variable.
  1043   1052   */
  1044   1053   int sqlite4_bind_blob(
  1045   1054     sqlite4_stmt *pStmt, 
  1046   1055     int i, 
  1047   1056     const void *zData, 
  1048   1057     int nData, 
  1049         -  void (*xDel)(void*)
         1058  +  void (*xDel)(void*,void*),
         1059  +  void *pDelArg
  1050   1060   ){
  1051         -  return bindText(pStmt, i, zData, nData, xDel, 0);
         1061  +  return bindText(pStmt, i, zData, nData, xDel, pDelArg, 0);
  1052   1062   }
  1053   1063   int sqlite4_bind_double(sqlite4_stmt *pStmt, int i, double rValue){
  1054   1064     int rc;
  1055   1065     Vdbe *p = (Vdbe *)pStmt;
  1056   1066     rc = vdbeUnbind(p, i);
  1057   1067     if( rc==SQLITE4_OK ){
  1058   1068       sqlite4VdbeMemSetDouble(&p->aVar[i-1], rValue);
................................................................................
  1083   1093     return rc;
  1084   1094   }
  1085   1095   int sqlite4_bind_text( 
  1086   1096     sqlite4_stmt *pStmt, 
  1087   1097     int i, 
  1088   1098     const char *zData, 
  1089   1099     int nData, 
  1090         -  void (*xDel)(void*)
         1100  +  void (*xDel)(void*,void*),
         1101  +  void *pDelArg
  1091   1102   ){
  1092         -  return bindText(pStmt, i, zData, nData, xDel, SQLITE4_UTF8);
         1103  +  return bindText(pStmt, i, zData, nData, xDel, pDelArg, SQLITE4_UTF8);
  1093   1104   }
  1094   1105   #ifndef SQLITE4_OMIT_UTF16
  1095   1106   int sqlite4_bind_text16(
  1096   1107     sqlite4_stmt *pStmt, 
  1097   1108     int i, 
  1098   1109     const void *zData, 
  1099   1110     int nData, 
  1100         -  void (*xDel)(void*)
         1111  +  void (*xDel)(void*,void*),
         1112  +  void *pDelArg
  1101   1113   ){
  1102         -  return bindText(pStmt, i, zData, nData, xDel, SQLITE4_UTF16NATIVE);
         1114  +  return bindText(pStmt, i, zData, nData, xDel, pDelArg, SQLITE4_UTF16NATIVE);
  1103   1115   }
  1104   1116   #endif /* SQLITE4_OMIT_UTF16 */
  1105   1117   int sqlite4_bind_value(sqlite4_stmt *pStmt, int i, const sqlite4_value *pValue){
  1106   1118     int rc;
  1107   1119     switch( pValue->type ){
  1108   1120       case SQLITE4_INTEGER: {
  1109   1121         rc = sqlite4_bind_int64(pStmt, i, pValue->u.i);
................................................................................
  1113   1125         rc = sqlite4_bind_double(pStmt, i, pValue->r);
  1114   1126         break;
  1115   1127       }
  1116   1128       case SQLITE4_BLOB: {
  1117   1129         if( pValue->flags & MEM_Zero ){
  1118   1130           rc = sqlite4_bind_zeroblob(pStmt, i, pValue->u.nZero);
  1119   1131         }else{
  1120         -        rc = sqlite4_bind_blob(pStmt, i, pValue->z, pValue->n,SQLITE4_TRANSIENT);
         1132  +        rc = sqlite4_bind_blob(pStmt, i, pValue->z, pValue->n,
         1133  +                               SQLITE4_TRANSIENT, 0);
  1121   1134         }
  1122   1135         break;
  1123   1136       }
  1124   1137       case SQLITE4_TEXT: {
  1125         -      rc = bindText(pStmt,i,  pValue->z, pValue->n, SQLITE4_TRANSIENT,
         1138  +      rc = bindText(pStmt,i,  pValue->z, pValue->n, SQLITE4_TRANSIENT, 0,
  1126   1139                                 pValue->enc);
  1127   1140         break;
  1128   1141       }
  1129   1142       default: {
  1130   1143         rc = sqlite4_bind_null(pStmt, i);
  1131   1144         break;
  1132   1145       }

Changes to src/vdbeaux.c.

  1191   1191       if( sqlite4VdbeMemGrow(pMem, 32, 0) ){            /* P4 */
  1192   1192         assert( p->db->mallocFailed );
  1193   1193         return SQLITE4_ERROR;
  1194   1194       }
  1195   1195       pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
  1196   1196       z = displayP4(pOp, pMem->z, 32);
  1197   1197       if( z!=pMem->z ){
  1198         -      sqlite4VdbeMemSetStr(pMem, z, -1, SQLITE4_UTF8, 0);
         1198  +      sqlite4VdbeMemSetStr(pMem, z, -1, SQLITE4_UTF8, 0, 0);
  1199   1199       }else{
  1200   1200         assert( pMem->z!=0 );
  1201   1201         pMem->n = sqlite4Strlen30(pMem->z);
  1202   1202         pMem->enc = SQLITE4_UTF8;
  1203   1203       }
  1204   1204       pMem->type = SQLITE4_TEXT;
  1205   1205       pMem++;
................................................................................
  1634   1634   ** to by zName will be freed by sqlite4DbFree() when the vdbe is destroyed.
  1635   1635   */
  1636   1636   int sqlite4VdbeSetColName(
  1637   1637     Vdbe *p,                         /* Vdbe being configured */
  1638   1638     int idx,                         /* Index of column zName applies to */
  1639   1639     int var,                         /* One of the COLNAME_* constants */
  1640   1640     const char *zName,               /* Pointer to buffer containing name */
  1641         -  void (*xDel)(void*)              /* Memory management strategy for zName */
         1641  +  void (*xDel)(void*,void*)        /* Memory management strategy for zName */
  1642   1642   ){
  1643   1643     int rc;
  1644   1644     Mem *pColName;
  1645   1645     assert( idx<p->nResColumn );
  1646   1646     assert( var<COLNAME_N );
         1647  +  assert( xDel==SQLITE4_STATIC || xDel==SQLITE4_TRANSIENT
         1648  +             || xDel==SQLITE4_DYNAMIC );
  1647   1649     if( p->db->mallocFailed ){
  1648   1650       assert( !zName || xDel!=SQLITE4_DYNAMIC );
  1649   1651       return SQLITE4_NOMEM;
  1650   1652     }
  1651   1653     assert( p->aColName!=0 );
  1652   1654     pColName = &(p->aColName[idx+var*p->nResColumn]);
  1653         -  rc = sqlite4VdbeMemSetStr(pColName, zName, -1, SQLITE4_UTF8, xDel);
         1655  +  rc = sqlite4VdbeMemSetStr(pColName, zName, -1, SQLITE4_UTF8, xDel, 0);
  1654   1656     assert( rc!=0 || !zName || (pColName->flags&MEM_Term)!=0 );
  1655   1657     return rc;
  1656   1658   }
  1657   1659   
  1658   1660   /*
  1659   1661   ** Free all Savepoint structures that correspond to transaction levels
  1660   1662   ** larger than iLevel. Passing iLevel==1 deletes all Savepoint structures.
................................................................................
  1972   1974   */
  1973   1975   int sqlite4VdbeTransferError(Vdbe *p){
  1974   1976     sqlite4 *db = p->db;
  1975   1977     int rc = p->rc;
  1976   1978     if( p->zErrMsg ){
  1977   1979       u8 mallocFailed = db->mallocFailed;
  1978   1980       sqlite4BeginBenignMalloc(db->pEnv);
  1979         -    sqlite4ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE4_UTF8, SQLITE4_TRANSIENT);
         1981  +    sqlite4ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE4_UTF8,
         1982  +                       SQLITE4_TRANSIENT, 0);
  1980   1983       sqlite4EndBenignMalloc(db->pEnv);
  1981   1984       db->mallocFailed = mallocFailed;
  1982   1985       db->errCode = rc;
  1983   1986     }else{
  1984   1987       sqlite4Error(db, rc, 0);
  1985   1988     }
  1986   1989     return rc;
................................................................................
  2019   2022       if( p->runOnlyOnce ) p->expired = 1;
  2020   2023     }else if( p->rc && p->expired ){
  2021   2024       /* The expired flag was set on the VDBE before the first call
  2022   2025       ** to sqlite4_step(). For consistency (since sqlite4_step() was
  2023   2026       ** called), set the database error in this case as well.
  2024   2027       */
  2025   2028       sqlite4Error(db, p->rc, 0);
  2026         -    sqlite4ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE4_UTF8, SQLITE4_TRANSIENT);
         2029  +    sqlite4ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE4_UTF8,
         2030  +                       SQLITE4_TRANSIENT, 0);
  2027   2031       sqlite4DbFree(db, p->zErrMsg);
  2028   2032       p->zErrMsg = 0;
  2029   2033     }
  2030   2034   
  2031   2035     /* Reclaim all memory used by the VDBE
  2032   2036     */
  2033   2037     Cleanup(p);
................................................................................
  2081   2085   */
  2082   2086   void sqlite4VdbeDeleteAuxData(VdbeFunc *pVdbeFunc, int mask){
  2083   2087     int i;
  2084   2088     for(i=0; i<pVdbeFunc->nAux; i++){
  2085   2089       struct AuxData *pAux = &pVdbeFunc->apAux[i];
  2086   2090       if( (i>31 || !(mask&(((u32)1)<<i))) && pAux->pAux ){
  2087   2091         if( pAux->xDelete ){
  2088         -        pAux->xDelete(pAux->pAux);
         2092  +        pAux->xDelete(pAux->pDeleteArg, pAux->pAux);
  2089   2093         }
  2090   2094         pAux->pAux = 0;
  2091   2095       }
  2092   2096     }
  2093   2097   }
  2094   2098   
  2095   2099   /*

Changes to src/vdbecodec.c.

   141    141           e = e>>2;
   142    142           while( e>=10 ){ r *= 1.0e10; e -= 10; }
   143    143           while( e>0 ){ r *= 10.0; e--; }
   144    144         }
   145    145         sqlite4VdbeMemSetDouble(pOut, r);
   146    146       }else if( cclass==0 ){
   147    147         if( size==0 ){
   148         -        sqlite4VdbeMemSetStr(pOut, "", 0, SQLITE4_UTF8, SQLITE4_TRANSIENT);
          148  +        sqlite4VdbeMemSetStr(pOut, "", 0, SQLITE4_UTF8, SQLITE4_TRANSIENT, 0);
   149    149         }else if( p->a[ofst]>0x02 ){
   150    150           sqlite4VdbeMemSetStr(pOut, (char*)(p->a+ofst), size, 
   151         -                             SQLITE4_UTF8, SQLITE4_TRANSIENT);
          151  +                             SQLITE4_UTF8, SQLITE4_TRANSIENT, 0);
   152    152         }else{
   153    153           static const u8 enc[] = {SQLITE4_UTF8,SQLITE4_UTF16LE,SQLITE4_UTF16BE };
   154    154           sqlite4VdbeMemSetStr(pOut, (char*)(p->a+ofst+1), size-1, 
   155         -                             enc[p->a[ofst]], SQLITE4_TRANSIENT);
          155  +                             enc[p->a[ofst]], SQLITE4_TRANSIENT, 0);
   156    156         }
   157    157       }else{
   158         -      sqlite4VdbeMemSetStr(pOut, (char*)(p->a+ofst), size, 0,SQLITE4_TRANSIENT);
          158  +      sqlite4VdbeMemSetStr(pOut, (char*)(p->a+ofst), size, 0,
          159  +                           SQLITE4_TRANSIENT, 0);
   159    160       }
   160    161     }
   161    162     testcase( i==iVal );
   162    163     testcase( i==iVal+1 );
   163    164     if( i<=iVal ){
   164    165       if( pDefault ){
   165    166         sqlite4VdbeMemShallowCopy(pOut, pDefault, MEM_Static);

Changes to src/vdbemem.c.

    89     89     }
    90     90   
    91     91     if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
    92     92       memcpy(pMem->zMalloc, pMem->z, pMem->n);
    93     93     }
    94     94     if( pMem->flags&MEM_Dyn && pMem->xDel ){
    95     95       assert( pMem->xDel!=SQLITE4_DYNAMIC );
    96         -    pMem->xDel((void *)(pMem->z));
           96  +    pMem->xDel(pMem->pDelArg, (void *)(pMem->z));
    97     97     }
    98     98   
    99     99     pMem->z = pMem->zMalloc;
   100    100     if( pMem->z==0 ){
   101    101       pMem->flags = MEM_Null;
   102    102     }else{
   103    103       pMem->flags &= ~(MEM_Ephem|MEM_Static);
................................................................................
   240    240     if( p->flags&MEM_Agg ){
   241    241       sqlite4VdbeMemFinalize(p, p->u.pDef);
   242    242       assert( (p->flags & MEM_Agg)==0 );
   243    243       sqlite4VdbeMemRelease(p);
   244    244     }else if( p->flags&MEM_Dyn && p->xDel ){
   245    245       assert( (p->flags&MEM_RowSet)==0 );
   246    246       assert( p->xDel!=SQLITE4_DYNAMIC );
   247         -    p->xDel((void *)p->z);
          247  +    p->xDel(p->pDelArg, (void *)p->z);
   248    248       p->xDel = 0;
   249    249     }else if( p->flags&MEM_RowSet ){
   250    250       sqlite4RowSetClear(p->u.pRowSet);
   251    251     }else if( p->flags&MEM_Frame ){
   252    252       sqlite4VdbeMemSetNull(p);
   253    253     }
   254    254   }
................................................................................
   632    632   ** If the string is too large (if it exceeds the SQLITE4_LIMIT_LENGTH
   633    633   ** size limit) then no memory allocation occurs.  If the string can be
   634    634   ** stored without allocating memory, then it is.  If a memory allocation
   635    635   ** is required to store the string, then value of pMem is unchanged.  In
   636    636   ** either case, SQLITE4_TOOBIG is returned.
   637    637   */
   638    638   int sqlite4VdbeMemSetStr(
   639         -  Mem *pMem,          /* Memory cell to set to string value */
   640         -  const char *z,      /* String pointer */
   641         -  int n,              /* Bytes in string, or negative */
   642         -  u8 enc,             /* Encoding of z.  0 for BLOBs */
   643         -  void (*xDel)(void*) /* Destructor function */
          639  +  Mem *pMem,                /* Memory cell to set to string value */
          640  +  const char *z,            /* String pointer */
          641  +  int n,                    /* Bytes in string, or negative */
          642  +  u8 enc,                   /* Encoding of z.  0 for BLOBs */
          643  +  void (*xDel)(void*,void*),/* Destructor function */
          644  +  void *pDelArg             /* First argument to xDel() */
   644    645   ){
   645    646     int nByte = n;      /* New value for pMem->n */
   646    647     int iLimit;         /* Maximum allowed string or blob size */
   647    648     u16 flags = 0;      /* New value for pMem->flags */
   648    649   
   649    650     assert( pMem->db==0 || sqlite4_mutex_held(pMem->db->mutex) );
   650    651     assert( (pMem->flags & MEM_RowSet)==0 );
................................................................................
   691    692       sqlite4VdbeMemRelease(pMem);
   692    693       pMem->zMalloc = pMem->z = (char *)z;
   693    694       pMem->xDel = 0;
   694    695     }else{
   695    696       sqlite4VdbeMemRelease(pMem);
   696    697       pMem->z = (char *)z;
   697    698       pMem->xDel = xDel;
          699  +    pMem->pDelArg = pDelArg;
   698    700       flags |= ((xDel==SQLITE4_STATIC)?MEM_Static:MEM_Dyn);
   699    701     }
   700    702   
   701    703     pMem->n = nByte;
   702    704     pMem->flags = flags;
   703    705     pMem->enc = (enc==0 ? SQLITE4_UTF8 : enc);
   704    706     pMem->type = (enc==0 ? SQLITE4_BLOB : SQLITE4_TEXT);
................................................................................
   947    949       pVal = sqlite4ValueNew(db);
   948    950       if( pVal==0 ) goto no_mem;
   949    951       if( ExprHasProperty(pExpr, EP_IntValue) ){
   950    952         sqlite4VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
   951    953       }else{
   952    954         zVal = sqlite4MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
   953    955         if( zVal==0 ) goto no_mem;
   954         -      sqlite4ValueSetStr(pVal, -1, zVal, SQLITE4_UTF8, SQLITE4_DYNAMIC);
          956  +      sqlite4ValueSetStr(pVal, -1, zVal, SQLITE4_UTF8, SQLITE4_DYNAMIC, 0);
   955    957         if( op==TK_FLOAT ) pVal->type = SQLITE4_FLOAT;
   956    958       }
   957    959       if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE4_AFF_NONE ){
   958    960         sqlite4ValueApplyAffinity(pVal, SQLITE4_AFF_NUMERIC, SQLITE4_UTF8);
   959    961       }else{
   960    962         sqlite4ValueApplyAffinity(pVal, affinity, SQLITE4_UTF8);
   961    963       }
................................................................................
   988    990       assert( pExpr->u.zToken[1]=='\'' );
   989    991       pVal = sqlite4ValueNew(db);
   990    992       if( !pVal ) goto no_mem;
   991    993       zVal = &pExpr->u.zToken[2];
   992    994       nVal = sqlite4Strlen30(zVal)-1;
   993    995       assert( zVal[nVal]=='\'' );
   994    996       sqlite4VdbeMemSetStr(pVal, sqlite4HexToBlob(db, zVal, nVal), nVal/2,
   995         -                         0, SQLITE4_DYNAMIC);
          997  +                         0, SQLITE4_DYNAMIC, 0);
   996    998     }
   997    999   #endif
   998   1000   
   999   1001     if( pVal ){
  1000   1002       sqlite4VdbeMemStoreType(pVal);
  1001   1003     }
  1002   1004     *ppVal = pVal;
................................................................................
  1010   1012     return SQLITE4_NOMEM;
  1011   1013   }
  1012   1014   
  1013   1015   /*
  1014   1016   ** Change the string value of an sqlite4_value object
  1015   1017   */
  1016   1018   void sqlite4ValueSetStr(
  1017         -  sqlite4_value *v,     /* Value to be set */
  1018         -  int n,                /* Length of string z */
  1019         -  const void *z,        /* Text of the new string */
  1020         -  u8 enc,               /* Encoding to use */
  1021         -  void (*xDel)(void*)   /* Destructor for the string */
         1019  +  sqlite4_value *v,          /* Value to be set */
         1020  +  int n,                     /* Length of string z */
         1021  +  const void *z,             /* Text of the new string */
         1022  +  u8 enc,                    /* Encoding to use */
         1023  +  void (*xDel)(void*,void*), /* Destructor for the string */
         1024  +  void *pDelArg              /* First argument to xDel() */
  1022   1025   ){
  1023         -  if( v ) sqlite4VdbeMemSetStr((Mem *)v, z, n, enc, xDel);
         1026  +  if( v ) sqlite4VdbeMemSetStr((Mem *)v, z, n, enc, xDel, pDelArg);
  1024   1027   }
  1025   1028   
  1026   1029   /*
  1027   1030   ** Free an sqlite4_value object
  1028   1031   */
  1029   1032   void sqlite4ValueFree(sqlite4_value *v){
  1030   1033     if( !v ) return;

Changes to src/vdbetrace.c.

   126    126         }else if( pVar->flags & MEM_Str ){
   127    127   #ifndef SQLITE4_OMIT_UTF16
   128    128           u8 enc = ENC(db);
   129    129           if( enc!=SQLITE4_UTF8 ){
   130    130             Mem utf8;
   131    131             memset(&utf8, 0, sizeof(utf8));
   132    132             utf8.db = db;
   133         -          sqlite4VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE4_STATIC);
          133  +          sqlite4VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE4_STATIC, 0);
   134    134             sqlite4VdbeChangeEncoding(&utf8, SQLITE4_UTF8);
   135    135             sqlite4XPrintf(&out, "'%.*q'", utf8.n, utf8.z);
   136    136             sqlite4VdbeMemRelease(&utf8);
   137    137           }else
   138    138   #endif
   139    139           {
   140    140             sqlite4XPrintf(&out, "'%.*q'", pVar->n, pVar->z);

Changes to test/test_func.c.

    65     65     }
    66     66     assert( n<sizeof(zBuf) );
    67     67     sqlite4_randomness(pEnv, n, zBuf);
    68     68     for(i=0; i<n; i++){
    69     69       zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
    70     70     }
    71     71     zBuf[n] = 0;
    72         -  sqlite4_result_text(context, (char*)zBuf, n, SQLITE4_TRANSIENT);
           72  +  sqlite4_result_text(context, (char*)zBuf, n, SQLITE4_TRANSIENT, 0);
    73     73   }
    74     74   
    75     75   /*
    76     76   ** The following two SQL functions are used to test returning a text
    77     77   ** result with a destructor. Function 'test_destructor' takes one argument
    78     78   ** and returns the same argument interpreted as TEXT. A destructor is
    79     79   ** passed with the sqlite4_result_text() call.
................................................................................
    80     80   **
    81     81   ** SQL function 'test_destructor_count' returns the number of outstanding 
    82     82   ** allocations made by 'test_destructor';
    83     83   **
    84     84   ** WARNING: Not threadsafe.
    85     85   */
    86     86   static int test_destructor_count_var = 0;
    87         -static void destructor(void *p){
           87  +static void destructor(void *pNotUsed, void *p){
    88     88     char *zVal = (char *)p;
    89     89     assert(zVal);
    90     90     zVal--;
    91     91     sqlite4_free(0, zVal);
    92     92     test_destructor_count_var--;
    93     93   }
    94     94   static void test_destructor(
................................................................................
   107    107     if( !zVal ){
   108    108       return;
   109    109     }
   110    110     zVal[len+1] = 0;
   111    111     zVal[len+2] = 0;
   112    112     zVal++;
   113    113     memcpy(zVal, sqlite4_value_text(argv[0]), len);
   114         -  sqlite4_result_text(pCtx, zVal, -1, destructor);
          114  +  sqlite4_result_text(pCtx, zVal, -1, destructor, 0);
   115    115   }
   116    116   #ifndef SQLITE4_OMIT_UTF16
   117    117   static void test_destructor16(
   118    118     sqlite4_context *pCtx, 
   119    119     int nArg,
   120    120     sqlite4_value **argv
   121    121   ){
................................................................................
   130    130     if( !zVal ){
   131    131       return;
   132    132     }
   133    133     zVal[len+1] = 0;
   134    134     zVal[len+2] = 0;
   135    135     zVal++;
   136    136     memcpy(zVal, sqlite4_value_text16(argv[0]), len);
   137         -  sqlite4_result_text16(pCtx, zVal, -1, destructor);
          137  +  sqlite4_result_text16(pCtx, zVal, -1, destructor, 0);
   138    138   }
   139    139   #endif
   140    140   static void test_destructor_count(
   141    141     sqlite4_context *pCtx, 
   142    142     int nArg,
   143    143     sqlite4_value **argv
   144    144   ){
................................................................................
   163    163   #ifndef SQLITE4_OMIT_UTF16
   164    164     const void *z;
   165    165     sqlite4 * db = sqlite4_context_db_handle(ctx);
   166    166     sqlite4_aggregate_context(ctx, 2048);
   167    167     sqlite4BeginBenignMalloc();
   168    168     z = sqlite4_errmsg16(db);
   169    169     sqlite4EndBenignMalloc();
   170         -  sqlite4_result_text16(ctx, z, -1, SQLITE4_TRANSIENT);
          170  +  sqlite4_result_text16(ctx, z, -1, SQLITE4_TRANSIENT, 0);
   171    171   #endif
   172    172   }
   173    173   
   174    174   /*
   175    175   ** Routines for testing the sqlite4_get_auxdata() and sqlite4_set_auxdata()
   176    176   ** interface.
   177    177   **
................................................................................
   178    178   ** The test_auxdata() SQL function attempts to register each of its arguments
   179    179   ** as auxiliary data.  If there are no prior registrations of aux data for
   180    180   ** that argument (meaning the argument is not a constant or this is its first
   181    181   ** call) then the result for that argument is 0.  If there is a prior
   182    182   ** registration, the result for that argument is 1.  The overall result
   183    183   ** is the individual argument results separated by spaces.
   184    184   */
   185         -static void free_test_auxdata(void *p) {sqlite4_free(0, p);}
          185  +static void free_test_auxdata(void *pEnv, void *p){
          186  +  sqlite4_free((sqlite4_env*)pEnv, p);
          187  +}
   186    188   static void test_auxdata(
   187    189     sqlite4_context *pCtx, 
   188    190     int nArg,
   189    191     sqlite4_value **argv
   190    192   ){
   191    193     int i;
   192    194     char *zRet = testContextMalloc(pCtx, nArg*2);
          195  +  sqlite4_env *pEnv;
   193    196     if( !zRet ) return;
   194    197     memset(zRet, 0, nArg*2);
   195    198     for(i=0; i<nArg; i++){
   196    199       char const *z = (char*)sqlite4_value_text(argv[i]);
   197    200       if( z ){
   198    201         int n;
   199    202         char *zAux = sqlite4_get_auxdata(pCtx, i);
................................................................................
   203    206         }else {
   204    207           zRet[i*2] = '0';
   205    208         }
   206    209         n = strlen(z) + 1;
   207    210         zAux = testContextMalloc(pCtx, n);
   208    211         if( zAux ){
   209    212           memcpy(zAux, z, n);
   210         -        sqlite4_set_auxdata(pCtx, i, zAux, free_test_auxdata);
          213  +        sqlite4_set_auxdata(pCtx, i, zAux,
          214  +                            free_test_auxdata, sqlite4_context_env(pCtx));
   211    215         }
   212    216         zRet[i*2+1] = ' ';
   213    217       }
   214    218     }
   215         -  sqlite4_result_text(pCtx, zRet, 2*nArg-1, free_test_auxdata);
          219  +  sqlite4_result_text(pCtx, zRet, 2*nArg-1,
          220  +                      free_test_auxdata, sqlite4_context_env(pCtx));
   216    221   }
   217    222   
   218    223   /*
   219    224   ** A function to test error reporting from user functions. This function
   220    225   ** returns a copy of its first argument as the error message.  If the
   221    226   ** second argument exists, it becomes the error code.
   222    227   */
................................................................................
   230    235       sqlite4_result_error_code(pCtx, sqlite4_value_int(argv[1]));
   231    236     }
   232    237   }
   233    238   
   234    239   /* A counter object with its destructor.  Used by counterFunc() below.
   235    240   */
   236    241   struct counterObject { int cnt; sqlite4_env *pEnv; };
   237         -void counterFree(void *x){
          242  +void counterFree(void *NotUsed, void *x){
   238    243     struct counterObject *p = (struct counterObject*)x;
   239    244     sqlite4_free(p->pEnv, p);
   240    245   }
   241    246   
   242    247   /*
   243    248   ** Implementation of the counter(X) function.  If X is an integer
   244    249   ** constant, then the first invocation will return X.  The second X+1.
................................................................................
   256    261       pCounter = sqlite4_malloc(sqlite4_context_env(pCtx), sizeof(*pCounter) );
   257    262       if( pCounter==0 ){
   258    263         sqlite4_result_error_nomem(pCtx);
   259    264         return;
   260    265       }
   261    266       pCounter->cnt = sqlite4_value_int(argv[0]);
   262    267       pCounter->pEnv = sqlite4_context_env(pCtx);
   263         -    sqlite4_set_auxdata(pCtx, 0, pCounter, counterFree);
          268  +    sqlite4_set_auxdata(pCtx, 0, pCounter, counterFree, 0);
   264    269     }else{
   265    270       pCounter->cnt++;
   266    271     }
   267    272     sqlite4_result_int(pCtx, pCounter->cnt);
   268    273   }
   269    274   
   270    275   
................................................................................
   319    324     }
   320    325     if( rc ){
   321    326       char *zErr;
   322    327       sqlite4_env *pEnv = sqlite4_context_env(pCtx);
   323    328       assert( pStmt==0 );
   324    329       zErr = sqlite4_mprintf(pEnv, "sqlite4_prepare() error: %s",
   325    330                              sqlite4_errmsg(db));
   326         -    sqlite4_result_text(pCtx, zErr, -1, SQLITE4_DYNAMIC);
          331  +    sqlite4_result_text(pCtx, zErr, -1, SQLITE4_DYNAMIC, 0);
   327    332       sqlite4_result_error_code(pCtx, rc);
   328    333     }
   329    334   }
   330    335   
   331    336   
   332    337   /*
   333    338   ** convert one character from hex to binary
................................................................................
   372    377     n = sqlite4_value_bytes(argv[0]);
   373    378     zIn = (const char*)sqlite4_value_text(argv[0]);
   374    379     zOut = sqlite4_malloc(sqlite4_context_env(pCtx), n/2 );
   375    380     if( zOut==0 ){
   376    381       sqlite4_result_error_nomem(pCtx);
   377    382     }else{
   378    383       testHexToBin(zIn, zOut);
   379         -    sqlite4_result_text16be(pCtx, zOut, n/2, SQLITE4_DYNAMIC);
          384  +    sqlite4_result_text16be(pCtx, zOut, n/2, SQLITE4_DYNAMIC, 0);
   380    385     }
   381    386   }
   382    387   #endif
   383    388   
   384    389   /*
   385    390   **      hex_to_utf8(HEX)
   386    391   **
................................................................................
   399    404     n = sqlite4_value_bytes(argv[0]);
   400    405     zIn = (const char*)sqlite4_value_text(argv[0]);
   401    406     zOut = sqlite4_malloc(sqlite4_context_env(pCtx), n/2 );
   402    407     if( zOut==0 ){
   403    408       sqlite4_result_error_nomem(pCtx);
   404    409     }else{
   405    410       testHexToBin(zIn, zOut);
   406         -    sqlite4_result_text(pCtx, zOut, n/2, SQLITE4_DYNAMIC);
          411  +    sqlite4_result_text(pCtx, zOut, n/2, SQLITE4_DYNAMIC, 0);
   407    412     }
   408    413   }
   409    414   
   410    415   /*
   411    416   **      hex_to_utf16le(HEX)
   412    417   **
   413    418   ** Convert the input string from HEX into binary.  Then return the
................................................................................
   426    431     n = sqlite4_value_bytes(argv[0]);
   427    432     zIn = (const char*)sqlite4_value_text(argv[0]);
   428    433     zOut = sqlite4_malloc(sqlite4_context_env(pCtx), n/2 );
   429    434     if( zOut==0 ){
   430    435       sqlite4_result_error_nomem(pCtx);
   431    436     }else{
   432    437       testHexToBin(zIn, zOut);
   433         -    sqlite4_result_text16le(pCtx, zOut, n/2, SQLITE4_DYNAMIC);
          438  +    sqlite4_result_text16le(pCtx, zOut, n/2, SQLITE4_DYNAMIC, 0);
   434    439     }
   435    440   }
   436    441   #endif
   437    442   
   438    443   static int registerTestFunctions(sqlite4 *db){
   439    444     static const struct {
   440    445        char *zName;

Changes to test/test_main.c.

   682    682     sqlite4_value **argv
   683    683   ){
   684    684     int i;
   685    685     for(i=0; i<argc; i++){
   686    686       if( SQLITE4_NULL!=sqlite4_value_type(argv[i]) ){
   687    687         int n = sqlite4_value_bytes(argv[i]);
   688    688         sqlite4_result_text(context, (char*)sqlite4_value_text(argv[i]),
   689         -          n, SQLITE4_TRANSIENT);
          689  +          n, SQLITE4_TRANSIENT, 0);
   690    690         break;
   691    691       }
   692    692     }
   693    693   }
   694    694   
   695    695   /*
   696    696   ** These are test functions.    hex8() interprets its argument as
................................................................................
   702    702     int i;
   703    703     char zBuf[200];
   704    704     z = sqlite4_value_text(argv[0]);
   705    705     for(i=0; i<sizeof(zBuf)/2 - 2 && z[i]; i++){
   706    706       sprintf(&zBuf[i*2], "%02x", z[i]&0xff);
   707    707     }
   708    708     zBuf[i*2] = 0;
   709         -  sqlite4_result_text(p, (char*)zBuf, -1, SQLITE4_TRANSIENT);
          709  +  sqlite4_result_text(p, (char*)zBuf, -1, SQLITE4_TRANSIENT, 0);
   710    710   }
   711    711   #ifndef SQLITE4_OMIT_UTF16
   712    712   static void hex16Func(sqlite4_context *p, int argc, sqlite4_value **argv){
   713    713     const unsigned short int *z;
   714    714     int i;
   715    715     char zBuf[400];
   716    716     z = sqlite4_value_text16(argv[0]);
   717    717     for(i=0; i<sizeof(zBuf)/4 - 4 && z[i]; i++){
   718    718       sprintf(&zBuf[i*4], "%04x", z[i]&0xff);
   719    719     }
   720    720     zBuf[i*4] = 0;
   721         -  sqlite4_result_text(p, (char*)zBuf, -1, SQLITE4_TRANSIENT);
          721  +  sqlite4_result_text(p, (char*)zBuf, -1, SQLITE4_TRANSIENT, 0);
   722    722   }
   723    723   #endif
   724    724   
   725    725   /*
   726    726   ** A structure into which to accumulate text.
   727    727   */
   728    728   struct dstr {
................................................................................
   787    787     sqlite4_value **argv
   788    788   ){
   789    789     struct dstr x;
   790    790     memset(&x, 0, sizeof(x));
   791    791     (void)sqlite4_exec((sqlite4*)sqlite4_user_data(context),
   792    792         (char*)sqlite4_value_text(argv[0]),
   793    793         execFuncCallback, &x, 0);
   794         -  sqlite4_result_text(context, x.z, x.nUsed, SQLITE4_TRANSIENT);
          794  +  sqlite4_result_text(context, x.z, x.nUsed, SQLITE4_TRANSIENT, 0);
   795    795     sqlite4_free(0, x.z);
   796    796   }
   797    797   
   798    798   /*
   799    799   ** Implementation of tkt2213func(), a scalar function that takes exactly
   800    800   ** one argument. It has two interesting features:
   801    801   **
................................................................................
   827    827     zText3 = sqlite4_value_text(argv[0]);
   828    828   
   829    829     if( zText1!=zText2 || zText2!=zText3 ){
   830    830       sqlite4_result_error(context, "tkt2213 is not fixed", -1);
   831    831     }else{
   832    832       char *zCopy = (char *)sqlite4_malloc(sqlite4_context_env(context),nText);
   833    833       memcpy(zCopy, zText1, nText);
   834         -    sqlite4_result_text(context, zCopy, nText, SQLITE4_DYNAMIC);
          834  +    sqlite4_result_text(context, zCopy, nText, SQLITE4_DYNAMIC, 0);
   835    835     }
   836    836   }
   837    837   
   838    838   /*
   839    839   ** The following SQL function takes 4 arguments.  The 2nd and
   840    840   ** 4th argument must be one of these strings:  'text', 'text16',
   841    841   ** or 'blob' corresponding to API functions
................................................................................
   965    965     /* Use the sqlite4_create_function16() API here. Mainly for fun, but also 
   966    966     ** because it is not tested anywhere else. */
   967    967     if( rc==SQLITE4_OK ){
   968    968       const void *zUtf16;
   969    969       sqlite4_value *pVal;
   970    970       sqlite4_mutex_enter(db->mutex);
   971    971       pVal = sqlite4ValueNew(db);
   972         -    sqlite4ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE4_UTF8, SQLITE4_STATIC);
          972  +    sqlite4ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE4_UTF8,
          973  +                       SQLITE4_STATIC, 0);
   973    974       zUtf16 = sqlite4ValueText(pVal, SQLITE4_UTF16NATIVE);
   974    975       if( db->mallocFailed ){
   975    976         rc = SQLITE4_NOMEM;
   976    977       }else{
   977    978         rc = sqlite4_create_function16(db, zUtf16, 
   978    979                   1, SQLITE4_UTF16, db, sqlite4ExecFunc, 0, 0);
   979    980       }
................................................................................
  1710   1711       if( zArg0 ){
  1711   1712         if( 0==sqlite4_stricmp(zArg0, "int") ){
  1712   1713           sqlite4_result_int(context, sqlite4_value_int(argv[1]));
  1713   1714         }else if( sqlite4_stricmp(zArg0,"int64")==0 ){
  1714   1715           sqlite4_result_int64(context, sqlite4_value_int64(argv[1]));
  1715   1716         }else if( sqlite4_stricmp(zArg0,"string")==0 ){
  1716   1717           sqlite4_result_text(context, (char*)sqlite4_value_text(argv[1]), -1,
  1717         -            SQLITE4_TRANSIENT);
         1718  +            SQLITE4_TRANSIENT, 0);
  1718   1719         }else if( sqlite4_stricmp(zArg0,"double")==0 ){
  1719   1720           sqlite4_result_double(context, sqlite4_value_double(argv[1]));
  1720   1721         }else if( sqlite4_stricmp(zArg0,"null")==0 ){
  1721   1722           sqlite4_result_null(context);
  1722   1723         }else if( sqlite4_stricmp(zArg0,"value")==0 ){
  1723   1724           sqlite4_result_value(context, argv[sqlite4_value_int(argv[1])]);
  1724   1725         }else{
................................................................................
  2096   2097       return TCL_ERROR;
  2097   2098     }
  2098   2099     if( getStmtPointer(interp, argv[1], &pStmt) ) return TCL_ERROR;
  2099   2100     if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR;
  2100   2101     if( strcmp(argv[4],"null")==0 ){
  2101   2102       rc = sqlite4_bind_null(pStmt, idx);
  2102   2103     }else if( strcmp(argv[4],"static")==0 ){
  2103         -    rc = sqlite4_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0);
         2104  +    rc = sqlite4_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0, 0);
  2104   2105     }else if( strcmp(argv[4],"static-nbytes")==0 ){
  2105   2106       rc = sqlite4_bind_text(pStmt, idx, sqlite_static_bind_value,
  2106         -                                       sqlite_static_bind_nbyte, 0);
         2107  +                                       sqlite_static_bind_nbyte, 0, 0);
  2107   2108     }else if( strcmp(argv[4],"normal")==0 ){
  2108         -    rc = sqlite4_bind_text(pStmt, idx, argv[3], -1, SQLITE4_TRANSIENT);
         2109  +    rc = sqlite4_bind_text(pStmt, idx, argv[3], -1, SQLITE4_TRANSIENT, 0);
  2109   2110     }else if( strcmp(argv[4],"blob10")==0 ){
  2110         -    rc = sqlite4_bind_text(pStmt, idx, "abc\000xyz\000pq", 10, SQLITE4_STATIC);
         2111  +    rc = sqlite4_bind_text(pStmt, idx, "abc\000xyz\000pq", 10,SQLITE4_STATIC,0);
  2111   2112     }else{
  2112   2113       Tcl_AppendResult(interp, "4th argument should be "
  2113   2114           "\"null\" or \"static\" or \"normal\"", 0);
  2114   2115       return TCL_ERROR;
  2115   2116     }
  2116   2117     if( sqlite4TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  2117   2118     if( rc ){
................................................................................
  2183   2184       default:
  2184   2185         assert(0);
  2185   2186     }
  2186   2187   
  2187   2188     sqlite4BeginBenignMalloc(pEnv);
  2188   2189     pVal = sqlite4ValueNew(0);
  2189   2190     if( pVal ){
  2190         -    sqlite4ValueSetStr(pVal, nA, zA, encin, SQLITE4_STATIC);
         2191  +    sqlite4ValueSetStr(pVal, nA, zA, encin, SQLITE4_STATIC, 0);
  2191   2192       n = sqlite4_value_bytes(pVal);
  2192   2193       Tcl_ListObjAppendElement(i,pX,
  2193   2194           Tcl_NewStringObj((char*)sqlite4_value_text(pVal),n));
  2194         -    sqlite4ValueSetStr(pVal, nB, zB, encin, SQLITE4_STATIC);
         2195  +    sqlite4ValueSetStr(pVal, nB, zB, encin, SQLITE4_STATIC, 0);
  2195   2196       n = sqlite4_value_bytes(pVal);
  2196   2197       Tcl_ListObjAppendElement(i,pX,
  2197   2198           Tcl_NewStringObj((char*)sqlite4_value_text(pVal),n));
  2198   2199       sqlite4ValueFree(pVal);
  2199   2200     }
  2200   2201     sqlite4EndBenignMalloc(pEnv);
  2201   2202   
................................................................................
  2385   2386     pX = Tcl_NewStringObj("test_function", -1);
  2386   2387     Tcl_IncrRefCount(pX);
  2387   2388     Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1));
  2388   2389     Tcl_ListObjAppendElement(interp, pX, 
  2389   2390         Tcl_NewStringObj((char*)sqlite4_value_text(argv[0]), -1));
  2390   2391     Tcl_EvalObjEx(interp, pX, 0);
  2391   2392     Tcl_DecrRefCount(pX);
  2392         -  sqlite4_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE4_TRANSIENT);
         2393  +  sqlite4_result_text(pCtx, Tcl_GetStringResult(interp), -1,
         2394  +                      SQLITE4_TRANSIENT, 0);
  2393   2395     pVal = sqlite4ValueNew(0);
  2394   2396     sqlite4ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), 
  2395         -      SQLITE4_UTF8, SQLITE4_STATIC);
         2397  +      SQLITE4_UTF8, SQLITE4_STATIC, 0);
  2396   2398     sqlite4_result_text16be(pCtx, sqlite4_value_text16be(pVal),
  2397         -      -1, SQLITE4_TRANSIENT);
         2399  +      -1, SQLITE4_TRANSIENT, 0);
  2398   2400     sqlite4ValueFree(pVal);
  2399   2401   }
  2400   2402   static void test_function_utf16le(
  2401   2403     sqlite4_context *pCtx, 
  2402   2404     int nArg,
  2403   2405     sqlite4_value **argv
  2404   2406   ){
................................................................................
  2411   2413     Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1));
  2412   2414     Tcl_ListObjAppendElement(interp, pX, 
  2413   2415         Tcl_NewStringObj((char*)sqlite4_value_text(argv[0]), -1));
  2414   2416     Tcl_EvalObjEx(interp, pX, 0);
  2415   2417     Tcl_DecrRefCount(pX);
  2416   2418     pVal = sqlite4ValueNew(0);
  2417   2419     sqlite4ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), 
  2418         -      SQLITE4_UTF8, SQLITE4_STATIC);
  2419         -  sqlite4_result_text(pCtx,(char*)sqlite4_value_text(pVal),-1,SQLITE4_TRANSIENT);
         2420  +      SQLITE4_UTF8, SQLITE4_STATIC, 0);
         2421  +  sqlite4_result_text(pCtx, (char*)sqlite4_value_text(pVal), -1,
         2422  +                      SQLITE4_TRANSIENT, 0);
  2420   2423     sqlite4ValueFree(pVal);
  2421   2424   }
  2422   2425   static void test_function_utf16be(
  2423   2426     sqlite4_context *pCtx, 
  2424   2427     int nArg,
  2425   2428     sqlite4_value **argv
  2426   2429   ){
................................................................................
  2433   2436     Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1));
  2434   2437     Tcl_ListObjAppendElement(interp, pX, 
  2435   2438         Tcl_NewStringObj((char*)sqlite4_value_text(argv[0]), -1));
  2436   2439     Tcl_EvalObjEx(interp, pX, 0);
  2437   2440     Tcl_DecrRefCount(pX);
  2438   2441     pVal = sqlite4ValueNew(0);
  2439   2442     sqlite4ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), 
  2440         -      SQLITE4_UTF8, SQLITE4_STATIC);
         2443  +      SQLITE4_UTF8, SQLITE4_STATIC, 0);
  2441   2444     sqlite4_result_text16(pCtx, sqlite4_value_text16le(pVal),
  2442         -      -1, SQLITE4_TRANSIENT);
         2445  +      -1, SQLITE4_TRANSIENT, 0);
  2443   2446     sqlite4_result_text16be(pCtx, sqlite4_value_text16le(pVal),
  2444         -      -1, SQLITE4_TRANSIENT);
         2447  +      -1, SQLITE4_TRANSIENT, 0);
  2445   2448     sqlite4_result_text16le(pCtx, sqlite4_value_text16le(pVal),
  2446         -      -1, SQLITE4_TRANSIENT);
         2449  +      -1, SQLITE4_TRANSIENT, 0);
  2447   2450     sqlite4ValueFree(pVal);
  2448   2451   }
  2449   2452   #endif /* SQLITE4_OMIT_UTF16 */
  2450   2453   static int test_function(
  2451   2454     void * clientData,
  2452   2455     Tcl_Interp *interp,
  2453   2456     int objc,
................................................................................
  2784   2787     }
  2785   2788   
  2786   2789     if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  2787   2790     if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
  2788   2791     value = (char*)Tcl_GetByteArrayFromObj(objv[3], &bytes);
  2789   2792     if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
  2790   2793   
  2791         -  rc = sqlite4_bind_text(pStmt, idx, value, bytes, SQLITE4_TRANSIENT);
         2794  +  rc = sqlite4_bind_text(pStmt, idx, value, bytes, SQLITE4_TRANSIENT, 0);
  2792   2795     if( sqlite4TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  2793   2796     if( rc!=SQLITE4_OK ){
  2794   2797       Tcl_AppendResult(interp, sqlite4TestErrorName(rc), 0);
  2795   2798       return TCL_ERROR;
  2796   2799     }
  2797   2800   
  2798   2801     return TCL_OK;
................................................................................
  2832   2835     }
  2833   2836   
  2834   2837     if( getStmtPointer(interp, Tcl_GetString(oStmt), &pStmt) ) return TCL_ERROR;
  2835   2838     if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR;
  2836   2839     value = (char*)Tcl_GetByteArrayFromObj(oString, 0);
  2837   2840     if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR;
  2838   2841   
  2839         -  rc = sqlite4_bind_text16(pStmt, idx, (void *)value, bytes, xDel);
         2842  +  rc = sqlite4_bind_text16(pStmt, idx, (void *)value, bytes, xDel, 0);
  2840   2843     if( sqlite4TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  2841   2844     if( rc!=SQLITE4_OK ){
  2842   2845       Tcl_AppendResult(interp, sqlite4TestErrorName(rc), 0);
  2843   2846       return TCL_ERROR;
  2844   2847     }
  2845   2848   
  2846   2849   #endif /* SQLITE4_OMIT_UTF16 */
................................................................................
  2879   2882     }
  2880   2883   
  2881   2884     if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  2882   2885     if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
  2883   2886     value = Tcl_GetString(objv[3]);
  2884   2887     if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
  2885   2888   
  2886         -  rc = sqlite4_bind_blob(pStmt, idx, value, bytes, xDestructor);
         2889  +  rc = sqlite4_bind_blob(pStmt, idx, value, bytes, xDestructor, 0);
  2887   2890     if( sqlite4TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  2888   2891     if( rc!=SQLITE4_OK ){
  2889   2892       return TCL_ERROR;
  2890   2893     }
  2891   2894   
  2892   2895     return TCL_OK;
  2893   2896   }

Changes to test/test_utf.c.

   112    112     }
   113    113     if( pEnc->enc==SQLITE4_UTF16 ){
   114    114       return SQLITE4_UTF16NATIVE;
   115    115     }
   116    116     return pEnc->enc;
   117    117   }
   118    118   
   119         -static void freeStr(void *pStr){ sqlite4_free(0, pStr); }
          119  +static void freeStr(void *pEnv, void *pStr){
          120  +  sqlite4_free((sqlite4_env*)pEnv, pStr);
          121  +}
   120    122   
   121    123   /*
   122    124   ** Usage:   test_translate <string/blob> <from enc> <to enc> ?<transient>?
   123    125   **
   124    126   */
   125    127   static int test_translate(
   126    128     void * clientData,
................................................................................
   130    132   ){
   131    133     u8 enc_from;
   132    134     u8 enc_to;
   133    135     sqlite4_value *pVal;
   134    136   
   135    137     char *z;
   136    138     int len;
   137         -  void (*xDel)(void *p) = SQLITE4_STATIC;
          139  +  void (*xDel)(void*,void*) = SQLITE4_STATIC;
   138    140   
   139    141     if( objc!=4 && objc!=5 ){
   140    142       Tcl_AppendResult(interp, "wrong # args: should be \"",
   141    143           Tcl_GetStringFromObj(objv[0], 0), 
   142    144           " <string/blob> <from enc> <to enc>", 0
   143    145       );
   144    146       return TCL_ERROR;
................................................................................
   155    157     pVal = sqlite4ValueNew(0);
   156    158   
   157    159     if( enc_from==SQLITE4_UTF8 ){
   158    160       z = Tcl_GetString(objv[1]);
   159    161       if( objc==5 ){
   160    162         z = sqlite4_mprintf(0, "%s", z);
   161    163       }
   162         -    sqlite4ValueSetStr(pVal, -1, z, enc_from, xDel);
          164  +    sqlite4ValueSetStr(pVal, -1, z, enc_from, xDel, 0);
   163    165     }else{
   164    166       z = (char*)Tcl_GetByteArrayFromObj(objv[1], &len);
   165    167       if( objc==5 ){
   166    168         char *zTmp = z;
   167    169         z = sqlite4_malloc(0, len);
   168    170         memcpy(z, zTmp, len);
   169    171       }
   170         -    sqlite4ValueSetStr(pVal, -1, z, enc_from, xDel);
          172  +    sqlite4ValueSetStr(pVal, -1, z, enc_from, xDel, 0);
   171    173     }
   172    174   
   173    175     z = (char *)sqlite4ValueText(pVal, enc_to);
   174    176     len = sqlite4ValueBytes(pVal, enc_to) + (enc_to==SQLITE4_UTF8?1:2);
   175    177     Tcl_SetObjResult(interp, Tcl_NewByteArrayObj((u8*)z, len));
   176    178   
   177    179     sqlite4ValueFree(pVal);