Skip to content

Commit ef1b5ae

Browse files
committed
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@46b5c9b.
1 parent 0b4ba56 commit ef1b5ae

File tree

10 files changed

+47
-47
lines changed

10 files changed

+47
-47
lines changed

Zend/zend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ static bool php_auto_globals_create_globals(zend_string *name) /* {{{ */
910910
{
911911
/* While we keep registering $GLOBALS as an auto-global, we do not create an
912912
* actual variable for it. Access to it handled specially by the compiler. */
913-
return 0;
913+
return false;
914914
}
915915
/* }}} */
916916

Zend/zend_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,7 @@ ZEND_API bool is_zend_mm(void)
26272627
#if ZEND_MM_CUSTOM
26282628
return !AG(mm_heap)->use_custom_heap;
26292629
#else
2630-
return 1;
2630+
return true;
26312631
#endif
26322632
}
26332633

Zend/zend_ast.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,9 +1575,9 @@ static ZEND_COLD bool zend_ast_valid_var_char(char ch)
15751575
(c < '0' || c > '9') &&
15761576
(c < 'A' || c > 'Z') &&
15771577
(c < 'a' || c > 'z')) {
1578-
return 0;
1578+
return false;
15791579
}
1580-
return 1;
1580+
return true;
15811581
}
15821582

15831583
static ZEND_COLD bool zend_ast_valid_var_name(const char *s, size_t len)
@@ -1586,24 +1586,24 @@ static ZEND_COLD bool zend_ast_valid_var_name(const char *s, size_t len)
15861586
size_t i;
15871587

15881588
if (len == 0) {
1589-
return 0;
1589+
return false;
15901590
}
15911591
c = (unsigned char)s[0];
15921592
if (c != '_' && c < 127 &&
15931593
(c < 'A' || c > 'Z') &&
15941594
(c < 'a' || c > 'z')) {
1595-
return 0;
1595+
return false;
15961596
}
15971597
for (i = 1; i < len; i++) {
15981598
c = (unsigned char)s[i];
15991599
if (c != '_' && c < 127 &&
16001600
(c < '0' || c > '9') &&
16011601
(c < 'A' || c > 'Z') &&
16021602
(c < 'a' || c > 'z')) {
1603-
return 0;
1603+
return false;
16041604
}
16051605
}
1606-
return 1;
1606+
return true;
16071607
}
16081608

16091609
static ZEND_COLD bool zend_ast_var_needs_braces(char ch)

Zend/zend_closures.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static bool zend_valid_closure_binding(
8282
if (newthis) {
8383
if (func->common.fn_flags & ZEND_ACC_STATIC) {
8484
zend_error(E_WARNING, "Cannot bind an instance to a static closure, this will be an error in PHP 9");
85-
return 0;
85+
return false;
8686
}
8787

8888
if (is_fake_closure && func->common.scope &&
@@ -92,23 +92,23 @@ static bool zend_valid_closure_binding(
9292
ZSTR_VAL(func->common.scope->name),
9393
ZSTR_VAL(func->common.function_name),
9494
ZSTR_VAL(Z_OBJCE_P(newthis)->name));
95-
return 0;
95+
return false;
9696
}
9797
} else if (is_fake_closure && func->common.scope
9898
&& !(func->common.fn_flags & ZEND_ACC_STATIC)) {
9999
zend_error(E_WARNING, "Cannot unbind $this of method, this will be an error in PHP 9");
100-
return 0;
100+
return false;
101101
} else if (!is_fake_closure && !Z_ISUNDEF(closure->this_ptr)
102102
&& (func->common.fn_flags & ZEND_ACC_USES_THIS)) {
103103
zend_error(E_WARNING, "Cannot unbind $this of closure using $this, this will be an error in PHP 9");
104-
return 0;
104+
return false;
105105
}
106106

107107
if (scope && scope != func->common.scope && scope->type == ZEND_INTERNAL_CLASS) {
108108
/* rebinding to internal class is not allowed */
109109
zend_error(E_WARNING, "Cannot bind closure to scope of internal class %s, this will be an error in PHP 9",
110110
ZSTR_VAL(scope->name));
111-
return 0;
111+
return false;
112112
}
113113

114114
if (is_fake_closure && scope != func->common.scope) {
@@ -117,10 +117,10 @@ static bool zend_valid_closure_binding(
117117
} else {
118118
zend_error(E_WARNING, "Cannot rebind scope of closure created from method, this will be an error in PHP 9");
119119
}
120-
return 0;
120+
return false;
121121
}
122122

123-
return 1;
123+
return true;
124124
}
125125
/* }}} */
126126

