From 9fecb1cd541b8edd909972e372083ca2b6f81ded Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 2 Mar 2012 07:47:16 -0700 Subject: [PATCH] racket/sandbox: use `gui-available?' at sandbox creation Previously, sandbox creation used `gui?', which is the result of `gui-available?' at the time that `racket/sandbox' is instanited. This change makes sandbox behavior less sensitive tothe order in which modules `require'd into a program are intiantiated. The change depends on a new `sandbox-make-namespace' default function for `sandbox-namespace-specs'. The new function uses either `make-base-namespace' or `make-gui-namespace', depending on whether the GUI library is available at that point. A new `sandbox-gui-enabled' parameter can disable use of the GUI library even if it is available. The `gui?' binding is still exported for backward compatibility, but it shouldn't be used anymore. original commit: 5630a3a1cab8d7953bfbb290bd6ae63c84ead605 --- collects/tests/racket/sandbox-gui.rkt | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 collects/tests/racket/sandbox-gui.rkt diff --git a/collects/tests/racket/sandbox-gui.rkt b/collects/tests/racket/sandbox-gui.rkt new file mode 100644 index 00000000..3c6aaaa3 --- /dev/null +++ b/collects/tests/racket/sandbox-gui.rkt @@ -0,0 +1,48 @@ +#lang racket +(require racket/sandbox + racket/gui/dynamic) + +(define-syntax-rule (test expect expr) + (do-test 'expr expect expr)) + +(define (do-test which expect got) + (unless (equal? expect got) + (error 'test "failed: ~s expect: ~e got: ~e" which expect got))) + +;; GUI is initialled allowed by sandbox, but not initially available: + +(test #t (sandbox-gui-available)) +(test #f (gui-available?)) + +;; Create a pre-GUI evaluator: + +(define e (call-with-trusted-sandbox-configuration + (lambda () + (make-evaluator 'racket)))) +(test (void) (e '(require racket/gui/dynamic))) +(test #f (e '(gui-available?))) + +;; Load GUI library + +(test (void) (dynamic-require 'racket/gui #f)) + +;; Now the GUI is available: + +(test #t (gui-available?)) + +;; Create a post-GUI evaluator: + +(define ge (call-with-trusted-sandbox-configuration + (lambda () + (make-evaluator 'racket)))) +(test (void) (ge '(require racket/gui/dynamic))) +(test #t (ge '(gui-available?))) + +;; A post-GUI evaluator, but with GUI disabled: + +(define pe (parameterize ([sandbox-gui-available #f]) + (call-with-trusted-sandbox-configuration + (lambda () + (make-evaluator 'racket))))) +(test (void) (pe '(require racket/gui/dynamic))) +(test #f (pe '(gui-available?)))