[racket] Sandboxed evaluation with 2htdp/image requires

From: Nadeem Abdul Hamid (nadeem at acm.org)
Date: Sun Feb 5 12:14:30 EST 2012

As a follow-up question, here is what I've been doing to load in
student files, which may be either plain text files, or in the WXME
format. (It used to work, but I guess not since the update to the GUI
framework.) First, I use file->bytes to read in the bytes of their
file. Then, given:

 data : bytes
 x : (oneof/c 'beginner 'beginner-abbr 'intermediate …)

do this (which reads the file into a text% and then gets the bytes of
the file, but without the first three metadata lines of the file, if
they are there):

   ...
         (let ([t (make-object text%)]
               [outp (open-output-bytes)])
           (send t insert-port (open-input-bytes data))
           (send t move-position 'home)
           (send t save-port outp)
           (let ([data-x (get-output-bytes outp)])
             (make-module-evaluator data-x #:language (lang-for x))))]))))

Because of the use of text%, this requires racket/gui and causes
conflicts then if the loaded file requires 2htdp/image. Is there a
better way to construct an evaluator, given raw bytes of a .rkt file
in either plain text or WXME format? (I looked the the wxme module,
but it doesn't quite seem to provide functionality to replace what I'm
doing above.)



On Sun, Feb 5, 2012 at 11:02 AM, Nadeem Abdul Hamid <nadeem at acm.org> wrote:
> I'm having a problem with the error "cannot instantiate
> `racket/gui/base' a second time in the same process" in a script that
> I have to perform automated testing of student BSL programs. My script
> requires 2htdp/image for its own purposes and uses
> make-module-evaluator to create an evaluator for a student program.
> The problem is that if the student program also has a (require
> 2htdp/image), it attempts to instantiate racket/gui/base which is
> problematic (http://docs.racket-lang.org/gui/Startup_Actions.html ).
> Any suggestions for dealing with this?
>
> Thanks,
> nadeem


Posted on the users mailing list.