Hi Tim, Your code is a little more complicated than I can grok directly. I believe that you problem does not have to with the web-language, but just with using serialize.
The serialize output format is basically an s-expression, but every time a non-prefab struct appears it has a cons of the name of the module and the constructor function. Basically, deserialize walks through this and when it gets to one of these is does a dynamic-require using the car as the module and the cdr as the symbol. If that module isn't around, or means something different, then it will fail. Look at this example: (define my-eval (make-evaluator 'racket/base)) (my-eval '(require racket/serialize)) (my-eval '(define-serializable-struct point (x y))) (define external-point-rep (my-eval '(serialize (point 1 2)))) external-point-rep (my-eval `(deserialize ',external-point-rep)) This fails because the evaluator is for a top-level and the structure definition is never associated with a module. In contrast, this works: (define my-eval (make-module-evaluator '(module m racket/base (require racket/serialize) (define-serializable-struct point (x y))))) (define external-point-rep (my-eval '(serialize (point 1 2)))) external-point-rep (my-eval `(deserialize ',external-point-rep)) Because it is in a module and the deserialize happens where that module could be found. In contrast, this will fail: (define my-eval (make-module-evaluator '(module m racket/base (require racket/serialize) (define-serializable-struct point (x y))))) (define external-point-rep (my-eval '(serialize (point 1 2)))) external-point-rep (require racket/serialize) (deserialize external-point-rep) Because the sandbox's module isn't visible anymore. This is basically equivalent to this failure too: (define mod-eval (make-module-evaluator '(module m racket/base (require racket/serialize) (define-serializable-struct point (x y))))) (define top-eval (make-evaluator 'racket/base)) (define external-point-rep (mod-eval '(serialize (point 1 2)))) external-point-rep (top-eval `(deserialize ',external-point-rep)) Finally, notice that deserialize can be seriously tricked: (define mod-eval1 (make-module-evaluator '(module m racket/base (require racket/serialize) (define-serializable-struct point (x y))))) (define mod-eval2 (make-module-evaluator '(module m racket/base (require racket/serialize) (define-serializable-struct point (x y z))))) (define external-point-rep (mod-eval1 '(serialize (point 1 2)))) external-point-rep (mod-eval2 `(deserialize ',external-point-rep)) My guess is that to fix your code, you need to change your hash to store the continuation and its associated sandbox to re-evaluate it in or run all the code in the same sandbox. Jay On Thu, Sep 17, 2015 at 5:29 AM, Tim Brown <tim.br...@cityc.co.uk> wrote: > Folks, > > The attached file exp-serialize-continuation.rkt implements > “define-generator”, which defines a generator. The resultant generators > take a “key”, which allows several generator states to be saved for > later use (in a (key -> continuation) hash table). > > So far, so good: It works as expected with standard continuations, as > well as serializable continuations (which means I can stuff the > continuations somewhere more permanent than a hash table). > > I use them in exp-serialize-module-continuation.rkt (supported by > exp-serialized-continuation-tests.rkt). All tests pass. > > I want to allow my users to write these generators and, as such, I need > to protect my code from their mistakes (and malice). Evaluators from > racket/sandbox are designed just for that. So I want to use code like > “sbx-1” in exp-serialize-sandbox-continuation.rkt . > > This is where I encounter my problem... when it comes to de-serializing > the continuations; I get the following error report: > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > error deserializing: ((3) 5 (((lib "web-server/lang/web-cells.rkt") . > deserialize-info:frame-v0) ((lib "web-server/lang/abort-resume.rkt") . > "lifted.3") ((quote program) . "lifted.376") ((quote program) . > "lifted.367") ((quote program) . "lifted.33")) 2 ((0 (h - ())) (1 (? . > 0) ())) () (1 (? . 0) (c (v! (2 (? . 1)) #f #f) c (v! (3 tim (? . 1)) #f > #f) c (v! (4 (? . 1)) #f #f)))) > dynamic-require: unknown module > module name: #<resolved-module-path:'program> > context...: > > /usr/local/racket-6.2.900.12/share/racket/collects/racket/private/serialize.rkt:654:8: > loop > > /usr/local/racket-6.2.900.12/share/racket/collects/racket/private/serialize.rkt:649:2: > deserialize > g22 > G > /home/tim/tmp/exp-serialize-continuation-tests.rkt:6:0 > /home/tim/tmp/exp-serialize-sandbox-continuation.rkt: [running body] > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > My limited understanding is that dynamic-require is used to look up the > ANF function representing my continuation; and since I’m in a sandbox > there has been some disconnection between where the function was lodged > vs. how dynamic-require is attempting to find it. > > Is there any way around this? > -- hinting dynamic-require, embellishing my sandbox, something else > > Which ('program . "lifted.X") is likely to be causing the problem? > - the first one encountered? (3) > - the last one encountered? (33) > - the one after the first encountered? (376) > - the one before the last encountered? (367) > - one chosen at whim by dynamic-require? (?) > > The reason I ask is to understand why my continuation in sbx-2 works. > > The following continuation ALSO has a reference to 'program (although > I’ve only been able to engineer it to 1 deep: > > '((3) 3 (((lib "web-server/lang/abort-resume.rkt") . "lifted.3") ((lib > "web-server/lang/web-cells.rkt") . deserialize-info:frame-v0) ('program > . "lifted.24")) 0 () () (0 (1 (h - ())) (c (v! (2) #f #f)))) > > But I can generate, persist, de-serialize and invoke this structure. > Why sbx-2, but not sbx-1? > > > I expect that I can avoid all of this by writing my code to a temporary > disk file and require'ing it into the sandbox; but that’s not pretty on > a number of levels. > > > Thanks, in advance, for your help, > > Tim > > -- > Tim Brown CEng MBCS <tim.br...@cityc.co.uk> > ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ > City Computing Limited · www.cityc.co.uk > City House · Sutton Park Rd · Sutton · Surrey · SM1 2AE · GB > T:+44 20 8770 2110 · F:+44 20 8770 2130 > ──────────────────────────────────────────────────────────────────────── > City Computing Limited registered in London No:1767817. > Registered Office: City House, Sutton Park Road, Sutton, Surrey, SM1 2AE > VAT No: GB 918 4680 96 > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Jay McCarthy http://jeapostrophe.github.io "Wherefore, be not weary in well-doing, for ye are laying the foundation of a great work. And out of small things proceedeth that which is great." - D&C 64:33 -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.