1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-26 05:02:18 +00:00

math/Imath: relax user to C++11, regression fix

Cherry-pick an upstream fix to relax users to C++11, only the
Imath code itself requires C++14.

Cherry-pick an upstream fix for a regression in succf()/predf().

While here, run tests in parallel and clean up for portclippy.
This commit is contained in:
Matthias Andree 2021-05-08 11:52:43 +02:00
parent 487828600d
commit bce7a5281d
3 changed files with 238 additions and 3 deletions

View File

@ -2,6 +2,7 @@
PORTNAME= Imath
PORTVERSION= 3.0.1
PORTREVISION= 1
CATEGORIES= math devel graphics
MAINTAINER= mandree@FreeBSD.org
@ -18,6 +19,8 @@ USE_LDCONFIG= yes
CMAKE_ARGS+= -DCMAKE_DEBUG_POSTFIX= \
-DCMAKE_INSTALL_PREFIX=${PREFIX}
PATCH_STRIP= -p1
PLIST_SUB= MAJORVER=${_MAJORVER} \
MINVER=${_MINVER} \
PLVER=${_PLVER} \
@ -31,11 +34,11 @@ OPTIONS_SUB= yes
LARGE_STACK_DESC= Enable sys-dependent large stack optimizations
LARGE_STACK_CMAKE_BOOL= IMATH_ENABLE_LARGE_STACK
PYTHON_BUILD_DEPENDS= ${PYNUMPY}
PYTHON_LIB_DEPENDS= ${PY_BOOST}
PYTHON_RUN_DEPENDS= ${PYNUMPY}
PYTHON_USES= python
PYTHON_CMAKE_BOOL= PYTHON
PYTHON_BUILD_DEPENDS= ${PYNUMPY}
PYTHON_RUN_DEPENDS= ${PYNUMPY}
_MAJORVER= 3_0
_VER= 27
@ -51,6 +54,6 @@ post-install:
${INSTALL_DATA} ${PORTDOCS:S|^|${WRKSRC}/|} ${STAGEDIR}${DOCSDIR}
do-test:
cd ${BUILD_WRKSRC} && ctest
cd ${BUILD_WRKSRC} && ctest -j ${MAKE_JOBS_NUMBER}
.include <bsd.port.mk>

View File

@ -0,0 +1,49 @@
From 1c8a010f9c48fb9c8dd5330337936802c3dee2bd Mon Sep 17 00:00:00 2001
From: Larry Gritz <lg@larrygritz.com>
Date: Thu, 15 Apr 2021 17:41:11 -0700
Subject: [PATCH] Don't impose C++14 on downstream projects (#137)
We were setting
target_compile_features(${objlib} PUBLIC cxx_std_${IMATH_CXX_STANDARD})
The PUBLIC forced downstream projects that consume the
ImathConfig*.cmake exports to use C++ standard at least as recent as
what Imath used to build (which defaults to 14).
But this is unnecessary. There's nothing in Imath's headers that
requires anything beyond C++11. So this patch uses a more fine-grained
setting of target properties to express this more correctly. Now it
will be fine for a C++11 project to consume Imath (via its exported
configs) even if that Imath happened to be built with C++14.
This change is exactly the same as
https://github.com/AcademySoftwareFoundation/openexr/pull/995
Signed-off-by: Larry Gritz <lg@larrygritz.com>
---
config/LibraryDefine.cmake | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/config/LibraryDefine.cmake b/config/LibraryDefine.cmake
index 7770d71..faf430e 100644
--- a/config/LibraryDefine.cmake
+++ b/config/LibraryDefine.cmake
@@ -14,7 +14,16 @@ function(IMATH_DEFINE_LIBRARY libname)
${IMATH_CURLIB_HEADERS}
${IMATH_CURLIB_SOURCES})
- target_compile_features(${objlib} PUBLIC cxx_std_${IMATH_CXX_STANDARD})
+ # Use ${IMATH_CXX_STANDARD} to determine the standard we use to compile
+ # Imath itself. But the headers only require C++11 features, so that's
+ # all we need to pass on as interface reqirements to downstream projects.
+ # For example, it's fine for an Imath built with C++14 to be called from
+ # an app that is compiled with C++11; Imath needn't force the app to
+ # also use C++14.
+ target_compile_features(${objlib}
+ PRIVATE cxx_std_${IMATH_CXX_STANDARD}
+ INTERFACE cxx_std_11 )
+
if(IMATH_CURLIB_PRIV_EXPORT AND BUILD_SHARED_LIBS)
target_compile_definitions(${objlib} PRIVATE ${IMATH_CURLIB_PRIV_EXPORT})
if(WIN32)

View File

@ -0,0 +1,183 @@
From 6ddc8294f319dfd6ac27b511f65f5900f819eca5 Mon Sep 17 00:00:00 2001
From: Cary Phillips <cary@ilm.com>
Date: Fri, 7 May 2021 14:27:47 -0700
Subject: [PATCH] Fix regression in succf()/predf() (#140)
And add more thorough test.
Signed-off-by: Cary Phillips <cary@ilm.com>
---
src/Imath/ImathFun.cpp | 4 +-
src/ImathTest/testFun.cpp | 86 +++++++++++++++++++++++++++++----------
2 files changed, 67 insertions(+), 23 deletions(-)
diff --git a/src/Imath/ImathFun.cpp b/src/Imath/ImathFun.cpp
index 62ecadf..793927c 100644
--- a/src/Imath/ImathFun.cpp
+++ b/src/Imath/ImathFun.cpp
@@ -27,7 +27,7 @@ succf (float f) noexcept
u.i = 0x00000001;
}
- else if (u.i > 0)
+ else if (u.f > 0)
{
// Positive float, normalized or denormalized.
// Incrementing the largest positive float
@@ -65,7 +65,7 @@ predf (float f) noexcept
u.i = 0x80000001;
}
- else if (u.i > 0)
+ else if (u.f > 0)
{
// Positive float, normalized or denormalized.
diff --git a/src/ImathTest/testFun.cpp b/src/ImathTest/testFun.cpp
index abb2bd3..56db842 100644
--- a/src/ImathTest/testFun.cpp
+++ b/src/ImathTest/testFun.cpp
@@ -8,6 +8,10 @@
#endif
#include "ImathFun.h"
+#if __cplusplus >= 202002L
+# include <bit>
+#endif
+#include <iostream>
#include <assert.h>
#include <iostream>
#include <stdio.h>
@@ -18,16 +22,32 @@ using namespace std;
#if ULONG_MAX == 18446744073709551615LU
typedef long unsigned int Int64;
#else
-typedef long long unsigned int Int64;
+ typedef long long unsigned int Int64;
+#endif
+
+#if __cplusplus < 202002L
+ template <typename To, typename From>
+ static inline To
+ bit_cast (From from)
+ {
+ static_assert (sizeof (From) == sizeof (To), "Type sizes do not match");
+ union
+ {
+ From f;
+ To t;
+ } u;
+ u.f = from;
+ return u.t;
+ }
#endif
void
-testf (float f)
+testf (float f, bool changeExpected = true)
{
printf ("\n");
- float sf = IMATH_INTERNAL_NAMESPACE::succf (f);
- float pf = IMATH_INTERNAL_NAMESPACE::predf (f);
+ float sf = IMATH_INTERNAL_NAMESPACE::succf (f);
+ float pf = IMATH_INTERNAL_NAMESPACE::predf (f);
float spf = IMATH_INTERNAL_NAMESPACE::succf (IMATH_INTERNAL_NAMESPACE::predf (f));
float psf = IMATH_INTERNAL_NAMESPACE::predf (IMATH_INTERNAL_NAMESPACE::succf (f));
@@ -36,15 +56,29 @@ testf (float f)
printf ("pf %.9g\n", pf);
printf ("spf %.9g\n", spf);
printf ("psf %.9g\n", psf);
+
+ fflush (stdout);
+
+ if (changeExpected)
+ {
+ assert (pf < f);
+ assert (f < sf);
+ }
+ else
+ {
+ // No bit change expected if input was inf or NaN
+ assert (bit_cast<unsigned> (pf) == bit_cast<unsigned> (f));
+ assert (bit_cast<unsigned> (sf) == bit_cast<unsigned> (f));
+ }
}
void
-testd (double d)
+testd (double d, bool changeExpected = true)
{
printf ("\n");
- double sd = IMATH_INTERNAL_NAMESPACE::succd (d);
- double pd = IMATH_INTERNAL_NAMESPACE::predd (d);
+ double sd = IMATH_INTERNAL_NAMESPACE::succd (d);
+ double pd = IMATH_INTERNAL_NAMESPACE::predd (d);
double spd = IMATH_INTERNAL_NAMESPACE::succd (IMATH_INTERNAL_NAMESPACE::predd (d));
double psd = IMATH_INTERNAL_NAMESPACE::predd (IMATH_INTERNAL_NAMESPACE::succd (d));
@@ -53,6 +87,20 @@ testd (double d)
printf ("pd %.18lg\n", pd);
printf ("spd %.18lg\n", spd);
printf ("psd %.18lg\n", psd);
+
+ fflush (stdout);
+
+ if (changeExpected)
+ {
+ assert (pd < d);
+ assert (d < sd);
+ }
+ else
+ {
+ // No bit change expected if input was inf or NaN
+ assert (bit_cast<Int64> (pd) == bit_cast<Int64> (d));
+ assert (bit_cast<Int64> (sd) == bit_cast<Int64> (d));
+ }
}
void
@@ -196,15 +244,13 @@ testFun()
testf (7);
testf (0.7);
- union
- {
- float f;
- int i;
- } u;
+ union {float f; int i;} u;
u.i = 0x7f800000; // inf
- testf (u.f);
+ testf (u.f, false);
+ u.i = 0xff800000; // -inf
+ testf (u.f, false);
u.i = 0x7f800001; // nan
- testf (u.f);
+ testf (u.f, false);
u.i = 0x7f7fffff; // FLT_MAX
testf (u.f);
u.i = 0xff7fffff; // -FLT_MAX
@@ -218,15 +264,13 @@ testFun()
testd (7);
testd (0.7);
- union
- {
- double d;
- Int64 i;
- } v;
+ union {double d; Int64 i;} v;
v.i = 0x7ff0000000000000ULL; // inf
- testd (v.d);
+ testd (v.d, false);
+ v.i = 0xfff0000000000000ULL; // -inf
+ testd (v.d, false);
v.i = 0x7ff0000000000001ULL; // NAN
- testd (v.d);
+ testd (v.d, false);
v.i = 0x7fefffffffffffffULL; // FLT_MAX
testd (v.d);
v.i = 0xffefffffffffffffULL; // -FLT_MAX