From dee990ff18e7d69f0f597451eb6628f04b4f820e Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 20 Jan 2019 08:18:10 -0700 Subject: [PATCH] cs: implement phantom bytes Mostly just connect to the implementation as a Chez Scheme addition. --- racket/src/cs/compile-file.ss | 1 + racket/src/cs/rumble/memory.ss | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/racket/src/cs/compile-file.ss b/racket/src/cs/compile-file.ss index 36f0082aac..c8d3bdd526 100644 --- a/racket/src/cs/compile-file.ss +++ b/racket/src/cs/compile-file.ss @@ -36,6 +36,7 @@ (check-defined 'compute-size-increments) (check-defined 'enable-type-recovery) (check-defined 'make-wrapper-procedure) +(check-defined 'make-phantom-bytevector) ;; ---------------------------------------- diff --git a/racket/src/cs/rumble/memory.ss b/racket/src/cs/rumble/memory.ss index c72369918b..034be584cb 100644 --- a/racket/src/cs/rumble/memory.ss +++ b/racket/src/cs/rumble/memory.ss @@ -324,16 +324,19 @@ ;; ---------------------------------------- (define-record-type (phantom-bytes create-phantom-bytes phantom-bytes?) - (fields [mutable size])) + (fields pbv)) (define/who (make-phantom-bytes 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) (check who phantom-bytes? phantom-bstr) (check who exact-nonnegative-integer? k) - (phantom-bytes-size-set! phantom-bstr k)) + (set-phantom-bytevector-length! (phantom-bytes-pbv phantom-bstr) k)) ;; ----------------------------------------