From 334787b6d6a34a65f30ff5a2414bf0c708aaf974 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 5 Dec 2023 18:14:52 -0800 Subject: [PATCH] Issue #517 - Raise error when reading invalid number Previously #f was returned in this case but it is more correct to raise an error instead. This prevents weird edge cases and is more consistent with other schemes. --- CHANGELOG.md | 1 + scheme/read.sld | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f270f22..4ec00b84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Bug Fixes - Fix `read-line` to read entire lines that consist of more than 1022 bytes. Previously the function would only return partial data up to this limit. Thanks to Robby Zambito for the bug report. - `(include "body.scm")` inside a file `path/to/lib.sld` will look for `path/to/body.scm`, then fallback to the legacy behavior, and look for `$(pwd)/body.scm`. - Pass append and prepend directories when compiling dependent libraries of a program. This prevents issues where the directories are not made available to any `include` directives within such libraries. +- Updated the reader to throw an error if a number cannot be parsed, rather than returning `#f`. ## 0.35.0 - August 25, 2022 diff --git a/scheme/read.sld b/scheme/read.sld index efc41e21..0b67f6e4 100644 --- a/scheme/read.sld +++ b/scheme/read.sld @@ -179,6 +179,12 @@ "(void *data, object ptr, object opq)" " return(Cyc_is_string(opaque_ptr(opq)));") +(define-c Cyc-opaque->string + "(void *data, int argc, closure _, object k, object opq)" + " return_closcall1(data, k, opaque_ptr(opq));" + "(void *data, object ptr, object opq)" + " return(opaque_ptr(opq));") + (define-c Cyc-opaque-unsafe-string->number "(void *data, int argc, closure _, object k, object opq)" " Cyc_string2number_(data, k, opaque_ptr(opq));") @@ -226,7 +232,10 @@ ((Cyc-opaque? token) (cond ((Cyc-opaque-unsafe-string? token) - (Cyc-opaque-unsafe-string->number token)) + (let ((rv (Cyc-opaque-unsafe-string->number token))) + (if rv + rv + (error "Invalid numeric syntax" (Cyc-opaque->string token))))) ;; Open paren, start read loop ((Cyc-opaque-unsafe-eq? token #\() (let ((line-num (get-line-num fp))