[php-src] master: Zend: use new zend_object_copy() API
| From: | Gina Peter Banyard | Date: | Thu, 01 Oct 2026 11:44:21 +0000 |
| Subject: | [php-src] master: Zend: use new zend_object_copy() API | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141824@lists.php.net to get a copy of this message | ||
Author: Gina Peter Banyard (Girgias)
Date: 2026-10-01T12:43:56+01:00
Commit: https://github.com/php/php-src/commit/4d35f4a9c8fad06206390b2670515b10fea23800
Raw diff: https://github.com/php/php-src/commit/4d35f4a9c8fad06206390b2670515b10fea23800.diff
Zend: use new zend_object_copy() API
Changed paths:
M Zend/zend_API.c
M Zend/zend_closures.c
M Zend/zend_execute.c
M Zend/zend_execute_API.c
M Zend/zend_vm_def.h
M Zend/zend_vm_execute.h
M Zend/zend_weakrefs.c
Diff:
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index f0b45a64ba98..4e2b407e9122 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -4452,8 +4452,7 @@ ZEND_API void zend_get_callable_zval_from_fcc(const zend_fcall_info_cache
*fcc,
} else if (fcc->function_handler->common.scope) {
array_init(callable);
if (fcc->object) {
- GC_ADDREF(fcc->object);
- add_next_index_object(callable, fcc->object);
+ add_next_index_object(callable, zend_object_copy(fcc->object));
} else {
add_next_index_str(callable, zend_string_copy(fcc->calling_scope->name));
}
diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index c7279ea36e70..f5b88a33aa86 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -902,8 +902,7 @@ static void zend_create_closure_ex(
if (scope) {
closure->func.common.fn_flags |= ZEND_ACC_PUBLIC;
if (this_ptr && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0) {
- closure->this_ptr = this_ptr;
- GC_ADDREF(this_ptr);
+ closure->this_ptr = zend_object_copy(this_ptr);
}
}
}
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 9c414634a23e..e7923d76996c 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -5222,8 +5222,8 @@ static zend_never_inline zend_execute_data
*zend_init_dynamic_call_object(zend_o
call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC;
if (object) {
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
- GC_ADDREF(object); /* For $this pointer */
- object_or_called_scope = object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(object);
}
}
} else {
@@ -5311,8 +5311,8 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(const
z
object_or_called_scope = object->ce;
} else {
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
- GC_ADDREF(object); /* For $this pointer */
- object_or_called_scope = object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(object);
}
}
} else {
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index c608b13cb259..a1b7c16ba73f 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -873,8 +873,7 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_
} else {
object_or_called_scope = fci_cache->object;
call_info = ZEND_CALL_TOP_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_HAS_THIS;
- pinned_this = fci_cache->object;
- GC_ADDREF(pinned_this);
+ pinned_this = zend_object_copy(fci_cache->object);
}
if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_DEPRECATED)) {
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index b01d7287c53f..efa05df6aa6f 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -22,6 +22,8 @@
* php zend_vm_gen.php
*/
+#include "zend_objects_API.h"
+
ZEND_VM_HELPER(zend_add_helper, ANY, ANY, zval *op_1, zval *op_2)
{
USE_OPLINE
@@ -4011,8 +4013,8 @@ ZEND_VM_HANDLER(118, ZEND_INIT_USER_CALL, CONST, CONST|TMP|CV, NUM)
call_info |= ZEND_CALL_HAS_THIS;
}
} else if (fcc.object) {
- GC_ADDREF(fcc.object); /* For $this pointer */
- object_or_called_scope = fcc.object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(fcc.object);
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 352e6d9f6924..243716bfe87c 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -7695,8 +7695,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV
ZEND_INIT_USER_CAL
call_info |= ZEND_CALL_HAS_THIS;
}
} else if (fcc.object) {
- GC_ADDREF(fcc.object); /* For $this pointer */
- object_or_called_scope = fcc.object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(fcc.object);
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
}
@@ -10470,8 +10470,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV
ZEND_INIT_USER_CAL
call_info |= ZEND_CALL_HAS_THIS;
}
} else if (fcc.object) {
- GC_ADDREF(fcc.object); /* For $this pointer */
- object_or_called_scope = fcc.object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(fcc.object);
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
}
@@ -13135,8 +13135,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV
ZEND_INIT_USER_CAL
call_info |= ZEND_CALL_HAS_THIS;
}
} else if (fcc.object) {
- GC_ADDREF(fcc.object); /* For $this pointer */
- object_or_called_scope = fcc.object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(fcc.object);
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
}
@@ -60556,8 +60556,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV
ZEND_INIT_USER_CALL_SPE
call_info |= ZEND_CALL_HAS_THIS;
}
} else if (fcc.object) {
- GC_ADDREF(fcc.object); /* For $this pointer */
- object_or_called_scope = fcc.object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(fcc.object);
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
}
@@ -63331,8 +63331,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV
ZEND_INIT_USER_CALL_SPE
call_info |= ZEND_CALL_HAS_THIS;
}
} else if (fcc.object) {
- GC_ADDREF(fcc.object); /* For $this pointer */
- object_or_called_scope = fcc.object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(fcc.object);
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
}
@@ -65894,8 +65894,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV
ZEND_INIT_USER_CALL_SPE
call_info |= ZEND_CALL_HAS_THIS;
}
} else if (fcc.object) {
- GC_ADDREF(fcc.object); /* For $this pointer */
- object_or_called_scope = fcc.object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(fcc.object);
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
}
diff --git a/Zend/zend_weakrefs.c b/Zend/zend_weakrefs.c
index ad0308f44e20..adb31dfc5c1a 100644
--- a/Zend/zend_weakrefs.c
+++ b/Zend/zend_weakrefs.c
@@ -488,8 +488,7 @@ static HashTable *zend_weakmap_get_properties_for(zend_object *object, zend_prop
zval pair;
array_init(&pair);
- GC_ADDREF(obj);
- add_assoc_object(&pair, "key", obj);
+ add_assoc_object(&pair, "key", zend_object_copy(obj));
Z_TRY_ADDREF_P(val);
add_assoc_zval(&pair, "value", val);