From: Nikita Popov Date: Fri, 7 Aug 2020 13:05:24 +0000 (+0200) Subject: Accept zend_object in zend_read_property X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7991fc2753c9c15eeccb2a6384050a21c6ffaa71;p=php Accept zend_object in zend_read_property --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 9906d7b423..bd45b093cf 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -4179,21 +4179,21 @@ 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) /* {{{ */ +ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_bool silent, zval *rv) /* {{{ */ { zval *value; zend_class_entry *old_scope = EG(fake_scope); EG(fake_scope) = scope; - value = Z_OBJ_HT_P(object)->read_property(Z_OBJ_P(object), name, silent?BP_VAR_IS:BP_VAR_R, NULL, rv); + value = object->handlers->read_property(object, name, silent?BP_VAR_IS:BP_VAR_R, NULL, rv); EG(fake_scope) = old_scope; return value; } /* }}} */ -ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_bool silent, zval *rv) /* {{{ */ +ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_bool silent, zval *rv) /* {{{ */ { zval *value; zend_string *str; diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 916a2ab425..4d5de411bf 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -400,8 +400,8 @@ ZEND_API int zend_update_static_property_double(zend_class_entry *scope, const c ZEND_API int zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value); ZEND_API int zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length); -ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zend_bool silent, zval *rv); -ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_bool silent, zval *rv); +ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_bool silent, zval *rv); +ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_bool silent, zval *rv); ZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, zend_bool silent); ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, zend_bool silent); diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index d617bae108..aa0c8e64a4 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -99,16 +99,16 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo ZVAL_OBJ(&zv, exception); ex = &zv; do { - ancestor = zend_read_property_ex(i_get_exception_base(&pv), &pv, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); + ancestor = zend_read_property_ex(i_get_exception_base(&pv), Z_OBJ(pv), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); while (Z_TYPE_P(ancestor) == IS_OBJECT) { if (Z_OBJ_P(ancestor) == Z_OBJ_P(ex)) { OBJ_RELEASE(add_previous); return; } - ancestor = zend_read_property_ex(i_get_exception_base(ancestor), ancestor, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); + ancestor = zend_read_property_ex(i_get_exception_base(ancestor), Z_OBJ_P(ancestor), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); } base_ce = i_get_exception_base(ex); - previous = zend_read_property_ex(base_ce, ex, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); + previous = zend_read_property_ex(base_ce, Z_OBJ_P(ex), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); if (Z_TYPE_P(previous) == IS_NULL) { zend_update_property_ex(base_ce, ex, ZSTR_KNOWN(ZEND_STR_PREVIOUS), &pv); GC_DELREF(add_previous); @@ -309,7 +309,7 @@ ZEND_METHOD(Exception, __construct) /* {{{ Exception unserialize checks */ #define CHECK_EXC_TYPE(id, type) \ - pvalue = zend_read_property_ex(i_get_exception_base(object), (object), ZSTR_KNOWN(id), 1, &value); \ + pvalue = zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &value); \ if (Z_TYPE_P(pvalue) != IS_NULL && Z_TYPE_P(pvalue) != type) { \ zend_unset_property(i_get_exception_base(object), object, ZSTR_VAL(ZSTR_KNOWN(id)), ZSTR_LEN(ZSTR_KNOWN(id))); \ } @@ -375,9 +375,9 @@ ZEND_METHOD(ErrorException, __construct) /* }}} */ #define GET_PROPERTY(object, id) \ - zend_read_property_ex(i_get_exception_base(object), (object), ZSTR_KNOWN(id), 0, &rv) + zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 0, &rv) #define GET_PROPERTY_SILENT(object, id) \ - zend_read_property_ex(i_get_exception_base(object), (object), ZSTR_KNOWN(id), 1, &rv) + zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv) /* {{{ Get the file in which the exception occurred */ ZEND_METHOD(Exception, getFile) @@ -603,7 +603,7 @@ ZEND_METHOD(Exception, getTraceAsString) object = ZEND_THIS; base_ce = i_get_exception_base(object); - trace = zend_read_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_TRACE), 1, &rv); + trace = zend_read_property_ex(base_ce, Z_OBJ_P(object), ZSTR_KNOWN(ZEND_STR_TRACE), 1, &rv); if (EG(exception)) { RETURN_THROWS(); } diff --git a/ext/com_dotnet/com_wrapper.c b/ext/com_dotnet/com_wrapper.c index c4f41a4916..05ffb41f26 100644 --- a/ext/com_dotnet/com_wrapper.c +++ b/ext/com_dotnet/com_wrapper.c @@ -278,7 +278,7 @@ static HRESULT STDMETHODCALLTYPE disp_invokeex( * and expose it as a COM exception */ if (wFlags & DISPATCH_PROPERTYGET) { - retval = zend_read_property(Z_OBJCE(disp->object), &disp->object, Z_STRVAL_P(name), Z_STRLEN_P(name)+1, 1, &rv); + retval = zend_read_property(Z_OBJCE(disp->object), Z_OBJ(disp->object), Z_STRVAL_P(name), Z_STRLEN_P(name)+1, 1, &rv); } else if (wFlags & DISPATCH_PROPERTYPUT) { zend_update_property(Z_OBJCE(disp->object), &disp->object, Z_STRVAL_P(name), Z_STRLEN_P(name), ¶ms[0]); } else if (wFlags & DISPATCH_METHOD) { diff --git a/ext/curl/curl_file.c b/ext/curl/curl_file.c index 7f31451f55..950b670d84 100644 --- a/ext/curl/curl_file.c +++ b/ext/curl/curl_file.c @@ -71,7 +71,7 @@ static void curlfile_get_property(char *name, size_t name_len, INTERNAL_FUNCTION zval *res, rv; ZEND_PARSE_PARAMETERS_NONE(); - res = zend_read_property(curl_CURLFile_class, ZEND_THIS, name, name_len, 1, &rv); + res = zend_read_property(curl_CURLFile_class, Z_OBJ_P(ZEND_THIS), name, name_len, 1, &rv); ZVAL_COPY_DEREF(return_value, res); } diff --git a/ext/curl/interface.c b/ext/curl/interface.c index f8edbefa2f..8621c23b2b 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2047,7 +2047,7 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields curl_seek_callback seekfunc = seek_cb; #endif - prop = zend_read_property(curl_CURLFile_class, current, "name", sizeof("name")-1, 0, &rv); + prop = zend_read_property(curl_CURLFile_class, Z_OBJ_P(current), "name", sizeof("name")-1, 0, &rv); if (Z_TYPE_P(prop) != IS_STRING) { php_error_docref(NULL, E_WARNING, "Invalid filename for key %s", ZSTR_VAL(string_key)); } else { @@ -2057,11 +2057,11 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields return 1; } - prop = zend_read_property(curl_CURLFile_class, current, "mime", sizeof("mime")-1, 0, &rv); + prop = zend_read_property(curl_CURLFile_class, Z_OBJ_P(current), "mime", sizeof("mime")-1, 0, &rv); if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) { type = Z_STRVAL_P(prop); } - prop = zend_read_property(curl_CURLFile_class, current, "postname", sizeof("postname")-1, 0, &rv); + prop = zend_read_property(curl_CURLFile_class, Z_OBJ_P(current), "postname", sizeof("postname")-1, 0, &rv); if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) { filename = Z_STRVAL_P(prop); } diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 054240acd9..8eae00fc03 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -1539,11 +1539,8 @@ static int dom_nodelist_has_dimension(zend_object *object, zval *member, int che if (offset < 0) { return 0; } else { - zval obj; - zval *length; - - ZVAL_OBJ(&obj, object); - length = zend_read_property(object->ce, &obj, "length", sizeof("length") - 1, 0, &rv); + zval *length = zend_read_property( + object->ce, object, "length", sizeof("length") - 1, 0, &rv); return length && offset < Z_LVAL_P(length); } } /* }}} end dom_nodelist_has_dimension */ diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f11198f27d..4d860c2a58 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5316,7 +5316,7 @@ ZEND_METHOD(ReflectionProperty, getValue) RETURN_THROWS(); } - member_p = zend_read_property_ex(intern->ce, object, ref->unmangled_name, 0, &rv); + member_p = zend_read_property_ex(intern->ce, Z_OBJ_P(object), ref->unmangled_name, 0, &rv); if (member_p != &rv) { ZVAL_COPY_DEREF(return_value, member_p); } else { diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 4a7dc2ad80..d189b3f282 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -1170,7 +1170,7 @@ static void set_zval_property(zval* object, char* name, zval* val) static zval* get_zval_property(zval* object, char* name, zval *rv) { if (Z_TYPE_P(object) == IS_OBJECT) { - zval *data = zend_read_property(Z_OBJCE_P(object), object, name, strlen(name), 1, rv); + zval *data = zend_read_property(Z_OBJCE_P(object), Z_OBJ_P(object), name, strlen(name), 1, rv); if (data == &EG(uninitialized_zval)) { return NULL; } diff --git a/ext/soap/soap.c b/ext/soap/soap.c index af9b26161f..8dc05c3802 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -643,10 +643,10 @@ PHP_METHOD(SoapFault, __toString) } this_ptr = ZEND_THIS; - faultcode = zend_read_property(soap_fault_class_entry, this_ptr, "faultcode", sizeof("faultcode")-1, 1, &rv1); - faultstring = zend_read_property(soap_fault_class_entry, this_ptr, "faultstring", sizeof("faultstring")-1, 1, &rv2); - file = zend_read_property(soap_fault_class_entry, this_ptr, "file", sizeof("file")-1, 1, &rv3); - line = zend_read_property(soap_fault_class_entry, this_ptr, "line", sizeof("line")-1, 1, &rv4); + faultcode = zend_read_property(soap_fault_class_entry, Z_OBJ_P(this_ptr), "faultcode", sizeof("faultcode")-1, 1, &rv1); + faultstring = zend_read_property(soap_fault_class_entry, Z_OBJ_P(this_ptr), "faultstring", sizeof("faultstring")-1, 1, &rv2); + file = zend_read_property(soap_fault_class_entry, Z_OBJ_P(this_ptr), "file", sizeof("file")-1, 1, &rv3); + line = zend_read_property(soap_fault_class_entry, Z_OBJ_P(this_ptr), "line", sizeof("line")-1, 1, &rv4); zend_call_method_with_0_params( Z_OBJ_P(ZEND_THIS), Z_OBJCE_P(ZEND_THIS), NULL, "gettraceasstring", &trace); @@ -1176,7 +1176,7 @@ static void _soap_server_exception(soapServicePtr service, sdlFunctionPtr functi } else if (instanceof_function(Z_OBJCE(exception_object), zend_ce_error)) { if (service->send_errors) { zval rv; - zend_string *msg = zval_get_string(zend_read_property(zend_ce_error, &exception_object, "message", sizeof("message")-1, 0, &rv)); + zend_string *msg = zval_get_string(zend_read_property(zend_ce_error, Z_OBJ(exception_object), "message", sizeof("message")-1, 0, &rv)); add_soap_fault_ex(&exception_object, this_ptr, "Server", ZSTR_VAL(msg), NULL, NULL); zend_string_release_ex(msg, 0); } else { @@ -2241,7 +2241,7 @@ static int do_request(zval *this_ptr, xmlDoc *request, char *location, char *act zval exception_object; ZVAL_OBJ(&exception_object, EG(exception)); - msg = zval_get_string(zend_read_property(zend_ce_error, &exception_object, "message", sizeof("message")-1, 0, &rv)); + msg = zval_get_string(zend_read_property(zend_ce_error, Z_OBJ(exception_object), "message", sizeof("message")-1, 0, &rv)); /* change class */ EG(exception)->ce = soap_fault_class_entry; set_soap_fault(&exception_object, NULL, "Client", ZSTR_VAL(msg), NULL, NULL, NULL); diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 93f1297c74..ecb11d5f38 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -99,7 +99,7 @@ static void sodium_remove_param_values_from_backtrace(zend_object *obj) { zval obj_zv, rv, *trace; ZVAL_OBJ(&obj_zv, obj); - trace = zend_read_property(zend_get_exception_base(&obj_zv), &obj_zv, "trace", sizeof("trace")-1, 0, &rv); + trace = zend_read_property(zend_get_exception_base(&obj_zv), Z_OBJ(obj_zv), "trace", sizeof("trace")-1, 0, &rv); if (trace && Z_TYPE_P(trace) == IS_ARRAY) { zval *frame; ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(trace), frame) { diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index c71f3cb142..2410050586 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -1863,7 +1863,7 @@ PHP_METHOD(RegexIterator, accept) break; case REGIT_MODE_REPLACE: { - zval *replacement = zend_read_property(intern->std.ce, ZEND_THIS, "replacement", sizeof("replacement")-1, 1, &rv); + zval *replacement = zend_read_property(intern->std.ce, Z_OBJ_P(ZEND_THIS), "replacement", sizeof("replacement")-1, 1, &rv); zend_string *replacement_str = zval_try_get_string(replacement); if (UNEXPECTED(!replacement_str)) { return; diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 845312e9c6..4874e0920c 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1067,12 +1067,10 @@ static int do_cli(int argc, char **argv) /* {{{ */ pce->constructor, Z_OBJ(ref), NULL, &arg); if (EG(exception)) { - zval tmp, *msg, rv; - - ZVAL_OBJ(&tmp, EG(exception)); - msg = zend_read_property(zend_ce_exception, &tmp, "message", sizeof("message")-1, 0, &rv); + zval rv; + zval *msg = zend_read_property(zend_ce_exception, EG(exception), "message", sizeof("message")-1, 0, &rv); zend_printf("Exception: %s\n", Z_STRVAL_P(msg)); - zval_ptr_dtor(&tmp); + zend_object_release(EG(exception)); EG(exception) = NULL; } else { zend_print_zval(&ref, 0); diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 9977adad4c..7647859222 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -726,8 +726,8 @@ static inline void phpdbg_handle_exception(void) /* {{{ */ ZVAL_OBJ(&zv, ex); zend_call_known_instance_method_with_0_params(ex->ce->__tostring, ex, &tmp); - file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("file"), 1, &rv)); - line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv)); + file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("file"), 1, &rv)); + line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("line"), 1, &rv)); if (EG(exception)) { EG(exception) = NULL; @@ -735,7 +735,7 @@ static inline void phpdbg_handle_exception(void) /* {{{ */ } else { zend_update_property_string(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), Z_STRVAL(tmp)); zval_ptr_dtor(&tmp); - msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), 1, &rv)); + msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("string"), 1, &rv)); } phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT, ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line); @@ -1740,9 +1740,9 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ PHPDBG_G(handled_exception) = exception; ZVAL_OBJ(&zv, exception); - file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("file"), 1, &rv)); - line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv)); - msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("message"), 1, &rv)); + file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("file"), 1, &rv)); + line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("line"), 1, &rv)); + msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("message"), 1, &rv)); phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"",