[Mesa-dev,v2] math: Import isinf and others to global namespace

Submitted by Pierre Moreau on March 31, 2016, 10:08 p.m.

Details

Message ID 1459462132-2362-1-git-send-email-pierre.morrow@free.fr
State Superseded
Headers show
Series "nv50/ra: `isinf()` is in namespace `std` since C++11" ( rev: 2 ) in Mesa

Not browsing as part of any series.

Commit Message

Pierre Moreau March 31, 2016, 10:08 p.m.
Starting from C++11, several math functions, like isinf, moved into the std
namespace. Since cmath undefines those functions before redefining them inside
the namespace, and glibc 2.23 defines the C variants as macros, the C variants
in global namespace are not accessible any longer.

v2: Move the fix outside of Nouveau, as suggested by Jose Fonseca, since anyone
    might need it when GCC switches to C++14 by default with GCC 6.0.

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 include/cpp11_math.h                | 61 +++++++++++++++++++++++++++++++++++++
 src/gallium/auxiliary/util/u_math.h |  3 ++
 2 files changed, 64 insertions(+)
 create mode 100644 include/cpp11_math.h

Patch hide | download patch | download mbox

diff --git a/include/cpp11_math.h b/include/cpp11_math.h
new file mode 100644
index 0000000..1f4aa3c
--- /dev/null
+++ b/include/cpp11_math.h
@@ -0,0 +1,61 @@ 
+/**************************************************************************
+ *
+ * Copyright 2016 Pierre Moreau
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * Wrapper for cmath which makes sure we maintain source compatibility with
+ * newer versions of C++.
+ */
+
+
+#ifndef _CPP11_MATH_H_
+#define _CPP11_MATH_H_
+
+
+/* Since C++11, the following functions are part of the std namespace. Their C
+ * counteparts should still exist in the global namespace, however cmath
+ * undefines those functions, which in glibc 2.23, are defined as macros rather
+ * than functions as in glibc 2.22.
+ */
+#if __cplusplus >= 201103L
+#include <cmath>
+
+using std::fpclassify;
+using std::isfinite;
+using std::isinf;
+using std::isnan;
+using std::isnormal;
+using std::signbit;
+using std::isgreater;
+using std::isgreaterequal;
+using std::isless;
+using std::islessequal;
+using std::islessgreater;
+using std::isunordered;
+#endif
+
+
+#endif /* #define _CPP11_MATH_H_ */
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index e92f83a..12a3780 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -42,6 +42,9 @@ 
 #include "pipe/p_compiler.h"
 
 #include "c99_math.h"
+#ifdef __cplusplus
+#include "cpp11_math.h"
+#endif
 #include <assert.h>
 #include <float.h>
 #include <stdarg.h>

Comments

On 31/03/16 23:08, Pierre Moreau wrote:
> Starting from C++11, several math functions, like isinf, moved into the std
> namespace. Since cmath undefines those functions before redefining them inside
> the namespace, and glibc 2.23 defines the C variants as macros, the C variants
> in global namespace are not accessible any longer.
>
> v2: Move the fix outside of Nouveau, as suggested by Jose Fonseca, since anyone
>      might need it when GCC switches to C++14 by default with GCC 6.0.
>
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> ---
>   include/cpp11_math.h                | 61 +++++++++++++++++++++++++++++++++++++
>   src/gallium/auxiliary/util/u_math.h |  3 ++
>   2 files changed, 64 insertions(+)
>   create mode 100644 include/cpp11_math.h
>
> diff --git a/include/cpp11_math.h b/include/cpp11_math.h
> new file mode 100644
> index 0000000..1f4aa3c
> --- /dev/null
> +++ b/include/cpp11_math.h

I'm not sure a new header is necessary for this.

What this is doing is making C++11 math functions "appear" like C99 
ones.  It's not making things matching C++11 standard.

So IMO the right place for this is the end of c99_math.h

Jose

