Skip to content

Commit a99f20b

Browse files
committed
Fix code review comments
1 parent 6d0139e commit a99f20b

File tree

10 files changed

+64
-71
lines changed

10 files changed

+64
-71
lines changed

ext/gd/gd.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,9 +2540,8 @@ PHP_FUNCTION(imagecolortransparent)
25402540
zend_long COL = 0;
25412541
zend_bool COL_IS_NULL = 1;
25422542
gdImagePtr im;
2543-
int argc = ZEND_NUM_ARGS();
25442543

2545-
if (zend_parse_parameters(argc, "O|l!", &IM, gd_image_ce, &COL, &COL_IS_NULL) == FAILURE) {
2544+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!", &IM, gd_image_ce, &COL, &COL_IS_NULL) == FAILURE) {
25462545
RETURN_THROWS();
25472546
}
25482547

@@ -2561,12 +2560,11 @@ PHP_FUNCTION(imagecolortransparent)
25612560
PHP_FUNCTION(imageinterlace)
25622561
{
25632562
zval *IM;
2564-
int argc = ZEND_NUM_ARGS();
25652563
zend_long INT = 0;
25662564
zend_bool INT_IS_NULL = 1;
25672565
gdImagePtr im;
25682566

2569-
if (zend_parse_parameters(argc, "O|l!", &IM, gd_image_ce, &INT, &INT_IS_NULL) == FAILURE) {
2567+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!", &IM, gd_image_ce, &INT, &INT_IS_NULL) == FAILURE) {
25702568
RETURN_THROWS();
25712569
}
25722570

@@ -4041,6 +4039,9 @@ PHP_FUNCTION(imageresolution)
40414039
} else if (!res_x_is_null && res_y_is_null) {
40424040
gdImageSetResolution(im, res_x, res_x);
40434041
RETURN_TRUE;
4042+
} else if (res_x_is_null && !res_y_is_null) {
4043+
gdImageSetResolution(im, res_y, res_y);
4044+
RETURN_TRUE;
40444045
}
40454046

40464047
array_init(return_value);
@@ -4122,11 +4123,10 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41224123
zval *imgind;
41234124
char *file = NULL;
41244125
size_t file_len = 0;
4125-
zend_long quality, basefilter;
4126-
zend_bool compressed = 1, quality_is_null = 1, basefilter_is_null = 1;
4126+
zend_long quality = -1, basefilter = -1;
4127+
zend_bool compressed = 1;
41274128
gdImagePtr im;
4128-
int q = -1, i;
4129-
int f = -1;
4129+
int i;
41304130
gdIOCtx *ctx = NULL;
41314131
zval *to_zval = NULL;
41324132
php_stream *stream;
@@ -4137,8 +4137,8 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41374137
*/
41384138
switch (image_type) {
41394139
case PHP_GDIMG_TYPE_XBM:
4140-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op!|l!l!",
4141-
&imgind, gd_image_ce, &file, &file_len, &quality, &quality_is_null, &basefilter, &basefilter_is_null
4140+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op!|l",
4141+
&imgind, gd_image_ce, &file, &file_len, &quality
41424142
) == FAILURE) {
41434143
RETURN_THROWS();
41444144
}
@@ -4148,32 +4148,33 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41484148
RETURN_THROWS();
41494149
}
41504150
break;
4151+
case PHP_GDIMG_TYPE_PNG:
4152+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!ll",
4153+
&imgind, gd_image_ce, &to_zval, &quality, &basefilter
4154+
) == FAILURE) {
4155+
RETURN_THROWS();
4156+
}
4157+
break;
4158+
case PHP_GDIMG_TYPE_GIF:
4159+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!", &imgind, gd_image_ce, &to_zval) == FAILURE) {
4160+
RETURN_THROWS();
4161+
}
4162+
break;
41514163
default:
4152-
/* PHP_GDIMG_TYPE_GIF
4153-
* PHP_GDIMG_TYPE_PNG
4164+
/*
41544165
* PHP_GDIMG_TYPE_JPG
41554166
* PHP_GDIMG_TYPE_WBM
41564167
* PHP_GDIMG_TYPE_WEBP
4157-
* */
4158-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!l!l!",
4159-
&imgind, gd_image_ce, &to_zval, &quality, &quality_is_null, &basefilter, &basefilter_is_null
4168+
*/
4169+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!l",
4170+
&imgind, gd_image_ce, &to_zval, &quality
41604171
) == FAILURE) {
41614172
RETURN_THROWS();
41624173
}
41634174
}
41644175

