Skip to content

Commit 0e8d196

Browse files
committed
Address review comments
1 parent aa54bf0 commit 0e8d196

File tree

4 files changed

+13
-30
lines changed

4 files changed

+13
-30
lines changed

Zend/zend_operators.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,6 @@ static const unsigned char tolower_map[256] = {
6666

6767
#define zend_tolower_ascii(c) (tolower_map[(unsigned char)(c)])
6868

69-
/* ctype's isalpha varies based on locale, which is not what we want for many use cases.
70-
* This is what it'd be in the "C" locale. */
71-
ZEND_API const bool zend_isalpha_map[256] = {
72-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
73-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
74-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
75-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
76-
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
77-
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
78-
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
79-
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
80-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
81-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
82-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
83-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
84-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
85-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
86-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
87-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
88-
};
89-
9069
/* ctype's isalnum is isalpha + isdigit(0-9) */
9170
ZEND_API const bool zend_isalnum_map[256] = {
9271
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

Zend/zend_operators.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,15 @@ ZEND_API int ZEND_FASTCALL string_compare_function(zval *op1, zval *op2);
414414
ZEND_API int ZEND_FASTCALL string_case_compare_function(zval *op1, zval *op2);
415415
ZEND_API int ZEND_FASTCALL string_locale_compare_function(zval *op1, zval *op2);
416416

417-
/* NOTE: The locale-independent alternatives to ctype(isalpha/isalnum) were added to fix bugs in php 7.3 patch releases, and should not be used externally until php 8.2 */
418-
ZEND_API extern const bool zend_isalpha_map[256];
417+
/* NOTE: The locale-independent alternatives to ctype(isalpha/isalnum) were added to fix bugs in php 8.0 patch releases, and should not be used externally until php 8.2 */
419418
ZEND_API extern const bool zend_isalnum_map[256];
420419

421-
#define zend_isalpha_ascii(c) (zend_isalpha_map[(unsigned char)(c)])
420+
static zend_always_inline bool zend_isalpha_ascii(unsigned char c) {
421+
/* Returns true for a-z and A-Z in a locale-independent way.
422+
* This is implemented in a way that can avoid branching. Note that ASCII 'a' == 'A' | 0x20. */
423+
c = (c | 0x20) - 'a';
424+
return c <= ('z' - 'a' + 1);
425+
}
422426
#define zend_isalnum_ascii(c) (zend_isalnum_map[(unsigned char)(c)])
423427

424428
ZEND_API void ZEND_FASTCALL zend_str_tolower(char *str, size_t length);

ext/filter/tests/filter_validate_domain_locale.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ FILTER_VALIDATE_DOMAIN FILTER_FLAG_HOSTNAME should not be locale dependent
44
filter
55
--SKIPIF--
66
<?php // try to activate a single-byte german locale
7-
if (!setlocale(LC_ALL, "de_DE")) {
8-
print "skip Can't find german locale";
7+
if (!setlocale(LC_ALL, 'de_DE', 'de_DE.ISO8859-1', 'de_DE.ISO_8859-1')) {
8+
print "skip Can't find german locale\n";
99
}
1010
?>
1111
--FILE--
1212
<?php
1313
var_dump(filter_var('٪', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
14-
setlocale(LC_ALL, "de_DE");
14+
setlocale(LC_ALL, 'de_DE', 'de_DE.ISO8859-1', 'de_DE.ISO_8859-1');
1515
var_dump(filter_var('٪', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
1616
?>
1717
--EXPECT--

ext/standard/tests/streams/locale.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
Stream wrappers should not be locale dependent
33
--SKIPIF--
44
<?php // try to activate a single-byte german locale
5-
if (!setlocale(LC_ALL, "de_DE")) {
6-
print "skip Can't find german locale";
5+
if (!setlocale(LC_ALL, 'de_DE','de_DE.ISO8859-1','de_DE.ISO_8859-1')) {
6+
print "skip Can't find german locale\n";
77
}
88
?>
99
--INI--
1010
allow_url_fopen=1
1111
display_errors=stderr
1212
--FILE--
1313
<?php
14-
setlocale(LC_ALL, "de_DE");
14+
setlocale(LC_ALL, 'de_DE', 'de_DE.ISO8859-1', 'de_DE.ISO_8859-1');
1515
class testwrapper {
1616
}
1717

0 commit comments

Comments
 (0)