> @@ -0,0 +1,61 @@
> +/**************************************************************************
> + *
> + * Copyright 2016 Pierre Moreau
> + * All Rights Reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sub license, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the
> + * next paragraph) shall be included in all copies or substantial portions
> + * of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
> + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
> + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + **************************************************************************/
> +
> +/**
> + * Wrapper for cmath which makes sure we maintain source compatibility with
> + * newer versions of C++.
> + */
> +
> +
> +#ifndef _CPP11_MATH_H_
> +#define _CPP11_MATH_H_
> +
> +
> +/* Since C++11, the following functions are part of the std namespace. Their C
> + * counteparts should still exist in the global namespace, however cmath
> + * undefines those functions, which in glibc 2.23, are defined as macros rather
> + * than functions as in glibc 2.22.
> + */
> +#if __cplusplus >= 201103L
> +#include <cmath>
> +
> +using std::fpclassify;
> +using std::isfinite;
> +using std::isinf;
> +using std::isnan;
> +using std::isnormal;
> +using std::signbit;
> +using std::isgreater;
> +using std::isgreaterequal;
> +using std::isless;
> +using std::islessequal;
> +using std::islessgreater;
> +using std::isunordered;
> +#endif
> +
> +
> +#endif /* #define _CPP11_MATH_H_ */
> diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
> index e92f83a..12a3780 100644
> --- a/src/gallium/auxiliary/util/u_math.h
> +++ b/src/gallium/auxiliary/util/u_math.h
> @@ -42,6 +42,9 @@
>   #include "pipe/p_compiler.h"
>
>   #include "c99_math.h"
> +#ifdef __cplusplus
> +#include "cpp11_math.h"
> +#endif
>   #include <assert.h>
>   #include <float.h>
>   #include <stdarg.h>
>
On 01:11 PM - Apr 01 2016, Jose Fonseca wrote:
> On 31/03/16 23:08, Pierre Moreau wrote:
> >Starting from C++11, several math functions, like isinf, moved into the std
> >namespace. Since cmath undefines those functions before redefining them inside
> >the namespace, and glibc 2.23 defines the C variants as macros, the C variants
> >in global namespace are not accessible any longer.
> >
> >v2: Move the fix outside of Nouveau, as suggested by Jose Fonseca, since anyone
> >     might need it when GCC switches to C++14 by default with GCC 6.0.
> >
> >Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> >---
> >  include/cpp11_math.h                | 61 +++++++++++++++++++++++++++++++++++++
> >  src/gallium/auxiliary/util/u_math.h |  3 ++
> >  2 files changed, 64 insertions(+)
> >  create mode 100644 include/cpp11_math.h
> >
> >diff --git a/include/cpp11_math.h b/include/cpp11_math.h
> >new file mode 100644
> >index 0000000..1f4aa3c
> >--- /dev/null
> >+++ b/include/cpp11_math.h
> 
> I'm not sure a new header is necessary for this.
> 
> What this is doing is making C++11 math functions "appear" like C99 ones.
> It's not making things matching C++11 standard.
> 
> So IMO the right place for this is the end of c99_math.h

I was planning to put it in the c99 header first, but as I was including some
C++ header, I felt that having a separate header which would only be included
by C++ files would be better. I could have the `#ifdef __cplusplus` around the
whole block inside the c99_math.h instead, if you prefer it that way.

Thanks,
Pierre

> 
> Jose
> 
> >@@ -0,0 +1,61 @@
> >+/**************************************************************************
> >+ *
> >+ * Copyright 2016 Pierre Moreau
> >+ * All Rights Reserved.
> >+ *
> >+ * Permission is hereby granted, free of charge, to any person obtaining a
> >+ * copy of this software and associated documentation files (the
> >+ * "Software"), to deal in the Software without restriction, including
> >+ * without limitation the rights to use, copy, modify, merge, publish,
> >+ * distribute, sub license, and/or sell copies of the Software, and to
> >+ * permit persons to whom the Software is furnished to do so, subject to
> >+ * the following conditions:
> >+ *
> >+ * The above copyright notice and this permission notice (including the
> >+ * next paragraph) shall be included in all copies or substantial portions
> >+ * of the Software.
> >+ *
> >+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> >+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> >+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
> >+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
> >+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> >+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> >+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> >+ *
> >+ **************************************************************************/
> >+
> >+/**
> >+ * Wrapper for cmath which makes sure we maintain source compatibility with
> >+ * newer versions of C++.
> >+ */
> >+
> >+
> >+#ifndef _CPP11_MATH_H_
> >+#define _CPP11_MATH_H_
> >+
> >+
> >+/* Since C++11, the following functions are part of the std namespace. Their C
> >+ * counteparts should still exist in the global namespace, however cmath
> >+ * undefines those functions, which in glibc 2.23, are defined as macros rather
> >+ * than functions as in glibc 2.22.
> >+ */
> >+#if __cplusplus >= 201103L
> >+#include <cmath>
> >+
> >+using std::fpclassify;
> >+using std::isfinite;
> >+using std::isinf;
> >+using std::isnan;
> >+using std::isnormal;
> >+using std::signbit;
> >+using std::isgreater;
> >+using std::isgreaterequal;
> >+using std::isless;
> >+using std::islessequal;
> >+using std::islessgreater;
> >+using std::isunordered;
> >+#endif
> >+
> >+
> >+#endif /* #define _CPP11_MATH_H_ */
> >diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
> >index e92f83a..12a3780 100644
> >--- a/src/gallium/auxiliary/util/u_math.h
> >+++ b/src/gallium/auxiliary/util/u_math.h
> >@@ -42,6 +42,9 @@
> >  #include "pipe/p_compiler.h"
> >
> >  #include "c99_math.h"
> >+#ifdef __cplusplus
> >+#include "cpp11_math.h"
> >+#endif
> >  #include <assert.h>
> >  #include <float.h>
> >  #include <stdarg.h>
> >
>