Skip to content

Commit 2d217f0

Browse files
authored
sapi/phpdbg: Use HASH_FOREACH macro (#16211)
1 parent 6436eaa commit 2d217f0

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

sapi/phpdbg/phpdbg_frame.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,10 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */
245245

246246
void phpdbg_dump_backtrace(size_t num) /* {{{ */
247247
{
248-
HashPosition position;
249248
zval zbacktrace;
250249
zval *tmp;
251-
zval startline, startfile;
252-
const char *startfilename;
253-
zval *file = &startfile, *line = &startline;
250+
zend_string *file = NULL;
251+
zend_long line = 0;
254252
int i = 0, limit = num;
255253

256254
PHPDBG_OUTPUT_BACKUP();
@@ -269,42 +267,39 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
269267
return;
270268
} phpdbg_end_try_access();
271269

272-
Z_LVAL(startline) = zend_get_executed_lineno();
273-
startfilename = zend_get_executed_filename();
274-
Z_STR(startfile) = zend_string_init(startfilename, strlen(startfilename), 0);
275-
276-
zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position);
270+
line = zend_get_executed_lineno();
271+
file = zend_get_executed_filename_ex();
277272

278273
zval *function_name = NULL;
279-
while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position))) {
274+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(zbacktrace), tmp) {
280275
if (file) { /* userland */
281276
phpdbg_out("frame #%d: ", i);
282277
phpdbg_dump_prototype(tmp);
283-
phpdbg_out(" at %s:"ZEND_LONG_FMT"\n", Z_STRVAL_P(file), Z_LVAL_P(line));
278+
phpdbg_out(" at %s:"ZEND_LONG_FMT"\n", ZSTR_VAL(file), line);
284279
i++;
285280
} else {
286281
phpdbg_out(" => ");
287282
phpdbg_dump_prototype(tmp);
288283
phpdbg_out(" (internal function)\n");
289284
}
290285

291-
file = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_FILE));
292-
line = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_LINE));
286+
file = zend_hash_find_ptr(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_FILE));
287+
zval *line_zv = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_LINE));
288+
if (line_zv) {
289+
line = Z_LVAL_P(line_zv);
290+
}
293291
function_name = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_FUNCTION));
294-
295-
zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
296-
}
292+
} ZEND_HASH_FOREACH_END();
297293

298294
/* This is possible for fibers' start closure for example, which have a frame that doesn't contain the info
299295
* of which location stated the fiber if that stack frame is already torn down. same behaviour with debug_backtrace(). */
300296
if (file == NULL) {
301297
phpdbg_writeln(" => %s (internal function)", Z_STRVAL_P(function_name));
302298
} else {
303-
phpdbg_writeln("frame #%d: {main} at %s:"ZEND_LONG_FMT, i, Z_STRVAL_P(file), Z_LVAL_P(line));
299+
phpdbg_writeln("frame #%d: {main} at %s:"ZEND_LONG_FMT, i, ZSTR_VAL(file), line);
304300
}
305301

306302
zval_ptr_dtor_nogc(&zbacktrace);
307-
zend_string_release(Z_STR(startfile));
308303

309304
PHPDBG_OUTPUT_BACKUP_RESTORE();
310305
} /* }}} */

0 commit comments

Comments
 (0)