Commits

Armin Rigo committed 572b329

Trying to fix issue677: remove the hard-coded endianness from dtoa.c,
and instead generate a stub .c file that defines the correct endianness
and #includes dtoa.c.

Comments (0)

Files changed (3)

 ^pypy/doc/.+\.html$
 ^pypy/doc/basicblock\.asc$
 ^pypy/doc/.+\.svninfo$
-^pypy/translator/c/src/dtoa.o$
 ^pypy/translator/c/src/libffi_msvc/.+\.obj$
 ^pypy/translator/c/src/libffi_msvc/.+\.dll$
 ^pypy/translator/c/src/libffi_msvc/.+\.lib$
 ^pypy/doc/image/parsing_example.+\.png$
 ^compiled
 ^.git/
-^release/
+^release/

pypy/rlib/rdtoa.py

 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rlib import jit
 from pypy.rlib.rstring import StringBuilder
-import py
+import py, sys
 
 cdir = py.path.local(pypydir) / 'translator' / 'c'
 include_dirs = [cdir]
 
+# set the word endianness based on the host's endianness
+if sys.byteorder == 'little':
+    source_file = []
+elif sys.byteorder == 'big':
+    source_file = ['#define WORDS_BIGENDIAN']
+else:
+    raise AssertionError(sys.byteorder)
+
+# ...and the C double's endianness
+if float.__getformat__('double') == 'IEEE, little-endian':
+    source_file.append('#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754')
+elif float.__getformat__('double') == 'IEEE, big-endian':
+    source_file.append('#define DOUBLE_IS_BIG_ENDIAN_IEEE754')
+else:
+    raise AssertionError(float.__getformat__())
+
+source_file.append('#include "src/dtoa.c"')
+source_file = '\n\n'.join(source_file)
+
+# ____________________________________________________________
+
 eci = ExternalCompilationInfo(
     include_dirs = [cdir],
     includes = ['src/dtoa.h'],
     libraries = [],
-    separate_module_files = [cdir / 'src' / 'dtoa.c'],
+    separate_module_sources = [source_file],
     export_symbols = ['_PyPy_dg_strtod',
                       '_PyPy_dg_dtoa',
                       '_PyPy_dg_freedtoa',

pypy/translator/c/src/dtoa.c

 
 /* Begin PYPY hacks */
 /* #include "Python.h" */
-#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754
 #define HAVE_UINT32_T
 #define HAVE_INT32_T
 #define HAVE_UINT64_T