Skip to content

Commit e92dbc9

Browse files
committed
refactor: change zend_is_true to return bool
Previously this returned `int`. Many function actually take advantage of the fact this returns exactly 0 or 1. For instance, `main/streams/xp_socket.c` does: sockopts |= STREAM_SOCKOP_IPV6_V6ONLY_ENABLED * zend_is_true(tmpzval); And `Zend/zend_compile.c` does: child = &ast->child[2 - zend_is_true(zend_ast_get_zval(ast->child[0]))]; I changed a few places trivially from `int` to `bool`, but there are still many places such as the object handlers which return `int` that should eventually be `bool`.
1 parent ace18f4 commit e92dbc9

18 files changed

+61
-51
lines changed

Zend/Optimizer/pass1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
309309
case ZEND_JMPZ:
310310
case ZEND_JMPNZ:
311311
if (opline->op1_type == IS_CONST) {
312-
int should_jmp = zend_is_true(&ZEND_OP1_LITERAL(opline));
312+
bool should_jmp = zend_is_true(&ZEND_OP1_LITERAL(opline));
313313

314314
if (opline->opcode == ZEND_JMPZ) {
315315
should_jmp = !should_jmp;

Zend/zend_object_handlers.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check
10611061
{
10621062
zend_class_entry *ce = object->ce;
10631063
zval retval, tmp_offset;
1064-
int result;
1064+
bool result;
10651065

10661066
zend_class_arrayaccess_funcs *funcs = ce->arrayaccess_funcs_ptr;
10671067
if (EXPECTED(funcs)) {
@@ -1081,7 +1081,9 @@ ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check
10811081
zend_bad_array_access(ce);
10821082
return 0;
10831083
}
1084-
return result;
1084+
1085+
// todo: make zend_std_has_dimension return bool as well
1086+
return (int)result;
10851087
}
10861088
/* }}} */
10871089

@@ -1812,7 +1814,7 @@ ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2)
18121814

18131815
ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) /* {{{ */
18141816
{
1815-
int result;
1817+
bool result;
18161818
zval *value = NULL;
18171819
uintptr_t property_offset;
18181820
const zend_property_info *prop_info = NULL;
@@ -1826,7 +1828,7 @@ ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has
18261828
}
18271829
if (UNEXPECTED(Z_PROP_FLAG_P(value) & IS_PROP_UNINIT)) {
18281830
/* Skip __isset() for uninitialized typed properties */
1829-
result = 0;
1831+
result = false;
18301832
goto exit;
18311833
}
18321834
} else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) {
@@ -1862,17 +1864,17 @@ ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has
18621864
result = (Z_TYPE_P(value) != IS_NULL);
18631865
} else {
18641866
ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS);
1865-
result = 1;
1867+
result = true;
18661868
}
18671869
goto exit;
18681870
}
18691871
}
18701872
} else if (UNEXPECTED(EG(exception))) {
1871-
result = 0;
1873+
result = false;
18721874
goto exit;
18731875
}
18741876

1875-
result = 0;
1877+
result = false;
18761878
if ((has_set_exists != ZEND_PROPERTY_EXISTS) && zobj->ce->__isset) {
18771879
uint32_t *guard = zend_get_property_guard(zobj, name);
18781880

@@ -1893,7 +1895,7 @@ ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has
18931895
result = i_zend_is_true(&rv);
18941896
zval_ptr_dtor(&rv);
18951897
} else {
1896-
result = 0;
1898+
result = false;
18971899
}
18981900
}
18991901
(*guard) &= ~IN_ISSET;
@@ -1902,7 +1904,8 @@ ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has
19021904
}
19031905

19041906
exit:
1905-
return result;
1907+
// todo: make zend_std_has_property return bool as well
1908+
return (int)result;
19061909
}
19071910
/* }}} */
19081911

Zend/zend_operators.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,9 +2818,9 @@ ZEND_API zend_result ZEND_FASTCALL decrement_function(zval *op1) /* {{{ */
28182818
}
28192819
/* }}} */
28202820

2821-
ZEND_API int ZEND_FASTCALL zend_is_true(const zval *op) /* {{{ */
2821+
ZEND_API bool ZEND_FASTCALL zend_is_true(const zval *op) /* {{{ */
28222822
{
2823-
return (int) i_zend_is_true(op);
2823+
return i_zend_is_true(op);
28242824
}
28252825
/* }}} */
28262826

