1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Two enums instead of preprocessor macros (#10617)

* Zend/zend_compile: convert `memoize_mode` macros to enum

* Zend/zend_stack: convert `ZEND_STACK_APPLY_*` macros to enum
This commit is contained in:
Max Kellermann
2023-02-21 15:34:33 +01:00
committed by GitHub
parent 22bc1eb447
commit bb07e20203
4 changed files with 17 additions and 13 deletions

View File

@@ -379,7 +379,7 @@ void zend_init_compiler_data_structures(void) /* {{{ */
CG(encoding_declared) = 0;
CG(memoized_exprs) = NULL;
CG(memoize_mode) = 0;
CG(memoize_mode) = ZEND_MEMOIZE_NONE;
}
/* }}} */
@@ -2445,13 +2445,9 @@ static void zend_emit_jmp_null(znode *obj_node, uint32_t bp_type)
zend_stack_push(&CG(short_circuiting_opnums), &jmp_null_opnum);
}
#define ZEND_MEMOIZE_NONE 0
#define ZEND_MEMOIZE_COMPILE 1
#define ZEND_MEMOIZE_FETCH 2
static void zend_compile_memoized_expr(znode *result, zend_ast *expr) /* {{{ */
{
int memoize_mode = CG(memoize_mode);
const zend_memoize_mode memoize_mode = CG(memoize_mode);
if (memoize_mode == ZEND_MEMOIZE_COMPILE) {
znode memoized_result;
@@ -9203,7 +9199,7 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */
/* Remember expressions compiled during the initial BP_VAR_IS lookup,
* to avoid double-evaluation when we compile again with BP_VAR_W. */
HashTable *orig_memoized_exprs = CG(memoized_exprs);
int orig_memoize_mode = CG(memoize_mode);
const zend_memoize_mode orig_memoize_mode = CG(memoize_mode);
zend_ensure_writable_variable(var_ast);
if (is_this_fetch(var_ast)) {

View File

@@ -70,6 +70,12 @@ typedef struct _zend_ini_entry zend_ini_entry;
typedef struct _zend_fiber_context zend_fiber_context;
typedef struct _zend_fiber zend_fiber;
typedef enum {
ZEND_MEMOIZE_NONE,
ZEND_MEMOIZE_COMPILE,
ZEND_MEMOIZE_FETCH,
} zend_memoize_mode;
struct _zend_compiler_globals {
zend_stack loop_var_stack;
@@ -129,7 +135,7 @@ struct _zend_compiler_globals {
zend_stack delayed_oplines_stack;
HashTable *memoized_exprs;
int memoize_mode;
zend_memoize_mode memoize_mode;
void *map_ptr_real_base;
void *map_ptr_base;

View File

@@ -119,7 +119,7 @@ ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function
}
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, zend_stack_apply_direction type, int (*apply_function)(void *element, void *arg), void *arg)
{
int i;

View File

@@ -28,6 +28,11 @@ typedef struct _zend_stack {
#define STACK_BLOCK_SIZE 16
typedef enum {
ZEND_STACK_APPLY_TOPDOWN,
ZEND_STACK_APPLY_BOTTOMUP,
} zend_stack_apply_direction;
BEGIN_EXTERN_C()
ZEND_API void zend_stack_init(zend_stack *stack, int size);
ZEND_API int zend_stack_push(zend_stack *stack, const void *element);
@@ -39,11 +44,8 @@ ZEND_API void zend_stack_destroy(zend_stack *stack);
ZEND_API void *zend_stack_base(const zend_stack *stack);
ZEND_API int zend_stack_count(const zend_stack *stack);
ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element));
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg);
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, zend_stack_apply_direction type, int (*apply_function)(void *element, void *arg), void *arg);
ZEND_API void zend_stack_clean(zend_stack *stack, void (*func)(void *), bool free_elements);
END_EXTERN_C()
#define ZEND_STACK_APPLY_TOPDOWN 1
#define ZEND_STACK_APPLY_BOTTOMUP 2
#endif /* ZEND_STACK_H */