summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Wick <markus@swabianinstruments.com>2023-03-29 18:23:02 +0200
committerOlly Betts <olly@survex.com>2023-04-21 11:10:10 +1200
commit69134f462b0deb672c77e5285184045db9e85db8 (patch)
tree0a0f15792c912e7b44f373e6cb7e12f5509d34ba
parent4ec23f5dcd20ce624f2d5466a0ece36568a6114a (diff)
downloadswig-69134f462b0deb672c77e5285184045db9e85db8.tar.gz
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
-rw-r--r--CHANGES.current4
-rw-r--r--Lib/typemaps/primtypes.swg8
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 {