Skip to content

Commit

Permalink
Closures: Catch all closures before searching any other callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
kovshenin committed Mar 23, 2022
1 parent d50c680 commit 0d026fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 14 additions & 1 deletion extension/trace.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef XHPROF_TRACE_H
#define XHPROF_TRACE_H

zend_string *hp_trace_callback_closure(zend_string *function_name, zend_execute_data *data);

static zend_always_inline void hp_mode_common_beginfn(hp_entry_t **entries, hp_entry_t *current)
{
hp_entry_t *p;
Expand Down Expand Up @@ -77,8 +79,19 @@ static zend_always_inline zend_string *hp_get_function_name(zend_execute_data *e

static zend_always_inline zend_string *hp_get_trace_callback(zend_string *function_name, zend_execute_data *data)
{
zend_string *trace_name;
zend_string *trace_name, *closure;
hp_trace_callback *callback;
zend_long offset = 0;

offset = ZSTR_LEN(function_name) - 9;
closure = zend_string_init(ZSTR_VAL(function_name) + offset, 9, 0);
if (zend_string_equals_literal(closure, "{closure}")) {
zend_string_release(closure);
trace_name = hp_trace_callback_closure(function_name, data);
return trace_name;
}

zend_string_release(closure);

if (XHPROF_G(trace_callbacks)) {
callback = (hp_trace_callback*)zend_hash_find_ptr(XHPROF_G(trace_callbacks), function_name);
Expand Down
3 changes: 0 additions & 3 deletions extension/xhprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1574,9 +1574,6 @@ void hp_init_trace_callbacks()
register_trace_callback("apply_filters", callback);
register_trace_callback("do_action", callback);

callback = hp_trace_callback_closure;
register_trace_callback("{closure}", callback);

callback = hp_trace_callback_do_shortcode_tag;
register_trace_callback("do_shortcode_tag", callback);
}

0 comments on commit 0d026fb

Please sign in to comment.