Zend/zend_operators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static zend_always_inline bool try_convert_to_string(zval *op) {
372372
#define convert_to_string(op) if (Z_TYPE_P(op) != IS_STRING) { _convert_to_string((op)); }
373373

374374

375-
ZEND_API int ZEND_FASTCALL zend_is_true(const zval *op);
375+
ZEND_API bool ZEND_FASTCALL zend_is_true(const zval *op);
376376
ZEND_API bool ZEND_FASTCALL zend_object_is_true(const zval *op);
377377

378378
#define zval_is_true(op) \

Zend/zend_vm_def.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7313,8 +7313,7 @@ ZEND_VM_HANDLER(114, ZEND_ISSET_ISEMPTY_VAR, CONST|TMPVAR|CV, UNUSED, VAR_FETCH|
73137313
{
73147314
USE_OPLINE
73157315
zval *value;
7316-
/* Should be bool result? as below got: result = (opline->extended_value & ZEND_ISEMPTY) */
7317-
int result;
7316+
bool result;
73187317
zval *varname;
73197318
zend_string *name, *tmp_name;
73207319
HashTable *target_symbol_table;
@@ -7351,7 +7350,7 @@ ZEND_VM_HANDLER(114, ZEND_ISSET_ISEMPTY_VAR, CONST|TMPVAR|CV, UNUSED, VAR_FETCH|
73517350
}
73527351
}
73537352

7354-
ZEND_VM_SMART_BRANCH(result, 1);
7353+
ZEND_VM_SMART_BRANCH(result, true);
73557354
}
73567355

73577356
/* No specialization for op_types (CONST|TMPVAR|CV, UNUSED|CLASS_FETCH|CONST|VAR) */

Zend/zend_weakrefs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ static int zend_weakmap_has_dimension(zend_object *object, zval *offset, int che
421421
}
422422

423423
if (check_empty) {
424-
return i_zend_is_true(zv);
424+
// todo: make zend_weakmap_has_dimension return bool as well
425+
return (int)i_zend_is_true(zv);
425426
}
426427
return Z_TYPE_P(zv) != IS_NULL;
427428
}

