Package: simgear
Version: 3.2.0~git20140719+4a9125-2
Control: found -1 3.0.0-4
Control: tags -1 patch

simgear/nasal/naref.h uses a list of architectures to determine endianness, which is wrong on mipsel (it assumes __mips is always big-endian) and fails on anything it doesn't recognise (such as arm64: https://launchpadlibrarian.net/183053167/buildlog_ubuntu-utopic-arm64.simgear_3.0.0-4_FAILEDTOBUILD.txt.gz ).

The attached replaces this with the gcc __BYTE_ORDER__ macro.
Description: Use __BYTE_ORDER__ instead of arch list, and add test

Fixes wrong endianness on mipsel and FTBFS on arm64
https://launchpadlibrarian.net/183053167/buildlog_ubuntu-utopic-arm64.simgear_3.0.0-4_FAILEDTOBUILD.txt.gz

Author: Rebecca Palmer
diff --git a/simgear/nasal/cppbind/nasal_num_test.cxx b/simgear/nasal/cppbind/nasal_num_test.cxx
index e1e7dd0..d99034b 100644
--- a/simgear/nasal/cppbind/nasal_num_test.cxx
+++ b/simgear/nasal/cppbind/nasal_num_test.cxx
@@ -83,6 +83,12 @@ static void runNumTests( double (TestContext::*test_double)(const std::string&),
   BOOST_CHECK_EQUAL((c.*test_int)("0x755"), 0x755);
   BOOST_CHECK_EQUAL((c.*test_int)("0x055"), 0x55);
   BOOST_CHECK_EQUAL((c.*test_int)("-0x155"), -0x155);
+  
+  BOOST_CHECK_CLOSE((c.*test_double)("2.000000953656983160"),
+  2.000000953656983160, 1e-5);
+  /* this value has bit pattern 0x400000007fff6789L,
+  * so will look like a pointer if the endianness is set wrong
+  * (see naref.h, data.h)*/
 }
 
 BOOST_AUTO_TEST_CASE( parse_num )
diff --git a/simgear/nasal/naref.h b/simgear/nasal/naref.h
index 66ddedb..2ff9d57 100644
--- a/simgear/nasal/naref.h
+++ b/simgear/nasal/naref.h
@@ -1,28 +1,31 @@
 #ifndef _NAREF_H
 #define _NAREF_H
 
-/* Rather than play elaborate and complicated games with
- * platform-dependent endianness headers, just detect the platforms we
- * support.  This list is simpler and smaller, yet still quite
- * complete. */
 #if (defined(__x86_64) && defined(__linux__)) || defined(__sparcv9) || \
     defined(__powerpc64__)
-/* Win64 and Irix should work with this too, but have not been
- * tested */
+/* NASAL_NAN64 mode requires 64 bit pointers that only use the
+ * lower 48 bits; Win64 and Irix should work with this too, but
+ * have not been tested */
 # define NASAL_NAN64
+#elif defined(__BYTE_ORDER__)
+/* GCC and Clang define these (as a builtin, while
+* __LITTLE_ENDIAN__ requires a header), MSVC doesn't */
+# if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
+#  define NASAL_LE
+# elif __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
+#  define NASAL_BE
+# else
+#  error Unrecognized endianness
+# endif
 #elif defined(_M_IX86) || defined(i386) || defined(__x86_64) || \
       defined(__ia64__) || defined(_M_IA64) || defined(__ARMEL__) || \
-      defined(_M_X64) || defined(__alpha__) || \
-      (defined(__sh__) && defined(__LITTLE_ENDIAN__))
+      defined(_M_X64) || defined(_M_ARM)
 # define NASAL_LE
-#elif defined(__sparc) || defined(__ppc__) || defined(__PPC) || \
-      defined (__powerpc__) || defined (__powerpc64__) || defined (__alpha__) || \
-      defined(__mips) || defined(__ARMEB__) || \
-      defined(__hppa__) || defined(__s390__) || defined(__s390x__) || \
-      (defined(__sh__) && !defined(__LITTLE_ENDIAN__))
+#elif defined(__sparc) || defined(__ARMEB__) || \
+      defined(__hppa__) || defined(__s390__) || defined(__s390x__)
 # define NASAL_BE
 #else
-# error Unrecognized CPU architecture
+# error Unknown endianness
 #endif
 
 typedef union {

Reply via email to