Skip to content

Commit c1a5495

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
2 parents 60f3bcd + 6363a49 commit c1a5495

File tree

7 files changed

+160
-193
lines changed

7 files changed

+160
-193
lines changed

cmake/cmake/checks/CheckGetaddrinfo.cmake

Lines changed: 59 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,95 +2,77 @@
22
Check whether getaddrinfo() function is working as expected.
33
#]=============================================================================]
44

5-
include(CheckSourceRuns)
6-
include(CMakePushCheckState)
75
include(PHP/SearchLibraries)
86

9-
# The getaddrinfo() is mostly in C library (Solaris 11.4, illumos...)
10-
php_search_libraries(
11-
SYMBOL getaddrinfo
12-
HEADERS
13-
netdb.h
14-
ws2tcpip.h
15-
LIBRARIES
16-
socket # Solaris <= 11.3
17-
network # Haiku
18-
ws2_32 # Windows
19-
RESULT_VARIABLE PHP_HAVE_GETADDRINFO_SYMBOL
20-
LIBRARY_VARIABLE PHP_HAVE_GETADDRINFO_LIBRARY
21-
)
22-
23-
if(PHP_HAVE_GETADDRINFO_SYMBOL AND NOT DEFINED PHP_HAVE_GETADDRINFO)
24-
message(CHECK_START "Checking whether getaddrinfo() works")
25-
26-
cmake_push_check_state(RESET)
27-
set(CMAKE_REQUIRED_QUIET TRUE)
28-
if(PHP_HAVE_GETADDRINFO_LIBRARY)
29-
set(CMAKE_REQUIRED_LIBRARIES ${PHP_HAVE_GETADDRINFO_LIBRARY})
30-
endif()
7+
# On Windows, getaddrinfo() and its implementation in PHP are supported.
8+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
9+
set(PHP_HAVE_GETADDRINFO TRUE)
10+
set(PHP_HAVE_GETADDRINFO_LIBRARY ws2_32)
11+
endif()
3112

32-
if(
33-
CMAKE_CROSSCOMPILING
34-
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
35-
AND NOT DEFINED PHP_HAVE_GETADDRINFO_EXITCODE
36-
AND CMAKE_SYSTEM_NAME MATCHES "^(Linux|Midipix)$"
37-
)
38-
set(PHP_HAVE_GETADDRINFO_EXITCODE 0)
39-
endif()
13+
if(
14+
CMAKE_CROSSCOMPILING
15+
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
16+
AND NOT DEFINED PHP_HAVE_GETADDRINFO_EXITCODE
17+
AND CMAKE_SYSTEM_NAME MATCHES "^(Linux|Midipix)$"
18+
)
19+
set(PHP_HAVE_GETADDRINFO_EXITCODE 0)
20+
endif()
4021