Zend/zend_cpuinfo.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,21 @@ static unsigned get_xcr0_eax(void) {
9393
static bool is_avx_supported(void) {
9494
if (!(cpuinfo.ecx & ZEND_CPU_FEATURE_AVX)) {
9595
/* No support for AVX */
96-
return 0;
96+
return false;
9797
}
9898
if (!(cpuinfo.ecx & ZEND_CPU_FEATURE_OSXSAVE)) {
9999
/* The operating system does not support XSAVE. */
100-
return 0;
100+
return false;
101101
}
102102
if ((get_xcr0_eax() & 0x6) != 0x6) {
103103
/* XCR0 SSE and AVX bits must be set. */
104-
return 0;
104+
return false;
105105
}
106-
return 1;
106+
return true;
107107
}
108108
#else
109109
static bool is_avx_supported(void) {
110-
return 0;
110+
return false;
111111
}
112112
#endif
113113

Zend/zend_execute.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -746,36 +746,36 @@ static bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg)
746746
if (type == IS_LONG) {
747747
zend_string_release(Z_STR_P(arg));
748748
ZVAL_LONG(arg, lval);
749-
return 1;
749+
return true;
750750
}
751751
if (type == IS_DOUBLE) {
752752
zend_string_release(Z_STR_P(arg));
753753
ZVAL_DOUBLE(arg, dval);
754-
return 1;
754+
return true;
755755
}
756756
} else if (zend_parse_arg_long_weak(arg, &lval, 0)) {
757757
zval_ptr_dtor(arg);
758758
ZVAL_LONG(arg, lval);
759-
return 1;
759+
return true;
760760
} else if (UNEXPECTED(EG(exception))) {
761-
return 0;
761+
return false;
762762
}
763763
}
764764
if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, 0)) {
765765
zval_ptr_dtor(arg);
766766
ZVAL_DOUBLE(arg, dval);
767-
return 1;
767+
return true;
768768
}
769769
if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(arg, &str, 0)) {
770770
/* on success "arg" is converted to IS_STRING */
771-
return 1;
771+
return true;
772772
}
773773
if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, 0)) {
774774
zval_ptr_dtor(arg);
775775
ZVAL_BOOL(arg, bval);
776-
return 1;
776+
return true;
777777
}
778-
return 0;
778+
return false;
779779
}
780780

781781
#if ZEND_DEBUG
@@ -800,18 +800,18 @@ static bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask,
800800
/* Pass (uint32_t)-1 as arg_num to indicate to ZPP not to emit any deprecation notice,
801801
* this is needed because the version with side effects also uses 0 (e.g. for typed properties) */
802802
if ((type_mask & MAY_BE_LONG) && zend_parse_arg_long_weak(arg, &lval, (uint32_t)-1)) {
803-
return 1;
803+
return true;
804804
}
805805
if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, (uint32_t)-1)) {
806-
return 1;
806+
return true;
807807
}
808808
if ((type_mask & MAY_BE_STRING) && can_convert_to_string(arg)) {
809-
return 1;
809+
return true;
810810
}
811811
if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, (uint32_t)-1)) {
812-
return 1;
812+
return true;
813813
}
814-
return 0;
814+
return false;
815815
}
816816
#endif
817817

