]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix portability issue with typeof.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Thu, 4 Mar 2021 09:44:47 +0000 (10:44 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:00 +0000 (09:03 +0100)
This patch adds a new configuration detection code for __typeof() and
introduce new macro TYPEOF_FUNC which should be used together
with HAVE_TYPEOF macro where this function is required.
It fixes  #0002600 when building Bacula on Solaris 11 and SDS.

bacula/autoconf/config.h.in
bacula/autoconf/configure.in
bacula/src/lib/serial.h

index 5b057b119701c08a65c7b3f01df6e13ee36a6b90..6a48764813b787d9dcb785afaa06e2e26fd0b963 100644 (file)
 /* Defind to 1 if compiler has typeof */
 #undef HAVE_TYPEOF
 
+/* Define to nonstandard `typeof` supported by compiler */
+#undef TYPEOF_FUNC
+
 /* Define to 1 if you don't have `tm_zone' but do have the external array
    `tzname'. */
 #undef HAVE_TZNAME
index c8ce0f10a6d588c6cdef2a006d29ec8f65ceafe5..1d8d60b7b746fbeb74cd8a715b30ce6312a4dfc2 100644 (file)
@@ -1891,20 +1891,44 @@ dnl --------------------------------------------------------------------------
 AC_LANG_PUSH(C++)
 AC_CACHE_CHECK(for typeof, ba_cv_have_typeof,
    [
-       AC_TRY_RUN(
-         [
-             main(){char *a = 0; a = (typeof a)a;}
-         ], [
-             ba_cv_have_typeof=yes
-         ], [
-             ba_cv_have_typeof=no
-         ], [
-             ba_cv_have_typeof=no
-         ]
-       )
+      AC_TRY_RUN(
+         [
+            main(){char *a = 0; a = (typeof a)a;}
+         ], [
+            ba_cv_have_typeof=yes
+         ], [
+            ba_cv_have_typeof=no
+         ], [
+            ba_cv_have_typeof=no
+         ]
+      )
    ]
 )
-test $ba_cv_have_typeof = yes && AC_DEFINE([HAVE_TYPEOF], 1, [Defind to 1 if compiler has typeof])
+if test $ba_cv_have_typeof = yes; then
+   AC_DEFINE([HAVE_TYPEOF], 1, [Defind to 1 if compiler has typeof])
+   AC_DEFINE([TYPEOF_FUNC], typeof, [Define to nonstandard `typeof` supported by compiler])
+else
+AC_CACHE_CHECK(for __typeof, ba_cv_have_utypeof,
+   [
+      AC_TRY_RUN(
+         [
+            main(){char *a = 0; a = (__typeof a)a;}
+         ], [
+            ba_cv_have_utypeof=yes
+         ], [
+            ba_cv_have_utypeof=no
+         ], [
+            ba_cv_have_utypeof=no
+         ]
+      )
+   ]
+)
+if test $ba_cv_have_utypeof = yes; then
+   AC_DEFINE([HAVE_TYPEOF], 1, [Defind to 1 if compiler has typeof])
+   AC_DEFINE([TYPEOF_FUNC], __typeof, [Define to nonstandard `typeof` supported by compiler])
+fi
+fi
+
 AC_LANG_POP(C++)
 
 AC_C_CONST
index 695d31e38c2c59a3a21681c5fa5abf36671fdd26..fb131888d73b3cd3ad960d779bcf3df2caf16f8d 100644 (file)
@@ -79,8 +79,25 @@ extern void unserial_string(uint8_t * * const ptr, char * const str, int max);
 #define unser_check(x, s) ASSERT(unser_length(x) == ((uint32_t)(s)))
 
 /*  ser_assign(ptr, len) -- assign current position to ptr and go len bytes forward  */
-#define ser_assign(ptr, len) { ptr = (typeof(ptr))ser_ptr; ser_ptr += (len); }
-#define unser_assign(ptr, len) { ptr = (typeof(ptr))ser_ptr; ser_ptr += (len); }
+#ifdef HAVE_TYPEOF
+#define ser_assign(ptr, len) { ptr = (TYPEOF_FUNC(ptr))ser_ptr; ser_ptr += (len); }
+#define unser_assign(ptr, len) { ptr = (TYPEOF_FUNC(ptr))ser_ptr; ser_ptr += (len); }
+#else
+#define ser_assign(ptr, len)            \
+   {                                    \
+      void **_p1 = (void **)(&ser_ptr); \
+      void **_p2 = (void **)(&ptr);     \
+      *_p2 = *_p1;                      \
+      ser_ptr += (len);                 \
+   }
+#define unser_assign(ptr, len)          \
+   {                                    \
+      void **_p1 = (void **)(&ser_ptr); \
+      void **_p2 = (void **)(&ptr);     \
+      *_p2 = *_p1;                      \
+      ser_ptr += (len);                 \
+   }
+#endif
 
 /*                          Serialisation                   */