From 5b4c1aea5d4ccfa1b9834afc218d14e55b098329 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 20 Oct 2009 18:26:10 -0400 Subject: [PATCH] run bootstrap and startup hooks inside a with-destructors. use &dispose instead of setting shutdown hooks in a couple of places --- basis/bootstrap/finish-bootstrap.factor | 24 +++++++++++++----------- basis/bootstrap/finish-staging.factor | 11 ++++++----- basis/bootstrap/stage2.factor | 1 + basis/io/sockets/unix/unix.factor | 3 +-- basis/random/unix/unix.factor | 15 ++++----------- basis/windows/uniscribe/uniscribe.factor | 5 +---- core/bootstrap/stage1.factor | 4 ++-- 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/basis/bootstrap/finish-bootstrap.factor b/basis/bootstrap/finish-bootstrap.factor index 65115fc2df..35b40df97a 100644 --- a/basis/bootstrap/finish-bootstrap.factor +++ b/basis/bootstrap/finish-bootstrap.factor @@ -1,17 +1,19 @@ USING: init command-line debugger system continuations -namespaces eval kernel vocabs.loader io ; +namespaces eval kernel vocabs.loader io destructors ; [ boot - do-startup-hooks [ - (command-line) parse-command-line - load-vocab-roots - run-user-init - "e" get [ eval( -- ) ] when* - ignore-cli-args? not script get and - [ run-script ] [ "run" get run ] if* - output-stream get [ stream-flush ] when* - 0 exit - ] [ print-error 1 exit ] recover + do-startup-hooks + [ + (command-line) parse-command-line + load-vocab-roots + run-user-init + "e" get [ eval( -- ) ] when* + ignore-cli-args? not script get and + [ run-script ] [ "run" get run ] if* + output-stream get [ stream-flush ] when* + 0 + ] [ print-error 1 ] recover + ] with-destructors exit ] set-boot-quot diff --git a/basis/bootstrap/finish-staging.factor b/basis/bootstrap/finish-staging.factor index e75f0fa5c5..10d81d6ff6 100644 --- a/basis/bootstrap/finish-staging.factor +++ b/basis/bootstrap/finish-staging.factor @@ -3,9 +3,10 @@ io ; [ boot - do-startup-hooks - (command-line) parse-command-line - "run" get run - output-stream get [ stream-flush ] when* - 0 exit + [ + do-startup-hooks + (command-line) parse-command-line + "run" get run + output-stream get [ stream-flush ] when* + ] with-destructors 0 exit ] set-boot-quot diff --git a/basis/bootstrap/stage2.factor b/basis/bootstrap/stage2.factor index 3cbe155dd2..b8531abd90 100644 --- a/basis/bootstrap/stage2.factor +++ b/basis/bootstrap/stage2.factor @@ -56,6 +56,7 @@ SYMBOL: bootstrap-time error-continuation set-global error set-global ; inline + [ ! We time bootstrap millis diff --git a/basis/io/sockets/unix/unix.factor b/basis/io/sockets/unix/unix.factor index 583fd8fba9..d2df4d9e13 100755 --- a/basis/io/sockets/unix/unix.factor +++ b/basis/io/sockets/unix/unix.factor @@ -113,8 +113,7 @@ SYMBOL: receive-buffer CONSTANT: packet-size 65536 -[ packet-size malloc receive-buffer set-global ] "io.sockets.unix" add-startup-hook -[ receive-buffer get-global free ] "io.sockets.unix" add-shutdown-hook +[ packet-size malloc &free receive-buffer set-global ] "io.sockets.unix" add-startup-hook :: do-receive ( port -- packet sockaddr ) port addr>> empty-sockaddr/size :> len :> sockaddr diff --git a/basis/random/unix/unix.factor b/basis/random/unix/unix.factor index b15b9ab8b9..fd93d6492c 100644 --- a/basis/random/unix/unix.factor +++ b/basis/random/unix/unix.factor @@ -16,19 +16,12 @@ M: unix-random random-bytes* ( n tuple -- byte-array ) os openbsd? [ [ - "/dev/srandom" secure-random-generator set-global - "/dev/arandom" system-random-generator set-global + "/dev/srandom" &dispose secure-random-generator set-global + "/dev/arandom" &dispose system-random-generator set-global ] "random.unix" add-startup-hook ] [ [ - "/dev/random" secure-random-generator set-global - "/dev/urandom" system-random-generator set-global + "/dev/random" &dispose secure-random-generator set-global + "/dev/urandom" &dispose system-random-generator set-global ] "random.unix" add-startup-hook ] if - -[ - [ - secure-random-generator get-global &dispose drop - system-random-generator get-global &dispose drop - ] with-destructors -] "random.unix" add-shutdown-hook diff --git a/basis/windows/uniscribe/uniscribe.factor b/basis/windows/uniscribe/uniscribe.factor index 1651e8b3d8..87540dc24f 100755 --- a/basis/windows/uniscribe/uniscribe.factor +++ b/basis/windows/uniscribe/uniscribe.factor @@ -113,8 +113,5 @@ SYMBOL: cached-script-strings : cached-script-string ( font string -- script-string ) cached-script-strings get-global [ ] 2cache ; -[ cached-script-strings set-global ] +[ &dispose cached-script-strings set-global ] "windows.uniscribe" add-startup-hook - -[ cached-script-strings get-global dispose ] -"windows.uniscribe" add-shutdown-hook diff --git a/core/bootstrap/stage1.factor b/core/bootstrap/stage1.factor index 6dab0f4162..1e8ebe2938 100644 --- a/core/bootstrap/stage1.factor +++ b/core/bootstrap/stage1.factor @@ -3,7 +3,7 @@ USING: arrays assocs continuations debugger generic hashtables init io io.files kernel kernel.private make math memory namespaces parser prettyprint sequences splitting system -vectors vocabs vocabs.loader words ; +vectors vocabs vocabs.loader words destructors ; QUALIFIED: bootstrap.image.private IN: bootstrap.stage1 @@ -42,7 +42,7 @@ load-help? off [ "resource:basis/bootstrap/stage2.factor" dup exists? [ - run-file + [ run-file ] with-destructors ] [ "Cannot find " write write "." print "Please move " write image write " to the same directory as the Factor sources," print -- 2.34.1