The first patch causes SQLite to use localtime_r() when available instead of using localtime() and a mutex (the configure script will have to be regenerated using automake). The second patch allows users to create and drop tables while cursors are open on other tables iff SQLITE_OMIT_AUTOVACUUM is defined (hopefully this is OK :).

These diffs were generated against 3.2.1.

-Charlie

======================================================================== =============
--- orig/main.mk Wed Mar 23 08:09:39 2005
+++ main.mk Sat Apr 23 12:57:04 2005
@@ -12,6 +12,9 @@
# USLEEP If the target operating system supports the "usleep()" system
# call, then define the HAVE_USLEEP macro for all C modules.
#
+# LOCALTIME_R If the target operating system supports the "localtime_r()"
+# function, then define the HAVE_LOCALTIME_R macro for all C modules.
+#
# THREADSAFE If you want the SQLite library to be safe for use within a
# multi-threaded program, then define the following macro
# appropriately:
@@ -50,7 +53,7 @@


# This is how we compile
#
-TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
+TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) $(LOCALTIME_R) -I. -I$(TOP)/src


 # Object files for the SQLite library.
 #
--- orig/Makefile.linux-gcc     Wed Mar 23 08:09:39 2005
+++ Makefile.linux-gcc  Sat Apr 23 12:55:52 2005
@@ -28,6 +28,12 @@
 #USLEEP =
 USLEEP = -DHAVE_USLEEP=1

+#### If the target operating system supports the "localtime_r()"
+# function, then define the HAVE_LOCALTIME_R macro for all C modules.
+#
+#LOCALTIME_R =
+LOCALTIME_R = -DHAVE_LOCALTIME_R=1
+
#### If you want the SQLite library to be safe for use within a
# multi-threaded program, then define the following macro
# appropriately:
--- orig/configure.ac Wed Mar 23 08:08:39 2005
+++ configure.ac Sat Apr 23 12:50:15 2005
@@ -607,6 +607,10 @@
#
AC_CHECK_FUNC(usleep, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_USLEEP=1"])


+# Figure out if "localtime_r()" function is available.
+#
+AC_CHECK_FUNC(localtime_r, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_LOCALTIME_R=1"])
+
#########
# Generate the output files.
#
--- orig/src/date.c Wed Mar 23 08:09:39 2005
+++ src/date.c Sat Apr 23 13:08:52 2005
@@ -395,7 +395,6 @@
static double localtimeOffset(DateTime *p){
DateTime x, y;
time_t t;
- struct tm *pTm;
x = *p;
computeYMD_HMS(&x);
if( x.Y<1971 || x.Y>=2038 ){
@@ -413,15 +412,25 @@
x.validJD = 0;
computeJD(&x);
t = (x.rJD-2440587.5)*86400.0 + 0.5;
- sqlite3OsEnterMutex();
- pTm = localtime(&t);
- y.Y = pTm->tm_year + 1900;
- y.M = pTm->tm_mon + 1;
- y.D = pTm->tm_mday;
- y.h = pTm->tm_hour;
- y.m = pTm->tm_min;
- y.s = pTm->tm_sec;
- sqlite3OsLeaveMutex();
+ {
+ struct tm *pTm;
+#ifdef HAVE_LOCALTIME_R
+ struct tm tm;
+ pTm = localtime_r(&t, &tm);
+#else
+ sqlite3OsEnterMutex();
+ pTm = localtime(&t);
+#endif
+ y.Y = pTm->tm_year + 1900;
+ y.M = pTm->tm_mon + 1;
+ y.D = pTm->tm_mday;
+ y.h = pTm->tm_hour;
+ y.m = pTm->tm_min;
+ y.s = pTm->tm_sec;
+#ifndef HAVE_LOCALTIME_R
+ sqlite3OsLeaveMutex();
+#endif
+ }
y.validYMD = 1;
y.validHMS = 1;
y.validJD = 0;
======================================================================== =============


======================================================================== =============
--- orig/src/btree.c Tue Mar 29 05:18:50 2005
+++ src/btree.c Thu Apr 21 08:52:25 2005
@@ -4699,6 +4699,11 @@
}
assert( !pBt->readOnly );


+#ifdef SQLITE_OMIT_AUTOVACUUM
+  rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0);
+  if( rc ) return rc;
+#else
+
   /* It is illegal to create a table if any cursors are open on the
   ** database. This is because in auto-vacuum mode the backend may
   ** need to move a database page to make room for the new root-page.
@@ -4708,10 +4713,6 @@
     return SQLITE_LOCKED;
   }

-#ifdef SQLITE_OMIT_AUTOVACUUM
- rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0);
- if( rc ) return rc;
-#else
if( pBt->autoVacuum ){
Pgno pgnoMove; /* Move a page here to make room for the root-page */
MemPage *pPageMove; /* The page to move to. */
@@ -4908,6 +4909,16 @@
return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
}


+#ifdef SQLITE_OMIT_AUTOVACUUM
+ {
+ BtCursor *pCur;
+ for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
+ if( pCur->pgnoRoot==(Pgno)iTable ){
+ return SQLITE_LOCKED; /* Cannot drop a table that has a cursor */
+ }
+ }
+ }
+#else
/* It is illegal to drop a table if any cursors are open on the
** database. This is because in auto-vacuum mode the backend may
** need to move another root-page to fill a gap left by the deleted
@@ -4917,6 +4928,7 @@
if( pBt->pCursor ){
return SQLITE_LOCKED;
}
+#endif


rc = getPage(pBt, (Pgno)iTable, &pPage);
if( rc ) return rc;
--- orig/src/vdbe.c Tue Mar 29 05:14:03 2005
+++ src/vdbe.c Thu Apr 21 10:13:34 2005
@@ -3749,10 +3749,12 @@
*/
case OP_Destroy: {
int iMoved;
+ #ifndef SQLITE_OMIT_AUTOVACUUM
if( db->activeVdbeCnt>1 ){
rc = SQLITE_LOCKED;
}else{
assert( db->activeVdbeCnt==1 );
+ #endif
rc = sqlite3BtreeDropTable(db->aDb[pOp->p2].pBt, pOp->p1, &iMoved);
pTos++;
pTos->flags = MEM_Int;
@@ -3761,8 +3763,8 @@
if( rc==SQLITE_OK && iMoved!=0 ){
sqlite3RootPageMoved(&db->aDb[pOp->p2], iMoved, pOp->p1);
}
- #endif
}
+ #endif
break;
}
======================================================================== =============




Reply via email to