From f0a9741a967e654222c98a242320348fa1f6f071 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 15 Sep 2010 19:10:21 -0500 Subject: [PATCH] Make windows random objects inherit from win32-handle, remove redundant error handling, use new-disposable instead of new --- basis/random/windows/windows.factor | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/basis/random/windows/windows.factor b/basis/random/windows/windows.factor index 77f1b80081..55d568f01d 100755 --- a/basis/random/windows/windows.factor +++ b/basis/random/windows/windows.factor @@ -2,10 +2,10 @@ USING: accessors alien.c-types alien.data byte-arrays combinators.short-circuit continuations destructors init kernel locals namespaces random windows.advapi32 windows.errors windows.kernel32 windows.types math.bitwise sequences fry -literals ; +literals io.backend.windows ; IN: random.windows -TUPLE: windows-crypto-context < disposable provider type handle ; +TUPLE: windows-crypto-context < win32-handle provider type ; M: windows-crypto-context dispose* ( tuple -- ) [ handle>> 0 CryptReleaseContext win32-error=0/f ] @@ -38,24 +38,17 @@ ERROR: acquire-crypto-context-failed provider type error ; dup [ provider>> ] [ type>> ] bi attempt-crypto-context >>handle ; : ( provider type -- windows-crypto-type ) - windows-crypto-context new + windows-crypto-context new-disposable swap >>type swap >>provider initialize-crypto-context ; inline -M: windows-crypto-context random-bytes* ( n windows-crypto-context -- bytes ) - dup already-disposed? [ initialize-crypto-context f >>disposed ] when - [ - |dispose - handle>> swap dup - [ CryptGenRandom win32-error=0/f ] keep - ] with-destructors ; +M: windows-crypto-context random-bytes* ( n windows-crypto-context -- bytes ) + handle>> swap [ ] [ ] bi + [ CryptGenRandom win32-error=0/f ] keep ; -ERROR: no-windows-crypto-provider error ; - : try-crypto-providers ( seq -- windows-crypto-context ) - [ first2 ] attempt-all - dup windows-crypto-context? [ no-windows-crypto-provider ] unless ; + [ first2 ] attempt-all ; [ {