Skip to content

Commit 721b0f1

Browse files
committed
Refactor checks
This is a recheck of these issues on current systems. - Refactored checks for pread(), pwrite() and ttyname_r(). - Cache variable naming conventions synced - Missing pread() and pwrite() declarations checks refactored with using only compilation checks. - Refactored SAPIs checks.
1 parent d3d71bd commit 721b0f1

13 files changed

+806
-638
lines changed

cmake/cmake/toolchains/template.cmake

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ set(ZEND_MM_EXITCODE__TRYRUN_OUTPUT "(size_t)8 (size_t)3 0")
5555
################################################################################
5656

5757
# Set the exit code for the clock_get_time() check.
58-
set(HAVE_CLOCK_GET_TIME_EXITCODE 0)
58+
set(PHP_SAPI_FPM_HAS_CLOCK_GET_TIME_EXITCODE 0)
5959

60-
# Set the exit code of the ptrace check for PHP FPM.
61-
set(HAVE_PTRACE_EXITCODE 0)
60+
# Set the exit code of the ptrace() check.
61+
set(PHP_SAPI_FPM_HAS_PTRACE_EXITCODE 0)
6262

6363
# Set the process memory access file - 'mem' on Linux-alike or 'as' on
6464
# Solaris-alike target systems for the PHP FPM to use pread trace type.
@@ -118,24 +118,13 @@ set(PHP_EXT_OPCACHE_HAS_SHM_MMAP_POSIX_EXITCODE 0)
118118
# support is available for the target architecture.
119119
set(PHP_EXT_PCRE_HAS_JIT_EXITCODE 0)
120120

121-
################################################################################
122-
# ext/posix
123-
################################################################################
124-
125-
# Set the exit code of the ttyname_r check.
126-
set(HAVE_TTYNAME_R_EXITCODE 0)
127-
128121
################################################################################
129122
# ext/session
130123
################################################################################
131124

132-
# Set the exit code of the pread check.
133-
set(HAVE_PREAD_EXITCODE 0)
134-
set(PHP_PREAD_64_EXITCODE 0)
135-
136-
# Set the exit code of the pwrite check.
137-
set(HAVE_PWRITE_EXITCODE 0)
138-
set(PHP_PWRITE_64_EXITCODE 0)
125+
# Set the exit codes for the pread()/pwrite() checks.
126+
set(PHP_EXT_SESSION_HAS_PREAD_EXITCODE 0)
127+
set(PHP_EXT_SESSION_HAS_PWRITE_EXITCODE 0)
139128

140129
################################################################################
141130
# ext/standard

cmake/ext/posix/cmake/CheckTtynameR.cmake

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
11
#[=============================================================================[
2-
# CheckTtynameR
2+
Check ttyname_r().
33
4-
Check `ttyname_r()`.
5-
6-
On Solaris/illumos `ttyname_r()` works only with larger buffers (>= 128),
7-
unlike, for example, on Linux and other systems, where buffer size can be any
8-
`size_t` size, also < 128. PHP code uses `ttyname_r()` with large buffers, so it
4+
On Solaris/illumos ttyname_r() works only with larger buffers (>= 128), unlike,
5+
for example, on Linux and other systems, where buffer size can be any
6+
'size_t' size, also < 128. PHP code uses ttyname_r() with large buffers, so it
97
wouldn't be necessary to check small buffers but the run check below is kept for
108
brevity.
119
1210
On modern systems a simpler check is sufficient in the future:
1311
14-
```cmake
15-
check_symbol_exists(ttyname_r unistd.h HAVE_TTYNAME_R)
16-
```
17-
18-
## Cache variables
19-
20-
* `HAVE_TTYNAME_R`
21-
22-
Whether `ttyname_r()` works as expected.
12+
check_symbol_exists(ttyname_r unistd.h HAVE_TTYNAME_R)
2313
24-
## Usage
14+
Result variables:
2515
26-
```cmake
27-
# CMakeLists.txt
28-
include(cmake/CheckTtynameR.cmake)
29-
```
16+
* HAVE_TTYNAME_R - Whether ttyname_r() works as expected.
3017
#]=============================================================================]
3118

3219
include_guard(GLOBAL)
@@ -36,6 +23,20 @@ include(CheckSourceRuns)
3623
include(CMakePushCheckState)
3724
include(PHP/SystemExtensions)
3825

26+
set(HAVE_TTYNAME_R FALSE)
27+
28+
# Skip in consecutive configuration phases.
29+
if(
30+
DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE
31+
OR DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R
32+
)
33+
if(PHP_EXT_POSIX_HAS_TTYNAME_R)
34+
set(HAVE_TTYNAME_R TRUE)
35+
endif()
36+
37+
return()
38+
endif()
39+
3940
message(CHECK_START "Checking for working ttyname_r()")
4041

4142
cmake_push_check_state(RESET)
@@ -54,21 +55,21 @@ cmake_push_check_state(RESET)
5455
"int ttyname_r(int fd, char *buf, size_t buflen)"
5556
"0"
5657
"unistd.h"
57-
PHP_HAS_TTYNAME_R_PROTOTYPE
58+
PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE
5859
)
5960

60-
if(NOT PHP_HAS_TTYNAME_R_PROTOTYPE)
61+
if(NOT PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE)
6162
message(CHECK_FAIL "no (non-standard declaration)")
6263
cmake_pop_check_state()
6364
return()
6465
endif()
6566

6667
if(
67-
NOT DEFINED HAVE_TTYNAME_R_EXITCODE
68-
AND CMAKE_CROSSCOMPILING
68+
CMAKE_CROSSCOMPILING
6969
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
70+
AND NOT DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE
7071
)
71-
set(HAVE_TTYNAME_R_EXITCODE 0)
72+
set(PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE 0)
7273
endif()
7374

7475
# PHP Autotools-based build system check uses a different return below due
@@ -92,8 +93,9 @@ cmake_push_check_state(RESET)
9293
9394
return ttyname_r(0, buf, buflen) ? 1 : 0;
9495
}
95-
]] HAVE_TTYNAME_R)
96-
if(HAVE_TTYNAME_R)
96+
]] PHP_EXT_POSIX_HAS_TTYNAME_R)
97+
if(PHP_EXT_POSIX_HAS_TTYNAME_R)
98+
set(HAVE_TTYNAME_R TRUE)
9799
message(CHECK_PASS "yes")
98100
else()
99101
message(CHECK_FAIL "no (posix_ttyname() will be thread-unsafe)")

0 commit comments

Comments
 (0)