Skip to content

Commit fc3deaa

Browse files
committed
Fix code review comments
1 parent c5d88a2 commit fc3deaa

File tree

16 files changed

+62
-62
lines changed

16 files changed

+62
-62
lines changed

Zend/zend_API.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
13271327
#define Z_PARAM_BOOL(dest) \
13281328
Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
13291329

1330+
#define Z_PARAM_BOOL_OR_NULL(dest, is_null) \
1331+
Z_PARAM_BOOL_EX(dest, is_null, 1, 0)
1332+
13301333
/* old "C" */
13311334
#define Z_PARAM_CLASS_EX2(dest, check_null, deref, separate) \
13321335
Z_PARAM_PROLOGUE(deref, separate); \

ext/enchant/enchant.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ PHP_FUNCTION(enchant_dict_quick_check)
626626
size_t wordlen;
627627
enchant_dict *pdict;
628628

629-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|z!", &dict, &word, &wordlen, &sugg) == FAILURE) {
629+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|z", &dict, &word, &wordlen, &sugg) == FAILURE) {
630630
RETURN_THROWS();
631631
}
632632

@@ -643,7 +643,7 @@ PHP_FUNCTION(enchant_dict_quick_check)
643643
size_t n_sugg;
644644
char **suggs;
645645

646-
if (!sugg) {
646+
if (!sugg && ZEND_NUM_ARGS() == 2) {
647647
RETURN_FALSE;
648648
}
649649

ext/ffi/ffi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
28342834
ZEND_FFI_VALIDATE_API_RESTRICTION();
28352835
ZEND_PARSE_PARAMETERS_START(0, 2)
28362836
Z_PARAM_OPTIONAL
2837-
Z_PARAM_STR_OR_NULL(code)
2837+
Z_PARAM_STR(code)
28382838
Z_PARAM_STR_OR_NULL(lib)
28392839
ZEND_PARSE_PARAMETERS_END();
28402840

@@ -2854,7 +2854,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
28542854
FFI_G(symbols) = NULL;
28552855
FFI_G(tags) = NULL;
28562856

2857-
if (code) {
2857+
if (ZSTR_LEN(code)) {
28582858
/* Parse C definitions */
28592859
FFI_G(default_type_attr) = ZEND_FFI_ATTR_STORED;
28602860

ext/ffi/ffi.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
final class FFI
66
{
7-
public static function cdef(?string $code = null, ?string $lib = null): FFI {}
7+
public static function cdef(string $code = "", ?string $lib = null): FFI {}
88

99
public static function load(string $filename): ?FFI {}
1010

ext/ffi/ffi_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This is a generated file, edit the .stub.php file instead. */
22

33
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0)
4-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 1, "null")
4+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"")
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, lib, IS_STRING, 1, "null")
66
ZEND_END_ARG_INFO()
77

ext/ftp/php_ftp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ PHP_FUNCTION(ftp_alloc)
427427
zend_long size, ret;
428428
zend_string *response = NULL;
429429

430-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|z!", &z_ftp, &size, &zresponse) == FAILURE) {
430+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|z", &z_ftp, &size, &zresponse) == FAILURE) {
431431
RETURN_THROWS();
432432
}
433433

ext/hash/hash.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,7 @@ PHP_FUNCTION(hash_update_file)
493493

494494
hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
495495
PHP_HASHCONTEXT_VERIFY(hash);
496-
497-
if (zcontext) {
498-
context = php_stream_context_from_zval(zcontext, 0);
499-
}
496+
context = php_stream_context_from_zval(zcontext, 0);
500497