41654176
im = php_gd_libgdimageptr_from_zval_p(imgind);
41664177

4167-
if (image_type != PHP_GDIMG_TYPE_BMP) {
4168-
if (!quality_is_null) {
4169-
q = quality; /* or colorindex for foreground of BW images (defaults to black) */
4170-
}
4171-
4172-
if (!basefilter_is_null) {
4173-
f = basefilter;
4174-
}
4175-
}
4176-
41774178
if (to_zval != NULL) {
41784179
if (Z_TYPE_P(to_zval) == IS_RESOURCE) {
41794180
php_stream_from_zval_no_verify(stream, to_zval);
@@ -4221,29 +4222,29 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
42214222

42224223
switch(image_type) {
42234224
case PHP_GDIMG_TYPE_JPG:
4224-
(*func_p)(im, ctx, q);
4225+
(*func_p)(im, ctx, quality);
42254226
break;
42264227
case PHP_GDIMG_TYPE_WEBP:
4227-
if (q == -1) {
4228-
q = 80;
4228+
if (quality == -1) {
4229+
quality = 80;
42294230
}
4230-
(*func_p)(im, ctx, q);
4231+
(*func_p)(im, ctx, quality);
42314232
break;
42324233
case PHP_GDIMG_TYPE_PNG:
4233-
(*func_p)(im, ctx, q, f);
4234+
(*func_p)(im, ctx, quality, (int) basefilter);
42344235
break;
42354236
case PHP_GDIMG_TYPE_XBM:
42364237
case PHP_GDIMG_TYPE_WBM:
4237-
if (quality_is_null) {
4238+
if (quality == -1) {
42384239
for(i=0; i < gdImageColorsTotal(im); i++) {
42394240
if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
42404241
}
4241-
q = i;
4242+
quality = i;
42424243
}
42434244
if (image_type == PHP_GDIMG_TYPE_XBM) {
4244-
(*func_p)(im, file ? file : "", q, ctx);
4245+
(*func_p)(im, file ? file : "", quality, ctx);
42454246
} else {
4246-
(*func_p)(im, q, ctx);
4247+
(*func_p)(im, quality, ctx);
42474248
}
42484249
break;
42494250
case PHP_GDIMG_TYPE_BMP:

ext/gd/gd.stub.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,23 @@ function imagecreatefrombmp(string $filename): GdImage|false {}
100100
function imagecreatefromtga(string $filename): GdImage|false {}
101101
#endif
102102

103-
function imagexbm(GdImage $im, ?string $filename, ?int $foreground = null, ?int $filters = null): bool {}
103+
function imagexbm(GdImage $im, ?string $filename, int $foreground = -1): bool {}
104104

105105
function imagegif(GdImage $im, $to = null): bool {}
106106

107107
#ifdef HAVE_GD_PNG
108-
function imagepng(GdImage $im, $to = null, ?int $quality = null, ?int $filters = null): bool {}
108+
function imagepng(GdImage $im, $to = null, int $quality = -1, int $filters = -1): bool {}
109109
#endif
110110

111111
#ifdef HAVE_GD_WEBP
112-
function imagewebp(GdImage $im, $to = null, ?int $quality = null, ?int $filters = null): bool {}
112+
function imagewebp(GdImage $im, $to = null, int $quality = -1): bool {}
113113
#endif
114114

115115
#ifdef HAVE_GD_JPG
116-
function imagejpeg(GdImage $im, $to = null, ?int $quality = null, ?int $filters = null): bool {}
116+
function imagejpeg(GdImage $im, $to = null, int $quality = -1): bool {}
117117
#endif
118118

119-
function imagewbmp(GdImage $im, $to = null, ?int $foreground = null, ?int $filters = null): bool {}
119+
function imagewbmp(GdImage $im, $to = null, int $foreground = -1): bool {}
120120

121121
function imagegd(GdImage $im, $to = UNKNOWN): bool {}
122122

ext/gd/gd_arginfo.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ ZEND_END_ARG_INFO()
199199
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagexbm, 0, 2, _IS_BOOL, 0)
200200
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
201201
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 1)
202-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, foreground, IS_LONG, 1, "null")
203-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filters, IS_LONG, 1, "null")
202+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, foreground, IS_LONG, 0, "-1")
204203
ZEND_END_ARG_INFO()
205204

