The default entry point for loadable extensions is now

always sqlite3_extension_init(). (CVS 3268)

FossilOrigin-Name: 059b1f61406ca60fdbd3ec59c5b15fadc6552564
This commit is contained in:
drh 2006-06-17 13:21:32 +00:00
parent e7ff403ab1
commit 428397c143
5 changed files with 46 additions and 74 deletions

View File

@ -1,5 +1,5 @@
C Add\snewly\screated\svirtual\stables\sto\sthe\scurrent\stransaction.\s(CVS\s3267)
D 2006-06-17T11:30:32
C The\sdefault\sentry\spoint\sfor\sloadable\sextensions\sis\snow\nalways\ssqlite3_extension_init().\s(CVS\s3268)
D 2006-06-17T13:21:32
F Makefile.in f839b470345d3cb4b0644068474623fe2464b5d3
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -48,7 +48,7 @@ F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185
F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
F src/insert.c 5c1fddd7e4d05805e02e12bdced2a3841d2bd8dc
F src/legacy.c fa15d505dd4e45044177ee4d1c6aeaf8c836d390
F src/loadext.c 676257ae268457e7f03261d8ca0d1e72968a26c8
F src/loadext.c 3a730b22dfb6ba2c261848c72fb96a5c3195defd
F src/main.c 7101314a365120465bf5e308caaf518b7776430c
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/os.c 59f05de8c5777c34876607114a2fbe55ae578235
@ -88,7 +88,7 @@ F src/test8.c 9641e41a7d35588fc0a834439b6c404700e7c148
F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
F src/test_schema.c 3b9fb30f0fed8297097c9b7bd3df484d0cd5e639
F src/test_schema.c 7026296434de0c3c531c0eb65f8990555575a764
F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c
F src/test_tclvar.c c52f67fbe06d32804af2ba9a2d7aadfc15f5910c
F src/tokenize.c 6ebcafa6622839968dda4418a7b6945f277a128f
@ -196,7 +196,7 @@ F test/lastinsert.test 9d7241f562d7adcf61730de83176417d7e30d76b
F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17
F test/like.test 5f7d76574752a9101cac13372c8a85999d0d91e6
F test/limit.test 71884068d47b18f614735f0686690319b32cdc22
F test/loadext.test 1704f48b39ba6d9d15b46bf0c0eb1ea82fb06f1f
F test/loadext.test 30b38ddaf4ca0703833903bf8ab2e9a680d9cfeb
F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107
F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
@ -370,7 +370,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P ca541ef3c464c5627596a48ee7f1ec40948cf65d
R faa9d9cb2a77be8fd7c7ebc5ab33c027
U danielk1977
Z 34ba78ce8d03975fc32264aceaa96871
P ea7e4eca106cea27d5dc447d2afcd45448152151
R 02aad4e8db5989bcc93408708ac41194
U drh
Z 306df56e80d8ad47056ba5abd005e0af

View File

@ -1 +1 @@
ea7e4eca106cea27d5dc447d2afcd45448152151
059b1f61406ca60fdbd3ec59c5b15fadc6552564

View File

