From 24e3088414ab52070221084e45b63879a754b015 Mon Sep 17 00:00:00 2001 From: Giovanni Giacobbi Date: Fri, 2 Aug 2024 12:05:07 +0000 Subject: [PATCH 1/3] Avoid C99 typedef redeclaration error --- Zend/zend_builtin_functions.h | 2 - Zend/zend_compile.h | 7 +--- Zend/zend_frameless_function.h | 5 +-- Zend/zend_ini_scanner.h | 2 - Zend/zend_iterators.h | 2 - Zend/zend_map_ptr.h | 3 +- Zend/zend_object_handlers.h | 2 - Zend/zend_property_hooks.h | 7 +--- Zend/zend_smart_str_public.h | 3 +- Zend/zend_stream.h | 4 +- Zend/zend_types.h | 9 +---- Zend/zend_types_defs.h | 38 +++++++++++++++++++ Zend/zend_vm.h | 3 -- ext/bcmath/libbcmath/src/private.h | 5 +++ .../lexbor/selectors-adapted/selectors.c | 2 +- ext/dom/namespace_compat.h | 3 -- ext/dom/private_data.h | 13 +------ ext/dom/xml_serializer.c | 1 + ext/dom/xml_serializer.h | 3 -- ext/opcache/jit/ir/ir_private.h | 4 +- ext/opcache/jit/ir/ir_x86.dasc | 2 +- ext/random/php_random.h | 4 +- main/debug_gdb_scripts.c | 2 +- 23 files changed, 62 insertions(+), 64 deletions(-) create mode 100644 Zend/zend_types_defs.h diff --git a/Zend/zend_builtin_functions.h b/Zend/zend_builtin_functions.h index 237b34b2927be..709e17420f106 100644 --- a/Zend/zend_builtin_functions.h +++ b/Zend/zend_builtin_functions.h @@ -22,8 +22,6 @@ #include "zend_types.h" -typedef struct _zval_struct zval; - zend_result zend_startup_builtin_functions(void); BEGIN_EXTERN_C() diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index c7e31877b5cd2..023c884e87ac1 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -52,7 +52,6 @@ } while (0) typedef struct _zend_op_array zend_op_array; -typedef struct _zend_op zend_op; /* On 64-bit systems less optimal, but more compact VM code leads to better * performance. So on 32-bit systems we use absolute addresses for jump @@ -189,8 +188,6 @@ typedef struct _zend_live_range { uint32_t end; } zend_live_range; -typedef struct _zend_property_info zend_property_info; - /* Compilation context that is different for each op array. */ typedef struct _zend_oparray_context { struct _zend_oparray_context *prev; @@ -417,7 +414,7 @@ char *zend_visibility_string(uint32_t fn_flags); zend_property_hook_kind zend_get_property_hook_kind_from_name(zend_string *name); -typedef struct _zend_property_info { +struct _zend_property_info { uint32_t offset; /* property offset for object properties or property index for static properties */ uint32_t flags; @@ -428,7 +425,7 @@ typedef struct _zend_property_info { zend_type type; const zend_property_info *prototype; zend_function **hooks; -} zend_property_info; +}; #define OBJ_PROP(obj, offset) \ ((zval*)((char*)(obj) + offset)) diff --git a/Zend/zend_frameless_function.h b/Zend/zend_frameless_function.h index d64ca7ee15e2f..f7f2b0f985726 100644 --- a/Zend/zend_frameless_function.h +++ b/Zend/zend_frameless_function.h @@ -27,6 +27,7 @@ #endif #include "zend_portability.h" +#include "zend_types_defs.h" #define ZEND_FRAMELESS_FUNCTION_PARAMETERS_0 zval *return_value #define ZEND_FRAMELESS_FUNCTION_PARAMETERS_1 zval *return_value, zval *arg1 @@ -103,10 +104,6 @@ BEGIN_EXTERN_C() -typedef struct _zval_struct zval; -typedef struct _zend_op zend_op; -typedef union _zend_function zend_function; - typedef void (*zend_frameless_function_0)(zval *return_value); typedef void (*zend_frameless_function_1)(zval *return_value, zval *op1); typedef void (*zend_frameless_function_2)(zval *return_value, zval *op1, zval *op2); diff --git a/Zend/zend_ini_scanner.h b/Zend/zend_ini_scanner.h index 62546413c7cb2..d25729e95a97e 100644 --- a/Zend/zend_ini_scanner.h +++ b/Zend/zend_ini_scanner.h @@ -22,8 +22,6 @@ #include "zend_types.h" -typedef struct _zend_file_handle zend_file_handle; - /* Scanner modes */ #define ZEND_INI_SCANNER_NORMAL 0 /* Normal mode. [DEFAULT] */ #define ZEND_INI_SCANNER_RAW 1 /* Raw mode. Option values are not parsed */ diff --git a/Zend/zend_iterators.h b/Zend/zend_iterators.h index 75549188ed6bb..cfd5935e146ec 100644 --- a/Zend/zend_iterators.h +++ b/Zend/zend_iterators.h @@ -29,8 +29,6 @@ * with similar names. * */ -typedef struct _zend_object_iterator zend_object_iterator; - typedef struct _zend_object_iterator_funcs { /* release all resources associated with this iterator instance */ void (*dtor)(zend_object_iterator *iter); diff --git a/Zend/zend_map_ptr.h b/Zend/zend_map_ptr.h index 7a0d853dbd166..0e8589c46c4eb 100644 --- a/Zend/zend_map_ptr.h +++ b/Zend/zend_map_ptr.h @@ -20,8 +20,7 @@ #define ZEND_MAP_PTR_H #include "zend_portability.h" - -typedef struct _zend_string zend_string; +#include "zend_types_defs.h" #define ZEND_MAP_PTR_KIND_PTR 0 #define ZEND_MAP_PTR_KIND_PTR_OR_OFFSET 1 diff --git a/Zend/zend_object_handlers.h b/Zend/zend_object_handlers.h index 730b110eccd37..0932c81e07447 100644 --- a/Zend/zend_object_handlers.h +++ b/Zend/zend_object_handlers.h @@ -304,8 +304,6 @@ ZEND_API HashTable *zend_std_get_properties_for(zend_object *obj, zend_prop_purp * consumers of the get_properties_for API. */ ZEND_API HashTable *zend_get_properties_for(zval *obj, zend_prop_purpose purpose); -typedef struct _zend_property_info zend_property_info; - ZEND_API zend_function *zend_get_property_hook_trampoline( const zend_property_info *prop_info, zend_property_hook_kind kind, zend_string *prop_name); diff --git a/Zend/zend_property_hooks.h b/Zend/zend_property_hooks.h index 3793fa1a683cb..5b1697d77b7ab 100644 --- a/Zend/zend_property_hooks.h +++ b/Zend/zend_property_hooks.h @@ -20,15 +20,10 @@ #define ZEND_PROPERTY_HOOKS_H #include "zend_portability.h" +#include "zend_types_defs.h" BEGIN_EXTERN_C() -typedef struct _zend_array zend_array; -typedef struct _zend_class_entry zend_class_entry; -typedef struct _zend_object zend_object; -typedef struct _zend_object_iterator zend_object_iterator; -typedef struct _zval_struct zval; - typedef enum { ZEND_PROPERTY_HOOK_GET = 0, ZEND_PROPERTY_HOOK_SET = 1, diff --git a/Zend/zend_smart_str_public.h b/Zend/zend_smart_str_public.h index 6a3b526254e48..ac080f4a53dc9 100644 --- a/Zend/zend_smart_str_public.h +++ b/Zend/zend_smart_str_public.h @@ -18,8 +18,7 @@ #define ZEND_SMART_STR_PUBLIC_H #include - -typedef struct _zend_string zend_string; +#include "zend_types_defs.h" typedef struct { /** See smart_str_extract() */ diff --git a/Zend/zend_stream.h b/Zend/zend_stream.h index 33d8656dad5ee..d4acc416091e5 100644 --- a/Zend/zend_stream.h +++ b/Zend/zend_stream.h @@ -50,7 +50,7 @@ typedef struct _zend_stream { zend_stream_closer_t closer; } zend_stream; -typedef struct _zend_file_handle { +struct _zend_file_handle { union { FILE *fp; zend_stream stream; @@ -62,7 +62,7 @@ typedef struct _zend_file_handle { bool in_list; /* added into CG(open_file) */ char *buf; size_t len; -} zend_file_handle; +}; BEGIN_EXTERN_C() ZEND_API void zend_stream_init_fp(zend_file_handle *handle, FILE *fp, const char *filename); diff --git a/Zend/zend_types.h b/Zend/zend_types.h index d1db25a8f2bda..ae2e2f399b95b 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -23,6 +23,7 @@ #define ZEND_TYPES_H #include "zend_portability.h" +#include "zend_types_defs.h" #include "zend_long.h" #include #include @@ -86,16 +87,8 @@ typedef ZEND_RESULT_CODE zend_result; #endif typedef struct _zend_object_handlers zend_object_handlers; -typedef struct _zend_class_entry zend_class_entry; -typedef union _zend_function zend_function; -typedef struct _zend_execute_data zend_execute_data; - -typedef struct _zval_struct zval; typedef struct _zend_refcounted zend_refcounted; -typedef struct _zend_string zend_string; -typedef struct _zend_array zend_array; -typedef struct _zend_object zend_object; typedef struct _zend_resource zend_resource; typedef struct _zend_reference zend_reference; typedef struct _zend_ast_ref zend_ast_ref; diff --git a/Zend/zend_types_defs.h b/Zend/zend_types_defs.h new file mode 100644 index 0000000000000..fdf6bdddec792 --- /dev/null +++ b/Zend/zend_types_defs.h @@ -0,0 +1,38 @@ +/* + +----------------------------------------------------------------------+ + | Zend Engine | + +----------------------------------------------------------------------+ + | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.00 of the Zend license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.zend.com/license/2_00.txt. | + | If you did not receive a copy of the Zend license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@zend.com so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ +*/ + +#ifndef ZEND_TYPES_DEFS_H +#define ZEND_TYPES_DEFS_H + +typedef struct _zend_class_entry zend_class_entry; +typedef union _zend_function zend_function; +typedef struct _zend_execute_data zend_execute_data; + +typedef struct _zval_struct zval; + +typedef struct _zend_string zend_string; +typedef struct _zend_array zend_array; +typedef struct _zend_object zend_object; + +typedef struct _zend_object_iterator zend_object_iterator; + +typedef struct _zend_op zend_op; + +typedef struct _zend_property_info zend_property_info; + +typedef struct _zend_file_handle zend_file_handle; + +#endif /* ZEND_TYPES_DEFS_H */ diff --git a/Zend/zend_vm.h b/Zend/zend_vm.h index c9c41c75c72a2..ba291b783f8e3 100644 --- a/Zend/zend_vm.h +++ b/Zend/zend_vm.h @@ -21,9 +21,6 @@ #include "zend_portability.h" -typedef struct _zend_op zend_op; -typedef struct _zend_execute_data zend_execute_data; - BEGIN_EXTERN_C() ZEND_API void ZEND_FASTCALL zend_vm_set_opcode_handler(zend_op* opcode); diff --git a/ext/bcmath/libbcmath/src/private.h b/ext/bcmath/libbcmath/src/private.h index 5c0087901a4a2..56cb5276299b5 100644 --- a/ext/bcmath/libbcmath/src/private.h +++ b/ext/bcmath/libbcmath/src/private.h @@ -31,6 +31,9 @@ /* "Private" routines to bcmath. */ +#ifndef _BCMATH_PRIVATE_H_ +#define _BCMATH_PRIVATE_H_ + #include #include #include "zend_portability.h" @@ -73,3 +76,5 @@ bcmath_compare_result _bc_do_compare (bc_num n1, bc_num n2, size_t scale, bool u bc_num _bc_do_add (bc_num n1, bc_num n2); bc_num _bc_do_sub (bc_num n1, bc_num n2); void _bc_rm_leading_zeros (bc_num num); + +#endif diff --git a/ext/dom/lexbor/lexbor/selectors-adapted/selectors.c b/ext/dom/lexbor/lexbor/selectors-adapted/selectors.c index 8bd996a3910fe..73c6ebe98776b 100644 --- a/ext/dom/lexbor/lexbor/selectors-adapted/selectors.c +++ b/ext/dom/lexbor/lexbor/selectors-adapted/selectors.c @@ -14,9 +14,9 @@ #include #include "lexbor/selectors-adapted/selectors.h" +#include "../../../php_dom.h" #include "../../../namespace_compat.h" #include "../../../domexception.h" -#include "../../../php_dom.h" #include diff --git a/ext/dom/namespace_compat.h b/ext/dom/namespace_compat.h index 23c80acc7fd78..e342c6d61bca1 100644 --- a/ext/dom/namespace_compat.h +++ b/ext/dom/namespace_compat.h @@ -30,9 +30,6 @@ struct php_dom_ns_magic_token; typedef struct php_dom_ns_magic_token php_dom_ns_magic_token; -struct php_dom_libxml_ns_mapper; -typedef struct php_dom_libxml_ns_mapper php_dom_libxml_ns_mapper; - PHP_DOM_EXPORT extern const php_dom_ns_magic_token *php_dom_ns_is_html_magic_token; PHP_DOM_EXPORT extern const php_dom_ns_magic_token *php_dom_ns_is_mathml_magic_token; PHP_DOM_EXPORT extern const php_dom_ns_magic_token *php_dom_ns_is_svg_magic_token; diff --git a/ext/dom/private_data.h b/ext/dom/private_data.h index ead6c75caf249..d3e71568198b5 100644 --- a/ext/dom/private_data.h +++ b/ext/dom/private_data.h @@ -27,20 +27,11 @@ struct php_dom_libxml_ns_mapper { HashTable uri_to_prefix_map; }; -typedef struct php_dom_private_data { +struct php_dom_private_data { php_libxml_private_data_header header; struct php_dom_libxml_ns_mapper ns_mapper; HashTable *template_fragments; -} php_dom_private_data; - -typedef struct php_libxml_private_data_header php_libxml_private_data_header; -struct php_libxml_private_data_header; - -struct php_dom_private_data; -typedef struct php_dom_private_data php_dom_private_data; - -struct php_dom_libxml_ns_mapper; -typedef struct php_dom_libxml_ns_mapper php_dom_libxml_ns_mapper; +}; php_libxml_private_data_header *php_dom_libxml_private_data_header(php_dom_private_data *private_data); php_dom_libxml_ns_mapper *php_dom_ns_mapper_from_private(php_dom_private_data *private_data); diff --git a/ext/dom/xml_serializer.c b/ext/dom/xml_serializer.c index 080f7ed30aa64..90dda308643ea 100644 --- a/ext/dom/xml_serializer.c +++ b/ext/dom/xml_serializer.c @@ -20,6 +20,7 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) +#include "php_dom.h" #include "xml_serializer.h" #include "private_data.h" #include "namespace_compat.h" diff --git a/ext/dom/xml_serializer.h b/ext/dom/xml_serializer.h index 2d5c3bd84277b..2a1cc45c5bd0b 100644 --- a/ext/dom/xml_serializer.h +++ b/ext/dom/xml_serializer.h @@ -22,9 +22,6 @@ #include #include -struct php_dom_private_data; -typedef struct php_dom_private_data php_dom_private_data; - int dom_xml_serialize(xmlSaveCtxtPtr ctx, xmlOutputBufferPtr out, xmlNodePtr node, bool format, bool require_well_formed, php_dom_private_data *private_data); #endif diff --git a/ext/opcache/jit/ir/ir_private.h b/ext/opcache/jit/ir/ir_private.h index 064d713b20147..85e4c5f344775 100644 --- a/ext/opcache/jit/ir/ir_private.h +++ b/ext/opcache/jit/ir/ir_private.h @@ -832,13 +832,13 @@ typedef struct _ir_hashtab_bucket { uint32_t next; } ir_hashtab_bucket; -typedef struct _ir_hashtab { +struct _ir_hashtab { void *data; uint32_t mask; uint32_t size; uint32_t count; uint32_t pos; -} ir_hashtab; +}; void ir_hashtab_init(ir_hashtab *tab, uint32_t size); void ir_hashtab_free(ir_hashtab *tab); diff --git a/ext/opcache/jit/ir/ir_x86.dasc b/ext/opcache/jit/ir/ir_x86.dasc index 1fa7001198c94..aaf0f9ddd45a2 100644 --- a/ext/opcache/jit/ir/ir_x86.dasc +++ b/ext/opcache/jit/ir/ir_x86.dasc @@ -10852,7 +10852,7 @@ next_block:; do { /* _cldemote(p); */ - asm volatile(".byte 0x0f, 0x1c, 0x06" :: "S" (p)); + __asm__ volatile(".byte 0x0f, 0x1c, 0x06" :: "S" (p)); p += 64; } while (p < start + size); } diff --git a/ext/random/php_random.h b/ext/random/php_random.h index 4c6ce344f6e38..06a79bc5a3795 100644 --- a/ext/random/php_random.h +++ b/ext/random/php_random.h @@ -102,10 +102,10 @@ typedef struct _php_random_algo_with_state { void *state; } php_random_algo_with_state; -typedef struct _php_random_fallback_seed_state { +struct _php_random_fallback_seed_state { bool initialized; unsigned char seed[20]; -} php_random_fallback_seed_state; +}; extern PHPAPI const php_random_algo php_random_algo_combinedlcg; extern PHPAPI const php_random_algo php_random_algo_mt19937; diff --git a/main/debug_gdb_scripts.c b/main/debug_gdb_scripts.c index ad03a2c2ba62f..98e57627e2b2b 100644 --- a/main/debug_gdb_scripts.c +++ b/main/debug_gdb_scripts.c @@ -6,7 +6,7 @@ * * See https://sourceware.org/gdb/current/onlinedocs/gdb.html/dotdebug_005fgdb_005fscripts-section.html#dotdebug_005fgdb_005fscripts-section */ -asm( +__asm__( ".pushsection \".debug_gdb_scripts\", \"MS\",%progbits,1\n" ".byte 4 /* Python Text */\n" ".ascii \"gdb.inlined-script\\n\"\n" From 86eb88638de216e38e6eb4a23e82fc2627d17d6c Mon Sep 17 00:00:00 2001 From: Giovanni Giacobbi Date: Fri, 2 Aug 2024 13:04:34 +0000 Subject: [PATCH 2/3] WIP FIXUP --- ext/dom/php_dom.h | 3 --- ext/dom/xml_common.h | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/dom/php_dom.h b/ext/dom/php_dom.h index c86fd2892e385..acc75e459370b 100644 --- a/ext/dom/php_dom.h +++ b/ext/dom/php_dom.h @@ -114,9 +114,6 @@ typedef enum dom_iterator_type { DOM_HTMLCOLLECTION, } dom_iterator_type; -struct php_dom_libxml_ns_mapper; -typedef struct php_dom_libxml_ns_mapper php_dom_libxml_ns_mapper; - static inline dom_object_namespace_node *php_dom_namespace_node_obj_from_obj(zend_object *obj) { return (dom_object_namespace_node*)((char*)(obj) - XtOffsetOf(dom_object_namespace_node, dom.std)); } diff --git a/ext/dom/xml_common.h b/ext/dom/xml_common.h index 8e5734d5a914e..0b2a52d77e559 100644 --- a/ext/dom/xml_common.h +++ b/ext/dom/xml_common.h @@ -83,6 +83,8 @@ PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj); struct php_dom_private_data; typedef struct php_dom_private_data php_dom_private_data; +typedef struct php_dom_libxml_ns_mapper php_dom_libxml_ns_mapper; + static zend_always_inline php_dom_private_data *php_dom_get_private_data(dom_object *intern) { ZEND_ASSERT(intern->document != NULL); From 21c9413ef059661e380d4cce4a090efb8d75205f Mon Sep 17 00:00:00 2001 From: Giovanni Giacobbi Date: Fri, 2 Aug 2024 13:32:40 +0000 Subject: [PATCH 3/3] WIP FIXUP --- scripts/gdb/debug_gdb_scripts_gen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gdb/debug_gdb_scripts_gen.php b/scripts/gdb/debug_gdb_scripts_gen.php index 1b33d9a63aa6e..2667f249fe4bb 100755 --- a/scripts/gdb/debug_gdb_scripts_gen.php +++ b/scripts/gdb/debug_gdb_scripts_gen.php @@ -27,7 +27,7 @@ * * See https://sourceware.org/gdb/current/onlinedocs/gdb.html/dotdebug_005fgdb_005fscripts-section.html#dotdebug_005fgdb_005fscripts-section */ - asm( + __asm__( ".pushsection \".debug_gdb_scripts\", \"MS\",%%progbits,1\n" ".byte 4 /* Python Text */\n" ".ascii \"gdb.inlined-script\\n\"\n"