Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,23 @@ typedef struct _zend_class_constant {

#define ZEND_CLASS_CONST_FLAGS(c) Z_CONSTANT_FLAGS((c)->value)

#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
enum zend_function_type: uint8_t
#else
enum zend_function_type
#endif
{
ZEND_INTERNAL_FUNCTION = 1,
ZEND_USER_FUNCTION = 2,
ZEND_EVAL_CODE = 4,
};

#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
typedef enum zend_function_type zend_function_type;
#else
typedef uint8_t zend_function_type;
#endif

Comment on lines +500 to +516
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better indeed, but I'd make it even more "compact". My motivation for this is the reduced "human parsing effort" overhead wrt preprocessor instructions.

Suggested change
#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
enum zend_function_type: uint8_t
#else
enum zend_function_type
#endif
{
ZEND_INTERNAL_FUNCTION = 1,
ZEND_USER_FUNCTION = 2,
ZEND_EVAL_CODE = 4,
};
#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
typedef enum zend_function_type zend_function_type;
#else
typedef uint8_t zend_function_type;
#endif
#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
typedef enum zend_function_type zend_function_type;
enum zend_function_type: uint8_t
#else
typedef uint8_t zend_function_type;
enum zend_function_type
#endif
{
ZEND_INTERNAL_FUNCTION = 1,
ZEND_USER_FUNCTION = 2,
ZEND_EVAL_CODE = 4,
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried that, but it didn't work for the C23 compiler. Don't have the error message at hand now, but it was something along the lines that the typedef implicitly defined the enum zend_function_type to be int-sized, which conflicted with the : uint8_t in the actual declaration. But AFAICT it is not possible to include the uint8_t within the (effective) forward-declaration in the typedef.

It could possibly become a bit cleaner if we would define a HAVE_C23_ENUM_SIZE or similar?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would be cleaner

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://godbolt.org/z/q9f77xe4z Just an idea, maybe something for zend_portability.h.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be the best if we end up doing more of those

/* arg_info for internal functions */
typedef struct _zend_internal_arg_info {
const char *name;
Expand Down Expand Up @@ -524,7 +541,7 @@ typedef struct _zend_internal_function_info {

struct _zend_op_array {
/* Common elements */
uint8_t type;
zend_function_type type;
uint8_t arg_flags[3]; /* bitset of arg_info.pass_by_reference */
uint32_t fn_flags;
zend_string *function_name;
Expand Down Expand Up @@ -584,7 +601,7 @@ typedef void (ZEND_FASTCALL *zif_handler)(INTERNAL_FUNCTION_PARAMETERS);

typedef struct _zend_internal_function {
/* Common elements */
uint8_t type;
zend_function_type type;
uint8_t arg_flags[3]; /* bitset of arg_info.pass_by_reference */
uint32_t fn_flags;
zend_string* function_name;
Expand All @@ -610,11 +627,11 @@ typedef struct _zend_internal_function {
#define ZEND_FN_SCOPE_NAME(function) ((function) && (function)->common.scope ? ZSTR_VAL((function)->common.scope->name) : "")

union _zend_function {
uint8_t type; /* MUST be the first element of this struct! */
zend_function_type type; /* MUST be the first element of this struct! */
uint32_t quick_arg_flags;

struct {
uint8_t type; /* never used */
zend_function_type type; /* never used */
uint8_t arg_flags[3]; /* bitset of arg_info.pass_by_reference */
uint32_t fn_flags;
zend_string *function_name;
Expand Down Expand Up @@ -956,7 +973,7 @@ ZEND_API zend_ast *zend_compile_string_to_ast(
ZEND_API zend_result zend_execute_scripts(int type, zval *retval, int file_count, ...);
ZEND_API zend_result zend_execute_script(int type, zval *retval, zend_file_handle *file_handle);
ZEND_API zend_result open_file_for_scanning(zend_file_handle *file_handle);
ZEND_API void init_op_array(zend_op_array *op_array, uint8_t type, int initial_ops_size);
ZEND_API void init_op_array(zend_op_array *op_array, zend_function_type type, int initial_ops_size);
ZEND_API void destroy_op_array(zend_op_array *op_array);
ZEND_API void zend_destroy_static_vars(zend_op_array *op_array);
ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle);
Expand Down Expand Up @@ -1071,10 +1088,6 @@ ZEND_API zend_string *zend_type_to_string(zend_type type);
#define BP_VAR_FUNC_ARG 4
#define BP_VAR_UNSET 5

#define ZEND_INTERNAL_FUNCTION 1
#define ZEND_USER_FUNCTION 2
#define ZEND_EVAL_CODE 4

#define ZEND_USER_CODE(type) ((type) != ZEND_INTERNAL_FUNCTION)

#define ZEND_INTERNAL_CLASS 1
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_language_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ ZEND_API zend_result open_file_for_scanning(zend_file_handle *file_handle)
return SUCCESS;
}

static zend_op_array *zend_compile(int type)
static zend_op_array *zend_compile(zend_function_type type)
{
zend_op_array *op_array = NULL;
bool original_in_compilation = CG(in_compilation);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void zend_extension_op_array_dtor_handler(zend_extension *extension, zend
}
}

void init_op_array(zend_op_array *op_array, uint8_t type, int initial_ops_size)
void init_op_array(zend_op_array *op_array, zend_function_type type, int initial_ops_size)
{
op_array->type = type;
op_array->arg_flags[0] = 0;
Expand Down
Loading