Skip to content

Commit e57f408

Browse files
committed
Refactor alloca check
Autoconf provides dedicated AC_FUNC_ALLOCA macro. This is for now the best effort to make it simple yet effective and have it synced with current PHP usage of alloca().
1 parent 31265a6 commit e57f408

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

cmake/cmake/ConfigureChecks.cmake

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ endif()
4343
# Check headers.
4444
################################################################################
4545

46-
check_include_files(alloca.h HAVE_ALLOCA_H)
4746
check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
4847
check_include_files(sys/types.h HAVE_SYS_TYPES_H)
4948

@@ -408,21 +407,17 @@ else()
408407
endif()
409408

410409
################################################################################
411-
# Miscellaneous checks.
410+
# Run all checks from cmake/checks.
412411
################################################################################
413412

414-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckAVX512.cmake)
415-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckCopyFileRange.cmake)
416-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckFlushIo.cmake)
417-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckFnmatch.cmake)
418-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckFopencookie.cmake)
419-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckGetaddrinfo.cmake)
420-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckGethostbynameR.cmake)
421-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckGetifaddrs.cmake)
422-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckInline.cmake)
423-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckIPv6.cmake)
424-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckReentrantFunctions.cmake)
425-
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckWrite.cmake)
413+
file(GLOB checks ${CMAKE_CURRENT_LIST_DIR}/checks/Check*.cmake)
414+
foreach(check IN LISTS checks)
415+
include(${check})
416+
endforeach()
417+
418+
################################################################################
419+
# Miscellaneous checks.
420+
################################################################################
426421

427422
# Checking file descriptor sets.
428423
message(CHECK_START "Checking file descriptor sets size")
@@ -443,16 +438,6 @@ else()
443438
message(CHECK_PASS "using system default")
444439
endif()
445440

446-
if(HAVE_ALLOCA_H)
447-
# Most *.nix systems.
448-
check_symbol_exists(alloca alloca.h HAVE_ALLOCA)
449-
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
450-
check_symbol_exists(alloca malloc.h HAVE_ALLOCA)
451-
else()
452-
# BSD-based systems.
453-
check_symbol_exists(alloca stdlib.h HAVE_ALLOCA)
454-
endif()
455-
456441
message(CHECK_START "Checking whether the compiler supports __alignof__")
457442
cmake_push_check_state(RESET)
458443
set(CMAKE_REQUIRED_QUIET TRUE)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#[=============================================================================[
2+
This check determines whether the system supports alloca() and follows the
3+
behavior of Autoconf's AC_FUNC_ALLOCA macro, with some adjustments for obsolete
4+
systems:
5+
6+
* Autoconf also checks whether <alloca.h> works on certain obsolete systems.
7+
* Autoconf provides variable substitution to integrate a custom alloca.c
8+
implementation if alloca() is not available on the system. However, PHP
9+
doesn't use this feature.
10+
11+
Result variables:
12+
13+
* HAVE_ALLOCA
14+
* HAVE_ALLOCA_H
15+
#]=============================================================================]
16+
17+
include(CheckIncludeFiles)
18+
include(CheckSymbolExists)
19+
20+
# On Windows, alloca is defined in malloc.h as _alloca. Cache variables are
21+
# overridden to speed up the check and commands used for documentation purposes.
22+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
23+
set(PHP_HAS_ALLOCA_H FALSE)
24+
set(PHP_HAS_ALLOCA TRUE)
25+
check_symbol_exists(alloca malloc.h PHP_HAS_ALLOCA)
26+
else()
27+
check_include_files(alloca.h PHP_HAS_ALLOCA_H)
28+
29+
if(PHP_HAS_ALLOCA_H)
30+
# Most *.nix systems (Linux, macOS, Solaris/illumos, Haiku).
31+
check_symbol_exists(alloca alloca.h PHP_HAS_ALLOCA)
32+
else()
33+
# BSD-based systems, old Linux.
34+
check_symbol_exists(alloca stdlib.h PHP_HAS_ALLOCA)
35+
endif()
36+
endif()
37+
38+
set(HAVE_ALLOCA ${PHP_HAS_ALLOCA})
39+
set(HAVE_ALLOCA_H ${PHP_HAS_ALLOCA_H})

cmake/cmake/platforms/Windows.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
5555
##############################################################################
5656

5757
set(HAVE_ALIGNOF FALSE)
58-
set(HAVE_ALLOCA TRUE)
59-
set(HAVE_ALLOCA_H FALSE)
6058
set(HAVE_ALPHASORT FALSE)
6159
set(HAVE_ARPA_INET_H FALSE)
6260
set(HAVE_ARPA_NAMESER_H FALSE)

0 commit comments

Comments
 (0)