Sfoglia il codice sorgente

Simplify the warnining for unknown endianness; related to #752

Julius Pfrommer 8 anni fa
parent
commit
9883f078ef
2 ha cambiato i file con 32 aggiunte e 28 eliminazioni
  1. 13 28
      include/ua_config.h.in
  2. 19 0
      src/ua_types_encoding_binary.c

+ 13 - 28
include/ua_config.h.in

@@ -108,8 +108,15 @@ extern "C" {
 #endif
 
 /**
+ * Binary Encoding Overlays
+ * ------------------------
+ * Integers and floating point numbers are transmitted in little-endian (IEE 754
+ * for floating point) encoding. If the target architecture uses the same
+ * format, numeral datatypes can be memcpy'd (overlayed) on the binary stream.
+ * This speeds up encoding.
+ *
  * Integer Endianness
- * ------------------ */
+ * ^^^^^^^^^^^^^^^^^^ */
 #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
                         (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) /* little endian detected */
 # define UA_BINARY_OVERLAYABLE_INTEGER true
@@ -148,9 +155,13 @@ extern "C" {
 # endif
 #endif
 
+#ifndef UA_BINARY_OVERLAYABLE_INTEGER
+# define UA_BINARY_OVERLAYABLE_INTEGER false
+#endif
+
 /**
  * Float Endianness
- * ---------------- */
+ * ^^^^^^^^^^^^^^^^ */
 #if defined(_WIN32)
 # define UA_BINARY_OVERLAYABLE_FLOAT true
 #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
@@ -161,34 +172,8 @@ extern "C" {
 # define UA_BINARY_OVERLAYABLE_FLOAT true
 #endif
 
-/**
- * Binary Encoding Overlays
- * ------------------------
- * Some data types have the same layout in memory as on the binary data stream.
- * This can be used to speed up the decoding. If we could not detect
- * little-endianness of integers and floats, this is not possible for types that
- * contain integers or floats respectively. See the definition of the
- * overlayable flag defined in `UA_DataType`. */
-
-/* Demote error to a warning on clang. There is no robust way to detect float
- * endianness here. On x86/x86-64, floats are always in the right IEEE 754
- * format. So floats are overlayable is the architecture is little-endian. */
-#if defined(__clang__)
-# pragma GCC diagnostic push
-# pragma GCC diagnostic warning "-W#warnings"
-#endif
-
-#ifndef UA_BINARY_OVERLAYABLE_INTEGER
-# define UA_BINARY_OVERLAYABLE_INTEGER false
-# warning Slow Integer Encoding. This warning can be removed safely. It is only an indicator that integer endianness could not be detected.
-#endif
 #ifndef UA_BINARY_OVERLAYABLE_FLOAT
 # define UA_BINARY_OVERLAYABLE_FLOAT false
-# warning Slow Float Encoding. This warning can be removed safely. It is only an indicator that the float encoding could not be detected.
-#endif
-
-#if defined(__clang__)
-# pragma GCC diagnostic pop
 #endif
 
 /**

+ 19 - 0
src/ua_types_encoding_binary.c

@@ -3,6 +3,25 @@
 #include "ua_types_generated.h"
 #include "ua_types_generated_handling.h"
 
+/* There is no robust way to detect float endianness in clang. This warning can
+ * be removed if the target is known to be little endian with floats in the IEEE
+ * 754 format. */
+#if defined(__clang__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic warning "-W#warnings"
+#endif
+
+#ifndef UA_BINARY_OVERLAYABLE_INTEGER
+# warning Integer endianness could not be detected to be little endian. Use slow generic encoding.
+#endif
+#ifndef UA_BINARY_OVERLAYABLE_FLOAT
+# warning Float endianness could not be detected to be little endian in the IEEE 754 format. Use slow generic encoding.
+#endif
+
+#if defined(__clang__)
+# pragma GCC diagnostic pop
+#endif
+
 /* Jumptables for de-/encoding and computing the buffer length */
 typedef UA_StatusCode (*UA_encodeBinarySignature)(const void *UA_RESTRICT src, const UA_DataType *type);
 static const UA_encodeBinarySignature encodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1];