Zend/zend_inheritance.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static zend_class_entry *lookup_class(zend_class_entry *scope, zend_string *name
312312
/* Instanceof that's safe to use on unlinked classes. */
313313
static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_entry *ce2) {
314314
if (ce1 == ce2) {
315-
return 1;
315+
return true;
316316
}
317317

318318
if (ce1->ce_flags & ZEND_ACC_LINKED) {
@@ -331,7 +331,7 @@ static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_en
331331
/* It's not sufficient to only check the parent chain itself, as need to do a full
332332
* recursive instanceof in case the parent interfaces haven't been copied yet. */
333333
if (parent_ce && unlinked_instanceof(parent_ce, ce2)) {
334-
return 1;
334+
return true;
335335
}
336336
}
337337

@@ -342,7 +342,7 @@ static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_en
342342
* check here, as the parent interfaces might not have been fully copied yet. */
343343
for (i = 0; i < ce1->num_interfaces; i++) {
344344
if (unlinked_instanceof(ce1->interfaces[i], ce2)) {
345-
return 1;
345+
return true;
346346
}
347347
}
348348
} else {
@@ -352,19 +352,19 @@ static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_en
352352
ZEND_FETCH_CLASS_ALLOW_UNLINKED | ZEND_FETCH_CLASS_NO_AUTOLOAD);
353353
/* Avoid recursing if class implements itself. */
354354
if (ce && ce != ce1 && unlinked_instanceof(ce, ce2)) {
355-
return 1;
355+
return true;
356356
}
357357
}
358358
}
359359
}
360360

361-
return 0;
361+
return false;
362362
}
363363

364364
static bool zend_type_permits_self(
365365
const zend_type type, const zend_class_entry *scope, zend_class_entry *self) {
366366
if (ZEND_TYPE_FULL_MASK(type) & MAY_BE_OBJECT) {
367-
return 1;
367+
return true;
368368
}
369369

370370
/* Any types that may satisfy self must have already been loaded at this point
@@ -376,11 +376,11 @@ static bool zend_type_permits_self(
376376
zend_string *name = resolve_class_name(scope, ZEND_TYPE_NAME(*single_type));
377377
const zend_class_entry *ce = lookup_class(self, name);
378378
if (ce && unlinked_instanceof(self, ce)) {
379-
return 1;
379+
return true;
380380
}
381381
}
382382
} ZEND_TYPE_FOREACH_END();
383-
return 0;
383+
return false;
384384
}
385385

386386
static void track_class_dependency(zend_class_entry *ce, zend_string *class_name)

Zend/zend_multibyte.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static const char *dummy_encoding_name_getter(const zend_encoding *encoding)
3535

3636
static bool dummy_encoding_lexer_compatibility_checker(const zend_encoding *encoding)
3737
{
38-
return 0;
38+
return false;
3939
}
4040

4141
static const zend_encoding *dummy_encoding_detector(const unsigned char *string, size_t length, const zend_encoding **list, size_t list_size)

Zend/zend_opcode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,14 +905,14 @@ static bool keeps_op1_alive(zend_op *opline) {
905905
|| opline->opcode == ZEND_FETCH_LIST_W
906906
|| opline->opcode == ZEND_COPY_TMP
907907
|| opline->opcode == ZEND_EXT_STMT) {
908-
return 1;
908+
return true;
909909
}
910910
ZEND_ASSERT(opline->opcode != ZEND_FE_FETCH_R
911911
&& opline->opcode != ZEND_FE_FETCH_RW
912912
&& opline->opcode != ZEND_VERIFY_RETURN_TYPE
913913
&& opline->opcode != ZEND_BIND_LEXICAL
914914
&& opline->opcode != ZEND_ROPE_ADD);
915-
return 0;
915+
return false;
916916
}
917917

918918
/* Live ranges must be sorted by increasing start opline */

Zend/zend_weakrefs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static zend_object* zend_weakref_new(zend_class_entry *ce) {
237237
static zend_always_inline bool zend_weakref_find(zend_object *referent, zval *return_value) {
238238
void *tagged_ptr = zend_hash_index_find_ptr(&EG(weakrefs), zend_object_to_weakref_key(referent));
239239
if (!tagged_ptr) {
240-
return 0;
240+
return false;
241241
}
242242

243243
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
247247
found_weakref:
248248
wr = ptr;
249249
RETVAL_OBJ_COPY(&wr->std);
250-
return 1;
250+
return true;
251251
}
252252

253253
if (tag == ZEND_WEAKREF_TAG_HT) {
@@ -259,7 +259,7 @@ static zend_always_inline bool zend_weakref_find(zend_object *referent, zval *re
259259
} ZEND_HASH_FOREACH_END();
260260
}
261261

262-
return 0;
262+
return false;
263263
}
264264

265265
static zend_always_inline void zend_weakref_create(zend_object *referent, zval *return_value) {

0 commit comments

Comments
 (0)