From fa58b9d538bab5c87fc2040e561b3eca31acbe39 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sun, 8 Aug 2021 21:47:31 -0400 Subject: [PATCH] `fxbit-set?` properly handles negative `i` --- CHANGELOG.md | 1 + srfi/143.sld | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad78142d..6c4f84b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Features Bug Fixes - @nmeum fixed `(scheme repl)` to flush the output port prior to writing the prompt, guaranteeing the prompt is written at the correct time. +- Fixed `fxbit-set?` to properly handle negative values of `i`. - Avoid unnecessary renaming of identifiers when the interpreter performs macro expansion. - When allocating a large vector we now guarantee all vector elements are initialized before the major collector can trace those elements. This avoids the potential for a race condition which could lead to a segmentation fault. - Ensure atomic objects are properly traced by the major garbage collector. diff --git a/srfi/143.sld b/srfi/143.sld index d94a216a..b147e0fa 100644 --- a/srfi/143.sld +++ b/srfi/143.sld @@ -50,7 +50,7 @@ fxarithmetic-shift fxarithmetic-shift-left fxarithmetic-shift-right fxbit-count - fxif fxbit-set? fxcopy-bit + fxif fxcopy-bit fxfirst-set-bit fxbit-field mask @@ -170,7 +170,12 @@ (fxior (fxand mask n0) (fxand (fxnot mask) n1))) - (define-c fxbit-set? + (define (fxbit-set? index i) + (or (%fxbit-set? index i) + (and (negative? i) + (>= index (fxlength i))))) + + (define-c %fxbit-set? "(void* data, int argc, closure _, object k, object index, object i)" " Cyc_check_fixnum(data, index); Cyc_check_fixnum(data, i);