]> gitweb.factorcode.org Git - factor.git/commitdiff
alien.libraries: load-library is misnamed, refactor library-dll.
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 19 Feb 2018 16:34:06 +0000 (10:34 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 19 Feb 2018 16:38:21 +0000 (10:38 -0600)
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.

basis/alien/libraries/libraries-docs.factor
basis/alien/libraries/libraries.factor
basis/compiler/tests/alien.factor
basis/compiler/tests/linkage-errors.factor
extra/readline/readline.factor

index 741a5be60c802be38ffd7cf018ea0c6a97463dad..366cc91da6c2941d407499dcdaebdc2391e121b6 100644 (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:"
index 0f95141e2d58e64d4a05e6a4ae5eae280de06af9..2365e0ee426100ceafdd439ba1d149a2380acab8 100755 (executable)
@@ -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
index 4d8a37a71e5818acc43d92ba9d03998779b997eb..08fdcf87611768b12b78d38eea45708c4b3bbccd 100755 (executable)
@@ -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 )
index 1b60462aa22f5a922f126e9c352a87f0a7cc7e8d..e5f3d21c9a0521dec39bca04a7ac5f52878b235a 100644 (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
index 75a90545b5383790ea8f62f55a519bb0ec4b14f8..bbad24a074e71e46fca69c231ce26245e338addb 100644 (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 -- )
     [