Browse Source

lib: IEC559 tests are fragile, reduce to warning rather than error.

* {network,stream}.c: Weaken the compile time tests for IEEE754 / IEC-559
  binary floating point format from an error to a warning when not detected.

  I can't think of any platforms that are not IEEE-754 format, and as the
  testing for the defines appears to be fragile (often not set) the error
  just gives false positives.

  Even the warnings may be too much.  Those should probably be moved
  to some configure test.  Will do for now though, to fix compilation
  on CentOS and some BSDs.
Paul Jakma 3 years ago
parent
commit
a3b161bb72
2 changed files with 18 additions and 22 deletions
  1. 3 4
      lib/network.c
  2. 15 18
      lib/stream.c

+ 3 - 4
lib/network.c

@@ -97,7 +97,9 @@ set_nonblocking(int fd)
 float
 htonf (float host)
 {
-#ifdef __STDC_IEC_559__
+#if !defined(__STDC_IEC_559__) && __GCC_IEC_559 < 0
+#warning "Unknown floating-point format on platform, htonf may break"
+#endif
   u_int32_t lu1, lu2;
   float convert;
   
@@ -105,9 +107,6 @@ htonf (float host)
   lu2 = htonl (lu1);
   memcpy (&convert, &lu2, sizeof (u_int32_t));
   return convert;
-#else
-#error "Please supply htonf implementation for this platform"
-#endif 
 }
 
 float

+ 15 - 18
lib/stream.c

@@ -498,33 +498,31 @@ stream_get_ipv4 (struct stream *s)
 float
 stream_getf (struct stream *s)
 {
-#if defined(__STDC_IEC_559__) || __GCC_IEC_559 >= 1
-/* we can safely assume 'float' is in the single precision
-   IEC 60559 binary format in host order */
+#if !defined(__STDC_IEC_559__) && __GCC_IEC_559 < 1
+#warning "Unknown floating-point format, __func__ may be wrong"
+#endif
+/* we assume 'float' is in the single precision IEC 60559 binary
+   format, in host byte order */
   union {
     float r;
     uint32_t d;
   } u;
   u.d = stream_getl (s);
   return u.r;
-#else
-#error "Please supply stream_getf implementation for this platform"
-#endif
 }
 
 double
 stream_getd (struct stream *s)
 {
-#if defined(__STDC_IEC_559__) || __GCC_IEC_559 >= 1
+#if !defined(__STDC_IEC_559__) && __GCC_IEC_559 < 1
+#warning "Unknown floating-point format, __func__ may be wrong"
+#endif
   union {
     double r;
     uint64_t d;
   } u;
   u.d = stream_getq (s);
   return u.r;
-#else
-#error "Please supply stream_getd implementation for this platform"
-#endif
 }
 
 /* Copy to source to stream.
@@ -638,7 +636,10 @@ stream_putq (struct stream *s, uint64_t q)
 int
 stream_putf (struct stream *s, float f)
 {
-#if defined(__STDC_IEC_559__) || __GCC_IEC_559 >= 1
+#if !defined(__STDC_IEC_559__) && __GCC_IEC_559 < 1
+#warning "Unknown floating-point format, __func__ may be wrong"
+#endif
+
 /* we can safely assume 'float' is in the single precision
    IEC 60559 binary format in host order */
   union {
@@ -647,24 +648,20 @@ stream_putf (struct stream *s, float f)
   } u;
   u.i = f;
   return stream_putl (s, u.o);
-#else
-#error "Please supply stream_putf implementation for this platform"
-#endif
 }
 
 int
 stream_putd (struct stream *s, double d)
 {
-#if defined(__STDC_IEC_559__) || __GCC_IEC_559 >= 1
+#if !defined(__STDC_IEC_559__) && __GCC_IEC_559 < 1
+#warning "Unknown floating-point format, __func__ may be wrong"
+#endif
   union {
     double i;
     uint64_t o;
   } u;
   u.i = d;
   return stream_putq (s, u.o);
-#else
-#error "Please supply stream_putd implementation for this platform"
-#endif
 }
 
 int