1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Zend: Use return true / return false for functions returning bool

Changes done with Coccinelle:

    @r1@
    identifier fn;
    typedef bool;
    symbol false;
    symbol true;
    @@

    bool fn ( ... )
    {
    <...
    return
    (
    - 0
    + false
    |
    - 1
    + true
    )
    ;
    ...>
    }

Coccinelle patch sourced from
torvalds/linux@46b5c9b856.
This commit is contained in:
Tim Düsterhus
2025-09-23 23:03:39 +02:00
committed by Tim Düsterhus
parent 0b4ba560ce
commit ef1b5ae61b
10 changed files with 47 additions and 47 deletions

View File

@@ -910,7 +910,7 @@ static bool php_auto_globals_create_globals(zend_string *name) /* {{{ */
{
/* While we keep registering $GLOBALS as an auto-global, we do not create an
* actual variable for it. Access to it handled specially by the compiler. */
return 0;
return false;
}
/* }}} */

View File

@@ -2627,7 +2627,7 @@ ZEND_API bool is_zend_mm(void)
#if ZEND_MM_CUSTOM
return !AG(mm_heap)->use_custom_heap;
#else
return 1;
return true;
#endif
}

View File

@@ -1575,9 +1575,9 @@ static ZEND_COLD bool zend_ast_valid_var_char(char ch)
(c < '0' || c > '9') &&
(c < 'A' || c > 'Z') &&
(c < 'a' || c > 'z')) {
return 0;
return false;
}
return 1;
return true;
}
static ZEND_COLD bool zend_ast_valid_var_name(const char *s, size_t len)
@@ -1586,13 +1586,13 @@ static ZEND_COLD bool zend_ast_valid_var_name(const char *s, size_t len)
size_t i;
if (len == 0) {
return 0;
return false;
}
c = (unsigned char)s[0];
if (c != '_' && c < 127 &&
(c < 'A' || c > 'Z') &&
(c < 'a' || c > 'z')) {
return 0;
return false;
}
for (i = 1; i < len; i++) {
c = (unsigned char)s[i];
@@ -1600,10 +1600,10 @@ static ZEND_COLD bool zend_ast_valid_var_name(const char *s, size_t len)
(c < '0' || c > '9') &&
(c < 'A' || c > 'Z') &&
(c < 'a' || c > 'z')) {
return 0;
return false;
}
}
return 1;
return true;
}
static ZEND_COLD bool zend_ast_var_needs_braces(char ch)

View File

@@ -82,7 +82,7 @@ static bool zend_valid_closure_binding(
if (newthis) {
if (func->common.fn_flags & ZEND_ACC_STATIC) {
zend_error(E_WARNING, "Cannot bind an instance to a static closure, this will be an error in PHP 9");
return 0;
return false;
}
if (is_fake_closure && func->common.scope &&
@@ -92,23 +92,23 @@ static bool zend_valid_closure_binding(
ZSTR_VAL(func->common.scope->name),
ZSTR_VAL(func->common.function_name),
ZSTR_VAL(Z_OBJCE_P(newthis)->name));
return 0;
return false;
}
} else if (is_fake_closure && func->common.scope
&& !(func->common.fn_flags & ZEND_ACC_STATIC)) {
zend_error(E_WARNING, "Cannot unbind $this of method, this will be an error in PHP 9");
return 0;
return false;
} else if (!is_fake_closure && !Z_ISUNDEF(closure->this_ptr)
&& (func->common.fn_flags & ZEND_ACC_USES_THIS)) {
zend_error(E_WARNING, "Cannot unbind $this of closure using $this, this will be an error in PHP 9");
return 0;
return false;
}
if (scope && scope != func->common.scope && scope->type == ZEND_INTERNAL_CLASS) {
/* rebinding to internal class is not allowed */
zend_error(E_WARNING, "Cannot bind closure to scope of internal class %s, this will be an error in PHP 9",
ZSTR_VAL(scope->name));
return 0;
return false;
}
if (is_fake_closure && scope != func->common.scope) {
@@ -117,10 +117,10 @@ static bool zend_valid_closure_binding(
} else {
zend_error(E_WARNING, "Cannot rebind scope of closure created from method, this will be an error in PHP 9");
}
return 0;
return false;
}
return 1;
return true;
}
/* }}} */

View File

