Skip to content

Commit 7114314

Browse files
authored
tree-wide: Replace XtOffsetOf by its definition (#21899)
`offsetof()` is in `stddef.h` and thus always available. The extra macro is an unnecessary layer of indirection.
1 parent 61e62a4 commit 7114314

116 files changed

Lines changed: 223 additions & 225 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

UPGRADING.INTERNALS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ PHP 8.6 INTERNALS UPGRADE NOTES
9696
and ZEND_PARSE_PARAMS_THROW have been removed due to being misleading,
9797
since ZPP always throws, unless ZEND_PARSE_PARAMS_QUIET is given. Use
9898
the non-throw versions.
99+
. The XtOffsetOf() alias of C’s offsetof() macro has been removed. Use
100+
offsetof() directly.
99101

100102
========================
101103
2. Build system changes

Zend/Optimizer/zend_optimizer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ static bool zend_optimizer_ignore_class(zval *ce_zv, const zend_string *filename
780780
if (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE) {
781781
return true;
782782
}
783-
const Bucket *ce_bucket = (const Bucket*)((uintptr_t)ce_zv - XtOffsetOf(Bucket, val));
783+
const Bucket *ce_bucket = (const Bucket*)((uintptr_t)ce_zv - offsetof(Bucket, val));
784784
size_t offset = ce_bucket - EG(class_table)->arData;
785785
if (offset < EG(persistent_classes_count)) {
786786
return false;
@@ -801,7 +801,7 @@ static bool zend_optimizer_ignore_function(zval *fbc_zv, const zend_string *file
801801
if (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE) {
802802
return true;
803803
}
804-
const Bucket *fbc_bucket = (const Bucket*)((uintptr_t)fbc_zv - XtOffsetOf(Bucket, val));
804+
const Bucket *fbc_bucket = (const Bucket*)((uintptr_t)fbc_zv - offsetof(Bucket, val));
805805
size_t offset = fbc_bucket - EG(function_table)->arData;
806806
if (offset < EG(persistent_functions_count)) {
807807
return false;

Zend/zend_ast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ typedef void (*zend_ast_apply_func)(zend_ast **ast_ptr, void *context);
358358
ZEND_API void zend_ast_apply(zend_ast *ast, zend_ast_apply_func fn, void *context);
359359

360360
static zend_always_inline size_t zend_ast_size(uint32_t children) {
361-
return XtOffsetOf(zend_ast, child) + (sizeof(zend_ast *) * children);
361+
return offsetof(zend_ast, child) + (sizeof(zend_ast *) * children);
362362
}
363363

364364
static zend_always_inline bool zend_ast_is_special(const zend_ast *ast) {

Zend/zend_closures.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ static void zend_create_closure_ex(zval *res, zend_function *func, zend_class_en
829829
/* wrap internal function handler to avoid memory leak */
830830
if (UNEXPECTED(closure->func.internal_function.handler == zend_closure_internal_handler)) {
831831
/* avoid infinity recursion, by taking handler from nested closure */
832-
zend_closure *nested = (zend_closure*)((char*)func - XtOffsetOf(zend_closure, func));
832+
zend_closure *nested = (zend_closure*)((char*)func - offsetof(zend_closure, func));
833833
ZEND_ASSERT(nested->std.ce == zend_ce_closure);
834834
closure->orig_internal_handler = nested->orig_internal_handler;
835835
} else {

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5175,7 +5175,7 @@ static zend_result zend_compile_func_array_map(znode *result, zend_ast_list *arg
51755175
opline->lineno = lineno;
51765176
opline->extended_value = (2 << 16) | IS_ARRAY;
51775177
const zval *fbc_zv = zend_hash_find(CG(function_table), lcname);
5178-
const Bucket *fbc_bucket = (const Bucket*)((uintptr_t)fbc_zv - XtOffsetOf(Bucket, val));
5178+
const Bucket *fbc_bucket = (const Bucket*)((uintptr_t)fbc_zv - offsetof(Bucket, val));
51795179
Z_EXTRA_P(CT_CONSTANT(opline->op1)) = fbc_bucket - CG(function_table)->arData;
51805180

51815181
/* Initialize the result array. */
@@ -5472,7 +5472,7 @@ static void zend_compile_call(znode *result, const zend_ast *ast, uint32_t type)
54725472

54735473
/* Store offset to function from symbol table in op2.extra. */
54745474
if (fbc->type == ZEND_INTERNAL_FUNCTION) {
5475-
const Bucket *fbc_bucket = (const Bucket*)((uintptr_t)fbc_zv - XtOffsetOf(Bucket, val));
5475+
const Bucket *fbc_bucket = (const Bucket*)((uintptr_t)fbc_zv - offsetof(Bucket, val));
54765476
Z_EXTRA_P(CT_CONSTANT(opline->op2)) = fbc_bucket - CG(function_table)->arData;
54775477
}
54785478

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ typedef struct _zend_property_info {
481481
#define OBJ_PROP_NUM(obj, num) \
482482
(&(obj)->properties_table[(num)])
483483
#define OBJ_PROP_TO_OFFSET(num) \
484-
((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num)))
484+
((uint32_t)(offsetof(zend_object, properties_table) + sizeof(zval) * (num)))
485485
#define OBJ_PROP_TO_NUM(offset) \
486486
(((offset) - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
487487
#define OBJ_PROP_SLOT_TO_OFFSET(obj, slot) \

Zend/zend_enum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void zend_register_enum_ce(void)
176176
zend_ce_backed_enum->interface_gets_implemented = zend_implement_backed_enum;
177177

178178
memcpy(&zend_enum_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
179-
zend_enum_object_handlers.offset = XtOffsetOf(zend_enum_obj, std);
179+
zend_enum_object_handlers.offset = offsetof(zend_enum_obj, std);
180180
zend_enum_object_handlers.clone_obj = NULL;
181181
zend_enum_object_handlers.compare = zend_objects_not_comparable;
182182
}

Zend/zend_enum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef struct zend_enum_obj {
3636

3737
static inline zend_enum_obj *zend_enum_obj_from_obj(zend_object *zobj) {
3838
ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM);
39-
return (zend_enum_obj*)((char*)(zobj) - XtOffsetOf(zend_enum_obj, std));
39+
return (zend_enum_obj*)((char*)(zobj) - offsetof(zend_enum_obj, std));
4040
}
4141

4242
void zend_enum_startup(void);

Zend/zend_fibers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static zend_always_inline zend_fiber *zend_fiber_from_context(zend_fiber_context
154154
{
155155
ZEND_ASSERT(context->kind == zend_ce_fiber && "Fiber context does not belong to a Zend fiber");
156156

157-
return (zend_fiber *)(((char *) context) - XtOffsetOf(zend_fiber, context));
157+
return (zend_fiber *)(((char *) context) - offsetof(zend_fiber, context));
158158
}
159159

160160
static zend_always_inline zend_fiber_context *zend_fiber_get_context(zend_fiber *fiber)

Zend/zend_ini.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,18 @@ END_EXTERN_C()
182182

183183
#ifdef ZTS
184184
#define STD_ZEND_INI_ENTRY(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr) \
185-
ZEND_INI_ENTRY2(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr##_id)
185+
ZEND_INI_ENTRY2(name, default_value, modifiable, on_modify, (void *) offsetof(struct_type, property_name), (void *) &struct_ptr##_id)
186186
#define STD_ZEND_INI_ENTRY_EX(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr, displayer) \
187-
ZEND_INI_ENTRY2_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr##_id, displayer)
187+
ZEND_INI_ENTRY2_EX(name, default_value, modifiable, on_modify, (void *) offsetof(struct_type, property_name), (void *) &struct_ptr##_id, displayer)
188188
#define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr) \
189-
ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr##_id, NULL, zend_ini_boolean_displayer_cb)
189+
ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) offsetof(struct_type, property_name), (void *) &struct_ptr##_id, NULL, zend_ini_boolean_displayer_cb)
190190
#else
191191
#define STD_ZEND_INI_ENTRY(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr) \
192-
ZEND_INI_ENTRY2(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr)
192+
ZEND_INI_ENTRY2(name, default_value, modifiable, on_modify, (void *) offsetof(struct_type, property_name), (void *) &struct_ptr)
193193
#define STD_ZEND_INI_ENTRY_EX(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr, displayer) \
194-
ZEND_INI_ENTRY2_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr, displayer)
194+
ZEND_INI_ENTRY2_EX(name, default_value, modifiable, on_modify, (void *) offsetof(struct_type, property_name), (void *) &struct_ptr, displayer)
195195
#define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr) \
196-
ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr, NULL, zend_ini_boolean_displayer_cb)
196+
ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) offsetof(struct_type, property_name), (void *) &struct_ptr, NULL, zend_ini_boolean_displayer_cb)
197197
#endif
198198

199199
#define REGISTER_INI_ENTRIES() zend_register_ini_entries_ex(ini_entries, module_number, type)

0 commit comments

Comments
 (0)