Skip to content

Commit bb07e20

Browse files
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
1 parent 22bc1eb commit bb07e20

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

Zend/zend_compile.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void zend_init_compiler_data_structures(void) /* {{{ */
379379

380380
CG(encoding_declared) = 0;
381381
CG(memoized_exprs) = NULL;
382-
CG(memoize_mode) = 0;
382+
CG(memoize_mode) = ZEND_MEMOIZE_NONE;
383383
}
384384
/* }}} */
385385

@@ -2445,13 +2445,9 @@ static void zend_emit_jmp_null(znode *obj_node, uint32_t bp_type)
24452445
zend_stack_push(&CG(short_circuiting_opnums), &jmp_null_opnum);
24462446
}
24472447

2448-
#define ZEND_MEMOIZE_NONE 0
2449-
#define ZEND_MEMOIZE_COMPILE 1
2450-
#define ZEND_MEMOIZE_FETCH 2
2451-
24522448
static void zend_compile_memoized_expr(znode *result, zend_ast *expr) /* {{{ */
24532449
{
2454-
int memoize_mode = CG(memoize_mode);
2450+
const zend_memoize_mode memoize_mode = CG(memoize_mode);
24552451
if (memoize_mode == ZEND_MEMOIZE_COMPILE) {
24562452
znode memoized_result;
24572453

@@ -9203,7 +9199,7 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */
92039199
/* Remember expressions compiled during the initial BP_VAR_IS lookup,
92049200
* to avoid double-evaluation when we compile again with BP_VAR_W. */
92059201
HashTable *orig_memoized_exprs = CG(memoized_exprs);
9206-
int orig_memoize_mode = CG(memoize_mode);
9202+
const zend_memoize_mode orig_memoize_mode = CG(memoize_mode);
92079203

92089204
zend_ensure_writable_variable(var_ast);
92099205
if (is_this_fetch(var_ast)) {

Zend/zend_globals.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ typedef struct _zend_ini_entry zend_ini_entry;
7070
typedef struct _zend_fiber_context zend_fiber_context;
7171
typedef struct _zend_fiber zend_fiber;
7272

73+
typedef enum {
74+
ZEND_MEMOIZE_NONE,
75+
ZEND_MEMOIZE_COMPILE,
76+
ZEND_MEMOIZE_FETCH,
77+
} zend_memoize_mode;
78+
7379
struct _zend_compiler_globals {
7480
zend_stack loop_var_stack;
7581

@@ -129,7 +135,7 @@ struct _zend_compiler_globals {
129135

130136
zend_stack delayed_oplines_stack;
131137
HashTable *memoized_exprs;
132-
int memoize_mode;
138+
zend_memoize_mode memoize_mode;
133139

134140
void *map_ptr_real_base;
135141
void *map_ptr_base;

Zend/zend_stack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function
119119
}
120120

121121

122-
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
122+
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)
123123
{
124124
int i;
125125

Zend/zend_stack.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ typedef struct _zend_stack {
2828

2929
#define STACK_BLOCK_SIZE 16
3030

31+
typedef enum {
32+
ZEND_STACK_APPLY_TOPDOWN,
33+
ZEND_STACK_APPLY_BOTTOMUP,
34+
} zend_stack_apply_direction;
35+
3136
BEGIN_EXTERN_C()
3237
ZEND_API void zend_stack_init(zend_stack *stack, int size);
3338
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);
3944
ZEND_API void *zend_stack_base(const zend_stack *stack);
4045
ZEND_API int zend_stack_count(const zend_stack *stack);
4146
ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element));
42-
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg);
47+
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);
4348
ZEND_API void zend_stack_clean(zend_stack *stack, void (*func)(void *), bool free_elements);
4449
END_EXTERN_C()
4550

46-
#define ZEND_STACK_APPLY_TOPDOWN 1
47-
#define ZEND_STACK_APPLY_BOTTOMUP 2
48-
4951
#endif /* ZEND_STACK_H */

0 commit comments

Comments
 (0)