1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Use zend_ast_size consistenly (#11955)

* opcache: use zend_ast_size helper in zend_persist_ast

* opcache: use zend_ast_size helper in zend_persist_ast_calc

* Zend: fix zend_ast_size definition

It is better not to use sizeof(struct_with_flexible_array)
and instead rely on offsetof(type, member) like most
other similar wrappers do.
This commit is contained in:
Cristian Rodríguez
2023-08-13 18:51:14 -04:00
committed by GitHub
parent e56ed6e1ab
commit 2196e2299f
3 changed files with 3 additions and 3 deletions

View File

@@ -313,7 +313,7 @@ typedef void (*zend_ast_apply_func)(zend_ast **ast_ptr, void *context);
ZEND_API void zend_ast_apply(zend_ast *ast, zend_ast_apply_func fn, void *context); ZEND_API void zend_ast_apply(zend_ast *ast, zend_ast_apply_func fn, void *context);
static zend_always_inline size_t zend_ast_size(uint32_t children) { static zend_always_inline size_t zend_ast_size(uint32_t children) {
return sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children; return XtOffsetOf(zend_ast, child) + (sizeof(zend_ast *) * children);
} }
static zend_always_inline bool zend_ast_is_special(zend_ast *ast) { static zend_always_inline bool zend_ast_is_special(zend_ast *ast) {

View File

@@ -188,7 +188,7 @@ static zend_ast *zend_persist_ast(zend_ast *ast)
node = (zend_ast *) copy; node = (zend_ast *) copy;
} else { } else {
uint32_t children = zend_ast_get_num_children(ast); uint32_t children = zend_ast_get_num_children(ast);
node = zend_shared_memdup(ast, sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children); node = zend_shared_memdup(ast, zend_ast_size(children));
for (i = 0; i < children; i++) { for (i = 0; i < children; i++) {
if (node->child[i]) { if (node->child[i]) {
node->child[i] = zend_persist_ast(node->child[i]); node->child[i] = zend_persist_ast(node->child[i]);

View File

@@ -87,7 +87,7 @@ static void zend_persist_ast_calc(zend_ast *ast)
} }
} else { } else {
uint32_t children = zend_ast_get_num_children(ast); uint32_t children = zend_ast_get_num_children(ast);
ADD_SIZE(sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children); ADD_SIZE(zend_ast_size(children));
for (i = 0; i < children; i++) { for (i = 0; i < children; i++) {
if (ast->child[i]) { if (ast->child[i]) {
zend_persist_ast_calc(ast->child[i]); zend_persist_ast_calc(ast->child[i]);