Skip to content

Commit

Permalink
Return value from ZEND_ATOL
Browse files Browse the repository at this point in the history
Instead of assigning it as part of the macro itself, which makes
usage quite awkward.
  • Loading branch information
nikic committed Jul 12, 2021
1 parent e081db0 commit efbb219
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 44 deletions.
4 changes: 1 addition & 3 deletions Zend/zend.c
Expand Up @@ -163,9 +163,7 @@ static ZEND_INI_MH(OnUpdateAssertions) /* {{{ */

static ZEND_INI_MH(OnSetExceptionStringParamMaxLen) /* {{{ */
{
zend_long i;

ZEND_ATOL(i, ZSTR_VAL(new_value));
zend_long i = ZEND_ATOL(ZSTR_VAL(new_value));
if (i >= 0 && i <= 1000000) {
EG(exception_string_param_max_len) = i;
return SUCCESS;
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_long.h
Expand Up @@ -61,7 +61,7 @@ typedef int32_t zend_off_t;
# define ZEND_ULONG_FMT_SPEC PRIu64
# ifdef ZEND_WIN32
# define ZEND_LTOA(i, s, len) _i64toa_s((i), (s), (len), 10)
# define ZEND_ATOL(i, s) i = _atoi64((s))
# define ZEND_ATOL(s) _atoi64((s))
# define ZEND_STRTOL(s0, s1, base) _strtoi64((s0), (s1), (base))
# define ZEND_STRTOUL(s0, s1, base) _strtoui64((s0), (s1), (base))
# define ZEND_STRTOL_PTR _strtoi64
Expand All @@ -73,7 +73,7 @@ typedef int32_t zend_off_t;
int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
(s)[st] = '\0'; \
} while (0)
# define ZEND_ATOL(i, s) (i) = atoll((s))
# define ZEND_ATOL(s) atoll((s))
# define ZEND_STRTOL(s0, s1, base) strtoll((s0), (s1), (base))
# define ZEND_STRTOUL(s0, s1, base) strtoull((s0), (s1), (base))
# define ZEND_STRTOL_PTR strtoll
Expand All @@ -90,14 +90,14 @@ typedef int32_t zend_off_t;
# define ZEND_ULONG_FMT_SPEC PRIu32
# ifdef ZEND_WIN32
# define ZEND_LTOA(i, s, len) _ltoa_s((i), (s), (len), 10)
# define ZEND_ATOL(i, s) i = atol((s))
# define ZEND_ATOL(s) atol((s))
# else
# define ZEND_LTOA(i, s, len) \
do { \
int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
(s)[st] = '\0'; \
} while (0)
# define ZEND_ATOL(i, s) (i) = atol((s))
# define ZEND_ATOL(s) atol((s))
# endif
# define ZEND_STRTOL_PTR strtol
# define ZEND_STRTOUL_PTR strtoul
Expand Down
5 changes: 1 addition & 4 deletions ext/ftp/ftp.c
Expand Up @@ -1108,8 +1108,6 @@ ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *i
zend_long
ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len)
{
zend_long res;

if (ftp == NULL) {
return -1;
}
Expand All @@ -1122,8 +1120,7 @@ ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len)
if (!ftp_getresp(ftp) || ftp->resp != 213) {
return -1;
}
ZEND_ATOL(res, ftp->inbuf);
return res;
return ZEND_ATOL(ftp->inbuf);
}
/* }}} */

Expand Down
4 changes: 1 addition & 3 deletions ext/mysqlnd/php_mysqlnd.c
Expand Up @@ -157,9 +157,7 @@ static PHP_GINIT_FUNCTION(mysqlnd)
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateNetCmdBufferSize)
{
zend_long long_value;

ZEND_ATOL(long_value, ZSTR_VAL(new_value));
zend_long long_value = ZEND_ATOL(ZSTR_VAL(new_value));
if (long_value < MYSQLND_NET_CMD_BUFFER_MIN_SIZE) {
return FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_pgsql/pgsql_driver.c
Expand Up @@ -308,7 +308,7 @@ static zend_long pgsql_handle_doer(pdo_dbh_t *dbh, const zend_string *sql)
}
H->pgoid = PQoidValue(res);
if (qs == PGRES_COMMAND_OK) {
ZEND_ATOL(ret, PQcmdTuples(res));
ret = ZEND_ATOL(PQcmdTuples(res));
} else {
ret = Z_L(0);
}
Expand Down
12 changes: 4 additions & 8 deletions ext/pdo_pgsql/pgsql_statement.c
Expand Up @@ -246,7 +246,7 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt)
}

