racket/serialize: fix for submodules
Closes PR 12795
This commit is contained in:
parent
a137459b65
commit
73ce5a4767
|
@ -56,13 +56,17 @@
|
|||
;; then it can cause simplified module paths to be paths;
|
||||
;; keep the literal path, but marshal it to bytes.
|
||||
(define (protect-path p)
|
||||
(if (path? p)
|
||||
(path->bytes p)
|
||||
p))
|
||||
(cond
|
||||
[(path? p) (path->bytes p)]
|
||||
[(and (pair? p) (eq? (car p) 'submod) (path? (cadr p)))
|
||||
`(submod ,(protect-path (cadr p)) . ,(cddr p))]
|
||||
[else p]))
|
||||
(define (unprotect-path p)
|
||||
(if (bytes? p)
|
||||
(bytes->path p)
|
||||
p))
|
||||
(cond
|
||||
[(bytes? p) (bytes->path p)]
|
||||
[(and (pair? p) (eq? (car p) 'submod) (bytes? (cadr p)))
|
||||
`(submod ,(unprotect-path (cadr p)) . ,(cddr p))]
|
||||
[else p]))
|
||||
|
||||
(define (revive-symbol s)
|
||||
(if (string? s)
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
(Section 'serialization)
|
||||
|
||||
(require scheme/serialize)
|
||||
(require racket/serialize
|
||||
racket/file)
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
|
@ -469,6 +470,24 @@
|
|||
(test #t pair? (serialize (new s:bad% [foo 10])))
|
||||
(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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user