1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-27 08:52:26 +03:00

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)

FossilOrigin-Name: a1bcc6de578992b28924c1cf974ea58251454e2d
This commit is contained in:
drh
2006-12-21 01:29:22 +00:00
parent ec4d88fab5
commit 761df87ea5
8 changed files with 115 additions and 65 deletions

View File

@@ -1,5 +1,5 @@
C Change\sa\sparameter\stype\sfrom\s"int"\sto\s"DWORD"\sin\sthe\swindows\sinterface.\nTicket\s#2122.\s(CVS\s3540) C Move\sthe\sshared-library\sloading\sroutines\sinto\sthe\sOS\sportability\slayer,\nthus\senabling\sthe\sos_win.c\scode\sto\shandle\sthe\scharacter\sencoding\nconfusion\sof\swin95/nt/ce.\s\sTicket\s#2023.\s(CVS\s3541)
D 2006-12-21T00:46:42 D 2006-12-21T01:29:23
F Makefile.in 8e14898d41a53033ecb687d93c9cd5d109fb9ae3 F Makefile.in 8e14898d41a53033ecb687d93c9cd5d109fb9ae3
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -71,19 +71,19 @@ F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185
F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
F src/insert.c e9526ced19978a55687b55faea969b6ff2a53fb4 F src/insert.c e9526ced19978a55687b55faea969b6ff2a53fb4
F src/legacy.c 2631df6a861f830d6b1c0fe92b9fdd745b2c0cd6 F src/legacy.c 2631df6a861f830d6b1c0fe92b9fdd745b2c0cd6
F src/loadext.c acbbf33357d7eec1ff2aa94dc1fcd38fef76c939 F src/loadext.c d7f0903ba15d7a713fc42943e72178cae8ad922b
F src/main.c 33c32014da3a1471e8869d2eba32b2c4314c39ce F src/main.c 33c32014da3a1471e8869d2eba32b2c4314c39ce
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/os.c 59f05de8c5777c34876607114a2fbe55ae578235 F src/os.c 59f05de8c5777c34876607114a2fbe55ae578235
F src/os.h fa6fcf5e4614a20ca2c90cddda0b40199360f27e F src/os.h 17fc73165cb7436aa79492d2dff754baec74fcb9
F src/os_common.h 545426356f0868a6765e70cb59e319d3acad0ed6 F src/os_common.h 545426356f0868a6765e70cb59e319d3acad0ed6
F src/os_os2.c c1bfc0c326f63caf0c94ab5523010ce0f5458070 F src/os_os2.c d399224753477c53dd0801af925edf92c9e388c6
F src/os_os2.h e5f17dd69333632bbc3112881ea407c37d245eb3 F src/os_os2.h e5f17dd69333632bbc3112881ea407c37d245eb3
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
F src/os_unix.c d3b6b66b79777c9177d76bd5c68c227978c4593c F src/os_unix.c d4bc8cbe1c0dc330bd55bf7821db5b7dbfbf183e
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c eb6642f708b1b183446bf121e0dbd84711d7d883 F src/os_win.c 359dd74a2bb58a5eef052da2c0c9e15f72aaf7c5
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 814268d5bbd69f30069867142f1d460b8b7ab778 F src/pager.c 814268d5bbd69f30069867142f1d460b8b7ab778
F src/pager.h 2e6d42f4ae004ae748a037b8468112b851c447a7 F src/pager.h 2e6d42f4ae004ae748a037b8468112b851c447a7
@@ -97,7 +97,7 @@ F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c f270a7996e30ef997500f2447d4c4a27b8809f0c F src/shell.c f270a7996e30ef997500f2447d4c4a27b8809f0c
F src/sqlite.h.in 2931f7ee2415e7a49fd12f386c23575046f0f540 F src/sqlite.h.in 2931f7ee2415e7a49fd12f386c23575046f0f540
F src/sqlite3ext.h 2c2156cc32a158e2b7bd9042d42accf94bff2e40 F src/sqlite3ext.h 2c2156cc32a158e2b7bd9042d42accf94bff2e40
F src/sqliteInt.h 28d060f44a4a3ad1acb47bf1cef627c86ec45f5f F src/sqliteInt.h 90dad3c0ba7a5151c48361748ccdada9ff2eff78
F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06 F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06
F src/tclsqlite.c d344c7f394d6f055ce3abfe0049b0480c5e34e56 F src/tclsqlite.c d344c7f394d6f055ce3abfe0049b0480c5e34e56
F src/test1.c 19786ff3274635b6eac27a89f842416f388f3654 F src/test1.c 19786ff3274635b6eac27a89f842416f388f3654
@@ -423,7 +423,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 6fdbd3bc91559ed95314842c0df33adbf276913e P cca1eb3dfaa67d64ced3e49e7ddbd8db27a5526a
R e7de2524dae8a72c2a984557a03085a8 R 2fa316d910e96d33fb975864696b955f
U drh U drh
Z 1e53dd9350f81249053a0f45ab30c9e6 Z a6682a31d2f426580df4abfdbb85f6ad

