Skip to content

Commit

Permalink
Accept zend_object in zend_read_property
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Aug 7, 2020
1 parent 0400d07 commit 7991fc2
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))); \
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion ext/com_dotnet/com_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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), &params[0]);
} else if (wFlags & DISPATCH_METHOD) {
Expand Down
2 changes: 1 addition & 1 deletion ext/curl/curl_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
7 changes: 2 additions & 5 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ext/soap/php_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ext/sodium/libsodium.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions sapi/phpdbg/phpdbg_prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,16 +726,16 @@ 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;
msg = ZSTR_EMPTY_ALLOC();
} 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);
Expand Down Expand Up @@ -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 "\"",
Expand Down

0 comments on commit 7991fc2

Please sign in to comment.