{
unsigned long length;
uint8_t * v = (arg_bytevector (1, (&length)));
- unsigned long end = (arg_ulong_index_integer (3, (length + 1)));
- unsigned long start = (arg_ulong_index_integer (2, (end + 1)));
- uint8_t value = (arg_byte (4));
+ uint8_t value = (arg_byte (2));
+ unsigned long end = (arg_ulong_index_integer (4, (length + 1)));
+ unsigned long start = (arg_ulong_index_integer (3, (end + 1)));
memset ((v + start), value, (end - start));
}
PRIMITIVE_RETURN (UNSPECIFIC);
(define-primitives
(allocate-bytevector 1)
- (bytevector-fill! 4)
(bytevector-length 1)
(bytevector-u8-ref 2)
(bytevector-u8-set! 3)
(define (make-bytevector k #!optional byte)
(let ((bytevector (allocate-bytevector k)))
(if (not (default-object? byte))
- (bytevector-fill! bytevector 0 k byte))
+ (bytevector-fill! bytevector byte 0 k))
bytevector))
(define (bytevector . bytes)
(bytevector-copy! bytevector index (car bytevectors)))
bytevector))
+(define (bytevector-fill! bytevector fill #!optional start end)
+ ((ucode-primitive bytevector-fill! 4)
+ bytevector
+ fill
+ (if (default-object? start) 0 start)
+ (if (default-object? end) (bytevector-length bytevector) end)))
+
(define (bytevector-copy bytevector #!optional start end)
((ucode-primitive bytevector-copy 3)
bytevector
bytevector-append
bytevector-copy
bytevector-copy!
+ bytevector-fill!
bytevector-length
bytevector-u8-ref
bytevector-u8-set!
(v (apply bytevector bytes)))
(bytevector-copy! v 5 v 3 7)
(assert-equal v (bytevector 15 14 13 12 11 12 11 10 9 6 5 4 3 2 1 0)))))
+\f
+(define-test 'bytevector-fill!
+ (lambda ()
+ (do ((n 0 (+ n 1)))
+ ((not (< n 16)))
+ (let ((bytes (reverse (iota n))))
+ (do ((end 0 (+ end 1)))
+ ((> end n))
+ (do ((start 0 (+ start 1)))
+ ((> start end))
+ (let ((v (apply bytevector bytes)))
+ (bytevector-fill! v 51 start end)
+ (assert-equal v
+ (apply bytevector
+ (append (sublist bytes 0 start)
+ (make-list (- end start) 51)
+ (sublist bytes end n))))))))
+ (assert-range-error
+ (lambda ()
+ (bytevector-fill! (make-bytevector n) 51 0 (+ n 1))))
+ (assert-range-error
+ (lambda ()
+ (bytevector-fill! (make-bytevector n) 51 n (+ n 1))))
+ (assert-range-error
+ (lambda ()
+ (bytevector-fill! (make-bytevector n) 51 -1 n))))))
(define (test-bytevector-properties v bytes)
(assert-true (bytevector? v))