From 5908f301b9df66f8376218aa0e8ded8f94faf1d8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 16 Jun 2015 18:41:47 -0700 Subject: [PATCH] alien.libraries: Add update-library. See #1185 --- basis/alien/libraries/libraries.factor | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/basis/alien/libraries/libraries.factor b/basis/alien/libraries/libraries.factor index 5a06b01a84..0fcb197335 100755 --- a/basis/alien/libraries/libraries.factor +++ b/basis/alien/libraries/libraries.factor @@ -45,9 +45,11 @@ M: library dispose dll>> [ dispose ] when* ; : remove-library ( name -- ) libraries get delete-at* [ dispose ] [ drop ] if ; +: same-library? ( library path abi -- ? ) + [ swap path>> = ] [ swap abi>> = ] bi-curry* bi and ; + : add-library? ( name path abi -- ? ) - [ lookup-library ] 2dip - '[ [ path>> _ = ] [ abi>> _ = ] bi and not ] [ t ] if* ; + [ lookup-library ] 2dip '[ _ _ same-library? not ] [ t ] if* ; : add-library ( name path abi -- ) 3dup add-library? [ @@ -56,6 +58,19 @@ M: library dispose dll>> [ dispose ] when* ; [ 2drop libraries get set-at ] 3tri ] [ 3drop ] if ; +: change-dll ( library path abi -- ) + swap >>abi + swap >>path + [ dispose ] + [ path>> open-dll ] + [ swap >>dlerror swap >>dll drop ] tri ; + +: update-library ( name path abi -- ) + pick lookup-library [ + [ 2over same-library? not ] keep swap + [ change-dll drop ] [ 4drop ] if + ] [ add-library ] if* ; + : library-abi ( library -- abi ) lookup-library [ abi>> ] [ cdecl ] if* ;