Skip to content

Commit f21308c

Browse files
committed
zend_execute: Mark zend_get_executed_*() as __attribute__((pure))
These functions do not modify the state of the program and depend on thread-safe global variables only.
1 parent 525cc9a commit f21308c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

Zend/zend_execute.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,10 @@ static zend_always_inline zend_function *zend_active_function(void)
467467

468468
ZEND_API zend_string *get_active_function_or_method_name(void);
469469
ZEND_API zend_string *get_function_or_method_name(const zend_function *func);
470-
ZEND_API const char *zend_get_executed_filename(void);
471-
ZEND_API zend_string *zend_get_executed_filename_ex(void);
472-
ZEND_API uint32_t zend_get_executed_lineno(void);
473-
ZEND_API zend_class_entry *zend_get_executed_scope(void);
470+
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_get_executed_filename(void);
471+
ZEND_ATTRIBUTE_PURE ZEND_API zend_string *zend_get_executed_filename_ex(void);
472+
ZEND_ATTRIBUTE_PURE ZEND_API uint32_t zend_get_executed_lineno(void);
473+
ZEND_ATTRIBUTE_PURE ZEND_API zend_class_entry *zend_get_executed_scope(void);
474474
ZEND_API bool zend_is_executing(void);
475475
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num);
476476

Zend/zend_execute_API.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,14 @@ ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t a
656656
}
657657
/* }}} */
658658

659-
ZEND_API const char *zend_get_executed_filename(void) /* {{{ */
659+
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_get_executed_filename(void) /* {{{ */
660660
{
661661
zend_string *filename = zend_get_executed_filename_ex();
662662
return filename != NULL ? ZSTR_VAL(filename) : "[no active file]";
663663
}
664664
/* }}} */
665665

666-
ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
666+
ZEND_ATTRIBUTE_PURE ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
667667
{
668668
zend_string *filename_override = EG(filename_override);
669669
if (filename_override != NULL) {
@@ -683,7 +683,7 @@ ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
683683
}
684684
/* }}} */
685685

686-
ZEND_API uint32_t zend_get_executed_lineno(void) /* {{{ */
686+
ZEND_ATTRIBUTE_PURE ZEND_API uint32_t zend_get_executed_lineno(void) /* {{{ */
687687
{
688688
zend_long lineno_override = EG(lineno_override);
689689
if (lineno_override != -1) {
@@ -711,7 +711,7 @@ ZEND_API uint32_t zend_get_executed_lineno(void) /* {{{ */
711711
}
712712
/* }}} */
713713

714-
ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */
714+
ZEND_ATTRIBUTE_PURE ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */
715715
{
716716
zend_execute_data *ex = EG(current_execute_data);
717717

Zend/zend_portability.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ char *alloca();
265265
# define ZEND_ATTRIBUTE_CONST
266266
#endif
267267

268+
#if ZEND_GCC_VERSION >= 3000
269+
# define ZEND_ATTRIBUTE_PURE __attribute__((pure))
270+
#else
271+
# define ZEND_ATTRIBUTE_PURE
272+
#endif
273+
268274
#if ZEND_GCC_VERSION >= 2007 || __has_attribute(format)
269275
# define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
270276
#else

0 commit comments

Comments
 (0)