Skip to content

Remove zend_atoi() #7232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,6 @@ static const unsigned char tolower_map[256] = {
zend_binary_strncasecmp
*/

ZEND_API int ZEND_FASTCALL zend_atoi(const char *str, size_t str_len) /* {{{ */
{
int retval;

if (!str_len) {
str_len = strlen(str);
}
retval = ZEND_STRTOL(str, NULL, 0);
if (str_len>0) {
switch (str[str_len-1]) {
case 'g':
case 'G':
retval *= 1024;
ZEND_FALLTHROUGH;
case 'm':
case 'M':
retval *= 1024;
ZEND_FALLTHROUGH;
case 'k':
case 'K':
retval *= 1024;
break;
}
}
return retval;
}
/* }}} */

ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* {{{ */
{
zend_long retval;
Expand Down
1 change: 0 additions & 1 deletion Zend/zend_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ ZEND_API int ZEND_FASTCALL zend_compare_symbol_tables(HashTable *ht1, HashTable
ZEND_API int ZEND_FASTCALL zend_compare_arrays(zval *a1, zval *a2);
ZEND_API int ZEND_FASTCALL zend_compare_objects(zval *o1, zval *o2);

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

#define convert_to_null_ex(zv) convert_to_null(zv)
Expand Down
11 changes: 6 additions & 5 deletions ext/ffi/tests/bug78270_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FR #78270 (Usage of __vectorcall convention with FFI)
--EXTENSIONS--
ffi
zend_test
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only");
Expand All @@ -14,8 +15,8 @@ if (preg_match('/Compiler => .*clang.*/', $info)) die("skip not for clang");

try {
FFI::cdef(<<<EOC
__vectorcall int zend_atoi(const char *str, size_t str_len);
EOC, ffi_get_php_dll_name());
__vectorcall int bug78270(const char *str, size_t str_len);
EOC, "php_zend_test.dll");
} catch (FFI\ParserException $ex) {
die('skip __vectorcall not supported');
}
Expand All @@ -24,9 +25,9 @@ try {
<?php
require_once('utils.inc');
$ffi = FFI::cdef(<<<EOC
__vectorcall int zend_atoi(const char *str, size_t str_len);
EOC, ffi_get_php_dll_name());
var_dump($ffi->zend_atoi("17.4", 4));
__vectorcall int bug78270(const char *str, size_t str_len);
EOC, "php_zend_test.dll");
var_dump($ffi->bug78270("17.4", 4));
?>
--EXPECT--
int(17)
5 changes: 3 additions & 2 deletions ext/ffi/tests/bug78270_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
FR #78270 (Usage of __vectorcall convention with FFI)
--EXTENSIONS--
ffi
zend_test
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only");

require_once('utils.inc');
try {
FFI::cdef(<<<EOC
__vectorcall int zend_atoi(const char *str, size_t str_len);
EOC, ffi_get_php_dll_name());
__vectorcall int bug78270(const char *str, size_t str_len);
EOC, "php_zend_test.dll");
} catch (FFI\ParserException $ex) {
die('skip __vectorcall not supported');
}
Expand Down
2 changes: 2 additions & 0 deletions ext/zend_test/php_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ struct bug79096 {
# define PHP_ZEND_TEST_API
#endif

PHP_ZEND_TEST_API int ZEND_FASTCALL bug78270(const char *str, size_t str_len);

PHP_ZEND_TEST_API struct bug79096 bug79096(void);
PHP_ZEND_TEST_API void bug79532(off_t *array, size_t elems);

Expand Down
6 changes: 6 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ ZEND_TSRMLS_CACHE_DEFINE()
ZEND_GET_MODULE(zend_test)
#endif

/* The important part here is the ZEND_FASTCALL. */
PHP_ZEND_TEST_API int ZEND_FASTCALL bug78270(const char *str, size_t str_len)
{
return (int) zend_atol(str, str_len);
}

PHP_ZEND_TEST_API struct bug79096 bug79096(void)
{
struct bug79096 b;
Expand Down
2 changes: 1 addition & 1 deletion ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression)
} else if (zend_string_equals_literal_ci(new_value, "on")) {
int_value = 1;
} else {
int_value = zend_atoi(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
int_value = (int) zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
}
ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0);

Expand Down