From 07129f8c4f314d4750e33f893921a24caf87680f Mon Sep 17 00:00:00 2001 From: Lightning11wins Date: Thu, 26 Mar 2026 10:00:14 -0600 Subject: [PATCH 1/2] Fix expect. Fix m4 macros not adding -DHAVE_BUILTIN_EXPECT to CFLAGS. Fix CHECK_BUILTIN_EXPECT being run too early, causing its CFLAGS to be clobbered by something. Fix typo in the module line of the expect.h copyright notice. Remake configure files. --- centrallix-lib/aclocal.m4 | 3 +- centrallix-lib/configure | 2 ++ centrallix-lib/include/expect.h | 2 +- centrallix/aclocal.m4 | 3 +- centrallix/configure | 62 +++++++++++++++++---------------- centrallix/configure.ac | 6 ++-- 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/centrallix-lib/aclocal.m4 b/centrallix-lib/aclocal.m4 index cd74b27b2..a1bb0b56d 100644 --- a/centrallix-lib/aclocal.m4 +++ b/centrallix-lib/aclocal.m4 @@ -45,9 +45,10 @@ AC_DEFUN(CHECK_BUILTIN_EXPECT, [AC_LANG_PROGRAM([], [__builtin_expect(0, 0)])], [ AC_DEFINE([HAVE_BUILTIN_EXPECT], [1], [Define if __builtin_expect is available]) + CFLAGS="$CFLAGS -DHAVE_BUILTIN_EXPECT" AC_MSG_RESULT([yes]) ], - [AC_MSG_RESULT([no])], + [AC_MSG_RESULT([no])] ) ] ) diff --git a/centrallix-lib/configure b/centrallix-lib/configure index 4995f514f..47752f3d6 100755 --- a/centrallix-lib/configure +++ b/centrallix-lib/configure @@ -4098,12 +4098,14 @@ if ac_fn_c_try_compile "$LINENO"; then : $as_echo "#define HAVE_BUILTIN_EXPECT 1" >>confdefs.h + CFLAGS="$CFLAGS -DHAVE_BUILTIN_EXPECT" { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } + fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext diff --git a/centrallix-lib/include/expect.h b/centrallix-lib/include/expect.h index 7f859213b..cc17614bc 100644 --- a/centrallix-lib/include/expect.h +++ b/centrallix-lib/include/expect.h @@ -11,7 +11,7 @@ /* GNU Lesser General Public License, Version 2.1, contained in the */ /* included file "COPYING". */ /* */ -/* Module: Expect Branch Optimization Module (mtask.c, mtask.h) */ +/* Module: Expect Branch Optimization Module (expect.h) */ /* Author: Israel Fuller */ /* Date: February 27th, 2026 */ /* */ diff --git a/centrallix/aclocal.m4 b/centrallix/aclocal.m4 index 3b8716131..0f0384693 100644 --- a/centrallix/aclocal.m4 +++ b/centrallix/aclocal.m4 @@ -1181,9 +1181,10 @@ AC_DEFUN(CHECK_BUILTIN_EXPECT, [AC_LANG_PROGRAM([], [__builtin_expect(0, 0)])], [ AC_DEFINE([HAVE_BUILTIN_EXPECT], [1], [Define if __builtin_expect is available]) + CFLAGS="$CFLAGS -DHAVE_BUILTIN_EXPECT" AC_MSG_RESULT([yes]) ], - [AC_MSG_RESULT([no])], + [AC_MSG_RESULT([no])] ) ] ) diff --git a/centrallix/configure b/centrallix/configure index adf0045a8..2fb42c49c 100755 --- a/centrallix/configure +++ b/centrallix/configure @@ -5807,36 +5807,6 @@ $as_echo "#define HAVE_NCURSES 1" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if __builtin_expect is available" >&5 -$as_echo_n "checking if __builtin_expect is available... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -__builtin_expect(0, 0) - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - -$as_echo "#define HAVE_BUILTIN_EXPECT 1" >>confdefs.h - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - - - has_ctype_b="test" { $as_echo "$as_me:${as_lineno-$LINENO}: checking if __ctype_b is present and usable" >&5 @@ -7501,6 +7471,38 @@ $as_echo "$logmethod" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if __builtin_expect is available" >&5 +$as_echo_n "checking if __builtin_expect is available... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +__builtin_expect(0, 0) + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + +$as_echo "#define HAVE_BUILTIN_EXPECT 1" >>confdefs.h + + CFLAGS="$CFLAGS -DHAVE_BUILTIN_EXPECT" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + if test "$WITH_DYNAMIC_LOAD" = "yes"; then $as_echo "#define WITH_DYNAMIC_LOAD 1" >>confdefs.h diff --git a/centrallix/configure.ac b/centrallix/configure.ac index c96525983..416658794 100644 --- a/centrallix/configure.ac +++ b/centrallix/configure.ac @@ -92,9 +92,6 @@ CENTRALLIX_CHECK_SQLITE dnl Check for ncurses CENTRALLIX_CHECK_NCURSES -dnl Check for __builtin_expect() -CHECK_BUILTIN_EXPECT - dnl Check for __ctype_b AH_TEMPLATE([HAVE_CTYPE_B], [Whether __ctype_b is present and usable]) CHECK_CTYPE_B @@ -189,6 +186,9 @@ CHECK_OPTIMIZE dnl Check for log method CHECK_LOGMETHOD +dnl Check for __builtin_expect() +CHECK_BUILTIN_EXPECT + dnl Define WITH_DYNAMIC_LOAD in config.h if test "$WITH_DYNAMIC_LOAD" = "yes"; then AC_DEFINE(WITH_DYNAMIC_LOAD,1,[Use dynamic loading]) From 44df6fc40e57abe8cafe75adea70f51607062800 Mon Sep 17 00:00:00 2001 From: Lightning11wins Date: Thu, 26 Mar 2026 16:10:17 -0600 Subject: [PATCH 2/2] Fix the fix because the previous fix was badly designed. Add HAVE_BUILTIN_EXPECT to config.h.in and cxlibconfig.h.in. Add code to include cxlibconfig.h.in from expect.h. Add comments to explain what each .h.in file is used for. Remove checks for __builtin_expect() from centrallix because we only need them in centrallix-lib. Remove cflags -DHAVE_BUILTIN_EXPECT because using configs is better. Rebuild configure files. --- centrallix-lib/aclocal.m4 | 1 - centrallix-lib/configure | 1 - .../include/cxlibconfig-internal.h.in | 6 +++- centrallix-lib/include/cxlibconfig.h.in | 9 ++++++ centrallix-lib/include/expect.h | 25 +++++++++------ centrallix/aclocal.m4 | 16 ---------- centrallix/config.h.in | 3 -- centrallix/configure | 32 ------------------- centrallix/configure.ac | 3 -- 9 files changed, 30 insertions(+), 66 deletions(-) diff --git a/centrallix-lib/aclocal.m4 b/centrallix-lib/aclocal.m4 index a1bb0b56d..279b7291d 100644 --- a/centrallix-lib/aclocal.m4 +++ b/centrallix-lib/aclocal.m4 @@ -45,7 +45,6 @@ AC_DEFUN(CHECK_BUILTIN_EXPECT, [AC_LANG_PROGRAM([], [__builtin_expect(0, 0)])], [ AC_DEFINE([HAVE_BUILTIN_EXPECT], [1], [Define if __builtin_expect is available]) - CFLAGS="$CFLAGS -DHAVE_BUILTIN_EXPECT" AC_MSG_RESULT([yes]) ], [AC_MSG_RESULT([no])] diff --git a/centrallix-lib/configure b/centrallix-lib/configure index 47752f3d6..c8c03668c 100755 --- a/centrallix-lib/configure +++ b/centrallix-lib/configure @@ -4098,7 +4098,6 @@ if ac_fn_c_try_compile "$LINENO"; then : $as_echo "#define HAVE_BUILTIN_EXPECT 1" >>confdefs.h - CFLAGS="$CFLAGS -DHAVE_BUILTIN_EXPECT" { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } diff --git a/centrallix-lib/include/cxlibconfig-internal.h.in b/centrallix-lib/include/cxlibconfig-internal.h.in index 6649e4478..7074db4ee 100644 --- a/centrallix-lib/include/cxlibconfig-internal.h.in +++ b/centrallix-lib/include/cxlibconfig-internal.h.in @@ -1,5 +1,10 @@ /* include/cxlibconfig-internal.h.in. Generated from configure.ac by autoheader. */ +/*** cxlibconfig-internal.h.in lists defines that are used by centrallix-lib + *** internally and will not be needed in other modules. For external + *** usecases, see cxlibconfig.h.in. + ***/ + /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT @@ -34,4 +39,3 @@ /* defined to 1 if SIOCOUTQ is available */ #undef HAVE_SIOCOUTQ - diff --git a/centrallix-lib/include/cxlibconfig.h.in b/centrallix-lib/include/cxlibconfig.h.in index dc6b3ad29..d1fc408fa 100644 --- a/centrallix-lib/include/cxlibconfig.h.in +++ b/centrallix-lib/include/cxlibconfig.h.in @@ -1,5 +1,11 @@ /* include/cxlibconfig.h.in. Generated from configure.ac by autoheader. */ +/*** cxlibconfig-h.in lists defines that should be availabe to anyone + *** using centrallix-lib. For example, a define used in an external .h + *** file should be written here so that the .h file can include it even + *** if it is used in another project. + ***/ + /* Define to 1 if you have the `endservent' function. */ #undef HAVE_ENDSERVENT @@ -33,6 +39,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H +/* Define to 1 if you have the `__builtin_expect' function. */ +#undef HAVE_BUILTIN_EXPECT + /* Define to 1 if you have the `strdup' function. */ #undef HAVE_STRDUP diff --git a/centrallix-lib/include/expect.h b/centrallix-lib/include/expect.h index cc17614bc..03db37ab3 100644 --- a/centrallix-lib/include/expect.h +++ b/centrallix-lib/include/expect.h @@ -23,19 +23,26 @@ /* true, UNLIKELY() indicates it is likely to be false. */ /************************************************************************/ +#ifdef HAVE_CONFIG_H + #ifdef CXLIB_INTERNAL + #include "cxlibconfig.h" + #else + #include "cxlib/cxlibconfig.h" + #endif +#endif /** Define macros for signalling the more likely branch to the compiler. **/ #ifdef HAVE_BUILTIN_EXPECT -/** Use the GCC __builtin_expect() function for optimization. **/ -/** Note: We use !!(x) which normalizes to 0 or 1 to help the compiler. **/ -#define LIKELY(x) (__builtin_expect(!!(x), 1)) -#define UNLIKELY(x) (__builtin_expect(!!(x), 0)) + /** Use the GCC __builtin_expect() function for optimization. **/ + /** Note: We use !!(x) which normalizes to 0 or 1 to help the compiler. **/ + #define LIKELY(x) (__builtin_expect(!!(x), 1)) + #define UNLIKELY(x) (__builtin_expect(!!(x), 0)) #else -/*** Fallback: Define pass through functions to support compilers that don't - *** have this feature. - ***/ -#define LIKELY(x) (x) -#define UNLIKELY(x) (x) + /*** Fallback: Define pass through functions to support compilers that don't + *** have this feature. + ***/ + #define LIKELY(x) (x) + #define UNLIKELY(x) (x) #endif #endif diff --git a/centrallix/aclocal.m4 b/centrallix/aclocal.m4 index 0f0384693..9f0905c91 100644 --- a/centrallix/aclocal.m4 +++ b/centrallix/aclocal.m4 @@ -1173,22 +1173,6 @@ AC_DEFUN(CHECK_COVERAGE, ] ) -dnl check if gcc allows __builtin_expect() -AC_DEFUN(CHECK_BUILTIN_EXPECT, - [ - AC_MSG_CHECKING(if __builtin_expect is available) - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([], [__builtin_expect(0, 0)])], - [ - AC_DEFINE([HAVE_BUILTIN_EXPECT], [1], [Define if __builtin_expect is available]) - CFLAGS="$CFLAGS -DHAVE_BUILTIN_EXPECT" - AC_MSG_RESULT([yes]) - ], - [AC_MSG_RESULT([no])] - ) - ] -) - dnl check if gcc allows -fPIC and -pg at the same time AC_DEFUN(CHECK_PROFILE, [ diff --git a/centrallix/config.h.in b/centrallix/config.h.in index a40a4e6a0..8abbefb32 100644 --- a/centrallix/config.h.in +++ b/centrallix/config.h.in @@ -12,9 +12,6 @@ /* Define to 1 if you have the `basename' function. */ #undef HAVE_BASENAME -/* Define if __builtin_expect is available */ -#undef HAVE_BUILTIN_EXPECT - /* Whether __ctype_b is present and usable */ #undef HAVE_CTYPE_B diff --git a/centrallix/configure b/centrallix/configure index 2fb42c49c..d8c30ba8f 100755 --- a/centrallix/configure +++ b/centrallix/configure @@ -7471,38 +7471,6 @@ $as_echo "$logmethod" >&6; } - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if __builtin_expect is available" >&5 -$as_echo_n "checking if __builtin_expect is available... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -__builtin_expect(0, 0) - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - -$as_echo "#define HAVE_BUILTIN_EXPECT 1" >>confdefs.h - - CFLAGS="$CFLAGS -DHAVE_BUILTIN_EXPECT" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - - if test "$WITH_DYNAMIC_LOAD" = "yes"; then $as_echo "#define WITH_DYNAMIC_LOAD 1" >>confdefs.h diff --git a/centrallix/configure.ac b/centrallix/configure.ac index 416658794..fe58222e3 100644 --- a/centrallix/configure.ac +++ b/centrallix/configure.ac @@ -186,9 +186,6 @@ CHECK_OPTIMIZE dnl Check for log method CHECK_LOGMETHOD -dnl Check for __builtin_expect() -CHECK_BUILTIN_EXPECT - dnl Define WITH_DYNAMIC_LOAD in config.h if test "$WITH_DYNAMIC_LOAD" = "yes"; then AC_DEFINE(WITH_DYNAMIC_LOAD,1,[Use dynamic loading])