Ensure NAN is always initialized.
authorRobert Bradshaw <robertwb@gmail.com>
Tue, 9 Apr 2013 21:34:23 +0000 (14:34 -0700)
committerRobert Bradshaw <robertwb@gmail.com>
Tue, 9 Apr 2013 21:34:23 +0000 (14:34 -0700)
Cython/Compiler/Naming.py
Cython/Compiler/Nodes.py
Cython/Utility/ModuleSetupCode.c

index 7a103d8..b7432b2 100644 (file)
@@ -133,7 +133,7 @@ h_guard_prefix   = "__PYX_HAVE__"
 api_guard_prefix = "__PYX_HAVE_API__"
 api_func_guard   = "__PYX_HAVE_API_FUNC_"
 
-PYX_NAN          = "__PYX_NAN"
+PYX_NAN          = "__PYX_NAN()"
 
 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)
index 6e75a3e..e1ce05e 100644 (file)
@@ -7082,8 +7082,6 @@ class ParallelStatNode(StatNode, ParallelNode):
                     if first:
                         code.putln("/* Initialize private variables to "
                                    "invalid values */")
-                        code.globalstate.use_utility_code(
-                                invalid_values_utility_code)
                         first = False
                     code.putln("%s = %s;" % (entry.cname,
                                              entry.type.cast_code(invalid_value)))
@@ -8156,21 +8154,3 @@ bad:
     return NULL;
 }
 """)
-
-################ Utility code for cython.parallel stuff ################
-
-invalid_values_utility_code = UtilityCode(
-proto="""\
-#include <string.h>
-
-void __pyx_init_nan(void);
-
-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 quiet NaN. */
-    memset(&%(PYX_NAN)s, 0xFF, sizeof(%(PYX_NAN)s));
-""" % vars(Naming))
index e28844c..2953072 100644 (file)
   #define __Pyx_DOCSTR(n)  (n)
 #endif
 
+#ifdef NAN
+#define __PYX_NAN() ((float) NAN)
+#else
+static inline float __PYX_NAN() {
+  /* 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 quiet NaN. */
+  float value;
+  memset(&value, 0xFF, sizeof(value));
+  return value;
+}
+#endif
+
 /////////////// UtilityFunctionPredeclarations.proto ///////////////
 
 /* inline attribute */