Skip to content

Fix GCC warning when using getThis() in a conditional #13923

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 1 commit into from
Apr 9, 2024
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
3 changes: 2 additions & 1 deletion Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ ZEND_API const char *zend_get_type_by_const(int type);

#define ZEND_THIS (&EX(This))

#define getThis() ((Z_TYPE_P(ZEND_THIS) == IS_OBJECT) ? ZEND_THIS : NULL)
#define hasThis() (Z_TYPE_P(ZEND_THIS) == IS_OBJECT)
#define getThis() (hasThis() ? ZEND_THIS : NULL)
#define ZEND_IS_METHOD_CALL() (EX(func)->common.scope != NULL)

#define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT()
Expand Down
14 changes: 7 additions & 7 deletions ext/intl/calendar/calendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ using icu::Locale;

#define ZEND_VALUE_ERROR_INVALID_FIELD(argument, zpp_arg_position) \
if (argument < 0 || argument >= UCAL_FIELD_COUNT) { \
zend_argument_value_error(getThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \
zend_argument_value_error(hasThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \
"must be a valid field"); \
RETURN_THROWS(); \
}

#define ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(argument, zpp_arg_position) \
if (UNEXPECTED(argument < INT32_MIN || argument > INT32_MAX)) { \
zend_argument_value_error(getThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \
zend_argument_value_error(hasThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \
"must be between %d and %d", INT32_MIN, INT32_MAX); \
RETURN_THROWS(); \
}

#define ZEND_VALUE_ERROR_INVALID_DAY_OF_WEEK(argument, zpp_arg_position) \
if (argument < UCAL_SUNDAY || argument > UCAL_SATURDAY) { \
zend_argument_value_error(getThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \
zend_argument_value_error(hasThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \
"must be a valid day of the week"); \
RETURN_THROWS(); \
}
Expand Down Expand Up @@ -641,7 +641,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_locale)
}

if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) {
zend_argument_value_error(getThis() ? 1 : 2, "must be either Locale::ACTUAL_LOCALE or Locale::VALID_LOCALE");
zend_argument_value_error(hasThis() ? 1 : 2, "must be either Locale::ACTUAL_LOCALE or Locale::VALID_LOCALE");
RETURN_THROWS();
}

Expand Down Expand Up @@ -886,7 +886,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set_minimal_days_in_first_week)

// Use ZEND_VALUE_ERROR_INVALID_DAY_OF_WEEK ?
if (num_days < 1 || num_days > 7) {
zend_argument_value_error(getThis() ? 1 : 2, "must be between 1 and 7");
zend_argument_value_error(hasThis() ? 1 : 2, "must be between 1 and 7");
RETURN_THROWS();
}

Expand Down Expand Up @@ -961,7 +961,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set_repeated_wall_time_option)
}

if (option != UCAL_WALLTIME_FIRST && option != UCAL_WALLTIME_LAST) {
zend_argument_value_error(getThis() ? 1 : 2, "must be either IntlCalendar::WALLTIME_FIRST or "
zend_argument_value_error(hasThis() ? 1 : 2, "must be either IntlCalendar::WALLTIME_FIRST or "
"IntlCalendar::WALLTIME_LAST");
RETURN_THROWS();
}
Expand All @@ -985,7 +985,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set_skipped_wall_time_option)

if (option != UCAL_WALLTIME_FIRST && option != UCAL_WALLTIME_LAST
&& option != UCAL_WALLTIME_NEXT_VALID) {
zend_argument_value_error(getThis() ? 1 : 2, "must be one of IntlCalendar::WALLTIME_FIRST, "
zend_argument_value_error(hasThis() ? 1 : 2, "must be one of IntlCalendar::WALLTIME_FIRST, "
"IntlCalendar::WALLTIME_LAST, or IntlCalendar::WALLTIME_NEXT_VALID");
RETURN_THROWS();
}
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/calendar/gregoriancalendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static void _php_intlgregcal_constructor_body(
} else {
// From date/time (3, 5 or 6 arguments)
for (int i = 0; i < variant; i++) {
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(largs[i], getThis() ? (i-1) : i);
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(largs[i], hasThis() ? (i-1) : i);
}

if (variant == 3) {
Expand Down Expand Up @@ -348,7 +348,7 @@ U_CFUNC PHP_FUNCTION(intlgregcal_is_leap_year)
}

if (UNEXPECTED(year < INT32_MIN || year > INT32_MAX)) {
zend_argument_value_error(getThis() ? 1 : 2, "must be between %d and %d", INT32_MIN, INT32_MAX);
zend_argument_value_error(hasThis() ? 1 : 2, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/intl/formatter/formatter_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ PHP_FUNCTION( numfmt_format )
}
RETURN_THROWS();
default:
zend_argument_value_error(getThis() ? 2 : 3, "must be a NumberFormatter::TYPE_* constant");
zend_argument_value_error(hasThis() ? 2 : 3, "must be a NumberFormatter::TYPE_* constant");
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/intl/formatter/formatter_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ PHP_FUNCTION( numfmt_parse )
}
goto cleanup;
default:
zend_argument_value_error(getThis() ? 2 : 3, "must be a NumberFormatter::TYPE_* constant");
zend_argument_value_error(hasThis() ? 2 : 3, "must be a NumberFormatter::TYPE_* constant");
goto cleanup;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static PHP_GINIT_FUNCTION(mysqli);
} \
}

#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
#define ERROR_ARG_POS(arg_num) (hasThis() ? (arg_num-1) : (arg_num))

static HashTable classes;
static zend_object_handlers mysqli_object_handlers;
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "mysqli_priv.h"
#include "ext/mysqlnd/mysql_float_to_double.h"

#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
#define ERROR_ARG_POS(arg_num) (hasThis() ? (arg_num-1) : (arg_num))

/* {{{ Get number of affected rows in previous MySQL operation */
PHP_FUNCTION(mysqli_affected_rows)
Expand Down Expand Up @@ -157,7 +157,7 @@ PHP_FUNCTION(mysqli_stmt_bind_param)
RETURN_THROWS();
}

RETVAL_BOOL(!mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, getThis() ? 1 : 2));
RETVAL_BOOL(!mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, hasThis() ? 1 : 2));
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/mysqli_nonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "zend_smart_str.h"
#include "php_mysqli_structs.h"
#include "mysqli_priv.h"
#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
#define ERROR_ARG_POS(arg_num) (hasThis() ? (arg_num-1) : (arg_num))

#define SAFE_STR(a) ((a)?a:"")

Expand Down
4 changes: 2 additions & 2 deletions ext/tidy/tidy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ PHP_FUNCTION(tidy_get_opt_doc)
opt = tidyGetOptionByName(obj->ptdoc->doc, optname);

if (!opt) {
zend_argument_value_error(getThis() ? 1 : 2, "is an invalid configuration option, \"%s\" given", optname);
zend_argument_value_error(hasThis() ? 1 : 2, "is an invalid configuration option, \"%s\" given", optname);
RETURN_THROWS();
}

Expand Down Expand Up @@ -1320,7 +1320,7 @@ PHP_FUNCTION(tidy_getopt)
opt = tidyGetOptionByName(obj->ptdoc->doc, optname);

if (!opt) {
zend_argument_value_error(getThis() ? 1 : 2, "is an invalid configuration option, \"%s\" given", optname);
zend_argument_value_error(hasThis() ? 1 : 2, "is an invalid configuration option, \"%s\" given", optname);
RETURN_THROWS();
}

Expand Down
Loading