schemify: ensure that deserialized constants are immutable
Closes #2394
This commit is contained in:
parent
669e51768d
commit
744d440ab9
|
@ -2185,6 +2185,26 @@
|
||||||
(test 'cons exn:fail:contract:variable-id e)
|
(test 'cons exn:fail:contract:variable-id e)
|
||||||
(test #t regexp-match? #rx"^cons: " (exn-message e)))
|
(test #t regexp-match? #rx"^cons: " (exn-message e)))
|
||||||
|
|
||||||
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Check immutability after saving and restoring quoted constants
|
||||||
|
|
||||||
|
(let ([m `(module defines-immutable-objects racket/base
|
||||||
|
(provide objs)
|
||||||
|
(define objs
|
||||||
|
'(#"x"
|
||||||
|
"x"
|
||||||
|
#()
|
||||||
|
#(1)
|
||||||
|
#(#:x)
|
||||||
|
#(#"x")
|
||||||
|
#&1
|
||||||
|
#&#:x
|
||||||
|
#&#"x"
|
||||||
|
#hasheq((a . b)))))])
|
||||||
|
(define c (compile m))
|
||||||
|
(eval c)
|
||||||
|
(test #t andmap immutable? (dynamic-require ''defines-immutable-objects 'objs)))
|
||||||
|
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(report-errs)
|
(report-errs)
|
||||||
|
|
|
@ -181,16 +181,14 @@
|
||||||
`(cons ,a ,d))))]
|
`(cons ,a ,d))))]
|
||||||
[(vector? q)
|
[(vector? q)
|
||||||
(let ([args (map make-construct (vector->list q))])
|
(let ([args (map make-construct (vector->list q))])
|
||||||
(if (and (andmap quote? args)
|
`(vector->immutable-vector
|
||||||
(not (impersonator? q)))
|
,(if (and (andmap quote? args)
|
||||||
`(quote ,q)
|
(not (impersonator? q)))
|
||||||
`(vector ,@args)))]
|
`(quote ,q)
|
||||||
|
`(vector ,@args))))]
|
||||||
[(box? q)
|
[(box? q)
|
||||||
(let ([arg (make-construct (unbox q))])
|
(let ([arg (make-construct (unbox q))])
|
||||||
(if (and (quote? arg)
|
`(box-immutable ,arg))]
|
||||||
(not (impersonator? q)))
|
|
||||||
`(quote ,q)
|
|
||||||
`(box ,arg)))]
|
|
||||||
[(prefab-struct-key q)
|
[(prefab-struct-key q)
|
||||||
=> (lambda (key)
|
=> (lambda (key)
|
||||||
`(make-prefab-struct ',key ,@(map make-construct
|
`(make-prefab-struct ',key ,@(map make-construct
|
||||||
|
|
Loading…
Reference in New Issue
Block a user