Skip to content

zend_execute: Mark zend_get_executed_*() as __attribute__((pure)) #18998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ZEND_API ZEND_COLD void zend_wrong_property_read(zval *object, zval *property)
}

/* Argument parsing API -- andrei */
ZEND_API const char *zend_get_type_by_const(int type) /* {{{ */
ZEND_ATTRIBUTE_CONST ZEND_API const char *zend_get_type_by_const(int type) /* {{{ */
{
switch(type) {
case IS_FALSE:
Expand Down Expand Up @@ -152,7 +152,7 @@ ZEND_API const char *zend_get_type_by_const(int type) /* {{{ */
}
/* }}} */

ZEND_API const char *zend_zval_value_name(const zval *arg)
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_zval_value_name(const zval *arg)
{
ZVAL_DEREF(arg);

Expand All @@ -171,7 +171,7 @@ ZEND_API const char *zend_zval_value_name(const zval *arg)
return zend_get_type_by_const(Z_TYPE_P(arg));
}

ZEND_API const char *zend_zval_type_name(const zval *arg)
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_zval_type_name(const zval *arg)
{
ZVAL_DEREF(arg);

Expand Down Expand Up @@ -3762,7 +3762,7 @@ ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_nam
}
/* }}} */

static zend_always_inline zend_class_entry *get_scope(zend_execute_data *frame)
ZEND_ATTRIBUTE_PURE static zend_always_inline zend_class_entry *get_scope(const zend_execute_data *frame)
{
return frame && frame->func ? frame->func->common.scope : NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ ZEND_API zend_result zend_parse_parameters_ex(int flags, uint32_t num_args, cons
/* NOTE: This must have at least one value in __VA_ARGS__ for the expression to be valid */
#define zend_parse_parameters_throw(num_args, ...) \
zend_parse_parameters(num_args, __VA_ARGS__)
ZEND_API const char *zend_zval_type_name(const zval *arg);
ZEND_API const char *zend_zval_value_name(const zval *arg);
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_zval_type_name(const zval *arg);
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_zval_value_name(const zval *arg);
ZEND_API zend_string *zend_zval_get_legacy_type(const zval *arg);

ZEND_API zend_result zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
Expand Down Expand Up @@ -520,7 +520,7 @@ ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object,
ZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, bool silent);
ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, bool silent);

ZEND_API const char *zend_get_type_by_const(int type);
ZEND_ATTRIBUTE_CONST ZEND_API const char *zend_get_type_by_const(int type);

#define ZEND_THIS (&EX(This))

Expand Down
20 changes: 10 additions & 10 deletions Zend/zend_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,12 @@ ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named

/* services */
ZEND_API const char *get_active_class_name(const char **space);
ZEND_API const char *get_active_function_name(void);
ZEND_API const char *get_active_function_arg_name(uint32_t arg_num);
ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num);
ZEND_API zend_function *zend_active_function_ex(zend_execute_data *execute_data);
ZEND_ATTRIBUTE_PURE ZEND_API const char *get_active_function_name(void);
ZEND_ATTRIBUTE_PURE ZEND_API const char *get_active_function_arg_name(uint32_t arg_num);
ZEND_ATTRIBUTE_PURE ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num);
ZEND_ATTRIBUTE_PURE ZEND_API zend_function *zend_active_function_ex(const zend_execute_data *execute_data);

static zend_always_inline zend_function *zend_active_function(void)
ZEND_ATTRIBUTE_PURE static zend_always_inline zend_function *zend_active_function(void)
{
zend_function *func = EG(current_execute_data)->func;
if (ZEND_USER_CODE(func->type)) {
Expand All @@ -460,11 +460,11 @@ static zend_always_inline zend_function *zend_active_function(void)

ZEND_API zend_string *get_active_function_or_method_name(void);
ZEND_API zend_string *get_function_or_method_name(const zend_function *func);
ZEND_API const char *zend_get_executed_filename(void);
ZEND_API zend_string *zend_get_executed_filename_ex(void);
ZEND_API uint32_t zend_get_executed_lineno(void);
ZEND_API zend_class_entry *zend_get_executed_scope(void);
ZEND_API bool zend_is_executing(void);
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_get_executed_filename(void);
ZEND_ATTRIBUTE_PURE ZEND_API zend_string *zend_get_executed_filename_ex(void);
ZEND_ATTRIBUTE_PURE ZEND_API uint32_t zend_get_executed_lineno(void);
ZEND_ATTRIBUTE_PURE ZEND_API zend_class_entry *zend_get_executed_scope(void);
ZEND_ATTRIBUTE_PURE ZEND_API bool zend_is_executing(void);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num);

ZEND_API void zend_set_timeout(zend_long seconds, bool reset_signals);
Expand Down
18 changes: 9 additions & 9 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ ZEND_API const char *get_active_class_name(const char **space) /* {{{ */
}
/* }}} */

