Skip to content

Commit 713bf66

Browse files
committed
Merge bitcoin/bitcoin#31500: depends: Fix compiling libevent package on NetBSD
f89f168 depends: Fix compiling `libevent` package on NetBSD (Hennadii Stepanov) Pull request description: Libevent [introduced](libevent/libevent#909) the [`typeof`](https://gcc.gnu.org/onlinedocs/gcc/Typeof.html) C language extension in the NetBSD-specific code, which was pulled into our depends in bitcoin/bitcoin#21991. However, GCC [states](https://gcc.gnu.org/onlinedocs/gcc/Alternate-Keywords.html): > the various `-std` options disable certain keywords. Due to our use of https://github.com/bitcoin/bitcoin/blob/b042c4f0538c6f9cdf8efbcef552796851e38a85/depends/hosts/netbsd.mk#L1 the `typeof` keyword is disabled, resulting in a compilation error: ``` $ gmake -C depends libevent CC=/usr/pkg/gcc14/bin/gcc CXX=/usr/pkg/gcc14/bin/g++ <snip> [ 37%] Building C object CMakeFiles/event_core_static.dir/kqueue.c.o /home/hebasto/dev/bitcoin/depends/work/build/x86_64-unknown-netbsd10.0/libevent/2.1.12-stable-ca6b96ec97c/kqueue.c: In function 'kq_setup_kevent': /home/hebasto/dev/bitcoin/depends/work/build/x86_64-unknown-netbsd10.0/libevent/2.1.12-stable-ca6b96ec97c/kqueue.c:56:27: error: implicit declaration of function 'typeof' [-Wimplicit-function-declaration] 56 | #define INT_TO_UDATA(x) ((typeof(((struct kevent *)0)->udata))(intptr_t)(x)) | ^~~~~~ /home/hebasto/dev/bitcoin/depends/work/build/x86_64-unknown-netbsd10.0/libevent/2.1.12-stable-ca6b96ec97c/kqueue.c:190:30: note: in expansion of macro 'INT_TO_UDATA' 190 | out->udata = INT_TO_UDATA(ADD_UDATA); | ^~~~~~~~~~~~ /home/hebasto/dev/bitcoin/depends/work/build/x86_64-unknown-netbsd10.0/libevent/2.1.12-stable-ca6b96ec97c/kqueue.c:56:64: error: expected expression before 'intptr_t' 56 | #define INT_TO_UDATA(x) ((typeof(((struct kevent *)0)->udata))(intptr_t)(x)) | ^~~~~~~~ /home/hebasto/dev/bitcoin/depends/work/build/x86_64-unknown-netbsd10.0/libevent/2.1.12-stable-ca6b96ec97c/kqueue.c:190:30: note: in expansion of macro 'INT_TO_UDATA' 190 | out->udata = INT_TO_UDATA(ADD_UDATA); | ^~~~~~~~~~~~ /home/hebasto/dev/bitcoin/depends/work/build/x86_64-unknown-netbsd10.0/libevent/2.1.12-stable-ca6b96ec97c/kqueue.c:56:27: error: called object is not a function or function pointer 56 | #define INT_TO_UDATA(x) ((typeof(((struct kevent *)0)->udata))(intptr_t)(x)) | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/hebasto/dev/bitcoin/depends/work/build/x86_64-unknown-netbsd10.0/libevent/2.1.12-stable-ca6b96ec97c/kqueue.c:190:30: note: in expansion of macro 'INT_TO_UDATA' 190 | out->udata = INT_TO_UDATA(ADD_UDATA); | ^~~~~~~~~~~~ gmake[3]: *** [CMakeFiles/event_core_static.dir/build.make:328: CMakeFiles/event_core_static.dir/kqueue.c.o] Error 1 <snip> ``` This PR resolves this issue by following GCC's [recommendation](https://gcc.gnu.org/onlinedocs/gcc/Typeof.html): > write `__typeof__` instead of `typeof`. ACKs for top commit: fanquake: ACK f89f168 Tree-SHA512: c0d2e535408db120535781f8518c616b0f5a39b1c6babb2a74e8e0565348aaf00b0f5a93cac0af7cf6d6bf028d5d58763fe71b3969ed9c7059fa7c3dca9d084c
2 parents ede388d + f89f168 commit 713bf66

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

depends/packages/libevent.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $(package)_download_path=https://github.com/libevent/libevent/releases/download/
44
$(package)_file_name=$(package)-$($(package)_version).tar.gz
55
$(package)_sha256_hash=92e6de1be9ec176428fd2367677e61ceffc2ee1cb119035037a27d346b0403bb
66
$(package)_patches=cmake_fixups.patch
7+
$(package)_patches += netbsd_fixup.patch
78
$(package)_build_subdir=build
89

910
# When building for Windows, we set _WIN32_WINNT to target the same Windows
@@ -23,7 +24,8 @@ define $(package)_set_vars
2324
endef
2425

2526
define $(package)_preprocess_cmds
26-
patch -p1 < $($(package)_patch_dir)/cmake_fixups.patch
27+
patch -p1 < $($(package)_patch_dir)/cmake_fixups.patch && \
28+
patch -p1 < $($(package)_patch_dir)/netbsd_fixup.patch
2729
endef
2830

2931
define $(package)_config_cmds
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Improve portability on NetBSD
2+
3+
According to GCC documentation, "the various `-std` options disable
4+
certain keywords".
5+
This change adheres to GCC's recommendation by replacing the `typeof`
6+
keyword with its alternative, `__typeof__`.
7+
8+
See https://github.com/libevent/libevent/commit/1759485e9a59147a47a674f5132fcfe764e7748c.
9+
10+
11+
--- a/kqueue.c
12+
+++ b/kqueue.c
13+
@@ -52,8 +52,8 @@
14+
* intptr_t, whereas others define it as void*. There doesn't seem to be an
15+
* easy way to tell them apart via autoconf, so we need to use OS macros. */
16+
#if defined(__NetBSD__)
17+
-#define PTR_TO_UDATA(x) ((typeof(((struct kevent *)0)->udata))(x))
18+
-#define INT_TO_UDATA(x) ((typeof(((struct kevent *)0)->udata))(intptr_t)(x))
19+
+#define PTR_TO_UDATA(x) ((__typeof__(((struct kevent *)0)->udata))(x))
20+
+#define INT_TO_UDATA(x) ((__typeof__(((struct kevent *)0)->udata))(intptr_t)(x))
21+
#elif defined(EVENT__HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__) && !defined(__CloudABI__)
22+
#define PTR_TO_UDATA(x) ((intptr_t)(x))
23+
#define INT_TO_UDATA(x) ((intptr_t)(x))

0 commit comments

Comments
 (0)