Skip to content

Commit ded0b34

Browse files
committed
Merge branch 'master' of git.php.net:/php-src
* 'master' of git.php.net:/php-src: Use new Fast ZPP macros for string|int parar types utime is always available on Windows
2 parents 3d4e23a + 1f05966 commit ded0b34

File tree

5 files changed

+204
-359
lines changed

5 files changed

+204
-359
lines changed

TSRM/tsrm_win32.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,6 @@ TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf)
769769
}
770770
}/*}}}*/
771771

772-
#if HAVE_UTIME
773772
static zend_always_inline void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {{{ */
774773
{
775774
// Note that LONGLONG is a 64-bit value
@@ -824,4 +823,3 @@ TSRM_API int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */
824823
}
825824
/* }}} */
826825
#endif
827-
#endif

TSRM/tsrm_win32.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
#include "TSRM.h"
2121
#include <windows.h>
22-
#if HAVE_UTIME
23-
# include <sys/utime.h>
24-
#endif
22+
#include <sys/utime.h>
2523
#include "win32/ipc.h"
2624

2725
struct ipc_perm {

ext/intl/uchar/uchar.c

Lines changed: 94 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,53 @@
88

99
#define IC_METHOD(mname) PHP_METHOD(IntlChar, mname)
1010

11-
static inline int convert_cp(UChar32* pcp, zval *zcp) {
12-
zend_long cp = -1;
13-
14-
if (Z_TYPE_P(zcp) == IS_LONG) {
15-
cp = Z_LVAL_P(zcp);
16-
} else if (Z_TYPE_P(zcp) == IS_STRING) {
11+
static inline int convert_cp(UChar32* pcp, zend_string *string_codepoint, zend_long int_codepoint) {
12+
if (string_codepoint != NULL) {
1713
int32_t i = 0;
18-
size_t zcp_len = Z_STRLEN_P(zcp);
14+
size_t string_codepoint_length = ZSTR_LEN(string_codepoint);
1915

20-
if (ZEND_SIZE_T_INT_OVFL(zcp_len)) {
16+
if (ZEND_SIZE_T_INT_OVFL(string_codepoint_length)) {
2117
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
2218
intl_error_set_custom_msg(NULL, "Input string is too long.", 0);
2319
return FAILURE;
2420
}
2521

26-
U8_NEXT(Z_STRVAL_P(zcp), i, zcp_len, cp);
27-
if ((size_t)i != zcp_len) {
22+
U8_NEXT(ZSTR_VAL(string_codepoint), i, string_codepoint_length, int_codepoint);
23+
if ((size_t)i != string_codepoint_length) {
2824
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
2925
intl_error_set_custom_msg(NULL, "Passing a UTF-8 character for codepoint requires a string which is exactly one UTF-8 codepoint long.", 0);
3026
return FAILURE;
3127
}
32-
} else {
33-
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
34-
intl_error_set_custom_msg(NULL, "Invalid parameter for unicode point. Must be either integer or UTF-8 sequence.", 0);
35-
return FAILURE;
3628
}
37-
if ((cp < UCHAR_MIN_VALUE) || (cp > UCHAR_MAX_VALUE)) {
29+
30+
if ((int_codepoint < UCHAR_MIN_VALUE) || (int_codepoint > UCHAR_MAX_VALUE)) {
3831
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
3932
intl_error_set_custom_msg(NULL, "Codepoint out of range", 0);
4033
return FAILURE;
4134
}
42-
*pcp = (UChar32)cp;
35+
*pcp = (UChar32)int_codepoint;
4336
return SUCCESS;
4437
}
4538

39+
static zend_never_inline int parse_code_point_param(INTERNAL_FUNCTION_PARAMETERS, UChar32 *cp) {
40+
zend_string *string_codepoint;
41+
zend_long int_codepoint;
42+
ZEND_PARSE_PARAMETERS_START(1, 1)
43+
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
44+
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
45+
return convert_cp(cp, string_codepoint, int_codepoint);
46+
}
47+
4648
/* {{{ proto string IntlChar::chr(int|string $codepoint)
4749
* Converts a numeric codepoint to UTF-8
4850
* Acts as an identify function when given a valid UTF-8 encoded codepoint
4951
*/
5052
IC_METHOD(chr) {
5153
UChar32 cp;
52-
zval *zcp;
5354
char buffer[5];
5455
int buffer_len = 0;
5556

56-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) {
57-
RETURN_THROWS();
58-
}
59-
60-
if (convert_cp(&cp, zcp) == FAILURE) {
57+
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
6158
RETURN_NULL();
6259
}
6360

@@ -76,13 +73,8 @@ IC_METHOD(chr) {
7673
*/
7774
IC_METHOD(ord) {
7875
UChar32 cp;
79-
zval *zcp;
8076

81-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) {
82-
RETURN_THROWS();
83-
}
84-
85-
if (convert_cp(&cp, zcp) == FAILURE) {
77+
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
8678
RETURN_NULL();
8779
}
8880

@@ -94,13 +86,15 @@ IC_METHOD(ord) {
9486
IC_METHOD(hasBinaryProperty) {
9587
UChar32 cp;
9688
zend_long prop;
97-
zval *zcp;
89+
zend_string *string_codepoint;
90+
zend_long int_codepoint;
9891

99-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zl", &zcp, &prop) == FAILURE) {
100-
RETURN_THROWS();
101-
}
92+
ZEND_PARSE_PARAMETERS_START(2, 2)
93+
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
94+
Z_PARAM_LONG(prop)
95+
ZEND_PARSE_PARAMETERS_END();
10296

103-
if (convert_cp(&cp, zcp) == FAILURE) {
97+
if (convert_cp(&cp, string_codepoint, int_codepoint) == FAILURE) {
10498
RETURN_NULL();
10599
}
106100

@@ -112,13 +106,15 @@ IC_METHOD(hasBinaryProperty) {
112106
IC_METHOD(getIntPropertyValue) {
113107
UChar32 cp;
114108
zend_long prop;
115-
zval *zcp;
109+
zend_string *string_codepoint;
110+
zend_long int_codepoint;
116111

117-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zl", &zcp, &prop) == FAILURE) {
118-
RETURN_THROWS();
119-
}
112+
ZEND_PARSE_PARAMETERS_START(2, 2)
113+
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
114+
Z_PARAM_LONG(prop)
115+
ZEND_PARSE_PARAMETERS_END();
120116

121-
if (convert_cp(&cp, zcp) == FAILURE) {
117+
if (convert_cp(&cp, string_codepoint, int_codepoint) == FAILURE) {
122118
RETURN_NULL();
123119
}
124120

@@ -153,13 +149,8 @@ IC_METHOD(getIntPropertyMaxValue) {
153149
/* {{{ proto float IntlChar::getNumericValue(int|string $codepoint) */
154150
IC_METHOD(getNumericValue) {
155151
UChar32 cp;
156-
zval *zcp;
157-
158-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) {
159-
RETURN_THROWS();
160-
}
161152

162-
if (convert_cp(&cp, zcp) == FAILURE) {
153+
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
163154
RETURN_NULL();
164155
}
165156

@@ -173,8 +164,7 @@ typedef struct _enumCharType_data {
173164
zend_fcall_info_cache fci_cache;
174165
} enumCharType_data;
175166
static UBool enumCharType_callback(enumCharType_data *context,
176-
UChar32 start, UChar32 limit,
177-
UCharCategory type) {
167+
UChar32 start, UChar32 limit, UCharCategory type) {
178168
zval retval;
179169
zval args[3];
180170

@@ -212,13 +202,8 @@ IC_METHOD(enumCharTypes) {
212202
/* {{{ proto int IntlChar::getBlockCode(int|string $codepoint) */
213203
IC_METHOD(getBlockCode) {
214204
UChar32 cp;
215-
zval *zcp;
216205

217-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) {
218-
RETURN_THROWS();
219-
}
220-
221-
if (convert_cp(&cp, zcp) == FAILURE) {
206+
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
222207
RETURN_NULL();
223208
}
224209

@@ -229,17 +214,20 @@ IC_METHOD(getBlockCode) {
229214
/* {{{ proto string IntlChar::charName(int|string $codepoint, int $nameChoice = IntlChar::UNICODE_CHAR_NAME) */
230215
IC_METHOD(charName) {
231216
UChar32 cp;
232-
zval *zcp;
217+
zend_string *string_codepoint;
218+
zend_long int_codepoint;
233219
UErrorCode error = U_ZERO_ERROR;
234220
zend_long nameChoice = U_UNICODE_CHAR_NAME;
235221
zend_string *buffer = NULL;
236222
int32_t buffer_len;
237223

238-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &zcp, &nameChoice) == FAILURE) {
239-
RETURN_THROWS();
240-
}
224+
ZEND_PARSE_PARAMETERS_START(1, 2)
225+
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
226+
Z_PARAM_OPTIONAL
227+
Z_PARAM_LONG(nameChoice)
228+
ZEND_PARSE_PARAMETERS_END();
241229

242-
if (convert_cp(&cp, zcp) == FAILURE) {
230+
if (convert_cp(&cp, string_codepoint, int_codepoint) == FAILURE) {
243231
RETURN_NULL();
244232
}
245233

@@ -279,8 +267,8 @@ typedef struct _enumCharNames_data {
279267
zend_fcall_info_cache fci_cache;
280268
} enumCharNames_data;
281269
static UBool enumCharNames_callback(enumCharNames_data *context,
282-
UChar32 code, UCharNameChoice nameChoice,
283-
const char *name, int32_t length) {
270+
UChar32 code, UCharNameChoice nameChoice,
271+
const char *name, int32_t length) {
284272
zval retval;
285273
zval args[3];
286274

@@ -306,16 +294,22 @@ static UBool enumCharNames_callback(enumCharNames_data *context,
306294
}
307295
IC_METHOD(enumCharNames) {
308296
UChar32 start, limit;
309-
zval *zstart, *zlimit;
297+
zend_string *string_start, *string_limit;
298+
zend_long int_start, int_limit;
310299
enumCharNames_data context;
311300
zend_long nameChoice = U_UNICODE_CHAR_NAME;
312301
UErrorCode error = U_ZERO_ERROR;
313302

314-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzf|l", &zstart, &zlimit, &context.fci, &context.fci_cache, &nameChoice) == FAILURE) {
315-
RETURN_THROWS();
316-
}
317303

318-
if (convert_cp(&start, zstart) == FAILURE || convert_cp(&limit, zlimit) == FAILURE) {
304+
ZEND_PARSE_PARAMETERS_START(3, 4)
305+
Z_PARAM_STR_OR_LONG(string_start, int_start)
306+
Z_PARAM_STR_OR_LONG(string_limit, int_limit)
307+
Z_PARAM_FUNC(context.fci, context.fci_cache)
308+
Z_PARAM_OPTIONAL
309+
Z_PARAM_LONG(nameChoice)
310+
ZEND_PARSE_PARAMETERS_END();
311+
312+
if (convert_cp(&start, string_start, int_start) == FAILURE || convert_cp(&limit, string_limit, int_limit) == FAILURE) {
319313
RETURN_NULL();
320314
}
321315

@@ -395,19 +389,21 @@ IC_METHOD(getPropertyValueEnum) {
395389
/* {{{ proto int|string IntlChar::foldCase(int|string $codepoint, int $options = IntlChar::FOLD_CASE_DEFAULT) */
396390
IC_METHOD(foldCase) {
397391
UChar32 cp, ret;
398-
zval *zcp;
399392
zend_long options = U_FOLD_CASE_DEFAULT;
393+
zend_string *string_codepoint;
394+
zend_long int_codepoint;
400395

401-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &zcp, &options) == FAILURE) {
402-
RETURN_THROWS();
403-
}
396+
ZEND_PARSE_PARAMETERS_START(2, 2)
397+
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
398+
Z_PARAM_LONG(options)
399+
ZEND_PARSE_PARAMETERS_END();
404400

405-
if (convert_cp(&cp, zcp) == FAILURE) {
401+
if (convert_cp(&cp, string_codepoint, int_codepoint) == FAILURE) {
406402
RETURN_NULL();
407403
}
408404

409405
ret = u_foldCase(cp, options);
410-
if (Z_TYPE_P(zcp) == IS_STRING) {
406+
if (string_codepoint != NULL) {
411407
char buffer[5];
412408
int buffer_len = 0;
413409
U8_APPEND_UNSAFE(buffer, buffer_len, ret);
@@ -422,15 +418,18 @@ IC_METHOD(foldCase) {
422418
/* {{{ proto int IntlChar::digit(int|string $codepoint[, int $radix = 10]) */
423419
IC_METHOD(digit) {
424420
UChar32 cp;
425-
zval *zcp;
426421
zend_long radix = 10;
427422
int ret;
423+
zend_string *string_codepoint;
424+
zend_long int_codepoint;
428425

429-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &zcp, &radix) == FAILURE) {
430-
RETURN_THROWS();
431-
}
426+
ZEND_PARSE_PARAMETERS_START(1, 2)
427+
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
428+
Z_PARAM_OPTIONAL
429+
Z_PARAM_LONG(radix)
430+
ZEND_PARSE_PARAMETERS_END();
432431

433-
if (convert_cp(&cp, zcp) == FAILURE) {
432+
if (convert_cp(&cp, string_codepoint, int_codepoint) == FAILURE) {
434433
RETURN_NULL();
435434
}
436435

@@ -459,15 +458,10 @@ IC_METHOD(forDigit) {
459458
/* {{{ proto array IntlChar::charAge(int|string $codepoint) */
460459
IC_METHOD(charAge) {
461460
UChar32 cp;
462-
zval *zcp;
463461
UVersionInfo version;
464462
int i;
465463

466-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) {
467-
RETURN_THROWS();
468-
}
469-
470-
if (convert_cp(&cp, zcp) == FAILURE) {
464+
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
471465
RETURN_NULL();
472466
}
473467

@@ -499,17 +493,12 @@ IC_METHOD(getUnicodeVersion) {
499493
/* {{{ proto string IntlChar::getFC_NFKC_Closure(int|string $codepoint) */
500494
IC_METHOD(getFC_NFKC_Closure) {
501495
UChar32 cp;
502-
zval *zcp;
503496
UChar *closure;
504497
zend_string *u8str;
505498
int32_t closure_len;
506499
UErrorCode error = U_ZERO_ERROR;
507500

508-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) {
509-
RETURN_THROWS();
510-
}
511-
512-
if (convert_cp(&cp, zcp) == FAILURE) {
501+
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
513502
RETURN_NULL();
514503
}
515504

@@ -536,9 +525,10 @@ IC_METHOD(getFC_NFKC_Closure) {
536525
/* {{{ proto bool IntlChar::<name>(int|string $codepoint) */
537526
#define IC_BOOL_METHOD_CHAR(name) \
538527
IC_METHOD(name) { \
539-
UChar32 cp; zval *zcp; \
540-
if ((zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) || \
541-
(convert_cp(&cp, zcp) == FAILURE)) { return; } \
528+
UChar32 cp; \
529+
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) { \
530+
RETURN_NULL(); \
531+
} \
542532
RETURN_BOOL(u_##name(cp)); \
543533
}
544534
IC_BOOL_METHOD_CHAR(isUAlphabetic)
@@ -575,9 +565,10 @@ IC_BOOL_METHOD_CHAR(isJavaIDPart)
575565
/* {{{ proto int IntlChar::<name>(int|string $codepoint) */
576566
#define IC_INT_METHOD_CHAR(name) \
577567
IC_METHOD(name) { \
578-
UChar32 cp; zval *zcp; \
579-
if ((zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) || \
580-
(convert_cp(&cp, zcp) == FAILURE)) { return; } \
568+
UChar32 cp; \
569+
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) { \
570+
RETURN_NULL(); \
571+
} \
581572
RETURN_LONG(u_##name(cp)); \
582573
}
583574
IC_INT_METHOD_CHAR(charDirection)
@@ -593,11 +584,17 @@ IC_INT_METHOD_CHAR(charDigitValue)
593584
*/
594585
#define IC_CHAR_METHOD_CHAR(name) \
595586
IC_METHOD(name) { \
596-
UChar32 cp, ret; zval *zcp; \
597-
if ((zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) || \
598-
(convert_cp(&cp, zcp) == FAILURE)) { return; } \
587+
UChar32 cp, ret; \
588+
zend_string *string_codepoint; \
589+
zend_long int_codepoint; \
590+
ZEND_PARSE_PARAMETERS_START(1, 1) \
591+
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint) \
592+
ZEND_PARSE_PARAMETERS_END(); \
593+
if (convert_cp(&cp, string_codepoint, int_codepoint) == FAILURE) { \
594+
RETURN_NULL(); \
595+
} \
599596
ret = u_##name(cp); \
600-
if (Z_TYPE_P(zcp) == IS_STRING) { \
597+
if (string_codepoint != NULL) { \
601598
char buffer[5]; \
602599
int buffer_len = 0; \
603600
U8_APPEND_UNSAFE(buffer, buffer_len, ret); \

0 commit comments

Comments
 (0)