| | @@ -16,11 +16,11 @@ |
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | | -** 354ce4f5e2a86b621b2058a6372495a5919c with changes in files: |
| 21 | +** 4aac1057eeaf6c29a4893e9c080497c780b0 with changes in files: |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| | @@ -467,14 +467,14 @@ |
| 467 | 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | 468 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | 469 | */ |
| 470 | 470 | #define SQLITE_VERSION "3.54.0" |
| 471 | 471 | #define SQLITE_VERSION_NUMBER 3054000 |
| 472 | | -#define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002" |
| 472 | +#define SQLITE_SOURCE_ID "2026-04-30 18:23:58 4aac1057eeaf6c29a4893e9c080497c780b0963e810c501532d79eba1b457f27" |
| 473 | 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | 474 | #define SQLITE_SCM_TAGS "" |
| 475 | | -#define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z" |
| 475 | +#define SQLITE_SCM_DATETIME "2026-04-30T18:23:58.352Z" |
| 476 | 476 | |
| 477 | 477 | /* |
| 478 | 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | 480 | ** |
| | @@ -14669,11 +14669,11 @@ |
| 14669 | 14669 | |
| 14670 | 14670 | /************** End of sqlite3.h *********************************************/ |
| 14671 | 14671 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 14672 | 14672 | |
| 14673 | 14673 | /* |
| 14674 | | -** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory. |
| 14674 | +** Reuse the STATIC_VFS1 for mutex access to sqlite3_temp_directory. |
| 14675 | 14675 | */ |
| 14676 | 14676 | #define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1 |
| 14677 | 14677 | |
| 14678 | 14678 | /* |
| 14679 | 14679 | ** Include the configuration header output by 'configure' if we're using the |
| | @@ -30666,14 +30666,27 @@ |
| 30666 | 30666 | # define SQLITE_MUTEX_NREF 1 |
| 30667 | 30667 | #else |
| 30668 | 30668 | # define SQLITE_MUTEX_NREF 0 |
| 30669 | 30669 | #endif |
| 30670 | 30670 | |
| 30671 | +#if GCC_VERSION>0 |
| 30672 | +# define ALIGN128 __attribute__((aligned(128))) |
| 30673 | +#else |
| 30674 | +# define ALIGN128 |
| 30675 | +#endif |
| 30676 | + |
| 30671 | 30677 | /* |
| 30672 | | -** Each recursive mutex is an instance of the following structure. |
| 30678 | +** Each SQLite mutex is an instance of the following structure. |
| 30679 | +** |
| 30680 | +** The ALIGN128 macro attempts to force 128-byte alignment on mutexes, |
| 30681 | +** so that adjacent mutex objects are always on different cache lines |
| 30682 | +** in the CPU. This is CPU-dependent, of course, but 128-byte alignment |
| 30683 | +** seems to work well for all contemporary processors. Experiments show |
| 30684 | +** that 64 works just as well most of the time, but the internet says |
| 30685 | +** that 128-byte alignment works better. |
| 30673 | 30686 | */ |
| 30674 | | -struct sqlite3_mutex { |
| 30687 | +struct ALIGN128 sqlite3_mutex { |
| 30675 | 30688 | pthread_mutex_t mutex; /* Mutex controlling the lock */ |
| 30676 | 30689 | #if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) |
| 30677 | 30690 | int id; /* Mutex type */ |
| 30678 | 30691 | #endif |
| 30679 | 30692 | #if SQLITE_MUTEX_NREF |
| | @@ -31081,57 +31094,15 @@ |
| 31081 | 31094 | # include <sys/stat.h> /* amalgamator: dontcache */ |
| 31082 | 31095 | # include <unistd.h> /* amalgamator: dontcache */ |
| 31083 | 31096 | # include <errno.h> /* amalgamator: dontcache */ |
| 31084 | 31097 | #endif |
| 31085 | 31098 | |
| 31086 | | -/* |
| 31087 | | -** Determine if we are dealing with Windows NT. |
| 31088 | | -** |
| 31089 | | -** We ought to be able to determine if we are compiling for Windows 9x or |
| 31090 | | -** Windows NT using the _WIN32_WINNT macro as follows: |
| 31091 | | -** |
| 31092 | | -** #if defined(_WIN32_WINNT) |
| 31093 | | -** # define SQLITE_OS_WINNT 1 |
| 31094 | | -** #else |
| 31095 | | -** # define SQLITE_OS_WINNT 0 |
| 31096 | | -** #endif |
| 31097 | | -** |
| 31098 | | -** However, Visual Studio 2005 does not set _WIN32_WINNT by default, as |
| 31099 | | -** it ought to, so the above test does not work. We'll just assume that |
| 31100 | | -** everything is Windows NT unless the programmer explicitly says otherwise |
| 31101 | | -** by setting SQLITE_OS_WINNT to 0. |
| 31102 | | -*/ |
| 31103 | | -#if SQLITE_OS_WIN && !defined(SQLITE_OS_WINNT) |
| 31104 | | -# define SQLITE_OS_WINNT 1 |
| 31105 | | -#endif |
| 31106 | | - |
| 31107 | | -/* |
| 31108 | | -** Determine if we are dealing with Windows CE - which has a much reduced |
| 31109 | | -** API. |
| 31110 | | -*/ |
| 31111 | | -#if defined(_WIN32_WCE) |
| 31112 | | -# define SQLITE_OS_WINCE 1 |
| 31113 | | -#else |
| 31114 | | -# define SQLITE_OS_WINCE 0 |
| 31115 | | -#endif |
| 31116 | | - |
| 31117 | | -/* |
| 31118 | | -** For WinCE, some API function parameters do not appear to be declared as |
| 31119 | | -** volatile. |
| 31120 | | -*/ |
| 31121 | | -#if SQLITE_OS_WINCE |
| 31122 | | -# define SQLITE_WIN32_VOLATILE |
| 31123 | | -#else |
| 31124 | | -# define SQLITE_WIN32_VOLATILE volatile |
| 31125 | | -#endif |
| 31126 | | - |
| 31127 | 31099 | /* |
| 31128 | 31100 | ** For some Windows sub-platforms, the _beginthreadex() / _endthreadex() |
| 31129 | 31101 | ** functions are not available (e.g. those not using MSVC, Cygwin, etc). |
| 31130 | 31102 | */ |
| 31131 | | -#if SQLITE_OS_WIN && !SQLITE_OS_WINCE && \ |
| 31132 | | - SQLITE_THREADSAFE>0 && !defined(__CYGWIN__) |
| 31103 | +#if SQLITE_OS_WIN && SQLITE_THREADSAFE>0 && !defined(__CYGWIN__) |
| 31133 | 31104 | # define SQLITE_OS_WIN_THREADS 1 |
| 31134 | 31105 | #else |
| 31135 | 31106 | # define SQLITE_OS_WIN_THREADS 0 |
| 31136 | 31107 | #endif |
| 31137 | 31108 | |
| | @@ -31145,36 +31116,41 @@ |
| 31145 | 31116 | ** The code in this file is only used if we are compiling multithreaded |
| 31146 | 31117 | ** on a Win32 system. |
| 31147 | 31118 | */ |
| 31148 | 31119 | #ifdef SQLITE_MUTEX_W32 |
| 31149 | 31120 | |
| 31121 | +#if MSVC_VERSION>0 |
| 31122 | +# define ALIGN128 __declspec(align(128)) |
| 31123 | +#else |
| 31124 | +# define ALIGN128 |
| 31125 | +#endif |
| 31126 | + |
| 31127 | +#pragma warning(push) |
| 31128 | +#pragma warning(disable: 4324) |
| 31150 | 31129 | /* |
| 31151 | | -** Each recursive mutex is an instance of the following structure. |
| 31130 | +** Each SQLite mutex is an instance of the following structure. |
| 31131 | +** |
| 31132 | +** The ALIGN128 macro attempts to force 128-byte alignment on mutexes, |
| 31133 | +** so that adjacent mutex objects are always on different cache lines |
| 31134 | +** in the CPU. This is CPU-dependent, of course, but 128-byte alignment |
| 31135 | +** seems to work well for all contemporary processors. Experiments show |
| 31136 | +** that 64 works just as well most of the time, but the internet says |
| 31137 | +** that 128-byte alignment works better. |
| 31152 | 31138 | */ |
| 31153 | | -struct sqlite3_mutex { |
| 31154 | | - CRITICAL_SECTION mutex; /* Mutex controlling the lock */ |
| 31139 | +struct ALIGN128 sqlite3_mutex { |
| 31140 | + union { |
| 31141 | + CRITICAL_SECTION cs; /* The CRITICAL_SECTION mutex. id==1 */ |
| 31142 | + SRWLOCK srwl; /* The Slim reader/writer lock. id!=1 */ |
| 31143 | + } u; |
| 31155 | 31144 | int id; /* Mutex type */ |
| 31156 | 31145 | #ifdef SQLITE_DEBUG |
| 31157 | 31146 | volatile int nRef; /* Number of entrances */ |
| 31158 | 31147 | volatile DWORD owner; /* Thread holding this mutex */ |
| 31159 | 31148 | volatile LONG trace; /* True to trace changes */ |
| 31160 | 31149 | #endif |
| 31161 | 31150 | }; |
| 31162 | | - |
| 31163 | | -/* |
| 31164 | | -** These are the initializer values used when declaring a "static" mutex |
| 31165 | | -** on Win32. It should be noted that all mutexes require initialization |
| 31166 | | -** on the Win32 platform. |
| 31167 | | -*/ |
| 31168 | | -#define SQLITE_W32_MUTEX_INITIALIZER { 0 } |
| 31169 | | - |
| 31170 | | -#ifdef SQLITE_DEBUG |
| 31171 | | -#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id, \ |
| 31172 | | - 0L, (DWORD)0, 0 } |
| 31173 | | -#else |
| 31174 | | -#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id } |
| 31175 | | -#endif |
| 31151 | +#pragma warning(pop) |
| 31176 | 31152 | |
| 31177 | 31153 | #ifdef SQLITE_DEBUG |
| 31178 | 31154 | /* |
| 31179 | 31155 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are |
| 31180 | 31156 | ** intended for use only inside assert() statements. |
| | @@ -31181,17 +31157,12 @@ |
| 31181 | 31157 | */ |
| 31182 | 31158 | static int winMutexHeld(sqlite3_mutex *p){ |
| 31183 | 31159 | return p->nRef!=0 && p->owner==GetCurrentThreadId(); |
| 31184 | 31160 | } |
| 31185 | 31161 | |
| 31186 | | -static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){ |
| 31187 | | - return p->nRef==0 || p->owner!=tid; |
| 31188 | | -} |
| 31189 | | - |
| 31190 | 31162 | static int winMutexNotheld(sqlite3_mutex *p){ |
| 31191 | | - DWORD tid = GetCurrentThreadId(); |
| 31192 | | - return winMutexNotheld2(p, tid); |
| 31163 | + return p->nRef==0 || p->owner!=GetCurrentThreadId(); |
| 31193 | 31164 | } |
| 31194 | 31165 | #endif |
| 31195 | 31166 | |
| 31196 | 31167 | /* |
| 31197 | 31168 | ** Try to provide a memory barrier operation, needed for initialization |
| | @@ -31211,43 +31182,34 @@ |
| 31211 | 31182 | } |
| 31212 | 31183 | |
| 31213 | 31184 | /* |
| 31214 | 31185 | ** Initialize and deinitialize the mutex subsystem. |
| 31215 | 31186 | */ |
| 31216 | | -static sqlite3_mutex winMutex_staticMutexes[] = { |
| 31217 | | - SQLITE3_MUTEX_INITIALIZER(2), |
| 31218 | | - SQLITE3_MUTEX_INITIALIZER(3), |
| 31219 | | - SQLITE3_MUTEX_INITIALIZER(4), |
| 31220 | | - SQLITE3_MUTEX_INITIALIZER(5), |
| 31221 | | - SQLITE3_MUTEX_INITIALIZER(6), |
| 31222 | | - SQLITE3_MUTEX_INITIALIZER(7), |
| 31223 | | - SQLITE3_MUTEX_INITIALIZER(8), |
| 31224 | | - SQLITE3_MUTEX_INITIALIZER(9), |
| 31225 | | - SQLITE3_MUTEX_INITIALIZER(10), |
| 31226 | | - SQLITE3_MUTEX_INITIALIZER(11), |
| 31227 | | - SQLITE3_MUTEX_INITIALIZER(12), |
| 31228 | | - SQLITE3_MUTEX_INITIALIZER(13) |
| 31229 | | -}; |
| 31230 | | - |
| 31187 | +static sqlite3_mutex winMutex_staticMutexes[12]; |
| 31231 | 31188 | static int winMutex_isInit = 0; |
| 31232 | | -static int winMutex_isNt = -1; /* <0 means "need to query" */ |
| 31233 | 31189 | |
| 31234 | 31190 | /* As the winMutexInit() and winMutexEnd() functions are called as part |
| 31235 | 31191 | ** of the sqlite3_initialize() and sqlite3_shutdown() processing, the |
| 31236 | 31192 | ** "interlocked" magic used here is probably not strictly necessary. |
| 31237 | 31193 | */ |
| 31238 | | -static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0; |
| 31194 | +static LONG volatile winMutex_lock = 0; |
| 31239 | 31195 | |
| 31240 | | -SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */ |
| 31241 | 31196 | SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */ |
| 31242 | 31197 | |
| 31243 | 31198 | static int winMutexInit(void){ |
| 31244 | 31199 | /* The first to increment to 1 does actual initialization */ |
| 31245 | 31200 | if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ |
| 31246 | 31201 | int i; |
| 31247 | 31202 | for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ |
| 31248 | | - InitializeCriticalSection(&winMutex_staticMutexes[i].mutex); |
| 31203 | + sqlite3_mutex *p = &winMutex_staticMutexes[i]; |
| 31204 | + p->id = i+2; |
| 31205 | + InitializeSRWLock(&p->u.srwl); |
| 31206 | +#ifdef SQLITE_DEBUG |
| 31207 | + p->nRef = 0; |
| 31208 | + p->owner = 0; |
| 31209 | + p->trace = 0; |
| 31210 | +#endif |
| 31249 | 31211 | } |
| 31250 | 31212 | winMutex_isInit = 1; |
| 31251 | 31213 | }else{ |
| 31252 | 31214 | /* Another thread is (in the process of) initializing the static |
| 31253 | 31215 | ** mutexes */ |
| | @@ -31261,14 +31223,10 @@ |
| 31261 | 31223 | static int winMutexEnd(void){ |
| 31262 | 31224 | /* The first to decrement to 0 does actual shutdown |
| 31263 | 31225 | ** (which should be the last to shutdown.) */ |
| 31264 | 31226 | if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){ |
| 31265 | 31227 | if( winMutex_isInit==1 ){ |
| 31266 | | - int i; |
| 31267 | | - for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ |
| 31268 | | - DeleteCriticalSection(&winMutex_staticMutexes[i].mutex); |
| 31269 | | - } |
| 31270 | 31228 | winMutex_isInit = 0; |
| 31271 | 31229 | } |
| 31272 | 31230 | } |
| 31273 | 31231 | return SQLITE_OK; |
| 31274 | 31232 | } |
| | @@ -31333,11 +31291,15 @@ |
| 31333 | 31291 | #ifdef SQLITE_DEBUG |
| 31334 | 31292 | #ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC |
| 31335 | 31293 | p->trace = 1; |
| 31336 | 31294 | #endif |
| 31337 | 31295 | #endif |
| 31338 | | - InitializeCriticalSection(&p->mutex); |
| 31296 | + if( iType==SQLITE_MUTEX_RECURSIVE ){ |
| 31297 | + InitializeCriticalSection(&p->u.cs); |
| 31298 | + }else{ |
| 31299 | + InitializeSRWLock(&p->u.srwl); |
| 31300 | + } |
| 31339 | 31301 | } |
| 31340 | 31302 | break; |
| 31341 | 31303 | } |
| 31342 | 31304 | default: { |
| 31343 | 31305 | #ifdef SQLITE_ENABLE_API_ARMOR |
| | @@ -31366,12 +31328,14 @@ |
| 31366 | 31328 | ** mutex that it allocates. |
| 31367 | 31329 | */ |
| 31368 | 31330 | static void winMutexFree(sqlite3_mutex *p){ |
| 31369 | 31331 | assert( p ); |
| 31370 | 31332 | assert( p->nRef==0 && p->owner==0 ); |
| 31371 | | - if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ){ |
| 31372 | | - DeleteCriticalSection(&p->mutex); |
| 31333 | + if( p->id==SQLITE_MUTEX_FAST ){ |
| 31334 | + sqlite3_free(p); |
| 31335 | + }else if( p->id==SQLITE_MUTEX_RECURSIVE ){ |
| 31336 | + DeleteCriticalSection(&p->u.cs); |
| 31373 | 31337 | sqlite3_free(p); |
| 31374 | 31338 | }else{ |
| 31375 | 31339 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 31376 | 31340 | (void)SQLITE_MISUSE_BKPT; |
| 31377 | 31341 | #endif |
| | @@ -31388,71 +31352,60 @@ |
| 31388 | 31352 | ** mutex must be exited an equal number of times before another thread |
| 31389 | 31353 | ** can enter. If the same thread tries to enter any other kind of mutex |
| 31390 | 31354 | ** more than once, the behavior is undefined. |
| 31391 | 31355 | */ |
| 31392 | 31356 | static void winMutexEnter(sqlite3_mutex *p){ |
| 31393 | | -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 31394 | | - DWORD tid = GetCurrentThreadId(); |
| 31395 | | -#endif |
| 31396 | | -#ifdef SQLITE_DEBUG |
| 31397 | | - assert( p ); |
| 31398 | | - assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) ); |
| 31399 | | -#else |
| 31400 | | - assert( p ); |
| 31357 | + assert( p ); |
| 31358 | +#ifdef SQLITE_DEBUG |
| 31359 | + assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) ); |
| 31401 | 31360 | #endif |
| 31402 | 31361 | assert( winMutex_isInit==1 ); |
| 31403 | | - EnterCriticalSection(&p->mutex); |
| 31362 | + if( p->id==SQLITE_MUTEX_RECURSIVE ){ |
| 31363 | + EnterCriticalSection(&p->u.cs); |
| 31364 | + }else{ |
| 31365 | + AcquireSRWLockExclusive(&p->u.srwl); |
| 31366 | + } |
| 31404 | 31367 | #ifdef SQLITE_DEBUG |
| 31405 | 31368 | assert( p->nRef>0 || p->owner==0 ); |
| 31406 | | - p->owner = tid; |
| 31369 | + p->owner = GetCurrentThreadId(); |
| 31407 | 31370 | p->nRef++; |
| 31408 | 31371 | if( p->trace ){ |
| 31409 | 31372 | OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n", |
| 31410 | | - tid, p->id, p, p->trace, p->nRef)); |
| 31373 | + GetCurrentThreadId(), p->id, p, p->trace, p->nRef)); |
| 31411 | 31374 | } |
| 31412 | 31375 | #endif |
| 31413 | 31376 | } |
| 31414 | 31377 | |
| 31415 | 31378 | static int winMutexTry(sqlite3_mutex *p){ |
| 31416 | | -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 31417 | | - DWORD tid = GetCurrentThreadId(); |
| 31418 | | -#endif |
| 31419 | 31379 | int rc = SQLITE_BUSY; |
| 31420 | 31380 | assert( p ); |
| 31421 | | - assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) ); |
| 31381 | + assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) ); |
| 31422 | 31382 | /* |
| 31423 | | - ** The sqlite3_mutex_try() routine is very rarely used, and when it |
| 31424 | | - ** is used it is merely an optimization. So it is OK for it to always |
| 31383 | + ** The sqlite3_mutex_try() routine is seldom used, and when it is |
| 31384 | + ** used it is merely an optimization. So it is OK for it to always |
| 31425 | 31385 | ** fail. |
| 31426 | | - ** |
| 31427 | | - ** The TryEnterCriticalSection() interface is only available on WinNT. |
| 31428 | | - ** And some windows compilers complain if you try to use it without |
| 31429 | | - ** first doing some #defines that prevent SQLite from building on Win98. |
| 31430 | | - ** For that reason, we will omit this optimization for now. See |
| 31431 | | - ** ticket #2685. |
| 31432 | 31386 | */ |
| 31433 | | -#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 |
| 31434 | | - assert( winMutex_isInit==1 ); |
| 31435 | | - assert( winMutex_isNt>=-1 && winMutex_isNt<=1 ); |
| 31436 | | - if( winMutex_isNt<0 ){ |
| 31437 | | - winMutex_isNt = sqlite3_win32_is_nt(); |
| 31438 | | - } |
| 31439 | | - assert( winMutex_isNt==0 || winMutex_isNt==1 ); |
| 31440 | | - if( winMutex_isNt && TryEnterCriticalSection(&p->mutex) ){ |
| 31441 | | -#ifdef SQLITE_DEBUG |
| 31442 | | - p->owner = tid; |
| 31387 | + if( p->id==SQLITE_MUTEX_RECURSIVE ){ |
| 31388 | + rc = TryEnterCriticalSection(&p->u.cs); |
| 31389 | + }else{ |
| 31390 | + rc = TryAcquireSRWLockExclusive(&p->u.srwl); |
| 31391 | + } |
| 31392 | + if( rc ){ |
| 31393 | +#ifdef SQLITE_DEBUG |
| 31394 | + p->owner = GetCurrentThreadId(); |
| 31443 | 31395 | p->nRef++; |
| 31444 | 31396 | #endif |
| 31445 | 31397 | rc = SQLITE_OK; |
| 31398 | + }else{ |
| 31399 | + rc = SQLITE_BUSY; |
| 31446 | 31400 | } |
| 31447 | | -#else |
| 31448 | | - UNUSED_PARAMETER(p); |
| 31449 | | -#endif |
| 31450 | 31401 | #ifdef SQLITE_DEBUG |
| 31451 | 31402 | if( p->trace ){ |
| 31452 | | - OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n", |
| 31453 | | - tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc))); |
| 31403 | + OSTRACE(( |
| 31404 | + "TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n", |
| 31405 | + GetCurrentThreadId(), p->id, p, p->trace, p->owner, p->nRef, |
| 31406 | + sqlite3ErrName(rc))); |
| 31454 | 31407 | } |
| 31455 | 31408 | #endif |
| 31456 | 31409 | return rc; |
| 31457 | 31410 | } |
| 31458 | 31411 | |
| | @@ -31461,27 +31414,28 @@ |
| 31461 | 31414 | ** previously entered by the same thread. The behavior |
| 31462 | 31415 | ** is undefined if the mutex is not currently entered or |
| 31463 | 31416 | ** is not currently allocated. SQLite will never do either. |
| 31464 | 31417 | */ |
| 31465 | 31418 | static void winMutexLeave(sqlite3_mutex *p){ |
| 31466 | | -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 31467 | | - DWORD tid = GetCurrentThreadId(); |
| 31468 | | -#endif |
| 31469 | 31419 | assert( p ); |
| 31470 | 31420 | #ifdef SQLITE_DEBUG |
| 31471 | 31421 | assert( p->nRef>0 ); |
| 31472 | | - assert( p->owner==tid ); |
| 31422 | + assert( p->owner==GetCurrentThreadId() ); |
| 31473 | 31423 | p->nRef--; |
| 31474 | 31424 | if( p->nRef==0 ) p->owner = 0; |
| 31475 | 31425 | assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); |
| 31476 | 31426 | #endif |
| 31477 | 31427 | assert( winMutex_isInit==1 ); |
| 31478 | | - LeaveCriticalSection(&p->mutex); |
| 31428 | + if( p->id==SQLITE_MUTEX_RECURSIVE ){ |
| 31429 | + LeaveCriticalSection(&p->u.cs); |
| 31430 | + }else{ |
| 31431 | + ReleaseSRWLockExclusive(&p->u.srwl); |
| 31432 | + } |
| 31479 | 31433 | #ifdef SQLITE_DEBUG |
| 31480 | 31434 | if( p->trace ){ |
| 31481 | 31435 | OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n", |
| 31482 | | - tid, p->id, p, p->trace, p->nRef)); |
| 31436 | + GetCurrentThreadId(), p->id, p, p->trace, p->nRef)); |
| 31483 | 31437 | } |
| 31484 | 31438 | #endif |
| 31485 | 31439 | } |
| 31486 | 31440 | |
| 31487 | 31441 | SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ |
| | @@ -36884,19 +36838,24 @@ |
| 36884 | 36838 | z++; |
| 36885 | 36839 | } |
| 36886 | 36840 | return h; |
| 36887 | 36841 | } |
| 36888 | 36842 | |
| 36843 | +#if !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 36844 | + && (defined(__GNUC__) || defined(__clang__)) \ |
| 36845 | + && (defined(__x86_64__) || defined(__aarch64__) || \ |
| 36846 | + (defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen>32))) |
| 36847 | +#define SQLITE_USE_UINT128 |
| 36848 | +#endif |
| 36849 | + |
| 36889 | 36850 | /* |
| 36890 | 36851 | ** Two inputs are multiplied to get a 128-bit result. Write the |
| 36891 | 36852 | ** lower 64-bits of the result into *pLo, and return the high-order |
| 36892 | 36853 | ** 64 bits. |
| 36893 | 36854 | */ |
| 36894 | 36855 | static u64 sqlite3Multiply128(u64 a, u64 b, u64 *pLo){ |
| 36895 | | -#if (defined(__GNUC__) || defined(__clang__)) \ |
| 36896 | | - && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \ |
| 36897 | | - && !defined(SQLITE_DISABLE_INTRINSIC) |
| 36856 | +#if defined(SQLITE_USE_UINT128) |
| 36898 | 36857 | __uint128_t r = (__uint128_t)a * b; |
| 36899 | 36858 | *pLo = (u64)r; |
| 36900 | 36859 | return (u64)(r>>64); |
| 36901 | 36860 | #elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 36902 | 36861 | *pLo = a*b; |
| | @@ -36926,13 +36885,11 @@ |
| 36926 | 36885 | ** into *pLo. Return the upper 64 bits of A*B. |
| 36927 | 36886 | ** |
| 36928 | 36887 | ** The lower 64 bits of A*B are discarded. |
| 36929 | 36888 | */ |
| 36930 | 36889 | static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){ |
| 36931 | | -#if (defined(__GNUC__) || defined(__clang__)) \ |
| 36932 | | - && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \ |
| 36933 | | - && !defined(SQLITE_DISABLE_INTRINSIC) |
| 36890 | +#if defined(SQLITE_USE_UINT128) |
| 36934 | 36891 | __uint128_t r = (__uint128_t)a * b; |
| 36935 | 36892 | r += ((__uint128_t)aLo * b) >> 32; |
| 36936 | 36893 | *pLo = (r>>32)&0xffffffff; |
| 36937 | 36894 | return r>>64; |
| 36938 | 36895 | #elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC) |
| | @@ -36965,10 +36922,12 @@ |
| 36965 | 36922 | r3 += r2>>32; |
| 36966 | 36923 | *pLo = r2&0xffffffff; |
| 36967 | 36924 | return (r4<<32) + r3; |
| 36968 | 36925 | #endif |
| 36969 | 36926 | } |
| 36927 | + |
| 36928 | +#undef SQLITE_USE_UINT128 |
| 36970 | 36929 | |
| 36971 | 36930 | /* |
| 36972 | 36931 | ** Return a u64 with the N-th bit set. |
| 36973 | 36932 | */ |
| 36974 | 36933 | #define U64_BIT(N) (((u64)1)<<(N)) |
| | @@ -48861,90 +48820,11 @@ |
| 48861 | 48820 | |
| 48862 | 48821 | /* |
| 48863 | 48822 | ** Include the header file for the Windows VFS. |
| 48864 | 48823 | */ |
| 48865 | 48824 | /* #include "os_win.h" */ |
| 48866 | | - |
| 48867 | | -/* |
| 48868 | | -** Compiling and using WAL mode requires several APIs that are only |
| 48869 | | -** available in Windows platforms based on the NT kernel. |
| 48870 | | -*/ |
| 48871 | | -#if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL) |
| 48872 | | -# error "WAL mode requires support from the Windows NT kernel, compile\ |
| 48873 | | - with SQLITE_OMIT_WAL." |
| 48874 | | -#endif |
| 48875 | | - |
| 48876 | | -#if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0 |
| 48877 | | -# error "Memory mapped files require support from the Windows NT kernel,\ |
| 48878 | | - compile with SQLITE_MAX_MMAP_SIZE=0." |
| 48879 | | -#endif |
| 48880 | | - |
| 48881 | | -/* |
| 48882 | | -** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions |
| 48883 | | -** based on the sub-platform)? |
| 48884 | | -*/ |
| 48885 | | -#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_ANSI) |
| 48886 | | -# define SQLITE_WIN32_HAS_ANSI |
| 48887 | | -#endif |
| 48888 | | - |
| 48889 | | -/* |
| 48890 | | -** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions |
| 48891 | | -** based on the sub-platform)? |
| 48892 | | -*/ |
| 48893 | | -#if (SQLITE_OS_WINCE || SQLITE_OS_WINNT) && \ |
| 48894 | | - !defined(SQLITE_WIN32_NO_WIDE) |
| 48895 | | -# define SQLITE_WIN32_HAS_WIDE |
| 48896 | | -#endif |
| 48897 | | - |
| 48898 | | -/* |
| 48899 | | -** Make sure at least one set of Win32 APIs is available. |
| 48900 | | -*/ |
| 48901 | | -#if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE) |
| 48902 | | -# error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\ |
| 48903 | | - must be defined." |
| 48904 | | -#endif |
| 48905 | | - |
| 48906 | | -/* |
| 48907 | | -** Define the required Windows SDK version constants if they are not |
| 48908 | | -** already available. |
| 48909 | | -*/ |
| 48910 | | -#ifndef NTDDI_WIN8 |
| 48911 | | -# define NTDDI_WIN8 0x06020000 |
| 48912 | | -#endif |
| 48913 | | - |
| 48914 | | -#ifndef NTDDI_WINBLUE |
| 48915 | | -# define NTDDI_WINBLUE 0x06030000 |
| 48916 | | -#endif |
| 48917 | | - |
| 48918 | | -#ifndef NTDDI_WINTHRESHOLD |
| 48919 | | -# define NTDDI_WINTHRESHOLD 0x06040000 |
| 48920 | | -#endif |
| 48921 | | - |
| 48922 | | -/* |
| 48923 | | -** Check to see if the GetVersionEx[AW] functions are deprecated on the |
| 48924 | | -** target system. GetVersionEx was first deprecated in Win8.1. |
| 48925 | | -*/ |
| 48926 | | -#ifndef SQLITE_WIN32_GETVERSIONEX |
| 48927 | | -# if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINBLUE |
| 48928 | | -# define SQLITE_WIN32_GETVERSIONEX 0 /* GetVersionEx() is deprecated */ |
| 48929 | | -# else |
| 48930 | | -# define SQLITE_WIN32_GETVERSIONEX 1 /* GetVersionEx() is current */ |
| 48931 | | -# endif |
| 48932 | | -#endif |
| 48933 | | - |
| 48934 | | -/* |
| 48935 | | -** Check to see if the CreateFileMappingA function is supported on the |
| 48936 | | -** target system. It is unavailable when using "mincore.lib" on Win10. |
| 48937 | | -** When compiling for Windows 10, always assume "mincore.lib" is in use. |
| 48938 | | -*/ |
| 48939 | | -#ifndef SQLITE_WIN32_CREATEFILEMAPPINGA |
| 48940 | | -# if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINTHRESHOLD |
| 48941 | | -# define SQLITE_WIN32_CREATEFILEMAPPINGA 0 |
| 48942 | | -# else |
| 48943 | | -# define SQLITE_WIN32_CREATEFILEMAPPINGA 1 |
| 48944 | | -# endif |
| 48945 | | -#endif |
| 48825 | +#define SQLITE_WIN32_HAS_WIDE 1 |
| 48946 | 48826 | |
| 48947 | 48827 | /* |
| 48948 | 48828 | ** This constant should already be defined (in the "WinDef.h" SDK file). |
| 48949 | 48829 | */ |
| 48950 | 48830 | #ifndef MAX_PATH |
| | @@ -49021,39 +48901,11 @@ |
| 49021 | 48901 | #ifndef winGetDirSep |
| 49022 | 48902 | # define winGetDirSep() '\\' |
| 49023 | 48903 | #endif |
| 49024 | 48904 | |
| 49025 | 48905 | /* |
| 49026 | | -** Do we need to manually define the Win32 file mapping APIs for use with WAL |
| 49027 | | -** mode or memory mapped files (e.g. these APIs are available in the Windows |
| 49028 | | -** CE SDK; however, they are not present in the header file)? |
| 49029 | | -*/ |
| 49030 | | -#if SQLITE_WIN32_FILEMAPPING_API && \ |
| 49031 | | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 49032 | | - |
| 49033 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 49034 | | -WINBASEAPI HANDLE WINAPI CreateFileMappingA(HANDLE, LPSECURITY_ATTRIBUTES, \ |
| 49035 | | - DWORD, DWORD, DWORD, LPCSTR); |
| 49036 | | -#endif /* defined(SQLITE_WIN32_HAS_ANSI) */ |
| 49037 | | - |
| 49038 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49039 | | -WINBASEAPI HANDLE WINAPI CreateFileMappingW(HANDLE, LPSECURITY_ATTRIBUTES, \ |
| 49040 | | - DWORD, DWORD, DWORD, LPCWSTR); |
| 49041 | | -#endif /* defined(SQLITE_WIN32_HAS_WIDE) */ |
| 49042 | | - |
| 49043 | | -WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T); |
| 49044 | | - |
| 49045 | | -/* |
| 49046 | | -** These file mapping APIs are common to both Win32 and WinRT. |
| 49047 | | -*/ |
| 49048 | | - |
| 49049 | | -WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T); |
| 49050 | | -WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); |
| 49051 | | -#endif /* SQLITE_WIN32_FILEMAPPING_API */ |
| 49052 | | - |
| 49053 | | -/* |
| 49054 | | -** Some Microsoft compilers lack this definition. |
| 48906 | +** Some older Microsoft compilers lack the following definition. |
| 49055 | 48907 | */ |
| 49056 | 48908 | #ifndef INVALID_FILE_ATTRIBUTES |
| 49057 | 48909 | # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) |
| 49058 | 48910 | #endif |
| 49059 | 48911 | |
| | @@ -49069,23 +48921,10 @@ |
| 49069 | 48921 | /* Forward references to structures used for WAL */ |
| 49070 | 48922 | typedef struct winShm winShm; /* A connection to shared-memory */ |
| 49071 | 48923 | typedef struct winShmNode winShmNode; /* A region of shared-memory */ |
| 49072 | 48924 | #endif |
| 49073 | 48925 | |
| 49074 | | -/* |
| 49075 | | -** WinCE lacks native support for file locking so we have to fake it |
| 49076 | | -** with some code of our own. |
| 49077 | | -*/ |
| 49078 | | -#if SQLITE_OS_WINCE |
| 49079 | | -typedef struct winceLock { |
| 49080 | | - int nReaders; /* Number of reader locks obtained */ |
| 49081 | | - BOOL bPending; /* Indicates a pending lock has been obtained */ |
| 49082 | | - BOOL bReserved; /* Indicates a reserved lock has been obtained */ |
| 49083 | | - BOOL bExclusive; /* Indicates an exclusive lock has been obtained */ |
| 49084 | | -} winceLock; |
| 49085 | | -#endif |
| 49086 | | - |
| 49087 | 48926 | /* |
| 49088 | 48927 | ** The winFile structure is a subclass of sqlite3_file* specific to the win32 |
| 49089 | 48928 | ** portability layer. |
| 49090 | 48929 | */ |
| 49091 | 48930 | typedef struct winFile winFile; |
| | @@ -49100,17 +48939,10 @@ |
| 49100 | 48939 | #ifndef SQLITE_OMIT_WAL |
| 49101 | 48940 | winShm *pShm; /* Instance of shared memory on this file */ |
| 49102 | 48941 | #endif |
| 49103 | 48942 | const char *zPath; /* Full pathname of this file */ |
| 49104 | 48943 | int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */ |
| 49105 | | -#if SQLITE_OS_WINCE |
| 49106 | | - LPWSTR zDeleteOnClose; /* Name of file to delete when closing */ |
| 49107 | | - HANDLE hMutex; /* Mutex used to control access to shared lock */ |
| 49108 | | - HANDLE hShared; /* Shared memory segment used for locking */ |
| 49109 | | - winceLock local; /* Locks obtained by this instance of winFile */ |
| 49110 | | - winceLock *shared; /* Global shared lock memory for the file */ |
| 49111 | | -#endif |
| 49112 | 48944 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 49113 | 48945 | int nFetchOut; /* Number of outstanding xFetch references */ |
| 49114 | 48946 | HANDLE hMap; /* Handle for accessing memory mapping */ |
| 49115 | 48947 | void *pMapRegion; /* Area memory mapped */ |
| 49116 | 48948 | sqlite3_int64 mmapSize; /* Size of mapped region */ |
| | @@ -49316,27 +49148,19 @@ |
| 49316 | 49148 | ** |
| 49317 | 49149 | ** In order to facilitate testing on a WinNT system, the test fixture |
| 49318 | 49150 | ** can manually set this value to 1 to emulate Win98 behavior. |
| 49319 | 49151 | */ |
| 49320 | 49152 | #ifdef SQLITE_TEST |
| 49321 | | -SQLITE_API LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0; |
| 49153 | +SQLITE_API LONG volatile sqlite3_os_type = 0; |
| 49322 | 49154 | #else |
| 49323 | | -static LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0; |
| 49155 | +static LONG volatile sqlite3_os_type = 0; |
| 49324 | 49156 | #endif |
| 49325 | 49157 | |
| 49326 | 49158 | #ifndef SYSCALL |
| 49327 | 49159 | # define SYSCALL sqlite3_syscall_ptr |
| 49328 | 49160 | #endif |
| 49329 | 49161 | |
| 49330 | | -/* |
| 49331 | | -** This function is not available on Windows CE or WinRT. |
| 49332 | | - */ |
| 49333 | | - |
| 49334 | | -#if SQLITE_OS_WINCE |
| 49335 | | -# define osAreFileApisANSI() 1 |
| 49336 | | -#endif |
| 49337 | | - |
| 49338 | 49162 | /* |
| 49339 | 49163 | ** Many system calls are accessed through pointer-to-functions so that |
| 49340 | 49164 | ** they may be overridden at runtime to facilitate fault injection during |
| 49341 | 49165 | ** testing and sandboxing. The following array holds the names and pointers |
| 49342 | 49166 | ** to all overrideable system calls. |
| | @@ -49344,642 +49168,290 @@ |
| 49344 | 49168 | static struct win_syscall { |
| 49345 | 49169 | const char *zName; /* Name of the system call */ |
| 49346 | 49170 | sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ |
| 49347 | 49171 | sqlite3_syscall_ptr pDefault; /* Default value */ |
| 49348 | 49172 | } aSyscall[] = { |
| 49349 | | -#if !SQLITE_OS_WINCE |
| 49350 | 49173 | { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 }, |
| 49351 | | -#else |
| 49352 | | - { "AreFileApisANSI", (SYSCALL)0, 0 }, |
| 49353 | | -#endif |
| 49354 | | - |
| 49355 | | -#ifndef osAreFileApisANSI |
| 49356 | 49174 | #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent) |
| 49357 | | -#endif |
| 49358 | | - |
| 49359 | | -#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) |
| 49360 | | - { "CharLowerW", (SYSCALL)CharLowerW, 0 }, |
| 49361 | | -#else |
| 49362 | | - { "CharLowerW", (SYSCALL)0, 0 }, |
| 49363 | | -#endif |
| 49364 | | - |
| 49365 | | -#define osCharLowerW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[1].pCurrent) |
| 49366 | | - |
| 49367 | | -#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) |
| 49368 | | - { "CharUpperW", (SYSCALL)CharUpperW, 0 }, |
| 49369 | | -#else |
| 49370 | | - { "CharUpperW", (SYSCALL)0, 0 }, |
| 49371 | | -#endif |
| 49372 | | - |
| 49373 | | -#define osCharUpperW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[2].pCurrent) |
| 49374 | 49175 | |
| 49375 | 49176 | { "CloseHandle", (SYSCALL)CloseHandle, 0 }, |
| 49376 | | - |
| 49377 | | -#define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[3].pCurrent) |
| 49378 | | - |
| 49379 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 49380 | | - { "CreateFileA", (SYSCALL)CreateFileA, 0 }, |
| 49381 | | -#else |
| 49382 | | - { "CreateFileA", (SYSCALL)0, 0 }, |
| 49383 | | -#endif |
| 49384 | | - |
| 49385 | | -#define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \ |
| 49386 | | - LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent) |
| 49387 | | - |
| 49388 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49389 | | - { "CreateFileW", (SYSCALL)CreateFileW, 0 }, |
| 49390 | | -#else |
| 49391 | | - { "CreateFileW", (SYSCALL)0, 0 }, |
| 49392 | | -#endif |
| 49393 | | - |
| 49177 | +#define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[1].pCurrent) |
| 49178 | + |
| 49179 | + |
| 49180 | + { "CreateFileW", (SYSCALL)CreateFileW, 0 }, |
| 49394 | 49181 | #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
| 49395 | | - LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) |
| 49396 | | - |
| 49397 | | -#if defined(SQLITE_WIN32_HAS_ANSI) && \ |
| 49398 | | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \ |
| 49399 | | - SQLITE_WIN32_CREATEFILEMAPPINGA |
| 49400 | | - { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, |
| 49401 | | -#else |
| 49402 | | - { "CreateFileMappingA", (SYSCALL)0, 0 }, |
| 49403 | | -#endif |
| 49404 | | - |
| 49405 | | -#define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 49406 | | - DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) |
| 49407 | | - |
| 49408 | | -#if (SQLITE_OS_WINCE || defined(SQLITE_WIN32_HAS_WIDE)) && \ |
| 49409 | | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 49410 | | - { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 49411 | | -#else |
| 49412 | | - { "CreateFileMappingW", (SYSCALL)0, 0 }, |
| 49413 | | -#endif |
| 49414 | | - |
| 49182 | + LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent) |
| 49183 | + |
| 49184 | + { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 49415 | 49185 | #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 49416 | | - DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent) |
| 49417 | | - |
| 49418 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49419 | | - { "CreateMutexW", (SYSCALL)CreateMutexW, 0 }, |
| 49420 | | -#else |
| 49421 | | - { "CreateMutexW", (SYSCALL)0, 0 }, |
| 49422 | | -#endif |
| 49423 | | - |
| 49424 | | -#define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \ |
| 49425 | | - LPCWSTR))aSyscall[8].pCurrent) |
| 49426 | | - |
| 49427 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 49428 | | - { "DeleteFileA", (SYSCALL)DeleteFileA, 0 }, |
| 49429 | | -#else |
| 49430 | | - { "DeleteFileA", (SYSCALL)0, 0 }, |
| 49431 | | -#endif |
| 49432 | | - |
| 49433 | | -#define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent) |
| 49434 | | - |
| 49435 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49186 | + DWORD,DWORD,DWORD,LPCWSTR))aSyscall[3].pCurrent) |
| 49187 | + |
| 49436 | 49188 | { "DeleteFileW", (SYSCALL)DeleteFileW, 0 }, |
| 49437 | | -#else |
| 49438 | | - { "DeleteFileW", (SYSCALL)0, 0 }, |
| 49439 | | -#endif |
| 49440 | | - |
| 49441 | | -#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent) |
| 49442 | | - |
| 49443 | | -#if SQLITE_OS_WINCE |
| 49444 | | - { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 }, |
| 49445 | | -#else |
| 49446 | | - { "FileTimeToLocalFileTime", (SYSCALL)0, 0 }, |
| 49447 | | -#endif |
| 49448 | | - |
| 49449 | | -#define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(const FILETIME*, \ |
| 49450 | | - LPFILETIME))aSyscall[11].pCurrent) |
| 49451 | | - |
| 49452 | | -#if SQLITE_OS_WINCE |
| 49453 | | - { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 }, |
| 49454 | | -#else |
| 49455 | | - { "FileTimeToSystemTime", (SYSCALL)0, 0 }, |
| 49456 | | -#endif |
| 49457 | | - |
| 49458 | | -#define osFileTimeToSystemTime ((BOOL(WINAPI*)(const FILETIME*, \ |
| 49459 | | - LPSYSTEMTIME))aSyscall[12].pCurrent) |
| 49189 | +#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[4].pCurrent) |
| 49460 | 49190 | |
| 49461 | 49191 | { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 }, |
| 49462 | | - |
| 49463 | | -#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent) |
| 49464 | | - |
| 49465 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 49466 | | - { "FormatMessageA", (SYSCALL)FormatMessageA, 0 }, |
| 49467 | | -#else |
| 49468 | | - { "FormatMessageA", (SYSCALL)0, 0 }, |
| 49469 | | -#endif |
| 49470 | | - |
| 49471 | | -#define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \ |
| 49472 | | - DWORD,va_list*))aSyscall[14].pCurrent) |
| 49473 | | - |
| 49474 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49192 | +#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[5].pCurrent) |
| 49193 | + |
| 49475 | 49194 | { "FormatMessageW", (SYSCALL)FormatMessageW, 0 }, |
| 49476 | | -#else |
| 49477 | | - { "FormatMessageW", (SYSCALL)0, 0 }, |
| 49478 | | -#endif |
| 49479 | | - |
| 49480 | 49195 | #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \ |
| 49481 | | - DWORD,va_list*))aSyscall[15].pCurrent) |
| 49196 | + DWORD,va_list*))aSyscall[6].pCurrent) |
| 49482 | 49197 | |
| 49483 | 49198 | #if !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 49484 | 49199 | { "FreeLibrary", (SYSCALL)FreeLibrary, 0 }, |
| 49485 | 49200 | #else |
| 49486 | 49201 | { "FreeLibrary", (SYSCALL)0, 0 }, |
| 49487 | 49202 | #endif |
| 49488 | 49203 | |
| 49489 | | -#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent) |
| 49204 | +#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[7].pCurrent) |
| 49490 | 49205 | |
| 49491 | 49206 | { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 }, |
| 49492 | | - |
| 49493 | | -#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent) |
| 49494 | | - |
| 49495 | | -#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI) |
| 49496 | | - { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 }, |
| 49497 | | -#else |
| 49498 | | - { "GetDiskFreeSpaceA", (SYSCALL)0, 0 }, |
| 49499 | | -#endif |
| 49500 | | - |
| 49501 | | -#define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \ |
| 49502 | | - LPDWORD))aSyscall[18].pCurrent) |
| 49503 | | - |
| 49504 | | -#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) |
| 49505 | | - { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 }, |
| 49506 | | -#else |
| 49507 | | - { "GetDiskFreeSpaceW", (SYSCALL)0, 0 }, |
| 49508 | | -#endif |
| 49509 | | - |
| 49510 | | -#define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \ |
| 49511 | | - LPDWORD))aSyscall[19].pCurrent) |
| 49512 | | - |
| 49513 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 49514 | | - { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 }, |
| 49515 | | -#else |
| 49516 | | - { "GetFileAttributesA", (SYSCALL)0, 0 }, |
| 49517 | | -#endif |
| 49518 | | - |
| 49519 | | -#define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent) |
| 49520 | | - |
| 49521 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49207 | +#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[8].pCurrent) |
| 49208 | + |
| 49522 | 49209 | { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 }, |
| 49523 | | -#else |
| 49524 | | - { "GetFileAttributesW", (SYSCALL)0, 0 }, |
| 49525 | | -#endif |
| 49210 | +#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent) |
| 49526 | 49211 | |
| 49527 | | -#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent) |
| 49528 | | - |
| 49529 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49530 | 49212 | { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 }, |
| 49531 | | -#else |
| 49532 | | - { "GetFileAttributesExW", (SYSCALL)0, 0 }, |
| 49533 | | -#endif |
| 49534 | | - |
| 49535 | 49213 | #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \ |
| 49536 | | - LPVOID))aSyscall[22].pCurrent) |
| 49214 | + LPVOID))aSyscall[10].pCurrent) |
| 49537 | 49215 | |
| 49538 | 49216 | { "GetFileSize", (SYSCALL)GetFileSize, 0 }, |
| 49539 | | - |
| 49540 | | -#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent) |
| 49541 | | - |
| 49542 | | -#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI) |
| 49543 | | - { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 }, |
| 49544 | | -#else |
| 49545 | | - { "GetFullPathNameA", (SYSCALL)0, 0 }, |
| 49546 | | -#endif |
| 49547 | | - |
| 49548 | | -#define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \ |
| 49549 | | - LPSTR*))aSyscall[24].pCurrent) |
| 49550 | | - |
| 49551 | | -#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE) |
| 49217 | +#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[11].pCurrent) |
| 49218 | + |
| 49552 | 49219 | { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 }, |
| 49553 | | -#else |
| 49554 | | - { "GetFullPathNameW", (SYSCALL)0, 0 }, |
| 49555 | | -#endif |
| 49556 | | - |
| 49557 | 49220 | #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \ |
| 49558 | | - LPWSTR*))aSyscall[25].pCurrent) |
| 49559 | | - |
| 49560 | | -/* |
| 49561 | | -** For GetLastError(), MSDN says: |
| 49562 | | -** |
| 49563 | | -** Minimum supported client: Windows XP [desktop apps | UWP apps] |
| 49564 | | -** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps] |
| 49565 | | -*/ |
| 49221 | + LPWSTR*))aSyscall[12].pCurrent) |
| 49222 | + |
| 49566 | 49223 | { "GetLastError", (SYSCALL)GetLastError, 0 }, |
| 49567 | | - |
| 49568 | | -#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent) |
| 49224 | +#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[13].pCurrent) |
| 49569 | 49225 | |
| 49570 | 49226 | #if !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 49571 | | -#if SQLITE_OS_WINCE |
| 49572 | | - /* The GetProcAddressA() routine is only available on Windows CE. */ |
| 49573 | | - { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 }, |
| 49574 | | -#else |
| 49575 | | - /* All other Windows platforms expect GetProcAddress() to take |
| 49576 | | - ** an ANSI string regardless of the _UNICODE setting */ |
| 49577 | 49227 | { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 }, |
| 49578 | | -#endif |
| 49579 | 49228 | #else |
| 49580 | 49229 | { "GetProcAddressA", (SYSCALL)0, 0 }, |
| 49581 | 49230 | #endif |
| 49582 | | - |
| 49583 | 49231 | #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \ |
| 49584 | | - LPCSTR))aSyscall[27].pCurrent) |
| 49232 | + LPCSTR))aSyscall[14].pCurrent) |
| 49585 | 49233 | |
| 49586 | 49234 | { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 }, |
| 49587 | | -#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent) |
| 49235 | +#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[15].pCurrent) |
| 49588 | 49236 | |
| 49589 | 49237 | { "GetSystemTime", (SYSCALL)GetSystemTime, 0 }, |
| 49590 | | -#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent) |
| 49591 | | - |
| 49592 | | -#if !SQLITE_OS_WINCE |
| 49593 | | - { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 }, |
| 49594 | | -#else |
| 49595 | | - { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 }, |
| 49596 | | -#endif |
| 49597 | | - |
| 49238 | +#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[16].pCurrent) |
| 49239 | + |
| 49240 | + { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 }, |
| 49598 | 49241 | #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \ |
| 49599 | | - LPFILETIME))aSyscall[30].pCurrent) |
| 49600 | | - |
| 49601 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 49602 | | - { "GetTempPathA", (SYSCALL)GetTempPathA, 0 }, |
| 49603 | | -#else |
| 49604 | | - { "GetTempPathA", (SYSCALL)0, 0 }, |
| 49605 | | -#endif |
| 49606 | | - |
| 49607 | | -#define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent) |
| 49608 | | - |
| 49609 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49242 | + LPFILETIME))aSyscall[17].pCurrent) |
| 49243 | + |
| 49610 | 49244 | { "GetTempPathW", (SYSCALL)GetTempPathW, 0 }, |
| 49611 | | -#else |
| 49612 | | - { "GetTempPathW", (SYSCALL)0, 0 }, |
| 49613 | | -#endif |
| 49614 | | - |
| 49615 | | -#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent) |
| 49245 | +#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent) |
| 49616 | 49246 | |
| 49617 | 49247 | { "GetTickCount", (SYSCALL)GetTickCount, 0 }, |
| 49618 | | - |
| 49619 | | -#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent) |
| 49620 | | - |
| 49621 | | -#if defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_GETVERSIONEX |
| 49622 | | - { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, |
| 49623 | | -#else |
| 49624 | | - { "GetVersionExA", (SYSCALL)0, 0 }, |
| 49625 | | -#endif |
| 49626 | | - |
| 49627 | | -#define osGetVersionExA ((BOOL(WINAPI*)( \ |
| 49628 | | - LPOSVERSIONINFOA))aSyscall[34].pCurrent) |
| 49629 | | - |
| 49630 | | -#if defined(SQLITE_WIN32_HAS_WIDE) && \ |
| 49631 | | - SQLITE_WIN32_GETVERSIONEX |
| 49632 | | - { "GetVersionExW", (SYSCALL)GetVersionExW, 0 }, |
| 49633 | | -#else |
| 49634 | | - { "GetVersionExW", (SYSCALL)0, 0 }, |
| 49635 | | -#endif |
| 49636 | | - |
| 49637 | | -#define osGetVersionExW ((BOOL(WINAPI*)( \ |
| 49638 | | - LPOSVERSIONINFOW))aSyscall[35].pCurrent) |
| 49248 | +#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[19].pCurrent) |
| 49639 | 49249 | |
| 49640 | 49250 | { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, |
| 49641 | | - |
| 49642 | 49251 | #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \ |
| 49643 | | - SIZE_T))aSyscall[36].pCurrent) |
| 49252 | + SIZE_T))aSyscall[20].pCurrent) |
| 49644 | 49253 | |
| 49645 | 49254 | { "HeapCreate", (SYSCALL)HeapCreate, 0 }, |
| 49646 | | - |
| 49647 | 49255 | #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \ |
| 49648 | | - SIZE_T))aSyscall[37].pCurrent) |
| 49256 | + SIZE_T))aSyscall[21].pCurrent) |
| 49649 | 49257 | |
| 49650 | 49258 | { "HeapDestroy", (SYSCALL)HeapDestroy, 0 }, |
| 49651 | | - |
| 49652 | | -#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[38].pCurrent) |
| 49259 | +#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent) |
| 49653 | 49260 | |
| 49654 | 49261 | { "HeapFree", (SYSCALL)HeapFree, 0 }, |
| 49655 | | - |
| 49656 | | -#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[39].pCurrent) |
| 49262 | +#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent) |
| 49657 | 49263 | |
| 49658 | 49264 | { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 }, |
| 49659 | | - |
| 49660 | 49265 | #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \ |
| 49661 | | - SIZE_T))aSyscall[40].pCurrent) |
| 49266 | + SIZE_T))aSyscall[24].pCurrent) |
| 49662 | 49267 | |
| 49663 | 49268 | { "HeapSize", (SYSCALL)HeapSize, 0 }, |
| 49664 | | - |
| 49665 | 49269 | #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \ |
| 49666 | | - LPCVOID))aSyscall[41].pCurrent) |
| 49270 | + LPCVOID))aSyscall[25].pCurrent) |
| 49667 | 49271 | |
| 49668 | 49272 | { "HeapValidate", (SYSCALL)HeapValidate, 0 }, |
| 49669 | | - |
| 49670 | 49273 | #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \ |
| 49671 | | - LPCVOID))aSyscall[42].pCurrent) |
| 49274 | + LPCVOID))aSyscall[26].pCurrent) |
| 49672 | 49275 | |
| 49673 | | -#if !SQLITE_OS_WINCE |
| 49674 | 49276 | { "HeapCompact", (SYSCALL)HeapCompact, 0 }, |
| 49675 | | -#else |
| 49676 | | - { "HeapCompact", (SYSCALL)0, 0 }, |
| 49677 | | -#endif |
| 49678 | | - |
| 49679 | | -#define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[43].pCurrent) |
| 49680 | | - |
| 49681 | | -#if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 49682 | | - { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 }, |
| 49683 | | -#else |
| 49684 | | - { "LoadLibraryA", (SYSCALL)0, 0 }, |
| 49685 | | -#endif |
| 49686 | | - |
| 49687 | | -#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[44].pCurrent) |
| 49688 | | - |
| 49689 | | -#if defined(SQLITE_WIN32_HAS_WIDE) && \ |
| 49690 | | - !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 49277 | +#define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent) |
| 49278 | + |
| 49279 | + |
| 49280 | +#if !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 49691 | 49281 | { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 }, |
| 49692 | 49282 | #else |
| 49693 | 49283 | { "LoadLibraryW", (SYSCALL)0, 0 }, |
| 49694 | 49284 | #endif |
| 49695 | | - |
| 49696 | | -#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[45].pCurrent) |
| 49285 | +#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent) |
| 49697 | 49286 | |
| 49698 | 49287 | { "LocalFree", (SYSCALL)LocalFree, 0 }, |
| 49699 | | - |
| 49700 | | -#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[46].pCurrent) |
| 49701 | | - |
| 49702 | | -#if !SQLITE_OS_WINCE |
| 49703 | | - { "LockFile", (SYSCALL)LockFile, 0 }, |
| 49704 | | -#else |
| 49705 | | - { "LockFile", (SYSCALL)0, 0 }, |
| 49706 | | -#endif |
| 49707 | | - |
| 49708 | | -#if !defined(osLockFile) && defined(SQLITE_WIN32_HAS_ANSI) |
| 49709 | | -#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49710 | | - DWORD))aSyscall[47].pCurrent) |
| 49711 | | -#endif |
| 49712 | | - |
| 49713 | | -#if !SQLITE_OS_WINCE |
| 49288 | +#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[29].pCurrent) |
| 49289 | + |
| 49714 | 49290 | { "LockFileEx", (SYSCALL)LockFileEx, 0 }, |
| 49715 | | -#else |
| 49716 | | - { "LockFileEx", (SYSCALL)0, 0 }, |
| 49717 | | -#endif |
| 49718 | | - |
| 49719 | | -#ifndef osLockFileEx |
| 49720 | 49291 | #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
| 49721 | | - LPOVERLAPPED))aSyscall[48].pCurrent) |
| 49722 | | -#endif |
| 49292 | + LPOVERLAPPED))aSyscall[30].pCurrent) |
| 49723 | 49293 | |
| 49724 | | -#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 49294 | +#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 49725 | 49295 | { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
| 49726 | 49296 | #else |
| 49727 | 49297 | { "MapViewOfFile", (SYSCALL)0, 0 }, |
| 49728 | 49298 | #endif |
| 49729 | | - |
| 49730 | 49299 | #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49731 | | - SIZE_T))aSyscall[49].pCurrent) |
| 49300 | + SIZE_T))aSyscall[31].pCurrent) |
| 49732 | 49301 | |
| 49733 | 49302 | { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, |
| 49734 | | - |
| 49735 | 49303 | #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \ |
| 49736 | | - int))aSyscall[50].pCurrent) |
| 49304 | + int))aSyscall[32].pCurrent) |
| 49737 | 49305 | |
| 49738 | 49306 | { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 }, |
| 49739 | | - |
| 49740 | 49307 | #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \ |
| 49741 | | - LARGE_INTEGER*))aSyscall[51].pCurrent) |
| 49308 | + LARGE_INTEGER*))aSyscall[33].pCurrent) |
| 49742 | 49309 | |
| 49743 | 49310 | { "ReadFile", (SYSCALL)ReadFile, 0 }, |
| 49744 | | - |
| 49745 | 49311 | #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \ |
| 49746 | | - LPOVERLAPPED))aSyscall[52].pCurrent) |
| 49312 | + LPOVERLAPPED))aSyscall[34].pCurrent) |
| 49747 | 49313 | |
| 49748 | 49314 | { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 }, |
| 49749 | | - |
| 49750 | | -#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[53].pCurrent) |
| 49315 | +#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[35].pCurrent) |
| 49751 | 49316 | |
| 49752 | 49317 | { "SetFilePointer", (SYSCALL)SetFilePointer, 0 }, |
| 49753 | | - |
| 49754 | 49318 | #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \ |
| 49755 | | - DWORD))aSyscall[54].pCurrent) |
| 49319 | + DWORD))aSyscall[36].pCurrent) |
| 49756 | 49320 | |
| 49757 | 49321 | { "Sleep", (SYSCALL)Sleep, 0 }, |
| 49758 | | - |
| 49759 | | -#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[55].pCurrent) |
| 49760 | | - |
| 49761 | | - { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 }, |
| 49762 | | - |
| 49763 | | -#define osSystemTimeToFileTime ((BOOL(WINAPI*)(const SYSTEMTIME*, \ |
| 49764 | | - LPFILETIME))aSyscall[56].pCurrent) |
| 49765 | | - |
| 49766 | | -#if !SQLITE_OS_WINCE |
| 49767 | | - { "UnlockFile", (SYSCALL)UnlockFile, 0 }, |
| 49768 | | -#else |
| 49769 | | - { "UnlockFile", (SYSCALL)0, 0 }, |
| 49770 | | -#endif |
| 49771 | | - |
| 49772 | | -#if !defined(osUnlockFile) && defined(SQLITE_WIN32_HAS_ANSI) |
| 49773 | | -#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49774 | | - DWORD))aSyscall[57].pCurrent) |
| 49775 | | -#endif |
| 49776 | | - |
| 49777 | | -#if !SQLITE_OS_WINCE |
| 49322 | +#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[37].pCurrent) |
| 49323 | + |
| 49778 | 49324 | { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, |
| 49779 | | -#else |
| 49780 | | - { "UnlockFileEx", (SYSCALL)0, 0 }, |
| 49781 | | -#endif |
| 49782 | | - |
| 49783 | 49325 | #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49784 | | - LPOVERLAPPED))aSyscall[58].pCurrent) |
| 49326 | + LPOVERLAPPED))aSyscall[38].pCurrent) |
| 49785 | 49327 | |
| 49786 | | -#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 49328 | +#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 49787 | 49329 | { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
| 49788 | 49330 | #else |
| 49789 | 49331 | { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
| 49790 | 49332 | #endif |
| 49791 | | - |
| 49792 | | -#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[59].pCurrent) |
| 49333 | +#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[39].pCurrent) |
| 49793 | 49334 | |
| 49794 | 49335 | { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, |
| 49795 | | - |
| 49796 | 49336 | #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ |
| 49797 | | - LPCSTR,LPBOOL))aSyscall[60].pCurrent) |
| 49337 | + LPCSTR,LPBOOL))aSyscall[40].pCurrent) |
| 49798 | 49338 | |
| 49799 | 49339 | { "WriteFile", (SYSCALL)WriteFile, 0 }, |
| 49800 | | - |
| 49801 | 49340 | #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \ |
| 49802 | | - LPOVERLAPPED))aSyscall[61].pCurrent) |
| 49803 | | - |
| 49804 | | -/* |
| 49805 | | -** For WaitForSingleObject(), MSDN says: |
| 49806 | | -** |
| 49807 | | -** Minimum supported client: Windows XP [desktop apps | UWP apps] |
| 49808 | | -** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps] |
| 49809 | | -*/ |
| 49341 | + LPOVERLAPPED))aSyscall[41].pCurrent) |
| 49342 | + |
| 49810 | 49343 | { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 }, |
| 49811 | | - |
| 49812 | 49344 | #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \ |
| 49813 | | - DWORD))aSyscall[62].pCurrent) |
| 49814 | | - |
| 49815 | | -#if !SQLITE_OS_WINCE |
| 49816 | | - { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 }, |
| 49817 | | -#else |
| 49818 | | - { "WaitForSingleObjectEx", (SYSCALL)0, 0 }, |
| 49819 | | -#endif |
| 49820 | | - |
| 49345 | + DWORD))aSyscall[42].pCurrent) |
| 49346 | + |
| 49347 | + { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 }, |
| 49821 | 49348 | #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \ |
| 49822 | | - BOOL))aSyscall[63].pCurrent) |
| 49823 | | - |
| 49824 | | - { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 }, |
| 49825 | | - |
| 49826 | | -#define osGetNativeSystemInfo ((VOID(WINAPI*)( \ |
| 49827 | | - LPSYSTEM_INFO))aSyscall[64].pCurrent) |
| 49828 | | - |
| 49829 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 49349 | + BOOL))aSyscall[43].pCurrent) |
| 49350 | + |
| 49830 | 49351 | { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 }, |
| 49831 | | -#else |
| 49832 | | - { "OutputDebugStringA", (SYSCALL)0, 0 }, |
| 49833 | | -#endif |
| 49834 | | - |
| 49835 | | -#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[65].pCurrent) |
| 49836 | | - |
| 49837 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 49838 | | - { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 }, |
| 49839 | | -#else |
| 49840 | | - { "OutputDebugStringW", (SYSCALL)0, 0 }, |
| 49841 | | -#endif |
| 49842 | | - |
| 49843 | | -#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[66].pCurrent) |
| 49352 | +#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[44].pCurrent) |
| 49844 | 49353 | |
| 49845 | 49354 | { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
| 49846 | | - |
| 49847 | | -#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[67].pCurrent) |
| 49355 | +#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[45].pCurrent) |
| 49848 | 49356 | |
| 49849 | 49357 | /* |
| 49850 | 49358 | ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function" |
| 49851 | 49359 | ** is really just a macro that uses a compiler intrinsic (e.g. x64). |
| 49852 | 49360 | ** So do not try to make this is into a redefinable interface. |
| 49853 | 49361 | */ |
| 49854 | 49362 | #if defined(InterlockedCompareExchange) |
| 49855 | 49363 | { "InterlockedCompareExchange", (SYSCALL)0, 0 }, |
| 49856 | | - |
| 49857 | 49364 | #define osInterlockedCompareExchange InterlockedCompareExchange |
| 49858 | 49365 | #else |
| 49859 | 49366 | { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 }, |
| 49860 | | - |
| 49861 | | -#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \ |
| 49862 | | - SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[68].pCurrent) |
| 49367 | +#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\ |
| 49368 | + LONG,LONG))aSyscall[46].pCurrent) |
| 49863 | 49369 | #endif /* defined(InterlockedCompareExchange) */ |
| 49864 | 49370 | |
| 49865 | | -#if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID |
| 49371 | +#if SQLITE_WIN32_USE_UUID |
| 49866 | 49372 | { "UuidCreate", (SYSCALL)UuidCreate, 0 }, |
| 49867 | 49373 | #else |
| 49868 | 49374 | { "UuidCreate", (SYSCALL)0, 0 }, |
| 49869 | 49375 | #endif |
| 49376 | +#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[47].pCurrent) |
| 49870 | 49377 | |
| 49871 | | -#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[69].pCurrent) |
| 49872 | | - |
| 49873 | | -#if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID |
| 49378 | +#if SQLITE_WIN32_USE_UUID |
| 49874 | 49379 | { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 }, |
| 49875 | 49380 | #else |
| 49876 | 49381 | { "UuidCreateSequential", (SYSCALL)0, 0 }, |
| 49877 | 49382 | #endif |
| 49878 | | - |
| 49879 | 49383 | #define osUuidCreateSequential \ |
| 49880 | | - ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[70].pCurrent) |
| 49384 | + ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent) |
| 49881 | 49385 | |
| 49882 | 49386 | #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0 |
| 49883 | 49387 | { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 }, |
| 49884 | 49388 | #else |
| 49885 | 49389 | { "FlushViewOfFile", (SYSCALL)0, 0 }, |
| 49886 | 49390 | #endif |
| 49887 | | - |
| 49888 | 49391 | #define osFlushViewOfFile \ |
| 49889 | | - ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[71].pCurrent) |
| 49890 | | - |
| 49891 | | -/* |
| 49892 | | -** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CreateEvent() |
| 49893 | | -** to implement blocking locks with timeouts. MSDN says: |
| 49894 | | -** |
| 49895 | | -** Minimum supported client: Windows XP [desktop apps | UWP apps] |
| 49896 | | -** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps] |
| 49897 | | -*/ |
| 49392 | + ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[49].pCurrent) |
| 49393 | + |
| 49898 | 49394 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 49899 | 49395 | { "CreateEvent", (SYSCALL)CreateEvent, 0 }, |
| 49900 | 49396 | #else |
| 49901 | 49397 | { "CreateEvent", (SYSCALL)0, 0 }, |
| 49902 | 49398 | #endif |
| 49903 | | - |
| 49904 | 49399 | #define osCreateEvent ( \ |
| 49905 | 49400 | (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \ |
| 49906 | | - aSyscall[72].pCurrent \ |
| 49401 | + aSyscall[50].pCurrent \ |
| 49907 | 49402 | ) |
| 49908 | 49403 | |
| 49909 | | -/* |
| 49910 | | -** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CancelIo() |
| 49911 | | -** for the case where a timeout expires and a lock request must be |
| 49912 | | -** cancelled. |
| 49913 | | -** |
| 49914 | | -** Minimum supported client: Windows XP [desktop apps | UWP apps] |
| 49915 | | -** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps] |
| 49916 | | -*/ |
| 49917 | 49404 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 49918 | 49405 | { "CancelIo", (SYSCALL)CancelIo, 0 }, |
| 49919 | 49406 | #else |
| 49920 | 49407 | { "CancelIo", (SYSCALL)0, 0 }, |
| 49921 | 49408 | #endif |
| 49922 | | - |
| 49923 | | -#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[73].pCurrent) |
| 49924 | | - |
| 49925 | | -#if defined(SQLITE_WIN32_HAS_WIDE) && defined(_WIN32) |
| 49926 | | - { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 }, |
| 49927 | | -#else |
| 49928 | | - { "GetModuleHandleW", (SYSCALL)0, 0 }, |
| 49929 | | -#endif |
| 49930 | | - |
| 49931 | | -#define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[74].pCurrent) |
| 49409 | +#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent) |
| 49932 | 49410 | |
| 49933 | 49411 | #ifndef _WIN32 |
| 49934 | 49412 | { "getenv", (SYSCALL)getenv, 0 }, |
| 49935 | 49413 | #else |
| 49936 | 49414 | { "getenv", (SYSCALL)0, 0 }, |
| 49937 | 49415 | #endif |
| 49938 | | - |
| 49939 | | -#define osGetenv ((const char *(*)(const char *))aSyscall[75].pCurrent) |
| 49416 | +#define osGetenv ((const char *(*)(const char *))aSyscall[52].pCurrent) |
| 49940 | 49417 | |
| 49941 | 49418 | #ifndef _WIN32 |
| 49942 | 49419 | { "getcwd", (SYSCALL)getcwd, 0 }, |
| 49943 | 49420 | #else |
| 49944 | 49421 | { "getcwd", (SYSCALL)0, 0 }, |
| 49945 | 49422 | #endif |
| 49946 | | - |
| 49947 | | -#define osGetcwd ((char*(*)(char*,size_t))aSyscall[76].pCurrent) |
| 49423 | +#define osGetcwd ((char*(*)(char*,size_t))aSyscall[53].pCurrent) |
| 49948 | 49424 | |
| 49949 | 49425 | #ifndef _WIN32 |
| 49950 | 49426 | { "readlink", (SYSCALL)readlink, 0 }, |
| 49951 | 49427 | #else |
| 49952 | 49428 | { "readlink", (SYSCALL)0, 0 }, |
| 49953 | 49429 | #endif |
| 49954 | | - |
| 49955 | | -#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[77].pCurrent) |
| 49430 | +#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[54].pCurrent) |
| 49956 | 49431 | |
| 49957 | 49432 | #ifndef _WIN32 |
| 49958 | 49433 | { "lstat", (SYSCALL)lstat, 0 }, |
| 49959 | 49434 | #else |
| 49960 | 49435 | { "lstat", (SYSCALL)0, 0 }, |
| 49961 | 49436 | #endif |
| 49962 | | - |
| 49963 | | -#define osLstat ((int(*)(const char*,struct stat*))aSyscall[78].pCurrent) |
| 49437 | +#define osLstat ((int(*)(const char*,struct stat*))aSyscall[55].pCurrent) |
| 49964 | 49438 | |
| 49965 | 49439 | #ifndef _WIN32 |
| 49966 | 49440 | { "__errno", (SYSCALL)__errno, 0 }, |
| 49967 | 49441 | #else |
| 49968 | 49442 | { "__errno", (SYSCALL)0, 0 }, |
| 49969 | 49443 | #endif |
| 49970 | | - |
| 49971 | | -#define osErrno (*((int*(*)(void))aSyscall[79].pCurrent)()) |
| 49444 | +#define osErrno (*((int*(*)(void))aSyscall[56].pCurrent)()) |
| 49972 | 49445 | |
| 49973 | 49446 | #ifndef _WIN32 |
| 49974 | 49447 | { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 }, |
| 49975 | 49448 | #else |
| 49976 | 49449 | { "cygwin_conv_path", (SYSCALL)0, 0 }, |
| 49977 | 49450 | #endif |
| 49978 | | - |
| 49979 | 49451 | #define osCygwin_conv_path ((size_t(*)(unsigned int, \ |
| 49980 | | - const void *, void *, size_t))aSyscall[80].pCurrent) |
| 49452 | + const void *, void *, size_t))aSyscall[57].pCurrent) |
| 49981 | 49453 | |
| 49982 | 49454 | }; /* End of the overrideable system calls */ |
| 49983 | 49455 | |
| 49984 | 49456 | /* |
| 49985 | 49457 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| | @@ -50082,11 +49554,10 @@ |
| 50082 | 49554 | assert( hHeap!=0 ); |
| 50083 | 49555 | assert( hHeap!=INVALID_HANDLE_VALUE ); |
| 50084 | 49556 | #if defined(SQLITE_WIN32_MALLOC_VALIDATE) |
| 50085 | 49557 | assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); |
| 50086 | 49558 | #endif |
| 50087 | | -#if !SQLITE_OS_WINCE |
| 50088 | 49559 | if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){ |
| 50089 | 49560 | DWORD lastErrno = osGetLastError(); |
| 50090 | 49561 | if( lastErrno==NO_ERROR ){ |
| 50091 | 49562 | sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p", |
| 50092 | 49563 | (void*)hHeap); |
| | @@ -50095,15 +49566,10 @@ |
| 50095 | 49566 | sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p", |
| 50096 | 49567 | osGetLastError(), (void*)hHeap); |
| 50097 | 49568 | rc = SQLITE_ERROR; |
| 50098 | 49569 | } |
| 50099 | 49570 | } |
| 50100 | | -#else |
| 50101 | | - sqlite3_log(SQLITE_NOTFOUND, "failed to HeapCompact, heap=%p", |
| 50102 | | - (void*)hHeap); |
| 50103 | | - rc = SQLITE_NOTFOUND; |
| 50104 | | -#endif |
| 50105 | 49571 | if( pnLargest ) *pnLargest = nLargest; |
| 50106 | 49572 | return rc; |
| 50107 | 49573 | } |
| 50108 | 49574 | |
| 50109 | 49575 | /* |
| | @@ -50150,16 +49616,14 @@ |
| 50150 | 49616 | sqlite3_mutex_leave(pMainMtx); |
| 50151 | 49617 | return rc; |
| 50152 | 49618 | } |
| 50153 | 49619 | #endif /* SQLITE_WIN32_MALLOC */ |
| 50154 | 49620 | |
| 50155 | | -#ifdef _WIN32 |
| 50156 | 49621 | /* |
| 50157 | 49622 | ** This function outputs the specified (ANSI) string to the Win32 debugger |
| 50158 | | -** (if available). |
| 49623 | +** (if available). Undocumented. Might go away at any moment. |
| 50159 | 49624 | */ |
| 50160 | | - |
| 50161 | 49625 | SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){ |
| 50162 | 49626 | char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE]; |
| 50163 | 49627 | int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */ |
| 50164 | 49628 | if( nMin<-1 ) nMin = -1; /* all negative values become -1. */ |
| 50165 | 49629 | assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE ); |
| | @@ -50167,109 +49631,32 @@ |
| 50167 | 49631 | if( !zBuf ){ |
| 50168 | 49632 | (void)SQLITE_MISUSE_BKPT; |
| 50169 | 49633 | return; |
| 50170 | 49634 | } |
| 50171 | 49635 | #endif |
| 50172 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 50173 | 49636 | if( nMin>0 ){ |
| 50174 | 49637 | memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); |
| 50175 | 49638 | memcpy(zDbgBuf, zBuf, nMin); |
| 50176 | 49639 | osOutputDebugStringA(zDbgBuf); |
| 50177 | 49640 | }else{ |
| 50178 | 49641 | osOutputDebugStringA(zBuf); |
| 50179 | 49642 | } |
| 50180 | | -#elif defined(SQLITE_WIN32_HAS_WIDE) |
| 50181 | | - memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); |
| 50182 | | - if ( osMultiByteToWideChar( |
| 50183 | | - osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf, |
| 50184 | | - nMin, (LPWSTR)zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){ |
| 50185 | | - return; |
| 50186 | | - } |
| 50187 | | - osOutputDebugStringW((LPCWSTR)zDbgBuf); |
| 50188 | | -#else |
| 50189 | | - if( nMin>0 ){ |
| 50190 | | - memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); |
| 50191 | | - memcpy(zDbgBuf, zBuf, nMin); |
| 50192 | | - fprintf(stderr, "%s", zDbgBuf); |
| 50193 | | - }else{ |
| 50194 | | - fprintf(stderr, "%s", zBuf); |
| 50195 | | - } |
| 50196 | | -#endif |
| 50197 | | -} |
| 50198 | | -#endif /* _WIN32 */ |
| 49643 | +} |
| 50199 | 49644 | |
| 50200 | 49645 | SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){ |
| 50201 | 49646 | osSleep(milliseconds); |
| 50202 | 49647 | } |
| 50203 | 49648 | |
| 50204 | | -#if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINCE && \ |
| 50205 | | - SQLITE_THREADSAFE>0 |
| 49649 | +#if SQLITE_MAX_WORKER_THREADS>0 && SQLITE_THREADSAFE>0 |
| 50206 | 49650 | SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){ |
| 50207 | 49651 | DWORD rc; |
| 50208 | 49652 | while( (rc = osWaitForSingleObjectEx(hObject, INFINITE, |
| 50209 | 49653 | TRUE))==WAIT_IO_COMPLETION ){} |
| 50210 | 49654 | return rc; |
| 50211 | 49655 | } |
| 50212 | 49656 | #endif |
| 50213 | 49657 | |
| 50214 | | -/* |
| 50215 | | -** Return true (non-zero) if we are running under WinNT, Win2K, WinXP, |
| 50216 | | -** or WinCE. Return false (zero) for Win95, Win98, or WinME. |
| 50217 | | -** |
| 50218 | | -** Here is an interesting observation: Win95, Win98, and WinME lack |
| 50219 | | -** the LockFileEx() API. But we can still statically link against that |
| 50220 | | -** API as long as we don't call it when running Win95/98/ME. A call to |
| 50221 | | -** this routine is used to determine if the host is Win95/98/ME or |
| 50222 | | -** WinNT/2K/XP so that we will know whether or not we can safely call |
| 50223 | | -** the LockFileEx() API. |
| 50224 | | -*/ |
| 50225 | | - |
| 50226 | | -#if !SQLITE_WIN32_GETVERSIONEX |
| 50227 | | -# define osIsNT() (1) |
| 50228 | | -#elif SQLITE_OS_WINCE || !defined(SQLITE_WIN32_HAS_ANSI) |
| 50229 | | -# define osIsNT() (1) |
| 50230 | | -#elif !defined(SQLITE_WIN32_HAS_WIDE) |
| 50231 | | -# define osIsNT() (0) |
| 50232 | | -#else |
| 50233 | | -# define osIsNT() ((sqlite3_os_type==2) || sqlite3_win32_is_nt()) |
| 50234 | | -#endif |
| 50235 | | - |
| 50236 | | -/* |
| 50237 | | -** This function determines if the machine is running a version of Windows |
| 50238 | | -** based on the NT kernel. |
| 50239 | | -*/ |
| 50240 | | -SQLITE_API int sqlite3_win32_is_nt(void){ |
| 50241 | | -#if SQLITE_WIN32_GETVERSIONEX |
| 50242 | | - if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){ |
| 50243 | | -#if defined(SQLITE_WIN32_HAS_ANSI) |
| 50244 | | - OSVERSIONINFOA sInfo; |
| 50245 | | - sInfo.dwOSVersionInfoSize = sizeof(sInfo); |
| 50246 | | - osGetVersionExA(&sInfo); |
| 50247 | | - osInterlockedCompareExchange(&sqlite3_os_type, |
| 50248 | | - (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); |
| 50249 | | -#elif defined(SQLITE_WIN32_HAS_WIDE) |
| 50250 | | - OSVERSIONINFOW sInfo; |
| 50251 | | - sInfo.dwOSVersionInfoSize = sizeof(sInfo); |
| 50252 | | - osGetVersionExW(&sInfo); |
| 50253 | | - osInterlockedCompareExchange(&sqlite3_os_type, |
| 50254 | | - (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); |
| 50255 | | -#endif |
| 50256 | | - } |
| 50257 | | - return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2; |
| 50258 | | -#elif SQLITE_TEST |
| 50259 | | - return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2 |
| 50260 | | - || osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 |
| 50261 | | - ; |
| 50262 | | -#else |
| 50263 | | - /* |
| 50264 | | - ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are |
| 50265 | | - ** deprecated are always assumed to be based on the NT kernel. |
| 50266 | | - */ |
| 50267 | | - return 1; |
| 50268 | | -#endif |
| 50269 | | -} |
| 50270 | | - |
| 50271 | 49658 | #ifdef SQLITE_WIN32_MALLOC |
| 50272 | 49659 | /* |
| 50273 | 49660 | ** Allocate nBytes of memory. |
| 50274 | 49661 | */ |
| 50275 | 49662 | static void *winMemMalloc(int nBytes){ |
| | @@ -50809,53 +50196,28 @@ |
| 50809 | 50196 | ** returns the number of TCHARs written to the output |
| 50810 | 50197 | ** buffer, excluding the terminating null char. |
| 50811 | 50198 | */ |
| 50812 | 50199 | DWORD dwLen = 0; |
| 50813 | 50200 | char *zOut = 0; |
| 50814 | | - |
| 50815 | | - if( osIsNT() ){ |
| 50816 | | - LPWSTR zTempWide = NULL; |
| 50817 | | - dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 50818 | | - FORMAT_MESSAGE_FROM_SYSTEM | |
| 50819 | | - FORMAT_MESSAGE_IGNORE_INSERTS, |
| 50820 | | - NULL, |
| 50821 | | - lastErrno, |
| 50822 | | - 0, |
| 50823 | | - (LPWSTR) &zTempWide, |
| 50824 | | - 0, |
| 50825 | | - 0); |
| 50826 | | - if( dwLen > 0 ){ |
| 50827 | | - /* allocate a buffer and convert to UTF8 */ |
| 50828 | | - sqlite3BeginBenignMalloc(); |
| 50829 | | - zOut = winUnicodeToUtf8(zTempWide); |
| 50830 | | - sqlite3EndBenignMalloc(); |
| 50831 | | - /* free the system buffer allocated by FormatMessage */ |
| 50832 | | - osLocalFree(zTempWide); |
| 50833 | | - } |
| 50834 | | - } |
| 50835 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 50836 | | - else{ |
| 50837 | | - char *zTemp = NULL; |
| 50838 | | - dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 50839 | | - FORMAT_MESSAGE_FROM_SYSTEM | |
| 50840 | | - FORMAT_MESSAGE_IGNORE_INSERTS, |
| 50841 | | - NULL, |
| 50842 | | - lastErrno, |
| 50843 | | - 0, |
| 50844 | | - (LPSTR) &zTemp, |
| 50845 | | - 0, |
| 50846 | | - 0); |
| 50847 | | - if( dwLen > 0 ){ |
| 50848 | | - /* allocate a buffer and convert to UTF8 */ |
| 50849 | | - sqlite3BeginBenignMalloc(); |
| 50850 | | - zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI()); |
| 50851 | | - sqlite3EndBenignMalloc(); |
| 50852 | | - /* free the system buffer allocated by FormatMessage */ |
| 50853 | | - osLocalFree(zTemp); |
| 50854 | | - } |
| 50855 | | - } |
| 50856 | | -#endif |
| 50201 | + LPWSTR zTempWide = NULL; |
| 50202 | + dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 50203 | + FORMAT_MESSAGE_FROM_SYSTEM | |
| 50204 | + FORMAT_MESSAGE_IGNORE_INSERTS, |
| 50205 | + NULL, |
| 50206 | + lastErrno, |
| 50207 | + 0, |
| 50208 | + (LPWSTR) &zTempWide, |
| 50209 | + 0, |
| 50210 | + 0); |
| 50211 | + if( dwLen > 0 ){ |
| 50212 | + /* allocate a buffer and convert to UTF8 */ |
| 50213 | + sqlite3BeginBenignMalloc(); |
| 50214 | + zOut = winUnicodeToUtf8(zTempWide); |
| 50215 | + sqlite3EndBenignMalloc(); |
| 50216 | + /* free the system buffer allocated by FormatMessage */ |
| 50217 | + osLocalFree(zTempWide); |
| 50218 | + } |
| 50857 | 50219 | if( 0 == dwLen ){ |
| 50858 | 50220 | sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno); |
| 50859 | 50221 | }else{ |
| 50860 | 50222 | /* copy a maximum of nBuf chars to output buffer */ |
| 50861 | 50223 | sqlite3_snprintf(nBuf, zBuf, "%s", zOut); |
| | @@ -50987,327 +50349,10 @@ |
| 50987 | 50349 | winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno |
| 50988 | 50350 | ); |
| 50989 | 50351 | } |
| 50990 | 50352 | } |
| 50991 | 50353 | |
| 50992 | | -/* |
| 50993 | | -** This #if does not rely on the SQLITE_OS_WINCE define because the |
| 50994 | | -** corresponding section in "date.c" cannot use it. |
| 50995 | | -*/ |
| 50996 | | -#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \ |
| 50997 | | - (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API) |
| 50998 | | -/* |
| 50999 | | -** The MSVC CRT on Windows CE may not have a localtime() function. |
| 51000 | | -** So define a substitute. |
| 51001 | | -*/ |
| 51002 | | -/* # include <time.h> */ |
| 51003 | | -struct tm *__cdecl localtime(const time_t *t) |
| 51004 | | -{ |
| 51005 | | - static struct tm y; |
| 51006 | | - FILETIME uTm, lTm; |
| 51007 | | - SYSTEMTIME pTm; |
| 51008 | | - sqlite3_int64 t64; |
| 51009 | | - t64 = *t; |
| 51010 | | - t64 = (t64 + 11644473600)*10000000; |
| 51011 | | - uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF); |
| 51012 | | - uTm.dwHighDateTime= (DWORD)(t64 >> 32); |
| 51013 | | - osFileTimeToLocalFileTime(&uTm,&lTm); |
| 51014 | | - osFileTimeToSystemTime(&lTm,&pTm); |
| 51015 | | - y.tm_year = pTm.wYear - 1900; |
| 51016 | | - y.tm_mon = pTm.wMonth - 1; |
| 51017 | | - y.tm_wday = pTm.wDayOfWeek; |
| 51018 | | - y.tm_mday = pTm.wDay; |
| 51019 | | - y.tm_hour = pTm.wHour; |
| 51020 | | - y.tm_min = pTm.wMinute; |
| 51021 | | - y.tm_sec = pTm.wSecond; |
| 51022 | | - return &y; |
| 51023 | | -} |
| 51024 | | -#endif |
| 51025 | | - |
| 51026 | | -#if SQLITE_OS_WINCE |
| 51027 | | -/************************************************************************* |
| 51028 | | -** This section contains code for WinCE only. |
| 51029 | | -*/ |
| 51030 | | -#define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)] |
| 51031 | | - |
| 51032 | | -/* |
| 51033 | | -** Acquire a lock on the handle h |
| 51034 | | -*/ |
| 51035 | | -static void winceMutexAcquire(HANDLE h){ |
| 51036 | | - DWORD dwErr; |
| 51037 | | - do { |
| 51038 | | - dwErr = osWaitForSingleObject(h, INFINITE); |
| 51039 | | - } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED); |
| 51040 | | -} |
| 51041 | | -/* |
| 51042 | | -** Release a lock acquired by winceMutexAcquire() |
| 51043 | | -*/ |
| 51044 | | -#define winceMutexRelease(h) ReleaseMutex(h) |
| 51045 | | - |
| 51046 | | -/* |
| 51047 | | -** Create the mutex and shared memory used for locking in the file |
| 51048 | | -** descriptor pFile |
| 51049 | | -*/ |
| 51050 | | -static int winceCreateLock(const char *zFilename, winFile *pFile){ |
| 51051 | | - LPWSTR zTok; |
| 51052 | | - LPWSTR zName; |
| 51053 | | - DWORD lastErrno; |
| 51054 | | - BOOL bLogged = FALSE; |
| 51055 | | - BOOL bInit = TRUE; |
| 51056 | | - |
| 51057 | | - zName = winUtf8ToUnicode(zFilename); |
| 51058 | | - if( zName==0 ){ |
| 51059 | | - /* out of memory */ |
| 51060 | | - return SQLITE_IOERR_NOMEM_BKPT; |
| 51061 | | - } |
| 51062 | | - |
| 51063 | | - /* Initialize the local lockdata */ |
| 51064 | | - memset(&pFile->local, 0, sizeof(pFile->local)); |
| 51065 | | - |
| 51066 | | - /* Replace the backslashes from the filename and lowercase it |
| 51067 | | - ** to derive a mutex name. */ |
| 51068 | | - zTok = osCharLowerW(zName); |
| 51069 | | - for (;*zTok;zTok++){ |
| 51070 | | - if (*zTok == '\\') *zTok = '_'; |
| 51071 | | - } |
| 51072 | | - |
| 51073 | | - /* Create/open the named mutex */ |
| 51074 | | - pFile->hMutex = osCreateMutexW(NULL, FALSE, zName); |
| 51075 | | - if (!pFile->hMutex){ |
| 51076 | | - pFile->lastErrno = osGetLastError(); |
| 51077 | | - sqlite3_free(zName); |
| 51078 | | - return winLogError(SQLITE_IOERR, pFile->lastErrno, |
| 51079 | | - "winceCreateLock1", zFilename); |
| 51080 | | - } |
| 51081 | | - |
| 51082 | | - /* Acquire the mutex before continuing */ |
| 51083 | | - winceMutexAcquire(pFile->hMutex); |
| 51084 | | - |
| 51085 | | - /* Since the names of named mutexes, semaphores, file mappings etc are |
| 51086 | | - ** case-sensitive, take advantage of that by uppercasing the mutex name |
| 51087 | | - ** and using that as the shared filemapping name. |
| 51088 | | - */ |
| 51089 | | - osCharUpperW(zName); |
| 51090 | | - pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL, |
| 51091 | | - PAGE_READWRITE, 0, sizeof(winceLock), |
| 51092 | | - zName); |
| 51093 | | - |
| 51094 | | - /* Set a flag that indicates we're the first to create the memory so it |
| 51095 | | - ** must be zero-initialized */ |
| 51096 | | - lastErrno = osGetLastError(); |
| 51097 | | - if (lastErrno == ERROR_ALREADY_EXISTS){ |
| 51098 | | - bInit = FALSE; |
| 51099 | | - } |
| 51100 | | - |
| 51101 | | - sqlite3_free(zName); |
| 51102 | | - |
| 51103 | | - /* If we succeeded in making the shared memory handle, map it. */ |
| 51104 | | - if( pFile->hShared ){ |
| 51105 | | - pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared, |
| 51106 | | - FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); |
| 51107 | | - /* If mapping failed, close the shared memory handle and erase it */ |
| 51108 | | - if( !pFile->shared ){ |
| 51109 | | - pFile->lastErrno = osGetLastError(); |
| 51110 | | - winLogError(SQLITE_IOERR, pFile->lastErrno, |
| 51111 | | - "winceCreateLock2", zFilename); |
| 51112 | | - bLogged = TRUE; |
| 51113 | | - osCloseHandle(pFile->hShared); |
| 51114 | | - pFile->hShared = NULL; |
| 51115 | | - } |
| 51116 | | - } |
| 51117 | | - |
| 51118 | | - /* If shared memory could not be created, then close the mutex and fail */ |
| 51119 | | - if( pFile->hShared==NULL ){ |
| 51120 | | - if( !bLogged ){ |
| 51121 | | - pFile->lastErrno = lastErrno; |
| 51122 | | - winLogError(SQLITE_IOERR, pFile->lastErrno, |
| 51123 | | - "winceCreateLock3", zFilename); |
| 51124 | | - bLogged = TRUE; |
| 51125 | | - } |
| 51126 | | - winceMutexRelease(pFile->hMutex); |
| 51127 | | - osCloseHandle(pFile->hMutex); |
| 51128 | | - pFile->hMutex = NULL; |
| 51129 | | - return SQLITE_IOERR; |
| 51130 | | - } |
| 51131 | | - |
| 51132 | | - /* Initialize the shared memory if we're supposed to */ |
| 51133 | | - if( bInit ){ |
| 51134 | | - memset(pFile->shared, 0, sizeof(winceLock)); |
| 51135 | | - } |
| 51136 | | - |
| 51137 | | - winceMutexRelease(pFile->hMutex); |
| 51138 | | - return SQLITE_OK; |
| 51139 | | -} |
| 51140 | | - |
| 51141 | | -/* |
| 51142 | | -** Destroy the part of winFile that deals with wince locks |
| 51143 | | -*/ |
| 51144 | | -static void winceDestroyLock(winFile *pFile){ |
| 51145 | | - if (pFile->hMutex){ |
| 51146 | | - /* Acquire the mutex */ |
| 51147 | | - winceMutexAcquire(pFile->hMutex); |
| 51148 | | - |
| 51149 | | - /* The following blocks should probably assert in debug mode, but they |
| 51150 | | - are to cleanup in case any locks remained open */ |
| 51151 | | - if (pFile->local.nReaders){ |
| 51152 | | - pFile->shared->nReaders --; |
| 51153 | | - } |
| 51154 | | - if (pFile->local.bReserved){ |
| 51155 | | - pFile->shared->bReserved = FALSE; |
| 51156 | | - } |
| 51157 | | - if (pFile->local.bPending){ |
| 51158 | | - pFile->shared->bPending = FALSE; |
| 51159 | | - } |
| 51160 | | - if (pFile->local.bExclusive){ |
| 51161 | | - pFile->shared->bExclusive = FALSE; |
| 51162 | | - } |
| 51163 | | - |
| 51164 | | - /* De-reference and close our copy of the shared memory handle */ |
| 51165 | | - osUnmapViewOfFile(pFile->shared); |
| 51166 | | - osCloseHandle(pFile->hShared); |
| 51167 | | - |
| 51168 | | - /* Done with the mutex */ |
| 51169 | | - winceMutexRelease(pFile->hMutex); |
| 51170 | | - osCloseHandle(pFile->hMutex); |
| 51171 | | - pFile->hMutex = NULL; |
| 51172 | | - } |
| 51173 | | -} |
| 51174 | | - |
| 51175 | | -/* |
| 51176 | | -** An implementation of the LockFile() API of Windows for CE |
| 51177 | | -*/ |
| 51178 | | -static BOOL winceLockFile( |
| 51179 | | - LPHANDLE phFile, |
| 51180 | | - DWORD dwFileOffsetLow, |
| 51181 | | - DWORD dwFileOffsetHigh, |
| 51182 | | - DWORD nNumberOfBytesToLockLow, |
| 51183 | | - DWORD nNumberOfBytesToLockHigh |
| 51184 | | -){ |
| 51185 | | - winFile *pFile = HANDLE_TO_WINFILE(phFile); |
| 51186 | | - BOOL bReturn = FALSE; |
| 51187 | | - |
| 51188 | | - UNUSED_PARAMETER(dwFileOffsetHigh); |
| 51189 | | - UNUSED_PARAMETER(nNumberOfBytesToLockHigh); |
| 51190 | | - |
| 51191 | | - if (!pFile->hMutex) return TRUE; |
| 51192 | | - winceMutexAcquire(pFile->hMutex); |
| 51193 | | - |
| 51194 | | - /* Wanting an exclusive lock? */ |
| 51195 | | - if (dwFileOffsetLow == (DWORD)SHARED_FIRST |
| 51196 | | - && nNumberOfBytesToLockLow == (DWORD)SHARED_SIZE){ |
| 51197 | | - if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){ |
| 51198 | | - pFile->shared->bExclusive = TRUE; |
| 51199 | | - pFile->local.bExclusive = TRUE; |
| 51200 | | - bReturn = TRUE; |
| 51201 | | - } |
| 51202 | | - } |
| 51203 | | - |
| 51204 | | - /* Want a read-only lock? */ |
| 51205 | | - else if (dwFileOffsetLow == (DWORD)SHARED_FIRST && |
| 51206 | | - nNumberOfBytesToLockLow == 1){ |
| 51207 | | - if (pFile->shared->bExclusive == 0){ |
| 51208 | | - pFile->local.nReaders ++; |
| 51209 | | - if (pFile->local.nReaders == 1){ |
| 51210 | | - pFile->shared->nReaders ++; |
| 51211 | | - } |
| 51212 | | - bReturn = TRUE; |
| 51213 | | - } |
| 51214 | | - } |
| 51215 | | - |
| 51216 | | - /* Want a pending lock? */ |
| 51217 | | - else if (dwFileOffsetLow == (DWORD)PENDING_BYTE |
| 51218 | | - && nNumberOfBytesToLockLow == 1){ |
| 51219 | | - /* If no pending lock has been acquired, then acquire it */ |
| 51220 | | - if (pFile->shared->bPending == 0) { |
| 51221 | | - pFile->shared->bPending = TRUE; |
| 51222 | | - pFile->local.bPending = TRUE; |
| 51223 | | - bReturn = TRUE; |
| 51224 | | - } |
| 51225 | | - } |
| 51226 | | - |
| 51227 | | - /* Want a reserved lock? */ |
| 51228 | | - else if (dwFileOffsetLow == (DWORD)RESERVED_BYTE |
| 51229 | | - && nNumberOfBytesToLockLow == 1){ |
| 51230 | | - if (pFile->shared->bReserved == 0) { |
| 51231 | | - pFile->shared->bReserved = TRUE; |
| 51232 | | - pFile->local.bReserved = TRUE; |
| 51233 | | - bReturn = TRUE; |
| 51234 | | - } |
| 51235 | | - } |
| 51236 | | - |
| 51237 | | - winceMutexRelease(pFile->hMutex); |
| 51238 | | - return bReturn; |
| 51239 | | -} |
| 51240 | | - |
| 51241 | | -/* |
| 51242 | | -** An implementation of the UnlockFile API of Windows for CE |
| 51243 | | -*/ |
| 51244 | | -static BOOL winceUnlockFile( |
| 51245 | | - LPHANDLE phFile, |
| 51246 | | - DWORD dwFileOffsetLow, |
| 51247 | | - DWORD dwFileOffsetHigh, |
| 51248 | | - DWORD nNumberOfBytesToUnlockLow, |
| 51249 | | - DWORD nNumberOfBytesToUnlockHigh |
| 51250 | | -){ |
| 51251 | | - winFile *pFile = HANDLE_TO_WINFILE(phFile); |
| 51252 | | - BOOL bReturn = FALSE; |
| 51253 | | - |
| 51254 | | - UNUSED_PARAMETER(dwFileOffsetHigh); |
| 51255 | | - UNUSED_PARAMETER(nNumberOfBytesToUnlockHigh); |
| 51256 | | - |
| 51257 | | - if (!pFile->hMutex) return TRUE; |
| 51258 | | - winceMutexAcquire(pFile->hMutex); |
| 51259 | | - |
| 51260 | | - /* Releasing a reader lock or an exclusive lock */ |
| 51261 | | - if (dwFileOffsetLow == (DWORD)SHARED_FIRST){ |
| 51262 | | - /* Did we have an exclusive lock? */ |
| 51263 | | - if (pFile->local.bExclusive){ |
| 51264 | | - assert(nNumberOfBytesToUnlockLow == (DWORD)SHARED_SIZE); |
| 51265 | | - pFile->local.bExclusive = FALSE; |
| 51266 | | - pFile->shared->bExclusive = FALSE; |
| 51267 | | - bReturn = TRUE; |
| 51268 | | - } |
| 51269 | | - |
| 51270 | | - /* Did we just have a reader lock? */ |
| 51271 | | - else if (pFile->local.nReaders){ |
| 51272 | | - assert(nNumberOfBytesToUnlockLow == (DWORD)SHARED_SIZE |
| 51273 | | - || nNumberOfBytesToUnlockLow == 1); |
| 51274 | | - pFile->local.nReaders --; |
| 51275 | | - if (pFile->local.nReaders == 0) |
| 51276 | | - { |
| 51277 | | - pFile->shared->nReaders --; |
| 51278 | | - } |
| 51279 | | - bReturn = TRUE; |
| 51280 | | - } |
| 51281 | | - } |
| 51282 | | - |
| 51283 | | - /* Releasing a pending lock */ |
| 51284 | | - else if (dwFileOffsetLow == (DWORD)PENDING_BYTE |
| 51285 | | - && nNumberOfBytesToUnlockLow == 1){ |
| 51286 | | - if (pFile->local.bPending){ |
| 51287 | | - pFile->local.bPending = FALSE; |
| 51288 | | - pFile->shared->bPending = FALSE; |
| 51289 | | - bReturn = TRUE; |
| 51290 | | - } |
| 51291 | | - } |
| 51292 | | - /* Releasing a reserved lock */ |
| 51293 | | - else if (dwFileOffsetLow == (DWORD)RESERVED_BYTE |
| 51294 | | - && nNumberOfBytesToUnlockLow == 1){ |
| 51295 | | - if (pFile->local.bReserved) { |
| 51296 | | - pFile->local.bReserved = FALSE; |
| 51297 | | - pFile->shared->bReserved = FALSE; |
| 51298 | | - bReturn = TRUE; |
| 51299 | | - } |
| 51300 | | - } |
| 51301 | | - |
| 51302 | | - winceMutexRelease(pFile->hMutex); |
| 51303 | | - return bReturn; |
| 51304 | | -} |
| 51305 | | -/* |
| 51306 | | -** End of the special code for wince |
| 51307 | | -*****************************************************************************/ |
| 51308 | | -#endif /* SQLITE_OS_WINCE */ |
| 51309 | 50354 | |
| 51310 | 50355 | /* |
| 51311 | 50356 | ** Lock a file region. |
| 51312 | 50357 | */ |
| 51313 | 50358 | static BOOL winLockFile( |
| | @@ -51316,31 +50361,15 @@ |
| 51316 | 50361 | DWORD offsetLow, |
| 51317 | 50362 | DWORD offsetHigh, |
| 51318 | 50363 | DWORD numBytesLow, |
| 51319 | 50364 | DWORD numBytesHigh |
| 51320 | 50365 | ){ |
| 51321 | | -#if SQLITE_OS_WINCE |
| 51322 | | - /* |
| 51323 | | - ** NOTE: Windows CE is handled differently here due its lack of the Win32 |
| 51324 | | - ** API LockFile. |
| 51325 | | - */ |
| 51326 | | - return winceLockFile(phFile, offsetLow, offsetHigh, |
| 51327 | | - numBytesLow, numBytesHigh); |
| 51328 | | -#else |
| 51329 | | - if( osIsNT() ){ |
| 51330 | | - OVERLAPPED ovlp; |
| 51331 | | - memset(&ovlp, 0, sizeof(OVERLAPPED)); |
| 51332 | | - ovlp.Offset = offsetLow; |
| 51333 | | - ovlp.OffsetHigh = offsetHigh; |
| 51334 | | - return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp); |
| 51335 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 51336 | | - }else{ |
| 51337 | | - return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow, |
| 51338 | | - numBytesHigh); |
| 51339 | | -#endif |
| 51340 | | - } |
| 51341 | | -#endif |
| 50366 | + OVERLAPPED ovlp; |
| 50367 | + memset(&ovlp, 0, sizeof(OVERLAPPED)); |
| 50368 | + ovlp.Offset = offsetLow; |
| 50369 | + ovlp.OffsetHigh = offsetHigh; |
| 50370 | + return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp); |
| 51342 | 50371 | } |
| 51343 | 50372 | |
| 51344 | 50373 | #ifndef SQLITE_OMIT_WAL |
| 51345 | 50374 | /* |
| 51346 | 50375 | ** Lock a region of nByte bytes starting at offset offset of file hFile. |
| | @@ -51360,66 +50389,59 @@ |
| 51360 | 50389 | DWORD nMs |
| 51361 | 50390 | ){ |
| 51362 | 50391 | DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | (bExcl?LOCKFILE_EXCLUSIVE_LOCK:0); |
| 51363 | 50392 | int rc = SQLITE_OK; |
| 51364 | 50393 | BOOL ret; |
| 51365 | | - |
| 51366 | | - if( !osIsNT() ){ |
| 51367 | | - ret = winLockFile(&hFile, flags, offset, 0, nByte, 0); |
| 51368 | | - }else{ |
| 51369 | | - OVERLAPPED ovlp; |
| 51370 | | - memset(&ovlp, 0, sizeof(OVERLAPPED)); |
| 51371 | | - ovlp.Offset = offset; |
| 51372 | | - |
| 51373 | | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 51374 | | - if( nMs!=0 ){ |
| 51375 | | - flags &= ~LOCKFILE_FAIL_IMMEDIATELY; |
| 51376 | | - } |
| 51377 | | - ovlp.hEvent = osCreateEvent(NULL, TRUE, FALSE, NULL); |
| 51378 | | - if( ovlp.hEvent==NULL ){ |
| 51379 | | - return SQLITE_IOERR_LOCK; |
| 51380 | | - } |
| 51381 | | -#endif |
| 51382 | | - |
| 51383 | | - ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp); |
| 51384 | | - |
| 51385 | | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 51386 | | - /* If SQLITE_ENABLE_SETLK_TIMEOUT is defined, then the file-handle was |
| 51387 | | - ** opened with FILE_FLAG_OVERHEAD specified. In this case, the call to |
| 51388 | | - ** LockFileEx() may fail because the request is still pending. This can |
| 51389 | | - ** happen even if LOCKFILE_FAIL_IMMEDIATELY was specified. |
| 51390 | | - ** |
| 51391 | | - ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags |
| 51392 | | - ** passed to LockFileEx(). In this case, if the operation is pending, |
| 51393 | | - ** block indefinitely until it is finished. |
| 51394 | | - ** |
| 51395 | | - ** Otherwise, wait for up to nMs ms for the operation to finish. nMs |
| 51396 | | - ** may be set to INFINITE. |
| 51397 | | - */ |
| 51398 | | - if( !ret && GetLastError()==ERROR_IO_PENDING ){ |
| 51399 | | - DWORD nDelay = (nMs==0 ? INFINITE : nMs); |
| 51400 | | - DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay); |
| 51401 | | - if( res==WAIT_OBJECT_0 ){ |
| 51402 | | - ret = TRUE; |
| 51403 | | - }else if( res==WAIT_TIMEOUT ){ |
| 50394 | + OVERLAPPED ovlp; |
| 50395 | + memset(&ovlp, 0, sizeof(OVERLAPPED)); |
| 50396 | + ovlp.Offset = offset; |
| 50397 | + |
| 50398 | +#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) |
| 50399 | + if( nMs!=0 ){ |
| 50400 | + flags &= ~LOCKFILE_FAIL_IMMEDIATELY; |
| 50401 | + } |
| 50402 | + ovlp.hEvent = osCreateEvent(NULL, TRUE, FALSE, NULL); |
| 50403 | + if( ovlp.hEvent==NULL ){ |
| 50404 | + return SQLITE_IOERR_LOCK; |
| 50405 | + } |
| 50406 | +#endif |
| 50407 | + ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp); |
| 50408 | +#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) |
| 50409 | + /* If SQLITE_ENABLE_SETLK_TIMEOUT is defined, then the file-handle was |
| 50410 | + ** opened with FILE_FLAG_OVERHEAD specified. In this case, the call to |
| 50411 | + ** LockFileEx() may fail because the request is still pending. This can |
| 50412 | + ** happen even if LOCKFILE_FAIL_IMMEDIATELY was specified. |
| 50413 | + ** |
| 50414 | + ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags |
| 50415 | + ** passed to LockFileEx(). In this case, if the operation is pending, |
| 50416 | + ** block indefinitely until it is finished. |
| 50417 | + ** |
| 50418 | + ** Otherwise, wait for up to nMs ms for the operation to finish. nMs |
| 50419 | + ** may be set to INFINITE. |
| 50420 | + */ |
| 50421 | + if( !ret && GetLastError()==ERROR_IO_PENDING ){ |
| 50422 | + DWORD nDelay = (nMs==0 ? INFINITE : nMs); |
| 50423 | + DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay); |
| 50424 | + if( res==WAIT_OBJECT_0 ){ |
| 50425 | + ret = TRUE; |
| 50426 | + }else if( res==WAIT_TIMEOUT ){ |
| 51404 | 50427 | #if SQLITE_ENABLE_SETLK_TIMEOUT==1 |
| 51405 | | - rc = SQLITE_BUSY_TIMEOUT; |
| 51406 | | -#else |
| 51407 | | - rc = SQLITE_BUSY; |
| 51408 | | -#endif |
| 51409 | | - }else{ |
| 51410 | | - /* Some other error has occurred */ |
| 51411 | | - rc = SQLITE_IOERR_LOCK; |
| 51412 | | - } |
| 51413 | | - |
| 51414 | | - /* If it is still pending, cancel the LockFileEx() call. */ |
| 51415 | | - osCancelIo(hFile); |
| 51416 | | - } |
| 51417 | | - |
| 51418 | | - osCloseHandle(ovlp.hEvent); |
| 51419 | | -#endif |
| 51420 | | - } |
| 50428 | + rc = SQLITE_BUSY_TIMEOUT; |
| 50429 | +#else |
| 50430 | + rc = SQLITE_BUSY; |
| 50431 | +#endif |
| 50432 | + }else{ |
| 50433 | + /* Some other error has occurred */ |
| 50434 | + rc = SQLITE_IOERR_LOCK; |
| 50435 | + } |
| 50436 | + |
| 50437 | + /* If it is still pending, cancel the LockFileEx() call. */ |
| 50438 | + osCancelIo(hFile); |
| 50439 | + } |
| 50440 | + |
| 50441 | + osCloseHandle(ovlp.hEvent); |
| 50442 | +#endif /* defined(SQLITE_ENABLE_SETLK_TIMEOUT) */ |
| 51421 | 50443 | |
| 51422 | 50444 | if( rc==SQLITE_OK && !ret ){ |
| 51423 | 50445 | rc = SQLITE_BUSY; |
| 51424 | 50446 | } |
| 51425 | 50447 | return rc; |
| | @@ -51434,31 +50456,15 @@ |
| 51434 | 50456 | DWORD offsetLow, |
| 51435 | 50457 | DWORD offsetHigh, |
| 51436 | 50458 | DWORD numBytesLow, |
| 51437 | 50459 | DWORD numBytesHigh |
| 51438 | 50460 | ){ |
| 51439 | | -#if SQLITE_OS_WINCE |
| 51440 | | - /* |
| 51441 | | - ** NOTE: Windows CE is handled differently here due its lack of the Win32 |
| 51442 | | - ** API UnlockFile. |
| 51443 | | - */ |
| 51444 | | - return winceUnlockFile(phFile, offsetLow, offsetHigh, |
| 51445 | | - numBytesLow, numBytesHigh); |
| 51446 | | -#else |
| 51447 | | - if( osIsNT() ){ |
| 51448 | | - OVERLAPPED ovlp; |
| 51449 | | - memset(&ovlp, 0, sizeof(OVERLAPPED)); |
| 51450 | | - ovlp.Offset = offsetLow; |
| 51451 | | - ovlp.OffsetHigh = offsetHigh; |
| 51452 | | - return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp); |
| 51453 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 51454 | | - }else{ |
| 51455 | | - return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow, |
| 51456 | | - numBytesHigh); |
| 51457 | | -#endif |
| 51458 | | - } |
| 51459 | | -#endif |
| 50461 | + OVERLAPPED ovlp; |
| 50462 | + memset(&ovlp, 0, sizeof(OVERLAPPED)); |
| 50463 | + ovlp.Offset = offsetLow; |
| 50464 | + ovlp.OffsetHigh = offsetHigh; |
| 50465 | + return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp); |
| 51460 | 50466 | } |
| 51461 | 50467 | |
| 51462 | 50468 | #ifndef SQLITE_OMIT_WAL |
| 51463 | 50469 | /* |
| 51464 | 50470 | ** Remove an nByte lock starting at offset iOff from HANDLE h. |
| | @@ -51567,30 +50573,10 @@ |
| 51567 | 50573 | |
| 51568 | 50574 | do{ |
| 51569 | 50575 | rc = osCloseHandle(pFile->h); |
| 51570 | 50576 | /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ |
| 51571 | 50577 | }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); |
| 51572 | | -#if SQLITE_OS_WINCE |
| 51573 | | -#define WINCE_DELETION_ATTEMPTS 3 |
| 51574 | | - { |
| 51575 | | - winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData; |
| 51576 | | - if( pAppData==NULL || !pAppData->bNoLock ){ |
| 51577 | | - winceDestroyLock(pFile); |
| 51578 | | - } |
| 51579 | | - } |
| 51580 | | - if( pFile->zDeleteOnClose ){ |
| 51581 | | - int cnt = 0; |
| 51582 | | - while( |
| 51583 | | - osDeleteFileW(pFile->zDeleteOnClose)==0 |
| 51584 | | - && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff |
| 51585 | | - && cnt++ < WINCE_DELETION_ATTEMPTS |
| 51586 | | - ){ |
| 51587 | | - sqlite3_win32_sleep(100); /* Wait a little before trying again */ |
| 51588 | | - } |
| 51589 | | - sqlite3_free(pFile->zDeleteOnClose); |
| 51590 | | - } |
| 51591 | | -#endif |
| 51592 | 50578 | if( rc ){ |
| 51593 | 50579 | pFile->h = NULL; |
| 51594 | 50580 | } |
| 51595 | 50581 | OpenCounter(-1); |
| 51596 | 50582 | OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n", |
| | @@ -51609,11 +50595,11 @@ |
| 51609 | 50595 | sqlite3_file *id, /* File to read from */ |
| 51610 | 50596 | void *pBuf, /* Write content into this buffer */ |
| 51611 | 50597 | int amt, /* Number of bytes to read */ |
| 51612 | 50598 | sqlite3_int64 offset /* Begin reading at this offset */ |
| 51613 | 50599 | ){ |
| 51614 | | -#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 50600 | +#if !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 51615 | 50601 | OVERLAPPED overlapped; /* The offset for ReadFile. */ |
| 51616 | 50602 | #endif |
| 51617 | 50603 | winFile *pFile = (winFile*)id; /* file handle */ |
| 51618 | 50604 | DWORD nRead; /* Number of bytes actually read from file */ |
| 51619 | 50605 | int nRetry = 0; /* Number of retrys */ |
| | @@ -51643,11 +50629,11 @@ |
| 51643 | 50629 | offset += nCopy; |
| 51644 | 50630 | } |
| 51645 | 50631 | } |
| 51646 | 50632 | #endif |
| 51647 | 50633 | |
| 51648 | | -#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 50634 | +#if defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 51649 | 50635 | if( winSeekFile(pFile, offset) ){ |
| 51650 | 50636 | OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", |
| 51651 | 50637 | osGetCurrentProcessId(), pFile, pFile->h)); |
| 51652 | 50638 | return SQLITE_FULL; |
| 51653 | 50639 | } |
| | @@ -51721,32 +50707,32 @@ |
| 51721 | 50707 | offset += nCopy; |
| 51722 | 50708 | } |
| 51723 | 50709 | } |
| 51724 | 50710 | #endif |
| 51725 | 50711 | |
| 51726 | | -#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 50712 | +#if defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 51727 | 50713 | rc = winSeekFile(pFile, offset); |
| 51728 | 50714 | if( rc==0 ){ |
| 51729 | 50715 | #else |
| 51730 | 50716 | { |
| 51731 | 50717 | #endif |
| 51732 | | -#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 50718 | +#if !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 51733 | 50719 | OVERLAPPED overlapped; /* The offset for WriteFile. */ |
| 51734 | 50720 | #endif |
| 51735 | 50721 | u8 *aRem = (u8 *)pBuf; /* Data yet to be written */ |
| 51736 | 50722 | int nRem = amt; /* Number of bytes yet to be written */ |
| 51737 | 50723 | DWORD nWrite; /* Bytes written by each WriteFile() call */ |
| 51738 | 50724 | DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */ |
| 51739 | 50725 | |
| 51740 | | -#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 50726 | +#if !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 51741 | 50727 | memset(&overlapped, 0, sizeof(OVERLAPPED)); |
| 51742 | 50728 | overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 51743 | 50729 | overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 51744 | 50730 | #endif |
| 51745 | 50731 | |
| 51746 | 50732 | while( nRem>0 ){ |
| 51747 | | -#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 50733 | +#if defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 51748 | 50734 | if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){ |
| 51749 | 50735 | #else |
| 51750 | 50736 | if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){ |
| 51751 | 50737 | #endif |
| 51752 | 50738 | if( winRetryIoerr(&nRetry, &lastErrno) ) continue; |
| | @@ -51755,11 +50741,11 @@ |
| 51755 | 50741 | assert( nWrite==0 || nWrite<=(DWORD)nRem ); |
| 51756 | 50742 | if( nWrite==0 || nWrite>(DWORD)nRem ){ |
| 51757 | 50743 | lastErrno = osGetLastError(); |
| 51758 | 50744 | break; |
| 51759 | 50745 | } |
| 51760 | | -#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 50746 | +#if !defined(SQLITE_WIN32_NO_OVERLAPPED) |
| 51761 | 50747 | offset += nWrite; |
| 51762 | 50748 | overlapped.Offset = (LONG)(offset & 0xffffffff); |
| 51763 | 50749 | overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
| 51764 | 50750 | #endif |
| 51765 | 50751 | aRem += nWrite; |
| | @@ -52076,31 +51062,12 @@ |
| 52076 | 51062 | */ |
| 52077 | 51063 | static int winGetReadLock(winFile *pFile, int bBlock){ |
| 52078 | 51064 | int res; |
| 52079 | 51065 | DWORD mask = ~(bBlock ? LOCKFILE_FAIL_IMMEDIATELY : 0); |
| 52080 | 51066 | OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype)); |
| 52081 | | - if( osIsNT() ){ |
| 52082 | | -#if SQLITE_OS_WINCE |
| 52083 | | - /* |
| 52084 | | - ** NOTE: Windows CE is handled differently here due its lack of the Win32 |
| 52085 | | - ** API LockFileEx. |
| 52086 | | - */ |
| 52087 | | - res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0); |
| 52088 | | -#else |
| 52089 | | - res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0, |
| 52090 | | - SHARED_SIZE, 0); |
| 52091 | | -#endif |
| 52092 | | - } |
| 52093 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 52094 | | - else{ |
| 52095 | | - int lk; |
| 52096 | | - sqlite3_randomness(sizeof(lk), &lk); |
| 52097 | | - pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1)); |
| 52098 | | - res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS&mask, |
| 52099 | | - SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); |
| 52100 | | - } |
| 52101 | | -#endif |
| 51067 | + res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0, |
| 51068 | + SHARED_SIZE, 0); |
| 52102 | 51069 | if( res == 0 ){ |
| 52103 | 51070 | pFile->lastErrno = osGetLastError(); |
| 52104 | 51071 | /* No need to log a failure to lock */ |
| 52105 | 51072 | } |
| 52106 | 51073 | OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res)); |
| | @@ -52112,18 +51079,11 @@ |
| 52112 | 51079 | */ |
| 52113 | 51080 | static int winUnlockReadLock(winFile *pFile){ |
| 52114 | 51081 | int res; |
| 52115 | 51082 | DWORD lastErrno; |
| 52116 | 51083 | OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype)); |
| 52117 | | - if( osIsNT() ){ |
| 52118 | | - res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); |
| 52119 | | - } |
| 52120 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 52121 | | - else{ |
| 52122 | | - res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); |
| 52123 | | - } |
| 52124 | | -#endif |
| 51084 | + res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); |
| 52125 | 51085 | if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){ |
| 52126 | 51086 | pFile->lastErrno = lastErrno; |
| 52127 | 51087 | winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno, |
| 52128 | 51088 | "winUnlockReadLock", pFile->zPath); |
| 52129 | 51089 | } |
| | @@ -52673,82 +51633,75 @@ |
| 52673 | 51633 | ** happen when the file path >32k, in which case winUtf8ToUnicode() |
| 52674 | 51634 | ** will fail too. |
| 52675 | 51635 | */ |
| 52676 | 51636 | static void *winConvertFromUtf8Filename(const char *zFilename){ |
| 52677 | 51637 | void *zConverted = 0; |
| 52678 | | - if( osIsNT() ){ |
| 52679 | 51638 | #ifdef __CYGWIN__ |
| 52680 | | - int nChar; |
| 52681 | | - LPWSTR zWideFilename; |
| 52682 | | - |
| 52683 | | - if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename) |
| 52684 | | - && winIsDirSep(zFilename[2])) ){ |
| 52685 | | - i64 nByte; |
| 52686 | | - int convertflag = CCP_POSIX_TO_WIN_W; |
| 52687 | | - if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE; |
| 52688 | | - nByte = (i64)osCygwin_conv_path(convertflag, |
| 52689 | | - zFilename, 0, 0); |
| 52690 | | - if( nByte>0 ){ |
| 52691 | | - zConverted = sqlite3MallocZero(12+(u64)nByte); |
| 52692 | | - if ( zConverted==0 ){ |
| 52693 | | - return zConverted; |
| 52694 | | - } |
| 52695 | | - zWideFilename = zConverted; |
| 52696 | | - /* Filenames should be prefixed, except when converted |
| 52697 | | - * full path already starts with "\\?\". */ |
| 52698 | | - if( osCygwin_conv_path(convertflag, zFilename, |
| 52699 | | - zWideFilename+4, nByte)==0 ){ |
| 52700 | | - if( (convertflag&CCP_RELATIVE) ){ |
| 52701 | | - memmove(zWideFilename, zWideFilename+4, nByte); |
| 52702 | | - }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){ |
| 52703 | | - memcpy(zWideFilename, L"\\\\?\\", 8); |
| 52704 | | - }else if( zWideFilename[6]!='?' ){ |
| 52705 | | - memmove(zWideFilename+6, zWideFilename+4, nByte); |
| 52706 | | - memcpy(zWideFilename, L"\\\\?\\UNC", 14); |
| 52707 | | - }else{ |
| 52708 | | - memmove(zWideFilename, zWideFilename+4, nByte); |
| 52709 | | - } |
| 52710 | | - return zConverted; |
| 52711 | | - } |
| 52712 | | - sqlite3_free(zConverted); |
| 52713 | | - } |
| 52714 | | - } |
| 52715 | | - nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0); |
| 52716 | | - if( nChar==0 ){ |
| 52717 | | - return 0; |
| 52718 | | - } |
| 52719 | | - zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 ); |
| 52720 | | - if( zWideFilename==0 ){ |
| 52721 | | - return 0; |
| 52722 | | - } |
| 52723 | | - nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, |
| 52724 | | - zWideFilename, nChar); |
| 52725 | | - if( nChar==0 ){ |
| 52726 | | - sqlite3_free(zWideFilename); |
| 52727 | | - zWideFilename = 0; |
| 52728 | | - }else if( nChar>MAX_PATH |
| 52729 | | - && winIsDriveLetterAndColon(zFilename) |
| 52730 | | - && winIsDirSep(zFilename[2]) ){ |
| 52731 | | - memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR)); |
| 52732 | | - zWideFilename[2] = '\\'; |
| 52733 | | - memcpy(zWideFilename, L"\\\\?\\", 8); |
| 52734 | | - }else if( nChar>MAX_PATH |
| 52735 | | - && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1]) |
| 52736 | | - && zFilename[2] != '?' ){ |
| 52737 | | - memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR)); |
| 52738 | | - memcpy(zWideFilename, L"\\\\?\\UNC", 14); |
| 52739 | | - } |
| 52740 | | - zConverted = zWideFilename; |
| 52741 | | -#else |
| 52742 | | - zConverted = winUtf8ToUnicode(zFilename); |
| 52743 | | -#endif /* __CYGWIN__ */ |
| 52744 | | - } |
| 52745 | | -#if defined(SQLITE_WIN32_HAS_ANSI) && defined(_WIN32) |
| 52746 | | - else{ |
| 52747 | | - zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI()); |
| 52748 | | - } |
| 52749 | | -#endif |
| 51639 | + int nChar; |
| 51640 | + LPWSTR zWideFilename; |
| 51641 | + |
| 51642 | + if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename) |
| 51643 | + && winIsDirSep(zFilename[2])) ){ |
| 51644 | + i64 nByte; |
| 51645 | + int convertflag = CCP_POSIX_TO_WIN_W; |
| 51646 | + if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE; |
| 51647 | + nByte = (i64)osCygwin_conv_path(convertflag, |
| 51648 | + zFilename, 0, 0); |
| 51649 | + if( nByte>0 ){ |
| 51650 | + zConverted = sqlite3MallocZero(12+(u64)nByte); |
| 51651 | + if ( zConverted==0 ){ |
| 51652 | + return zConverted; |
| 51653 | + } |
| 51654 | + zWideFilename = zConverted; |
| 51655 | + /* Filenames should be prefixed, except when converted |
| 51656 | + * full path already starts with "\\?\". */ |
| 51657 | + if( osCygwin_conv_path(convertflag, zFilename, |
| 51658 | + zWideFilename+4, nByte)==0 ){ |
| 51659 | + if( (convertflag&CCP_RELATIVE) ){ |
| 51660 | + memmove(zWideFilename, zWideFilename+4, nByte); |
| 51661 | + }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){ |
| 51662 | + memcpy(zWideFilename, L"\\\\?\\", 8); |
| 51663 | + }else if( zWideFilename[6]!='?' ){ |
| 51664 | + memmove(zWideFilename+6, zWideFilename+4, nByte); |
| 51665 | + memcpy(zWideFilename, L"\\\\?\\UNC", 14); |
| 51666 | + }else{ |
| 51667 | + memmove(zWideFilename, zWideFilename+4, nByte); |
| 51668 | + } |
| 51669 | + return zConverted; |
| 51670 | + } |
| 51671 | + sqlite3_free(zConverted); |
| 51672 | + } |
| 51673 | + } |
| 51674 | + nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0); |
| 51675 | + if( nChar==0 ){ |
| 51676 | + return 0; |
| 51677 | + } |
| 51678 | + zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 ); |
| 51679 | + if( zWideFilename==0 ){ |
| 51680 | + return 0; |
| 51681 | + } |
| 51682 | + nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, |
| 51683 | + zWideFilename, nChar); |
| 51684 | + if( nChar==0 ){ |
| 51685 | + sqlite3_free(zWideFilename); |
| 51686 | + zWideFilename = 0; |
| 51687 | + }else if( nChar>MAX_PATH |
| 51688 | + && winIsDriveLetterAndColon(zFilename) |
| 51689 | + && winIsDirSep(zFilename[2]) ){ |
| 51690 | + memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR)); |
| 51691 | + zWideFilename[2] = '\\'; |
| 51692 | + memcpy(zWideFilename, L"\\\\?\\", 8); |
| 51693 | + }else if( nChar>MAX_PATH |
| 51694 | + && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1]) |
| 51695 | + && zFilename[2] != '?' ){ |
| 51696 | + memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR)); |
| 51697 | + memcpy(zWideFilename, L"\\\\?\\UNC", 14); |
| 51698 | + } |
| 51699 | + zConverted = zWideFilename; |
| 51700 | +#else /* if !defined(__CYGWIN__) */ |
| 51701 | + zConverted = winUtf8ToUnicode(zFilename); |
| 51702 | +#endif /* __CYGWIN__ */ |
| 52750 | 51703 | /* caller will handle out of memory */ |
| 52751 | 51704 | return zConverted; |
| 52752 | 51705 | } |
| 52753 | 51706 | |
| 52754 | 51707 | #ifndef SQLITE_OMIT_WAL |
| | @@ -52991,33 +51944,18 @@ |
| 52991 | 51944 | } |
| 52992 | 51945 | |
| 52993 | 51946 | /* TODO: platforms. |
| 52994 | 51947 | ** TODO: retry-on-ioerr. |
| 52995 | 51948 | */ |
| 52996 | | - if( osIsNT() ){ |
| 52997 | | - h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */ |
| 52998 | | - (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */ |
| 52999 | | - FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */ |
| 53000 | | - NULL, /* lpSecurityAttributes */ |
| 53001 | | - OPEN_ALWAYS, /* dwCreationDisposition */ |
| 53002 | | - FILE_ATTRIBUTE_NORMAL|flag_overlapped, |
| 53003 | | - NULL |
| 53004 | | - ); |
| 53005 | | - }else{ |
| 53006 | | - /* Due to pre-processor directives earlier in this file, |
| 53007 | | - ** SQLITE_WIN32_HAS_ANSI is always defined if osIsNT() is false. */ |
| 53008 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 53009 | | - h = osCreateFileA((LPCSTR)zConverted, |
| 53010 | | - (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */ |
| 53011 | | - FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */ |
| 53012 | | - NULL, /* lpSecurityAttributes */ |
| 53013 | | - OPEN_ALWAYS, /* dwCreationDisposition */ |
| 53014 | | - FILE_ATTRIBUTE_NORMAL|flag_overlapped, |
| 53015 | | - NULL |
| 53016 | | - ); |
| 53017 | | -#endif |
| 53018 | | - } |
| 51949 | + h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */ |
| 51950 | + (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */ |
| 51951 | + FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */ |
| 51952 | + NULL, /* lpSecurityAttributes */ |
| 51953 | + OPEN_ALWAYS, /* dwCreationDisposition */ |
| 51954 | + FILE_ATTRIBUTE_NORMAL|flag_overlapped, |
| 51955 | + NULL |
| 51956 | + ); |
| 53019 | 51957 | |
| 53020 | 51958 | if( h==INVALID_HANDLE_VALUE ){ |
| 53021 | 51959 | if( bReadonly==0 ){ |
| 53022 | 51960 | bReadonly = 1; |
| 53023 | 51961 | rc = winHandleOpen(zUtf8, &bReadonly, &h); |
| | @@ -53467,16 +52405,11 @@ |
| 53467 | 52405 | |
| 53468 | 52406 | while( pShmNode->nRegion<=iRegion ){ |
| 53469 | 52407 | HANDLE hMap = NULL; /* file-mapping handle */ |
| 53470 | 52408 | void *pMap = 0; /* Mapped memory region */ |
| 53471 | 52409 | |
| 53472 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 53473 | 52410 | hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL); |
| 53474 | | -#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA |
| 53475 | | - hMap = osCreateFileMappingA(hShared, NULL, protect, 0, nByte, NULL); |
| 53476 | | -#endif |
| 53477 | | - |
| 53478 | 52411 | OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n", |
| 53479 | 52412 | osGetCurrentProcessId(), pShmNode->nRegion, nByte, |
| 53480 | 52413 | hMap ? "ok" : "failed")); |
| 53481 | 52414 | if( hMap ){ |
| 53482 | 52415 | int iOffset = pShmNode->nRegion*szRegion; |
| | @@ -53614,19 +52547,13 @@ |
| 53614 | 52547 | if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ |
| 53615 | 52548 | protect = PAGE_READWRITE; |
| 53616 | 52549 | flags |= FILE_MAP_WRITE; |
| 53617 | 52550 | } |
| 53618 | 52551 | #endif |
| 53619 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 53620 | 52552 | pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, |
| 53621 | 52553 | (DWORD)((nMap>>32) & 0xffffffff), |
| 53622 | 52554 | (DWORD)(nMap & 0xffffffff), NULL); |
| 53623 | | -#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA |
| 53624 | | - pFd->hMap = osCreateFileMappingA(pFd->h, NULL, protect, |
| 53625 | | - (DWORD)((nMap>>32) & 0xffffffff), |
| 53626 | | - (DWORD)(nMap & 0xffffffff), NULL); |
| 53627 | | -#endif |
| 53628 | 52555 | if( pFd->hMap==NULL ){ |
| 53629 | 52556 | pFd->lastErrno = osGetLastError(); |
| 53630 | 52557 | rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, |
| 53631 | 52558 | "winMapfile1", pFd->zPath); |
| 53632 | 52559 | /* Log the error, but continue normal operation using xRead/xWrite */ |
| | @@ -53969,11 +52896,11 @@ |
| 53969 | 52896 | } |
| 53970 | 52897 | } |
| 53971 | 52898 | } |
| 53972 | 52899 | #endif |
| 53973 | 52900 | |
| 53974 | | - else if( osIsNT() ){ |
| 52901 | + else{ |
| 53975 | 52902 | char *zMulti; |
| 53976 | 52903 | LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) ); |
| 53977 | 52904 | if( !zWidePath ){ |
| 53978 | 52905 | sqlite3_free(zBuf); |
| 53979 | 52906 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| | @@ -53996,36 +52923,10 @@ |
| 53996 | 52923 | sqlite3_free(zBuf); |
| 53997 | 52924 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 53998 | 52925 | return SQLITE_IOERR_NOMEM_BKPT; |
| 53999 | 52926 | } |
| 54000 | 52927 | } |
| 54001 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 54002 | | - else{ |
| 54003 | | - char *zUtf8; |
| 54004 | | - char *zMbcsPath = sqlite3MallocZero( nMax ); |
| 54005 | | - if( !zMbcsPath ){ |
| 54006 | | - sqlite3_free(zBuf); |
| 54007 | | - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 54008 | | - return SQLITE_IOERR_NOMEM_BKPT; |
| 54009 | | - } |
| 54010 | | - if( osGetTempPathA(nMax, zMbcsPath)==0 ){ |
| 54011 | | - sqlite3_free(zBuf); |
| 54012 | | - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); |
| 54013 | | - return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), |
| 54014 | | - "winGetTempname3", 0); |
| 54015 | | - } |
| 54016 | | - zUtf8 = winMbcsToUtf8(zMbcsPath, osAreFileApisANSI()); |
| 54017 | | - if( zUtf8 ){ |
| 54018 | | - sqlite3_snprintf(nMax, zBuf, "%s", zUtf8); |
| 54019 | | - sqlite3_free(zUtf8); |
| 54020 | | - }else{ |
| 54021 | | - sqlite3_free(zBuf); |
| 54022 | | - OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 54023 | | - return SQLITE_IOERR_NOMEM_BKPT; |
| 54024 | | - } |
| 54025 | | - } |
| 54026 | | -#endif /* SQLITE_WIN32_HAS_ANSI */ |
| 54027 | 52928 | |
| 54028 | 52929 | /* |
| 54029 | 52930 | ** Check to make sure the temporary directory ends with an appropriate |
| 54030 | 52931 | ** separator. If it does not and there is not enough space left to add |
| 54031 | 52932 | ** one, fail. |
| | @@ -54079,27 +52980,20 @@ |
| 54079 | 52980 | */ |
| 54080 | 52981 | static int winIsDir(const void *zConverted){ |
| 54081 | 52982 | DWORD attr; |
| 54082 | 52983 | int rc = 0; |
| 54083 | 52984 | DWORD lastErrno; |
| 54084 | | - |
| 54085 | | - if( osIsNT() ){ |
| 54086 | | - int cnt = 0; |
| 54087 | | - WIN32_FILE_ATTRIBUTE_DATA sAttrData; |
| 54088 | | - memset(&sAttrData, 0, sizeof(sAttrData)); |
| 54089 | | - while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted, |
| 54090 | | - GetFileExInfoStandard, |
| 54091 | | - &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){} |
| 54092 | | - if( !rc ){ |
| 54093 | | - return 0; /* Invalid name? */ |
| 54094 | | - } |
| 54095 | | - attr = sAttrData.dwFileAttributes; |
| 54096 | | -#if SQLITE_OS_WINCE==0 && defined(SQLITE_WIN32_HAS_ANSI) |
| 54097 | | - }else{ |
| 54098 | | - attr = osGetFileAttributesA((char*)zConverted); |
| 54099 | | -#endif |
| 54100 | | - } |
| 52985 | + int cnt = 0; |
| 52986 | + WIN32_FILE_ATTRIBUTE_DATA sAttrData; |
| 52987 | + memset(&sAttrData, 0, sizeof(sAttrData)); |
| 52988 | + while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted, |
| 52989 | + GetFileExInfoStandard, |
| 52990 | + &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){} |
| 52991 | + if( !rc ){ |
| 52992 | + return 0; /* Invalid name? */ |
| 52993 | + } |
| 52994 | + attr = sAttrData.dwFileAttributes; |
| 54101 | 52995 | return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY); |
| 54102 | 52996 | } |
| 54103 | 52997 | |
| 54104 | 52998 | /* forward reference */ |
| 54105 | 52999 | static int winAccess( |
| | @@ -54129,13 +53023,10 @@ |
| 54129 | 53023 | DWORD lastErrno = 0; |
| 54130 | 53024 | DWORD dwDesiredAccess; |
| 54131 | 53025 | DWORD dwShareMode; |
| 54132 | 53026 | DWORD dwCreationDisposition; |
| 54133 | 53027 | DWORD dwFlagsAndAttributes = 0; |
| 54134 | | -#if SQLITE_OS_WINCE |
| 54135 | | - int isTemp = 0; |
| 54136 | | -#endif |
| 54137 | 53028 | winVfsAppData *pAppData; |
| 54138 | 53029 | winFile *pFile = (winFile*)id; |
| 54139 | 53030 | void *zConverted; /* Filename in OS encoding */ |
| 54140 | 53031 | const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */ |
| 54141 | 53032 | int cnt = 0; |
| | @@ -54145,11 +53036,11 @@ |
| 54145 | 53036 | ** a temporary file. Use this buffer to store the file name in. |
| 54146 | 53037 | */ |
| 54147 | 53038 | char *zTmpname = 0; /* For temporary filename, if necessary. */ |
| 54148 | 53039 | |
| 54149 | 53040 | int rc = SQLITE_OK; /* Function Return Code */ |
| 54150 | | -#if !defined(NDEBUG) || SQLITE_OS_WINCE |
| 53041 | +#if !defined(NDEBUG) |
| 54151 | 53042 | int eType = flags&0x0FFF00; /* Type of file to open */ |
| 54152 | 53043 | #endif |
| 54153 | 53044 | |
| 54154 | 53045 | int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); |
| 54155 | 53046 | int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE); |
| | @@ -54260,65 +53151,32 @@ |
| 54260 | 53151 | }else{ |
| 54261 | 53152 | dwShareMode = 0; |
| 54262 | 53153 | } |
| 54263 | 53154 | |
| 54264 | 53155 | if( isDelete ){ |
| 54265 | | -#if SQLITE_OS_WINCE |
| 54266 | | - dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN; |
| 54267 | | - isTemp = 1; |
| 54268 | | -#else |
| 54269 | 53156 | dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY |
| 54270 | 53157 | | FILE_ATTRIBUTE_HIDDEN |
| 54271 | 53158 | | FILE_FLAG_DELETE_ON_CLOSE; |
| 54272 | | -#endif |
| 54273 | 53159 | }else{ |
| 54274 | 53160 | dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL; |
| 54275 | 53161 | } |
| 54276 | | - /* Reports from the internet are that performance is always |
| 54277 | | - ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */ |
| 54278 | | -#if SQLITE_OS_WINCE |
| 54279 | | - dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; |
| 54280 | | -#endif |
| 54281 | | - |
| 54282 | | - if( osIsNT() ){ |
| 54283 | | - do{ |
| 54284 | | - h = osCreateFileW((LPCWSTR)zConverted, |
| 54285 | | - dwDesiredAccess, |
| 54286 | | - dwShareMode, NULL, |
| 54287 | | - dwCreationDisposition, |
| 54288 | | - dwFlagsAndAttributes, |
| 54289 | | - NULL); |
| 54290 | | - if( h!=INVALID_HANDLE_VALUE ) break; |
| 54291 | | - if( isReadWrite ){ |
| 54292 | | - int rc2; |
| 54293 | | - sqlite3BeginBenignMalloc(); |
| 54294 | | - rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO); |
| 54295 | | - sqlite3EndBenignMalloc(); |
| 54296 | | - if( rc2==SQLITE_OK && isRO ) break; |
| 54297 | | - } |
| 54298 | | - }while( winRetryIoerr(&cnt, &lastErrno) ); |
| 54299 | | - } |
| 54300 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 54301 | | - else{ |
| 54302 | | - do{ |
| 54303 | | - h = osCreateFileA((LPCSTR)zConverted, |
| 54304 | | - dwDesiredAccess, |
| 54305 | | - dwShareMode, NULL, |
| 54306 | | - dwCreationDisposition, |
| 54307 | | - dwFlagsAndAttributes, |
| 54308 | | - NULL); |
| 54309 | | - if( h!=INVALID_HANDLE_VALUE ) break; |
| 54310 | | - if( isReadWrite ){ |
| 54311 | | - int rc2; |
| 54312 | | - sqlite3BeginBenignMalloc(); |
| 54313 | | - rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO); |
| 54314 | | - sqlite3EndBenignMalloc(); |
| 54315 | | - if( rc2==SQLITE_OK && isRO ) break; |
| 54316 | | - } |
| 54317 | | - }while( winRetryIoerr(&cnt, &lastErrno) ); |
| 54318 | | - } |
| 54319 | | -#endif |
| 53162 | + do{ |
| 53163 | + h = osCreateFileW((LPCWSTR)zConverted, |
| 53164 | + dwDesiredAccess, |
| 53165 | + dwShareMode, NULL, |
| 53166 | + dwCreationDisposition, |
| 53167 | + dwFlagsAndAttributes, |
| 53168 | + NULL); |
| 53169 | + if( h!=INVALID_HANDLE_VALUE ) break; |
| 53170 | + if( isReadWrite ){ |
| 53171 | + int rc2; |
| 53172 | + sqlite3BeginBenignMalloc(); |
| 53173 | + rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO); |
| 53174 | + sqlite3EndBenignMalloc(); |
| 53175 | + if( rc2==SQLITE_OK && isRO ) break; |
| 53176 | + } |
| 53177 | + }while( winRetryIoerr(&cnt, &lastErrno) ); |
| 54320 | 53178 | winLogIoerr(cnt, __LINE__); |
| 54321 | 53179 | |
| 54322 | 53180 | OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name, |
| 54323 | 53181 | dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); |
| 54324 | 53182 | |
| | @@ -54349,31 +53207,11 @@ |
| 54349 | 53207 | "rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ? |
| 54350 | 53208 | *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); |
| 54351 | 53209 | |
| 54352 | 53210 | pAppData = (winVfsAppData*)pVfs->pAppData; |
| 54353 | 53211 | |
| 54354 | | -#if SQLITE_OS_WINCE |
| 54355 | | - { |
| 54356 | | - if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB |
| 54357 | | - && ((pAppData==NULL) || !pAppData->bNoLock) |
| 54358 | | - && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK |
| 54359 | | - ){ |
| 54360 | | - osCloseHandle(h); |
| 54361 | | - sqlite3_free(zConverted); |
| 54362 | | - sqlite3_free(zTmpname); |
| 54363 | | - OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc))); |
| 54364 | | - return rc; |
| 54365 | | - } |
| 54366 | | - } |
| 54367 | | - if( isTemp ){ |
| 54368 | | - pFile->zDeleteOnClose = zConverted; |
| 54369 | | - }else |
| 54370 | | -#endif |
| 54371 | | - { |
| 54372 | | - sqlite3_free(zConverted); |
| 54373 | | - } |
| 54374 | | - |
| 53212 | + sqlite3_free(zConverted); |
| 54375 | 53213 | sqlite3_free(zTmpname); |
| 54376 | 53214 | id->pMethods = pAppData ? pAppData->pMethod : &winIoMethod; |
| 54377 | 53215 | pFile->pVfs = pVfs; |
| 54378 | 53216 | pFile->h = h; |
| 54379 | 53217 | if( isReadonly ){ |
| | @@ -54428,66 +53266,35 @@ |
| 54428 | 53266 | zConverted = winConvertFromUtf8Filename(zFilename); |
| 54429 | 53267 | if( zConverted==0 ){ |
| 54430 | 53268 | OSTRACE(("DELETE name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename)); |
| 54431 | 53269 | return SQLITE_IOERR_NOMEM_BKPT; |
| 54432 | 53270 | } |
| 54433 | | - if( osIsNT() ){ |
| 54434 | | - do { |
| 54435 | | - attr = osGetFileAttributesW(zConverted); |
| 54436 | | - if ( attr==INVALID_FILE_ATTRIBUTES ){ |
| 54437 | | - lastErrno = osGetLastError(); |
| 54438 | | - if( lastErrno==ERROR_FILE_NOT_FOUND |
| 54439 | | - || lastErrno==ERROR_PATH_NOT_FOUND ){ |
| 54440 | | - rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */ |
| 54441 | | - }else{ |
| 54442 | | - rc = SQLITE_ERROR; |
| 54443 | | - } |
| 54444 | | - break; |
| 54445 | | - } |
| 54446 | | - if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ |
| 54447 | | - rc = SQLITE_ERROR; /* Files only. */ |
| 54448 | | - break; |
| 54449 | | - } |
| 54450 | | - if ( osDeleteFileW(zConverted) ){ |
| 54451 | | - rc = SQLITE_OK; /* Deleted OK. */ |
| 54452 | | - break; |
| 54453 | | - } |
| 54454 | | - if ( !winRetryIoerr(&cnt, &lastErrno) ){ |
| 54455 | | - rc = SQLITE_ERROR; /* No more retries. */ |
| 54456 | | - break; |
| 54457 | | - } |
| 54458 | | - } while(1); |
| 54459 | | - } |
| 54460 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 54461 | | - else{ |
| 54462 | | - do { |
| 54463 | | - attr = osGetFileAttributesA(zConverted); |
| 54464 | | - if ( attr==INVALID_FILE_ATTRIBUTES ){ |
| 54465 | | - lastErrno = osGetLastError(); |
| 54466 | | - if( lastErrno==ERROR_FILE_NOT_FOUND |
| 54467 | | - || lastErrno==ERROR_PATH_NOT_FOUND ){ |
| 54468 | | - rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */ |
| 54469 | | - }else{ |
| 54470 | | - rc = SQLITE_ERROR; |
| 54471 | | - } |
| 54472 | | - break; |
| 54473 | | - } |
| 54474 | | - if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ |
| 54475 | | - rc = SQLITE_ERROR; /* Files only. */ |
| 54476 | | - break; |
| 54477 | | - } |
| 54478 | | - if ( osDeleteFileA(zConverted) ){ |
| 54479 | | - rc = SQLITE_OK; /* Deleted OK. */ |
| 54480 | | - break; |
| 54481 | | - } |
| 54482 | | - if ( !winRetryIoerr(&cnt, &lastErrno) ){ |
| 54483 | | - rc = SQLITE_ERROR; /* No more retries. */ |
| 54484 | | - break; |
| 54485 | | - } |
| 54486 | | - } while(1); |
| 54487 | | - } |
| 54488 | | -#endif |
| 53271 | + do { |
| 53272 | + attr = osGetFileAttributesW(zConverted); |
| 53273 | + if ( attr==INVALID_FILE_ATTRIBUTES ){ |
| 53274 | + lastErrno = osGetLastError(); |
| 53275 | + if( lastErrno==ERROR_FILE_NOT_FOUND |
| 53276 | + || lastErrno==ERROR_PATH_NOT_FOUND ){ |
| 53277 | + rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */ |
| 53278 | + }else{ |
| 53279 | + rc = SQLITE_ERROR; |
| 53280 | + } |
| 53281 | + break; |
| 53282 | + } |
| 53283 | + if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ |
| 53284 | + rc = SQLITE_ERROR; /* Files only. */ |
| 53285 | + break; |
| 53286 | + } |
| 53287 | + if ( osDeleteFileW(zConverted) ){ |
| 53288 | + rc = SQLITE_OK; /* Deleted OK. */ |
| 53289 | + break; |
| 53290 | + } |
| 53291 | + if ( !winRetryIoerr(&cnt, &lastErrno) ){ |
| 53292 | + rc = SQLITE_ERROR; /* No more retries. */ |
| 53293 | + break; |
| 53294 | + } |
| 53295 | + } while(1); |
| 54489 | 53296 | if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){ |
| 54490 | 53297 | rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename); |
| 54491 | 53298 | }else{ |
| 54492 | 53299 | winLogIoerr(cnt, __LINE__); |
| 54493 | 53300 | } |
| | @@ -54505,13 +53312,15 @@ |
| 54505 | 53312 | int flags, /* Type of test to make on this file */ |
| 54506 | 53313 | int *pResOut /* OUT: Result */ |
| 54507 | 53314 | ){ |
| 54508 | 53315 | DWORD attr; |
| 54509 | 53316 | int rc = 0; |
| 53317 | + int cnt = 0; |
| 54510 | 53318 | DWORD lastErrno = 0; |
| 54511 | 53319 | void *zConverted; |
| 54512 | 53320 | int noRetry = 0; /* Do not use winRetryIoerr() */ |
| 53321 | + WIN32_FILE_ATTRIBUTE_DATA sAttrData; |
| 54513 | 53322 | UNUSED_PARAMETER(pVfs); |
| 54514 | 53323 | |
| 54515 | 53324 | if( (flags & NORETRY)!=0 ){ |
| 54516 | 53325 | noRetry = 1; |
| 54517 | 53326 | flags &= ~NORETRY; |
| | @@ -54531,48 +53340,39 @@ |
| 54531 | 53340 | zConverted = winConvertFromUtf8Filename(zFilename); |
| 54532 | 53341 | if( zConverted==0 ){ |
| 54533 | 53342 | OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename)); |
| 54534 | 53343 | return SQLITE_IOERR_NOMEM_BKPT; |
| 54535 | 53344 | } |
| 54536 | | - if( osIsNT() ){ |
| 54537 | | - int cnt = 0; |
| 54538 | | - WIN32_FILE_ATTRIBUTE_DATA sAttrData; |
| 54539 | | - memset(&sAttrData, 0, sizeof(sAttrData)); |
| 54540 | | - while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted, |
| 54541 | | - GetFileExInfoStandard, |
| 54542 | | - &sAttrData)) |
| 54543 | | - && !noRetry |
| 54544 | | - && winRetryIoerr(&cnt, &lastErrno) |
| 54545 | | - ){ /* Loop until true */} |
| 54546 | | - if( rc ){ |
| 54547 | | - /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file |
| 54548 | | - ** as if it does not exist. |
| 54549 | | - */ |
| 54550 | | - if( flags==SQLITE_ACCESS_EXISTS |
| 54551 | | - && sAttrData.nFileSizeHigh==0 |
| 54552 | | - && sAttrData.nFileSizeLow==0 ){ |
| 54553 | | - attr = INVALID_FILE_ATTRIBUTES; |
| 54554 | | - }else{ |
| 54555 | | - attr = sAttrData.dwFileAttributes; |
| 54556 | | - } |
| 54557 | | - }else{ |
| 54558 | | - if( noRetry ) lastErrno = osGetLastError(); |
| 54559 | | - winLogIoerr(cnt, __LINE__); |
| 54560 | | - if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){ |
| 54561 | | - sqlite3_free(zConverted); |
| 54562 | | - return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", |
| 54563 | | - zFilename); |
| 54564 | | - }else{ |
| 54565 | | - attr = INVALID_FILE_ATTRIBUTES; |
| 54566 | | - } |
| 54567 | | - } |
| 54568 | | - } |
| 54569 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 54570 | | - else{ |
| 54571 | | - attr = osGetFileAttributesA((char*)zConverted); |
| 54572 | | - } |
| 54573 | | -#endif |
| 53345 | + memset(&sAttrData, 0, sizeof(sAttrData)); |
| 53346 | + while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted, |
| 53347 | + GetFileExInfoStandard, |
| 53348 | + &sAttrData)) |
| 53349 | + && !noRetry |
| 53350 | + && winRetryIoerr(&cnt, &lastErrno) |
| 53351 | + ){ /* Loop until true */} |
| 53352 | + if( rc ){ |
| 53353 | + /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file |
| 53354 | + ** as if it does not exist. |
| 53355 | + */ |
| 53356 | + if( flags==SQLITE_ACCESS_EXISTS |
| 53357 | + && sAttrData.nFileSizeHigh==0 |
| 53358 | + && sAttrData.nFileSizeLow==0 ){ |
| 53359 | + attr = INVALID_FILE_ATTRIBUTES; |
| 53360 | + }else{ |
| 53361 | + attr = sAttrData.dwFileAttributes; |
| 53362 | + } |
| 53363 | + }else{ |
| 53364 | + if( noRetry ) lastErrno = osGetLastError(); |
| 53365 | + winLogIoerr(cnt, __LINE__); |
| 53366 | + if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){ |
| 53367 | + sqlite3_free(zConverted); |
| 53368 | + return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", |
| 53369 | + zFilename); |
| 53370 | + }else{ |
| 53371 | + attr = INVALID_FILE_ATTRIBUTES; |
| 53372 | + } |
| 53373 | + } |
| 54574 | 53374 | sqlite3_free(zConverted); |
| 54575 | 53375 | switch( flags ){ |
| 54576 | 53376 | case SQLITE_ACCESS_READ: |
| 54577 | 53377 | case SQLITE_ACCESS_EXISTS: |
| 54578 | 53378 | rc = attr!=INVALID_FILE_ATTRIBUTES; |
| | @@ -54722,15 +53522,13 @@ |
| 54722 | 53522 | sqlite3_vfs *pVfs, /* Pointer to vfs object */ |
| 54723 | 53523 | const char *zRelative, /* Possibly relative input path */ |
| 54724 | 53524 | int nFull, /* Size of output buffer in bytes */ |
| 54725 | 53525 | char *zFull /* Output buffer */ |
| 54726 | 53526 | ){ |
| 54727 | | -#if !SQLITE_OS_WINCE |
| 54728 | 53527 | int nByte; |
| 54729 | 53528 | void *zConverted; |
| 54730 | 53529 | char *zOut; |
| 54731 | | -#endif |
| 54732 | 53530 | |
| 54733 | 53531 | /* If this path name begins with "/X:" or "\\?\", where "X" is any |
| 54734 | 53532 | ** alphabetic character, discard the initial "/" from the pathname. |
| 54735 | 53533 | */ |
| 54736 | 53534 | if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1) |
| | @@ -54743,26 +53541,27 @@ |
| 54743 | 53541 | #ifdef __CYGWIN__ |
| 54744 | 53542 | if( osGetcwd ){ |
| 54745 | 53543 | zFull[nFull-1] = '\0'; |
| 54746 | 53544 | if( !winIsDriveLetterAndColon(zRelative) || !winIsDirSep(zRelative[2]) ){ |
| 54747 | 53545 | int rc = SQLITE_OK; |
| 54748 | | - int nLink = 1; /* Number of symbolic links followed so far */ |
| 54749 | | - const char *zIn = zRelative; /* Input path for each iteration of loop */ |
| 53546 | + int nLink = 1; /* Number of symbolic links followed so far */ |
| 53547 | + const char *zIn = zRelative; /* Input path for each iteration of loop */ |
| 54750 | 53548 | char *zDel = 0; |
| 54751 | 53549 | struct stat buf; |
| 54752 | 53550 | |
| 54753 | 53551 | UNUSED_PARAMETER(pVfs); |
| 54754 | 53552 | |
| 54755 | 53553 | do { |
| 54756 | | - /* Call lstat() on path zIn. Set bLink to true if the path is a symbolic |
| 54757 | | - ** link, or false otherwise. */ |
| 53554 | + /* Call lstat() on path zIn. Set bLink to true if the path |
| 53555 | + ** is a symbolic link, or false otherwise. */ |
| 54758 | 53556 | int bLink = 0; |
| 54759 | 53557 | if( osLstat && osReadlink ) { |
| 54760 | 53558 | if( osLstat(zIn, &buf)!=0 ){ |
| 54761 | 53559 | int myErrno = osErrno; |
| 54762 | 53560 | if( myErrno!=ENOENT ){ |
| 54763 | | - rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)myErrno, "lstat", zIn); |
| 53561 | + rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)myErrno, |
| 53562 | + "lstat", zIn); |
| 54764 | 53563 | } |
| 54765 | 53564 | }else{ |
| 54766 | 53565 | bLink = ((buf.st_mode & 0170000) == 0120000); |
| 54767 | 53566 | } |
| 54768 | 53567 | |
| | @@ -54775,11 +53574,12 @@ |
| 54775 | 53574 | } |
| 54776 | 53575 | |
| 54777 | 53576 | if( rc==SQLITE_OK ){ |
| 54778 | 53577 | nByte = osReadlink(zIn, zDel, nFull-1); |
| 54779 | 53578 | if( nByte ==(DWORD)-1 ){ |
| 54780 | | - rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "readlink", zIn); |
| 53579 | + rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, |
| 53580 | + "readlink", zIn); |
| 54781 | 53581 | }else{ |
| 54782 | 53582 | if( zDel[0]!='/' ){ |
| 54783 | 53583 | int n; |
| 54784 | 53584 | for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--); |
| 54785 | 53585 | if( nByte+n+1>nFull ){ |
| | @@ -54811,30 +53611,10 @@ |
| 54811 | 53611 | return rc; |
| 54812 | 53612 | } |
| 54813 | 53613 | } |
| 54814 | 53614 | #endif /* __CYGWIN__ */ |
| 54815 | 53615 | |
| 54816 | | -#if SQLITE_OS_WINCE && defined(_WIN32) |
| 54817 | | - SimulateIOError( return SQLITE_ERROR ); |
| 54818 | | - /* WinCE has no concept of a relative pathname, or so I am told. */ |
| 54819 | | - /* WinRT has no way to convert a relative path to an absolute one. */ |
| 54820 | | - if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ |
| 54821 | | - /* |
| 54822 | | - ** NOTE: We are dealing with a relative path name and the data |
| 54823 | | - ** directory has been set. Therefore, use it as the basis |
| 54824 | | - ** for converting the relative path name to an absolute |
| 54825 | | - ** one by prepending the data directory and a backslash. |
| 54826 | | - */ |
| 54827 | | - sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", |
| 54828 | | - sqlite3_data_directory, winGetDirSep(), zRelative); |
| 54829 | | - }else{ |
| 54830 | | - sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative); |
| 54831 | | - } |
| 54832 | | - return SQLITE_OK; |
| 54833 | | -#endif |
| 54834 | | - |
| 54835 | | -#if !SQLITE_OS_WINCE |
| 54836 | 53616 | #if defined(_WIN32) |
| 54837 | 53617 | /* It's odd to simulate an io-error here, but really this is just |
| 54838 | 53618 | ** using the io-error infrastructure to test that SQLite handles this |
| 54839 | 53619 | ** function failing. This function could fail if, for example, the |
| 54840 | 53620 | ** current working directory has been unlinked. |
| | @@ -54854,11 +53634,11 @@ |
| 54854 | 53634 | #endif |
| 54855 | 53635 | zConverted = winConvertFromUtf8Filename(zRelative); |
| 54856 | 53636 | if( zConverted==0 ){ |
| 54857 | 53637 | return SQLITE_IOERR_NOMEM_BKPT; |
| 54858 | 53638 | } |
| 54859 | | - if( osIsNT() ){ |
| 53639 | + { |
| 54860 | 53640 | LPWSTR zTemp; |
| 54861 | 53641 | nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0); |
| 54862 | 53642 | if( nByte==0 ){ |
| 54863 | 53643 | sqlite3_free(zConverted); |
| 54864 | 53644 | return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
| | @@ -54879,36 +53659,10 @@ |
| 54879 | 53659 | } |
| 54880 | 53660 | sqlite3_free(zConverted); |
| 54881 | 53661 | zOut = winUnicodeToUtf8(zTemp); |
| 54882 | 53662 | sqlite3_free(zTemp); |
| 54883 | 53663 | } |
| 54884 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 54885 | | - else{ |
| 54886 | | - char *zTemp; |
| 54887 | | - nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0); |
| 54888 | | - if( nByte==0 ){ |
| 54889 | | - sqlite3_free(zConverted); |
| 54890 | | - return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
| 54891 | | - "winFullPathname3", zRelative); |
| 54892 | | - } |
| 54893 | | - zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) ); |
| 54894 | | - if( zTemp==0 ){ |
| 54895 | | - sqlite3_free(zConverted); |
| 54896 | | - return SQLITE_IOERR_NOMEM_BKPT; |
| 54897 | | - } |
| 54898 | | - nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0); |
| 54899 | | - if( nByte==0 ){ |
| 54900 | | - sqlite3_free(zConverted); |
| 54901 | | - sqlite3_free(zTemp); |
| 54902 | | - return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
| 54903 | | - "winFullPathname4", zRelative); |
| 54904 | | - } |
| 54905 | | - sqlite3_free(zConverted); |
| 54906 | | - zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI()); |
| 54907 | | - sqlite3_free(zTemp); |
| 54908 | | - } |
| 54909 | | -#endif |
| 54910 | 53664 | if( zOut ){ |
| 54911 | 53665 | #ifdef __CYGWIN__ |
| 54912 | 53666 | if( memcmp(zOut, "\\\\?\\", 4) ){ |
| 54913 | 53667 | sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut); |
| 54914 | 53668 | }else if( memcmp(zOut+4, "UNC\\", 4) ){ |
| | @@ -54931,11 +53685,10 @@ |
| 54931 | 53685 | sqlite3_free(zOut); |
| 54932 | 53686 | return SQLITE_OK; |
| 54933 | 53687 | }else{ |
| 54934 | 53688 | return SQLITE_IOERR_NOMEM_BKPT; |
| 54935 | 53689 | } |
| 54936 | | -#endif |
| 54937 | 53690 | } |
| 54938 | 53691 | static int winFullPathname( |
| 54939 | 53692 | sqlite3_vfs *pVfs, /* Pointer to vfs object */ |
| 54940 | 53693 | const char *zRelative, /* Possibly relative input path */ |
| 54941 | 53694 | int nFull, /* Size of output buffer in bytes */ |
| | @@ -54961,18 +53714,11 @@ |
| 54961 | 53714 | UNUSED_PARAMETER(pVfs); |
| 54962 | 53715 | if( zConverted==0 ){ |
| 54963 | 53716 | OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0)); |
| 54964 | 53717 | return 0; |
| 54965 | 53718 | } |
| 54966 | | - if( osIsNT() ){ |
| 54967 | | - h = osLoadLibraryW((LPCWSTR)zConverted); |
| 54968 | | - } |
| 54969 | | -#ifdef SQLITE_WIN32_HAS_ANSI |
| 54970 | | - else{ |
| 54971 | | - h = osLoadLibraryA((char*)zConverted); |
| 54972 | | - } |
| 54973 | | -#endif |
| 53719 | + h = osLoadLibraryW((LPCWSTR)zConverted); |
| 54974 | 53720 | OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h)); |
| 54975 | 53721 | sqlite3_free(zConverted); |
| 54976 | 53722 | return (void*)h; |
| 54977 | 53723 | } |
| 54978 | 53724 | static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ |
| | @@ -55053,21 +53799,21 @@ |
| 55053 | 53799 | { |
| 55054 | 53800 | LARGE_INTEGER i; |
| 55055 | 53801 | osQueryPerformanceCounter(&i); |
| 55056 | 53802 | xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER)); |
| 55057 | 53803 | } |
| 55058 | | -#if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID |
| 53804 | +#if SQLITE_WIN32_USE_UUID |
| 55059 | 53805 | { |
| 55060 | 53806 | UUID id; |
| 55061 | 53807 | memset(&id, 0, sizeof(UUID)); |
| 55062 | 53808 | osUuidCreate(&id); |
| 55063 | 53809 | xorMemory(&e, (unsigned char*)&id, sizeof(UUID)); |
| 55064 | 53810 | memset(&id, 0, sizeof(UUID)); |
| 55065 | 53811 | osUuidCreateSequential(&id); |
| 55066 | 53812 | xorMemory(&e, (unsigned char*)&id, sizeof(UUID)); |
| 55067 | 53813 | } |
| 55068 | | -#endif /* !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID */ |
| 53814 | +#endif /* SQLITE_WIN32_USE_UUID */ |
| 55069 | 53815 | return e.nXor>nBuf ? nBuf : e.nXor; |
| 55070 | 53816 | #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */ |
| 55071 | 53817 | } |
| 55072 | 53818 | |
| 55073 | 53819 | |
| | @@ -55111,21 +53857,11 @@ |
| 55111 | 53857 | /* 2^32 - to avoid use of LL and warnings in gcc */ |
| 55112 | 53858 | static const sqlite3_int64 max32BitValue = |
| 55113 | 53859 | (sqlite3_int64)2000000000 + (sqlite3_int64)2000000000 + |
| 55114 | 53860 | (sqlite3_int64)294967296; |
| 55115 | 53861 | |
| 55116 | | -#if SQLITE_OS_WINCE |
| 55117 | | - SYSTEMTIME time; |
| 55118 | | - osGetSystemTime(&time); |
| 55119 | | - /* if SystemTimeToFileTime() fails, it returns zero. */ |
| 55120 | | - if (!osSystemTimeToFileTime(&time,&ft)){ |
| 55121 | | - return SQLITE_ERROR; |
| 55122 | | - } |
| 55123 | | -#else |
| 55124 | 53862 | osGetSystemTimeAsFileTime( &ft ); |
| 55125 | | -#endif |
| 55126 | | - |
| 55127 | 53863 | *piNow = winFiletimeEpoch + |
| 55128 | 53864 | ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) + |
| 55129 | 53865 | (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000; |
| 55130 | 53866 | |
| 55131 | 53867 | #ifdef SQLITE_TEST |
| | @@ -55215,11 +53951,10 @@ |
| 55215 | 53951 | winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
| 55216 | 53952 | winSetSystemCall, /* xSetSystemCall */ |
| 55217 | 53953 | winGetSystemCall, /* xGetSystemCall */ |
| 55218 | 53954 | winNextSystemCall, /* xNextSystemCall */ |
| 55219 | 53955 | }; |
| 55220 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 55221 | 53956 | static sqlite3_vfs winLongPathVfs = { |
| 55222 | 53957 | 3, /* iVersion */ |
| 55223 | 53958 | sizeof(winFile), /* szOsFile */ |
| 55224 | 53959 | SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */ |
| 55225 | 53960 | 0, /* pNext */ |
| | @@ -55240,11 +53975,10 @@ |
| 55240 | 53975 | winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
| 55241 | 53976 | winSetSystemCall, /* xSetSystemCall */ |
| 55242 | 53977 | winGetSystemCall, /* xGetSystemCall */ |
| 55243 | 53978 | winNextSystemCall, /* xNextSystemCall */ |
| 55244 | 53979 | }; |
| 55245 | | -#endif |
| 55246 | 53980 | static sqlite3_vfs winNolockVfs = { |
| 55247 | 53981 | 3, /* iVersion */ |
| 55248 | 53982 | sizeof(winFile), /* szOsFile */ |
| 55249 | 53983 | SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */ |
| 55250 | 53984 | 0, /* pNext */ |
| | @@ -55265,11 +53999,10 @@ |
| 55265 | 53999 | winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
| 55266 | 54000 | winSetSystemCall, /* xSetSystemCall */ |
| 55267 | 54001 | winGetSystemCall, /* xGetSystemCall */ |
| 55268 | 54002 | winNextSystemCall, /* xNextSystemCall */ |
| 55269 | 54003 | }; |
| 55270 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 55271 | 54004 | static sqlite3_vfs winLongPathNolockVfs = { |
| 55272 | 54005 | 3, /* iVersion */ |
| 55273 | 54006 | sizeof(winFile), /* szOsFile */ |
| 55274 | 54007 | SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */ |
| 55275 | 54008 | 0, /* pNext */ |
| | @@ -55290,39 +54023,29 @@ |
| 55290 | 54023 | winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
| 55291 | 54024 | winSetSystemCall, /* xSetSystemCall */ |
| 55292 | 54025 | winGetSystemCall, /* xGetSystemCall */ |
| 55293 | 54026 | winNextSystemCall, /* xNextSystemCall */ |
| 55294 | 54027 | }; |
| 55295 | | -#endif |
| 55296 | 54028 | |
| 55297 | 54029 | /* Double-check that the aSyscall[] array has been constructed |
| 55298 | 54030 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 55299 | | - assert( ArraySize(aSyscall)==81 ); |
| 54031 | + assert( ArraySize(aSyscall)==58 ); |
| 55300 | 54032 | assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 ); |
| 55301 | | - assert( strcmp(aSyscall[20].zName,"GetFileAttributesA")==0 ); |
| 55302 | | - assert( strcmp(aSyscall[40].zName,"HeapReAlloc")==0 ); |
| 55303 | | - assert( strcmp(aSyscall[60].zName,"WideCharToMultiByte")==0 ); |
| 55304 | | - assert( strcmp(aSyscall[80].zName,"cygwin_conv_path")==0 ); |
| 54033 | + assert( strcmp(aSyscall[20].zName,"HeapAlloc")==0 ); |
| 54034 | + assert( strcmp(aSyscall[40].zName,"WideCharToMultiByte")==0 ); |
| 54035 | + assert( strcmp(aSyscall[57].zName,"cygwin_conv_path")==0 ); |
| 55305 | 54036 | |
| 55306 | 54037 | /* get memory map allocation granularity */ |
| 55307 | 54038 | memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); |
| 55308 | 54039 | osGetSystemInfo(&winSysInfo); |
| 55309 | 54040 | assert( winSysInfo.dwAllocationGranularity>0 ); |
| 55310 | 54041 | assert( winSysInfo.dwPageSize>0 ); |
| 55311 | 54042 | |
| 55312 | 54043 | sqlite3_vfs_register(&winVfs, 1); |
| 55313 | | - |
| 55314 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 55315 | 54044 | sqlite3_vfs_register(&winLongPathVfs, 0); |
| 55316 | | -#endif |
| 55317 | | - |
| 55318 | 54045 | sqlite3_vfs_register(&winNolockVfs, 0); |
| 55319 | | - |
| 55320 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 55321 | 54046 | sqlite3_vfs_register(&winLongPathNolockVfs, 0); |
| 55322 | | -#endif |
| 55323 | | - |
| 55324 | 54047 | #ifndef SQLITE_OMIT_WAL |
| 55325 | 54048 | winBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1); |
| 55326 | 54049 | #endif |
| 55327 | 54050 | |
| 55328 | 54051 | return SQLITE_OK; |
| | @@ -56215,14 +54938,14 @@ |
| 56215 | 54938 | sqlite3_free(zSql); |
| 56216 | 54939 | } |
| 56217 | 54940 | if( rc ) goto end_deserialize; |
| 56218 | 54941 | db->init.iDb = (u8)iDb; |
| 56219 | 54942 | db->init.reopenMemdb = 1; |
| 56220 | | - rc = sqlite3_step(pStmt); |
| 54943 | + sqlite3_step(pStmt); |
| 56221 | 54944 | db->init.reopenMemdb = 0; |
| 56222 | | - if( rc!=SQLITE_DONE ){ |
| 56223 | | - rc = SQLITE_ERROR; |
| 54945 | + rc = sqlite3_finalize(pStmt); |
| 54946 | + if( rc!=SQLITE_OK ){ |
| 56224 | 54947 | goto end_deserialize; |
| 56225 | 54948 | } |
| 56226 | 54949 | p = memdbFromDbSchema(db, zSchema); |
| 56227 | 54950 | if( p==0 ){ |
| 56228 | 54951 | rc = SQLITE_ERROR; |
| | @@ -56239,11 +54962,10 @@ |
| 56239 | 54962 | pStore->mFlags = mFlags; |
| 56240 | 54963 | rc = SQLITE_OK; |
| 56241 | 54964 | } |
| 56242 | 54965 | |
| 56243 | 54966 | end_deserialize: |
| 56244 | | - sqlite3_finalize(pStmt); |
| 56245 | 54967 | if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){ |
| 56246 | 54968 | sqlite3_free(pData); |
| 56247 | 54969 | } |
| 56248 | 54970 | sqlite3_mutex_leave(db->mutex); |
| 56249 | 54971 | return rc; |
| | @@ -84791,17 +83513,17 @@ |
| 84791 | 83513 | /* |
| 84792 | 83514 | ** Structure allocated for each backup operation. |
| 84793 | 83515 | */ |
| 84794 | 83516 | struct sqlite3_backup { |
| 84795 | 83517 | sqlite3* pDestDb; /* Destination database handle */ |
| 84796 | | - Btree *pDest; /* Destination b-tree file */ |
| 83518 | + Db *pDest; /* Destination db file */ |
| 84797 | 83519 | u32 iDestSchema; /* Original schema cookie in destination */ |
| 84798 | 83520 | int bDestLocked; /* True once a write-transaction is open on pDest */ |
| 84799 | 83521 | |
| 84800 | 83522 | Pgno iNext; /* Page number of the next source page to copy */ |
| 84801 | 83523 | sqlite3* pSrcDb; /* Source database handle */ |
| 84802 | | - Btree *pSrc; /* Source b-tree file */ |
| 83524 | + Db *pSrc; /* Source db file */ |
| 84803 | 83525 | |
| 84804 | 83526 | int rc; /* Backup process error code */ |
| 84805 | 83527 | |
| 84806 | 83528 | /* These two variables are set by every call to backup_step(). They are |
| 84807 | 83529 | ** read by calls to backup_remaining() and backup_pagecount(). |
| | @@ -84850,11 +83572,11 @@ |
| 84850 | 83572 | ** |
| 84851 | 83573 | ** If the "temp" database is requested, it may need to be opened by this |
| 84852 | 83574 | ** function. If an error occurs while doing so, return 0 and write an |
| 84853 | 83575 | ** error message to pErrorDb. |
| 84854 | 83576 | */ |
| 84855 | | -static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){ |
| 83577 | +static Db *findDatabase(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){ |
| 84856 | 83578 | int i = sqlite3FindDbName(pDb, zDb); |
| 84857 | 83579 | |
| 84858 | 83580 | if( i==1 ){ |
| 84859 | 83581 | Parse sParse; |
| 84860 | 83582 | int rc = 0; |
| | @@ -84873,21 +83595,21 @@ |
| 84873 | 83595 | if( i<0 ){ |
| 84874 | 83596 | sqlite3ErrorWithMsg(pErrorDb, SQLITE_ERROR, "unknown database %s", zDb); |
| 84875 | 83597 | return 0; |
| 84876 | 83598 | } |
| 84877 | 83599 | |
| 84878 | | - return pDb->aDb[i].pBt; |
| 83600 | + return &pDb->aDb[i]; |
| 84879 | 83601 | } |
| 84880 | 83602 | |
| 84881 | 83603 | /* |
| 84882 | 83604 | ** Attempt to set the page size of the destination to match the page size |
| 84883 | 83605 | ** of the source. |
| 84884 | 83606 | */ |
| 84885 | 83607 | static int setDestPgsz(sqlite3_backup *p){ |
| 84886 | | - int rc; |
| 84887 | | - rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0); |
| 84888 | | - return rc; |
| 83608 | + return sqlite3BtreeSetPageSize(p->pDest->pBt, |
| 83609 | + sqlite3BtreeGetPageSize(p->pSrc->pBt), 0, 0 |
| 83610 | + ); |
| 84889 | 83611 | } |
| 84890 | 83612 | |
| 84891 | 83613 | /* |
| 84892 | 83614 | ** Check that there is no open read-transaction on the b-tree passed as the |
| 84893 | 83615 | ** second argument. If there is not, return SQLITE_OK. Otherwise, if there |
| | @@ -84952,19 +83674,19 @@ |
| 84952 | 83674 | } |
| 84953 | 83675 | } |
| 84954 | 83676 | |
| 84955 | 83677 | /* If the allocation succeeded, populate the new object. */ |
| 84956 | 83678 | if( p ){ |
| 84957 | | - p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb); |
| 84958 | | - p->pDest = findBtree(pDestDb, pDestDb, zDestDb); |
| 83679 | + p->pSrc = findDatabase(pDestDb, pSrcDb, zSrcDb); |
| 83680 | + p->pDest = findDatabase(pDestDb, pDestDb, zDestDb); |
| 84959 | 83681 | p->pDestDb = pDestDb; |
| 84960 | 83682 | p->pSrcDb = pSrcDb; |
| 84961 | 83683 | p->iNext = 1; |
| 84962 | 83684 | p->isAttached = 0; |
| 84963 | 83685 | |
| 84964 | 83686 | if( 0==p->pSrc || 0==p->pDest |
| 84965 | | - || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK |
| 83687 | + || checkReadTransaction(pDestDb, p->pDest->pBt)!=SQLITE_OK |
| 84966 | 83688 | ){ |
| 84967 | 83689 | /* One (or both) of the named databases did not exist or an OOM |
| 84968 | 83690 | ** error was hit. Or there is a transaction open on the destination |
| 84969 | 83691 | ** database. The error has already been written into the pDestDb |
| 84970 | 83692 | ** handle. All that is left to do here is free the sqlite3_backup |
| | @@ -84972,11 +83694,11 @@ |
| 84972 | 83694 | sqlite3_free(p); |
| 84973 | 83695 | p = 0; |
| 84974 | 83696 | } |
| 84975 | 83697 | } |
| 84976 | 83698 | if( p ){ |
| 84977 | | - p->pSrc->nBackup++; |
| 83699 | + p->pSrc->pBt->nBackup++; |
| 84978 | 83700 | } |
| 84979 | 83701 | |
| 84980 | 83702 | sqlite3_mutex_leave(pDestDb->mutex); |
| 84981 | 83703 | sqlite3_mutex_leave(pSrcDb->mutex); |
| 84982 | 83704 | return p; |
| | @@ -85000,22 +83722,22 @@ |
| 85000 | 83722 | sqlite3_backup *p, /* Backup handle */ |
| 85001 | 83723 | Pgno iSrcPg, /* Source database page to backup */ |
| 85002 | 83724 | const u8 *zSrcData, /* Source database page data */ |
| 85003 | 83725 | int bUpdate /* True for an update, false otherwise */ |
| 85004 | 83726 | ){ |
| 85005 | | - Pager * const pDestPager = sqlite3BtreePager(p->pDest); |
| 85006 | | - const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc); |
| 85007 | | - int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest); |
| 83727 | + Pager * const pDestPager = sqlite3BtreePager(p->pDest->pBt); |
| 83728 | + const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc->pBt); |
| 83729 | + int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest->pBt); |
| 85008 | 83730 | const int nCopy = MIN(nSrcPgsz, nDestPgsz); |
| 85009 | 83731 | const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz; |
| 85010 | 83732 | int rc = SQLITE_OK; |
| 85011 | 83733 | i64 iOff; |
| 85012 | 83734 | |
| 85013 | | - assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 ); |
| 83735 | + assert( sqlite3BtreeGetReserveNoMutex(p->pSrc->pBt)>=0 ); |
| 85014 | 83736 | assert( p->bDestLocked ); |
| 85015 | 83737 | assert( !isFatalError(p->rc) ); |
| 85016 | | - assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ); |
| 83738 | + assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt->pBt) ); |
| 85017 | 83739 | assert( zSrcData ); |
| 85018 | 83740 | assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 ); |
| 85019 | 83741 | |
| 85020 | 83742 | /* This loop runs once for each destination page spanned by the source |
| 85021 | 83743 | ** page. For each iteration, variable iOff is set to the byte offset |
| | @@ -85022,11 +83744,11 @@ |
| 85022 | 83744 | ** of the destination page. |
| 85023 | 83745 | */ |
| 85024 | 83746 | for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){ |
| 85025 | 83747 | DbPage *pDestPg = 0; |
| 85026 | 83748 | Pgno iDest = (Pgno)(iOff/nDestPgsz)+1; |
| 85027 | | - if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue; |
| 83749 | + if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt->pBt) ) continue; |
| 85028 | 83750 | if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0)) |
| 85029 | 83751 | && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg)) |
| 85030 | 83752 | ){ |
| 85031 | 83753 | const u8 *zIn = &zSrcData[iOff%nSrcPgsz]; |
| 85032 | 83754 | u8 *zDestData = sqlite3PagerGetData(pDestPg); |
| | @@ -85040,11 +83762,11 @@ |
| 85040 | 83762 | ** "MUST BE FIRST" for this purpose. |
| 85041 | 83763 | */ |
| 85042 | 83764 | memcpy(zOut, zIn, nCopy); |
| 85043 | 83765 | ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0; |
| 85044 | 83766 | if( iOff==0 && bUpdate==0 ){ |
| 85045 | | - sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc)); |
| 83767 | + sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc->pBt)); |
| 85046 | 83768 | } |
| 85047 | 83769 | } |
| 85048 | 83770 | sqlite3PagerUnref(pDestPg); |
| 85049 | 83771 | } |
| 85050 | 83772 | |
| | @@ -85072,12 +83794,12 @@ |
| 85072 | 83794 | ** Register this backup object with the associated source pager for |
| 85073 | 83795 | ** callbacks when pages are changed or the cache invalidated. |
| 85074 | 83796 | */ |
| 85075 | 83797 | static void attachBackupObject(sqlite3_backup *p){ |
| 85076 | 83798 | sqlite3_backup **pp; |
| 85077 | | - assert( sqlite3BtreeHoldsMutex(p->pSrc) ); |
| 85078 | | - pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc)); |
| 83799 | + assert( sqlite3BtreeHoldsMutex(p->pSrc->pBt) ); |
| 83800 | + pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt)); |
| 85079 | 83801 | p->pNext = *pp; |
| 85080 | 83802 | *pp = p; |
| 85081 | 83803 | p->isAttached = 1; |
| 85082 | 83804 | } |
| 85083 | 83805 | |
| | @@ -85087,43 +83809,45 @@ |
| 85087 | 83809 | SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){ |
| 85088 | 83810 | int rc; |
| 85089 | 83811 | int destMode; /* Destination journal mode */ |
| 85090 | 83812 | int pgszSrc = 0; /* Source page size */ |
| 85091 | 83813 | int pgszDest = 0; /* Destination page size */ |
| 83814 | + Btree *pDest = p->pDest->pBt; |
| 83815 | + Btree *pSrc = p->pSrc->pBt; |
| 85092 | 83816 | |
| 85093 | 83817 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 85094 | 83818 | if( p==0 ) return SQLITE_MISUSE_BKPT; |
| 85095 | 83819 | #endif |
| 85096 | 83820 | sqlite3_mutex_enter(p->pSrcDb->mutex); |
| 85097 | | - sqlite3BtreeEnter(p->pSrc); |
| 83821 | + sqlite3BtreeEnter(pSrc); |
| 85098 | 83822 | if( p->pDestDb ){ |
| 85099 | 83823 | sqlite3_mutex_enter(p->pDestDb->mutex); |
| 85100 | 83824 | } |
| 85101 | 83825 | |
| 85102 | 83826 | rc = p->rc; |
| 85103 | 83827 | if( !isFatalError(rc) ){ |
| 85104 | | - Pager * const pSrcPager = sqlite3BtreePager(p->pSrc); /* Source pager */ |
| 85105 | | - Pager * const pDestPager = sqlite3BtreePager(p->pDest); /* Dest pager */ |
| 83828 | + Pager * const pSrcPager = sqlite3BtreePager(pSrc); /* Source pager */ |
| 83829 | + Pager * const pDestPager = sqlite3BtreePager(pDest); /* Dest pager */ |
| 85106 | 83830 | int ii; /* Iterator variable */ |
| 85107 | 83831 | int nSrcPage = -1; /* Size of source db in pages */ |
| 85108 | 83832 | int bCloseTrans = 0; /* True if src db requires unlocking */ |
| 85109 | 83833 | |
| 85110 | 83834 | /* If the source pager is currently in a write-transaction, return |
| 85111 | 83835 | ** SQLITE_BUSY immediately. |
| 85112 | 83836 | */ |
| 85113 | | - if( p->pDestDb && p->pSrc->pBt->inTransaction==TRANS_WRITE ){ |
| 83837 | + if( p->pDestDb && pSrc->pBt->inTransaction==TRANS_WRITE ){ |
| 85114 | 83838 | rc = SQLITE_BUSY; |
| 85115 | 83839 | }else{ |
| 85116 | 83840 | rc = SQLITE_OK; |
| 85117 | 83841 | } |
| 85118 | 83842 | |
| 85119 | 83843 | /* If there is no open read-transaction on the source database, open |
| 85120 | 83844 | ** one now. If a transaction is opened here, then it will be closed |
| 85121 | 83845 | ** before this function exits. |
| 85122 | 83846 | */ |
| 85123 | | - if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(p->pSrc) ){ |
| 85124 | | - rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0); |
| 83847 | + if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(pSrc) ){ |
| 83848 | + rc = sqlite3BtreeBeginTrans(pSrc, 0, 0); |
| 85125 | 83849 | bCloseTrans = 1; |
| 85126 | 83850 | } |
| 85127 | 83851 | |
| 85128 | 83852 | /* If the destination database has not yet been locked (i.e. if this |
| 85129 | 83853 | ** is the first call to backup_step() for the current backup operation), |
| | @@ -85135,21 +83859,21 @@ |
| 85135 | 83859 | rc = SQLITE_NOMEM; |
| 85136 | 83860 | } |
| 85137 | 83861 | |
| 85138 | 83862 | /* Lock the destination database, if it is not locked already. */ |
| 85139 | 83863 | if( SQLITE_OK==rc && p->bDestLocked==0 |
| 85140 | | - && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p->pDest, 2, |
| 83864 | + && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(pDest, 2, |
| 85141 | 83865 | (int*)&p->iDestSchema)) |
| 85142 | 83866 | ){ |
| 85143 | 83867 | p->bDestLocked = 1; |
| 85144 | 83868 | } |
| 85145 | 83869 | |
| 85146 | 83870 | /* Do not allow backup if the destination database is in WAL mode |
| 85147 | 83871 | ** and the page sizes are different between source and destination */ |
| 85148 | | - pgszSrc = sqlite3BtreeGetPageSize(p->pSrc); |
| 85149 | | - pgszDest = sqlite3BtreeGetPageSize(p->pDest); |
| 85150 | | - destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p->pDest)); |
| 83872 | + pgszSrc = sqlite3BtreeGetPageSize(pSrc); |
| 83873 | + pgszDest = sqlite3BtreeGetPageSize(pDest); |
| 83874 | + destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(pDest)); |
| 85151 | 83875 | if( SQLITE_OK==rc |
| 85152 | 83876 | && (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager)) |
| 85153 | 83877 | && pgszSrc!=pgszDest |
| 85154 | 83878 | ){ |
| 85155 | 83879 | rc = SQLITE_READONLY; |
| | @@ -85156,15 +83880,15 @@ |
| 85156 | 83880 | } |
| 85157 | 83881 | |
| 85158 | 83882 | /* Now that there is a read-lock on the source database, query the |
| 85159 | 83883 | ** source pager for the number of pages in the database. |
| 85160 | 83884 | */ |
| 85161 | | - nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc); |
| 83885 | + nSrcPage = (int)sqlite3BtreeLastPage(pSrc); |
| 85162 | 83886 | assert( nSrcPage>=0 ); |
| 85163 | 83887 | for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){ |
| 85164 | 83888 | const Pgno iSrcPg = p->iNext; /* Source page number */ |
| 85165 | | - if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){ |
| 83889 | + if( iSrcPg!=PENDING_BYTE_PAGE(pSrc->pBt) ){ |
| 85166 | 83890 | DbPage *pSrcPg; /* Source page object */ |
| 85167 | 83891 | rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY); |
| 85168 | 83892 | if( rc==SQLITE_OK ){ |
| 85169 | 83893 | rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0); |
| 85170 | 83894 | sqlite3PagerUnref(pSrcPg); |
| | @@ -85187,22 +83911,22 @@ |
| 85187 | 83911 | ** the case where the source and destination databases have the |
| 85188 | 83912 | ** same schema version. |
| 85189 | 83913 | */ |
| 85190 | 83914 | if( rc==SQLITE_DONE ){ |
| 85191 | 83915 | if( nSrcPage==0 ){ |
| 85192 | | - rc = sqlite3BtreeNewDb(p->pDest); |
| 83916 | + rc = sqlite3BtreeNewDb(pDest); |
| 85193 | 83917 | nSrcPage = 1; |
| 85194 | 83918 | } |
| 85195 | 83919 | if( rc==SQLITE_OK || rc==SQLITE_DONE ){ |
| 85196 | | - rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1); |
| 83920 | + rc = sqlite3BtreeUpdateMeta(pDest,1,p->iDestSchema+1); |
| 85197 | 83921 | } |
| 85198 | 83922 | if( rc==SQLITE_OK ){ |
| 85199 | 83923 | if( p->pDestDb ){ |
| 85200 | 83924 | sqlite3ResetAllSchemasOfConnection(p->pDestDb); |
| 85201 | 83925 | } |
| 85202 | 83926 | if( destMode==PAGER_JOURNALMODE_WAL ){ |
| 85203 | | - rc = sqlite3BtreeSetVersion(p->pDest, 2); |
| 83927 | + rc = sqlite3BtreeSetVersion(pDest, 2); |
| 85204 | 83928 | } |
| 85205 | 83929 | } |
| 85206 | 83930 | if( rc==SQLITE_OK ){ |
| 85207 | 83931 | int nDestTruncate; |
| 85208 | 83932 | /* Set nDestTruncate to the final number of pages in the destination |
| | @@ -85215,16 +83939,16 @@ |
| 85215 | 83939 | ** sqlite3PagerTruncateImage() here so that any pages in the |
| 85216 | 83940 | ** destination file that lie beyond the nDestTruncate page mark are |
| 85217 | 83941 | ** journalled by PagerCommitPhaseOne() before they are destroyed |
| 85218 | 83942 | ** by the file truncation. |
| 85219 | 83943 | */ |
| 85220 | | - assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) ); |
| 85221 | | - assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) ); |
| 83944 | + assert( pgszSrc==sqlite3BtreeGetPageSize(pSrc) ); |
| 83945 | + assert( pgszDest==sqlite3BtreeGetPageSize(pDest) ); |
| 85222 | 83946 | if( pgszSrc<pgszDest ){ |
| 85223 | 83947 | int ratio = pgszDest/pgszSrc; |
| 85224 | 83948 | nDestTruncate = (nSrcPage+ratio-1)/ratio; |
| 85225 | | - if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){ |
| 83949 | + if( nDestTruncate==(int)PENDING_BYTE_PAGE(pDest->pBt) ){ |
| 85226 | 83950 | nDestTruncate--; |
| 85227 | 83951 | } |
| 85228 | 83952 | }else{ |
| 85229 | 83953 | nDestTruncate = nSrcPage * (pgszSrc/pgszDest); |
| 85230 | 83954 | } |
| | @@ -85248,11 +83972,11 @@ |
| 85248 | 83972 | i64 iEnd; |
| 85249 | 83973 | |
| 85250 | 83974 | assert( pFile ); |
| 85251 | 83975 | assert( nDestTruncate==0 |
| 85252 | 83976 | || (i64)nDestTruncate*(i64)pgszDest >= iSize || ( |
| 85253 | | - nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1) |
| 83977 | + nDestTruncate==(int)(PENDING_BYTE_PAGE(pDest->pBt)-1) |
| 85254 | 83978 | && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest |
| 85255 | 83979 | )); |
| 85256 | 83980 | |
| 85257 | 83981 | /* This block ensures that all data required to recreate the original |
| 85258 | 83982 | ** database has been stored in the journal for pDestPager and the |
| | @@ -85260,11 +83984,11 @@ |
| 85260 | 83984 | ** the database file in any way, knowing that if a power failure |
| 85261 | 83985 | ** occurs, the original database will be reconstructed from the |
| 85262 | 83986 | ** journal file. */ |
| 85263 | 83987 | sqlite3PagerPagecount(pDestPager, &nDstPage); |
| 85264 | 83988 | for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){ |
| 85265 | | - if( iPg!=PENDING_BYTE_PAGE(p->pDest->pBt) ){ |
| 83989 | + if( iPg!=PENDING_BYTE_PAGE(pDest->pBt) ){ |
| 85266 | 83990 | DbPage *pPg; |
| 85267 | 83991 | rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0); |
| 85268 | 83992 | if( rc==SQLITE_OK ){ |
| 85269 | 83993 | rc = sqlite3PagerWrite(pPg); |
| 85270 | 83994 | sqlite3PagerUnref(pPg); |
| | @@ -85304,11 +84028,11 @@ |
| 85304 | 84028 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 85305 | 84029 | } |
| 85306 | 84030 | |
| 85307 | 84031 | /* Finish committing the transaction to the destination database. */ |
| 85308 | 84032 | if( SQLITE_OK==rc |
| 85309 | | - && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0)) |
| 84033 | + && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(pDest, 0)) |
| 85310 | 84034 | ){ |
| 85311 | 84035 | rc = SQLITE_DONE; |
| 85312 | 84036 | } |
| 85313 | 84037 | } |
| 85314 | 84038 | } |
| | @@ -85318,12 +84042,12 @@ |
| 85318 | 84042 | ** no need to check the return values of the btree methods here, as |
| 85319 | 84043 | ** "committing" a read-only transaction cannot fail. |
| 85320 | 84044 | */ |
| 85321 | 84045 | if( bCloseTrans ){ |
| 85322 | 84046 | TESTONLY( int rc2 ); |
| 85323 | | - TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0); |
| 85324 | | - TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0); |
| 84047 | + TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(pSrc, 0); |
| 84048 | + TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(pSrc, 0); |
| 85325 | 84049 | assert( rc2==SQLITE_OK ); |
| 85326 | 84050 | } |
| 85327 | 84051 | |
| 85328 | 84052 | if( rc==SQLITE_IOERR_NOMEM ){ |
| 85329 | 84053 | rc = SQLITE_NOMEM_BKPT; |
| | @@ -85331,11 +84055,11 @@ |
| 85331 | 84055 | p->rc = rc; |
| 85332 | 84056 | } |
| 85333 | 84057 | if( p->pDestDb ){ |
| 85334 | 84058 | sqlite3_mutex_leave(p->pDestDb->mutex); |
| 85335 | 84059 | } |
| 85336 | | - sqlite3BtreeLeave(p->pSrc); |
| 84060 | + sqlite3BtreeLeave(pSrc); |
| 85337 | 84061 | sqlite3_mutex_leave(p->pSrcDb->mutex); |
| 85338 | 84062 | return rc; |
| 85339 | 84063 | } |
| 85340 | 84064 | |
| 85341 | 84065 | /* |
| | @@ -85348,41 +84072,41 @@ |
| 85348 | 84072 | |
| 85349 | 84073 | /* Enter the mutexes */ |
| 85350 | 84074 | if( p==0 ) return SQLITE_OK; |
| 85351 | 84075 | pSrcDb = p->pSrcDb; |
| 85352 | 84076 | sqlite3_mutex_enter(pSrcDb->mutex); |
| 85353 | | - sqlite3BtreeEnter(p->pSrc); |
| 84077 | + sqlite3BtreeEnter(p->pSrc->pBt); |
| 85354 | 84078 | if( p->pDestDb ){ |
| 85355 | 84079 | sqlite3_mutex_enter(p->pDestDb->mutex); |
| 85356 | 84080 | } |
| 85357 | 84081 | |
| 85358 | 84082 | /* Detach this backup from the source pager. */ |
| 85359 | 84083 | if( p->pDestDb ){ |
| 85360 | | - p->pSrc->nBackup--; |
| 84084 | + p->pSrc->pBt->nBackup--; |
| 85361 | 84085 | } |
| 85362 | 84086 | if( p->isAttached ){ |
| 85363 | | - pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc)); |
| 84087 | + pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt)); |
| 85364 | 84088 | assert( pp!=0 ); |
| 85365 | 84089 | while( *pp!=p ){ |
| 85366 | 84090 | pp = &(*pp)->pNext; |
| 85367 | 84091 | assert( pp!=0 ); |
| 85368 | 84092 | } |
| 85369 | 84093 | *pp = p->pNext; |
| 85370 | 84094 | } |
| 85371 | 84095 | |
| 85372 | 84096 | /* If a transaction is still open on the Btree, roll it back. */ |
| 85373 | | - sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0); |
| 84097 | + sqlite3BtreeRollback(p->pDest->pBt, SQLITE_OK, 0); |
| 85374 | 84098 | |
| 85375 | 84099 | /* Set the error code of the destination database handle. */ |
| 85376 | 84100 | rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc; |
| 85377 | 84101 | if( p->pDestDb ){ |
| 85378 | 84102 | sqlite3Error(p->pDestDb, rc); |
| 85379 | 84103 | |
| 85380 | 84104 | /* Exit the mutexes and free the backup context structure. */ |
| 85381 | 84105 | sqlite3LeaveMutexAndCloseZombie(p->pDestDb); |
| 85382 | 84106 | } |
| 85383 | | - sqlite3BtreeLeave(p->pSrc); |
| 84107 | + sqlite3BtreeLeave(p->pSrc->pBt); |
| 85384 | 84108 | if( p->pDestDb ){ |
| 85385 | 84109 | /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a |
| 85386 | 84110 | ** call to sqlite3_backup_init() and is destroyed by a call to |
| 85387 | 84111 | ** sqlite3_backup_finish(). */ |
| 85388 | 84112 | sqlite3_free(p); |
| | @@ -85436,11 +84160,11 @@ |
| 85436 | 84160 | Pgno iPage, |
| 85437 | 84161 | const u8 *aData |
| 85438 | 84162 | ){ |
| 85439 | 84163 | assert( p!=0 ); |
| 85440 | 84164 | do{ |
| 85441 | | - assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) ); |
| 84165 | + assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) ); |
| 85442 | 84166 | if( !isFatalError(p->rc) && iPage<p->iNext ){ |
| 85443 | 84167 | /* The backup process p has already copied page iPage. But now it |
| 85444 | 84168 | ** has been modified by a transaction on the source pager. Copy |
| 85445 | 84169 | ** the new data into the backup. |
| 85446 | 84170 | */ |
| | @@ -85472,11 +84196,11 @@ |
| 85472 | 84196 | ** called. |
| 85473 | 84197 | */ |
| 85474 | 84198 | SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *pBackup){ |
| 85475 | 84199 | sqlite3_backup *p; /* Iterator variable */ |
| 85476 | 84200 | for(p=pBackup; p; p=p->pNext){ |
| 85477 | | - assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) ); |
| 84201 | + assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) ); |
| 85478 | 84202 | p->iNext = 1; |
| 85479 | 84203 | } |
| 85480 | 84204 | } |
| 85481 | 84205 | |
| 85482 | 84206 | #ifndef SQLITE_OMIT_VACUUM |
| | @@ -85490,10 +84214,12 @@ |
| 85490 | 84214 | */ |
| 85491 | 84215 | SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){ |
| 85492 | 84216 | int rc; |
| 85493 | 84217 | sqlite3_file *pFd; /* File descriptor for database pTo */ |
| 85494 | 84218 | sqlite3_backup b; |
| 84219 | + Db dbDest; |
| 84220 | + Db dbSrc; |
| 85495 | 84221 | sqlite3BtreeEnter(pTo); |
| 85496 | 84222 | sqlite3BtreeEnter(pFrom); |
| 85497 | 84223 | |
| 85498 | 84224 | assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE ); |
| 85499 | 84225 | pFd = sqlite3PagerFile(sqlite3BtreePager(pTo)); |
| | @@ -85508,13 +84234,17 @@ |
| 85508 | 84234 | ** to 0. This is used by the implementations of sqlite3_backup_step() |
| 85509 | 84235 | ** and sqlite3_backup_finish() to detect that they are being called |
| 85510 | 84236 | ** from this function, not directly by the user. |
| 85511 | 84237 | */ |
| 85512 | 84238 | memset(&b, 0, sizeof(b)); |
| 84239 | + memset(&dbDest, 0, sizeof(dbDest)); |
| 84240 | + memset(&dbSrc, 0, sizeof(dbSrc)); |
| 84241 | + dbDest.pBt = pTo; |
| 84242 | + dbSrc.pBt = pFrom; |
| 85513 | 84243 | b.pSrcDb = pFrom->db; |
| 85514 | | - b.pSrc = pFrom; |
| 85515 | | - b.pDest = pTo; |
| 84244 | + b.pSrc = &dbSrc; |
| 84245 | + b.pDest = &dbDest; |
| 85516 | 84246 | b.iNext = 1; |
| 85517 | 84247 | |
| 85518 | 84248 | /* 0x7FFFFFFF is the hard limit for the number of pages in a database |
| 85519 | 84249 | ** file. By passing this as the number of pages to copy to |
| 85520 | 84250 | ** sqlite3_backup_step(), we can guarantee that the copy finishes |
| | @@ -85526,11 +84256,11 @@ |
| 85526 | 84256 | |
| 85527 | 84257 | rc = sqlite3_backup_finish(&b); |
| 85528 | 84258 | if( rc==SQLITE_OK ){ |
| 85529 | 84259 | pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED; |
| 85530 | 84260 | }else{ |
| 85531 | | - sqlite3PagerClearCache(sqlite3BtreePager(b.pDest)); |
| 84261 | + sqlite3PagerClearCache(sqlite3BtreePager(pTo)); |
| 85532 | 84262 | } |
| 85533 | 84263 | |
| 85534 | 84264 | assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE ); |
| 85535 | 84265 | copy_finished: |
| 85536 | 84266 | sqlite3BtreeLeave(pFrom); |
| | @@ -125657,21 +124387,30 @@ |
| 125657 | 124387 | if( REOPEN_AS_MEMDB(db) ){ |
| 125658 | 124388 | /* This is not a real ATTACH. Instead, this routine is being called |
| 125659 | 124389 | ** from sqlite3_deserialize() to close database db->init.iDb and |
| 125660 | 124390 | ** reopen it as a MemDB */ |
| 125661 | 124391 | Btree *pNewBt = 0; |
| 124392 | + |
| 124393 | + pNew = &db->aDb[db->init.iDb]; |
| 124394 | + assert( pNew->pBt!=0 ); |
| 124395 | + if( sqlite3BtreeTxnState(pNew->pBt)!=SQLITE_TXN_NONE |
| 124396 | + || sqlite3BtreeIsInBackup(pNew->pBt) |
| 124397 | + ){ |
| 124398 | + rc = SQLITE_BUSY; |
| 124399 | + goto attach_error; |
| 124400 | + } |
| 124401 | + |
| 125662 | 124402 | pVfs = sqlite3_vfs_find("memdb"); |
| 125663 | 124403 | if( pVfs==0 ) return; |
| 125664 | 124404 | rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNewBt, 0, SQLITE_OPEN_MAIN_DB); |
| 125665 | 124405 | if( rc==SQLITE_OK ){ |
| 125666 | 124406 | Schema *pNewSchema = sqlite3SchemaGet(db, pNewBt); |
| 125667 | 124407 | if( pNewSchema ){ |
| 125668 | 124408 | /* Both the Btree and the new Schema were allocated successfully. |
| 125669 | 124409 | ** Close the old db and update the aDb[] slot with the new memdb |
| 125670 | 124410 | ** values. */ |
| 125671 | | - pNew = &db->aDb[db->init.iDb]; |
| 125672 | | - if( ALWAYS(pNew->pBt) ) sqlite3BtreeClose(pNew->pBt); |
| 124411 | + sqlite3BtreeClose(pNew->pBt); |
| 125673 | 124412 | pNew->pBt = pNewBt; |
| 125674 | 124413 | pNew->pSchema = pNewSchema; |
| 125675 | 124414 | }else{ |
| 125676 | 124415 | sqlite3BtreeClose(pNewBt); |
| 125677 | 124416 | rc = SQLITE_NOMEM; |
| | @@ -234231,21 +232970,21 @@ |
| 234231 | 232970 | unsigned int h = 0; /* Value to return */ |
| 234232 | 232971 | int i; /* Used to iterate through columns */ |
| 234233 | 232972 | u8 *a = aRecord; /* Used to iterate through change record */ |
| 234234 | 232973 | |
| 234235 | 232974 | for(i=0; i<pTab->nCol; i++){ |
| 234236 | | - int eType = *a; |
| 234237 | 232975 | int isPK = pTab->abPK[i]; |
| 234238 | 232976 | if( bPkOnly && isPK==0 ) continue; |
| 234239 | 232977 | |
| 234240 | | - assert( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT |
| 234241 | | - || eType==SQLITE_TEXT || eType==SQLITE_BLOB |
| 234242 | | - || eType==SQLITE_NULL || eType==0 |
| 234243 | | - ); |
| 234244 | | - |
| 234245 | 232978 | if( isPK ){ |
| 234246 | | - a++; |
| 232979 | + int eType = *a++; |
| 232980 | + |
| 232981 | + assert( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT |
| 232982 | + || eType==SQLITE_TEXT || eType==SQLITE_BLOB |
| 232983 | + || eType==SQLITE_NULL || eType==0 |
| 232984 | + ); |
| 232985 | + |
| 234247 | 232986 | h = sessionHashAppendType(h, eType); |
| 234248 | 232987 | if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ |
| 234249 | 232988 | h = sessionHashAppendI64(h, sessionGetI64(a)); |
| 234250 | 232989 | a += 8; |
| 234251 | 232990 | }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){ |
| | @@ -263478,11 +262217,11 @@ |
| 263478 | 262217 | int nArg, /* Number of args */ |
| 263479 | 262218 | sqlite3_value **apUnused /* Function arguments */ |
| 263480 | 262219 | ){ |
| 263481 | 262220 | assert( nArg==0 ); |
| 263482 | 262221 | UNUSED_PARAM2(nArg, apUnused); |
| 263483 | | - sqlite3_result_text(pCtx, "fts5: 2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002", -1, SQLITE_TRANSIENT); |
| 262222 | + sqlite3_result_text(pCtx, "fts5: 2026-04-29 19:14:54 1f940357f7bb160b583ac5b08ff4e32a9fef353255d032c5a18bcb04416c0f0b", -1, SQLITE_TRANSIENT); |
| 263484 | 262223 | } |
| 263485 | 262224 | |
| 263486 | 262225 | /* |
| 263487 | 262226 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 263488 | 262227 | ** |
| 263489 | 262228 | |