Index: src/sqlite3ext.h ================================================================== --- src/sqlite3ext.h +++ src/sqlite3ext.h @@ -13,11 +13,11 @@ ** shared libraries that want to be imported as extensions into ** an SQLite instance. Shared libraries that intend to be loaded ** as extensions by SQLite should #include this file instead of ** sqlite3.h. ** -** @(#) $Id: sqlite3ext.h,v 1.23 2008/06/27 00:52:45 drh Exp $ +** @(#) $Id: sqlite3ext.h,v 1.24 2008/06/30 15:09:29 danielk1977 Exp $ */ #ifndef _SQLITE3EXT_H_ #define _SQLITE3EXT_H_ #include "sqlite3.h" @@ -364,9 +364,9 @@ #define sqlite3_next_stmt sqlite3_api->next_stmt #define sqlite3_sql sqlite3_api->sql #define sqlite3_status sqlite3_api->status #endif /* SQLITE_CORE */ -#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api; +#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0; #define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v; #endif /* _SQLITE3EXT_H_ */ Index: test/loadext.test ================================================================== --- test/loadext.test +++ test/loadext.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is extension loading. # -# $Id: loadext.test,v 1.12 2008/06/19 15:44:00 drh Exp $ +# $Id: loadext.test,v 1.13 2008/06/30 15:09:29 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl ifcapable !load_ext { @@ -26,10 +26,14 @@ if {$::tcl_platform(platform) eq "windows"} { set testextension ./testloadext.dll } else { set testextension ./libtestloadext.so } +set gcc_shared -shared +if {$::tcl_platform(os) eq "Darwin"} { + set gcc_shared -dynamiclib +} # The error messages tested by this file are operating system dependent # (because they are returned by sqlite3OsDlError()). For now, they only # work with UNIX (and probably only certain kinds of UNIX). # @@ -53,20 +57,27 @@ # set dlerror_nosuchfile \ {%s: cannot open shared object file: No such file or directory} set dlerror_notadll {%s: file too short} set dlerror_nosymbol {%s: undefined symbol: %s} + +if {$::tcl_platform(os) eq "Darwin"} { + set dlerror_nosuchfile {dlopen(%s, 10): image not found} + set dlerror_notadll {dlopen(%1$s, 10): no suitable image found. Did find: + %1$s: file to short} + set dlerror_nosymbol {dlsym(XXX, %2$s): symbol not found} +} # 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]} { set srcdir [file dir $testdir]/src set testextsrc $srcdir/test_loadext.c if {[catch { - exec gcc -Wall -I$srcdir -I. -g -shared $testextsrc -o $testextension + exec gcc $gcc_shared -Wall -I$srcdir -I. -g $testextsrc -o $testextension } msg]} { puts "Skipping loadext tests: Test extension not built..." puts $msg finish_test return @@ -146,10 +157,13 @@ # do_test loadext-2.3 { set rc [catch { sqlite3_load_extension db $testextension icecream } msg] + if {$::tcl_platform(os) eq "Darwin"} { + regsub {0x[1234567890abcdefABCDEF]*} $msg XXX msg + } list $rc $msg } [list 1 [format $dlerror_nosymbol $testextension icecream]] # Try to load an extension for which the entry point fails (returns non-zero) # @@ -171,13 +185,17 @@ catchsql { SELECT half(5); } } {1 {no such function: half}} do_test loadext-3.2 { - catchsql { + set res [catchsql { SELECT load_extension($::testextension) + }] + if {$::tcl_platform(os) eq "Darwin"} { + regsub {0x[1234567890abcdefABCDEF]*} $res XXX res } + set res } [list 1 [format $dlerror_nosymbol $testextension sqlite3_extension_init]] do_test loadext-3.3 { catchsql { SELECT load_extension($::testextension,'testloadext_init') }