racket/serialize: fix for submodules

Closes PR 12795
This commit is contained in:
Matthew Flatt 2012-05-27 14:39:51 -06:00
parent a137459b65
commit 73ce5a4767
2 changed files with 30 additions and 7 deletions

View File

@ -56,13 +56,17 @@
;; then it can cause simplified module paths to be paths; ;; then it can cause simplified module paths to be paths;
;; keep the literal path, but marshal it to bytes. ;; keep the literal path, but marshal it to bytes.
(define (protect-path p) (define (protect-path p)
(if (path? p) (cond
(path->bytes p) [(path? p) (path->bytes p)]
p)) [(and (pair? p) (eq? (car p) 'submod) (path? (cadr p)))
`(submod ,(protect-path (cadr p)) . ,(cddr p))]
[else p]))
(define (unprotect-path p) (define (unprotect-path p)
(if (bytes? p) (cond
(bytes->path p) [(bytes? p) (bytes->path p)]
p)) [(and (pair? p) (eq? (car p) 'submod) (bytes? (cadr p)))
`(submod ,(unprotect-path (cadr p)) . ,(cddr p))]
[else p]))
(define (revive-symbol s) (define (revive-symbol s)
(if (string? s) (if (string? s)

View File

@ -4,7 +4,8 @@
(Section 'serialization) (Section 'serialization)
(require scheme/serialize) (require racket/serialize
racket/file)
;; ---------------------------------------- ;; ----------------------------------------
@ -469,6 +470,24 @@
(test #t pair? (serialize (new s:bad% [foo 10]))) (test #t pair? (serialize (new s:bad% [foo 10])))
(err/rt-test (deserialize (serialize (new s:bad% [foo 10]))) exn:fail:object?) (err/rt-test (deserialize (serialize (new s:bad% [foo 10]))) exn:fail:object?)
;; ----------------------------------------
(let ([fn (make-temporary-file)])
(with-output-to-file fn
#:exists 'truncate
(lambda () (display
(string-append "#lang racket/base\n"
"(require racket/serialize)\n"
"(module+ main\n"
" (provide s)\n"
" (serializable-struct foo (bar))\n"
" (define s (serialize (foo 35))))\n"))))
(define s (dynamic-require `(submod ,fn main) 's))
(let ([o (open-output-bytes)])
(write s o)
(test s read (open-input-string (get-output-string o)))))
;; ---------------------------------------- ;; ----------------------------------------
(report-errs) (report-errs)