]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Documentation changes to warn that sqlite3_set_auxdata() might call the
authordrh <drh@noemail.net>
Thu, 18 Jul 2013 14:16:48 +0000 (14:16 +0000)
committerdrh <drh@noemail.net>
Thu, 18 Jul 2013 14:16:48 +0000 (14:16 +0000)
destructor even before it returns.  Also fix the regexp extension to deal
with that case.  Ticket [406d3b2ef91c].

FossilOrigin-Name: 7acc8cd32d593a473c9e9adaf323220a7a46480a

ext/misc/regexp.c
manifest
manifest.uuid
src/sqlite.h.in

index 16fa7d0b968593d5df52610fc93e65283437417c..7244d5299815b3607fb8098172eabcfc1a5fe7a6 100644 (file)
@@ -713,6 +713,7 @@ static void re_sql_func(
   const char *zPattern;     /* The regular expression */
   const unsigned char *zStr;/* String being searched */
   const char *zErr;         /* Compile error message */
+  int setAux = 0;           /* True to invoke sqlite3_set_auxdata() */
 
   pRe = sqlite3_get_auxdata(context, 0);
   if( pRe==0 ){
@@ -728,12 +729,15 @@ static void re_sql_func(
       sqlite3_result_error_nomem(context);
       return;
     }
-    sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
+    setAux = 1;
   }
   zStr = (const unsigned char*)sqlite3_value_text(argv[1]);
   if( zStr!=0 ){
     sqlite3_result_int(context, re_match(pRe, zStr, -1));
   }
+  if( setAux ){
+    sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
+  }
 }
 
 /*
index 959b43b31b6596a56ed14a164b91e86538fca7e0..e3da8a2f42fac8186fc8a23a88ea564f088a9d1d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\scopy/paste\serrors\sin\scomments\sin\sthe\stransitive_closure\svirtual\stable.\nNo\schanges\sto\scode.
-D 2013-07-17T21:08:49.318
+C Documentation\schanges\sto\swarn\sthat\ssqlite3_set_auxdata()\smight\scall\sthe\ndestructor\seven\sbefore\sit\sreturns.\s\sAlso\sfix\sthe\sregexp\sextension\sto\sdeal\nwith\sthat\scase.\s\sTicket\s[406d3b2ef91c].
+D 2013-07-18T14:16:48.544
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -112,7 +112,7 @@ F ext/misc/fuzzer.c 136533c53cfce0957f0b48fa11dba27e21c5c01d
 F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e
 F ext/misc/nextchar.c 80ba262d23238efcfcb3d72d71aa4513098e26a6
 F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63
-F ext/misc/regexp.c c25c65fe775f5d9801fb8573e36ebe73f2c0c2e0
+F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc
 F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a
 F ext/misc/spellfix.c 5e1d547e9a2aed13897fa91bac924333f62fd2d9
 F ext/misc/vtshim.c 5fb6be7fe37659a8cbd1e16982d74cceacbc4543
@@ -218,7 +218,7 @@ F src/resolve.c 89f9003e8316ee3a172795459efc2a0274e1d5a8
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
 F src/select.c 91b62654caf8dfe292fb8882715e575d34ad3874
 F src/shell.c 4c02ec99e42aeb624bb221b253273da6c910b814
-F src/sqlite.h.in 30c88ce7862096b0aecf4c2c886bc0934eeaa515
+F src/sqlite.h.in ab59321198fe4e002890c8154642338e7da75e82
 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
 F src/sqliteInt.h 6d3115f774aa3e87737f9447c9c0cea992c5bdbf
@@ -1103,7 +1103,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 3b4096cc8a3b4517cdf49dcfe1f33279a5eb8efb
-R 72a343c5196cc394b974aafe1ea79d9a
+P b1b0de29fdf7de83722bb85b748f058b9901e77a
+R 1373096ae79cc1001233efb4a308bce9
 U drh
-Z 567058614f26922b80a2886ec42c5224
+Z 4c86c705c11f63416d538424aa7f228b
index 05bc013ddf4c0cef4d2dc051c7d6b0d52693813d..c3cee86f445c865c74024c260da2cd71ecfe9c86 100644 (file)
@@ -1 +1 @@
-b1b0de29fdf7de83722bb85b748f058b9901e77a
\ No newline at end of file
+7acc8cd32d593a473c9e9adaf323220a7a46480a
\ No newline at end of file
index 3b7237996b7f89e7572f3ac1e65c2bfa77d7d0fd..8c600a1fa397cbb87c1d8f637e2fd37d6ef320db 100644 (file)
@@ -4179,8 +4179,8 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
 ** The following two functions may be used by scalar SQL functions to
 ** associate metadata with argument values. If the same value is passed to
 ** multiple invocations of the same SQL function during query execution, under
-** some circumstances the associated metadata may be preserved. This may
-** be used, for example, to add a regular-expression matching scalar
+** some circumstances the associated metadata may be preserved. This might
+** be used, for example, in a regular-expression matching
 ** function. The compiled version of the regular expression is stored as
 ** metadata associated with the SQL value passed as the regular expression
 ** pattern.  The compiled regular expression can be reused on multiple
@@ -4194,23 +4194,32 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
 ** function parameter has changed since the meta-data was set,
 ** then sqlite3_get_auxdata() returns a NULL pointer.
 **
-** ^The sqlite3_set_auxdata() interface saves the metadata
-** pointed to by its 3rd parameter as the metadata for the N-th
-** argument of the application-defined function.  Subsequent
-** calls to sqlite3_get_auxdata() might return this data, if it has
-** not been destroyed.
-** ^If it is not NULL, SQLite will invoke the destructor
-** function given by the 4th parameter to sqlite3_set_auxdata() on
-** the metadata when the corresponding function parameter changes
-** or when the SQL statement completes, whichever comes first.
+** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
+** argument of the application-defined function.  ^Subsequent
+** calls to sqlite3_get_auxdata(C,N) return P from the most recent
+** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
+** NULL if the data has been dropped.
+** ^(If it is not NULL, SQLite will invoke the destructor
+** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
+** <li> the corresponding function parameter changes,
+** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
+**      SQL statement,
+** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
+** <li> a memory allocation error occurs. </ul>)^
 **
 ** SQLite is free to call the destructor and drop metadata on any
 ** parameter of any function at any time.  ^The only guarantee is that
-** the destructor will be called before the metadata is dropped.
+** the destructor will be called when the [prepared statement] is destroyed.
+** Note in particular that the destructor X in the call to
+** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
+** the sqlite3_set_auxdata() call even returns.  Hence sqlite3_set_auxdata()
+** should be called near the end of the function implementation and the
+** implementation should not make any use of P after sqlite3_set_auxdata()
+** has been called.
 **
 ** ^(In practice, metadata is preserved between function calls for
-** expressions that are constant at compile time. This includes literal
-** values and [parameters].)^
+** function parameters that are compile-time constants, including literal
+** values and [parameters] and expressions composed from the same.)^
 **
 ** These routines must be called from the same thread in which
 ** the SQL function is running.