From a9ac7639125f6a90d7ab69e65607bd8feb7b41b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Wed, 30 Nov 2016 16:34:53 +0100 Subject: [PATCH] alien.libraries: word>dlsym was a stupid idea that didn't work The def>> attribute is stripped when deploying. So return dlsym? and use that. --- basis/alien/libraries/libraries-docs.factor | 12 ++++++++---- basis/alien/libraries/libraries-tests.factor | 7 +++---- basis/alien/libraries/libraries.factor | 7 +++---- basis/images/loader/gtk/gtk.factor | 2 +- basis/io/sockets/secure/secure.factor | 6 +++--- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/basis/alien/libraries/libraries-docs.factor b/basis/alien/libraries/libraries-docs.factor index 262ff71e32..741a5be60c 100644 --- a/basis/alien/libraries/libraries-docs.factor +++ b/basis/alien/libraries/libraries-docs.factor @@ -44,6 +44,14 @@ HELP: dlsym { $values { "name" "a C symbol name" } { "dll" "a DLL handle" } { "alien" { $maybe alien } } } { $description "Looks up a symbol in a native library. If " { $snippet "dll" } " is " { $link f } " looks for the symbol in the runtime executable. If the symbol was not found, outputs " { $link f } "." } ; +HELP: dlsym? +{ $values + { "function" string } + { "library" string } + { "alien/f" { $maybe alien } } +} +{ $description "Outputs the alien dynamically loaded with the given name in the given library. If no symbol is loaded, output f." } ; + HELP: make-library { $values { "path" "a pathname string" } { "abi" "the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } } @@ -72,10 +80,6 @@ HELP: remove-library { $values { "name" string } } { $description "Unloads a library and removes it from the internal list of libraries. The " { $snippet "name" } " parameter should be a name that was previously passed to " { $link add-library } ". If no library with that name exists, this word does nothing." } ; -HELP: word>dlsym -{ $values { "word" word } { "alien/f" maybe{ alien } } } -{ $description "Takes a word which calls a C library function and outputs the address of the symbol it points to as an alien. If the symbol isn't loaded, outputs f." } ; - ARTICLE: "loading-libs" "Loading native libraries" "Before calling a C library, you must associate its path name on disk with a logical name which Factor uses to identify the library:" { $subsections diff --git a/basis/alien/libraries/libraries-tests.factor b/basis/alien/libraries/libraries-tests.factor index 33bdeaf2db..66793bf745 100755 --- a/basis/alien/libraries/libraries-tests.factor +++ b/basis/alien/libraries/libraries-tests.factor @@ -1,5 +1,4 @@ -USING: accessors alien alien.libraries alien.syntax kernel libc -tools.test ; +USING: accessors alien alien.libraries alien.syntax kernel tools.test ; IN: alien.libraries.tests { f } [ DLL" fadfasdfsada" dll-valid? ] unit-test @@ -32,7 +31,7 @@ IN: alien.libraries.tests "blah" cdecl make-library [ path>> ] [ dll>> dll-valid? ] bi ] unit-test -! word>dlsym +! dlsym? { t } [ - \ errno word>dlsym alien? + "errno" "libc" dlsym? alien? ] unit-test diff --git a/basis/alien/libraries/libraries.factor b/basis/alien/libraries/libraries.factor index 0eb4dad7ab..0f95141e2d 100755 --- a/basis/alien/libraries/libraries.factor +++ b/basis/alien/libraries/libraries.factor @@ -29,10 +29,6 @@ C: library : lookup-library ( name -- library/f ) libraries get at ; -: word>dlsym ( word -- alien/f ) - def>> [ third ] [ second dup [ lookup-library dll>> ] when ] bi - dlsym ; - : open-dll ( path -- dll dll-error/f ) [ dlopen dup dll-valid? [ f ] [ dlerror ] if ] [ f f ] if* ; @@ -46,6 +42,9 @@ C: library : load-library ( name -- dll ) lookup-library library-dll ; +: dlsym? ( function library -- alien/f ) + load-library dlsym ; + M: dll dispose dlclose ; M: library dispose dll>> [ dispose ] when* ; diff --git a/basis/images/loader/gtk/gtk.factor b/basis/images/loader/gtk/gtk.factor index 2fd2510185..88071da3f0 100644 --- a/basis/images/loader/gtk/gtk.factor +++ b/basis/images/loader/gtk/gtk.factor @@ -10,7 +10,7 @@ SPECIALIZED-ARRAY: uchar SINGLETON: gtk-image [ - os linux? \ g_type_init word>dlsym and [ + os linux? "g_type_init" "gobject" dlsym? and [ ! Explicit type initialization needed for glib < 2.36. g_type_init { "png" "tif" "tiff" "gif" "jpg" "jpeg" "bmp" "ico" } diff --git a/basis/io/sockets/secure/secure.factor b/basis/io/sockets/secure/secure.factor index 8a80c59bf9..b0f896f722 100644 --- a/basis/io/sockets/secure/secure.factor +++ b/basis/io/sockets/secure/secure.factor @@ -23,9 +23,9 @@ ERROR: no-tls-supported ; MEMO: best-tls-method ( -- class ) { - { [ \ TLSv1_2_method word>dlsym ] [ TLSv1.2 ] } - { [ \ TLSv1_1_method word>dlsym ] [ TLSv1.1 ] } - { [ \ TLSv1_method word>dlsym ] [ TLSv1 ] } + { [ "TLSv1_2_method" "libssl" dlsym? ] [ TLSv1.2 ] } + { [ "TLSv1_1_method" "libssl" dlsym? ] [ TLSv1.1 ] } + { [ "TLSv1_method" "libssl" dlsym? ] [ TLSv1 ] } [ no-tls-supported ] } cond ;