206205
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegif, 0, 1, _IS_BOOL, 0)
@@ -212,34 +211,31 @@ ZEND_END_ARG_INFO()
212211
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagepng, 0, 1, _IS_BOOL, 0)
213212
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
214213
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, to, "null")
215-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, quality, IS_LONG, 1, "null")
216-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filters, IS_LONG, 1, "null")
214+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, quality, IS_LONG, 0, "-1")
215+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filters, IS_LONG, 0, "-1")
217216
ZEND_END_ARG_INFO()
218217
#endif
219218

220219
#if defined(HAVE_GD_WEBP)
221220
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagewebp, 0, 1, _IS_BOOL, 0)
222221
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
223222
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, to, "null")
224-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, quality, IS_LONG, 1, "null")
225-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filters, IS_LONG, 1, "null")
223+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, quality, IS_LONG, 0, "-1")
226224
ZEND_END_ARG_INFO()
227225
#endif
228226

229227
#if defined(HAVE_GD_JPG)
230228
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagejpeg, 0, 1, _IS_BOOL, 0)
231229
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
232230
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, to, "null")
233-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, quality, IS_LONG, 1, "null")
234-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filters, IS_LONG, 1, "null")
231+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, quality, IS_LONG, 0, "-1")
235232
ZEND_END_ARG_INFO()
236233
#endif
237234

238235
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagewbmp, 0, 1, _IS_BOOL, 0)
239236
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
240237
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, to, "null")
241-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, foreground, IS_LONG, 1, "null")
242-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filters, IS_LONG, 1, "null")
238+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, foreground, IS_LONG, 0, "-1")
243239
ZEND_END_ARG_INFO()
244240

245241
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd, 0, 1, _IS_BOOL, 0)

ext/mbstring/mbstring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,7 @@ PHP_FUNCTION(mb_encode_mimeheader)
28992899

29002900
string.encoding = MBSTRG(current_internal_encoding);
29012901

2902-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S!s!s!l",
2902+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S!s!sl",
29032903
(char **)&string.val, &string.len, &charset_name, &trans_enc_name, &trans_enc_name_len,
29042904
&linefeed, &linefeed_len, &indent
29052905
) == FAILURE) {

ext/mbstring/mbstring.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function mb_strcut(string $str, int $start, ?int $length = null, ?string $encodi
4848

4949
function mb_strwidth(string $str, ?string $encoding = null): int {}
5050

51-
function mb_strimwidth(string $str, int $start, int $width, ?string $trim_marker = null, ?string $encoding = null): string {}
51+
function mb_strimwidth(string $str, int $start, int $width, string $trim_marker = "", ?string $encoding = null): string {}
5252

5353
function mb_convert_encoding(array|string $str, string $to, array|string|null $from = null): array|string|false {}
5454

@@ -64,11 +64,11 @@ function mb_list_encodings(): array {}
6464

6565
function mb_encoding_aliases(string $encoding): array {}
6666

67-
function mb_encode_mimeheader(string $str, ?string $charset = null, ?string $transfer = null, ?string $linefeed = null, int $indent = 0): string {}
67+
function mb_encode_mimeheader(string $str, ?string $charset = null, ?string $transfer = null, string $linefeed = "\r\n", int $indent = 0): string {}
6868

6969
function mb_decode_mimeheader(string $string): string {}
7070

71-
function mb_convert_kana(string $str, ?string $option = null, ?string $encoding = null): string {}
71+
function mb_convert_kana(string $str, string $option = "KV", ?string $encoding = null): string {}
7272

7373
function mb_convert_variables(string $to, array|string $from, &$var, &...$vars): string|false {}
7474

ext/mbstring/mbstring_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_strimwidth, 0, 3, IS_STRING,
9999
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
100100
ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0)
101101
ZEND_ARG_TYPE_INFO(0, width, IS_LONG, 0)
102-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, trim_marker, IS_STRING, 1, "null")
102+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, trim_marker, IS_STRING, 0, "\"\"")
103103
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null")
104104
ZEND_END_ARG_INFO()
105105

