diff --git a/pkgs/racket-doc/scribblings/foreign/pointers.scrbl b/pkgs/racket-doc/scribblings/foreign/pointers.scrbl index 3373f9e214..fea0463af1 100644 --- a/pkgs/racket-doc/scribblings/foreign/pointers.scrbl +++ b/pkgs/racket-doc/scribblings/foreign/pointers.scrbl @@ -289,14 +289,15 @@ specification is required at minimum: This allocation mode corresponds to @cpp{scheme_malloc_atomic_allow_interior} in the C API.} - @item{@indexed-racket['nonatomic-interior] --- Like + @item{@indexed-racket['interior] --- Like @racket['nonatomic], but the allocated object will not be moved by the garbage collector as long as the allocated object is retained. - This mode is supported only for the @BC[] Racket implementation, and - it corresponds to @cpp{scheme_malloc_allow_interior} in the C - API.} + For the @BC[] Racket implementation, a reference can point + to the interior of the object, instead of its starting address. + This allocation mode corresponds to + @cpp{scheme_malloc_allow_interior} in the C API.} @item{@indexed-racket['tagged] --- Allocates memory that must start with a @tt{short} value that is registered as a tag with @@ -337,7 +338,8 @@ If no mode is specified, then @racket['nonatomic] allocation is used when the type is a @racket[_gcpointer]- or @racket[_scheme]-based type, and @racket['atomic] allocation is used otherwise. -@history[#:changed "6.4.0.10" @elem{Added the @racket['tagged] allocation mode.}]} +@history[#:changed "6.4.0.10" @elem{Added the @racket['tagged] allocation mode.} + #:changed "8.0.0.13" @elem{Changed CS to support the @racket['interior] allocation mode.}]} @defproc[(free [cptr cpointer?]) void]{ diff --git a/pkgs/racket-test-core/tests/racket/foreign-test.rktl b/pkgs/racket-test-core/tests/racket/foreign-test.rktl index 14931312cc..72451c3317 100644 --- a/pkgs/racket-test-core/tests/racket/foreign-test.rktl +++ b/pkgs/racket-test-core/tests/racket/foreign-test.rktl @@ -747,7 +747,7 @@ _pointer)))) ;; test 'interior allocation mode -(when (eq? 'racket (system-type 'vm)) +(let () ;; Example by Ron Garcia (define-struct data (a b)) (define (cbox s) diff --git a/racket/src/cs/rumble/foreign.ss b/racket/src/cs/rumble/foreign.ss index d6e978f792..ef6948dabb 100644 --- a/racket/src/cs/rumble/foreign.ss +++ b/racket/src/cs/rumble/foreign.ss @@ -1437,12 +1437,14 @@ [(eq? mode 'nonatomic) (make-cpointer (#%make-vector (quotient size ptr-size-in-bytes) 0) #f)] [(eq? mode 'atomic-interior) - ;; This is not quite the same as traditional Racket, because - ;; a finalizer is associated with the cpointer (as opposed to - ;; the address that is wrapped by the cpointer). Also, interior - ;; pointers are not allowed as GCable pointers. + ;; This is not quite the same as Racket BC, because interior + ;; pointers are not allowed as GCable pointers. So, "interior" + ;; just means "doesn't move". (let* ([bstr (make-immobile-bytevector size)]) (make-cpointer bstr #f))] + [(eq? mode 'interior) + ;; Ditto + (make-cpointer (#%make-immobile-vector (quotient size ptr-size-in-bytes) 0) #f)] [else (raise-unsupported-error 'malloc (format "'~a mode is not supported" mode))]))