cs: implement phantom bytes

Mostly just connect to the implementation as a Chez Scheme addition.
This commit is contained in:
Matthew Flatt 2019-01-20 08:18:10 -07:00
parent dc047d8922
commit dee990ff18
2 changed files with 7 additions and 3 deletions

View File

@ -36,6 +36,7 @@
(check-defined 'compute-size-increments) (check-defined 'compute-size-increments)
(check-defined 'enable-type-recovery) (check-defined 'enable-type-recovery)
(check-defined 'make-wrapper-procedure) (check-defined 'make-wrapper-procedure)
(check-defined 'make-phantom-bytevector)
;; ---------------------------------------- ;; ----------------------------------------

View File

@ -324,16 +324,19 @@
;; ---------------------------------------- ;; ----------------------------------------
(define-record-type (phantom-bytes create-phantom-bytes phantom-bytes?) (define-record-type (phantom-bytes create-phantom-bytes phantom-bytes?)
(fields [mutable size])) (fields pbv))
(define/who (make-phantom-bytes k) (define/who (make-phantom-bytes k)
(check who exact-nonnegative-integer? k) (check who exact-nonnegative-integer? k)
(create-phantom-bytes k)) (let ([ph (create-phantom-bytes (make-phantom-bytevector k))])
(when (>= (bytes-allocated) (* 2 allocated-after-major))
(collect-garbage))
ph))
(define/who (set-phantom-bytes! phantom-bstr k) (define/who (set-phantom-bytes! phantom-bstr k)
(check who phantom-bytes? phantom-bstr) (check who phantom-bytes? phantom-bstr)
(check who exact-nonnegative-integer? k) (check who exact-nonnegative-integer? k)
(phantom-bytes-size-set! phantom-bstr k)) (set-phantom-bytevector-length! (phantom-bytes-pbv phantom-bstr) k))
;; ---------------------------------------- ;; ----------------------------------------