ZEND_API const char *get_active_function_name(void) /* {{{ */
ZEND_ATTRIBUTE_PURE ZEND_API const char *get_active_function_name(void) /* {{{ */
{
zend_function *func;

Expand Down Expand Up @@ -597,7 +597,7 @@ ZEND_API const char *get_active_function_name(void) /* {{{ */
}
/* }}} */

ZEND_API zend_function *zend_active_function_ex(zend_execute_data *execute_data)
ZEND_ATTRIBUTE_PURE ZEND_API zend_function *zend_active_function_ex(const zend_execute_data *execute_data)
{
zend_function *func = EX(func);

Expand Down Expand Up @@ -630,7 +630,7 @@ ZEND_API zend_string *get_function_or_method_name(const zend_function *func) /*
}
/* }}} */

ZEND_API const char *get_active_function_arg_name(uint32_t arg_num) /* {{{ */
ZEND_ATTRIBUTE_PURE ZEND_API const char *get_active_function_arg_name(uint32_t arg_num) /* {{{ */
{
if (!zend_is_executing()) {
return NULL;
Expand All @@ -642,7 +642,7 @@ ZEND_API const char *get_active_function_arg_name(uint32_t arg_num) /* {{{ */
}
/* }}} */

ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num) /* {{{ */
ZEND_ATTRIBUTE_PURE ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num) /* {{{ */
{
if (!func || arg_num == 0 || func->common.num_args < arg_num) {
return NULL;
Expand All @@ -656,14 +656,14 @@ ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t a
}
/* }}} */

ZEND_API const char *zend_get_executed_filename(void) /* {{{ */
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_get_executed_filename(void) /* {{{ */
{
zend_string *filename = zend_get_executed_filename_ex();
return filename != NULL ? ZSTR_VAL(filename) : "[no active file]";
}
/* }}} */

ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
ZEND_ATTRIBUTE_PURE ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
{
zend_string *filename_override = EG(filename_override);
if (filename_override != NULL) {
Expand All @@ -683,7 +683,7 @@ ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
}
/* }}} */

ZEND_API uint32_t zend_get_executed_lineno(void) /* {{{ */
ZEND_ATTRIBUTE_PURE ZEND_API uint32_t zend_get_executed_lineno(void) /* {{{ */
{
zend_long lineno_override = EG(lineno_override);
if (lineno_override != -1) {
Expand Down Expand Up @@ -711,7 +711,7 @@ ZEND_API uint32_t zend_get_executed_lineno(void) /* {{{ */
}
/* }}} */

ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */
ZEND_ATTRIBUTE_PURE ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */
{
zend_execute_data *ex = EG(current_execute_data);

Expand All @@ -726,7 +726,7 @@ ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */
}
/* }}} */

ZEND_API bool zend_is_executing(void) /* {{{ */
ZEND_ATTRIBUTE_PURE ZEND_API bool zend_is_executing(void) /* {{{ */
{
return EG(current_execute_data) != 0;
}
Expand Down
6 changes: 6 additions & 0 deletions Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ char *alloca();
# define ZEND_ATTRIBUTE_CONST
#endif

#if ZEND_GCC_VERSION >= 3000
# define ZEND_ATTRIBUTE_PURE __attribute__((pure))
#else
# define ZEND_ATTRIBUTE_PURE
#endif

#if ZEND_GCC_VERSION >= 2007 || __has_attribute(format)
# define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
#else
Expand Down