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
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" ] }

View File

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

View File

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

View File

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

View File

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

View File

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