Skip to content

Commit 2fb856e

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 b8b0497 commit 2fb856e

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
@@ -460,10 +460,10 @@ static zend_always_inline zend_function *zend_active_function(void)
460460

461461
ZEND_API zend_string *get_active_function_or_method_name(void);
462462
ZEND_API zend_string *get_function_or_method_name(const zend_function *func);
463-
ZEND_API const char *zend_get_executed_filename(void);
464-
ZEND_API zend_string *zend_get_executed_filename_ex(void);
465-
ZEND_API uint32_t zend_get_executed_lineno(void);
466-
ZEND_API zend_class_entry *zend_get_executed_scope(void);
463+
ZEND_ATTRIBUTE_PURE ZEND_API const char *zend_get_executed_filename(void);
464+
ZEND_ATTRIBUTE_PURE ZEND_API zend_string *zend_get_executed_filename_ex(void);
465+
ZEND_ATTRIBUTE_PURE ZEND_API uint32_t zend_get_executed_lineno(void);
466+
ZEND_ATTRIBUTE_PURE ZEND_API zend_class_entry *zend_get_executed_scope(void);
467467
ZEND_API bool zend_is_executing(void);
468468
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num);
469469

‎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
@@ -251,6 +251,12 @@ char *alloca();
251251
# define ZEND_ATTRIBUTE_CONST
252252
#endif
253253

254+
#if ZEND_GCC_VERSION >= 3000
255+
# define ZEND_ATTRIBUTE_PURE __attribute__((pure))
256+
#else
257+
# define ZEND_ATTRIBUTE_PURE
258+
#endif
259+
254260
#if ZEND_GCC_VERSION >= 2007 || __has_attribute(format)
255261
# define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
256262
#else

0 commit comments

Comments
 (0)