alien.libraries: load-library is misnamed, refactor library-dll.

load-library implies that dlopen() is called, which is totally not the
case. add-library calls dlopen() and load-library just looks the opened
library up in the ``libraries`` global. What load-library did is now
library-dll.

If we want to do it right, add-library should be a declarative top-level
form that tries to call a real load-library on demand instead of
memoizing the first try which would fix the case where the library is
not found, is moved into position by the user and Factor declines to
look it up again.
windows-high-dpi
Doug Coleman 2018-02-19 10:34:06 -06:00
parent 75b0289e74
commit 310a4a247c
5 changed files with 17 additions and 13 deletions

View File

@ -38,7 +38,7 @@ HELP: dlopen
{ $values { "path" "a pathname string" } { "dll" "a DLL handle" } }
{ $description "Opens a native library and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } "." }
{ $errors "Throws an error if the library could not be found, or if loading fails for some other reason." }
{ $notes "This is the low-level facility used to implement " { $link load-library } ". Use the latter instead." } ;
{ $notes "This is the low-level facility used to implement " { $link add-library } ". Use the latter instead." } ;
HELP: dlsym
{ $values { "name" "a C symbol name" } { "dll" "a DLL handle" } { "alien" { $maybe alien } } }
@ -72,9 +72,9 @@ HELP: library
}
} ;
HELP: load-library
HELP: library-dll
{ $values { "name" string } { "dll" "a DLL handle" } }
{ $description "Loads a library by logical name and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } ". If the library is already loaded, returns the existing handle." } ;
{ $description "Looks up a library by logical name and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } "." } ;
HELP: remove-library
{ $values { "name" string } }
@ -86,8 +86,8 @@ ARTICLE: "loading-libs" "Loading native libraries"
add-library
remove-library
}
"Once a library has been defined, you can try loading it to see if the path name is correct:"
{ $subsections load-library }
"Once a library has been defined, you can see if the library has correctly loaded:"
{ $subsections library-dll }
"If the compiler cannot load a library, or cannot resolve a symbol in a library, a linkage error is reported using the compiler error mechanism (see " { $link "compiler-errors" } "). Once you install the right library, reload the source file containing the " { $link add-library } " form to force the compiler to try loading the library again."
$nl
"Libraries that do not come standard with the operating system need to be included with deployed applications that use them. A word is provided to instruct " { $link "tools.deploy" } " that a library must be so deployed:"

View File

@ -36,14 +36,18 @@ C: <library> library
: make-library ( path abi -- library )
[ dup open-dll ] dip <library> ;
: library-dll ( library -- dll )
GENERIC: library-dll ( obj -- dll )
M: f library-dll ;
M: library library-dll
dup [ dll>> ] when ;
: load-library ( name -- dll )
M: string library-dll ( library -- dll )
lookup-library library-dll ;
: dlsym? ( function library -- alien/f )
load-library dlsym ;
library-dll dlsym ;
M: dll dispose dlclose ;
@ -84,7 +88,7 @@ M: library dispose dll>> [ dispose ] when* ;
lookup-library [ abi>> ] [ cdecl ] if* ;
: address-of ( name library -- value )
2dup load-library dlsym-raw
2dup library-dll dlsym-raw
[ 2nip ] [ no-such-symbol ] if* ;
SYMBOL: deploy-libraries

View File

@ -132,7 +132,7 @@ unit-test
int { int int int int } stdcall alien-indirect
gc ;
[ f ] [ "f-stdcall" load-library f = ] unit-test
[ f ] [ "f-stdcall" library-dll f = ] unit-test
[ stdcall ] [ "f-stdcall" lookup-library abi>> ] unit-test
: ffi_test_18 ( w x y z -- int )
@ -642,7 +642,7 @@ os windows? [
[ ] [ assembly-test-1 ] unit-test
[ f ] [ "f-fastcall" load-library f = ] unit-test
[ f ] [ "f-fastcall" library-dll f = ] unit-test
[ fastcall ] [ "f-fastcall" lookup-library abi>> ] unit-test
: ffi_test_49 ( x -- int )

View File

@ -33,7 +33,7 @@ FUNCTION: void no_such_function ( )
${
KERNEL-ERROR ERROR-UNDEFINED-SYMBOL
"no_such_function" string>symbol
"no_such_library" load-library
"no_such_library" library-dll
}
=
] must-fail-with

View File

@ -21,7 +21,7 @@ IN: readline
current-line readline.ffi:rl_point head ;
: has-readline? ( -- ? )
"readline" dup load-library dlsym-raw >boolean ;
"readline" dup library-dll dlsym-raw >boolean ;
: set-completion ( quot -- )
[