From d8b918b566fd24d65f05eff3f6dcc692aa1aa120 Mon Sep 17 00:00:00 2001 From: Gustavo Massaccesi Date: Fri, 6 Mar 2026 10:56:50 -0300 Subject: [PATCH] fix bytevector-ieee-double-native-set! error When the last argument raises an error and the offset is out of the bounds, the compiler was reorganizing the code and the out of bound error was raised instead. (define bv (make-bytevector 16 0)) (define (f x) (bytevector-ieee-double-native-set! bv 100 (+ x 1))) (f 'bad) --- release_notes/release_notes.stex | 3 +++ s/cpprim.ss | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/release_notes/release_notes.stex b/release_notes/release_notes.stex index e5b2c6cc6..68ccede9f 100644 --- a/release_notes/release_notes.stex +++ b/release_notes/release_notes.stex @@ -2984,6 +2984,9 @@ When \scheme{>} and \scheme{>=} are applied to two non-real arguments, the first is now reported as incorrect instead of the second. In general, when two or more arguments are invalid, there is no guarantee about which one is reported invalid. +A bug in the error produced by \scheme{bytevector-ieee-double-native-set!} when the last +argument raises and error and the offset is out of bounds has been fixed. + \subsection{Fix \scheme{remainder} and \scheme{modulo} for inexact/exact mixtures (10.4.0)} When \scheme{remainder} and \scheme{modulo} receive an inexact first diff --git a/s/cpprim.ss b/s/cpprim.ss index 01a0e2260..d8f873704 100644 --- a/s/cpprim.ss +++ b/s/cpprim.ss @@ -7200,11 +7200,11 @@ (define-inline 2 bytevector-ieee-double-native-set! [(e-bv e-offset e-val) (bind #t (e-bv e-offset) - (let ([info (make-info-call #f #f #f #f #f)]) - `(if (call ,info ,#f ,(lookup-primref 3 '$bytevector-set!-check?) (quote 64) ,e-bv ,e-offset) - ;; checks to make sure e-val produces a real number: - (call ,info ,#f ,(lookup-primref 3 'bytevector-ieee-double-native-set!) ,e-bv ,e-offset ,e-val) - ,(build-libcall #t src sexpr bytevector-ieee-double-native-set! e-bv e-offset))))])) + (bind #f fp ([e-val (build-$real->flonum src sexpr `(quote bytevector-ieee-double-native-set!) e-val)]) + (let ([info (make-info-call #f #f #f #f #f)]) + `(if (call ,info ,#f ,(lookup-primref 3 '$bytevector-set!-check?) (quote 64) ,e-bv ,e-offset) + (call ,info ,#f ,(lookup-primref 3 'bytevector-ieee-double-native-set!) ,e-bv ,e-offset ,e-val) + ,(build-libcall #t src sexpr bytevector-ieee-double-native-set! e-bv e-offset)))))])) (let () (define-syntax define-bv-int-ref-inline