/ Check-in [8f287979]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Expand passing of a last error argument to the getLastErrorMsg function. Also, remove unused SQLITE_W32_THREADS define.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8f28797984c1d4700357a75815ca4b324c3ebf5c
User & Date: mistachkin 2011-11-10 21:45:06
Context
2011-11-11
22:08
Work in progress to implement the 'syscall' functionality for Windows. check-in: ed88fb00 user: mistachkin tags: winSyscall
00:27
Make sure a corrupt index does not cause a buffer overread in sqlite3VdbeRecordCompare(). check-in: 471cf0d8 user: drh tags: trunk
2011-11-10
21:45
Expand passing of a last error argument to the getLastErrorMsg function. Also, remove unused SQLITE_W32_THREADS define. check-in: 8f287979 user: mistachkin tags: trunk
20:21
In winAccess, save the Win32 last error value prior to invoking user logging callback. Also, explicitly pass the Win32 last error value to winLogError in order to keep it accurate. Fixes a problem reported on the mailing list. check-in: 32ab3657 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

    44     44   
    45     45   #include <winbase.h>
    46     46   
    47     47   #ifdef __CYGWIN__
    48     48   # include <sys/cygwin.h>
    49     49   #endif
    50     50   
    51         -/*
    52         -** Macros used to determine whether or not to use threads.
    53         -*/
    54         -#if defined(THREADSAFE) && THREADSAFE
    55         -# define SQLITE_W32_THREADS 1
    56         -#endif
    57         -
    58     51   /*
    59     52   ** Include code that is common to all os_*.c files
    60     53   */
    61     54   #include "os_common.h"
    62     55   
    63     56   /*
    64     57   ** Some microsoft compilers lack this definition.
................................................................................
   554    547   
   555    548   
   556    549   /*
   557    550   ** The return value of getLastErrorMsg
   558    551   ** is zero if the error message fits in the buffer, or non-zero
   559    552   ** otherwise (if the message was truncated).
   560    553   */
   561         -static int getLastErrorMsg(int nBuf, char *zBuf){
          554  +static int getLastErrorMsg(DWORD lastErrno, int nBuf, char *zBuf){
   562    555     /* FormatMessage returns 0 on failure.  Otherwise it
   563    556     ** returns the number of TCHARs written to the output
   564    557     ** buffer, excluding the terminating null char.
   565    558     */
   566         -  DWORD error = GetLastError();
   567    559     DWORD dwLen = 0;
   568    560     char *zOut = 0;
   569    561   
   570    562     if( isNT() ){
   571    563       WCHAR *zTempWide = NULL;
   572         -    dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
          564  +    dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
          565  +                           FORMAT_MESSAGE_FROM_SYSTEM |
          566  +                           FORMAT_MESSAGE_IGNORE_INSERTS,
   573    567                              NULL,
   574         -                           error,
          568  +                           lastErrno,
   575    569                              0,
   576    570                              (LPWSTR) &zTempWide,
   577    571                              0,
   578    572                              0);
   579    573       if( dwLen > 0 ){
   580    574         /* allocate a buffer and convert to UTF8 */
   581    575         zOut = unicodeToUtf8(zTempWide);
................................................................................
   585    579   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
   586    580   ** Since the ASCII version of these Windows API do not exist for WINCE,
   587    581   ** it's important to not reference them for WINCE builds.
   588    582   */
   589    583   #if SQLITE_OS_WINCE==0
   590    584     }else{
   591    585       char *zTemp = NULL;
   592         -    dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
          586  +    dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
          587  +                           FORMAT_MESSAGE_FROM_SYSTEM |
          588  +                           FORMAT_MESSAGE_IGNORE_INSERTS,
   593    589                              NULL,
   594         -                           error,
          590  +                           lastErrno,
   595    591                              0,
   596    592                              (LPSTR) &zTemp,
   597    593                              0,
   598    594                              0);
   599    595       if( dwLen > 0 ){
   600    596         /* allocate a buffer and convert to UTF8 */
   601    597         zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
   602    598         /* free the system buffer allocated by FormatMessage */
   603    599         LocalFree(zTemp);
   604    600       }
   605    601   #endif
   606    602     }
   607    603     if( 0 == dwLen ){
   608         -    sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error);
          604  +    sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno);
   609    605     }else{
   610    606       /* copy a maximum of nBuf chars to output buffer */
   611    607       sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
   612    608       /* free the UTF8 buffer */
   613    609       free(zOut);
   614    610     }
   615    611     return 0;
................................................................................
   638    634     const char *zPath,              /* File path associated with error */
   639    635     int iLine                       /* Source line number where error occurred */
   640    636   ){
   641    637     char zMsg[500];                 /* Human readable error text */
   642    638     int i;                          /* Loop counter */
   643    639   
   644    640     zMsg[0] = 0;
   645         -  getLastErrorMsg(sizeof(zMsg), zMsg);
          641  +  getLastErrorMsg(lastErrno, sizeof(zMsg), zMsg);
   646    642     assert( errcode!=SQLITE_OK );
   647    643     if( zPath==0 ) zPath = "";
   648    644     for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){}
   649    645     zMsg[i] = 0;
   650    646     sqlite3_log(errcode,
   651    647         "os_win.c:%d: (%d) %s(%s) - %s",
   652    648         iLine, lastErrno, zFunc, zPath, zMsg
................................................................................
  2994   2990   #endif
  2995   2991     }
  2996   2992     free(zConverted);
  2997   2993     return (void*)h;
  2998   2994   }
  2999   2995   static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
  3000   2996     UNUSED_PARAMETER(pVfs);
  3001         -  getLastErrorMsg(nBuf, zBufOut);
         2997  +  getLastErrorMsg(GetLastError(), nBuf, zBufOut);
  3002   2998   }
  3003   2999   static void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
  3004   3000     UNUSED_PARAMETER(pVfs);
  3005   3001   #if SQLITE_OS_WINCE
  3006   3002     /* The GetProcAddressA() routine is only available on wince. */
  3007   3003     return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol);
  3008   3004   #else
................................................................................
  3168   3164   **
  3169   3165   ** However if an error message is supplied, it will be incorporated
  3170   3166   ** by sqlite into the error message available to the user using
  3171   3167   ** sqlite3_errmsg(), possibly making IO errors easier to debug.
  3172   3168   */
  3173   3169   static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
  3174   3170     UNUSED_PARAMETER(pVfs);
  3175         -  return getLastErrorMsg(nBuf, zBuf);
         3171  +  return getLastErrorMsg(GetLastError(), nBuf, zBuf);
  3176   3172   }
  3177   3173   
  3178   3174   
  3179   3175   
  3180   3176   /*
  3181   3177   ** Initialize and deinitialize the operating system interface.
  3182   3178   */