diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-06-17 12:34:04 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-06-17 16:36:56 +0200 |
commit | 15846ff115722b2f95d699abf07141d774b0e2cd (patch) | |
tree | 0be3155ce95856e82c4a0cf4c694ab0c6df49e62 /Zend | |
parent | b516566b84c210ce6ceddeb238e45d4b1bcb32ce (diff) | |
download | php-git-15846ff115722b2f95d699abf07141d774b0e2cd.tar.gz |
Add ZVAL_OBJ_COPY macro
For the common ZVAL_OBJ + GC_ADDREF pattern.
This mirrors the existing ZVAL_STR_COPY API.
Diffstat (limited to 'Zend')
-rw-r--r-- | Zend/zend_API.h | 2 | ||||
-rw-r--r-- | Zend/zend_builtin_functions.c | 3 | ||||
-rw-r--r-- | Zend/zend_closures.c | 6 | ||||
-rw-r--r-- | Zend/zend_generators.c | 3 | ||||
-rw-r--r-- | Zend/zend_inheritance.c | 3 | ||||
-rw-r--r-- | Zend/zend_interfaces.c | 3 | ||||
-rw-r--r-- | Zend/zend_types.h | 8 | ||||
-rw-r--r-- | Zend/zend_weakrefs.c | 12 |
8 files changed, 20 insertions, 20 deletions
diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 8ed0e20871..bdcdfaea31 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -716,6 +716,7 @@ END_EXTERN_C() #define RETVAL_ARR(r) ZVAL_ARR(return_value, r) #define RETVAL_EMPTY_ARRAY() ZVAL_EMPTY_ARRAY(return_value) #define RETVAL_OBJ(r) ZVAL_OBJ(return_value, r) +#define RETVAL_OBJ_COPY(r) ZVAL_OBJ_COPY(return_value, r) #define RETVAL_COPY(zv) ZVAL_COPY(return_value, zv) #define RETVAL_COPY_VALUE(zv) ZVAL_COPY_VALUE(return_value, zv) #define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor) @@ -740,6 +741,7 @@ END_EXTERN_C() #define RETURN_ARR(r) do { RETVAL_ARR(r); return; } while (0) #define RETURN_EMPTY_ARRAY() do { RETVAL_EMPTY_ARRAY(); return; } while (0) #define RETURN_OBJ(r) do { RETVAL_OBJ(r); return; } while (0) +#define RETURN_OBJ_COPY(r) do { RETVAL_OBJ_COPY(r); return; } while (0) #define RETURN_COPY(zv) do { RETVAL_COPY(zv); return; } while (0) #define RETURN_COPY_VALUE(zv) do { RETVAL_COPY_VALUE(zv); return; } while (0) #define RETURN_ZVAL(zv, copy, dtor) do { RETVAL_ZVAL(zv, copy, dtor); return; } while (0) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 775bab1504..521c2c32de 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -2069,9 +2069,8 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int } zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_CLASS), &tmp); if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) { - ZVAL_OBJ(&tmp, object); + ZVAL_OBJ_COPY(&tmp, object); zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_OBJECT), &tmp); - Z_ADDREF(tmp); } ZVAL_INTERNED_STR(&tmp, ZSTR_KNOWN(ZEND_STR_OBJECT_OPERATOR)); diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index af008c3628..40ebaae0ab 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -283,8 +283,7 @@ static int zend_create_closure_from_callable(zval *return_value, zval *callable, /* For Closure::fromCallable([$closure, "__invoke"]) return $closure. */ if (fcc.object && fcc.object->ce == zend_ce_closure && zend_string_equals_literal(mptr->common.function_name, "__invoke")) { - ZVAL_OBJ(return_value, fcc.object); - GC_ADDREF(fcc.object); + RETVAL_OBJ_COPY(fcc.object); zend_free_trampoline(mptr); return SUCCESS; } @@ -725,8 +724,7 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_ent if (scope) { closure->func.common.fn_flags |= ZEND_ACC_PUBLIC; if (this_ptr && Z_TYPE_P(this_ptr) == IS_OBJECT && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0) { - Z_ADDREF_P(this_ptr); - ZVAL_OBJ(&closure->this_ptr, Z_OBJ_P(this_ptr)); + ZVAL_OBJ_COPY(&closure->this_ptr, Z_OBJ_P(this_ptr)); } } } diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index a74ae530b1..803627f9a1 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -1120,8 +1120,7 @@ zend_object_iterator *zend_generator_get_iterator(zend_class_entry *ce, zval *ob zend_iterator_init(iterator); iterator->funcs = &zend_generator_iterator_functions; - Z_ADDREF_P(object); - ZVAL_OBJ(&iterator->data, Z_OBJ_P(object)); + ZVAL_OBJ_COPY(&iterator->data, Z_OBJ_P(object)); return iterator; } diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index b6a3a891b2..7cee42085b 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -2416,8 +2416,7 @@ static void check_unrecoverable_load_failure(zend_class_entry *ce) { zend_string *exception_str; zval exception_zv; ZEND_ASSERT(EG(exception) && "Exception must have been thrown"); - ZVAL_OBJ(&exception_zv, EG(exception)); - Z_ADDREF(exception_zv); + ZVAL_OBJ_COPY(&exception_zv, EG(exception)); zend_clear_exception(); exception_str = zval_get_string(&exception_zv); zend_error_noreturn(E_ERROR, diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index 52d3a8ee19..6ac2721f45 100644 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -211,8 +211,7 @@ static zend_object_iterator *zend_user_it_get_iterator(zend_class_entry *ce, zva zend_iterator_init((zend_object_iterator*)iterator); - Z_ADDREF_P(object); - ZVAL_OBJ(&iterator->it.data, Z_OBJ_P(object)); + ZVAL_OBJ_COPY(&iterator->it.data, Z_OBJ_P(object)); iterator->it.funcs = &zend_interface_iterator_funcs_iterator; iterator->ce = Z_OBJCE_P(object); ZVAL_UNDEF(&iterator->value); diff --git a/Zend/zend_types.h b/Zend/zend_types.h index 10a751d1b4..7796979ed8 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -968,6 +968,14 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) { Z_TYPE_INFO_P(__z) = IS_OBJECT_EX; \ } while (0) +#define ZVAL_OBJ_COPY(z, o) do { \ + zval *__z = (z); \ + zend_object *__o = (o); \ + GC_ADDREF(__o); \ + Z_OBJ_P(__z) = __o; \ + Z_TYPE_INFO_P(__z) = IS_OBJECT_EX; \ + } while (0) + #define ZVAL_RES(z, r) do { \ zval *__z = (z); \ Z_RES_P(__z) = (r); \ diff --git a/Zend/zend_weakrefs.c b/Zend/zend_weakrefs.c index db5ffde2fd..b633a57e9f 100644 --- a/Zend/zend_weakrefs.c +++ b/Zend/zend_weakrefs.c @@ -189,8 +189,7 @@ static zend_always_inline zend_bool zend_weakref_find(zval *referent, zval *retu zend_weakref *wr; found_weakref: wr = ptr; - GC_ADDREF(&wr->std); - ZVAL_OBJ(return_value, &wr->std); + RETVAL_OBJ_COPY(&wr->std); return 1; } @@ -221,8 +220,7 @@ static zend_always_inline void zend_weakref_get(zval *weakref, zval *return_valu zend_weakref *wr = zend_weakref_fetch(weakref); if (wr->referent) { - ZVAL_OBJ(return_value, wr->referent); - Z_ADDREF_P(return_value); + RETVAL_OBJ_COPY(wr->referent); } } @@ -433,8 +431,7 @@ static HashTable *zend_weakmap_get_properties_for(zend_object *object, zend_prop zval obj_zv; array_init(&pair); - ZVAL_OBJ(&obj_zv, (zend_object *) obj_addr); - Z_ADDREF(obj_zv); + ZVAL_OBJ_COPY(&obj_zv, (zend_object *) obj_addr); add_assoc_zval(&pair, "key", &obj_zv); Z_TRY_ADDREF_P(val); add_assoc_zval(&pair, "value", val); @@ -511,8 +508,7 @@ static void zend_weakmap_iterator_get_current_key(zend_object_iterator *obj_iter ZEND_ASSERT(0 && "Must have integer key"); } - ZVAL_OBJ(key, (zend_object *) num_key); - Z_ADDREF_P(key); + ZVAL_OBJ_COPY(key, (zend_object *) num_key); } static void zend_weakmap_iterator_move_forward(zend_object_iterator *obj_iter) |