@ -197,37 +197,20 @@ const sqlite3_api_routines sqlite3_api = {
/*
** Attempt to load an SQLite extension library contained in the file
** zFile. The entry point is zProc. zProc may be 0 in which case the
** name of the entry point is derived from the filename.
** zFile. The entry point is zProc. zProc may be 0 in which case a
** default entry point name (sqlite3_extension_init) is used. Use
** of the default name is recommended.
**
** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
**
** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
** error message text. The calling function should free this memory
** by calling sqlite3_free().
**
** The entry point name is derived from the filename according to the
** following steps:
**
** * Convert the name to lower case
** * Remove the path prefix from the name
** * Remove the first "." and all following characters from the name
** * If the name begins with "lib" remove the first 3 characters
** * Remove all characters that are not US-ASCII alphanumerics
** or underscores
** * Remove any leading digits and underscores from the name
** * Append "_init" to the name
**
** So, for example, if the input filename is "/home/drh/libtest1.52.so"
** then the entry point would be computed as "test1_init".
**
** The derived entry point name is limited to a reasonable number of
** characters (currently 200).
*/
int sqlite3_load_extension(
sqlite3 *db, /* Load the extension into this database connection */
const char *zFile, /* Name of the shared library containing extension */
const char *zProc, /* Entry point. Derived from zFile if 0 */
const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
char **pzErrMsg /* Put error message here if not 0 */
){
#ifdef SQLITE_LIBRARY_TYPE
@ -237,30 +220,7 @@ int sqlite3_load_extension(
SQLITE_LIBRARY_TYPE *aHandle;
if( zProc==0 ){
int i, j, n;
char *z;
char zBuf[200];
n = strlen(zFile);
for(i=n-1; i>0 && zFile[i-1]!='/'; i--){}
for(j=i; zFile[j] && zFile[j]!='.'; j++){}
if( j-i > sizeof(zBuf)-10 ) j = i + sizeof(zBuf) - 10;
memcpy(zBuf, &zFile[i], j - i);
zBuf[j - i] = 0;
z = zBuf;
for(i=j=0; z[i]; i++){
int c = z[i];
if( (c & 0x80)!=0 || (!isalnum(c) && c!='_') ) continue;
z[j++] = tolower(c);
}
z[j] = 0;
if( strncmp(z, "lib", 3)==0 ){
z += 3;
}
while( z[0] && !isalpha(z[0]) ){
z++;
}
strcat(z, "_init");
zProc = z;
zProc = "sqlite3_extension_init";
}
handle = SQLITE_OPEN_LIBRARY(zFile);

View File

@ -13,12 +13,12 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test_schema.c,v 1.3 2006/06/16 06:17:47 danielk1977 Exp $
** $Id: test_schema.c,v 1.4 2006/06/17 13:21:33 drh Exp $
*/
/* The code in this file defines a sqlite3 module that provides
** a read-only view of the current database schema. There is one
** row in the schema table for each column in the database.
/* The code in this file defines a sqlite3 virtual-table module that
** provides a read-only view of the current database schema. There is one
** row in the schema table for each column in the database schema.
*/
#define SCHEMA \
"CREATE TABLE x(" \
@ -332,7 +332,7 @@ int Sqlitetestschema_Init(Tcl_Interp *interp){
/*
** Extension load function.
*/
int schema_init(
int sqlite3_extension_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi

View File

@ -11,21 +11,34 @@
# This file implements regression tests for SQLite library. The
# focus of this script is in-memory database backend.
#
# $Id: loadext.test,v 1.1 2006/06/14 10:38:03 danielk1977 Exp $
# $Id: loadext.test,v 1.2 2006/06/17 13:21:33 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# The name of the test extension varies by operating system.
#
if {$::tcl_platform(platform) eq "windows"} {
set testextension testloadext.dll
set testextension ./testloadext.dll
} else {
set testextension libtestloadext.so
set testextension ./libtestloadext.so
}
# Make sure the test extension actually exists. If it does not
# exist, try to create it. If unable to create it, then skip this
# test file.
#
if {![file exists $testextension]} {
puts "Skipping loadext tests: Test extension not built..."
finish_test
return
set srcdir [file dir $testdir]/src
set testextsrc $srcdir/test_loadext.c
if {[catch {
exec gcc -shared $testextsrc -o $testextension
} msg]} {
puts "Skipping loadext tests: Test extension not built..."
puts $msg
finish_test
return
}
}
# Test that loading the extension produces the expected results - adding
@ -37,7 +50,7 @@ do_test loadext-1.1 {
}
} {1 {no such function: half}}
do_test loadext-1.2 {
sqlite3_load_extension db $testextension
sqlite3_load_extension db $testextension testloadext_init
catchsql {
SELECT half(1.0);
}
@ -52,7 +65,7 @@ do_test loadext-1.3 {
} db2
} {1 {no such function: half}}
do_test loadext-1.4 {
sqlite3_load_extension db2 $testextension
sqlite3_load_extension db2 $testextension testloadext_init
catchsql {
SELECT half(1.0);
} db2
@ -75,25 +88,25 @@ sqlite3 db test.db
#
do_test loadext-2.1 {
set rc [catch {
sqlite3_load_extension db "xx${testextension}"
sqlite3_load_extension db "${testextension}xx"
} msg]
list $rc $msg
} [list 1 [subst -nocommands \
{unable to open shared library [xx${testextension}]}
{unable to open shared library [${testextension}xx]}
]]
# Try to load an extension for which the file is not a shared object
#
do_test loadext-2.2 {
set fd [open "xx${testextension}" w]
set fd [open "${testextension}xx" w]
puts $fd blah
close $fd
set rc [catch {
sqlite3_load_extension db "xx${testextension}"
sqlite3_load_extension db "${testextension}xx"
} msg]
list $rc $msg
} [list 1 [subst -nocommands \
{unable to open shared library [xx${testextension}]}
{unable to open shared library [${testextension}xx]}
]]
# Try to load an extension for which the file is present but the
@ -118,4 +131,3 @@ do_test loadext-2.4 {
} {1 {error during initialization: broken!}}
finish_test