501498
stream = php_stream_open_wrapper_ex(ZSTR_VAL(filename), "rb", REPORT_ERRORS, NULL, context);
502499
if (!stream) {

ext/iconv/iconv.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,20 +1826,20 @@ static void _php_iconv_show_error(php_iconv_err_t err, const char *out_charset,
18261826
Returns the character count of str */
18271827
PHP_FUNCTION(iconv_strlen)
18281828
{
1829-
const char *charset;
1830-
size_t charset_len = 0;
1829+
const char *charset = NULL;
1830+
size_t charset_len;
18311831
zend_string *str;
18321832

18331833
php_iconv_err_t err;
18341834

18351835
size_t retval;
18361836

1837-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|s",
1837+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|s!",
18381838
&str, &charset, &charset_len) == FAILURE) {
18391839
RETURN_THROWS();
18401840
}
18411841

1842-
if (charset_len == 0) {
1842+
if (charset == NULL) {
18431843
charset = get_internal_encoding();
18441844
} else if (charset_len >= ICONV_CSNMAXLEN) {
18451845
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
@@ -1860,8 +1860,8 @@ PHP_FUNCTION(iconv_strlen)
18601860
Returns specified part of a string */
18611861
PHP_FUNCTION(iconv_substr)
18621862
{
1863-
const char *charset;
1864-
size_t charset_len = 0;
1863+
const char *charset = NULL;
1864+
size_t charset_len;
18651865
zend_string *str;
18661866
zend_long offset, length = 0;
18671867
zend_bool len_is_null = 1;
@@ -1870,13 +1870,13 @@ PHP_FUNCTION(iconv_substr)
18701870

18711871
smart_str retval = {0};
18721872

1873-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l!s",
1873+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l!s!",
18741874
&str, &offset, &length, &len_is_null,
18751875
&charset, &charset_len) == FAILURE) {
18761876
RETURN_THROWS();
18771877
}
18781878

1879-
if (charset_len == 0) {
1879+
if (charset == NULL) {
18801880
charset = get_internal_encoding();
18811881
} else if (charset_len >= ICONV_CSNMAXLEN) {
18821882
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
@@ -1902,8 +1902,8 @@ PHP_FUNCTION(iconv_substr)
19021902
Finds position of first occurrence of needle within part of haystack beginning with offset */
19031903
PHP_FUNCTION(iconv_strpos)
19041904
{
1905-
const char *charset;
1906-
size_t charset_len = 0, haystk_len;
1905+
const char *charset = NULL;
1906+
size_t charset_len, haystk_len;
19071907
zend_string *haystk;
19081908
zend_string *ndl;
19091909
zend_long offset = 0;
@@ -1912,13 +1912,13 @@ PHP_FUNCTION(iconv_strpos)
19121912

19131913
size_t retval;
19141914

1915-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|ls",
1915+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|ls!",
19161916
&haystk, &ndl,
19171917
&offset, &charset, &charset_len) == FAILURE) {
19181918
RETURN_THROWS();
19191919
}
19201920

1921-
if (charset_len == 0) {
1921+
if (charset == NULL) {
19221922
charset = get_internal_encoding();
19231923
} else if (charset_len >= ICONV_CSNMAXLEN) {
19241924
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
@@ -1959,16 +1959,16 @@ PHP_FUNCTION(iconv_strpos)
19591959
Finds position of last occurrence of needle within part of haystack beginning with offset */
19601960
PHP_FUNCTION(iconv_strrpos)
19611961
{
1962-
const char *charset;
1963-
size_t charset_len = 0;
1962+
const char *charset = NULL;
1963+
size_t charset_len;
19641964
zend_string *haystk;
19651965
zend_string *ndl;
19661966

19671967
php_iconv_err_t err;
19681968

19691969
size_t retval;
19701970

1971-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|s",
1971+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|s!",
19721972
&haystk, &ndl,
19731973
&charset, &charset_len) == FAILURE) {
19741974
RETURN_THROWS();
@@ -1978,7 +1978,7 @@ PHP_FUNCTION(iconv_strrpos)
19781978
RETURN_FALSE;
19791979
}
19801980

1981-
if (charset_len == 0) {
1981+
if (charset == NULL) {
19821982
charset = get_internal_encoding();
19831983
} else if (charset_len >= ICONV_CSNMAXLEN) {
19841984
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
@@ -2105,21 +2105,21 @@ PHP_FUNCTION(iconv_mime_encode)
21052105
PHP_FUNCTION(iconv_mime_decode)
21062106
{
21072107
zend_string *encoded_str;
2108-
const char *charset;
2109-
size_t charset_len = 0;
2108+
const char *charset = NULL;
2109+
size_t charset_len;
21102110
zend_long mode = 0;
21112111

21122112
smart_str retval = {0};
21132113

21142114
php_iconv_err_t err;
21152115

2116-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls",
2116+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls!",
21172117
&encoded_str, &mode, &charset, &charset_len) == FAILURE) {
21182118

21192119
RETURN_THROWS();
21202120
}
21212121

2122-
if (charset_len == 0) {
2122+
if (charset == NULL) {
21232123
charset = get_internal_encoding();
21242124
} else if (charset_len >= ICONV_CSNMAXLEN) {
21252125
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
@@ -2147,21 +2147,21 @@ PHP_FUNCTION(iconv_mime_decode)
21472147
PHP_FUNCTION(iconv_mime_decode_headers)
21482148
{
21492149
zend_string *encoded_str;
2150-
const char *charset;
2151-
size_t charset_len = 0;
2150+
const char *charset = NULL;
2151+
size_t charset_len;
21522152
zend_long mode = 0;
21532153
char *enc_str_tmp;
21542154
size_t enc_str_len_tmp;
21552155

21562156
php_iconv_err_t err = PHP_ICONV_ERR_SUCCESS;
21572157

2158-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls",
2158+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls!",
21592159
&encoded_str, &mode, &charset, &charset_len) == FAILURE) {
21602160

21612161
RETURN_THROWS();
21622162
}
21632163

2164-
if (charset_len == 0) {
2164+
if (charset == NULL) {
21652165
charset = get_internal_encoding();
21662166
} else if (charset_len >= ICONV_CSNMAXLEN) {
21672167
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);

ext/iconv/iconv.stub.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
/** @generate-function-entries */
44

5-
function iconv_strlen(string $str, string $charset = ""): int|false {}
5+
function iconv_strlen(string $str, ?string $charset = null): int|false {}
66

7-
function iconv_substr(string $str, int $offset, ?int $length = null, string $charset = ""): string|false {}
7+
function iconv_substr(string $str, int $offset, ?int $length = null, ?string $charset = null): string|false {}
88

9-
function iconv_strpos(string $haystack, string $needle, int $offset = 0, string $charset = ""): int|false {}
9+
function iconv_strpos(string $haystack, string $needle, int $offset = 0, ?string $charset = null): int|false {}
1010

11-
function iconv_strrpos(string $haystack, string $needle, string $charset = ""): int|false {}
11+
function iconv_strrpos(string $haystack, string $needle, ?string $charset = null): int|false {}
1212

1313
function iconv_mime_encode(string $field_name, string $field_value, array $preference = []): string|false {}
1414

15-
function iconv_mime_decode(string $encoded_string, int $mode = 0, string $charset = ""): string|false {}
15+
function iconv_mime_decode(string $encoded_string, int $mode = 0, ?string $charset = null): string|false {}
1616

17-
function iconv_mime_decode_headers(string $headers, int $mode = 0, string $charset = ""): array|false {}
17+
function iconv_mime_decode_headers(string $headers, int $mode = 0, ?string $charset = null): array|false {}
1818

1919
function iconv(string $in_charset, string $out_charset, string $str): string|false {}
2020

ext/iconv/iconv_arginfo.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
44
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
5-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 0, "\"\"")
5+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null")
66
ZEND_END_ARG_INFO()
77

88
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_substr, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
99
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
1010
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
1111
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null")
12-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 0, "\"\"")
12+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null")
1313
ZEND_END_ARG_INFO()
1414

1515
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strpos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
1616
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
1717
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
1818
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 0, "0")
19-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 0, "\"\"")
19+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null")
2020
ZEND_END_ARG_INFO()
2121

2222
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strrpos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
2323
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
2424
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
25-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 0, "\"\"")
25+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null")
2626
ZEND_END_ARG_INFO()
2727

2828
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_mime_encode, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
@@ -34,13 +34,13 @@ ZEND_END_ARG_INFO()
3434
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_mime_decode, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
3535
ZEND_ARG_TYPE_INFO(0, encoded_string, IS_STRING, 0)
3636
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0")
37-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 0, "\"\"")
37+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null")
3838
ZEND_END_ARG_INFO()
3939

4040
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_mime_decode_headers, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
4141
ZEND_ARG_TYPE_INFO(0, headers, IS_STRING, 0)
4242
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0")
43-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 0, "\"\"")
43+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null")
4444
ZEND_END_ARG_INFO()
4545

