From c92189e7ece51d7069a794430834b6534286faf4 Mon Sep 17 00:00:00 2001
From: Mark Florisson <markflorisson88@gmail.com>
Date: Mon, 23 May 2011 18:13:21 +0200
Subject: [PATCH] Remove platform-specific NaN initialization

---
 Cython/Compiler/Naming.py     |  3 ---
 Cython/Compiler/Nodes.py      | 43 +++++++++++------------------------
 Cython/Compiler/PyrexTypes.py | 10 ++++----
 3 files changed, 18 insertions(+), 38 deletions(-)

diff --git a/Cython/Compiler/Naming.py b/Cython/Compiler/Naming.py
index 2c516617f..501a84a1a 100644
--- a/Cython/Compiler/Naming.py
+++ b/Cython/Compiler/Naming.py
@@ -117,9 +117,6 @@ api_guard_prefix = "__PYX_HAVE_API__"
 api_func_guard   = "__PYX_HAVE_API_FUNC_"
 
 PYX_NAN          = "__PYX_NAN"
-HUGE_VAL         = "Py_HUGE_VAL"
-LONG_LONG_MAX    = "__PYX_LONG_LONG_MAX"
-ULONG_LONG_MAX   = "__PYX_ULONG_LONG_MAX"
 
 def py_version_hex(major, minor=0, micro=0, release_level=0, release_serial=0):
     return (major << 24) | (minor << 16) | (micro << 8) | (release_level << 4) | (release_serial)
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index 4406da393..6a426768a 100644
--- a/Cython/Compiler/Nodes.py
+++ b/Cython/Compiler/Nodes.py
@@ -7592,36 +7592,19 @@ bad:
 
 ################ Utility code for cython.parallel stuff ################
 
-invalid_values_utility_code = UtilityCode(proto="""
-#ifdef HAVE_LONG_LONG
-    #define %(LONG_LONG_MAX)s PY_LLONG_MAX
-    #define %(ULONG_LONG_MAX)s PY_ULLONG_MAX
-#else
-    #define PY_LONG_LONG LONG_LONG
+invalid_values_utility_code = UtilityCode(
+proto="""\
+#include <string.h>
 
-    #if defined(LLONG_MAX)
-        #define %(LONG_LONG_MAX)s LLONG_MAX
-        #define %(ULONG_LONG_MAX)s ULLONG_MAX
-    #else
-        #define %(LONG_LONG_MAX)s LONG_MAX
-        #define %(ULONG_LONG_MAX)s ULONG_MAX
-    #endif
-#endif
+void __pyx_init_nan(void);
 
-/* Define NAN */
-#ifdef Py_NAN
-    #define %(PYX_NAN)s Py_NAN
-#elif defined(NAN)
-    #define %(PYX_NAN)s NAN
-#elif defined(HUGE_VALL)
-    #define %(PYX_NAN)s HUGE_VALL
-#elif defined(__STDC__) && __STDC_VERSION__ >= 199901L
-    /* C99 or greater */
-    #include <float.h>
-    #define %(PYX_NAN)s LDBL_MAX
-#else
-    static PY_LONG_LONG __pyx__nan = %(LONG_LONG_MAX)s;
-    #define %(PYX_NAN)s (*(double*) &__pyx__nan)
-#endif
-"""  % vars(Naming))
+static float %(PYX_NAN)s;
+"""  % vars(Naming),
+
+init="""
+/* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
+   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
+   a signalling NaN. */
+    memset(&%(PYX_NAN)s, 0xFF, sizeof(%(PYX_NAN)s));
+""" % vars(Naming))
 
diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py
index 11dd0cea3..b9e61b385 100755
--- a/Cython/Compiler/PyrexTypes.py
+++ b/Cython/Compiler/PyrexTypes.py
@@ -2370,11 +2370,11 @@ rank_to_type_name = (
 )
 
 typename_to_maxval = {
-    "char" : ("CHAR_MAX", "UCHAR_MAX"),
-    "short": ("SHRT_MAX", "USHRT_MAX"),
-    "int"  : ("INT_MAX", "UINT_MAX"),
-    "long" : ("LONG_MAX", "ULONG_MAX"),
-    "PY_LONG_LONG" : (Naming.LONG_LONG_MAX, Naming.ULONG_LONG_MAX),
+    "char" : ("'?'", "'?'"),
+    "short": ("0xbad", "0xbad0"),
+    "int"  : ("0xbad", "0xbad0"),
+    "long" : ("0xbad0bad", "0xbad0bad0"),
+    "PY_LONG_LONG" : ("0xbad0bad0bad0bad", "0xbad0bad0bad0bad0"),
     # CFloatType overrides invalid_value
 }
 
-- 
2.30.9