View File

@@ -1 +1 @@
cca1eb3dfaa67d64ced3e49e7ddbd8db27a5526a a1bcc6de578992b28924c1cf974ea58251454e2d

View File

@@ -217,38 +217,6 @@ const sqlite3_api_routines sqlite3_apis = {
sqlite3_overload_function, sqlite3_overload_function,
}; };
/*
** The windows implementation of shared-library loaders
*/
#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || defined(__BORLANDC__)
# include <windows.h>
# define SQLITE_LIBRARY_TYPE HANDLE
# ifdef _WIN32_WCE
static HANDLE loadLibraryUtf8(const char *z){
WCHAR zWide[MAX_PATH];
MultiByteToWideChar(CP_ACP,0,z,-1,zWide,MAX_PATH);
return LoadLibrary(zWide);
}
# define SQLITE_OPEN_LIBRARY(A) loadLibraryUtf8(A)
# define SQLITE_FIND_SYMBOL(A,B) GetProcAddressA(A,B)
# else
# define SQLITE_OPEN_LIBRARY(A) LoadLibrary(A)
# define SQLITE_FIND_SYMBOL(A,B) GetProcAddress(A,B)
# endif
# define SQLITE_CLOSE_LIBRARY(A) FreeLibrary(A)
#endif /* windows */
/*
** The unix implementation of shared-library loaders
*/
#if defined(HAVE_DLOPEN) && !defined(SQLITE_LIBRARY_TYPE)
# include <dlfcn.h>
# define SQLITE_LIBRARY_TYPE void*
# define SQLITE_OPEN_LIBRARY(A) dlopen(A, RTLD_NOW | RTLD_GLOBAL)
# define SQLITE_FIND_SYMBOL(A,B) dlsym(A,B)
# define SQLITE_CLOSE_LIBRARY(A) dlclose(A)
#endif
/* /*
** Attempt to load an SQLite extension library contained in the file ** Attempt to load an SQLite extension library contained in the file
** zFile. The entry point is zProc. zProc may be 0 in which case a ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -267,11 +235,10 @@ int sqlite3_load_extension(
const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */ const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
char **pzErrMsg /* Put error message here if not 0 */ char **pzErrMsg /* Put error message here if not 0 */
){ ){
#ifdef SQLITE_LIBRARY_TYPE void *handle;
SQLITE_LIBRARY_TYPE handle;
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
char *zErrmsg = 0; char *zErrmsg = 0;
SQLITE_LIBRARY_TYPE *aHandle; void **aHandle;
/* Ticket #1863. To avoid a creating security problems for older /* Ticket #1863. To avoid a creating security problems for older
** applications that relink against newer versions of SQLite, the ** applications that relink against newer versions of SQLite, the
@@ -290,7 +257,7 @@ int sqlite3_load_extension(
zProc = "sqlite3_extension_init"; zProc = "sqlite3_extension_init";
} }
handle = SQLITE_OPEN_LIBRARY(zFile); handle = sqlite3OsDlopen(zFile);
if( handle==0 ){ if( handle==0 ){
if( pzErrMsg ){ if( pzErrMsg ){
*pzErrMsg = sqlite3_mprintf("unable to open shared library [%s]", zFile); *pzErrMsg = sqlite3_mprintf("unable to open shared library [%s]", zFile);
@@ -298,20 +265,20 @@ int sqlite3_load_extension(
return SQLITE_ERROR; return SQLITE_ERROR;
} }
xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
SQLITE_FIND_SYMBOL(handle, zProc); sqlite3OsDlsym(handle, zProc);
if( xInit==0 ){ if( xInit==0 ){
if( pzErrMsg ){ if( pzErrMsg ){
*pzErrMsg = sqlite3_mprintf("no entry point [%s] in shared library [%s]", *pzErrMsg = sqlite3_mprintf("no entry point [%s] in shared library [%s]",
zProc, zFile); zProc, zFile);
} }
SQLITE_CLOSE_LIBRARY(handle); sqlite3OsDlclose(handle);
return SQLITE_ERROR; return SQLITE_ERROR;
}else if( xInit(db, &zErrmsg, &sqlite3_apis) ){ }else if( xInit(db, &zErrmsg, &sqlite3_apis) ){
if( pzErrMsg ){ if( pzErrMsg ){
*pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg); *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
} }
sqlite3_free(zErrmsg); sqlite3_free(zErrmsg);
SQLITE_CLOSE_LIBRARY(handle); sqlite3OsDlclose(handle);
return SQLITE_ERROR; return SQLITE_ERROR;
} }
@@ -327,14 +294,8 @@ int sqlite3_load_extension(
sqliteFree(db->aExtension); sqliteFree(db->aExtension);
db->aExtension = aHandle; db->aExtension = aHandle;
((SQLITE_LIBRARY_TYPE*)db->aExtension)[db->nExtension-1] = handle; db->aExtension[db->nExtension-1] = handle;
return SQLITE_OK; return SQLITE_OK;
#else
if( pzErrMsg ){
*pzErrMsg = sqlite3_mprintf("extension loading is disabled");
}
return SQLITE_ERROR;
#endif
} }
/* /*
@@ -342,13 +303,11 @@ int sqlite3_load_extension(
** to clean up loaded extensions ** to clean up loaded extensions
*/ */
void sqlite3CloseExtensions(sqlite3 *db){ void sqlite3CloseExtensions(sqlite3 *db){
#ifdef SQLITE_LIBRARY_TYPE
int i; int i;
for(i=0; i<db->nExtension; i++){ for(i=0; i<db->nExtension; i++){
SQLITE_CLOSE_LIBRARY(((SQLITE_LIBRARY_TYPE*)db->aExtension)[i]); sqlite3OsDlclose(db->aExtension[i]);
} }
sqliteFree(db->aExtension); sqliteFree(db->aExtension);
#endif
} }
/* /*

View File

@@ -122,6 +122,9 @@
#define sqlite3OsRealloc sqlite3GenericRealloc #define sqlite3OsRealloc sqlite3GenericRealloc
#define sqlite3OsFree sqlite3GenericFree #define sqlite3OsFree sqlite3GenericFree
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize #define sqlite3OsAllocationSize sqlite3GenericAllocationSize
#define sqlite3OsDlopen sqlite3UnixDlopen
#define sqlite3OsDlsym sqlite3UnixDlsym
#define sqlite3OsDlclose sqlite3UnixDlclose
#endif #endif
#if OS_WIN #if OS_WIN
#define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite #define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite
@@ -144,6 +147,9 @@
#define sqlite3OsRealloc sqlite3GenericRealloc #define sqlite3OsRealloc sqlite3GenericRealloc
#define sqlite3OsFree sqlite3GenericFree #define sqlite3OsFree sqlite3GenericFree
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize #define sqlite3OsAllocationSize sqlite3GenericAllocationSize
#define sqlite3OsDlopen sqlite3WinDlopen
#define sqlite3OsDlsym sqlite3WinDlsym
#define sqlite3OsDlclose sqlite3WinDlclose
#endif #endif
#if OS_OS2 #if OS_OS2
#define sqlite3OsOpenReadWrite sqlite3Os2OpenReadWrite #define sqlite3OsOpenReadWrite sqlite3Os2OpenReadWrite
@@ -166,6 +172,9 @@
#define sqlite3OsRealloc sqlite3GenericRealloc #define sqlite3OsRealloc sqlite3GenericRealloc
#define sqlite3OsFree sqlite3GenericFree #define sqlite3OsFree sqlite3GenericFree
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize #define sqlite3OsAllocationSize sqlite3GenericAllocationSize
#define sqlite3OsDlopen sqlite3Os2Dlopen
#define sqlite3OsDlsym sqlite3Os2Dlsym
#define sqlite3OsDlclose sqlite3Os2Dlclose
#endif #endif
@@ -349,6 +358,9 @@ void *sqlite3OsMalloc(int);
void *sqlite3OsRealloc(void *, int); void *sqlite3OsRealloc(void *, int);
void sqlite3OsFree(void *); void sqlite3OsFree(void *);
int sqlite3OsAllocationSize(void *); int sqlite3OsAllocationSize(void *);
void *sqlite3OsDlopen(const char*);
void *sqlite3OsDlsym(void*, const char*);
int sqlite3OsDlclose(void*);
/* /*
** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer ** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
@@ -393,16 +405,26 @@ struct sqlite3OsVtbl {
void *(*xRealloc)(void *, int); void *(*xRealloc)(void *, int);
void (*xFree)(void *); void (*xFree)(void *);
int (*xAllocationSize)(void *); int (*xAllocationSize)(void *);
void *(*xDlopen)(const char*);
void *(*xDlsym)(void*, const char*);
int (*xDlclose)(void*);
}; };
/* Macro used to comment out routines that do not exists when there is /* Macro used to comment out routines that do not exists when there is
** no disk I/O ** no disk I/O or extension loading
*/ */
#ifdef SQLITE_OMIT_DISKIO #ifdef SQLITE_OMIT_DISKIO
# define IF_DISKIO(X) 0 # define IF_DISKIO(X) 0
#else #else
# define IF_DISKIO(X) X # define IF_DISKIO(X) X
#endif #endif
#ifdef SQLITE_OMIT_LOAD_EXTENSION
# define IF_DLOPEN(X) 0
#else
# define IF_DLOPEN(X) X
#endif
#ifdef _SQLITE_OS_C_ #ifdef _SQLITE_OS_C_
/* /*
@@ -428,7 +450,10 @@ struct sqlite3OsVtbl {
sqlite3OsMalloc, sqlite3OsMalloc,
sqlite3OsRealloc, sqlite3OsRealloc,
sqlite3OsFree, sqlite3OsFree,
sqlite3OsAllocationSize sqlite3OsAllocationSize,
IF_DLOPEN( sqlite3OsDlopen ),
IF_DLOPEN( sqlite3OsDlsym ),
IF_DLOPEN( sqlite3OsDlclose ),
}; };
#else #else
/* /*

View File

@@ -768,6 +768,23 @@ int allocateOs2File( os2File *pInit, OsFile **pld ){
** with other miscellanous aspects of the operating system interface ** with other miscellanous aspects of the operating system interface
****************************************************************************/ ****************************************************************************/
#ifndef SQLITE_OMIT_LOAD_EXTENSION
/*
** Interfaces for opening a shared library, finding entry points
** within the shared library, and closing the shared library.
*/
void *sqlite3Os2Dlopen(const char *zFilename){
return 0;
}
void *sqlite3Os2Dlsym(void *pHandle, const char *zSymbol){
return 0;
}
int sqlite3Os2Dlclose(void *pHandle){
return 0;
}
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
/* /*
** Get information to seed the random number generator. The seed ** Get information to seed the random number generator. The seed
** is written into the buffer zBuf[256]. The calling function must ** is written into the buffer zBuf[256]. The calling function must

View File

@@ -2581,6 +2581,23 @@ static int allocateUnixFile(
****************************************************************************/ ****************************************************************************/
#ifndef SQLITE_OMIT_LOAD_EXTENSION
/*
** Interfaces for opening a shared library, finding entry points
** within the shared library, and closing the shared library.
*/
#include <dlfcn.h>
void *sqlite3UnixDlopen(const char *zFilename){
return dlopen(zFilename, RTLD_NOW | RTLD_GLOBAL);
}
void *sqlite3UnixDlsym(void *pHandle, const char *zSymbol){
return dlsym(pHandle, zSymbol);
}
int sqlite3UnixDlclose(void *pHandle){
return dlclose(pHandle);
}
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
/* /*
** Get information to seed the random number generator. The seed ** Get information to seed the random number generator. The seed
** is written into the buffer zBuf[256]. The calling function must ** is written into the buffer zBuf[256]. The calling function must

View File

@@ -1498,6 +1498,38 @@ static int allocateWinFile(winFile *pInit, OsFile **pId){
** with other miscellanous aspects of the operating system interface ** with other miscellanous aspects of the operating system interface
****************************************************************************/ ****************************************************************************/
#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
/*
** Interfaces for opening a shared library, finding entry points
** within the shared library, and closing the shared library.
*/
void *sqlite3WinDlopen(const char *zFilename){
HANDLE h;
void *zConverted = convertUtf8Filename(zFilename);
if( zConverted==0 ){
return 0;
}
if( isNT() ){
h = LoadLibraryW(zConverted);
}else{
#if OS_WINCE
return SQLITE_NOMEM;
#else
h = LoadLibraryA(zConverted);
#endif
}
sqliteFree(zConverted);
return (void*)h;
}
void *sqlite3WinDlsym(void *pHandle, const char *zSymbol){
return GetProcAddress((HANDLE)pHandle, zSymbol);
}
int sqlite3WinDlclose(void *pHandle){
return FreeLibrary((HANDLE)pHandle);
}
#endif /* !SQLITE_OMIT_LOAD_EXTENSION */
/* /*
** Get information to seed the random number generator. The seed ** Get information to seed the random number generator. The seed
** is written into the buffer zBuf[256]. The calling function must ** is written into the buffer zBuf[256]. The calling function must

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** Internal interface definitions for SQLite. ** Internal interface definitions for SQLite.
** **
** @(#) $Id: sqliteInt.h,v 1.531 2006/12/16 16:25:16 drh Exp $ ** @(#) $Id: sqliteInt.h,v 1.532 2006/12/21 01:29:23 drh Exp $
*/ */
#ifndef _SQLITEINT_H_ #ifndef _SQLITEINT_H_
#define _SQLITEINT_H_ #define _SQLITEINT_H_
@@ -463,7 +463,7 @@ struct sqlite3 {
u8 busy; /* TRUE if currently initializing */ u8 busy; /* TRUE if currently initializing */
} init; } init;
int nExtension; /* Number of loaded extensions */ int nExtension; /* Number of loaded extensions */
void *aExtension; /* Array of shared libraray handles */ void **aExtension; /* Array of shared libraray handles */
struct Vdbe *pVdbe; /* List of active virtual machines */ struct Vdbe *pVdbe; /* List of active virtual machines */
int activeVdbeCnt; /* Number of vdbes currently executing */ int activeVdbeCnt; /* Number of vdbes currently executing */
void (*xTrace)(void*,const char*); /* Trace function */ void (*xTrace)(void*,const char*); /* Trace function */