@@ -93,21 +93,21 @@ static unsigned get_xcr0_eax(void) {
static bool is_avx_supported(void) {
if (!(cpuinfo.ecx & ZEND_CPU_FEATURE_AVX)) {
/* No support for AVX */
return 0;
return false;
}
if (!(cpuinfo.ecx & ZEND_CPU_FEATURE_OSXSAVE)) {
/* The operating system does not support XSAVE. */
return 0;
return false;
}
if ((get_xcr0_eax() & 0x6) != 0x6) {
/* XCR0 SSE and AVX bits must be set. */
return 0;
return false;
}
return 1;
return true;
}
#else
static bool is_avx_supported(void) {
return 0;
return false;
}
#endif

View File

@@ -746,36 +746,36 @@ static bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg)
if (type == IS_LONG) {
zend_string_release(Z_STR_P(arg));
ZVAL_LONG(arg, lval);
return 1;
return true;
}
if (type == IS_DOUBLE) {
zend_string_release(Z_STR_P(arg));
ZVAL_DOUBLE(arg, dval);
return 1;
return true;
}
} else if (zend_parse_arg_long_weak(arg, &lval, 0)) {
zval_ptr_dtor(arg);
ZVAL_LONG(arg, lval);
return 1;
return true;
} else if (UNEXPECTED(EG(exception))) {
return 0;
return false;
}
}
if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, 0)) {
zval_ptr_dtor(arg);
ZVAL_DOUBLE(arg, dval);
return 1;
return true;
}
if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(arg, &str, 0)) {
/* on success "arg" is converted to IS_STRING */
return 1;
return true;
}
if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, 0)) {
zval_ptr_dtor(arg);
ZVAL_BOOL(arg, bval);
return 1;
return true;
}
return 0;
return false;
}
#if ZEND_DEBUG
@@ -800,18 +800,18 @@ static bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask,
/* Pass (uint32_t)-1 as arg_num to indicate to ZPP not to emit any deprecation notice,
* this is needed because the version with side effects also uses 0 (e.g. for typed properties) */
if ((type_mask & MAY_BE_LONG) && zend_parse_arg_long_weak(arg, &lval, (uint32_t)-1)) {
return 1;
return true;
}
if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, (uint32_t)-1)) {
return 1;
return true;
}
if ((type_mask & MAY_BE_STRING) && can_convert_to_string(arg)) {
return 1;
return true;
}
if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, (uint32_t)-1)) {
return 1;
return true;
}
return 0;
return false;
}
#endif

View File

@@ -312,7 +312,7 @@ static zend_class_entry *lookup_class(zend_class_entry *scope, zend_string *name
/* Instanceof that's safe to use on unlinked classes. */
static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_entry *ce2) {
if (ce1 == ce2) {
return 1;
return true;
}
if (ce1->ce_flags & ZEND_ACC_LINKED) {
@@ -331,7 +331,7 @@ static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_en
/* It's not sufficient to only check the parent chain itself, as need to do a full
* recursive instanceof in case the parent interfaces haven't been copied yet. */
if (parent_ce && unlinked_instanceof(parent_ce, ce2)) {
return 1;
return true;
}
}
@@ -342,7 +342,7 @@ static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_en
* check here, as the parent interfaces might not have been fully copied yet. */
for (i = 0; i < ce1->num_interfaces; i++) {
if (unlinked_instanceof(ce1->interfaces[i], ce2)) {
return 1;
return true;
}
}
} else {
@@ -352,19 +352,19 @@ static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_en
ZEND_FETCH_CLASS_ALLOW_UNLINKED | ZEND_FETCH_CLASS_NO_AUTOLOAD);
/* Avoid recursing if class implements itself. */
if (ce && ce != ce1 && unlinked_instanceof(ce, ce2)) {
return 1;
return true;
}
}
}
}
return 0;
return false;
}
static bool zend_type_permits_self(
const zend_type type, const zend_class_entry *scope, zend_class_entry *self) {
if (ZEND_TYPE_FULL_MASK(type) & MAY_BE_OBJECT) {
return 1;
return true;
}
/* Any types that may satisfy self must have already been loaded at this point
@@ -376,11 +376,11 @@ static bool zend_type_permits_self(
zend_string *name = resolve_class_name(scope, ZEND_TYPE_NAME(*single_type));
const zend_class_entry *ce = lookup_class(self, name);
if (ce && unlinked_instanceof(self, ce)) {
return 1;
return true;
}
}
} ZEND_TYPE_FOREACH_END();
return 0;
return false;
}
static void track_class_dependency(zend_class_entry *ce, zend_string *class_name)

View File

@@ -35,7 +35,7 @@ static const char *dummy_encoding_name_getter(const zend_encoding *encoding)
static bool dummy_encoding_lexer_compatibility_checker(const zend_encoding *encoding)
{
return 0;
return false;
}
static const zend_encoding *dummy_encoding_detector(const unsigned char *string, size_t length, const zend_encoding **list, size_t list_size)

View File

@@ -905,14 +905,14 @@ static bool keeps_op1_alive(zend_op *opline) {
|| opline->opcode == ZEND_FETCH_LIST_W
|| opline->opcode == ZEND_COPY_TMP
|| opline->opcode == ZEND_EXT_STMT) {
return 1;
return true;
}
ZEND_ASSERT(opline->opcode != ZEND_FE_FETCH_R
&& opline->opcode != ZEND_FE_FETCH_RW
&& opline->opcode != ZEND_VERIFY_RETURN_TYPE
&& opline->opcode != ZEND_BIND_LEXICAL
&& opline->opcode != ZEND_ROPE_ADD);
return 0;
return false;
}
/* Live ranges must be sorted by increasing start opline */

View File

@@ -237,7 +237,7 @@ static zend_object* zend_weakref_new(zend_class_entry *ce) {
static zend_always_inline bool zend_weakref_find(zend_object *referent, zval *return_value) {
void *tagged_ptr = zend_hash_index_find_ptr(&EG(weakrefs), zend_object_to_weakref_key(referent));
if (!tagged_ptr) {
return 0;
return false;
}
void *ptr = ZEND_WEAKREF_GET_PTR(tagged_ptr);
@@ -247,7 +247,7 @@ static zend_always_inline bool zend_weakref_find(zend_object *referent, zval *re
found_weakref:
wr = ptr;
RETVAL_OBJ_COPY(&wr->std);
return 1;
return true;
}
if (tag == ZEND_WEAKREF_TAG_HT) {
@@ -259,7 +259,7 @@ found_weakref:
} ZEND_HASH_FOREACH_END();
}
return 0;
return false;
}
static zend_always_inline void zend_weakref_create(zend_object *referent, zval *return_value) {