From: Radosław Korzeniewski Date: Thu, 4 Mar 2021 09:44:47 +0000 (+0100) Subject: Fix portability issue with typeof. X-Git-Tag: Release-11.3.2~682 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab638dfbdce8aee2cf0948d71393b304f12b96bd;p=thirdparty%2Fbacula.git Fix portability issue with typeof. 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. --- diff --git a/bacula/autoconf/config.h.in b/bacula/autoconf/config.h.in index 5b057b119..6a4876481 100644 --- a/bacula/autoconf/config.h.in +++ b/bacula/autoconf/config.h.in @@ -1064,6 +1064,9 @@ /* 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 diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index c8ce0f10a..1d8d60b7b 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -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 diff --git a/bacula/src/lib/serial.h b/bacula/src/lib/serial.h index 695d31e38..fb131888d 100644 --- a/bacula/src/lib/serial.h +++ b/bacula/src/lib/serial.h @@ -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 */