valkey icon indicating copy to clipboard operation
valkey copied to clipboard

[BUG] 8.0.0 broken by including a non-existing header: `zmalloc.c: fatal error: threads.h: No such file or directory`

Open barracuda156 opened this issue 1 year ago • 5 comments

Describe the bug

/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_databases_valkey/valkey/work/compwrap/cc/opt/local/bin/gcc-mp-14 -pedantic -std=gnu11 -Wall -W -Wno-missing-field-initializers -Werror=deprecated-declarations -Wstrict-prototypes -O3 -flto=auto -fno-omit-frame-pointer -g -ggdb -arch ppc -isystem/opt/local/include/LegacySupport -isystem/opt/local/include -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram -I../deps/fpconv -DUSE_JEMALLOC -I../deps/jemalloc/include -DUSE_OPENSSL=1  -DBUILD_TLS_MODULE=0 -MMD -o zmalloc.o -c zmalloc.c
zmalloc.c:94:10: fatal error: threads.h: No such file or directory
   94 | #include <threads.h>
      |          ^~~~~~~~~~~
compilation terminated.
make[1]: *** [zmalloc.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_databases_valkey/valkey/work/valkey-8.0.0/src'
make: *** [all] Error 2

To reproduce

Run the build.

Expected behavior

It should build, as it did before.

Additional information

macOS 10.6, gcc 14.2.0

barracuda156 avatar Sep 19 '24 07:09 barracuda156

Breakage introduced by https://github.com/valkey-io/valkey/commit/3323e422ad0c0dc81859017798cb04a9621d6522

@lipzhu @guowangy Could someone please address this?

barracuda156 avatar Sep 19 '24 07:09 barracuda156

Maybe something like this using __has_include

#if !defined(__STDC_NO_THREADS__) && defined(__has_include)
# if __has_include(<threads.h>)
#  include <threads.h>
# endif
#endif

#ifndef thread_local
# define thread_local __thread
#endif

Alternatively, you could use _Thread_local instead of __thread, because a C11 compiler should support that. Including <threads.h> just gives you the thread_local macro that expands to _Thread_local, but you don't need <threads.h> to use _Thread_local.

The non-standard extension __thread will work with some pre-C11 compilers, if that's important.

jwakely avatar Sep 19 '24 09:09 jwakely

#define thread_local _Thread_local seems to work in my machine (mac M3)

enjoy-binbin avatar Sep 19 '24 09:09 enjoy-binbin

@jwakely do you think a #define thread_local _Thread_local is enough for this case? I tested it in some CI look like that all can pass the build, do you want to issue a fix?

enjoy-binbin avatar Sep 19 '24 10:09 enjoy-binbin

#define thread_local _Thread_local seems to work in my machine (mac M3)

This works for me on macOS.

barracuda156 avatar Sep 19 '24 11:09 barracuda156

@enjoy-binbin Thank you!

barracuda156 avatar Sep 23 '24 08:09 barracuda156