ext/dom/php_dom.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static int dom_property_exists(zend_object *object, zend_string *name, int check
409409
{
410410
dom_object *obj = php_dom_obj_from_obj(object);
411411
dom_prop_handler *hnd = NULL;
412-
int retval = 0;
412+
bool retval = false;
413413

414414
if (obj->prop_handler != NULL) {
415415
hnd = zend_hash_find_ptr(obj->prop_handler, name);
@@ -418,7 +418,7 @@ static int dom_property_exists(zend_object *object, zend_string *name, int check
418418
zval tmp;
419419

420420
if (check_empty == 2) {
421-
retval = 1;
421+
retval = true;
422422
} else if (hnd->read_func(obj, &tmp) == SUCCESS) {
423423
if (check_empty == 1) {
424424
retval = zend_is_true(&tmp);
@@ -428,10 +428,11 @@ static int dom_property_exists(zend_object *object, zend_string *name, int check
428428
zval_ptr_dtor(&tmp);
429429
}
430430
} else {
431-
retval = zend_std_has_property(object, name, check_empty, cache_slot);
431+
retval = (bool)zend_std_has_property(object, name, check_empty, cache_slot);
432432
}
433433

434-
return retval;
434+
// todo: make dom_property_exists return bool as well
435+
return (int)retval;
435436
}
436437
/* }}} */
437438

@@ -1441,7 +1442,7 @@ zend_object *dom_xpath_objects_new(zend_class_entry *class_type)
14411442
dom_xpath_object *intern = zend_object_alloc(sizeof(dom_xpath_object), class_type);
14421443

14431444
php_dom_xpath_callbacks_ctor(&intern->xpath_callbacks);
1444-
intern->register_node_ns = 1;
1445+
intern->register_node_ns = true;
14451446

14461447
intern->dom.prop_handler = &dom_xpath_prop_handlers;
14471448

ext/dom/php_dom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extern zend_module_entry dom_module_entry;
6666

6767
typedef struct _dom_xpath_object {
6868
php_dom_xpath_callbacks xpath_callbacks;
69-
int register_node_ns;
69+
bool register_node_ns;
7070
dom_object dom;
7171
} dom_xpath_object;
7272

ext/pdo/pdo_stmt.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,11 +2363,15 @@ static int row_prop_exists(zend_object *object, zend_string *name, int check_emp
23632363
return false;
23642364
}
23652365
ZEND_ASSERT(retval == &tmp_val);
2366-
int res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL;
2366+
bool res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL;
23672367
zval_ptr_dtor_nogc(retval);
2368-
return res;
2368+
2369+
// todo: make row_prop_exists return bool as well
2370+
return (int)res;
23692371
}
23702372

2373+
2374+
// todo: make row_dim_exists return bool as well
23712375
static int row_dim_exists(zend_object *object, zval *offset, int check_empty)
23722376
{
23732377
if (Z_TYPE_P(offset) == IS_LONG) {
@@ -2386,9 +2390,9 @@ static int row_dim_exists(zend_object *object, zval *offset, int check_empty)
23862390
return false;
23872391
}
23882392
ZEND_ASSERT(retval == &tmp_val);
2389-
int res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL;
2393+
bool res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL;
23902394
zval_ptr_dtor_nogc(retval);
2391-
return res;
2395+
return (int)res;
23922396
} else {
23932397
zend_string *member = zval_try_get_string(offset);
23942398
if (!member) {

ext/spl/spl_directory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ PHP_METHOD(DirectoryIterator, seek)
851851
}
852852

853853
while (intern->u.dir.index < pos) {
854-
bool valid = 0;
854+
bool valid = false;
855855
zend_call_method_with_0_params(Z_OBJ_P(ZEND_THIS), Z_OBJCE_P(ZEND_THIS), &intern->u.dir.func_valid, "valid", &retval);
856856
valid = zend_is_true(&retval);
857857
zval_ptr_dtor(&retval);

ext/spl/spl_iterators.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
263263
zend_class_entry *ce;
264264
zval retval, child;
265265
zend_object_iterator *sub_iter;
266-
int has_children;
267266

268267
SPL_FETCH_SUB_ITERATOR(iterator, object);
269268

@@ -308,7 +307,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
308307
}
309308
}
310309
if (Z_TYPE(retval) != IS_UNDEF) {
311-
has_children = zend_is_true(&retval);
310+
bool has_children = zend_is_true(&retval);
312311
zval_ptr_dtor(&retval);
313312
if (has_children) {
314313
if (object->max_depth == -1 || object->max_depth > object->level) {
@@ -3193,17 +3192,18 @@ typedef struct {
31933192
zend_fcall_info_cache fcc;
31943193
} spl_iterator_apply_info;
31953194

3195+
// todo: make spl_iterator_func_apply return bool as well
31963196
static int spl_iterator_func_apply(zend_object_iterator *iter, void *puser) /* {{{ */
31973197
{
31983198
zval retval;
31993199
spl_iterator_apply_info *apply_info = (spl_iterator_apply_info*)puser;
3200-
int result;
3200+
bool result;
32013201

32023202
apply_info->count++;
32033203
zend_call_function_with_return_value(&apply_info->fci, &apply_info->fcc, &retval);
32043204
result = zend_is_true(&retval) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_STOP;
32053205
zval_ptr_dtor(&retval);
3206-
return result;
3206+
return (int)result;
32073207
}
32083208
/* }}} */
32093209

ext/spl/spl_observer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ PHP_METHOD(SplObjectStorage, attach)
440440
spl_object_storage_attach(intern, obj, inf);
441441
} /* }}} */
442442

443+
// todo: make spl_object_storage_has_dimension return bool as well
443444
static int spl_object_storage_has_dimension(zend_object *object, zval *offset, int check_empty)
444445
{
445446
spl_SplObjectStorage *intern = spl_object_storage_from_obj(object);

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6548,7 +6548,7 @@ PHP_FUNCTION(array_filter)
65486548
fci.params = args;
65496549

65506550
if (zend_call_function(&fci, &fci_cache) == SUCCESS) {
6551-
int retval_true;
6551+
bool retval_true;
65526552

65536553
zval_ptr_dtor(&args[0]);
65546554
if (use_type == ARRAY_FILTER_USE_BOTH) {

ext/standard/filters.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,20 +1113,20 @@ static php_conv_err_t php_conv_get_ulong_prop_ex(const HashTable *ht, zend_ulong
11131113
}
11141114
}
11151115

1116-
static php_conv_err_t php_conv_get_bool_prop_ex(const HashTable *ht, int *pretval, char *field_name, size_t field_name_len)
1116+
static php_conv_err_t php_conv_get_bool_prop_ex(const HashTable *ht, bool *pretval, char *field_name, size_t field_name_len)
11171117
{
11181118
zval *tmpval = zend_hash_str_find((HashTable *)ht, field_name, field_name_len-1);
11191119
if (tmpval != NULL) {
11201120
*pretval = zend_is_true(tmpval);
11211121
return PHP_CONV_ERR_SUCCESS;
11221122
} else {
1123-
*pretval = 0;
1123+
*pretval = false;
11241124
return PHP_CONV_ERR_NOT_FOUND;
11251125
}
11261126
}
11271127

11281128
/* XXX this might need an additional fix so it uses size_t, whereby unsigned is quite big so leaving as is for now */
1129-
static int php_conv_get_uint_prop_ex(const HashTable *ht, unsigned int *pretval, char *field_name, size_t field_name_len)
1129+
static php_conv_err_t php_conv_get_uint_prop_ex(const HashTable *ht, unsigned int *pretval, char *field_name, size_t field_name_len)
11301130
{
11311131
zend_ulong l;
11321132
php_conv_err_t err;
@@ -1206,8 +1206,8 @@ static php_conv *php_conv_open(int conv_mode, const HashTable *options, int pers
12061206
int opts = 0;
12071207

12081208
if (options != NULL) {
1209-
int opt_binary = 0;
1210-
int opt_force_encode_first = 0;
1209+
bool opt_binary = false;
1210+
bool opt_force_encode_first = false;
12111211

12121212
GET_STR_PROP(options, lbchars, lbchars_len, "line-break-chars", 0);
12131213
GET_UINT_PROP(options, line_len, "line-length");

ext/standard/http_fopen_wrapper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
136136
zend_string *transport_string;
137137
zend_string *errstr = NULL;
138138
int have_header = 0;
139-
bool request_fulluri = 0, ignore_errors = 0;
139+
bool request_fulluri = false, ignore_errors = false;
140140
struct timeval timeout;
141141
char *user_headers = NULL;
142142
int header_init = ((flags & HTTP_WRAPPER_HEADER_INIT) != 0);
@@ -171,7 +171,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
171171
return php_stream_open_wrapper_ex(path, mode, REPORT_ERRORS, NULL, context);
172172
}
173173
/* Called from a non-http wrapper with http proxying requested (i.e. ftp) */
174-
request_fulluri = 1;
174+
request_fulluri = true;
175175
use_ssl = 0;
176176
use_proxy = 1;
177177
transport_string = zend_string_copy(Z_STR_P(tmpzval));
@@ -801,7 +801,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
801801

802802
/* create filter to decode response body */
803803
if (!(options & STREAM_ONLY_GET_HEADERS)) {
804-
zend_long decode = 1;
804+
bool decode = true;
805805

806806
if (context && (tmpzval = php_stream_context_get_option(context, "http", "auto_decode")) != NULL) {
807807
decode = zend_is_true(tmpzval);

ext/xsl/xsltprocessor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ PHP_METHOD(XSLTProcessor, importStylesheet)
197197
zval *id, *docp = NULL;
198198
xmlDoc *doc = NULL, *newdoc = NULL;
199199
xsltStylesheetPtr sheetp;
200-
int clone_docu = 0;
200+
bool clone_docu = false;
201201
xmlNode *nodep = NULL;
202202
zval *cloneDocu, rv;
203203
zend_string *member;
@@ -257,7 +257,7 @@ PHP_METHOD(XSLTProcessor, importStylesheet)
257257
cloneDocu = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_R, NULL, &rv);
258258
clone_docu = zend_is_true(cloneDocu);
259259
zend_string_release_ex(member, 0);
260-
if (clone_docu == 0) {
260+
if (!clone_docu) {
261261
/* Check if the stylesheet is using xsl:key, if yes, we have to clone the document _always_ before a transformation.
262262
* xsl:key elements may only occur at the top level. Furthermore, all elements at the top level must be in a
263263
* namespace (if not, then the stylesheet is not well-formed and this function will have returned false earlier). */

ext/zip/php_zip.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,11 +949,12 @@ static zval *php_zip_read_property(zend_object *object, zend_string *name, int t
949949
}
950950
/* }}} */
951951

952+
// todo: make php_zip_has_property return bool as well
952953
static int php_zip_has_property(zend_object *object, zend_string *name, int type, void **cache_slot) /* {{{ */
953954
{
954955
ze_zip_object *obj;
955956
zip_prop_handler *hnd = NULL;
956-
int retval = 0;
957+
bool retval = false;
957958

958959
obj = php_zip_fetch_object(object);
959960

@@ -965,7 +966,7 @@ static int php_zip_has_property(zend_object *object, zend_string *name, int type
965966
zval tmp, *prop;
966967

967968
if (type == 2) {
968-
retval = 1;
969+
retval = true;
969970
} else if ((prop = php_zip_property_reader(obj, hnd, &tmp)) != NULL) {
970971
if (type == 1) {
971972
retval = zend_is_true(&tmp);
@@ -976,10 +977,10 @@ static int php_zip_has_property(zend_object *object, zend_string *name, int type
976977

977978
zval_ptr_dtor(&tmp);
978979
} else {
979-
retval = zend_std_has_property(object, name, type, cache_slot);
980+
retval = (bool)zend_std_has_property(object, name, type, cache_slot);
980981
}
981982

982-
return retval;
983+
return (int)retval;
983984
}
984985
/* }}} */
985986

0 commit comments

Comments
 (0)