Skip to content

Commit 2064836

Browse files
committed
error_code as reference optional argument
1 parent b692f4a commit 2064836

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

Zend/Optimizer/zend_func_infos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static const func_info_t func_infos[] = {
373373
F1("session_cache_limiter", MAY_BE_STRING|MAY_BE_FALSE),
374374
F1("socket_get_option", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_LONG|MAY_BE_FALSE),
375375
FN("socket_export_stream", MAY_BE_RESOURCE|MAY_BE_FALSE),
376-
F1("socket_addrinfo_lookup", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_LONG),
376+
F1("socket_addrinfo_lookup", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_FALSE),
377377
F1("socket_addrinfo_explain", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY),
378378
FN("sodium_crypto_kx_client_session_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
379379
FN("sodium_crypto_kx_server_session_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),

ext/sockets/sockets.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,17 +2730,18 @@ PHP_FUNCTION(socket_addrinfo_lookup)
27302730
char *service = NULL;
27312731
size_t service_len = 0;
27322732
zend_string *hostname, *key;
2733-
zval *hint, *zhints = NULL;
2733+
zval *hint, *zhints = NULL, *error_code = NULL;
27342734
int ret = 0;
27352735

27362736
struct addrinfo hints, *result, *rp;
27372737
php_addrinfo *res;
27382738

2739-
ZEND_PARSE_PARAMETERS_START(1, 3)
2739+
ZEND_PARSE_PARAMETERS_START(1, 4)
27402740
Z_PARAM_STR(hostname)
27412741
Z_PARAM_OPTIONAL
27422742
Z_PARAM_STRING_OR_NULL(service, service_len)
27432743
Z_PARAM_ARRAY(zhints)
2744+
Z_PARAM_ZVAL_OR_NULL(error_code)
27442745
ZEND_PARSE_PARAMETERS_END();
27452746

27462747
memset(&hints, 0, sizeof(hints));
@@ -2827,7 +2828,10 @@ PHP_FUNCTION(socket_addrinfo_lookup)
28272828
}
28282829

28292830
if ((ret = getaddrinfo(ZSTR_VAL(hostname), service, &hints, &result)) != 0) {
2830-
RETURN_LONG(ret);
2831+
if (error_code) {
2832+
ZEND_TRY_ASSIGN_REF_LONG(error_code, ret);
2833+
}
2834+
RETURN_FALSE;
28312835
}
28322836

28332837
array_init(return_value);

ext/sockets/sockets.stub.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,10 +2302,11 @@ function socket_recvmsg(Socket $socket, array &$message, int $flags = 0): int|fa
23022302
function socket_cmsg_space(int $level, int $type, int $num = 0): ?int {}
23032303

23042304
/**
2305-
* @return array<int, AddressInfo>|int
2305+
* @return array<int, AddressInfo>|false
2306+
* @param int $error_code
23062307
* @refcount 1
23072308
*/
2308-
function socket_addrinfo_lookup(string $host, ?string $service = null, array $hints = []): array|int {}
2309+
function socket_addrinfo_lookup(string $host, ?string $service = null, array $hints = [], &$error_code = null): array|false {}
23092310

23102311
function socket_addrinfo_connect(AddressInfo $address): Socket|false {}
23112312

ext/sockets/sockets_arginfo.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/sockets/tests/gh20532.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ GH-20562 - socket_addrinfo_lookup() returns error codes on resolution failures.
44
sockets
55
--FILE--
66
<?php
7-
var_dump(socket_addrinfo_lookup(".whynot") == EAI_NONAME);
8-
var_dump(in_array(socket_addrinfo_lookup("2001:db8::1", null, ['ai_family' => AF_INET]), [EAI_FAMILY, EAI_ADDRFAMILY, EAI_NONAME, EAI_NODATA]));
9-
var_dump(in_array(socket_addrinfo_lookup("example.com", "http", ['ai_socktype' => SOCK_RAW, 'ai_flags' => 2147483647]), [EAI_SOCKTYPE, EAI_SERVICE, EAI_BADFLAGS, EAI_NONAME]));
7+
$error_code = 0;
8+
var_dump(socket_addrinfo_lookup(".whynot", null, [], $error_code) === false && $error_code === EAI_NONAME);
9+
var_dump(socket_addrinfo_lookup("2001:db8::1", null, ['ai_family' => AF_INET], $error_code) === false && in_array($error_code, [EAI_FAMILY, EAI_ADDRFAMILY, EAI_NONAME, EAI_NODATA]));
10+
var_dump(socket_addrinfo_lookup("example.com", "http", ['ai_socktype' => SOCK_RAW, 'ai_flags' => 2147483647], $error_code) === false && in_array($error_code, [EAI_SOCKTYPE, EAI_SERVICE, EAI_BADFLAGS, EAI_NONAME]));
1011
?>
1112
--EXPECT--
1213
bool(true)

0 commit comments

Comments
 (0)