@@ -139,7 +139,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_encode_mimeheader, 0, 1, IS_S
139139
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
140140
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null")
141141
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, transfer, IS_STRING, 1, "null")
142-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, linefeed, IS_STRING, 1, "null")
142+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, linefeed, IS_STRING, 0, "\"\\r\\n\"")
143143
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, indent, IS_LONG, 0, "0")
144144
ZEND_END_ARG_INFO()
145145

@@ -149,7 +149,7 @@ ZEND_END_ARG_INFO()
149149

150150
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_convert_kana, 0, 1, IS_STRING, 0)
151151
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
152-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, option, IS_STRING, 1, "null")
152+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, option, IS_STRING, 0, "\"KV\"")
153153
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null")
154154
ZEND_END_ARG_INFO()
155155

ext/mbstring/php_mbregex.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,8 +1348,7 @@ PHP_FUNCTION(mb_ereg_match)
13481348

13491349
/* regex search */
13501350
/* {{{ _php_mb_regex_ereg_search_exec */
1351-
static void
1352-
_php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
1351+
static void _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
13531352
{
13541353
char *arg_pattern = NULL, *arg_options = NULL;
13551354
size_t arg_pattern_len, arg_options_len;
@@ -1365,11 +1364,12 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
13651364
RETURN_THROWS();
13661365
}
13671366

1368-
option = MBREX(regex_default_options);
1369-
13701367
if (arg_options) {
13711368
option = 0;
13721369
_php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL);
1370+
} else {
1371+
option = MBREX(regex_default_options);
1372+
syntax = MBREX(regex_default_syntax);
13731373
}
13741374

13751375
if (MBREX(search_regs)) {
@@ -1506,12 +1506,12 @@ PHP_FUNCTION(mb_ereg_search_init)
15061506
RETURN_FALSE;
15071507
}
15081508

1509-
option = MBREX(regex_default_options);
1510-
syntax = MBREX(regex_default_syntax);
1511-
15121509
if (arg_options) {
15131510
option = 0;
15141511
_php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL);
1512+
} else {
1513+
option = MBREX(regex_default_options);
1514+
syntax = MBREX(regex_default_syntax);
15151515
}
15161516

15171517
if (arg_pattern) {
@@ -1527,11 +1527,7 @@ PHP_FUNCTION(mb_ereg_search_init)
15271527

15281528
ZVAL_STR_COPY(&MBREX(search_str), arg_str);
15291529

1530-
if (php_mb_check_encoding(
1531-
ZSTR_VAL(arg_str),
1532-
ZSTR_LEN(arg_str),
1533-
php_mb_regex_get_mbctype_encoding()
1534-
)) {
1530+
if (php_mb_check_encoding(ZSTR_VAL(arg_str), ZSTR_LEN(arg_str), php_mb_regex_get_mbctype_encoding())) {
15351531
MBREX(search_pos) = 0;
15361532
RETVAL_TRUE;
15371533
} else {

ext/xmlrpc/xmlrpc-epi-php.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ PHP_FUNCTION(xmlrpc_encode_request)
626626
size_t method_len;
627627
php_output_options out;
628628

629-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!z|a!", &method, &method_len, &vals, &out_opts) == FAILURE) {
629+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!z|a", &method, &method_len, &vals, &out_opts) == FAILURE) {
630630
RETURN_THROWS();
631631
}
632632

ext/xmlrpc/xmlrpc.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function xmlrpc_decode(string $xml, string $encoding = "iso-8859-1"): mixed {}
1212

1313
function xmlrpc_decode_request(string $xml, &$method, string $encoding = "iso-8859-1"): mixed {}
1414

15-
function xmlrpc_encode_request(?string $method, mixed $params, ?array $output_options = null): ?string {}
15+
function xmlrpc_encode_request(?string $method, mixed $params, array $output_options = []): ?string {}
1616

1717
function xmlrpc_get_type(mixed $value): string {}
1818

ext/xmlrpc/xmlrpc_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ZEND_END_ARG_INFO()
1818
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlrpc_encode_request, 0, 2, IS_STRING, 1)
1919
ZEND_ARG_TYPE_INFO(0, method, IS_STRING, 1)
2020
ZEND_ARG_TYPE_INFO(0, params, IS_MIXED, 0)
21-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, output_options, IS_ARRAY, 1, "null")
21+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, output_options, IS_ARRAY, 0, "[]")
2222
ZEND_END_ARG_INFO()
2323

2424
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlrpc_get_type, 0, 1, IS_STRING, 0)

0 commit comments

Comments
 (0)