From 77f806d6c51cc2389c3f2f96ed8e9f4b6565e905 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 8 Jul 2014 12:21:50 -0500 Subject: [PATCH 1/3] alien.libraries.finder: Add find-library-from-list utility word. --- basis/alien/libraries/finder/finder.factor | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/basis/alien/libraries/finder/finder.factor b/basis/alien/libraries/finder/finder.factor index 681c605d32..5ea6640985 100644 --- a/basis/alien/libraries/finder/finder.factor +++ b/basis/alien/libraries/finder/finder.factor @@ -1,11 +1,14 @@ - -USING: combinators kernel system vocabs alien.libraries ; +USING: combinators kernel sequences system vocabs +alien.libraries ; IN: alien.libraries.finder HOOK: find-library* os ( name -- path/f ) : find-library ( name -- path/library-not-found ) dup find-library* [ nip ] when* ; + +: find-library-from-list ( seq -- path/f ) + [ find-library* ] map [ ] find nip ; { { [ os macosx? ] [ "alien.libraries.finder.macosx" ] } From 8afdafac059f515b38adf8bb447b45631cd57635 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 8 Jul 2014 12:23:11 -0500 Subject: [PATCH 2/3] gdbm.ffi: Use find-library-from-list because nobody can agree on what to name the gdbm dll. --- extra/gdbm/ffi/ffi.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/gdbm/ffi/ffi.factor b/extra/gdbm/ffi/ffi.factor index 06f96aceeb..ba22b8153e 100755 --- a/extra/gdbm/ffi/ffi.factor +++ b/extra/gdbm/ffi/ffi.factor @@ -5,7 +5,7 @@ alien.syntax classes.struct combinators kernel system ; IN: gdbm.ffi << "libgdbm" -os windows? [ "gdbm3.dll" ] [ "gdbm" find-library ] if +{ "gdbm" "gdbm3" "libgdbm-3" } find-library-from-list cdecl add-library >> LIBRARY: libgdbm From 1e8655c5c08e98f07092844a93d217778a57a2d8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 8 Jul 2014 12:40:33 -0500 Subject: [PATCH 3/3] alien.libraries.finder: More robust finder code that doesn't return f to a string slot and error out. Use it in yaml.ffi. --- basis/alien/libraries/finder/finder.factor | 8 ++++++-- extra/yaml/ffi/ffi.factor | 9 +++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/basis/alien/libraries/finder/finder.factor b/basis/alien/libraries/finder/finder.factor index 5ea6640985..8df7c748ef 100644 --- a/basis/alien/libraries/finder/finder.factor +++ b/basis/alien/libraries/finder/finder.factor @@ -6,9 +6,13 @@ HOOK: find-library* os ( name -- path/f ) : find-library ( name -- path/library-not-found ) dup find-library* [ nip ] when* ; - + +! Try to find the library from a list, but if it's not found, +! try to open a library that is the first name in that list anyway +! or "library_not_found" as a last resort for better debugging. : find-library-from-list ( seq -- path/f ) - [ find-library* ] map [ ] find nip ; + dup [ find-library* ] map + [ ] find nip [ nip ] [ ?first "library_not_found" or ] if* ; { { [ os macosx? ] [ "alien.libraries.finder.macosx" ] } diff --git a/extra/yaml/ffi/ffi.factor b/extra/yaml/ffi/ffi.factor index a2177b0572..9c74ad3567 100644 --- a/extra/yaml/ffi/ffi.factor +++ b/extra/yaml/ffi/ffi.factor @@ -3,15 +3,12 @@ ! adapted from "yaml.h" libYAML 0.1.4 ! http://pyyaml.org/wiki/LibYAML USING: alien alien.c-types alien.destructors alien.libraries -alien.syntax classes.struct combinators literals system ; +alien.syntax classes.struct combinators literals system +alien.libraries.finder ; IN: yaml.ffi << -"libyaml" { - { [ os windows? ] [ "libyaml.dll" ] } - { [ os macosx? ] [ "libyaml.dylib" ] } - { [ os unix? ] [ "libyaml.so" ] } -} cond cdecl add-library +"libyaml" { "yaml" "libyaml-0-2" } find-library-from-list cdecl add-library >> C-TYPE: FILE