From 44a8fc42ebf62a4c89b4107f5f3d0fc74b84f6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 15 Sep 2025 22:57:42 +0200 Subject: [PATCH 1/5] uri: Inline `uri_internal_from_obj()` and `Z_URI_INTERNAL_P()` Changes performed with Coccinelle with some minor adjustments in places where it choked due to macros: @@ expression e; @@ - Z_URI_INTERNAL_P(e) + &Z_URI_OBJECT_P(e)->internal @@ expression e; @@ - uri_internal_from_obj(e) + &uri_object_from_obj(e)->internal --- ext/uri/php_uri.c | 14 +++++++------- ext/uri/php_uri_common.c | 6 +++--- ext/uri/php_uri_common.h | 5 ----- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 67de8110702d2..ce74b91405813 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -531,7 +531,7 @@ static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, php_uri_componen { ZEND_PARSE_PARAMETERS_NONE(); - uri_internal_t *internal_uri = Z_URI_INTERNAL_P(ZEND_THIS); + uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; URI_ASSERT_INITIALIZATION(internal_uri); if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_read(internal_uri->uri, read_mode, return_value) == FAILURE)) { @@ -566,7 +566,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) } zend_object *old_object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = Z_URI_INTERNAL_P(ZEND_THIS); + uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; URI_ASSERT_INITIALIZATION(internal_uri); zend_object *new_object = old_object->handlers->clone_obj(old_object); @@ -578,7 +578,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) * case of an exception being thrown. */ RETVAL_OBJ(new_object); - uri_internal_t *new_internal_uri = uri_internal_from_obj(new_object); + uri_internal_t *new_internal_uri = &uri_object_from_obj(new_object)->internal; URI_ASSERT_INITIALIZATION(new_internal_uri); if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_write(new_internal_uri->uri, &zv, NULL) == FAILURE)) { @@ -823,7 +823,7 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) ZEND_PARSE_PARAMETERS_END(); zend_object *object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = uri_internal_from_obj(object); + uri_internal_t *internal_uri = &uri_object_from_obj(object)->internal; if (internal_uri->uri != NULL) { /* Intentionally throw two exceptions for proper chaining. */ zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(object->ce->name)); @@ -944,7 +944,7 @@ PHP_METHOD(Uri_WhatWg_Url, toUnicodeString) ZEND_PARSE_PARAMETERS_NONE(); zend_object *this_object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = uri_internal_from_obj(this_object); + uri_internal_t *internal_uri = &uri_object_from_obj(this_object)->internal; URI_ASSERT_INITIALIZATION(internal_uri); RETURN_STR(internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE, false)); @@ -955,7 +955,7 @@ PHP_METHOD(Uri_WhatWg_Url, toAsciiString) ZEND_PARSE_PARAMETERS_NONE(); zend_object *this_object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = uri_internal_from_obj(this_object); + uri_internal_t *internal_uri = &uri_object_from_obj(this_object)->internal; URI_ASSERT_INITIALIZATION(internal_uri); RETURN_STR(internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false)); @@ -1056,7 +1056,7 @@ PHPAPI void php_uri_object_handler_free(zend_object *object) PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object) { uri_object_t *uri_object = uri_object_from_obj(object); - uri_internal_t *internal_uri = uri_internal_from_obj(object); + uri_internal_t *internal_uri = &uri_object_from_obj(object)->internal; URI_ASSERT_INITIALIZATION(internal_uri); diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c index c4ee94b4d5b98..be02db22be9ff 100644 --- a/ext/uri/php_uri_common.c +++ b/ext/uri/php_uri_common.c @@ -46,7 +46,7 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name prop { ZEND_PARSE_PARAMETERS_NONE(); - uri_internal_t *internal_uri = Z_URI_INTERNAL_P(ZEND_THIS); + uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; URI_ASSERT_INITIALIZATION(internal_uri); const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name); @@ -60,7 +60,7 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name prop static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, zval *property_zv) { zend_object *old_object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = Z_URI_INTERNAL_P(ZEND_THIS); + uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; URI_ASSERT_INITIALIZATION(internal_uri); zend_object *new_object = old_object->handlers->clone_obj(old_object); @@ -74,7 +74,7 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_propert const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name); - uri_internal_t *new_internal_uri = uri_internal_from_obj(new_object); + uri_internal_t *new_internal_uri = &uri_object_from_obj(new_object)->internal; URI_ASSERT_INITIALIZATION(new_internal_uri); if (UNEXPECTED(property_handler->write == NULL)) { zend_readonly_property_modification_error_ex(ZSTR_VAL(old_object->ce->name), diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index 2e2f9ce6452f7..e9b292f150fe6 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -151,12 +151,7 @@ static inline uri_object_t *uri_object_from_obj(zend_object *object) { return (uri_object_t*)((char*)(object) - XtOffsetOf(uri_object_t, std)); } -static inline uri_internal_t *uri_internal_from_obj(zend_object *object) { - return &(uri_object_from_obj(object)->internal); -} - #define Z_URI_OBJECT_P(zv) uri_object_from_obj(Z_OBJ_P((zv))) -#define Z_URI_INTERNAL_P(zv) uri_internal_from_obj(Z_OBJ_P((zv))) PHPAPI uri_object_t *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser); PHPAPI void php_uri_object_handler_free(zend_object *object); From 17fdc22e1ce00cbfb1f9c83e3de4d108d96edf14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 15 Sep 2025 23:08:29 +0200 Subject: [PATCH 2/5] uri: Inline definition of `URI_ASSERT_INITIALIZATION()` While a `NULL` pointer to `zend_object` would result in `->internal` also sitting at `0`, this is not a particularly useful assertion to have. Instead just assert that we have a parsed `->uri` available. Changes made with Coccinelle + some manual adjustments: @@ uri_internal_t *u; expression e; @@ u = &Z_URI_OBJECT_P(e)->internal ... when != u - URI_ASSERT_INITIALIZATION(u); + ZEND_ASSERT(u->uri != NULL); @@ uri_internal_t *u; expression e; @@ u = &uri_object_from_obj(e)->internal ... when != u - URI_ASSERT_INITIALIZATION(u); + ZEND_ASSERT(u->uri != NULL); --- ext/uri/php_uri.c | 26 +++++++++++++------------- ext/uri/php_uri_common.c | 6 +++--- ext/uri/php_uri_common.h | 4 ---- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index ce74b91405813..6e07365443894 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -346,7 +346,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri( if (base_url_object != NULL) { ZEND_ASSERT(base_url_object->std.ce == uri_object->std.ce); const uri_internal_t *internal_base_url = &base_url_object->internal; - URI_ASSERT_INITIALIZATION(internal_base_url); + ZEND_ASSERT(internal_base_url->uri != NULL); ZEND_ASSERT(internal_base_url->parser == uri_parser); base_url = internal_base_url->uri; } @@ -532,7 +532,7 @@ static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, php_uri_componen ZEND_PARSE_PARAMETERS_NONE(); uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_read(internal_uri->uri, read_mode, return_value) == FAILURE)) { zend_throw_error(NULL, "The userinfo component cannot be retrieved"); @@ -567,7 +567,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) zend_object *old_object = Z_OBJ_P(ZEND_THIS); uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); zend_object *new_object = old_object->handlers->clone_obj(old_object); if (new_object == NULL) { @@ -579,7 +579,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) RETVAL_OBJ(new_object); uri_internal_t *new_internal_uri = &uri_object_from_obj(new_object)->internal; - URI_ASSERT_INITIALIZATION(new_internal_uri); + ZEND_ASSERT(new_internal_uri->uri != NULL); if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_write(new_internal_uri->uri, &zv, NULL) == FAILURE)) { RETURN_THROWS(); @@ -685,10 +685,10 @@ static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, uri_object_t *that_object, { uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); uri_internal_t *this_internal_uri = &this_object->internal; - URI_ASSERT_INITIALIZATION(this_internal_uri); + ZEND_ASSERT(this_internal_uri->uri != NULL); uri_internal_t *that_internal_uri = &that_object->internal; - URI_ASSERT_INITIALIZATION(that_internal_uri); + ZEND_ASSERT(that_internal_uri->uri != NULL); if (this_object->std.ce != that_object->std.ce && !instanceof_function(this_object->std.ce, that_object->std.ce) && @@ -744,7 +744,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, toRawString) uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); uri_internal_t *internal_uri = &this_object->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); if (uri_str == NULL) { @@ -761,7 +761,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, toString) uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); uri_internal_t *internal_uri = &this_object->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, false); if (uri_str == NULL) { @@ -790,7 +790,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize) uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); uri_internal_t *internal_uri = &this_object->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); /* Serialize state: "uri" key in the first array */ zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); @@ -945,7 +945,7 @@ PHP_METHOD(Uri_WhatWg_Url, toUnicodeString) zend_object *this_object = Z_OBJ_P(ZEND_THIS); uri_internal_t *internal_uri = &uri_object_from_obj(this_object)->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); RETURN_STR(internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE, false)); } @@ -956,7 +956,7 @@ PHP_METHOD(Uri_WhatWg_Url, toAsciiString) zend_object *this_object = Z_OBJ_P(ZEND_THIS); uri_internal_t *internal_uri = &uri_object_from_obj(this_object)->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); RETURN_STR(internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false)); } @@ -982,7 +982,7 @@ PHP_METHOD(Uri_WhatWg_Url, __serialize) uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); uri_internal_t *internal_uri = &this_object->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); /* Serialize state: "uri" key in the first array */ zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); @@ -1058,7 +1058,7 @@ PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object) uri_object_t *uri_object = uri_object_from_obj(object); uri_internal_t *internal_uri = &uri_object_from_obj(object)->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); uri_object_t *new_uri_object = uri_object_from_obj(object->ce->create_object(object->ce)); ZEND_ASSERT(new_uri_object->internal.parser == internal_uri->parser); diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c index be02db22be9ff..2ed9d0bad18d0 100644 --- a/ext/uri/php_uri_common.c +++ b/ext/uri/php_uri_common.c @@ -47,7 +47,7 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name prop ZEND_PARSE_PARAMETERS_NONE(); uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name); @@ -61,7 +61,7 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_propert { zend_object *old_object = Z_OBJ_P(ZEND_THIS); uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; - URI_ASSERT_INITIALIZATION(internal_uri); + ZEND_ASSERT(internal_uri->uri != NULL); zend_object *new_object = old_object->handlers->clone_obj(old_object); if (new_object == NULL) { @@ -75,7 +75,7 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_propert const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name); uri_internal_t *new_internal_uri = &uri_object_from_obj(new_object)->internal; - URI_ASSERT_INITIALIZATION(new_internal_uri); + ZEND_ASSERT(new_internal_uri->uri != NULL); if (UNEXPECTED(property_handler->write == NULL)) { zend_readonly_property_modification_error_ex(ZSTR_VAL(old_object->ce->name), ZSTR_VAL(get_known_string_by_property_name(property_name))); diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index e9b292f150fe6..85ba441986a25 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -190,8 +190,4 @@ void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name void uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name); void uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name); -#define URI_ASSERT_INITIALIZATION(internal_uri) do { \ - ZEND_ASSERT(internal_uri != NULL && internal_uri->uri != NULL); \ -} while (0) - #endif From ff8418bded16442b9bf88bbf48e887441ba69e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 15 Sep 2025 23:31:49 +0200 Subject: [PATCH 3/5] uri: Inline `parser` and `uri` into `uri_object_t` After this, `uri_internal_t` will only be used when interacting with the URI parsers without having a full-blown URI object. Changes made with Coccinelle and some manual adjustments: @@ identifier u; expression e; @@ - uri_internal_t *u = &e->internal; + uri_object_t *u = e; @@ uri_object_t *u; identifier t; @@ - u->internal.t + u->t --- ext/uri/php_uri.c | 81 +++++++++++++++++----------------------- ext/uri/php_uri_common.c | 6 +-- ext/uri/php_uri_common.h | 3 +- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 6e07365443894..8d69c9eb1c41a 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -53,14 +53,11 @@ static zend_array uri_parsers; static HashTable *uri_get_debug_properties(uri_object_t *object) { - uri_internal_t *internal_uri = &object->internal; - ZEND_ASSERT(internal_uri != NULL); - const HashTable *std_properties = zend_std_get_properties(&object->std); HashTable *result = zend_array_dup(std_properties); - const php_uri_parser * const parser = internal_uri->parser; - void * const uri = internal_uri->uri; + const php_uri_parser * const parser = object->parser; + void * const uri = object->uri; if (UNEXPECTED(uri == NULL)) { return result; @@ -324,7 +321,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri( uri_object_t *uri_object; if (should_update_this_object) { uri_object = Z_URI_OBJECT_P(ZEND_THIS); - if (uri_object->internal.uri != NULL) { + if (uri_object->uri != NULL) { zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); RETURN_THROWS(); } @@ -337,7 +334,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri( uri_object = Z_URI_OBJECT_P(return_value); } - const php_uri_parser *uri_parser = uri_object->internal.parser; + const php_uri_parser *uri_parser = uri_object->parser; zval errors; ZVAL_UNDEF(&errors); @@ -345,10 +342,9 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri( void *base_url = NULL; if (base_url_object != NULL) { ZEND_ASSERT(base_url_object->std.ce == uri_object->std.ce); - const uri_internal_t *internal_base_url = &base_url_object->internal; - ZEND_ASSERT(internal_base_url->uri != NULL); - ZEND_ASSERT(internal_base_url->parser == uri_parser); - base_url = internal_base_url->uri; + ZEND_ASSERT(base_url_object->uri != NULL); + ZEND_ASSERT(base_url_object->parser == uri_parser); + base_url = base_url_object->uri; } void *uri = uri_parser->parse(ZSTR_VAL(uri_str), ZSTR_LEN(uri_str), base_url, errors_zv != NULL ? &errors : NULL, !should_throw); @@ -370,7 +366,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri( RETURN_THROWS(); } - uri_object->internal.uri = uri; + uri_object->uri = uri; } static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor) @@ -531,7 +527,7 @@ static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, php_uri_componen { ZEND_PARSE_PARAMETERS_NONE(); - uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; + uri_object_t *internal_uri = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(internal_uri->uri != NULL); if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_read(internal_uri->uri, read_mode, return_value) == FAILURE)) { @@ -566,7 +562,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) } zend_object *old_object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; + uri_object_t *internal_uri = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(internal_uri->uri != NULL); zend_object *new_object = old_object->handlers->clone_obj(old_object); @@ -578,7 +574,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) * case of an exception being thrown. */ RETVAL_OBJ(new_object); - uri_internal_t *new_internal_uri = &uri_object_from_obj(new_object)->internal; + uri_object_t *new_internal_uri = uri_object_from_obj(new_object); ZEND_ASSERT(new_internal_uri->uri != NULL); if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_write(new_internal_uri->uri, &zv, NULL) == FAILURE)) { @@ -684,11 +680,8 @@ static void throw_cannot_recompose_uri_to_string(uri_object_t *object) static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, uri_object_t *that_object, zend_object *comparison_mode) { uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); - uri_internal_t *this_internal_uri = &this_object->internal; - ZEND_ASSERT(this_internal_uri->uri != NULL); - - uri_internal_t *that_internal_uri = &that_object->internal; - ZEND_ASSERT(that_internal_uri->uri != NULL); + ZEND_ASSERT(this_object->uri != NULL); + ZEND_ASSERT(that_object->uri != NULL); if (this_object->std.ce != that_object->std.ce && !instanceof_function(this_object->std.ce, that_object->std.ce) && @@ -703,15 +696,15 @@ static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, uri_object_t *that_object, exclude_fragment = zend_string_equals_literal(Z_STR_P(case_name), "ExcludeFragment"); } - zend_string *this_str = this_internal_uri->parser->to_string( - this_internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, exclude_fragment); + zend_string *this_str = this_object->parser->to_string( + this_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, exclude_fragment); if (this_str == NULL) { throw_cannot_recompose_uri_to_string(this_object); RETURN_THROWS(); } - zend_string *that_str = that_internal_uri->parser->to_string( - that_internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, exclude_fragment); + zend_string *that_str = that_object->parser->to_string( + that_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, exclude_fragment); if (that_str == NULL) { zend_string_release(this_str); throw_cannot_recompose_uri_to_string(that_object); @@ -743,10 +736,9 @@ PHP_METHOD(Uri_Rfc3986_Uri, toRawString) ZEND_PARSE_PARAMETERS_NONE(); uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); - uri_internal_t *internal_uri = &this_object->internal; - ZEND_ASSERT(internal_uri->uri != NULL); + ZEND_ASSERT(this_object->uri != NULL); - zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); + zend_string *uri_str = this_object->parser->to_string(this_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); if (uri_str == NULL) { throw_cannot_recompose_uri_to_string(this_object); RETURN_THROWS(); @@ -760,10 +752,9 @@ PHP_METHOD(Uri_Rfc3986_Uri, toString) ZEND_PARSE_PARAMETERS_NONE(); uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); - uri_internal_t *internal_uri = &this_object->internal; - ZEND_ASSERT(internal_uri->uri != NULL); + ZEND_ASSERT(this_object->uri != NULL); - zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, false); + zend_string *uri_str = this_object->parser->to_string(this_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, false); if (uri_str == NULL) { throw_cannot_recompose_uri_to_string(this_object); RETURN_THROWS(); @@ -789,11 +780,10 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize) ZEND_PARSE_PARAMETERS_NONE(); uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); - uri_internal_t *internal_uri = &this_object->internal; - ZEND_ASSERT(internal_uri->uri != NULL); + ZEND_ASSERT(this_object->uri != NULL); /* Serialize state: "uri" key in the first array */ - zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); + zend_string *uri_str = this_object->parser->to_string(this_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); if (uri_str == NULL) { throw_cannot_recompose_uri_to_string(this_object); RETURN_THROWS(); @@ -823,7 +813,7 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) ZEND_PARSE_PARAMETERS_END(); zend_object *object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = &uri_object_from_obj(object)->internal; + uri_object_t *internal_uri = uri_object_from_obj(object); if (internal_uri->uri != NULL) { /* Intentionally throw two exceptions for proper chaining. */ zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(object->ce->name)); @@ -944,7 +934,7 @@ PHP_METHOD(Uri_WhatWg_Url, toUnicodeString) ZEND_PARSE_PARAMETERS_NONE(); zend_object *this_object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = &uri_object_from_obj(this_object)->internal; + uri_object_t *internal_uri = uri_object_from_obj(this_object); ZEND_ASSERT(internal_uri->uri != NULL); RETURN_STR(internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE, false)); @@ -955,7 +945,7 @@ PHP_METHOD(Uri_WhatWg_Url, toAsciiString) ZEND_PARSE_PARAMETERS_NONE(); zend_object *this_object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = &uri_object_from_obj(this_object)->internal; + uri_object_t *internal_uri = uri_object_from_obj(this_object); ZEND_ASSERT(internal_uri->uri != NULL); RETURN_STR(internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false)); @@ -981,11 +971,10 @@ PHP_METHOD(Uri_WhatWg_Url, __serialize) ZEND_PARSE_PARAMETERS_NONE(); uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); - uri_internal_t *internal_uri = &this_object->internal; - ZEND_ASSERT(internal_uri->uri != NULL); + ZEND_ASSERT(this_object->uri != NULL); /* Serialize state: "uri" key in the first array */ - zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); + zend_string *uri_str = this_object->parser->to_string(this_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); if (uri_str == NULL) { throw_cannot_recompose_uri_to_string(this_object); RETURN_THROWS(); @@ -1027,10 +1016,8 @@ PHPAPI uri_object_t *php_uri_object_create(zend_class_entry *class_type, const p zend_object_std_init(&uri_object->std, class_type); object_properties_init(&uri_object->std, class_type); - uri_object->internal = (uri_internal_t){ - .parser = parser, - .uri = NULL, - }; + uri_object->parser = parser; + uri_object->uri = NULL; return uri_object; } @@ -1049,24 +1036,24 @@ PHPAPI void php_uri_object_handler_free(zend_object *object) { uri_object_t *uri_object = uri_object_from_obj(object); - uri_object->internal.parser->destroy(uri_object->internal.uri); + uri_object->parser->destroy(uri_object->uri); zend_object_std_dtor(&uri_object->std); } PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object) { uri_object_t *uri_object = uri_object_from_obj(object); - uri_internal_t *internal_uri = &uri_object_from_obj(object)->internal; + uri_object_t *internal_uri = uri_object_from_obj(object); ZEND_ASSERT(internal_uri->uri != NULL); uri_object_t *new_uri_object = uri_object_from_obj(object->ce->create_object(object->ce)); - ZEND_ASSERT(new_uri_object->internal.parser == internal_uri->parser); + ZEND_ASSERT(new_uri_object->parser == internal_uri->parser); void *uri = internal_uri->parser->clone(internal_uri->uri); ZEND_ASSERT(uri != NULL); - new_uri_object->internal.uri = uri; + new_uri_object->uri = uri; zend_objects_clone_members(&new_uri_object->std, &uri_object->std); diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c index 2ed9d0bad18d0..402ae06739031 100644 --- a/ext/uri/php_uri_common.c +++ b/ext/uri/php_uri_common.c @@ -46,7 +46,7 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name prop { ZEND_PARSE_PARAMETERS_NONE(); - uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; + uri_object_t *internal_uri = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(internal_uri->uri != NULL); const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name); @@ -60,7 +60,7 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name prop static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, zval *property_zv) { zend_object *old_object = Z_OBJ_P(ZEND_THIS); - uri_internal_t *internal_uri = &Z_URI_OBJECT_P(ZEND_THIS)->internal; + uri_object_t *internal_uri = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(internal_uri->uri != NULL); zend_object *new_object = old_object->handlers->clone_obj(old_object); @@ -74,7 +74,7 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_propert const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name); - uri_internal_t *new_internal_uri = &uri_object_from_obj(new_object)->internal; + uri_object_t *new_internal_uri = uri_object_from_obj(new_object); ZEND_ASSERT(new_internal_uri->uri != NULL); if (UNEXPECTED(property_handler->write == NULL)) { zend_readonly_property_modification_error_ex(ZSTR_VAL(old_object->ce->name), diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index 85ba441986a25..52d80a290bb4d 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -143,7 +143,8 @@ typedef struct uri_internal_t { } uri_internal_t; typedef struct uri_object_t { - uri_internal_t internal; + const php_uri_parser *parser; + void *uri; zend_object std; } uri_object_t; From 9997637a45e5f833444b4ba726b92604aa2cc33a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 15 Sep 2025 23:38:51 +0200 Subject: [PATCH 4/5] uri: Fix outdated `internal` naming for `uri_object_t` --- ext/uri/php_uri.c | 43 ++++++++++++++++++++-------------------- ext/uri/php_uri_common.c | 8 ++++---- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 8d69c9eb1c41a..393743b3d9100 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -527,10 +527,10 @@ static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, php_uri_componen { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *internal_uri = Z_URI_OBJECT_P(ZEND_THIS); - ZEND_ASSERT(internal_uri->uri != NULL); + uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + ZEND_ASSERT(uri_object->uri != NULL); - if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_read(internal_uri->uri, read_mode, return_value) == FAILURE)) { + if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_read(uri_object->uri, read_mode, return_value) == FAILURE)) { zend_throw_error(NULL, "The userinfo component cannot be retrieved"); RETURN_THROWS(); } @@ -562,8 +562,8 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) } zend_object *old_object = Z_OBJ_P(ZEND_THIS); - uri_object_t *internal_uri = Z_URI_OBJECT_P(ZEND_THIS); - ZEND_ASSERT(internal_uri->uri != NULL); + uri_object_t *old_uri_object = uri_object_from_obj(old_object); + ZEND_ASSERT(old_uri_object->uri != NULL); zend_object *new_object = old_object->handlers->clone_obj(old_object); if (new_object == NULL) { @@ -574,10 +574,10 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) * case of an exception being thrown. */ RETVAL_OBJ(new_object); - uri_object_t *new_internal_uri = uri_object_from_obj(new_object); - ZEND_ASSERT(new_internal_uri->uri != NULL); + uri_object_t *new_uri_object = uri_object_from_obj(new_object); + ZEND_ASSERT(new_uri_object->uri != NULL); - if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_write(new_internal_uri->uri, &zv, NULL) == FAILURE)) { + if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_write(new_uri_object->uri, &zv, NULL) == FAILURE)) { RETURN_THROWS(); } } @@ -813,8 +813,8 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) ZEND_PARSE_PARAMETERS_END(); zend_object *object = Z_OBJ_P(ZEND_THIS); - uri_object_t *internal_uri = uri_object_from_obj(object); - if (internal_uri->uri != NULL) { + uri_object_t *uri_object = uri_object_from_obj(object); + if (uri_object->uri != NULL) { /* Intentionally throw two exceptions for proper chaining. */ zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(object->ce->name)); zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); @@ -846,8 +846,8 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) RETURN_THROWS(); } - internal_uri->uri = internal_uri->parser->parse(Z_STRVAL_P(uri_zv), Z_STRLEN_P(uri_zv), NULL, NULL, true); - if (internal_uri->uri == NULL) { + uri_object->uri = uri_object->parser->parse(Z_STRVAL_P(uri_zv), Z_STRLEN_P(uri_zv), NULL, NULL, true); + if (uri_object->uri == NULL) { zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); RETURN_THROWS(); } @@ -934,10 +934,10 @@ PHP_METHOD(Uri_WhatWg_Url, toUnicodeString) ZEND_PARSE_PARAMETERS_NONE(); zend_object *this_object = Z_OBJ_P(ZEND_THIS); - uri_object_t *internal_uri = uri_object_from_obj(this_object); - ZEND_ASSERT(internal_uri->uri != NULL); + uri_object_t *uri_object = uri_object_from_obj(this_object); + ZEND_ASSERT(uri_object->uri != NULL); - RETURN_STR(internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE, false)); + RETURN_STR(uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE, false)); } PHP_METHOD(Uri_WhatWg_Url, toAsciiString) @@ -945,10 +945,10 @@ PHP_METHOD(Uri_WhatWg_Url, toAsciiString) ZEND_PARSE_PARAMETERS_NONE(); zend_object *this_object = Z_OBJ_P(ZEND_THIS); - uri_object_t *internal_uri = uri_object_from_obj(this_object); - ZEND_ASSERT(internal_uri->uri != NULL); + uri_object_t *uri_object = uri_object_from_obj(this_object); + ZEND_ASSERT(uri_object->uri != NULL); - RETURN_STR(internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false)); + RETURN_STR(uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false)); } PHP_METHOD(Uri_WhatWg_Url, resolve) @@ -1043,14 +1043,13 @@ PHPAPI void php_uri_object_handler_free(zend_object *object) PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object) { uri_object_t *uri_object = uri_object_from_obj(object); - uri_object_t *internal_uri = uri_object_from_obj(object); - ZEND_ASSERT(internal_uri->uri != NULL); + ZEND_ASSERT(uri_object->uri != NULL); uri_object_t *new_uri_object = uri_object_from_obj(object->ce->create_object(object->ce)); - ZEND_ASSERT(new_uri_object->parser == internal_uri->parser); + ZEND_ASSERT(new_uri_object->parser == uri_object->parser); - void *uri = internal_uri->parser->clone(internal_uri->uri); + void *uri = uri_object->parser->clone(uri_object->uri); ZEND_ASSERT(uri != NULL); new_uri_object->uri = uri; diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c index 402ae06739031..c558799b4c00c 100644 --- a/ext/uri/php_uri_common.c +++ b/ext/uri/php_uri_common.c @@ -46,12 +46,12 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name prop { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *internal_uri = Z_URI_OBJECT_P(ZEND_THIS); - ZEND_ASSERT(internal_uri->uri != NULL); + uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + ZEND_ASSERT(uri_object->uri != NULL); - const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name); + const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(uri_object->parser, property_name); - if (UNEXPECTED(property_handler->read(internal_uri->uri, component_read_mode, return_value) == FAILURE)) { + if (UNEXPECTED(property_handler->read(uri_object->uri, component_read_mode, return_value) == FAILURE)) { zend_throw_exception_ex(uri_error_ce, 0, "The %s component cannot be retrieved", ZSTR_VAL(get_known_string_by_property_name(property_name))); RETURN_THROWS(); } From 1f9d9ecc84770b19aa98c2167a211ee1a0c3ff20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 16 Sep 2025 00:14:59 +0200 Subject: [PATCH 5/5] uri: Clean up naming of `uri_object_t` variables --- ext/uri/php_uri.c | 52 +++++++++++++++++++--------------------- ext/uri/php_uri_common.c | 17 +++++++------ 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 393743b3d9100..10660888781de 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -561,11 +561,10 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) ZVAL_STR(&zv, value); } - zend_object *old_object = Z_OBJ_P(ZEND_THIS); - uri_object_t *old_uri_object = uri_object_from_obj(old_object); + uri_object_t *old_uri_object = uri_object_from_obj(Z_OBJ_P(ZEND_THIS)); ZEND_ASSERT(old_uri_object->uri != NULL); - zend_object *new_object = old_object->handlers->clone_obj(old_object); + zend_object *new_object = old_uri_object->std.handlers->clone_obj(&old_uri_object->std); if (new_object == NULL) { RETURN_THROWS(); } @@ -735,12 +734,12 @@ PHP_METHOD(Uri_Rfc3986_Uri, toRawString) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); - ZEND_ASSERT(this_object->uri != NULL); + uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + ZEND_ASSERT(uri_object->uri != NULL); - zend_string *uri_str = this_object->parser->to_string(this_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); + zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); if (uri_str == NULL) { - throw_cannot_recompose_uri_to_string(this_object); + throw_cannot_recompose_uri_to_string(uri_object); RETURN_THROWS(); } @@ -751,12 +750,12 @@ PHP_METHOD(Uri_Rfc3986_Uri, toString) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); - ZEND_ASSERT(this_object->uri != NULL); + uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + ZEND_ASSERT(uri_object->uri != NULL); - zend_string *uri_str = this_object->parser->to_string(this_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, false); + zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, false); if (uri_str == NULL) { - throw_cannot_recompose_uri_to_string(this_object); + throw_cannot_recompose_uri_to_string(uri_object); RETURN_THROWS(); } @@ -779,13 +778,13 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); - ZEND_ASSERT(this_object->uri != NULL); + uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + ZEND_ASSERT(uri_object->uri != NULL); /* Serialize state: "uri" key in the first array */ - zend_string *uri_str = this_object->parser->to_string(this_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); + zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); if (uri_str == NULL) { - throw_cannot_recompose_uri_to_string(this_object); + throw_cannot_recompose_uri_to_string(uri_object); RETURN_THROWS(); } zval tmp; @@ -799,7 +798,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize) zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr); /* Serialize regular properties: second array */ - ZVAL_ARR(&arr, this_object->std.handlers->get_properties(&this_object->std)); + ZVAL_ARR(&arr, uri_object->std.handlers->get_properties(&uri_object->std)); Z_TRY_ADDREF(arr); zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr); } @@ -812,56 +811,55 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) Z_PARAM_ARRAY_HT(data) ZEND_PARSE_PARAMETERS_END(); - zend_object *object = Z_OBJ_P(ZEND_THIS); - uri_object_t *uri_object = uri_object_from_obj(object); + uri_object_t *uri_object = uri_object_from_obj(Z_OBJ_P(ZEND_THIS)); if (uri_object->uri != NULL) { /* Intentionally throw two exceptions for proper chaining. */ - zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(object->ce->name)); - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(uri_object->std.ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name)); RETURN_THROWS(); } /* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */ if (zend_hash_num_elements(data) != 2) { - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name)); RETURN_THROWS(); } /* Unserialize state: "uri" key in the first array */ zval *arr = zend_hash_index_find(data, 0); if (arr == NULL || Z_TYPE_P(arr) != IS_ARRAY) { - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name)); RETURN_THROWS(); } /* Verify the expected number of elements inside the first array, this implicitly ensures that no additional elements are present. */ if (zend_hash_num_elements(Z_ARRVAL_P(arr)) != 1) { - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name)); RETURN_THROWS(); } zval *uri_zv = zend_hash_str_find_ind(Z_ARRVAL_P(arr), ZEND_STRL(URI_SERIALIZED_PROPERTY_NAME)); if (uri_zv == NULL || Z_TYPE_P(uri_zv) != IS_STRING) { - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name)); RETURN_THROWS(); } uri_object->uri = uri_object->parser->parse(Z_STRVAL_P(uri_zv), Z_STRLEN_P(uri_zv), NULL, NULL, true); if (uri_object->uri == NULL) { - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name)); RETURN_THROWS(); } /* Unserialize regular properties: second array */ arr = zend_hash_index_find(data, 1); if (arr == NULL || Z_TYPE_P(arr) != IS_ARRAY) { - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name)); RETURN_THROWS(); } /* Verify that there is no regular property in the second array, because the URI classes have no properties and they are final. */ if (zend_hash_num_elements(Z_ARRVAL_P(arr)) > 0) { - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name)); RETURN_THROWS(); } } diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c index c558799b4c00c..282c45d7824c4 100644 --- a/ext/uri/php_uri_common.c +++ b/ext/uri/php_uri_common.c @@ -59,11 +59,10 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name prop static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, zval *property_zv) { - zend_object *old_object = Z_OBJ_P(ZEND_THIS); - uri_object_t *internal_uri = Z_URI_OBJECT_P(ZEND_THIS); - ZEND_ASSERT(internal_uri->uri != NULL); + uri_object_t *old_uri_object = Z_URI_OBJECT_P(ZEND_THIS); + ZEND_ASSERT(old_uri_object->uri != NULL); - zend_object *new_object = old_object->handlers->clone_obj(old_object); + zend_object *new_object = old_uri_object->std.handlers->clone_obj(&old_uri_object->std); if (new_object == NULL) { RETURN_THROWS(); } @@ -72,19 +71,19 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_propert * case of an exception being thrown. */ RETVAL_OBJ(new_object); - const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name); + const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(old_uri_object->parser, property_name); - uri_object_t *new_internal_uri = uri_object_from_obj(new_object); - ZEND_ASSERT(new_internal_uri->uri != NULL); + uri_object_t *new_uri_object = uri_object_from_obj(new_object); + ZEND_ASSERT(new_uri_object->uri != NULL); if (UNEXPECTED(property_handler->write == NULL)) { - zend_readonly_property_modification_error_ex(ZSTR_VAL(old_object->ce->name), + zend_readonly_property_modification_error_ex(ZSTR_VAL(old_uri_object->std.ce->name), ZSTR_VAL(get_known_string_by_property_name(property_name))); RETURN_THROWS(); } zval errors; ZVAL_UNDEF(&errors); - if (UNEXPECTED(property_handler->write(new_internal_uri->uri, property_zv, &errors) == FAILURE)) { + if (UNEXPECTED(property_handler->write(new_uri_object->uri, property_zv, &errors) == FAILURE)) { zval_ptr_dtor(&errors); RETURN_THROWS(); }