/ Check-in [a1bcc6de]
Login

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

Overview
Comment:Move the shared-library loading routines into the OS portability layer, thus enabling the os_win.c code to handle the character encoding confusion of win95/nt/ce. Ticket #2023. (CVS 3541)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a1bcc6de578992b28924c1cf974ea58251454e2d
User & Date: drh 2006-12-21 01:29:23
Context
2006-12-21
01:37
Reduce the number of utf8->unicode conversions required in wince. Ticket #2122 (CVS 3542) check-in: 6d2ff096 user: drh tags: trunk
01:29
Move the shared-library loading routines into the OS portability layer, thus enabling the os_win.c code to handle the character encoding confusion of win95/nt/ce. Ticket #2023. (CVS 3541) check-in: a1bcc6de user: drh tags: trunk
00:46
Change a parameter type from "int" to "DWORD" in the windows interface. Ticket #2122. (CVS 3540) check-in: cca1eb3d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/loadext.c.

   213    213     ** sqlite3_libversion_number() to make sure they are dealing with
   214    214     ** a library that is new enough to support that API.
   215    215     *************************************************************************
   216    216     */
   217    217     sqlite3_overload_function,
   218    218   };
   219    219   
   220         -/*
   221         -** The windows implementation of shared-library loaders
   222         -*/
   223         -#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || defined(__BORLANDC__)
   224         -# include <windows.h>
   225         -# define SQLITE_LIBRARY_TYPE     HANDLE
   226         -# ifdef _WIN32_WCE
   227         -    static HANDLE loadLibraryUtf8(const char *z){
   228         -      WCHAR zWide[MAX_PATH];
   229         -      MultiByteToWideChar(CP_ACP,0,z,-1,zWide,MAX_PATH);
   230         -      return LoadLibrary(zWide);
   231         -    }
   232         -#   define SQLITE_OPEN_LIBRARY(A)  loadLibraryUtf8(A)
   233         -#   define SQLITE_FIND_SYMBOL(A,B) GetProcAddressA(A,B)
   234         -# else
   235         -#   define SQLITE_OPEN_LIBRARY(A)  LoadLibrary(A)
   236         -#   define SQLITE_FIND_SYMBOL(A,B) GetProcAddress(A,B)
   237         -# endif
   238         -# define SQLITE_CLOSE_LIBRARY(A) FreeLibrary(A)
   239         -#endif /* windows */
   240         -
   241         -/*
   242         -** The unix implementation of shared-library loaders
   243         -*/
   244         -#if defined(HAVE_DLOPEN) && !defined(SQLITE_LIBRARY_TYPE)
   245         -# include <dlfcn.h>
   246         -# define SQLITE_LIBRARY_TYPE     void*
   247         -# define SQLITE_OPEN_LIBRARY(A)  dlopen(A, RTLD_NOW | RTLD_GLOBAL)
   248         -# define SQLITE_FIND_SYMBOL(A,B) dlsym(A,B)
   249         -# define SQLITE_CLOSE_LIBRARY(A) dlclose(A)
   250         -#endif
   251         -
   252    220   /*
   253    221   ** Attempt to load an SQLite extension library contained in the file
   254    222   ** zFile.  The entry point is zProc.  zProc may be 0 in which case a
   255    223   ** default entry point name (sqlite3_extension_init) is used.  Use
   256    224   ** of the default name is recommended.
   257    225   **
   258    226   ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
................................................................................
   263    231   */
   264    232   int sqlite3_load_extension(
   265    233     sqlite3 *db,          /* Load the extension into this database connection */
   266    234     const char *zFile,    /* Name of the shared library containing extension */
   267    235     const char *zProc,    /* Entry point.  Use "sqlite3_extension_init" if 0 */
   268    236     char **pzErrMsg       /* Put error message here if not 0 */
   269    237   ){
   270         -#ifdef SQLITE_LIBRARY_TYPE
   271         -  SQLITE_LIBRARY_TYPE handle;
          238  +  void *handle;
   272    239     int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
   273    240     char *zErrmsg = 0;
   274         -  SQLITE_LIBRARY_TYPE *aHandle;
          241  +  void **aHandle;
   275    242   
   276    243     /* Ticket #1863.  To avoid a creating security problems for older
   277    244     ** applications that relink against newer versions of SQLite, the
   278    245     ** ability to run load_extension is turned off by default.  One
   279    246     ** must call sqlite3_enable_load_extension() to turn on extension
   280    247     ** loading.  Otherwise you get the following error.
   281    248     */
................................................................................
   286    253       return SQLITE_ERROR;
   287    254     }
   288    255   
   289    256     if( zProc==0 ){
   290    257       zProc = "sqlite3_extension_init";
   291    258     }
   292    259   
   293         -  handle = SQLITE_OPEN_LIBRARY(zFile);
          260  +  handle = sqlite3OsDlopen(zFile);
   294    261     if( handle==0 ){
   295    262       if( pzErrMsg ){
   296    263         *pzErrMsg = sqlite3_mprintf("unable to open shared library [%s]", zFile);
   297    264       }
   298    265       return SQLITE_ERROR;
   299    266     }
   300    267     xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
   301         -                   SQLITE_FIND_SYMBOL(handle, zProc);
          268  +                   sqlite3OsDlsym(handle, zProc);
   302    269     if( xInit==0 ){
   303    270       if( pzErrMsg ){
   304    271          *pzErrMsg = sqlite3_mprintf("no entry point [%s] in shared library [%s]",
   305    272                                      zProc, zFile);
   306    273       }
   307         -    SQLITE_CLOSE_LIBRARY(handle);
          274  +    sqlite3OsDlclose(handle);
   308    275       return SQLITE_ERROR;
   309    276     }else if( xInit(db, &zErrmsg, &sqlite3_apis) ){
   310    277       if( pzErrMsg ){
   311    278         *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
   312    279       }
   313    280       sqlite3_free(zErrmsg);
   314         -    SQLITE_CLOSE_LIBRARY(handle);
          281  +    sqlite3OsDlclose(handle);
   315    282       return SQLITE_ERROR;
   316    283     }
   317    284   
   318    285     /* Append the new shared library handle to the db->aExtension array. */
   319    286     db->nExtension++;
   320    287     aHandle = sqliteMalloc(sizeof(handle)*db->nExtension);
   321    288     if( aHandle==0 ){
................................................................................
   323    290     }
   324    291     if( db->nExtension>0 ){
   325    292       memcpy(aHandle, db->aExtension, sizeof(handle)*(db->nExtension-1));
   326    293     }
   327    294     sqliteFree(db->aExtension);
   328    295     db->aExtension = aHandle;
   329    296   
   330         -  ((SQLITE_LIBRARY_TYPE*)db->aExtension)[db->nExtension-1] = handle;
          297  +  db->aExtension[db->nExtension-1] = handle;
   331    298     return SQLITE_OK;
   332         -#else
   333         -  if( pzErrMsg ){
   334         -    *pzErrMsg = sqlite3_mprintf("extension loading is disabled");
   335         -  }
   336         -  return SQLITE_ERROR;
   337         -#endif
   338    299   }
   339    300   
   340    301   /*
   341    302   ** Call this routine when the database connection is closing in order
   342    303   ** to clean up loaded extensions
   343    304   */
   344    305   void sqlite3CloseExtensions(sqlite3 *db){
   345         -#ifdef SQLITE_LIBRARY_TYPE
   346    306     int i;
   347    307     for(i=0; i<db->nExtension; i++){
   348         -    SQLITE_CLOSE_LIBRARY(((SQLITE_LIBRARY_TYPE*)db->aExtension)[i]);
          308  +    sqlite3OsDlclose(db->aExtension[i]);
   349    309     }
   350    310     sqliteFree(db->aExtension);
   351         -#endif
   352    311   }
   353    312   
   354    313   /*
   355    314   ** Enable or disable extension loading.  Extension loading is disabled by
   356    315   ** default so as not to open security holes in older applications.
   357    316   */
   358    317   int sqlite3_enable_load_extension(sqlite3 *db, int onoff){

Changes to src/os.h.

   118    118   #define sqlite3OsLeaveMutex         sqlite3UnixLeaveMutex
   119    119   #define sqlite3OsInMutex            sqlite3UnixInMutex
   120    120   #define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData
   121    121   #define sqlite3OsMalloc             sqlite3GenericMalloc
   122    122   #define sqlite3OsRealloc            sqlite3GenericRealloc
   123    123   #define sqlite3OsFree               sqlite3GenericFree
   124    124   #define sqlite3OsAllocationSize     sqlite3GenericAllocationSize
          125  +#define sqlite3OsDlopen             sqlite3UnixDlopen
          126  +#define sqlite3OsDlsym              sqlite3UnixDlsym
          127  +#define sqlite3OsDlclose            sqlite3UnixDlclose
   125    128   #endif
   126    129   #if OS_WIN
   127    130   #define sqlite3OsOpenReadWrite      sqlite3WinOpenReadWrite
   128    131   #define sqlite3OsOpenExclusive      sqlite3WinOpenExclusive
   129    132   #define sqlite3OsOpenReadOnly       sqlite3WinOpenReadOnly
   130    133   #define sqlite3OsDelete             sqlite3WinDelete
   131    134   #define sqlite3OsFileExists         sqlite3WinFileExists
................................................................................
   140    143   #define sqlite3OsLeaveMutex         sqlite3WinLeaveMutex
   141    144   #define sqlite3OsInMutex            sqlite3WinInMutex
   142    145   #define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData
   143    146   #define sqlite3OsMalloc             sqlite3GenericMalloc
   144    147   #define sqlite3OsRealloc            sqlite3GenericRealloc
   145    148   #define sqlite3OsFree               sqlite3GenericFree
   146    149   #define sqlite3OsAllocationSize     sqlite3GenericAllocationSize
          150  +#define sqlite3OsDlopen             sqlite3WinDlopen
          151  +#define sqlite3OsDlsym              sqlite3WinDlsym
          152  +#define sqlite3OsDlclose            sqlite3WinDlclose
   147    153   #endif
   148    154   #if OS_OS2
   149    155   #define sqlite3OsOpenReadWrite      sqlite3Os2OpenReadWrite
   150    156   #define sqlite3OsOpenExclusive      sqlite3Os2OpenExclusive
   151    157   #define sqlite3OsOpenReadOnly       sqlite3Os2OpenReadOnly
   152    158   #define sqlite3OsDelete             sqlite3Os2Delete
   153    159   #define sqlite3OsFileExists         sqlite3Os2FileExists
................................................................................
   162    168   #define sqlite3OsLeaveMutex         sqlite3Os2LeaveMutex
   163    169   #define sqlite3OsInMutex            sqlite3Os2InMutex
   164    170   #define sqlite3OsThreadSpecificData sqlite3Os2ThreadSpecificData
   165    171   #define sqlite3OsMalloc             sqlite3GenericMalloc
   166    172   #define sqlite3OsRealloc            sqlite3GenericRealloc
   167    173   #define sqlite3OsFree               sqlite3GenericFree
   168    174   #define sqlite3OsAllocationSize     sqlite3GenericAllocationSize
          175  +#define sqlite3OsDlopen             sqlite3Os2Dlopen
          176  +#define sqlite3OsDlsym              sqlite3Os2Dlsym
          177  +#define sqlite3OsDlclose            sqlite3Os2Dlclose
   169    178   #endif
   170    179   
   171    180   
   172    181   
   173    182   
   174    183   /*
   175    184   ** If using an alternative OS interface, then we must have an "os_other.h"
................................................................................
   345    354   void sqlite3OsLeaveMutex(void);
   346    355   int sqlite3OsInMutex(int);
   347    356   ThreadData *sqlite3OsThreadSpecificData(int);
   348    357   void *sqlite3OsMalloc(int);
   349    358   void *sqlite3OsRealloc(void *, int);
   350    359   void sqlite3OsFree(void *);
   351    360   int sqlite3OsAllocationSize(void *);
          361  +void *sqlite3OsDlopen(const char*);
          362  +void *sqlite3OsDlsym(void*, const char*);
          363  +int sqlite3OsDlclose(void*);
   352    364   
   353    365   /*
   354    366   ** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
   355    367   ** interface routines are not called directly but are invoked using
   356    368   ** pointers to functions.  This allows the implementation of various
   357    369   ** OS-layer interface routines to be modified at run-time.  There are
   358    370   ** obscure but legitimate reasons for wanting to do this.  But for
................................................................................
   389    401     int (*xInMutex)(int);
   390    402     ThreadData *(*xThreadSpecificData)(int);
   391    403   
   392    404     void *(*xMalloc)(int);
   393    405     void *(*xRealloc)(void *, int);
   394    406     void (*xFree)(void *);
   395    407     int (*xAllocationSize)(void *);
          408  +
          409  +  void *(*xDlopen)(const char*);
          410  +  void *(*xDlsym)(void*, const char*);
          411  +  int (*xDlclose)(void*);
   396    412   };
   397    413   
   398    414   /* Macro used to comment out routines that do not exists when there is
   399         -** no disk I/O 
          415  +** no disk I/O or extension loading
   400    416   */
   401    417   #ifdef SQLITE_OMIT_DISKIO
   402    418   # define IF_DISKIO(X)  0
   403    419   #else
   404    420   # define IF_DISKIO(X)  X
   405    421   #endif
          422  +#ifdef SQLITE_OMIT_LOAD_EXTENSION
          423  +# define IF_DLOPEN(X)  0
          424  +#else
          425  +# define IF_DLOPEN(X)  X
          426  +#endif
          427  +
   406    428   
   407    429   #ifdef _SQLITE_OS_C_
   408    430     /*
   409    431     ** The os.c file implements the global virtual function table.
   410    432     */
   411    433     struct sqlite3OsVtbl sqlite3Os = {
   412    434       IF_DISKIO( sqlite3OsOpenReadWrite ),
................................................................................
   424    446       sqlite3OsEnterMutex,
   425    447       sqlite3OsLeaveMutex,
   426    448       sqlite3OsInMutex,
   427    449       sqlite3OsThreadSpecificData,
   428    450       sqlite3OsMalloc,
   429    451       sqlite3OsRealloc,
   430    452       sqlite3OsFree,
   431         -    sqlite3OsAllocationSize
          453  +    sqlite3OsAllocationSize,
          454  +    IF_DLOPEN( sqlite3OsDlopen ),
          455  +    IF_DLOPEN( sqlite3OsDlsym ),
          456  +    IF_DLOPEN( sqlite3OsDlclose ),
   432    457     };
   433    458   #else
   434    459     /*
   435    460     ** Files other than os.c just reference the global virtual function table. 
   436    461     */
   437    462     extern struct sqlite3OsVtbl sqlite3Os;
   438    463   #endif /* _SQLITE_OS_C_ */

Changes to src/os_os2.c.

   763    763   }
   764    764   
   765    765   #endif /* SQLITE_OMIT_DISKIO */
   766    766   /***************************************************************************
   767    767   ** Everything above deals with file I/O.  Everything that follows deals
   768    768   ** with other miscellanous aspects of the operating system interface
   769    769   ****************************************************************************/
          770  +
          771  +#ifndef SQLITE_OMIT_LOAD_EXTENSION
          772  +/*
          773  +** Interfaces for opening a shared library, finding entry points
          774  +** within the shared library, and closing the shared library.
          775  +*/
          776  +void *sqlite3Os2Dlopen(const char *zFilename){
          777  +  return 0;
          778  +}
          779  +void *sqlite3Os2Dlsym(void *pHandle, const char *zSymbol){
          780  +  return 0;
          781  +}
          782  +int sqlite3Os2Dlclose(void *pHandle){
          783  +  return 0;
          784  +}
          785  +#endif /* SQLITE_OMIT_LOAD_EXTENSION */
          786  +
   770    787   
   771    788   /*
   772    789   ** Get information to seed the random number generator.  The seed
   773    790   ** is written into the buffer zBuf[256].  The calling function must
   774    791   ** supply a sufficiently large buffer.
   775    792   */
   776    793   int sqlite3Os2RandomSeed( char *zBuf ){

Changes to src/os_unix.c.

  2577   2577   #endif /* SQLITE_OMIT_DISKIO */
  2578   2578   /***************************************************************************
  2579   2579   ** Everything above deals with file I/O.  Everything that follows deals
  2580   2580   ** with other miscellanous aspects of the operating system interface
  2581   2581   ****************************************************************************/
  2582   2582   
  2583   2583   
         2584  +#ifndef SQLITE_OMIT_LOAD_EXTENSION
         2585  +/*
         2586  +** Interfaces for opening a shared library, finding entry points
         2587  +** within the shared library, and closing the shared library.
         2588  +*/
         2589  +#include <dlfcn.h>
         2590  +void *sqlite3UnixDlopen(const char *zFilename){
         2591  +  return dlopen(zFilename, RTLD_NOW | RTLD_GLOBAL);
         2592  +}
         2593  +void *sqlite3UnixDlsym(void *pHandle, const char *zSymbol){
         2594  +  return dlsym(pHandle, zSymbol);
         2595  +}
         2596  +int sqlite3UnixDlclose(void *pHandle){
         2597  +  return dlclose(pHandle);
         2598  +}
         2599  +#endif /* SQLITE_OMIT_LOAD_EXTENSION */
         2600  +
  2584   2601   /*
  2585   2602   ** Get information to seed the random number generator.  The seed
  2586   2603   ** is written into the buffer zBuf[256].  The calling function must
  2587   2604   ** supply a sufficiently large buffer.
  2588   2605   */
  2589   2606   int sqlite3UnixRandomSeed(char *zBuf){
  2590   2607     /* We have to initialize zBuf to prevent valgrind from reporting

Changes to src/os_win.c.

  1493   1493   
  1494   1494   
  1495   1495   #endif /* SQLITE_OMIT_DISKIO */
  1496   1496   /***************************************************************************
  1497   1497   ** Everything above deals with file I/O.  Everything that follows deals
  1498   1498   ** with other miscellanous aspects of the operating system interface
  1499   1499   ****************************************************************************/
         1500  +
         1501  +#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
         1502  +/*
         1503  +** Interfaces for opening a shared library, finding entry points
         1504  +** within the shared library, and closing the shared library.
         1505  +*/
         1506  +void *sqlite3WinDlopen(const char *zFilename){
         1507  +  HANDLE h;
         1508  +  void *zConverted = convertUtf8Filename(zFilename);
         1509  +  if( zConverted==0 ){
         1510  +    return 0;
         1511  +  }
         1512  +  if( isNT() ){
         1513  +    h = LoadLibraryW(zConverted);
         1514  +  }else{
         1515  +#if OS_WINCE
         1516  +    return SQLITE_NOMEM;
         1517  +#else
         1518  +    h = LoadLibraryA(zConverted);
         1519  +#endif
         1520  +  }
         1521  +  sqliteFree(zConverted);
         1522  +  return (void*)h;
         1523  +  
         1524  +}
         1525  +void *sqlite3WinDlsym(void *pHandle, const char *zSymbol){
         1526  +  return GetProcAddress((HANDLE)pHandle, zSymbol);
         1527  +}
         1528  +int sqlite3WinDlclose(void *pHandle){
         1529  +  return FreeLibrary((HANDLE)pHandle);
         1530  +}
         1531  +#endif /* !SQLITE_OMIT_LOAD_EXTENSION */
  1500   1532   
  1501   1533   /*
  1502   1534   ** Get information to seed the random number generator.  The seed
  1503   1535   ** is written into the buffer zBuf[256].  The calling function must
  1504   1536   ** supply a sufficiently large buffer.
  1505   1537   */
  1506   1538   int sqlite3WinRandomSeed(char *zBuf){

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.531 2006/12/16 16:25:16 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.532 2006/12/21 01:29:23 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Extra interface definitions for those who need them
    21     21   */
................................................................................
   459    459     int nTotalChange;             /* Value returned by sqlite3_total_changes() */
   460    460     struct sqlite3InitInfo {      /* Information used during initialization */
   461    461       int iDb;                    /* When back is being initialized */
   462    462       int newTnum;                /* Rootpage of table being initialized */
   463    463       u8 busy;                    /* TRUE if currently initializing */
   464    464     } init;
   465    465     int nExtension;               /* Number of loaded extensions */
   466         -  void *aExtension;             /* Array of shared libraray handles */
          466  +  void **aExtension;            /* Array of shared libraray handles */
   467    467     struct Vdbe *pVdbe;           /* List of active virtual machines */
   468    468     int activeVdbeCnt;            /* Number of vdbes currently executing */
   469    469     void (*xTrace)(void*,const char*);        /* Trace function */
   470    470     void *pTraceArg;                          /* Argument to the trace function */
   471    471     void (*xProfile)(void*,const char*,u64);  /* Profiling function */
   472    472     void *pProfileArg;                        /* Argument to profile function */
   473    473     void *pCommitArg;                 /* Argument to xCommitCallback() */