fasl: use longer fasl prefix
Change fasl prefix from `rkt:` to `racket/fasl:`, in the hope that future civilizations will be able to decipher these binary files.
This commit is contained in:
parent
fb635c0d97
commit
8b797a10a8
|
@ -31,7 +31,7 @@
|
|||
|
||||
;; The fasl format is meant to be forward-compatible:
|
||||
(define immutables-regression-bstr
|
||||
#"rkt:\0\200\371\0\34\"n\4\3\6\ao\r2\16\5three\23\4four\25\4five\21\3six\"u \3vwx\36yz\35\2{|\16\afifteen%\1\2\200\16\bnineteen\16\asixteen\177%\0\2\202\23\ntwenty-one\204\23\ftwenty-three%\2\2\206\207\210\211#\16\ftwenty-eight\3\213\214\23\00231\b\340\b\200\344\f\b\201\320\204\0\0\b\2010W\5\0\b\201\200\3566\0\b\201\200\300\r\26\b\202\0\374\371\330\b\0\0\0\b\202\0`v\363\263b\1\0\b\202\0\0\220\235\316\332\2027\t\0\0\0\0\0\200D@\t\315\314\314\314\314\314\20@\v\231\322\f\232\322\f\t\0\0\0\0\0\200F@\t\0\0\0\0\0\0Y@\n\0\08B")
|
||||
#"racket/fasl:\0\200\371\0\34\"n\4\3\6\ao\r2\16\5three\23\4four\25\4five\21\3six\"u \3vwx\36yz\35\2{|\16\afifteen%\1\2\200\16\bnineteen\16\asixteen\177%\0\2\202\23\ntwenty-one\204\23\ftwenty-three%\2\2\206\207\210\211#\16\ftwenty-eight\3\213\214\23\00231\b\340\b\200\344\f\b\201\320\204\0\0\b\2010W\5\0\b\201\200\3566\0\b\201\200\300\r\26\b\202\0\374\371\330\b\0\0\0\b\202\0`v\363\263b\1\0\b\202\0\0\220\235\316\332\2027\t\0\0\0\0\0\200D@\t\315\314\314\314\314\314\20@\v\231\322\f\232\322\f\t\0\0\0\0\0\200F@\t\0\0\0\0\0\0Y@\n\0\08B")
|
||||
|
||||
(for ([i (in-list immutables)])
|
||||
(test i fasl->s-exp (s-exp->fasl i)))
|
||||
|
|
33
pkgs/racket-test-extra/tests/racket/fasl-prefix.rkt
Normal file
33
pkgs/racket-test-extra/tests/racket/fasl-prefix.rkt
Normal file
|
@ -0,0 +1,33 @@
|
|||
#lang racket/base
|
||||
|
||||
;; Test that bytestrings created by "the fasl library" start with the name
|
||||
;; of the library.
|
||||
;;
|
||||
;; In particular:
|
||||
;; - use `s-exp->fasl` from `racket/fasl` to create a bytestring
|
||||
;; - read the prefix of the bytestring, i.e. everything before the first ':'
|
||||
;; - use `dynamic-require` on the prefix to import the `s-exp->fasl` function
|
||||
;;
|
||||
;; The idea is that if someone finds a fasl-encoded file, they can view the
|
||||
;; file in a text editor and search the internet to learn more --- instead
|
||||
;; of being stuck with a mysterious binary.
|
||||
|
||||
(require rackunit)
|
||||
|
||||
(define SECRET-VALUE 'any-value)
|
||||
|
||||
(define bstr
|
||||
(parameterize ([current-namespace (make-base-namespace)])
|
||||
(namespace-require 'racket/fasl)
|
||||
(eval `(s-exp->fasl ',SECRET-VALUE))))
|
||||
|
||||
(define fasl-prefix
|
||||
(string->symbol
|
||||
(apply string
|
||||
(for/list ([b (in-bytes bstr)]
|
||||
#:break (eq? (integer->char b) #\:))
|
||||
(integer->char b)))))
|
||||
|
||||
(check-equal?
|
||||
((dynamic-require fasl-prefix 's-exp->fasl) SECRET-VALUE)
|
||||
bstr)
|
|
@ -83,6 +83,8 @@
|
|||
|
||||
(define fasl-lowest-small-integer -10)
|
||||
(define fasl-highest-small-integer (- 255 (- fasl-small-integer-start fasl-lowest-small-integer) 1))
|
||||
(define fasl-prefix #"racket/fasl:")
|
||||
(define fasl-prefix-length (bytes-length fasl-prefix))
|
||||
|
||||
(define-constants
|
||||
(fasl-hash-eq-variant 0)
|
||||
|
@ -124,7 +126,7 @@
|
|||
(define exploded-wrt-dir 'not-ready)
|
||||
(define (treat-immutable? v) (or (not keep-mutable?) (immutable? v)))
|
||||
;; The fasl formal prefix:
|
||||
(write-bytes #"rkt:" o)
|
||||
(write-bytes fasl-prefix o)
|
||||
;; Write content to a string, so we can measure it
|
||||
(define bstr
|
||||
(let ([o (open-output-bytes)])
|
||||
|
@ -303,7 +305,7 @@
|
|||
[(bytes? orig-i) (mcons orig-i 0)]
|
||||
[(input-port? orig-i) orig-i]
|
||||
[else (raise-argument-error 'fasl->s-exp "(or/c bytes? input-port?)" orig-i)]))
|
||||
(unless (bytes=? (read-bytes/exactly 4 init-i) #"rkt:")
|
||||
(unless (bytes=? (read-bytes/exactly fasl-prefix-length init-i) fasl-prefix)
|
||||
(read-error "unrecognized prefix"))
|
||||
(define shared-count (read-fasl-integer init-i))
|
||||
(define shared (make-vector shared-count))
|
||||
|
|
Loading…
Reference in New Issue
Block a user