[Kst] extragear/graphics/kst/src/datasources/dirfile

Helge Deller deller at kde.org
Fri Apr 14 11:04:41 CEST 2006


SVN commit 529713 by deller:

some platforms have very strict alignment definitions for double type
variables.
Take code from kjs, where we already fixed this years ago.


 M  +19 -11    getdata.h  


--- trunk/extragear/graphics/kst/src/datasources/dirfile/getdata.h #529712:529713
@@ -2,27 +2,35 @@
 #ifndef GETDATA_H
 #define GETDATA_H
 
-/* The following has been extracted from kstmath.h */
+/* The following has been extracted from internal.cpp from kjs */
 
 /*
 ** For systems without NAN, this is a NAN in IEEE double format.
-** Code lifted from kde screensavers.
 */
+
 #if !defined(NAN)
-static inline double nan__()
+#include <qconfig.h>
+static double __NAN()
 {
-  static const unsigned int one = 1;
-  const int BigEndian = (*((unsigned char*)&one) == 0);
+  /* work around some strict alignment requirements
+     for double variables on some architectures (e.g. PA-RISC) */
+  typedef union { unsigned char b[8]; double d; } kjs_double_t;
+#if Q_BYTE_ORDER == Q_BIG_ENDIAN
+  static const kjs_double_t NaN_Bytes = { { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 } };
+#elif defined(arm)
+  static const kjs_double_t NaN_Bytes = { { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 } };
+#else
+  static const kjs_double_t NaN_Bytes = { { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f } };
+#endif
 
-  static const unsigned char be_nan_bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
-  static const unsigned char le_nan_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
-
-  return *( ( const double * )( BigEndian ? be_nan_bytes : le_nan_bytes ) );
+  const double NaN = NaN_Bytes.d;
+  return NaN;
 }
-#define NAN (nan__())
-#endif
+#define NAN __NAN()
+#endif /* !defined(NAN) */
 
 
+
 extern const char *GD_ERROR_CODES[15];
 
 #define GD_E_OK                0


More information about the Kst mailing list