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 ){
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);
+ }
}
/*
-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
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
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
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
** 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
** 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.