alien.libraries.finder: Make find-library return the string passed in instead of f if the library is not found. We want vocabularies to load no matter what instead of throwing a missing library error. Also, print dlerror in the error message and take away the redundant line about possible missing libraries. Fixes #986.

db4
Doug Coleman 2014-06-07 20:48:09 -07:00
parent a88310438e
commit d10443186c
6 changed files with 26 additions and 24 deletions

View File

@ -1,9 +1,11 @@
USING: combinators system vocabs ; USING: combinators kernel system vocabs alien.libraries ;
IN: alien.libraries.finder IN: alien.libraries.finder
HOOK: find-library os ( name -- path/f ) HOOK: find-library* os ( name -- path/f )
: find-library ( name -- path/library-not-found )
dup find-library* [ nip ] when* ;
{ {
{ [ os macosx? ] [ "alien.libraries.finder.macosx" ] } { [ os macosx? ] [ "alien.libraries.finder.macosx" ] }

View File

@ -35,7 +35,7 @@ CONSTANT: mach-map {
PRIVATE> PRIVATE>
M: linux find-library M: linux find-library*
"lib" ".so" surround ldconfig-find-soname [ "lib" ".so" surround ldconfig-find-soname [
{ [ exists? ] [ file-info regular-file? ] } 1&& { [ exists? ] [ file-info regular-file? ] } 1&&
] map-find nip ; ] map-find nip ;

View File

@ -128,7 +128,7 @@ PRIVATE>
] if* file-name append-path dyld-find ] if* file-name append-path dyld-find
] if* ; ] if* ;
M: macosx find-library M: macosx find-library*
[ "lib" ".dylib" surround ] [ "lib" ".dylib" surround ]
[ ".dylib" append ] [ ".dylib" append ]
[ ".framework/" over 3append ] tri 3array [ ".framework/" over 3append ] tri 3array

View File

@ -26,7 +26,7 @@ IN: alien.libraries.finder.windows
PRIVATE> PRIVATE>
M: windows find-library M: windows find-library*
candidate-paths [ candidate-paths [
{ [ exists? ] [ file-info regular-file? ] } 1&& { [ exists? ] [ file-info regular-file? ] } 1&&
] map-find nip ; ] map-find nip ;

View File

@ -23,8 +23,6 @@ C: <library> library
ERROR: no-library name ; ERROR: no-library name ;
ERROR: library-path-is-f name path abi ;
: lookup-library ( name -- library ) libraries get at ; : lookup-library ( name -- library ) libraries get at ;
: open-dll ( path -- dll dll-error/f ) : open-dll ( path -- dll dll-error/f )
@ -34,10 +32,6 @@ ERROR: library-path-is-f name path abi ;
: make-library ( path abi -- library ) : make-library ( path abi -- library )
[ dup open-dll ] dip <library> ; [ dup open-dll ] dip <library> ;
: try-make-library ( name path abi -- library )
over [ [ nip ] dip ] [ library-path-is-f ] if
make-library ;
: library-dll ( library -- dll ) : library-dll ( library -- dll )
dup [ dll>> ] when ; dup [ dll>> ] when ;
@ -58,7 +52,7 @@ M: library dispose dll>> [ dispose ] when* ;
: add-library ( name path abi -- ) : add-library ( name path abi -- )
3dup add-library? [ 3dup add-library? [
[ 2drop remove-library ] [ 2drop remove-library ]
[ try-make-library ] [ [ nip ] dip make-library ]
[ 2drop libraries get set-at ] 3tri [ 2drop libraries get set-at ] 3tri
] [ 3drop ] if ; ] [ 3drop ] if ;

View File

@ -2,14 +2,14 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.strings arrays assocs classes USING: accessors alien.strings arrays assocs classes
classes.builtin classes.mixin classes.tuple classes.tuple.parser classes.builtin classes.mixin classes.tuple classes.tuple.parser
combinators combinators.short-circuit compiler.units combinators combinators.short-circuit compiler.errors
continuations definitions destructors effects.parser generic compiler.units continuations definitions destructors
generic.math generic.parser generic.single grouping io effects.parser fry generic generic.math generic.parser
io.encodings io.styles kernel kernel.private lexer make math generic.single grouping io io.encodings io.styles kernel
math.order math.parser namespaces parser prettyprint sequences kernel.private lexer make math math.order math.parser namespaces
sequences.private slots source-files.errors strings parser prettyprint sequences sequences.private slots
strings.parser summary system vocabs vocabs.loader source-files.errors strings strings.parser summary system vocabs
vocabs.parser words ; vocabs.loader vocabs.parser words ;
FROM: namespaces => change-global ; FROM: namespaces => change-global ;
IN: debugger IN: debugger
@ -110,11 +110,17 @@ HOOK: signal-error. os ( obj -- )
: ffi-error. ( obj -- ) : ffi-error. ( obj -- )
"FFI error" print drop ; "FFI error" print drop ;
: find-ffi-error ( string -- error )
[ linkage-errors get ] dip
'[ nip asset>> name>> _ = ] assoc-find drop nip
[ error>> message>> ] [ "none" ] if* ;
: undefined-symbol-error. ( obj -- ) : undefined-symbol-error. ( obj -- )
"Cannot resolve C library function" print "Cannot resolve C library function" print
"Symbol: " write dup third symbol>string print "Library: " write dup fourth .
"Library: " write fourth . third symbol>string
"You are probably missing a library or the library path is wrong." print [ "Symbol: " write print ]
[ "DlError: " write find-ffi-error print ] bi
"See http://concatenative.org/wiki/view/Factor/Requirements" print ; "See http://concatenative.org/wiki/view/Factor/Requirements" print ;
: stack-underflow. ( obj name -- ) : stack-underflow. ( obj name -- )