4646
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)

ext/libxml/libxml.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,11 @@ PHP_FUNCTION(libxml_set_streams_context)
913913
PHP_FUNCTION(libxml_use_internal_errors)
914914
{
915915
xmlStructuredErrorFunc current_handler;
916-
zend_bool use_errors=0, retval;
916+
zend_bool use_errors, use_errors_is_null = 1, retval;
917917

918918
ZEND_PARSE_PARAMETERS_START(0, 1)
919919
Z_PARAM_OPTIONAL
920-
Z_PARAM_BOOL(use_errors)
920+
Z_PARAM_BOOL_OR_NULL(use_errors, use_errors_is_null)
921921
ZEND_PARSE_PARAMETERS_END();
922922

923923
current_handler = xmlStructuredError;
@@ -927,7 +927,7 @@ PHP_FUNCTION(libxml_use_internal_errors)
927927
retval = 0;
928928
}
929929

930-
if (ZEND_NUM_ARGS() == 0) {
930+
if (use_errors_is_null) {
931931
RETURN_BOOL(retval);
932932
}
933933

ext/libxml/libxml.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/** @param resource $context */
66
function libxml_set_streams_context($context): void {}
77

8-
function libxml_use_internal_errors(bool $use_errors = false): bool {}
8+
function libxml_use_internal_errors(?bool $use_errors = null): bool {}
99

1010
function libxml_get_last_error(): LibXMLError|false {}
1111

ext/libxml/libxml_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_libxml_set_streams_context, 0, 1
55
ZEND_END_ARG_INFO()
66

77
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_libxml_use_internal_errors, 0, 0, _IS_BOOL, 0)
8-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, use_errors, _IS_BOOL, 0, "false")
8+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, use_errors, _IS_BOOL, 1, "null")
99
ZEND_END_ARG_INFO()
1010

1111
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_libxml_get_last_error, 0, 0, LibXMLError, MAY_BE_FALSE)

ext/mysqli/mysqli.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,18 +1003,18 @@ PHP_FUNCTION(mysqli_stmt_construct)
10031003
zval *mysql_link;
10041004
MY_STMT *stmt;
10051005
MYSQLI_RESOURCE *mysqli_resource;
1006-
char *statement;
1007-
size_t statement_len = 0;
1006+
char *statement = NULL;
1007+
size_t statement_len;
10081008

1009-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &mysql_link, mysqli_link_class_entry, &statement, &statement_len) == FAILURE) {
1009+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s!", &mysql_link, mysqli_link_class_entry, &statement, &statement_len) == FAILURE) {
10101010
RETURN_THROWS();
10111011
}
10121012

10131013
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
10141014

10151015
stmt = (MY_STMT *) ecalloc(1, sizeof(MY_STMT));
10161016
stmt->stmt = mysql_stmt_init(mysql->mysql);
1017-
if (stmt->stmt && statement_len != 0) {
1017+
if (stmt->stmt && statement) {
10181018
mysql_stmt_prepare(stmt->stmt, (char *)statement, statement_len);
10191019
}
10201020

0 commit comments

Comments
 (0)