From 9a57d1af1ab641800a5b9cd25ed54bb44a4f87d0 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Fri, 19 Jun 2026 20:24:19 +0200 Subject: [PATCH 1/3] Autotools: Fix out-of-source builds and epoll_pwait2 check (#22334) * Added main/poll to build directories to enable out-of-source builds. * AC_CHECK_FUNCS() Autoconf macro doesn't accept 4th argument (it's a link check). Instead, added a AC_CHECK_DECL() fallback check if epoll_pwait2 is defined as a macro (as in glibc at the time of writing in certain scenarios). --- build/php.m4 | 6 +++++- configure.ac | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/build/php.m4 b/build/php.m4 index 74c069f5887b..83375bec5aa2 100644 --- a/build/php.m4 +++ b/build/php.m4 @@ -1396,7 +1396,11 @@ AC_DEFUN([PHP_POLL_MECHANISMS], AC_DEFINE([HAVE_EPOLL], [1], [Define if epoll is available]) poll_mechanisms="$poll_mechanisms epoll" - AC_CHECK_FUNCS([epoll_pwait2], [], [], [#include ]) + AC_CHECK_FUNCS([epoll_pwait2], [], + [AC_CHECK_DECL([epoll_pwait2], + [AC_DEFINE([HAVE_EPOLL_PWAIT2], [1])], + [], + [#include ])]) ]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ diff --git a/configure.ac b/configure.ac index 63c00f508c1c..b61b909b67b7 100644 --- a/configure.ac +++ b/configure.ac @@ -1817,6 +1817,7 @@ AC_DEFINE([HAVE_BUILD_DEFS_H], [1], PHP_ADD_BUILD_DIR([ main + main/poll main/streams scripts scripts/man1 From e246a0dfcb28e06bcc3d4a8f8ba9f669c349179b Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 19 Jun 2026 20:56:13 +0200 Subject: [PATCH 2/3] Remove unneeded casts of php_poll_handle_object.handle_data handle_data is void*, which auto-coerces to any pointer type in C. --- ext/standard/io_poll.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/standard/io_poll.c b/ext/standard/io_poll.c index c36306a0b49b..93e9a51c5fb2 100644 --- a/ext/standard/io_poll.c +++ b/ext/standard/io_poll.c @@ -222,7 +222,7 @@ static const char *php_io_poll_backend_type_to_name(php_poll_backend_type type) static php_socket_t php_stream_poll_handle_get_fd(php_poll_handle_object *handle) { - php_stream_poll_handle_data *data = (php_stream_poll_handle_data *) handle->handle_data; + php_stream_poll_handle_data *data = handle->handle_data; php_socket_t fd; if (!data || !data->stream) { @@ -241,13 +241,13 @@ static php_socket_t php_stream_poll_handle_get_fd(php_poll_handle_object *handle static int php_stream_poll_handle_is_valid(php_poll_handle_object *handle) { - php_stream_poll_handle_data *data = (php_stream_poll_handle_data *) handle->handle_data; + php_stream_poll_handle_data *data = handle->handle_data; return data && data->stream && !php_stream_eof(data->stream); } static void php_stream_poll_handle_cleanup(php_poll_handle_object *handle) { - php_stream_poll_handle_data *data = (php_stream_poll_handle_data *) handle->handle_data; + php_stream_poll_handle_data *data = handle->handle_data; if (data) { if (data->res) { zend_list_delete(data->res); @@ -508,7 +508,7 @@ PHP_METHOD(StreamPollHandle, getStream) ZEND_PARSE_PARAMETERS_NONE(); php_poll_handle_object *intern = PHP_POLL_HANDLE_OBJ_FROM_ZV(getThis()); - php_stream_poll_handle_data *data = (php_stream_poll_handle_data *) intern->handle_data; + php_stream_poll_handle_data *data = intern->handle_data; if (!data || !data->stream) { RETURN_NULL(); From 4d559cad690cce7a6bfd1929b66ddc74b95b9997 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 19 Jun 2026 20:59:45 +0200 Subject: [PATCH 3/3] [skip ci] Use safe_emalloc() for php_poll_event allocation --- ext/standard/io_poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/io_poll.c b/ext/standard/io_poll.c index 93e9a51c5fb2..e8366c7e8802 100644 --- a/ext/standard/io_poll.c +++ b/ext/standard/io_poll.c @@ -851,7 +851,7 @@ PHP_METHOD(Io_Poll_Context, wait) RETURN_THROWS(); } - php_poll_event *events = emalloc(sizeof(php_poll_event) * max_events); + php_poll_event *events = safe_emalloc(max_events, sizeof(*events), 0); int num_events = php_poll_wait(intern->ctx, events, (int) max_events, timeout); if (num_events < 0) {