From b03a16ef4db6d2fc8334aaa0c29741c95ca95326 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 25 Oct 2010 23:39:15 -0500 Subject: [PATCH 1/5] alien.libraries: add-library won't close and re-open the library if nothing changed. This fixes a crash on Windows when reloading the windows vocab --- basis/alien/libraries/libraries-tests.factor | 20 +++++++++++++++++++- basis/alien/libraries/libraries.factor | 12 +++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) mode change 100644 => 100755 basis/alien/libraries/libraries-tests.factor diff --git a/basis/alien/libraries/libraries-tests.factor b/basis/alien/libraries/libraries-tests.factor old mode 100644 new mode 100755 index f1dc228d83..2721ce48c0 --- a/basis/alien/libraries/libraries-tests.factor +++ b/basis/alien/libraries/libraries-tests.factor @@ -1,4 +1,4 @@ -USING: alien.libraries alien.syntax tools.test kernel ; +USING: alien alien.libraries alien.syntax tools.test kernel ; IN: alien.libraries.tests [ f ] [ DLL" fadfasdfsada" dll-valid? ] unit-test @@ -8,3 +8,21 @@ IN: alien.libraries.tests [ ] [ "doesnotexist" dlopen dlclose ] unit-test [ "fdasfsf" dll-valid? drop ] must-fail + +[ t ] [ + "test-library" "blah" cdecl add-library + "test-library" "BLAH" cdecl add-library? + "blah" remove-library +] unit-test + +[ t ] [ + "test-library" "blah" cdecl add-library + "test-library" "blah" stdcall add-library? + "blah" remove-library +] unit-test + +[ f ] [ + "test-library" "blah" cdecl add-library + "test-library" "blah" cdecl add-library? + "blah" remove-library +] unit-test diff --git a/basis/alien/libraries/libraries.factor b/basis/alien/libraries/libraries.factor index a3f52df098..206db7b188 100755 --- a/basis/alien/libraries/libraries.factor +++ b/basis/alien/libraries/libraries.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.strings assocs io.backend kernel namespaces destructors sequences strings -system io.pathnames ; +system io.pathnames fry ; IN: alien.libraries : dlopen ( path -- dll ) native-string>alien (dlopen) ; @@ -32,9 +32,15 @@ M: library dispose dll>> [ dispose ] when* ; : remove-library ( name -- ) libraries get delete-at* [ dispose ] [ drop ] if ; +: add-library? ( name path abi -- ? ) + [ library ] 2dip + '[ [ path>> _ = ] [ abi>> _ = ] bi and not ] [ t ] if* ; + : add-library ( name path abi -- ) - [ 2drop remove-library ] - [ swap libraries get set-at ] 3bi ; + 3dup add-library? [ + [ 2drop remove-library ] + [ swap libraries get set-at ] 3bi + ] [ 3drop ] if ; : library-abi ( library -- abi ) library [ abi>> ] [ cdecl ] if* ; From 68712ed84c26c07a9e4fe32134730edf67e0afba Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 25 Oct 2010 23:52:45 -0500 Subject: [PATCH 2/5] cache: add unit tests, make clear-assoc method dispose of all values --- basis/cache/cache-tests.factor | 50 ++++++++++++++++++++++++++++++++++ basis/cache/cache.factor | 12 ++++---- 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100755 basis/cache/cache-tests.factor mode change 100644 => 100755 basis/cache/cache.factor diff --git a/basis/cache/cache-tests.factor b/basis/cache/cache-tests.factor new file mode 100755 index 0000000000..ea1c22b2cf --- /dev/null +++ b/basis/cache/cache-tests.factor @@ -0,0 +1,50 @@ +USING: cache tools.test accessors destructors kernel assocs +namespaces ; +IN: cache.tests + +TUPLE: mock-disposable < disposable n ; + +: ( n -- mock-disposable ) + mock-disposable new-disposable swap >>n ; + +M: mock-disposable dispose* drop ; + +[ ] [ "cache" set ] unit-test + +[ 0 ] [ "cache" get assoc-size ] unit-test + +[ ] [ "cache" get 2 >>max-age drop ] unit-test + +[ ] [ 1 dup "a" set 2 "cache" get set-at ] unit-test + +[ 1 ] [ "cache" get assoc-size ] unit-test + +[ ] [ "cache" get purge-cache ] unit-test + +[ ] [ 2 3 "cache" get set-at ] unit-test + +[ 2 ] [ "cache" get assoc-size ] unit-test + +[ ] [ "cache" get purge-cache ] unit-test + +[ 1 ] [ "cache" get assoc-size ] unit-test + +[ ] [ 3 dup "b" set 4 "cache" get set-at ] unit-test + +[ 2 ] [ "cache" get assoc-size ] unit-test + +[ ] [ "cache" get purge-cache ] unit-test + +[ 1 ] [ "cache" get assoc-size ] unit-test + +[ f ] [ 2 "cache" get key? ] unit-test + +[ 3 ] [ 4 "cache" get at n>> ] unit-test + +[ t ] [ "a" get disposed>> ] unit-test + +[ f ] [ "b" get disposed>> ] unit-test + +[ ] [ "cache" get clear-assoc ] unit-test + +[ t ] [ "b" get disposed>> ] unit-test diff --git a/basis/cache/cache.factor b/basis/cache/cache.factor old mode 100644 new mode 100755 index a226500c63..1247774bee --- a/basis/cache/cache.factor +++ b/basis/cache/cache.factor @@ -25,19 +25,21 @@ M: cache-assoc set-at [ ] 2dip assoc>> set-at ; -M: cache-assoc clear-assoc assoc>> clear-assoc ; +M: cache-assoc clear-assoc + [ assoc>> values dispose-each ] + [ assoc>> clear-assoc ] + bi ; M: cache-assoc >alist assoc>> [ value>> ] { } assoc-map-as ; INSTANCE: cache-assoc assoc -M: cache-assoc dispose* - [ values dispose-each ] [ clear-assoc ] bi ; +M: cache-assoc dispose* clear-assoc ; PRIVATE> : purge-cache ( cache -- ) dup max-age>> '[ - [ nip [ 1 + ] change-age age>> _ >= ] assoc-partition - [ values dispose-each ] dip + [ nip [ 1 + ] change-age age>> _ < ] assoc-partition + values dispose-each ] change-assoc drop ; From 372d2dc36399aa05532d6af437929365b5703739 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 31 Oct 2010 22:47:34 -0500 Subject: [PATCH 3/5] concurrency.mailboxes: break dependency on debugger vocab by creating concurrency.mailboxes.debugger --- basis/concurrency/mailboxes/debugger/authors.txt | 1 + basis/concurrency/mailboxes/debugger/debugger.factor | 8 ++++++++ basis/concurrency/mailboxes/mailboxes.factor | 8 +++----- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100755 basis/concurrency/mailboxes/debugger/authors.txt create mode 100755 basis/concurrency/mailboxes/debugger/debugger.factor mode change 100644 => 100755 basis/concurrency/mailboxes/mailboxes.factor diff --git a/basis/concurrency/mailboxes/debugger/authors.txt b/basis/concurrency/mailboxes/debugger/authors.txt new file mode 100755 index 0000000000..56f4654064 --- /dev/null +++ b/basis/concurrency/mailboxes/debugger/authors.txt @@ -0,0 +1 @@ +Slava Pestov diff --git a/basis/concurrency/mailboxes/debugger/debugger.factor b/basis/concurrency/mailboxes/debugger/debugger.factor new file mode 100755 index 0000000000..c222ab0a16 --- /dev/null +++ b/basis/concurrency/mailboxes/debugger/debugger.factor @@ -0,0 +1,8 @@ +! Copyright (C) 2010 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: debugger accessors debugger.threads kernel +concurrency.mailboxes ; +IN: concurrency.mailboxes.debugger + +M: linked-error error. + [ thread>> error-in-thread. ] [ error>> error. ] bi ; diff --git a/basis/concurrency/mailboxes/mailboxes.factor b/basis/concurrency/mailboxes/mailboxes.factor old mode 100644 new mode 100755 index 163873575c..df73c36183 --- a/basis/concurrency/mailboxes/mailboxes.factor +++ b/basis/concurrency/mailboxes/mailboxes.factor @@ -2,8 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: dlists deques threads sequences continuations namespaces math quotations words kernel arrays assocs init system -concurrency.conditions accessors debugger debugger.threads -locals fry ; +concurrency.conditions accessors locals fry vocabs.loader ; IN: concurrency.mailboxes TUPLE: mailbox { threads dlist } { data dlist } ; @@ -77,9 +76,6 @@ M: mailbox mailbox-get-timeout block-if-empty data>> pop-back ; TUPLE: linked-error error thread ; -M: linked-error error. - [ thread>> error-in-thread. ] [ error>> error. ] bi ; - C: linked-error : ?linked ( message -- message ) @@ -95,3 +91,5 @@ M: linked-thread error-in-thread : spawn-linked-to ( quot name mailbox -- thread ) [ (spawn) ] keep ; + +{ "concurrency.mailboxes" "debugger" } "concurrency.mailboxes.debugger" require-when From c24c399b774c68554778c22c207517ed16d9c810 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 31 Oct 2010 22:49:50 -0500 Subject: [PATCH 4/5] concurrency.count-downs: remove unused dependency on debugger vocab --- basis/concurrency/count-downs/count-downs.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 basis/concurrency/count-downs/count-downs.factor diff --git a/basis/concurrency/count-downs/count-downs.factor b/basis/concurrency/count-downs/count-downs.factor old mode 100644 new mode 100755 index d88fcef609..51dfc9e706 --- a/basis/concurrency/count-downs/count-downs.factor +++ b/basis/concurrency/count-downs/count-downs.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: dlists kernel math concurrency.promises -concurrency.mailboxes debugger accessors fry ; +concurrency.mailboxes accessors fry ; IN: concurrency.count-downs ! http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/CountDownLatch.html From 974f4cfda4063c8755bcaec4a0b92d55b34fca49 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 31 Oct 2010 22:50:37 -0500 Subject: [PATCH 5/5] game.loop: remove unneeded dependency on tools.memory vocab --- extra/game/loop/loop.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 extra/game/loop/loop.factor diff --git a/extra/game/loop/loop.factor b/extra/game/loop/loop.factor old mode 100644 new mode 100755 index 1bdcece936..fa9d17eb0f --- a/extra/game/loop/loop.factor +++ b/extra/game/loop/loop.factor @@ -2,7 +2,7 @@ USING: accessors timers alien.c-types calendar classes.struct continuations destructors fry kernel math math.order memory namespaces sequences specialized-vectors system -tools.memory ui ui.gadgets.worlds vm vocabs.loader arrays +ui ui.gadgets.worlds vm vocabs.loader arrays tools.time.struct locals ; IN: game.loop