diff --git a/basis/alien/libraries/libraries-docs.factor b/basis/alien/libraries/libraries-docs.factor index 741a5be60c..366cc91da6 100644 --- a/basis/alien/libraries/libraries-docs.factor +++ b/basis/alien/libraries/libraries-docs.factor @@ -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:" diff --git a/basis/alien/libraries/libraries.factor b/basis/alien/libraries/libraries.factor index 0f95141e2d..2365e0ee42 100755 --- a/basis/alien/libraries/libraries.factor +++ b/basis/alien/libraries/libraries.factor @@ -36,14 +36,18 @@ C: library : make-library ( path abi -- library ) [ dup open-dll ] dip ; -: 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 diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index 4d8a37a71e..08fdcf8761 100755 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -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 ) diff --git a/basis/compiler/tests/linkage-errors.factor b/basis/compiler/tests/linkage-errors.factor index 1b60462aa2..e5f3d21c9a 100644 --- a/basis/compiler/tests/linkage-errors.factor +++ b/basis/compiler/tests/linkage-errors.factor @@ -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 diff --git a/extra/readline/readline.factor b/extra/readline/readline.factor index 75a90545b5..bbad24a074 100644 --- a/extra/readline/readline.factor +++ b/extra/readline/readline.factor @@ -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 -- ) [