From 40a79766afac01bf80e56b09d2189950b0665f96 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 5 Jun 2014 14:26:38 -0700 Subject: [PATCH] alien.libraries: Change to be just a constructor. Replace with make-library and try-make-library so that we throw better errors. --- basis/alien/libraries/libraries-docs.factor | 2 +- basis/alien/libraries/libraries.factor | 23 +++++++++++++++------ basis/tools/deploy/shaker/shaker.factor | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/basis/alien/libraries/libraries-docs.factor b/basis/alien/libraries/libraries-docs.factor index f9828e2835..b09cc904df 100644 --- a/basis/alien/libraries/libraries-docs.factor +++ b/basis/alien/libraries/libraries-docs.factor @@ -4,7 +4,7 @@ USING: accessors alien alien.syntax assocs help.markup help.syntax io.backend kernel namespaces strings ; IN: alien.libraries -HELP: +HELP: make-library { $values { "path" "a pathname string" } { "abi" "the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } } { "library" library } } diff --git a/basis/alien/libraries/libraries.factor b/basis/alien/libraries/libraries.factor index 7e8611405e..17f75a670f 100755 --- a/basis/alien/libraries/libraries.factor +++ b/basis/alien/libraries/libraries.factor @@ -17,16 +17,26 @@ SYMBOL: libraries libraries [ H{ } clone ] initialize -TUPLE: library { path string } { abi abi initial: cdecl } dll dlerror ; +TUPLE: library { path string } dll dlerror { abi abi initial: cdecl } ; + +C: library ERROR: no-library name ; +ERROR: library-path-is-f name path abi ; + : lookup-library ( name -- library ) libraries get at ; -: ( path abi -- library ) - over dup - [ dlopen dup dll-valid? [ f ] [ dlerror ] if ] [ f ] if - \ library boa ; +: open-dll ( path -- dll dll-error/f ) + [ dlopen dup dll-valid? [ f ] [ dlerror ] if ] + [ f f ] if* ; + +: make-library ( path abi -- library ) + [ dup open-dll ] dip ; + +: try-make-library ( name path abi -- library ) + over [ [ nip ] dip ] [ library-path-is-f ] if + make-library ; : library-dll ( library -- dll ) dup [ dll>> ] when ; @@ -48,7 +58,8 @@ M: library dispose dll>> [ dispose ] when* ; : add-library ( name path abi -- ) 3dup add-library? [ [ 2drop remove-library ] - [ swap libraries get set-at ] 3bi + [ try-make-library ] + [ 2drop libraries get set-at ] 3tri ] [ 3drop ] if ; : library-abi ( library -- abi ) diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index f25247cd48..47e2256ead 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -558,7 +558,7 @@ SYMBOL: deploy-vocab "Preparing deployed libraries" show deploy-libraries get [ libraries get [ - [ path>> >deployed-library-path ] [ abi>> ] bi + [ path>> >deployed-library-path ] [ abi>> ] bi make-library ] change-at ] each