test/utils: Check for FE_INVALID definition before use

Submitted by Khem Raj on May 18, 2016, 12:32 a.m.

Details

Message ID 1463531520-13158-1-git-send-email-raj.khem@gmail.com
State New
Headers show
Series "test/utils: Check for FE_INVALID definition before use" ( rev: 1 ) in Pixman

Not browsing as part of any series.

Commit Message

Khem Raj May 18, 2016, 12:32 a.m.
Some architectures e.g. nios2 do not support all exceptions

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 test/utils.c | 2 ++
 1 file changed, 2 insertions(+)

Patch hide | download patch | download mbox

diff --git a/test/utils.c b/test/utils.c
index f8e42a5..fe32b1e 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -978,9 +978,11 @@  enable_invalid_exceptions (void)
 {
 #ifdef HAVE_FENV_H
 #ifdef HAVE_FEENABLEEXCEPT
+#ifdef FE_INVALID
     feenableexcept (FE_INVALID);
 #endif
 #endif
+#endif
 }
 
 void *

Comments

On Tue, 17 May 2016 17:32:00 -0700
Khem Raj <raj.khem@gmail.com> wrote:

> Some architectures e.g. nios2 do not support all exceptions
> 
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> ---
>  test/utils.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/test/utils.c b/test/utils.c
> index f8e42a5..fe32b1e 100644
> --- a/test/utils.c
> +++ b/test/utils.c
> @@ -978,9 +978,11 @@ enable_invalid_exceptions (void)
>  {
>  #ifdef HAVE_FENV_H
>  #ifdef HAVE_FEENABLEEXCEPT
> +#ifdef FE_INVALID
>      feenableexcept (FE_INVALID);
>  #endif
>  #endif
> +#endif
>  }
>  
>  void *

Thanks,

I think that we have seen this problem reported earlier, but the
proposed "fix" was an attempt to just disable compiling tests
altogether:
    https://patchwork.freedesktop.org/patch/70676

I'm glad that the root cause is finally getting properly addressed.
But before we can apply your patch, please change it to look like
    https://cgit.freedesktop.org/pixman/commit/?id=4297e9058d252cac653723fe0b1bee559fbac3a4

The reason is that such #ifdef based checks are not always reliable. We
never know what kind of stunts may be hidden in the header files on
various platforms and operating systems. And we already had been
surprised more than once. This is an artificial example, but please
consider the following code:

$ cat test.c 
/*******************************************************************/
static const int SOMETHING_THAT_LOOKS_LIKE_A_DEFINE = 123;

#ifdef SOMETHING_THAT_LOOKS_LIKE_A_DEFINE
#error SOMETHING_THAT_LOOKS_LIKE_A_DEFINE seems to be available
#else
#error SOMETHING_THAT_LOOKS_LIKE_A_DEFINE seems to be not available
#endif
/*******************************************************************/

$ gcc test.c
test.c:7:2: error: #error SOMETHING_THAT_LOOKS_LIKE_A_DEFINE seems to be not available
 #error SOMETHING_THAT_LOOKS_LIKE_A_DEFINE seems to be not available
  ^