Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMATH_NOEXCEPT macro to make noexcept a compile-time option #157

Merged
merged 6 commits into from
Jun 4, 2021

Conversation

cary-ilm
Copy link
Member

@cary-ilm cary-ilm commented Jun 2, 2021

Legacy code that depends on the IlmBase v2 ExcMath mechanism of signal
handlers that throw exceptions is incompatible with noexcept, since
floating-point overflow and underflow can occur in computations within
Imath functions now marked with noexcept. Legacy code that needs to
accomodate the exception-handling behavior can disable the noexcept
specifier by defining the IMATH_NOEXCEPT macro to be empty. Otherwise,
IMATH_NOEXEPT defaults to "noexcept".

Signed-off-by: Cary Phillips [email protected]

Legacy code that depends on the IlmBase v2 ExcMath mechanism of signal
handlers that throw exceptions is incompatible with noexcept, since
floating-point overflow and underflow can occur in computations within
Imath functions now marked with noexcept. Legacy code that needs to
accomodate the exception-handling behavior can disable the noexcept
specifier by defining the IMATH_NOEXCEPT macro to be empty. Otherwise,
IMATH_NOEXEPT defaults to "noexcept".

Signed-off-by: Cary Phillips <[email protected]>
@lgritz
Copy link
Contributor

lgritz commented Jun 2, 2021

Excuse the dumb question because I don't use exceptions, so maybe this is just showing off my ignorance.

FPU exceptions don't throw C++ exceptions, do they?

I'm not sure I understand how an overflow leads to a regular C++ exception.

@cary-ilm
Copy link
Member Author

cary-ilm commented Jun 2, 2021

In v2.5, the IexMath library (https://github.com/AcademySoftwareFoundation/openexr/blob/RB-2.5/IlmBase/IexMath/IexMathFpu.cpp) installs signal handlers that catch floating point overflow, underflow, division by zero, and invalid floating point operations, and the signal handlers throw exceptions. ILM also uses a custom "math.h" with fancy macros to substitute throwing versions of sqrt(), etc for the standard library functions. Both of these dramatically affect the normal flow of control and mean exceptions can arise anywhere floating-point computation occurs, which is incompatible with "noexcept".

I'm not necessarily endorsing or encouraging this, but it's behavior a large body of legacy code relies on. It's a philosophy of preventing bad values from ever entering your program's data by intercepting NaN as close to their point of origin as possible.

@lgritz
Copy link
Contributor

lgritz commented Jun 2, 2021

I assume that this is was never turned on by default?

@cary-ilm
Copy link
Member Author

cary-ilm commented Jun 2, 2021

It's turned on via the mathExcOn(when) function, which I don't think is invoked by the OpenEXR library, but the Imath python bindings did previously enable them by default.

Signed-off-by: Cary Phillips <[email protected]>
Signed-off-by: Cary Phillips <[email protected]>
@cary-ilm cary-ilm closed this Jun 2, 2021
@cary-ilm cary-ilm reopened this Jun 2, 2021
@cary-ilm
Copy link
Member Author

cary-ilm commented Jun 3, 2021

Added IMATH_USE_NOEXCEPT Cmake option, defaults to ON.

@cary-ilm cary-ilm merged commit 7df486c into AcademySoftwareFoundation:master Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants