Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,20 +504,22 @@ ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest
convert_to_string(arg);
*dest = Z_STR_P(arg);
} else if (UNEXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
zend_object *zobj = Z_OBJ_P(arg);

if (Z_OBJ_HANDLER_P(arg, cast_object)) {
zval obj;
if (Z_OBJ_HANDLER_P(arg, cast_object)(arg, &obj, IS_STRING) == SUCCESS) {
zval_ptr_dtor(arg);
if (zobj->handlers->cast_object(zobj, &obj, IS_STRING) == SUCCESS) {
OBJ_RELEASE(zobj);
ZVAL_COPY_VALUE(arg, &obj);
*dest = Z_STR_P(arg);
return 1;
}
} else if (Z_OBJ_HANDLER_P(arg, get)) {
} else if (zobj->handlers->get) {
zval rv;
zval *z = Z_OBJ_HANDLER_P(arg, get)(arg, &rv);
zval *z = zobj->handlers->get(zobj, &rv);

if (Z_TYPE_P(z) != IS_OBJECT) {
zval_ptr_dtor(arg);
OBJ_RELEASE(zobj);
if (Z_TYPE_P(z) == IS_STRING) {
ZVAL_COPY_VALUE(arg, z);
} else {
Expand Down Expand Up @@ -1101,18 +1103,16 @@ ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this
* because it may call __set from the uninitialized object otherwise. */
ZEND_API void zend_merge_properties(zval *obj, HashTable *properties) /* {{{ */
{
const zend_object_handlers *obj_ht = Z_OBJ_HT_P(obj);
zend_object *zobj = Z_OBJ_P(obj);
zend_object_write_property_t write_property = zobj->handlers->write_property;
zend_class_entry *old_scope = EG(fake_scope);
zend_string *key;
zval *value;

EG(fake_scope) = Z_OBJCE_P(obj);
ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, value) {
if (key) {
zval member;

ZVAL_STR(&member, key);
obj_ht->write_property(obj, &member, value, NULL);
write_property(zobj, key, value, NULL);
}
} ZEND_HASH_FOREACH_END();
EG(fake_scope) = old_scope;
Expand Down Expand Up @@ -1728,11 +1728,11 @@ ZEND_API int add_property_stringl_ex(zval *arg, const char *key, size_t key_len,

ZEND_API int add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value) /* {{{ */
{
zval z_key;
zend_string *str;

ZVAL_STRINGL(&z_key, key, key_len);
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, value, NULL);
zval_ptr_dtor(&z_key);
str = zend_string_init(key, key_len, 0);
Z_OBJ_HANDLER_P(arg, write_property)(Z_OBJ_P(arg), str, value, NULL);
zend_string_release_ex(str, 0);
return SUCCESS;
}
/* }}} */
Expand Down Expand Up @@ -3143,16 +3143,18 @@ ZEND_API zend_string *zend_get_callable_name_ex(zval *callable, zend_object *obj
zend_class_entry *calling_scope;
zend_function *fptr;
zend_object *object;
if (Z_OBJ_HANDLER_P(callable, get_closure)
&& Z_OBJ_HANDLER_P(callable, get_closure)(callable, &calling_scope, &fptr, &object) == SUCCESS) {
zend_class_entry *ce = Z_OBJCE_P(callable);
zend_object *zobj = Z_OBJ_P(callable);

if (zobj->handlers->get_closure
&& zobj->handlers->get_closure(zobj, &calling_scope, &fptr, &object) == SUCCESS) {
zend_class_entry *ce = zobj->ce;
zend_string *callable_name = zend_string_alloc(
ZSTR_LEN(ce->name) + sizeof("::__invoke") - 1, 0);
memcpy(ZSTR_VAL(callable_name), ZSTR_VAL(ce->name), ZSTR_LEN(ce->name));
memcpy(ZSTR_VAL(callable_name) + ZSTR_LEN(ce->name), "::__invoke", sizeof("::__invoke"));
return callable_name;
}
return zval_get_string(callable);
return zval_get_string_func(callable);
}
case IS_REFERENCE:
callable = Z_REFVAL_P(callable);
Expand Down Expand Up @@ -3277,7 +3279,7 @@ static zend_always_inline zend_bool zend_is_callable_impl(zval *callable, zend_o
}
return 0;
case IS_OBJECT:
if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, &fcc->object) == SUCCESS) {
if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(Z_OBJ_P(callable), &fcc->calling_scope, &fcc->function_handler, &fcc->object) == SUCCESS) {
fcc->called_scope = fcc->calling_scope;
return 1;
}
Expand Down Expand Up @@ -3944,28 +3946,26 @@ ZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, const char

ZEND_API void zend_update_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zval *value) /* {{{ */
{
zval property;
zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;

ZVAL_STR(&property, name);
Z_OBJ_HT_P(object)->write_property(object, &property, value, NULL);
Z_OBJ_HT_P(object)->write_property(Z_OBJ_P(object), name, value, NULL);

EG(fake_scope) = old_scope;
}
/* }}} */

ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zval *value) /* {{{ */
{
zval property;
zend_string *property;
zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;

ZVAL_STRINGL(&property, name, name_length);
Z_OBJ_HT_P(object)->write_property(object, &property, value, NULL);
zval_ptr_dtor(&property);
property = zend_string_init(name, name_length, 0);
Z_OBJ_HT_P(object)->write_property(Z_OBJ_P(object), property, value, NULL);
zend_string_release_ex(property, 0);

EG(fake_scope) = old_scope;
}
Expand All @@ -3982,14 +3982,14 @@ ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, c

ZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length) /* {{{ */
{
zval property;
zend_string *property;
zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;

ZVAL_STRINGL(&property, name, name_length);
Z_OBJ_HT_P(object)->unset_property(object, &property, 0);
zval_ptr_dtor(&property);
property = zend_string_init(name, name_length, 0);
Z_OBJ_HT_P(object)->unset_property(Z_OBJ_P(object), property, 0);
zend_string_release_ex(property, 0);

EG(fake_scope) = old_scope;
}
Expand Down Expand Up @@ -4148,13 +4148,12 @@ ZEND_API int zend_update_static_property_stringl(zend_class_entry *scope, const

ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zend_bool silent, zval *rv) /* {{{ */
{
zval property, *value;
zval *value;
zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;

ZVAL_STR(&property, name);
value = Z_OBJ_HT_P(object)->read_property(object, &property, silent?BP_VAR_IS:BP_VAR_R, NULL, rv);
value = Z_OBJ_HT_P(object)->read_property(Z_OBJ_P(object), name, silent?BP_VAR_IS:BP_VAR_R, NULL, rv);

EG(fake_scope) = old_scope;
return value;
Expand Down
15 changes: 8 additions & 7 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ END_EXTERN_C()
#define RETURN_FALSE { RETVAL_FALSE; return; }
#define RETURN_TRUE { RETVAL_TRUE; return; }

#define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL)))
#define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties(Z_OBJ_P(p)) : NULL)))
#define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)

/* For compatibility */
Expand Down Expand Up @@ -1501,15 +1501,16 @@ static zend_always_inline int zend_parse_arg_array_ht(zval *arg, HashTable **des
if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
*dest = Z_ARRVAL_P(arg);
} else if (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
zend_object *zobj = Z_OBJ_P(arg);
if (separate
&& Z_OBJ_P(arg)->properties
&& UNEXPECTED(GC_REFCOUNT(Z_OBJ_P(arg)->properties) > 1)) {
if (EXPECTED(!(GC_FLAGS(Z_OBJ_P(arg)->properties) & IS_ARRAY_IMMUTABLE))) {
GC_DELREF(Z_OBJ_P(arg)->properties);
&& zobj->properties
&& UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
GC_DELREF(zobj->properties);
}
Z_OBJ_P(arg)->properties = zend_array_dup(Z_OBJ_P(arg)->properties);
zobj->properties = zend_array_dup(zobj->properties);
}
*dest = Z_OBJ_HT_P(arg)->get_properties(arg);
*dest = zobj->handlers->get_properties(zobj);
} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
*dest = NULL;
} else {
Expand Down
14 changes: 5 additions & 9 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,11 @@ ZEND_FUNCTION(define)
if (Z_TYPE(val_free) == IS_UNDEF) {
if (Z_OBJ_HT_P(val)->get) {
zval rv;
val = Z_OBJ_HT_P(val)->get(val, &rv);
val = Z_OBJ_HT_P(val)->get(Z_OBJ_P(val), &rv);
ZVAL_COPY_VALUE(&val_free, val);
goto repeat;
} else if (Z_OBJ_HT_P(val)->cast_object) {
if (Z_OBJ_HT_P(val)->cast_object(val, &val_free, IS_STRING) == SUCCESS) {
if (Z_OBJ_HT_P(val)->cast_object(Z_OBJ_P(val), &val_free, IS_STRING) == SUCCESS) {
val = &val_free;
break;
}
Expand Down Expand Up @@ -1097,13 +1097,12 @@ ZEND_FUNCTION(get_object_vars)
Z_PARAM_OBJECT(obj)
ZEND_PARSE_PARAMETERS_END();

properties = Z_OBJ_HT_P(obj)->get_properties(obj);
zobj = Z_OBJ_P(obj);
properties = zobj->handlers->get_properties(zobj);
if (properties == NULL) {
RETURN_FALSE;
}

zobj = Z_OBJ_P(obj);

if (!zobj->ce->default_properties_count && properties == zobj->properties && !GC_IS_RECURSIVE(properties)) {
/* fast copy */
if (EXPECTED(zobj->handlers == &std_object_handlers)) {
Expand Down Expand Up @@ -1292,7 +1291,6 @@ ZEND_FUNCTION(property_exists)
zend_string *property;
zend_class_entry *ce;
zend_property_info *property_info;
zval property_z;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &object, &property) == FAILURE) {
return;
Expand Down Expand Up @@ -1321,10 +1319,8 @@ ZEND_FUNCTION(property_exists)
RETURN_TRUE;
}

ZVAL_STR(&property_z, property);

if (Z_TYPE_P(object) == IS_OBJECT &&
Z_OBJ_HANDLER_P(object, has_property)(object, &property_z, 2, NULL)) {
Z_OBJ_HANDLER_P(object, has_property)(Z_OBJ_P(object), property, 2, NULL)) {
RETURN_TRUE;
}
RETURN_FALSE;
Expand Down
26 changes: 13 additions & 13 deletions Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,28 +395,28 @@ static zend_function *zend_closure_get_method(zend_object **object, zend_string
}
/* }}} */

static zval *zend_closure_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv) /* {{{ */
static zval *zend_closure_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv) /* {{{ */
{
ZEND_CLOSURE_PROPERTY_ERROR();
return &EG(uninitialized_zval);
}
/* }}} */

static zval *zend_closure_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */
static zval *zend_closure_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot) /* {{{ */
{
ZEND_CLOSURE_PROPERTY_ERROR();
return value;
}
/* }}} */

static zval *zend_closure_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
static zval *zend_closure_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot) /* {{{ */
{
ZEND_CLOSURE_PROPERTY_ERROR();
return NULL;
}
/* }}} */

static int zend_closure_has_property(zval *object, zval *member, int has_set_exists, void **cache_slot) /* {{{ */
static int zend_closure_has_property(zend_object *object, zend_string *member, int has_set_exists, void **cache_slot) /* {{{ */
{
if (has_set_exists != ZEND_PROPERTY_EXISTS) {
ZEND_CLOSURE_PROPERTY_ERROR();
Expand All @@ -425,7 +425,7 @@ static int zend_closure_has_property(zval *object, zval *member, int has_set_exi
}
/* }}} */

static void zend_closure_unset_property(zval *object, zval *member, void **cache_slot) /* {{{ */
static void zend_closure_unset_property(zend_object *object, zend_string *member, void **cache_slot) /* {{{ */
{
ZEND_CLOSURE_PROPERTY_ERROR();
}
Expand Down Expand Up @@ -461,9 +461,9 @@ static zend_object *zend_closure_new(zend_class_entry *class_type) /* {{{ */
}
/* }}} */

static zend_object *zend_closure_clone(zval *zobject) /* {{{ */
static zend_object *zend_closure_clone(zend_object *zobject) /* {{{ */
{
zend_closure *closure = (zend_closure *)Z_OBJ_P(zobject);
zend_closure *closure = (zend_closure *)zobject;
zval result;

zend_create_closure(&result, &closure->func,
Expand All @@ -472,9 +472,9 @@ static zend_object *zend_closure_clone(zval *zobject) /* {{{ */
}
/* }}} */

int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr) /* {{{ */
int zend_closure_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr) /* {{{ */
{
zend_closure *closure = (zend_closure *)Z_OBJ_P(obj);
zend_closure *closure = (zend_closure *)obj;
*fptr_ptr = &closure->func;
*ce_ptr = closure->called_scope;

Expand All @@ -488,9 +488,9 @@ int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function
}
/* }}} */