if (status == PGRES_COMMAND_OK) {
ZEND_ATOL(stmt->row_count, PQcmdTuples(S->result));
stmt->row_count = ZEND_ATOL(PQcmdTuples(S->result));
H->pgoid = PQoidValue(S->result);
} else {
stmt->row_count = (zend_long)PQntuples(S->result);
Expand All @@ -272,14 +272,14 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
/* decode name from $1, $2 into 0, 1 etc. */
if (param->name) {
if (ZSTR_VAL(param->name)[0] == '$') {
ZEND_ATOL(param->paramno, ZSTR_VAL(param->name) + 1);
param->paramno = ZEND_ATOL(ZSTR_VAL(param->name) + 1);
} else {
/* resolve parameter name to rewritten name */
zend_string *namevar;

if (stmt->bound_param_map && (namevar = zend_hash_find_ptr(stmt->bound_param_map,
param->name)) != NULL) {
ZEND_ATOL(param->paramno, ZSTR_VAL(namevar) + 1);
param->paramno = ZEND_ATOL(ZSTR_VAL(namevar) + 1);
param->paramno--;
} else {
pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", ZSTR_VAL(param->name));
Expand Down Expand Up @@ -505,12 +505,8 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pd
#if SIZEOF_ZEND_LONG >= 8
case INT8OID:
#endif
{
zend_long intval;
ZEND_ATOL(intval, ptr);
ZVAL_LONG(result, intval);
ZVAL_LONG(result, ZEND_ATOL(ptr));
break;
}

case OIDOID: {
char *end_ptr;
Expand Down
11 changes: 3 additions & 8 deletions main/fastcgi.c
Expand Up @@ -511,21 +511,16 @@ int fcgi_init(void)

str = getenv("_FCGI_SHUTDOWN_EVENT_");
if (str != NULL) {
zend_long ev;
HANDLE shutdown_event;

ZEND_ATOL(ev, str);
shutdown_event = (HANDLE) ev;
zend_long ev = ZEND_ATOL(str);
HANDLE shutdown_event = (HANDLE) ev;
if (!CreateThread(NULL, 0, fcgi_shutdown_thread,
shutdown_event, 0, NULL)) {
return -1;
}
}
str = getenv("_FCGI_MUTEX_");
if (str != NULL) {
zend_long mt;
ZEND_ATOL(mt, str);
fcgi_accept_mutex = (HANDLE) mt;
fcgi_accept_mutex = (HANDLE) ZEND_ATOL(str);
}
return is_fastcgi = 1;
} else {
Expand Down
16 changes: 5 additions & 11 deletions main/main.c
Expand Up @@ -236,9 +236,7 @@ static PHP_INI_MH(OnSetFacility)
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnSetPrecision)
{
zend_long i;

ZEND_ATOL(i, ZSTR_VAL(new_value));
zend_long i = ZEND_ATOL(ZSTR_VAL(new_value));
if (i >= -1) {
EG(precision) = i;
return SUCCESS;
Expand All @@ -251,9 +249,7 @@ static PHP_INI_MH(OnSetPrecision)
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnSetSerializePrecision)
{
zend_long i;

ZEND_ATOL(i, ZSTR_VAL(new_value));
zend_long i = ZEND_ATOL(ZSTR_VAL(new_value));
if (i >= -1) {
PG(serialize_precision) = i;
return SUCCESS;
Expand Down Expand Up @@ -402,11 +398,11 @@ static PHP_INI_MH(OnUpdateTimeout)
{
if (stage==PHP_INI_STAGE_STARTUP) {
/* Don't set a timeout on startup, only per-request */
ZEND_ATOL(EG(timeout_seconds), ZSTR_VAL(new_value));
EG(timeout_seconds) = ZEND_ATOL(ZSTR_VAL(new_value));
return SUCCESS;
}
zend_unset_timeout();
ZEND_ATOL(EG(timeout_seconds), ZSTR_VAL(new_value));
EG(timeout_seconds) = ZEND_ATOL(ZSTR_VAL(new_value));
if (stage != PHP_INI_STAGE_DEACTIVATE) {
/*
* If we're restoring INI values, we shouldn't reset the timer.
Expand All @@ -423,8 +419,6 @@ static PHP_INI_MH(OnUpdateTimeout)
/* {{{ php_get_display_errors_mode() helper function */
static zend_uchar php_get_display_errors_mode(zend_string *value)
{
zend_uchar mode;

if (!value) {
return PHP_DISPLAY_ERRORS_STDOUT;
}
Expand All @@ -446,7 +440,7 @@ static zend_uchar php_get_display_errors_mode(zend_string *value)
return PHP_DISPLAY_ERRORS_STDOUT;
}

ZEND_ATOL(mode, ZSTR_VAL(value));
zend_uchar mode = ZEND_ATOL(ZSTR_VAL(value));
if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
return PHP_DISPLAY_ERRORS_STDOUT;
}
Expand Down
2 changes: 1 addition & 1 deletion sapi/apache2handler/sapi_apache2.c
Expand Up @@ -519,7 +519,7 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx)

content_length = (char *) apr_table_get(r->headers_in, "Content-Length");
if (content_length) {
ZEND_ATOL(SG(request_info).content_length, content_length);
SG(request_info).content_length = ZEND_ATOL(content_length);
} else {
SG(request_info).content_length = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion sapi/cli/php_cli_server.c
Expand Up @@ -2382,7 +2382,7 @@ static void php_cli_server_startup_workers() {
}

#if HAVE_FORK
ZEND_ATOL(php_cli_server_workers_max, workers);
php_cli_server_workers_max = ZEND_ATOL(workers);
if (php_cli_server_workers_max > 1) {
zend_long php_cli_server_worker;

Expand Down

1 comment on commit efbb219

@Girgias
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a changelog entry in UPGRADING.INTERNALS?

Please sign in to comment.