From 5397d845273f96ebd81e9ad186619648cb47db74 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sat, 9 Sep 2023 20:16:59 +0100 Subject: [PATCH 1/2] Zend: Remove dependency on zend.h for certain headers Allows to move AST definitions out from zend_compile.h and into zend_ast.h --- Zend/zend_alloc.h | 1 - Zend/zend_ast.h | 38 +++++++++++++++++++++++++++++++++- Zend/zend_compile.h | 45 ++++++----------------------------------- Zend/zend_hash.h | 4 +++- Zend/zend_objects_API.h | 6 ++++-- Zend/zend_string.h | 4 +++- Zend/zend_variables.h | 1 + 7 files changed, 54 insertions(+), 45 deletions(-) diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h index 578d4c78cc5c5..eb80bfb14b018 100644 --- a/Zend/zend_alloc.h +++ b/Zend/zend_alloc.h @@ -24,7 +24,6 @@ #include #include "../TSRM/TSRM.h" -#include "zend.h" #ifndef ZEND_MM_ALIGNMENT # error "ZEND_MM_ALIGNMENT was not defined during configure" diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h index 4c1a87e288a73..bdabc1b5dc6d8 100644 --- a/Zend/zend_ast.h +++ b/Zend/zend_ast.h @@ -21,7 +21,7 @@ #ifndef ZEND_AST_H #define ZEND_AST_H -#include "zend.h" +#include "zend_types.h" #ifndef ZEND_AST_SPEC # define ZEND_AST_SPEC 1 @@ -213,6 +213,37 @@ typedef struct _zend_ast_decl { zend_ast *child[5]; } zend_ast_decl; +typedef union _znode_op { + uint32_t constant; + uint32_t var; + uint32_t num; + uint32_t opline_num; /* Needs to be signed */ +#if ZEND_USE_ABS_JMP_ADDR + zend_op *jmp_addr; +#else + uint32_t jmp_offset; +#endif +#if ZEND_USE_ABS_CONST_ADDR + zval *zv; +#endif +} znode_op; + +typedef struct _znode { /* used only during compilation */ + uint8_t op_type; + uint8_t flag; + union { + znode_op op; + zval constant; /* replaced by literal/zv */ + } u; +} znode; + +typedef struct _zend_ast_znode { + zend_ast_kind kind; + zend_ast_attr attr; + uint32_t lineno; + znode node; +} zend_ast_znode; + typedef void (*zend_ast_process_t)(zend_ast *ast); extern ZEND_API zend_ast_process_t zend_ast_process; @@ -224,6 +255,7 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval_from_long(zend_long lval) ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_constant(zend_string *name, zend_ast_attr attr); ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_class_const_or_name(zend_ast *class_name, zend_ast *name); +ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_znode(znode *node); #if ZEND_AST_SPEC # define ZEND_AST_SPEC_CALL(name, ...) \ @@ -360,6 +392,10 @@ static zend_always_inline uint32_t zend_ast_get_lineno(zend_ast *ast) { } } +static zend_always_inline znode *zend_ast_get_znode(zend_ast *ast) { + return &((zend_ast_znode *) ast)->node; +} + static zend_always_inline zend_ast *zend_ast_create_binary_op(uint32_t opcode, zend_ast *op0, zend_ast *op1) { return zend_ast_create_ex(ZEND_AST_BINARY_OP, opcode, op0, op1); } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 724b5b8c8a57c..28c19ed4837ad 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -20,8 +20,10 @@ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H -#include "zend.h" #include "zend_ast.h" +#include "zend_types.h" +#include "zend_map_ptr.h" +#include "zend_alloc.h" #include #include @@ -61,44 +63,6 @@ typedef struct _zend_op zend_op; # define ZEND_USE_ABS_CONST_ADDR 0 #endif -typedef union _znode_op { - uint32_t constant; - uint32_t var; - uint32_t num; - uint32_t opline_num; /* Needs to be signed */ -#if ZEND_USE_ABS_JMP_ADDR - zend_op *jmp_addr; -#else - uint32_t jmp_offset; -#endif -#if ZEND_USE_ABS_CONST_ADDR - zval *zv; -#endif -} znode_op; - -typedef struct _znode { /* used only during compilation */ - uint8_t op_type; - uint8_t flag; - union { - znode_op op; - zval constant; /* replaced by literal/zv */ - } u; -} znode; - -/* Temporarily defined here, to avoid header ordering issues */ -typedef struct _zend_ast_znode { - zend_ast_kind kind; - zend_ast_attr attr; - uint32_t lineno; - znode node; -} zend_ast_znode; - -ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_znode(znode *node); - -static zend_always_inline znode *zend_ast_get_znode(zend_ast *ast) { - return &((zend_ast_znode *) ast)->node; -} - typedef struct _zend_declarables { zend_long ticks; } zend_declarables; @@ -492,6 +456,9 @@ struct _zend_op_array { #define ZEND_RETURN_VALUE 0 #define ZEND_RETURN_REFERENCE 1 +#define INTERNAL_FUNCTION_PARAMETERS zend_execute_data *execute_data, zval *return_value +#define INTERNAL_FUNCTION_PARAM_PASSTHRU execute_data, return_value + /* zend_internal_function_handler */ typedef void (ZEND_FASTCALL *zif_handler)(INTERNAL_FUNCTION_PARAMETERS); diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 5726c8a919f43..335cb3f48b855 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -21,7 +21,9 @@ #ifndef ZEND_HASH_H #define ZEND_HASH_H -#include "zend.h" +#include "zend_types.h" +#include "zend_gc.h" +#include "zend_string.h" #include "zend_sort.h" #define HASH_KEY_IS_STRING 1 diff --git a/Zend/zend_objects_API.h b/Zend/zend_objects_API.h index 422bf6a53e2f3..95fa5acf62fb7 100644 --- a/Zend/zend_objects_API.h +++ b/Zend/zend_objects_API.h @@ -20,8 +20,10 @@ #ifndef ZEND_OBJECTS_API_H #define ZEND_OBJECTS_API_H -#include "zend.h" -#include "zend_compile.h" +#include "zend_types.h" +#include "zend_gc.h" +#include "zend_alloc.h" +#include "zend_compile.h" /* For zend_property_info */ #define OBJ_BUCKET_INVALID (1<<0) diff --git a/Zend/zend_string.h b/Zend/zend_string.h index 1513a19c36070..910e2eed250fe 100644 --- a/Zend/zend_string.h +++ b/Zend/zend_string.h @@ -19,7 +19,9 @@ #ifndef ZEND_STRING_H #define ZEND_STRING_H -#include "zend.h" +#include "zend_types.h" +#include "zend_gc.h" +#include "zend_alloc.h" BEGIN_EXTERN_C() diff --git a/Zend/zend_variables.h b/Zend/zend_variables.h index ea3fd9c5efcb8..d504b0f0f5795 100644 --- a/Zend/zend_variables.h +++ b/Zend/zend_variables.h @@ -23,6 +23,7 @@ #include "zend_types.h" #include "zend_gc.h" +#include "zend_hash.h" BEGIN_EXTERN_C() From 44e77f7df4587b43ff194476720daffd7816527f Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 10 Sep 2023 00:03:21 +0100 Subject: [PATCH 2/2] Move znode back to compile header --- Zend/zend_ast.h | 36 ------------------------------------ Zend/zend_compile.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h index bdabc1b5dc6d8..963b81e533084 100644 --- a/Zend/zend_ast.h +++ b/Zend/zend_ast.h @@ -213,37 +213,6 @@ typedef struct _zend_ast_decl { zend_ast *child[5]; } zend_ast_decl; -typedef union _znode_op { - uint32_t constant; - uint32_t var; - uint32_t num; - uint32_t opline_num; /* Needs to be signed */ -#if ZEND_USE_ABS_JMP_ADDR - zend_op *jmp_addr; -#else - uint32_t jmp_offset; -#endif -#if ZEND_USE_ABS_CONST_ADDR - zval *zv; -#endif -} znode_op; - -typedef struct _znode { /* used only during compilation */ - uint8_t op_type; - uint8_t flag; - union { - znode_op op; - zval constant; /* replaced by literal/zv */ - } u; -} znode; - -typedef struct _zend_ast_znode { - zend_ast_kind kind; - zend_ast_attr attr; - uint32_t lineno; - znode node; -} zend_ast_znode; - typedef void (*zend_ast_process_t)(zend_ast *ast); extern ZEND_API zend_ast_process_t zend_ast_process; @@ -255,7 +224,6 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval_from_long(zend_long lval) ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_constant(zend_string *name, zend_ast_attr attr); ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_class_const_or_name(zend_ast *class_name, zend_ast *name); -ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_znode(znode *node); #if ZEND_AST_SPEC # define ZEND_AST_SPEC_CALL(name, ...) \ @@ -392,10 +360,6 @@ static zend_always_inline uint32_t zend_ast_get_lineno(zend_ast *ast) { } } -static zend_always_inline znode *zend_ast_get_znode(zend_ast *ast) { - return &((zend_ast_znode *) ast)->node; -} - static zend_always_inline zend_ast *zend_ast_create_binary_op(uint32_t opcode, zend_ast *op0, zend_ast *op1) { return zend_ast_create_ex(ZEND_AST_BINARY_OP, opcode, op0, op1); } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 28c19ed4837ad..765e54fb56ee8 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -63,6 +63,43 @@ typedef struct _zend_op zend_op; # define ZEND_USE_ABS_CONST_ADDR 0 #endif +typedef union _znode_op { + uint32_t constant; + uint32_t var; + uint32_t num; + uint32_t opline_num; /* Needs to be signed */ +#if ZEND_USE_ABS_JMP_ADDR + zend_op *jmp_addr; +#else + uint32_t jmp_offset; +#endif +#if ZEND_USE_ABS_CONST_ADDR + zval *zv; +#endif +} znode_op; + +typedef struct _znode { /* used only during compilation */ + uint8_t op_type; + uint8_t flag; + union { + znode_op op; + zval constant; /* replaced by literal/zv */ + } u; +} znode; + +typedef struct _zend_ast_znode { + zend_ast_kind kind; + zend_ast_attr attr; + uint32_t lineno; + znode node; +} zend_ast_znode; + +ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_znode(znode *node); + +static zend_always_inline znode *zend_ast_get_znode(zend_ast *ast) { + return &((zend_ast_znode *) ast)->node; +} + typedef struct _zend_declarables { zend_long ticks; } zend_declarables;