diff --git a/mats/foreign.ms b/mats/foreign.ms index 930eec642..aefc07b92 100644 --- a/mats/foreign.ms +++ b/mats/foreign.ms @@ -3680,12 +3680,35 @@ (error? (make-reference-bytevector -1)) (error? (bytevector-reference-ref #vu8(1 2 3) 0)) (error? (bytevector-reference-ref (make-reference-bytevector 8) -8)) + (< 3 (foreign-sizeof 'ptr)) ;; assumption for some of the following tests + (error? (bytevector-reference-ref (make-reference-bytevector 3) 1)) + (error? (bytevector-reference-ref (make-reference-bytevector 3) 0)) + (error? (bytevector-reference-ref (make-reference-bytevector 3) -1)) + (error? (guard (x [#t (error 'bytevector-reference-ref "failed as expected")]) + ;; guard the exception to hide the size of the vector, which + ;; varies with the machine's word size + (bytevector-reference-ref (make-reference-bytevector (foreign-sizeof 'ptr)) 1))) (error? (bytevector-reference-ref (make-reference-bytevector 8) 'oops)) (error? (bytevector-reference*-ref (make-reference-bytevector 8) -8)) (error? (bytevector-reference*-ref (make-reference-bytevector 8) 'oops)) + (error? (bytevector-reference*-ref (make-reference-bytevector 3) 1)) + (error? (bytevector-reference*-ref (make-reference-bytevector 3) 0)) + (error? (bytevector-reference*-ref (make-reference-bytevector 3) -1)) + (error? (guard (x [#t (error 'bytevector-reference-ref "failed as expected")]) + (bytevector-reference-ref (make-reference*-bytevector (foreign-sizeof 'ptr)) 1))) + (error? (bytevector-reference-set! (make-reference-bytevector 8) -8 #false)) + (error? (bytevector-reference-set! (make-reference-bytevector 8) 'oops #false)) + (error? (bytevector-reference-set! (make-reference-bytevector 3) 1 #false)) + (error? (bytevector-reference-set! (make-reference-bytevector 3) 0 #false)) + (error? (guard (x [#t (error 'bytevector-reference-set! "failed as expected")]) + (bytevector-reference-set! (make-reference-bytevector (foreign-sizeof 'ptr)) 1 #false))) (error? (reference-address->object #f)) (error? (reference*-address->object #f)) + (equal? #false (bytevector-reference-ref (make-reference-bytevector (foreign-sizeof 'ptr)) 0)) + (equal? #false (bytevector-reference*-ref (make-reference-bytevector (foreign-sizeof 'ptr)) 0)) + (equal? (void) (bytevector-reference-set! (make-reference-bytevector (foreign-sizeof 'ptr)) 0 #false)) + (not (reference-bytevector? #vu8(1 2 3))) (not (reference-bytevector? 7)) (begin diff --git a/mats/root-experr-compile-0-f-f-f b/mats/root-experr-compile-0-f-f-f index b8df4f0b1..6fd56e566 100644 --- a/mats/root-experr-compile-0-f-f-f +++ b/mats/root-experr-compile-0-f-f-f @@ -10458,9 +10458,22 @@ foreign.mo:Expected error in mat collect-safe: "foreign-callable: string result foreign.mo:Expected error in mat reference-bytevector: "make-reference-bytevector: -1 is not a valid bytevector length". foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-ref: #vu8(1 2 3) is not a reference bytevector". foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-ref: invalid index -8 for #vu8(0 0 0 0 0 0 ...)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-ref: invalid index 1 for #vu8(0 0 0)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-ref: invalid index 0 for #vu8(0 0 0)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-ref: invalid index -1 for #vu8(0 0 0)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-ref: failed as expected". foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-ref: invalid index oops for #vu8(0 0 0 0 0 0 ...)". foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference*-ref: invalid index -8 for #vu8(0 0 0 0 0 0 ...)". foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference*-ref: invalid index oops for #vu8(0 0 0 0 0 0 ...)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference*-ref: invalid index 1 for #vu8(0 0 0)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference*-ref: invalid index 0 for #vu8(0 0 0)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference*-ref: invalid index -1 for #vu8(0 0 0)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-ref: failed as expected". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-set!: invalid index -8 for #vu8(0 0 0 0 0 0 ...)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-set!: invalid index oops for #vu8(0 0 0 0 0 0 ...)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-set!: invalid index 1 for #vu8(0 0 0)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-set!: invalid index 0 for #vu8(0 0 0)". +foreign.mo:Expected error in mat reference-bytevector: "bytevector-reference-set!: failed as expected". foreign.mo:Expected error in mat reference-bytevector: "reference-address->object: invalid address #f". foreign.mo:Expected error in mat reference-bytevector: "reference*-address->object: invalid address #f". ftype.mo:Expected error in mat ftype: "unexpected function ftype outside pointer field (function #f (int) int)". diff --git a/s/prims.ss b/s/prims.ss index fb925609d..14aa49064 100644 --- a/s/prims.ss +++ b/s/prims.ss @@ -88,7 +88,7 @@ (lambda (bv i) (unless (reference-bytevector? bv) ($oops who "~s is not a reference bytevector" bv)) (unless (and (fixnum? i) - (not ($fxu< (fx- (bytevector-length bv) (fx- (constant ptr-bytes) 1)) i))) + (fx<= 0 i (fx- (bytevector-length bv) (constant ptr-bytes)))) ($oops who "invalid index ~s for ~s" i bv)) (bytevector-reference-ref bv i))) @@ -97,7 +97,7 @@ (lambda (bv i) (unless (reference-bytevector? bv) ($oops who "~s is not a reference bytevector" bv)) (unless (and (fixnum? i) - (not ($fxu< (fx- (bytevector-length bv) (fx- (constant ptr-bytes) 1)) i))) + (fx<= 0 i (fx- (bytevector-length bv) (constant ptr-bytes)))) ($oops who "invalid index ~s for ~s" i bv)) (ref bv i)))) @@ -105,7 +105,7 @@ (lambda (bv i val) (unless (reference-bytevector? bv) ($oops who "~s is not a reference bytevector" bv)) (unless (and (fixnum? i) - (not ($fxu< (fx- (bytevector-length bv) (fx- (constant ptr-bytes) 1)) i))) + (fx<= 0 i (fx- (bytevector-length bv) (constant ptr-bytes)))) ($oops who "invalid index ~s for ~s" i bv)) (bytevector-reference-set! bv i val)))