static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp) /* {{{ */
static HashTable *zend_closure_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
{
zend_closure *closure = (zend_closure *)Z_OBJ_P(object);
zend_closure *closure = (zend_closure *)object;
zval val;
struct _zend_arg_info *arg_info = closure->func.common.arg_info;
HashTable *debug_info;
Expand Down Expand Up @@ -553,9 +553,9 @@ static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp) /* {{{
}
/* }}} */

static HashTable *zend_closure_get_gc(zval *obj, zval **table, int *n) /* {{{ */
static HashTable *zend_closure_get_gc(zend_object *obj, zval **table, int *n) /* {{{ */
{
zend_closure *closure = (zend_closure *)Z_OBJ_P(obj);
zend_closure *closure = (zend_closure *)obj;

*table = Z_TYPE(closure->this_ptr) != IS_NULL ? &closure->this_ptr : NULL;
*n = Z_TYPE(closure->this_ptr) != IS_NULL ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ ZEND_API ZEND_COLD void zend_exception_error(zend_object *ex, int severity) /* {
zend_string *str, *file = NULL;
zend_long line = 0;

zend_call_method_with_0_params(&exception, ce_exception, &ex->ce->__tostring, "__tostring", &tmp);
zend_call_method_with_0_params(Z_OBJ(exception), ce_exception, &ex->ce->__tostring, "__tostring", &tmp);
if (!EG(exception)) {
if (Z_TYPE(tmp) != IS_STRING) {
zend_error(E_WARNING, "%s::__toString() must return a string", ZSTR_VAL(ce_exception->name));
Expand Down
Loading