41-
check_source_runs(C [[
42-
#include <netdb.h>
43-
#include <sys/types.h>
44-
#include <string.h>
45-
#include <stdlib.h>
46-
#ifndef AF_INET
47-
# include <sys/socket.h>
48-
#endif
22+
# The getaddrinfo() is mostly in C library (Solaris 11.4, illumos...)
23+
php_search_libraries(
24+
SOURCE_RUNS [[
25+
#include <netdb.h>
26+
#include <sys/types.h>
27+
#include <string.h>
28+
#include <stdlib.h>
29+
#ifndef AF_INET
30+
# include <sys/socket.h>
31+
#endif
32+
33+
int main(void)
34+
{
35+
struct addrinfo *ai, *pai, hints;
36+
37+
memset(&hints, 0, sizeof(hints));
38+
hints.ai_flags = AI_NUMERICHOST;
39+
40+
if (getaddrinfo("127.0.0.1", 0, &hints, &ai) < 0) {
41+
return 1;
42+
}
4943

50-
int main(void)
51-
{
52-
struct addrinfo *ai, *pai, hints;
44+
if (ai == 0) {
45+
return 1;
46+
}
5347

54-
memset(&hints, 0, sizeof(hints));
55-
hints.ai_flags = AI_NUMERICHOST;
48+
pai = ai;
5649

57-
if (getaddrinfo("127.0.0.1", 0, &hints, &ai) < 0) {
50+
while (pai) {
51+
if (pai->ai_family != AF_INET) {
52+
/* 127.0.0.1/NUMERICHOST should only resolve ONE way */
5853
return 1;
5954
}
60-
61-
if (ai == 0) {
55+
if (pai->ai_addr->sa_family != AF_INET) {
56+
/* 127.0.0.1/NUMERICHOST should only resolve ONE way */
6257
return 1;
6358
}
64-
65-
pai = ai;
66-
67-
while (pai) {
68-
if (pai->ai_family != AF_INET) {
69-
/* 127.0.0.1/NUMERICHOST should only resolve ONE way */
70-
return 1;
71-
}
72-
if (pai->ai_addr->sa_family != AF_INET) {
73-
/* 127.0.0.1/NUMERICHOST should only resolve ONE way */
74-
return 1;
75-
}
76-
pai = pai->ai_next;
77-
}
78-
freeaddrinfo(ai);
79-
80-
return 0;
59+
pai = pai->ai_next;
8160
}
82-
]] PHP_HAVE_GETADDRINFO)
83-
cmake_pop_check_state()
84-
85-
if(PHP_HAVE_GETADDRINFO)
86-
message(CHECK_PASS "yes")
87-
else()
88-
message(CHECK_FAIL "no")
89-
endif()
90-
endif()
61+
freeaddrinfo(ai);
9162

92-
if(PHP_HAVE_GETADDRINFO AND PHP_HAVE_GETADDRINFO_LIBRARY)
93-
target_link_libraries(php_config INTERFACE ${PHP_HAVE_GETADDRINFO_LIBRARY})
94-
endif()
63+
return 0;
64+
}
65+
]]
66+
HEADERS
67+
netdb.h
68+
ws2tcpip.h
69+
LIBRARIES
70+
socket # Solaris <= 11.3
71+
network # Haiku
72+
ws2_32 # Windows
73+
RESULT_VARIABLE PHP_HAVE_GETADDRINFO
74+
LIBRARY_VARIABLE PHP_HAVE_GETADDRINFO_LIBRARY
75+
TARGET php_config INTERFACE
76+
)
9577

9678
set(HAVE_GETADDRINFO "${PHP_HAVE_GETADDRINFO}")

cmake/cmake/checks/CheckGetifaddrs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ few noted exceptions below. Some systems also need <sys/types.h> header
1212
include(PHP/SearchLibraries)
1313

1414
php_search_libraries(
15-
SOURCE [[
15+
SOURCE_COMPILES [[
1616
#include <sys/types.h>
1717
#include <ifaddrs.h>
1818

cmake/cmake/checks/CheckIPv6.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cmake_push_check_state(RESET)
3030
# On some systems, additional library is needed for the in6addr_any variable
3131
# (from <netinet/in.h>).
3232
php_search_libraries(
33-
SOURCE [[
33+
SOURCE_COMPILES [[
3434
#include <sys/types.h>
3535
#include <sys/socket.h>
3636
#include <netinet/in.h>

cmake/cmake/modules/PHP/SearchLibraries.cmake

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ given headers, and determines if additional libraries need to be linked:
3838
3939
```cmake
4040
php_search_libraries(
41-
SYMBOL <symbol> | SOURCE <code>
41+
SYMBOL <symbol> | SOURCE_COMPILES <code> | SOURCE_RUNS <code>
4242
[HEADERS <headers>...]
4343
[LIBRARIES <libraries>...]
4444
[RESULT_VARIABLE <var>]
@@ -59,10 +59,16 @@ libraries and links the first one in which the symbol is found.
5959
6060
The name of the C symbol to check.
6161
62-
* `SOURCE <code>`
62+
* `SOURCE_COMPILES <code>`
6363
6464
This argument can be used to check whether the specified C source `<code>` can
65-
be compiled and linked, instead of a `SYMBOL <symbol>` argument.
65+
be compiled and linked, instead of a `SYMBOL`, or `SOURCE_RUNS` argument.
66+
67+
* `SOURCE_RUNS <code>`
68+
69+
This argument can be used to check whether the specified C source `<code>` can
70+
be compiled, linked, and run, instead of a `SYMBOL`, or `SOURCE_COMPILES`
71+
argument.
6672
6773
* `HEADERS <headers>...`
6874
@@ -73,8 +79,8 @@ libraries and links the first one in which the symbol is found.
7379
example, to be able to use `<arpa/nameser.h>` header on Solaris, the
7480
`<sys/types.h>` header must be included before.
7581
76-
When using `SOURCE <code>` argument, `<headers>` are prepended to the C source
77-
`<code>` using `#include <header>...`.
82+
When using `SOURCE_COMPILES`, or `SOURCE_RUNS` argument, `<headers>` are
83+
prepended to the C source `<code>` using `#include <header>...`.
7884
7985
* `LIBRARIES <libraries>...`
8086
@@ -193,7 +199,7 @@ internal cache variable.
193199
include(PHP/SearchLibraries)
194200
195201
php_search_libraries(
196-
SOURCE [[
202+
SOURCE_COMPILES [[
197203
#include <sys/types.h>
198204
#include <sys/socket.h>
199205
#include <netinet/in.h>
@@ -224,6 +230,7 @@ include_guard(GLOBAL)
224230

225231
include(CheckIncludeFiles)
226232
include(CheckSourceCompiles)
233+
include(CheckSourceRuns)
227234
include(CheckSymbolExists)
228235
include(CMakePushCheckState)
229236

@@ -234,39 +241,64 @@ macro(_php_search_libraries_populate)
234241
endif()
235242
endmacro()
236243

237-
function(_php_search_libraries_check_source source headers result)
244+
function(_php_search_libraries_check_source_compiles source headers result)
238245
foreach(header IN LISTS headers)
239246
string(PREPEND source "#include <${header}>\n")
240247
endforeach()
241248

242249
check_source_compiles(C "${source}" ${result})
243250
endfunction()
244251

252+
function(_php_search_libraries_check_source_runs source headers result)
253+
foreach(header IN LISTS headers)
254+
string(PREPEND source "#include <${header}>\n")
255+
endforeach()
256+
257+
check_source_runs(C "${source}" ${result})
258+
endfunction()
259+
245260
function(php_search_libraries)
246261
cmake_parse_arguments(
247262
PARSE_ARGV
248263
0
249264
parsed # prefix
250265
"RECHECK_HEADERS" # options
251-
"SYMBOL;SOURCE;RESULT_VARIABLE;LIBRARY_VARIABLE" # one-value keywords
266+
"SYMBOL;SOURCE_COMPILES;SOURCE_RUNS;RESULT_VARIABLE;LIBRARY_VARIABLE" # one-value keywords
252267
"HEADERS;LIBRARIES;TARGET" # multi-value keywords
253268
)
254269

255270
if(parsed_UNPARSED_ARGUMENTS)
256271
message(FATAL_ERROR "Unrecognized arguments: ${parsed_UNPARSED_ARGUMENTS}")
257272
endif()
258273

259-
if(NOT DEFINED parsed_SYMBOL AND NOT DEFINED parsed_SOURCE)
260-
message(FATAL_ERROR "Missing SYMBOL or SOURCE argument")
261-
elseif(DEFINED parsed_SYMBOL AND DEFINED parsed_SOURCE)
262-
message(FATAL_ERROR "Use either SYMBOL or SOURCE argument. Not both.")
274+
if(
275+
NOT DEFINED parsed_SYMBOL
276+
AND NOT DEFINED parsed_SOURCE_COMPILES
277+
AND NOT DEFINED parsed_SOURCE_RUNS
278+
)
279+
message(
280+
FATAL_ERROR
281+
"Missing SYMBOL, SOURCE_COMPILES, or SOURCE_RUNS argument"
282+
)
283+
elseif(
284+
(DEFINED parsed_SYMBOL AND DEFINED parsed_SOURCE_COMPILES)
285+
OR (DEFINED parsed_SYMBOL AND DEFINED parsed_SOURCE_RUNS)
286+
OR (DEFINED parsed_SOURCE_COMPILES AND DEFINED parsed_SOURCE_RUNS)
287+
)
288+
message(
289+
FATAL_ERROR
290+
"Use either SYMBOL, SOURCE_COMPILES, or SOURCE_RUNS argument. "
291+
"Not multiple ones."
292+
)
263293
endif()
264294

265295
if(NOT parsed_RESULT_VARIABLE OR NOT parsed_LIBRARY_VARIABLE)
266296
if(DEFINED parsed_SYMBOL)
267297
set(id "${parsed_SYMBOL}")
268-
elseif(DEFINED parsed_SOURCE)
269-
set(id "${parsed_SOURCE}")
298+
elseif(DEFINED parsed_SOURCE_COMPILES)
299+
set(id "${parsed_SOURCE_COMPILES}")
300+
elseif(DEFINED parsed_SOURCE_RUNS)
301+
set(id "${parsed_SOURCE_RUNS}")
270302
endif()
271303

272304
string(MD5 hash "${id}_${parsed_HEADERS}_${parsed_LIBRARIES}")
@@ -344,9 +376,15 @@ function(php_search_libraries)
344376
"${headersFound}"
345377
${parsed_RESULT_VARIABLE}
346378
)
347-
elseif(DEFINED parsed_SOURCE)
348-
_php_search_libraries_check_source(
349-
"${parsed_SOURCE}"
379+
elseif(DEFINED parsed_SOURCE_COMPILES)
380+
_php_search_libraries_check_source_compiles(
381+
"${parsed_SOURCE_COMPILES}"
382+
"${headersFound}"
383+
${parsed_RESULT_VARIABLE}
384+
)
385+
elseif(DEFINED parsed_SOURCE_RUNS)
386+
_php_search_libraries_check_source_runs(
387+
"${parsed_SOURCE_RUNS}"
350388
"${headersFound}"
351389
${parsed_RESULT_VARIABLE}
352390
)
@@ -373,7 +411,7 @@ function(php_search_libraries)
373411
CHECK_START
374412
"Looking for ${parsed_SYMBOL} in library ${library}"
375413
)
376-
elseif(DEFINED parsed_SOURCE)
414+
elseif(DEFINED parsed_SOURCE_COMPILES OR DEFINED parsed_SOURCE_RUNS)
377415
message(
378416
CHECK_START
379417
"Performing test ${parsed_RESULT_VARIABLE} with library ${library}"
@@ -399,9 +437,15 @@ function(php_search_libraries)
399437
"${headersFound}"
400438
${parsed_RESULT_VARIABLE}
401439
)
402-
elseif(DEFINED parsed_SOURCE)
403-
_php_search_libraries_check_source(
404-
"${parsed_SOURCE}"
440+
elseif(DEFINED parsed_SOURCE_COMPILES)
441+
_php_search_libraries_check_source_compiles(
442+
"${parsed_SOURCE_COMPILES}"
443+
"${headersFound}"
444+
${parsed_RESULT_VARIABLE}
445+
)
446+
elseif(DEFINED parsed_SOURCE_RUNS)
447+
_php_search_libraries_check_source_runs(
448+
"${parsed_SOURCE_RUNS}"
405449
"${headersFound}"
406450
${parsed_RESULT_VARIABLE}
407451
)
@@ -416,7 +460,7 @@ function(php_search_libraries)
416460
# Store found library in a cache variable for internal purpose.
417461
if(DEFINED parsed_SYMBOL)
418462
set(help "Library required to use the '${parsed_SYMBOL}' symbol.")
419-
elseif(DEFINED parsed_SOURCE)
463+
elseif(DEFINED parsed_SOURCE_COMPILES OR DEFINED parsed_SOURCE_RUNS)
420464
set(help "Library required for the '${parsed_RESULT_VARIABLE}' test.")
421465
endif()
422466
set(${parsed_LIBRARY_VARIABLE} ${library} CACHE INTERNAL "${help}")

cmake/cmake/platforms/Windows.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
137137
set(PHP_HAVE_FORK FALSE)
138138
set(PHP_HAVE_FUNOPEN FALSE)
139139
set(PHP_HAVE_GAI_STRERROR FALSE)
140-
set(PHP_HAVE_GETADDRINFO TRUE)
141-
set(PHP_HAVE_GETADDRINFO_LIBRARY ws2_32)
142-
set(PHP_HAVE_GETADDRINFO_SYMBOL TRUE)
143140
set(PHP_HAVE_GETGRNAM_R FALSE)
144141
set(PHP_HAVE_GETHOSTNAME TRUE)
145142
set(PHP_HAVE_GETHOSTNAME_LIBRARY ws2_32)

0 commit comments

Comments
 (0)