apply couple of bug fixes from sqlite
applying the following bug fixes
http://www.sqlite.org/src/info/82dd61fccf
Sync the database file after a rollback
http://www.sqlite.org/src/info/6f368b5448
Modify the sqlite3_log() interface and implementation so that it never
uses dynamic memory allocation - to avoid deadlocking when called
while holding the memory allocator mutex.
Change-Id: I93929d2dacd399ae9bd291404bcdf2c512691254
diff --git a/dist/sqlite3.c b/dist/sqlite3.c
index e324f8f..1376241 100644
--- a/dist/sqlite3.c
+++ b/dist/sqlite3.c
@@ -633,7 +633,7 @@
*/
#define SQLITE_VERSION "3.6.22"
#define SQLITE_VERSION_NUMBER 3006022
-#define SQLITE_SOURCE_ID "2010-03-03 00:02:58 e5342234357dcfde33fb7589f87d64f6de7d9970"
+#define SQLITE_SOURCE_ID "2010-03-22 23:55:10 82dd61fccff3e4c77e060e5734cd4b4e2eeb7c32"
/*
** CAPI3REF: Run-Time Library Version Numbers
@@ -6182,6 +6182,12 @@
** virtual tables, collating functions, and SQL functions. While there is
** nothing to prevent an application from calling sqlite3_log(), doing so
** is considered bad form.
+**
+** To avoid deadlocks and other threading problems, the sqlite3_log() routine
+** will not use dynamically allocated memory. The log message is stored in
+** a fixed-length buffer on the stack. If the log message is longer than
+** a few hundred characters, it will be truncated to the length of the
+** buffer.
*/
SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
@@ -17259,24 +17265,38 @@
}
/*
+** This is the routine that actually formats the sqlite3_log() message.
+** We house it in a separate routine from sqlite3_log() to avoid using
+** stack space on small-stack systems when logging is disabled.
+**
+** sqlite3_log() must render into a static buffer. It cannot dynamically
+** allocate memory because it might be called while the memory allocator
+** mutex is held.
+*/
+static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
+ StrAccum acc; /* String accumulator */
+#ifdef SQLITE_SMALL_STACK
+ char zMsg[150]; /* Complete log message */
+#else
+ char zMsg[400]; /* Complete log message */
+#endif
+
+ sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
+ acc.useMalloc = 0;
+ sqlite3VXPrintf(&acc, 0, zFormat, ap);
+ sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
+ sqlite3StrAccumFinish(&acc));
+}
+
+/*
** Format and write a message to the log if logging is enabled.
*/
SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...){
- void (*xLog)(void*, int, const char*); /* The global logger function */
- void *pLogArg; /* First argument to the logger */
va_list ap; /* Vararg list */
- char *zMsg; /* Complete log message */
-
- xLog = sqlite3GlobalConfig.xLog;
- if( xLog && zFormat ){
+ if( sqlite3GlobalConfig.xLog ){
va_start(ap, zFormat);
- sqlite3BeginBenignMalloc();
- zMsg = sqlite3_vmprintf(zFormat, ap);
- sqlite3EndBenignMalloc();
+ renderLogMsg(iErrCode, zFormat, ap);
va_end(ap);
- pLogArg = sqlite3GlobalConfig.pLogArg;
- xLog(pLogArg, iErrCode, zMsg ? zMsg : zFormat);
- sqlite3_free(zMsg);
}
}
@@ -33435,6 +33455,9 @@
rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
testcase( rc!=SQLITE_OK );
}
+ if( rc==SQLITE_OK && pPager->noSync==0 && pPager->state>=PAGER_EXCLUSIVE ){
+ rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
+ }
if( rc==SQLITE_OK ){
rc = pager_end_transaction(pPager, zMaster[0]!='\0');
testcase( rc!=SQLITE_OK );
diff --git a/dist/sqlite3.c.orig b/dist/sqlite3.c.orig
index 91ec2e3..f84e675 100644
--- a/dist/sqlite3.c.orig
+++ b/dist/sqlite3.c.orig
@@ -633,7 +633,7 @@
*/
#define SQLITE_VERSION "3.6.22"
#define SQLITE_VERSION_NUMBER 3006022
-#define SQLITE_SOURCE_ID "2010-03-03 00:02:58 e5342234357dcfde33fb7589f87d64f6de7d9970"
+#define SQLITE_SOURCE_ID "2010-03-22 23:55:10 82dd61fccff3e4c77e060e5734cd4b4e2eeb7c32"
/*
** CAPI3REF: Run-Time Library Version Numbers
@@ -6182,6 +6182,12 @@
** virtual tables, collating functions, and SQL functions. While there is
** nothing to prevent an application from calling sqlite3_log(), doing so
** is considered bad form.
+**
+** To avoid deadlocks and other threading problems, the sqlite3_log() routine
+** will not use dynamically allocated memory. The log message is stored in
+** a fixed-length buffer on the stack. If the log message is longer than
+** a few hundred characters, it will be truncated to the length of the
+** buffer.
*/
SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
@@ -17254,24 +17260,38 @@
}
/*
+** This is the routine that actually formats the sqlite3_log() message.
+** We house it in a separate routine from sqlite3_log() to avoid using
+** stack space on small-stack systems when logging is disabled.
+**
+** sqlite3_log() must render into a static buffer. It cannot dynamically
+** allocate memory because it might be called while the memory allocator
+** mutex is held.
+*/
+static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
+ StrAccum acc; /* String accumulator */
+#ifdef SQLITE_SMALL_STACK
+ char zMsg[150]; /* Complete log message */
+#else
+ char zMsg[400]; /* Complete log message */
+#endif
+
+ sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
+ acc.useMalloc = 0;
+ sqlite3VXPrintf(&acc, 0, zFormat, ap);
+ sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
+ sqlite3StrAccumFinish(&acc));
+}
+
+/*
** Format and write a message to the log if logging is enabled.
*/
SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...){
- void (*xLog)(void*, int, const char*); /* The global logger function */
- void *pLogArg; /* First argument to the logger */
va_list ap; /* Vararg list */
- char *zMsg; /* Complete log message */
-
- xLog = sqlite3GlobalConfig.xLog;
- if( xLog && zFormat ){
+ if( sqlite3GlobalConfig.xLog ){
va_start(ap, zFormat);
- sqlite3BeginBenignMalloc();
- zMsg = sqlite3_vmprintf(zFormat, ap);
- sqlite3EndBenignMalloc();
+ renderLogMsg(iErrCode, zFormat, ap);
va_end(ap);
- pLogArg = sqlite3GlobalConfig.pLogArg;
- xLog(pLogArg, iErrCode, zMsg ? zMsg : zFormat);
- sqlite3_free(zMsg);
}
}
@@ -33430,6 +33450,9 @@
rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
testcase( rc!=SQLITE_OK );
}
+ if( rc==SQLITE_OK && pPager->noSync==0 && pPager->state>=PAGER_EXCLUSIVE ){
+ rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
+ }
if( rc==SQLITE_OK ){
rc = pager_end_transaction(pPager, zMaster[0]!='\0');
testcase( rc!=SQLITE_OK );
diff --git a/dist/sqlite3.h b/dist/sqlite3.h
index 9e5c6e7..a275b00 100644
--- a/dist/sqlite3.h
+++ b/dist/sqlite3.h
@@ -109,7 +109,7 @@
*/
#define SQLITE_VERSION "3.6.22"
#define SQLITE_VERSION_NUMBER 3006022
-#define SQLITE_SOURCE_ID "2010-03-03 00:02:58 e5342234357dcfde33fb7589f87d64f6de7d9970"
+#define SQLITE_SOURCE_ID "2010-03-22 23:55:10 82dd61fccff3e4c77e060e5734cd4b4e2eeb7c32"
/*
** CAPI3REF: Run-Time Library Version Numbers
@@ -5658,8 +5658,15 @@
** virtual tables, collating functions, and SQL functions. While there is
** nothing to prevent an application from calling sqlite3_log(), doing so
** is considered bad form.
+**
+** To avoid deadlocks and other threading problems, the sqlite3_log() routine
+** will not use dynamically allocated memory. The log message is stored in
+** a fixed-length buffer on the stack. If the log message is longer than
+** a few hundred characters, it will be truncated to the length of the
+** buffer.
*/
SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
+
// Begin Android add
/*
** Android additional API.
diff --git a/dist/sqlite3.h.orig b/dist/sqlite3.h.orig
index 3343141..56efddd 100644
--- a/dist/sqlite3.h.orig
+++ b/dist/sqlite3.h.orig
@@ -109,7 +109,7 @@
*/
#define SQLITE_VERSION "3.6.22"
#define SQLITE_VERSION_NUMBER 3006022
-#define SQLITE_SOURCE_ID "2010-03-03 00:02:58 e5342234357dcfde33fb7589f87d64f6de7d9970"
+#define SQLITE_SOURCE_ID "2010-03-22 23:55:10 82dd61fccff3e4c77e060e5734cd4b4e2eeb7c32"
/*
** CAPI3REF: Run-Time Library Version Numbers
@@ -5658,6 +5658,12 @@
** virtual tables, collating functions, and SQL functions. While there is
** nothing to prevent an application from calling sqlite3_log(), doing so
** is considered bad form.
+**
+** To avoid deadlocks and other threading problems, the sqlite3_log() routine
+** will not use dynamically allocated memory. The log message is stored in
+** a fixed-length buffer on the stack. If the log message is longer than
+** a few hundred characters, it will be truncated to the length of the
+** buffer.
*/
SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
diff --git a/dist/version b/dist/version
index 3aae4ce..dca041c 100644
--- a/dist/version
+++ b/dist/version
@@ -1,2 +1,2 @@
3.6.22 Froyo branch http://www.sqlite.org/src/timeline?t=branch-3.6.22
-at checkin http://www.sqlite.org/src/info/e534223435
+at checkin http://www.sqlite.org/src/info/82dd61fccf