From 69134f462b0deb672c77e5285184045db9e85db8 Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Wed, 29 Mar 2023 18:23:02 +0200 Subject: Fix CanCastAsInteger if errno is set. This method checks if the range of the input variable is fine. However if the errno variable was already set, it fails even for valid inputs. This fixes at least some random failures in the python castmode. Fixes: #2519 --- CHANGES.current | 4 ++++ Lib/typemaps/primtypes.swg | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 5caaddbe7..588459210 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.2.0 (in progress) =========================== +2023-04-21: degasus + #2519 Fix CanCastAsInteger range check to clear errno first to fix + bogus failures for valid inputs.if errno is set. + 2023-04-21: ZackerySpytz [OCaml] #1439 Fix reference typemaps for std::string diff --git a/Lib/typemaps/primtypes.swg b/Lib/typemaps/primtypes.swg index dd80eb775..85a0b8d9b 100644 --- a/Lib/typemaps/primtypes.swg +++ b/Lib/typemaps/primtypes.swg @@ -252,9 +252,11 @@ SWIGINTERNINLINE int SWIG_CanCastAsInteger(double *d, double min, double max) { double x = *d; if ((min <= x && x <= max)) { - double fx = floor(x); - double cx = ceil(x); - double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ + double fx, cx, rd; + errno = 0; + fx = floor(x); + cx = ceil(x); + rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ if ((errno == EDOM) || (errno == ERANGE)) { errno = 0; } else { -- cgit v1.2.1