Skip to content

Commit 1cba776

Browse files
nikiccmb69
andauthored
Remove zend_atoi() (#7232)
It's the same as (int) zend_atol() -- it doesn't try to do anything integer size specific. Canonicalize to one function in preparation for renaming zend_atol() to something less misleading. FFI test is adjusted to use a zend_test function. It just calls zend_atol() internally, but could really be anything. Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
1 parent 497858a commit 1cba776

File tree

7 files changed

+18
-37
lines changed

7 files changed

+18
-37
lines changed

Zend/zend_operators.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,34 +91,6 @@ static const unsigned char tolower_map[256] = {
9191
zend_binary_strncasecmp
9292
*/
9393

94-
ZEND_API int ZEND_FASTCALL zend_atoi(const char *str, size_t str_len) /* {{{ */
95-
{
96-
int retval;
97-
98-
if (!str_len) {
99-
str_len = strlen(str);
100-
}
101-
retval = ZEND_STRTOL(str, NULL, 0);
102-
if (str_len>0) {
103-
switch (str[str_len-1]) {
104-
case 'g':
105-
case 'G':
106-
retval *= 1024;
107-
ZEND_FALLTHROUGH;
108-
case 'm':
109-
case 'M':
110-
retval *= 1024;
111-
ZEND_FALLTHROUGH;
112-
case 'k':
113-
case 'K':
114-
retval *= 1024;
115-
break;
116-
}
117-
}
118-
return retval;
119-
}
120-
/* }}} */
121-
12294
ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* {{{ */
12395
{
12496
zend_long retval;

Zend/zend_operators.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ ZEND_API int ZEND_FASTCALL zend_compare_symbol_tables(HashTable *ht1, HashTable
458458
ZEND_API int ZEND_FASTCALL zend_compare_arrays(zval *a1, zval *a2);
459459
ZEND_API int ZEND_FASTCALL zend_compare_objects(zval *o1, zval *o2);
460460

461-
ZEND_API int ZEND_FASTCALL zend_atoi(const char *str, size_t str_len);
462461
ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len);
463462

464463
#define convert_to_null_ex(zv) convert_to_null(zv)

ext/ffi/tests/bug78270_1.phpt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
FR #78270 (Usage of __vectorcall convention with FFI)
33
--EXTENSIONS--
44
ffi
5+
zend_test
56
--SKIPIF--
67
<?php
78
if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only");
@@ -14,8 +15,8 @@ if (preg_match('/Compiler => .*clang.*/', $info)) die("skip not for clang");
1415

1516
try {
1617
FFI::cdef(<<<EOC
17-
__vectorcall int zend_atoi(const char *str, size_t str_len);
18-
EOC, ffi_get_php_dll_name());
18+
__vectorcall int bug78270(const char *str, size_t str_len);
19+
EOC, "php_zend_test.dll");
1920
} catch (FFI\ParserException $ex) {
2021
die('skip __vectorcall not supported');
2122
}
@@ -24,9 +25,9 @@ try {
2425
<?php
2526
require_once('utils.inc');
2627
$ffi = FFI::cdef(<<<EOC
27-
__vectorcall int zend_atoi(const char *str, size_t str_len);
28-
EOC, ffi_get_php_dll_name());
29-
var_dump($ffi->zend_atoi("17.4", 4));
28+
__vectorcall int bug78270(const char *str, size_t str_len);
29+
EOC, "php_zend_test.dll");
30+
var_dump($ffi->bug78270("17.4", 4));
3031
?>
3132
--EXPECT--
3233
int(17)

ext/ffi/tests/bug78270_2.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
FR #78270 (Usage of __vectorcall convention with FFI)
33
--EXTENSIONS--
44
ffi
5+
zend_test
56
--SKIPIF--
67
<?php
78
if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only");
89

910
require_once('utils.inc');
1011
try {
1112
FFI::cdef(<<<EOC
12-
__vectorcall int zend_atoi(const char *str, size_t str_len);
13-
EOC, ffi_get_php_dll_name());
13+
__vectorcall int bug78270(const char *str, size_t str_len);
14+
EOC, "php_zend_test.dll");
1415
} catch (FFI\ParserException $ex) {
1516
die('skip __vectorcall not supported');
1617
}

ext/zend_test/php_test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct bug79096 {
6767
# define PHP_ZEND_TEST_API
6868
#endif
6969

70+
PHP_ZEND_TEST_API int ZEND_FASTCALL bug78270(const char *str, size_t str_len);
71+
7072
PHP_ZEND_TEST_API struct bug79096 bug79096(void);
7173
PHP_ZEND_TEST_API void bug79532(off_t *array, size_t elems);
7274

ext/zend_test/test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,12 @@ ZEND_TSRMLS_CACHE_DEFINE()
469469
ZEND_GET_MODULE(zend_test)
470470
#endif
471471

472+
/* The important part here is the ZEND_FASTCALL. */
473+
PHP_ZEND_TEST_API int ZEND_FASTCALL bug78270(const char *str, size_t str_len)
474+
{
475+
return (int) zend_atol(str, str_len);
476+
}
477+
472478
PHP_ZEND_TEST_API struct bug79096 bug79096(void)
473479
{
474480
struct bug79096 b;

ext/zlib/zlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression)
12781278
} else if (zend_string_equals_literal_ci(new_value, "on")) {
12791279
int_value = 1;
12801280
} else {
1281-
int_value = zend_atoi(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
1281+
int_value = (int) zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
12821282
}
12831283
ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0);
12841284

0 commit comments

Comments
 (0)