From 0eecadcc7c3eafb2f0af86c65eff9c08762f762c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 22 Sep 2025 12:34:13 +0200 Subject: [PATCH 1/6] uri: Rename `uri_object_t` to `php_uri_object` --- ext/uri/php_uri.c | 58 ++++++++++++++++++++-------------------- ext/uri/php_uri.h | 2 +- ext/uri/php_uri_common.c | 6 ++--- ext/uri/php_uri_common.h | 12 ++++----- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 10660888781de..362259968f26f 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -51,7 +51,7 @@ static const zend_module_dep uri_deps[] = { static zend_array uri_parsers; -static HashTable *uri_get_debug_properties(uri_object_t *object) +static HashTable *uri_get_debug_properties(php_uri_object *object) { const HashTable *std_properties = zend_std_get_properties(&object->std); HashTable *result = zend_array_dup(std_properties); @@ -314,11 +314,11 @@ static zend_result pass_errors_by_ref_and_free(zval *errors_zv, zval *errors) } ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri( - INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const uri_object_t *base_url_object, + INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const php_uri_object *base_url_object, bool should_throw, bool should_update_this_object, zval *errors_zv ) { - uri_object_t *uri_object; + php_uri_object *uri_object; if (should_update_this_object) { uri_object = Z_URI_OBJECT_P(ZEND_THIS); if (uri_object->uri != NULL) { @@ -381,7 +381,7 @@ static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor ZEND_PARSE_PARAMETERS_END(); php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, - uri_str, base_url_object ? uri_object_from_obj(base_url_object) : NULL, is_constructor, is_constructor, NULL); + uri_str, base_url_object ? php_uri_object_from_obj(base_url_object) : NULL, is_constructor, is_constructor, NULL); } static bool is_list_of_whatwg_validation_errors(const HashTable *array) @@ -495,7 +495,7 @@ static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor) ZEND_PARSE_PARAMETERS_END(); php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, - uri_str, base_url_object ? uri_object_from_obj(base_url_object) : NULL, is_constructor, is_constructor, errors); + uri_str, base_url_object ? php_uri_object_from_obj(base_url_object) : NULL, is_constructor, is_constructor, errors); } PHP_METHOD(Uri_WhatWg_Url, parse) @@ -527,7 +527,7 @@ static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, php_uri_componen { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(uri_object->uri != NULL); if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_read(uri_object->uri, read_mode, return_value) == FAILURE)) { @@ -561,7 +561,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) ZVAL_STR(&zv, value); } - uri_object_t *old_uri_object = uri_object_from_obj(Z_OBJ_P(ZEND_THIS)); + php_uri_object *old_uri_object = php_uri_object_from_obj(Z_OBJ_P(ZEND_THIS)); ZEND_ASSERT(old_uri_object->uri != NULL); zend_object *new_object = old_uri_object->std.handlers->clone_obj(&old_uri_object->std); @@ -573,7 +573,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) * case of an exception being thrown. */ RETVAL_OBJ(new_object); - uri_object_t *new_uri_object = uri_object_from_obj(new_object); + php_uri_object *new_uri_object = php_uri_object_from_obj(new_object); ZEND_ASSERT(new_uri_object->uri != NULL); if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_write(new_uri_object->uri, &zv, NULL) == FAILURE)) { @@ -671,14 +671,14 @@ PHP_METHOD(Uri_Rfc3986_Uri, withFragment) uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT); } -static void throw_cannot_recompose_uri_to_string(uri_object_t *object) +static void throw_cannot_recompose_uri_to_string(php_uri_object *object) { zend_throw_exception_ex(uri_error_ce, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->std.ce->name)); } -static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, uri_object_t *that_object, zend_object *comparison_mode) +static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, php_uri_object *that_object, zend_object *comparison_mode) { - uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *this_object = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(this_object->uri != NULL); ZEND_ASSERT(that_object->uri != NULL); @@ -727,14 +727,14 @@ PHP_METHOD(Uri_Rfc3986_Uri, equals) Z_PARAM_OBJ_OF_CLASS(comparison_mode, uri_comparison_mode_ce) ZEND_PARSE_PARAMETERS_END(); - uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_object_from_obj(that_object), comparison_mode); + uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_uri_object_from_obj(that_object), comparison_mode); } PHP_METHOD(Uri_Rfc3986_Uri, toRawString) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(uri_object->uri != NULL); zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); @@ -750,7 +750,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, toString) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(uri_object->uri != NULL); zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, false); @@ -778,7 +778,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(uri_object->uri != NULL); /* Serialize state: "uri" key in the first array */ @@ -811,7 +811,7 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) Z_PARAM_ARRAY_HT(data) ZEND_PARSE_PARAMETERS_END(); - uri_object_t *uri_object = uri_object_from_obj(Z_OBJ_P(ZEND_THIS)); + php_uri_object *uri_object = php_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(uri_object->std.ce->name)); @@ -873,7 +873,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __debugInfo) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); RETURN_ARR(uri_get_debug_properties(uri_object)); } @@ -924,7 +924,7 @@ PHP_METHOD(Uri_WhatWg_Url, equals) Z_PARAM_OBJ_OF_CLASS(comparison_mode, uri_comparison_mode_ce) ZEND_PARSE_PARAMETERS_END(); - uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_object_from_obj(that_object), comparison_mode); + uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_uri_object_from_obj(that_object), comparison_mode); } PHP_METHOD(Uri_WhatWg_Url, toUnicodeString) @@ -932,7 +932,7 @@ PHP_METHOD(Uri_WhatWg_Url, toUnicodeString) ZEND_PARSE_PARAMETERS_NONE(); zend_object *this_object = Z_OBJ_P(ZEND_THIS); - uri_object_t *uri_object = uri_object_from_obj(this_object); + php_uri_object *uri_object = php_uri_object_from_obj(this_object); ZEND_ASSERT(uri_object->uri != NULL); RETURN_STR(uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE, false)); @@ -943,7 +943,7 @@ PHP_METHOD(Uri_WhatWg_Url, toAsciiString) ZEND_PARSE_PARAMETERS_NONE(); zend_object *this_object = Z_OBJ_P(ZEND_THIS); - uri_object_t *uri_object = uri_object_from_obj(this_object); + php_uri_object *uri_object = php_uri_object_from_obj(this_object); ZEND_ASSERT(uri_object->uri != NULL); RETURN_STR(uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false)); @@ -968,7 +968,7 @@ PHP_METHOD(Uri_WhatWg_Url, __serialize) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *this_object = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(this_object->uri != NULL); /* Serialize state: "uri" key in the first array */ @@ -1002,14 +1002,14 @@ PHP_METHOD(Uri_WhatWg_Url, __debugInfo) { ZEND_PARSE_PARAMETERS_NONE(); - uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); RETURN_ARR(uri_get_debug_properties(uri_object)); } -PHPAPI uri_object_t *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser) +PHPAPI php_uri_object *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser) { - uri_object_t *uri_object = zend_object_alloc(sizeof(*uri_object), class_type); + php_uri_object *uri_object = zend_object_alloc(sizeof(*uri_object), class_type); zend_object_std_init(&uri_object->std, class_type); object_properties_init(&uri_object->std, class_type); @@ -1032,7 +1032,7 @@ static zend_object *php_uri_object_create_whatwg(zend_class_entry *ce) PHPAPI void php_uri_object_handler_free(zend_object *object) { - uri_object_t *uri_object = uri_object_from_obj(object); + php_uri_object *uri_object = php_uri_object_from_obj(object); uri_object->parser->destroy(uri_object->uri); zend_object_std_dtor(&uri_object->std); @@ -1040,11 +1040,11 @@ 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); + php_uri_object *uri_object = php_uri_object_from_obj(object); ZEND_ASSERT(uri_object->uri != NULL); - uri_object_t *new_uri_object = uri_object_from_obj(object->ce->create_object(object->ce)); + php_uri_object *new_uri_object = php_uri_object_from_obj(object->ce->create_object(object->ce)); ZEND_ASSERT(new_uri_object->parser == uri_object->parser); void *uri = uri_object->parser->clone(uri_object->uri); @@ -1080,7 +1080,7 @@ static PHP_MINIT_FUNCTION(uri) uri_rfc3986_uri_ce->create_object = php_uri_object_create_rfc3986; uri_rfc3986_uri_ce->default_object_handlers = &uri_rfc3986_uri_object_handlers; memcpy(&uri_rfc3986_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - uri_rfc3986_uri_object_handlers.offset = XtOffsetOf(uri_object_t, std); + uri_rfc3986_uri_object_handlers.offset = XtOffsetOf(php_uri_object, std); uri_rfc3986_uri_object_handlers.free_obj = php_uri_object_handler_free; uri_rfc3986_uri_object_handlers.clone_obj = php_uri_object_handler_clone; @@ -1088,7 +1088,7 @@ static PHP_MINIT_FUNCTION(uri) uri_whatwg_url_ce->create_object = php_uri_object_create_whatwg; uri_whatwg_url_ce->default_object_handlers = &uri_whatwg_uri_object_handlers; memcpy(&uri_whatwg_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - uri_whatwg_uri_object_handlers.offset = XtOffsetOf(uri_object_t, std); + uri_whatwg_uri_object_handlers.offset = XtOffsetOf(php_uri_object, std); uri_whatwg_uri_object_handlers.free_obj = php_uri_object_handler_free; uri_whatwg_uri_object_handlers.clone_obj = php_uri_object_handler_clone; diff --git a/ext/uri/php_uri.h b/ext/uri/php_uri.h index 9cfe6dce1ab97..293f54942e232 100644 --- a/ext/uri/php_uri.h +++ b/ext/uri/php_uri.h @@ -207,7 +207,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI php_uri *php_uri_parse_to_struct( ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_struct_free(php_uri *uri); ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri( - INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const uri_object_t *base_url_object, + INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const php_uri_object *base_url_object, bool should_throw, bool should_update_this_object, zval *errors_zv ); diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c index 282c45d7824c4..1e1c4eeb95325 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_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *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(uri_object->parser, property_name); @@ -59,7 +59,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) { - uri_object_t *old_uri_object = Z_URI_OBJECT_P(ZEND_THIS); + php_uri_object *old_uri_object = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(old_uri_object->uri != NULL); zend_object *new_object = old_uri_object->std.handlers->clone_obj(&old_uri_object->std); @@ -73,7 +73,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(old_uri_object->parser, property_name); - uri_object_t *new_uri_object = uri_object_from_obj(new_object); + php_uri_object *new_uri_object = php_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_uri_object->std.ce->name), diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index 52d80a290bb4d..e23f41a9f09b3 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -142,19 +142,19 @@ typedef struct uri_internal_t { void *uri; } uri_internal_t; -typedef struct uri_object_t { +typedef struct php_uri_object { const php_uri_parser *parser; void *uri; zend_object std; -} uri_object_t; +} php_uri_object; -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 php_uri_object *php_uri_object_from_obj(zend_object *object) { + return (php_uri_object*)((char*)(object) - XtOffsetOf(php_uri_object, std)); } -#define Z_URI_OBJECT_P(zv) uri_object_from_obj(Z_OBJ_P((zv))) +#define Z_URI_OBJECT_P(zv) php_uri_object_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 php_uri_object *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser); PHPAPI void php_uri_object_handler_free(zend_object *object); PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object); From c4cde1d535a58f94ac1f2d891e74f0ed02f79c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 22 Sep 2025 12:44:12 +0200 Subject: [PATCH 2/6] uri: Rename `uri_(read|write)_component_*` to `php_uri_property_(read|write)_*_helper` --- ext/uri/php_uri.c | 56 ++++++++++++++++++++-------------------- ext/uri/php_uri_common.c | 16 ++++++------ ext/uri/php_uri_common.h | 8 +++--- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 362259968f26f..c32ba394b7ec0 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -510,17 +510,17 @@ PHP_METHOD(Uri_WhatWg_Url, __construct) PHP_METHOD(Uri_Rfc3986_Uri, getScheme) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_Rfc3986_Uri, getRawScheme) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_RAW); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_RAW); } PHP_METHOD(Uri_Rfc3986_Uri, withScheme) { - uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME); + php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME); } static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, php_uri_component_read_mode read_mode) @@ -583,92 +583,92 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) PHP_METHOD(Uri_Rfc3986_Uri, getUsername) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_Rfc3986_Uri, getRawUsername) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME, PHP_URI_COMPONENT_READ_MODE_RAW); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME, PHP_URI_COMPONENT_READ_MODE_RAW); } PHP_METHOD(Uri_Rfc3986_Uri, getPassword) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_Rfc3986_Uri, getRawPassword) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD, PHP_URI_COMPONENT_READ_MODE_RAW); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD, PHP_URI_COMPONENT_READ_MODE_RAW); } PHP_METHOD(Uri_Rfc3986_Uri, getHost) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_Rfc3986_Uri, getRawHost) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_RAW); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_RAW); } PHP_METHOD(Uri_Rfc3986_Uri, withHost) { - uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST); + php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST); } PHP_METHOD(Uri_Rfc3986_Uri, getPort) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PORT, PHP_URI_COMPONENT_READ_MODE_RAW); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PORT, PHP_URI_COMPONENT_READ_MODE_RAW); } PHP_METHOD(Uri_Rfc3986_Uri, withPort) { - uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PORT); + php_uri_property_write_long_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PORT); } PHP_METHOD(Uri_Rfc3986_Uri, getPath) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_Rfc3986_Uri, getRawPath) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH, PHP_URI_COMPONENT_READ_MODE_RAW); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH, PHP_URI_COMPONENT_READ_MODE_RAW); } PHP_METHOD(Uri_Rfc3986_Uri, withPath) { - uri_write_component_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH); + php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH); } PHP_METHOD(Uri_Rfc3986_Uri, getQuery) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_Rfc3986_Uri, getRawQuery) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, PHP_URI_COMPONENT_READ_MODE_RAW); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, PHP_URI_COMPONENT_READ_MODE_RAW); } PHP_METHOD(Uri_Rfc3986_Uri, withQuery) { - uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY); + php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY); } PHP_METHOD(Uri_Rfc3986_Uri, getFragment) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_Rfc3986_Uri, getRawFragment) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_RAW); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_RAW); } PHP_METHOD(Uri_Rfc3986_Uri, withFragment) { - uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT); + php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT); } static void throw_cannot_recompose_uri_to_string(php_uri_object *object) @@ -880,37 +880,37 @@ PHP_METHOD(Uri_Rfc3986_Uri, __debugInfo) PHP_METHOD(Uri_WhatWg_Url, getScheme) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_WhatWg_Url, withScheme) { - uri_write_component_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME); + php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME); } PHP_METHOD(Uri_WhatWg_Url, withUsername) { - uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME); + php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME); } PHP_METHOD(Uri_WhatWg_Url, withPassword) { - uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD); + php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD); } PHP_METHOD(Uri_WhatWg_Url, getAsciiHost) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); } PHP_METHOD(Uri_WhatWg_Url, getUnicodeHost) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_UNICODE); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_UNICODE); } PHP_METHOD(Uri_WhatWg_Url, getFragment) { - uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_UNICODE); + php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_UNICODE); } PHP_METHOD(Uri_WhatWg_Url, equals) diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c index 1e1c4eeb95325..23fb52c29e47b 100644 --- a/ext/uri/php_uri_common.c +++ b/ext/uri/php_uri_common.c @@ -42,7 +42,7 @@ static zend_string *get_known_string_by_property_name(php_uri_property_name prop } } -void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode) +void php_uri_property_read_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode) { ZEND_PARSE_PARAMETERS_NONE(); @@ -57,7 +57,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) +static void php_uri_property_write_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, zval *property_zv) { php_uri_object *old_uri_object = Z_URI_OBJECT_P(ZEND_THIS); ZEND_ASSERT(old_uri_object->uri != NULL); @@ -91,7 +91,7 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_propert ZEND_ASSERT(Z_ISUNDEF(errors)); } -void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name) +void php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name) { zend_string *value; @@ -102,10 +102,10 @@ void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name zval zv; ZVAL_STR(&zv, value); - uri_write_component_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv); + php_uri_property_write_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv); } -void uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name) +void php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name) { zend_string *value; @@ -120,10 +120,10 @@ void uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_prope ZVAL_STR(&zv, value); } - uri_write_component_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv); + php_uri_property_write_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv); } -void uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name) +void php_uri_property_write_long_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name) { zend_long value; bool value_is_null; @@ -139,5 +139,5 @@ void uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_prop ZVAL_LONG(&zv, value); } - uri_write_component_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv); + php_uri_property_write_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv); } diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index e23f41a9f09b3..07b1541a6b1db 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -186,9 +186,9 @@ static inline const php_uri_property_handler *php_uri_parser_property_handler_by } } -void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode); -void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name 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); +void php_uri_property_read_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode); +void php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name); +void php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name); +void php_uri_property_write_long_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name); #endif From e5962c01833ffc942f340cd515cf30fd6256770f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 22 Sep 2025 12:45:50 +0200 Subject: [PATCH 3/6] uri: Rename `URI_SERIALIZED_PROPERTY_NAME` to `PHP_URI_SERIALIZE_URI_FIELD_NAME` --- ext/uri/php_uri.c | 6 +++--- ext/uri/php_uri_common.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index c32ba394b7ec0..ca32b0c3f8b61 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -794,7 +794,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize) zval arr; array_init(&arr); - zend_hash_str_add_new(Z_ARRVAL(arr), URI_SERIALIZED_PROPERTY_NAME, sizeof(URI_SERIALIZED_PROPERTY_NAME) - 1, &tmp); + zend_hash_str_add_new(Z_ARRVAL(arr), PHP_URI_SERIALIZE_URI_FIELD_NAME, sizeof(PHP_URI_SERIALIZE_URI_FIELD_NAME) - 1, &tmp); zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr); /* Serialize regular properties: second array */ @@ -838,7 +838,7 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) RETURN_THROWS(); } - zval *uri_zv = zend_hash_str_find_ind(Z_ARRVAL_P(arr), ZEND_STRL(URI_SERIALIZED_PROPERTY_NAME)); + zval *uri_zv = zend_hash_str_find_ind(Z_ARRVAL_P(arr), ZEND_STRL(PHP_URI_SERIALIZE_URI_FIELD_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(uri_object->std.ce->name)); RETURN_THROWS(); @@ -984,7 +984,7 @@ PHP_METHOD(Uri_WhatWg_Url, __serialize) zval arr; array_init(&arr); - zend_hash_str_add_new(Z_ARRVAL(arr), ZEND_STRL(URI_SERIALIZED_PROPERTY_NAME), &tmp); + zend_hash_str_add_new(Z_ARRVAL(arr), ZEND_STRL(PHP_URI_SERIALIZE_URI_FIELD_NAME), &tmp); zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr); /* Serialize regular properties: second array */ diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index 07b1541a6b1db..d7b44b2ee0d57 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -161,7 +161,7 @@ PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object); #define PHP_URI_PARSER_RFC3986 "Uri\\Rfc3986\\Uri" #define PHP_URI_PARSER_WHATWG "Uri\\WhatWg\\Url" #define PHP_URI_PARSER_PHP_PARSE_URL "parse_url" -#define URI_SERIALIZED_PROPERTY_NAME "uri" +#define PHP_URI_SERIALIZE_URI_FIELD_NAME "uri" static inline const php_uri_property_handler *php_uri_parser_property_handler_by_name(const php_uri_parser *parser, php_uri_property_name property_name) { From 79c2fec6ce74a17816966240b87041900ff48a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 23 Sep 2025 08:37:05 +0200 Subject: [PATCH 4/6] uri: Rename `uri_internal_t` to `php_uri_internal` --- ext/openssl/xp_ssl.c | 2 +- ext/uri/php_uri.c | 24 ++++++++++++------------ ext/uri/php_uri.h | 20 ++++++++++---------- ext/uri/php_uri_common.h | 4 ++-- ext/zend_test/test.c | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 23f37355af568..6a4f8d7575c1a 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -2640,7 +2640,7 @@ static char *php_openssl_get_url_name(const char *resourcename, return NULL; } - uri_internal_t *internal_uri = php_uri_parse(uri_parser, resourcename, resourcenamelen, true); + php_uri_internal *internal_uri = php_uri_parse(uri_parser, resourcename, resourcenamelen, true); if (internal_uri == NULL) { return NULL; } diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index ca32b0c3f8b61..88c4ab39f074c 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -108,9 +108,9 @@ PHPAPI const php_uri_parser *php_uri_get_parser(zend_string *uri_parser_name) return zend_hash_find_ptr(&uri_parsers, uri_parser_name); } -ZEND_ATTRIBUTE_NONNULL PHPAPI uri_internal_t *php_uri_parse(const php_uri_parser *uri_parser, const char *uri_str, size_t uri_str_len, bool silent) +ZEND_ATTRIBUTE_NONNULL PHPAPI php_uri_internal *php_uri_parse(const php_uri_parser *uri_parser, const char *uri_str, size_t uri_str_len, bool silent) { - uri_internal_t *internal_uri = emalloc(sizeof(*internal_uri)); + php_uri_internal *internal_uri = emalloc(sizeof(*internal_uri)); internal_uri->parser = uri_parser; internal_uri->uri = uri_parser->parse(uri_str, uri_str_len, NULL, NULL, silent); @@ -122,47 +122,47 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI uri_internal_t *php_uri_parse(const php_uri_parser return internal_uri; } -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_scheme(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv) +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_scheme(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv) { return internal_uri->parser->property_handler.scheme.read(internal_uri->uri, read_mode, zv); } -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_username(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv) +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_username(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv) { return internal_uri->parser->property_handler.username.read(internal_uri->uri, read_mode, zv); } -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_password(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv) +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_password(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv) { return internal_uri->parser->property_handler.password.read(internal_uri->uri, read_mode, zv); } -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_host(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv) +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_host(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv) { return internal_uri->parser->property_handler.host.read(internal_uri->uri, read_mode, zv); } -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_port(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv) +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_port(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv) { return internal_uri->parser->property_handler.port.read(internal_uri->uri, read_mode, zv); } -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_path(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv) +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_path(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv) { return internal_uri->parser->property_handler.path.read(internal_uri->uri, read_mode, zv); } -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_query(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv) +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_query(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv) { return internal_uri->parser->property_handler.query.read(internal_uri->uri, read_mode, zv); } -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_fragment(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv) +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_fragment(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv) { return internal_uri->parser->property_handler.fragment.read(internal_uri->uri, read_mode, zv); } -ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_free(uri_internal_t *internal_uri) +ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_free(php_uri_internal *internal_uri) { internal_uri->parser->destroy(internal_uri->uri); internal_uri->uri = NULL; @@ -173,7 +173,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_free(uri_internal_t *internal_uri) ZEND_ATTRIBUTE_NONNULL PHPAPI php_uri *php_uri_parse_to_struct( const php_uri_parser *uri_parser, const char *uri_str, size_t uri_str_len, php_uri_component_read_mode read_mode, bool silent ) { - uri_internal_t *uri_internal = php_uri_parse(uri_parser, uri_str, uri_str_len, silent); + php_uri_internal *uri_internal = php_uri_parse(uri_parser, uri_str, uri_str_len, silent); if (uri_internal == NULL) { return NULL; } diff --git a/ext/uri/php_uri.h b/ext/uri/php_uri.h index 293f54942e232..1ec3617b096ca 100644 --- a/ext/uri/php_uri.h +++ b/ext/uri/php_uri.h @@ -51,7 +51,7 @@ PHPAPI zend_result php_uri_parser_register(const php_uri_parser *uri_parser); */ PHPAPI const php_uri_parser *php_uri_get_parser(zend_string *uri_parser_name); -ZEND_ATTRIBUTE_NONNULL PHPAPI uri_internal_t *php_uri_parse(const php_uri_parser *uri_parser, const char *uri_str, size_t uri_str_len, bool silent); +ZEND_ATTRIBUTE_NONNULL PHPAPI php_uri_internal *php_uri_parse(const php_uri_parser *uri_parser, const char *uri_str, size_t uri_str_len, bool silent); /** * Retrieves the scheme component based on the read_mode and passes it to the zv ZVAL in case of success. @@ -66,7 +66,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI uri_internal_t *php_uri_parse(const php_uri_parser * @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL). * @return SUCCESS in case of success, FAILURE otherwise. */ -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_scheme(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv); +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_scheme(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv); /** * Retrieves the username component based on the read_mode and passes it to the zv ZVAL in case of success. @@ -81,7 +81,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_scheme(const uri_internal_ * @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL). * @return SUCCESS in case of success, FAILURE otherwise. */ -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_username(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv); +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_username(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv); /** * Retrieves the password component based on the read_mode and passes it to the zv ZVAL in case of success. @@ -96,7 +96,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_username(const uri_interna * @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL). * @return SUCCESS in case of success, FAILURE otherwise. */ -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_password(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv); +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_password(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv); /** * Retrieves the host component based on the read_mode and passes it to the zv ZVAL in case of success. @@ -111,7 +111,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_password(const uri_interna * @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL). * @return SUCCESS in case of success, FAILURE otherwise. */ -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_host(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv); +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_host(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv); /** * Retrieves the port component based on the read_mode and passes it to the zv ZVAL in case of success. @@ -126,7 +126,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_host(const uri_internal_t * @param zv The output parameter containing the retrieved component as a ZVAL (either IS_LONG or IS_NULL). * @return SUCCESS in case of success, FAILURE otherwise. */ -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_port(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv); +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_port(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv); /** * Retrieves the path component based on the read_mode and passes it to the zv ZVAL in case of success. @@ -141,7 +141,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_port(const uri_internal_t * @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL). * @return SUCCESS in case of success, FAILURE otherwise. */ -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_path(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv); +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_path(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv); /** * Retrieves the query component based on the read_mode and passes it to the zv ZVAL in case of success. @@ -156,7 +156,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_path(const uri_internal_t * @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL). * @return SUCCESS in case of success, FAILURE otherwise. */ -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_query(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv); +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_query(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv); /** * Retrieves the fragment component based on the read_mode and passes it to the zv ZVAL in case of success. @@ -171,14 +171,14 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_query(const uri_internal_t * @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL). * @return SUCCESS in case of success, FAILURE otherwise. */ -ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_fragment(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv); +ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_fragment(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv); /** * Frees the uri member within the provided internal URI. * * @param internal_uri The internal URI */ -ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_free(uri_internal_t *internal_uri); +ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_free(php_uri_internal *internal_uri); /** * Creates a new php_uri struct containing all the URI components. The components are retrieved based on the read_mode parameter. diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index d7b44b2ee0d57..37c3a344f1fb6 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -137,10 +137,10 @@ typedef struct php_uri_parser { } property_handler; } php_uri_parser; -typedef struct uri_internal_t { +typedef struct php_uri_internal { const php_uri_parser *parser; void *uri; -} uri_internal_t; +} php_uri_internal; typedef struct php_uri_object { const php_uri_parser *parser; diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 6b0139e186b62..bdbd2f52f0f2d 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -741,7 +741,7 @@ static ZEND_FUNCTION(zend_test_uri_parser) RETURN_THROWS(); } - uri_internal_t *uri = php_uri_parse(parser, ZSTR_VAL(uri_string), ZSTR_LEN(uri_string), false); + php_uri_internal *uri = php_uri_parse(parser, ZSTR_VAL(uri_string), ZSTR_LEN(uri_string), false); if (uri == NULL) { RETURN_THROWS(); } From 4fefcbf158735479031d7cab2bfbc97af5cb34b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 23 Sep 2025 08:39:11 +0200 Subject: [PATCH 5/6] uri: Use proper `php_uri_ce_` prefix for all CEs --- ext/uri/php_uri.c | 74 +++++++++++++++--------------- ext/uri/php_uri_common.c | 2 +- ext/uri/php_uri_common.h | 18 ++++---- ext/uri/uri_parser_php_parse_url.c | 2 +- ext/uri/uri_parser_rfc3986.c | 46 +++++++++---------- ext/uri/uri_parser_whatwg.c | 14 +++--- 6 files changed, 78 insertions(+), 78 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 88c4ab39f074c..e02ff5a412e4e 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -32,17 +32,17 @@ #include "php_uri_arginfo.h" #include "uriparser/UriBase.h" -zend_class_entry *uri_rfc3986_uri_ce; +zend_class_entry *php_uri_ce_rfc3986_uri; zend_object_handlers uri_rfc3986_uri_object_handlers; -zend_class_entry *uri_whatwg_url_ce; +zend_class_entry *php_uri_ce_whatwg_url; zend_object_handlers uri_whatwg_uri_object_handlers; -zend_class_entry *uri_comparison_mode_ce; -zend_class_entry *uri_exception_ce; -zend_class_entry *uri_error_ce; -zend_class_entry *uri_invalid_uri_exception_ce; -zend_class_entry *uri_whatwg_invalid_url_exception_ce; -zend_class_entry *uri_whatwg_url_validation_error_type_ce; -zend_class_entry *uri_whatwg_url_validation_error_ce; +zend_class_entry *php_uri_ce_comparison_mode; +zend_class_entry *php_uri_ce_exception; +zend_class_entry *php_uri_ce_error; +zend_class_entry *php_uri_ce_invalid_uri_exception; +zend_class_entry *php_uri_ce_whatwg_invalid_url_exception; +zend_class_entry *php_uri_ce_whatwg_url_validation_error_type; +zend_class_entry *php_uri_ce_whatwg_url_validation_error; static const zend_module_dep uri_deps[] = { ZEND_MOD_REQUIRED("lexbor") @@ -377,7 +377,7 @@ static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH_STR(uri_str) Z_PARAM_OPTIONAL - Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, uri_rfc3986_uri_ce) + Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, php_uri_ce_rfc3986_uri) ZEND_PARSE_PARAMETERS_END(); php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, @@ -397,7 +397,7 @@ static bool is_list_of_whatwg_validation_errors(const HashTable *array) return false; } - if (!instanceof_function(Z_OBJCE_P(val), uri_whatwg_url_validation_error_ce)) { + if (!instanceof_function(Z_OBJCE_P(val), php_uri_ce_whatwg_url_validation_error)) { return false; } } ZEND_HASH_FOREACH_END(); @@ -437,14 +437,14 @@ PHP_METHOD(Uri_WhatWg_InvalidUrlException, __construct) if (errors == NULL) { zval tmp; ZVAL_EMPTY_ARRAY(&tmp); - zend_update_property(uri_whatwg_invalid_url_exception_ce, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), &tmp); + zend_update_property(php_uri_ce_whatwg_invalid_url_exception, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), &tmp); } else { if (!is_list_of_whatwg_validation_errors(Z_ARR_P(errors))) { - zend_argument_value_error(2, "must be a list of %s", ZSTR_VAL(uri_whatwg_url_validation_error_ce->name)); + zend_argument_value_error(2, "must be a list of %s", ZSTR_VAL(php_uri_ce_whatwg_url_validation_error->name)); RETURN_THROWS(); } - zend_update_property(uri_whatwg_invalid_url_exception_ce, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), errors); + zend_update_property(php_uri_ce_whatwg_invalid_url_exception, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), errors); } if (EG(exception)) { RETURN_THROWS(); @@ -459,23 +459,23 @@ PHP_METHOD(Uri_WhatWg_UrlValidationError, __construct) ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_STR(context) - Z_PARAM_OBJECT_OF_CLASS(type, uri_whatwg_url_validation_error_type_ce) + Z_PARAM_OBJECT_OF_CLASS(type, php_uri_ce_whatwg_url_validation_error_type) Z_PARAM_BOOL(failure) ZEND_PARSE_PARAMETERS_END(); - zend_update_property_str(uri_whatwg_url_validation_error_ce, Z_OBJ_P(ZEND_THIS), ZEND_STRL("context"), context); + zend_update_property_str(php_uri_ce_whatwg_url_validation_error, Z_OBJ_P(ZEND_THIS), ZEND_STRL("context"), context); if (EG(exception)) { RETURN_THROWS(); } - zend_update_property_ex(uri_whatwg_url_validation_error_ce, Z_OBJ_P(ZEND_THIS), ZSTR_KNOWN(ZEND_STR_TYPE), type); + zend_update_property_ex(php_uri_ce_whatwg_url_validation_error, Z_OBJ_P(ZEND_THIS), ZSTR_KNOWN(ZEND_STR_TYPE), type); if (EG(exception)) { RETURN_THROWS(); } zval failure_zv; ZVAL_BOOL(&failure_zv, failure); - zend_update_property(uri_whatwg_url_validation_error_ce, Z_OBJ_P(ZEND_THIS), ZEND_STRL("failure"), &failure_zv); + zend_update_property(php_uri_ce_whatwg_url_validation_error, Z_OBJ_P(ZEND_THIS), ZEND_STRL("failure"), &failure_zv); if (EG(exception)) { RETURN_THROWS(); } @@ -490,7 +490,7 @@ static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor) ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_PATH_STR(uri_str) Z_PARAM_OPTIONAL - Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, uri_whatwg_url_ce) + Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, php_uri_ce_whatwg_url) Z_PARAM_ZVAL(errors) ZEND_PARSE_PARAMETERS_END(); @@ -673,7 +673,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withFragment) static void throw_cannot_recompose_uri_to_string(php_uri_object *object) { - zend_throw_exception_ex(uri_error_ce, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->std.ce->name)); + zend_throw_exception_ex(php_uri_ce_error, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->std.ce->name)); } static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, php_uri_object *that_object, zend_object *comparison_mode) @@ -722,9 +722,9 @@ PHP_METHOD(Uri_Rfc3986_Uri, equals) zend_object *comparison_mode = NULL; ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_OBJ_OF_CLASS(that_object, uri_rfc3986_uri_ce) + Z_PARAM_OBJ_OF_CLASS(that_object, php_uri_ce_rfc3986_uri) Z_PARAM_OPTIONAL - Z_PARAM_OBJ_OF_CLASS(comparison_mode, uri_comparison_mode_ce) + Z_PARAM_OBJ_OF_CLASS(comparison_mode, php_uri_ce_comparison_mode) ZEND_PARSE_PARAMETERS_END(); uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_uri_object_from_obj(that_object), comparison_mode); @@ -919,9 +919,9 @@ PHP_METHOD(Uri_WhatWg_Url, equals) zend_object *comparison_mode = NULL; ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_OBJ_OF_CLASS(that_object, uri_whatwg_url_ce) + Z_PARAM_OBJ_OF_CLASS(that_object, php_uri_ce_whatwg_url) Z_PARAM_OPTIONAL - Z_PARAM_OBJ_OF_CLASS(comparison_mode, uri_comparison_mode_ce) + Z_PARAM_OBJ_OF_CLASS(comparison_mode, php_uri_ce_comparison_mode) ZEND_PARSE_PARAMETERS_END(); uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_uri_object_from_obj(that_object), comparison_mode); @@ -1076,29 +1076,29 @@ PHPAPI zend_result php_uri_parser_register(const php_uri_parser *uri_parser) static PHP_MINIT_FUNCTION(uri) { - uri_rfc3986_uri_ce = register_class_Uri_Rfc3986_Uri(); - uri_rfc3986_uri_ce->create_object = php_uri_object_create_rfc3986; - uri_rfc3986_uri_ce->default_object_handlers = &uri_rfc3986_uri_object_handlers; + php_uri_ce_rfc3986_uri = register_class_Uri_Rfc3986_Uri(); + php_uri_ce_rfc3986_uri->create_object = php_uri_object_create_rfc3986; + php_uri_ce_rfc3986_uri->default_object_handlers = &uri_rfc3986_uri_object_handlers; memcpy(&uri_rfc3986_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); uri_rfc3986_uri_object_handlers.offset = XtOffsetOf(php_uri_object, std); uri_rfc3986_uri_object_handlers.free_obj = php_uri_object_handler_free; uri_rfc3986_uri_object_handlers.clone_obj = php_uri_object_handler_clone; - uri_whatwg_url_ce = register_class_Uri_WhatWg_Url(); - uri_whatwg_url_ce->create_object = php_uri_object_create_whatwg; - uri_whatwg_url_ce->default_object_handlers = &uri_whatwg_uri_object_handlers; + php_uri_ce_whatwg_url = register_class_Uri_WhatWg_Url(); + php_uri_ce_whatwg_url->create_object = php_uri_object_create_whatwg; + php_uri_ce_whatwg_url->default_object_handlers = &uri_whatwg_uri_object_handlers; memcpy(&uri_whatwg_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); uri_whatwg_uri_object_handlers.offset = XtOffsetOf(php_uri_object, std); uri_whatwg_uri_object_handlers.free_obj = php_uri_object_handler_free; uri_whatwg_uri_object_handlers.clone_obj = php_uri_object_handler_clone; - uri_comparison_mode_ce = register_class_Uri_UriComparisonMode(); - uri_exception_ce = register_class_Uri_UriException(zend_ce_exception); - uri_error_ce = register_class_Uri_UriError(zend_ce_error); - uri_invalid_uri_exception_ce = register_class_Uri_InvalidUriException(uri_exception_ce); - uri_whatwg_invalid_url_exception_ce = register_class_Uri_WhatWg_InvalidUrlException(uri_invalid_uri_exception_ce); - uri_whatwg_url_validation_error_ce = register_class_Uri_WhatWg_UrlValidationError(); - uri_whatwg_url_validation_error_type_ce = register_class_Uri_WhatWg_UrlValidationErrorType(); + php_uri_ce_comparison_mode = register_class_Uri_UriComparisonMode(); + php_uri_ce_exception = register_class_Uri_UriException(zend_ce_exception); + php_uri_ce_error = register_class_Uri_UriError(zend_ce_error); + php_uri_ce_invalid_uri_exception = register_class_Uri_InvalidUriException(php_uri_ce_exception); + php_uri_ce_whatwg_invalid_url_exception = register_class_Uri_WhatWg_InvalidUrlException(php_uri_ce_invalid_uri_exception); + php_uri_ce_whatwg_url_validation_error = register_class_Uri_WhatWg_UrlValidationError(); + php_uri_ce_whatwg_url_validation_error_type = register_class_Uri_WhatWg_UrlValidationErrorType(); zend_hash_init(&uri_parsers, 4, NULL, NULL, true); diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c index 23fb52c29e47b..780cc95074159 100644 --- a/ext/uri/php_uri_common.c +++ b/ext/uri/php_uri_common.c @@ -52,7 +52,7 @@ void php_uri_property_read_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(uri_object->parser, property_name); 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))); + zend_throw_exception_ex(php_uri_ce_error, 0, "The %s component cannot be retrieved", ZSTR_VAL(get_known_string_by_property_name(property_name))); RETURN_THROWS(); } } diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index 37c3a344f1fb6..bc70ae2073b15 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -17,17 +17,17 @@ #ifndef PHP_URI_COMMON_H #define PHP_URI_COMMON_H -extern zend_class_entry *uri_rfc3986_uri_ce; +extern zend_class_entry *php_uri_ce_rfc3986_uri; extern zend_object_handlers uri_rfc3986_uri_object_handlers; -extern zend_class_entry *uri_whatwg_url_ce; +extern zend_class_entry *php_uri_ce_whatwg_url; extern zend_object_handlers uri_whatwg_uri_object_handlers; -extern zend_class_entry *uri_comparison_mode_ce; -extern zend_class_entry *uri_exception_ce; -extern zend_class_entry *uri_error_ce; -extern zend_class_entry *uri_invalid_uri_exception_ce; -extern zend_class_entry *uri_whatwg_invalid_url_exception_ce; -extern zend_class_entry *uri_whatwg_url_validation_error_type_ce; -extern zend_class_entry *uri_whatwg_url_validation_error_ce; +extern zend_class_entry *php_uri_ce_comparison_mode; +extern zend_class_entry *php_uri_ce_exception; +extern zend_class_entry *php_uri_ce_error; +extern zend_class_entry *php_uri_ce_invalid_uri_exception; +extern zend_class_entry *php_uri_ce_whatwg_invalid_url_exception; +extern zend_class_entry *php_uri_ce_whatwg_url_validation_error_type; +extern zend_class_entry *php_uri_ce_whatwg_url_validation_error; typedef enum php_uri_recomposition_mode { PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, diff --git a/ext/uri/uri_parser_php_parse_url.c b/ext/uri/uri_parser_php_parse_url.c index b8b3c8ae7d6d4..a185068a0392e 100644 --- a/ext/uri/uri_parser_php_parse_url.c +++ b/ext/uri/uri_parser_php_parse_url.c @@ -148,7 +148,7 @@ static void *uri_parser_php_parse_url_parse(const char *uri_str, size_t uri_str_ php_url *url = php_url_parse_ex2(uri_str, uri_str_len, &has_port); if (url == NULL && !silent) { - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified URI is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified URI is malformed", 0); } return url; diff --git a/ext/uri/uri_parser_rfc3986.c b/ext/uri/uri_parser_rfc3986.c index 0efae6d9db8c2..24dd4e1947b2b 100644 --- a/ext/uri/uri_parser_rfc3986.c +++ b/ext/uri/uri_parser_rfc3986.c @@ -132,11 +132,11 @@ static zend_result php_uri_parser_rfc3986_scheme_write(void *uri, zval *value, z case URI_SUCCESS: return SUCCESS; case URI_ERROR_SYNTAX: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified scheme is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified scheme is malformed", 0); return FAILURE; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to update the scheme", 0); + zend_throw_exception(php_uri_ce_error, "Failed to update the scheme", 0); return FAILURE; } } @@ -169,14 +169,14 @@ zend_result php_uri_parser_rfc3986_userinfo_write(void *uri, zval *value, zval * case URI_SUCCESS: return SUCCESS; case URI_ERROR_SETUSERINFO_HOST_NOT_SET: - zend_throw_exception(uri_invalid_uri_exception_ce, "Cannot set a userinfo without having a host", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "Cannot set a userinfo without having a host", 0); return FAILURE; case URI_ERROR_SYNTAX: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified userinfo is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified userinfo is malformed", 0); return FAILURE; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to update the userinfo", 0); + zend_throw_exception(php_uri_ce_error, "Failed to update the userinfo", 0); return FAILURE; } } @@ -261,17 +261,17 @@ static zend_result php_uri_parser_rfc3986_host_write(void *uri, zval *value, zva case URI_SUCCESS: return SUCCESS; case URI_ERROR_SETHOST_PORT_SET: - zend_throw_exception(uri_invalid_uri_exception_ce, "Cannot remove the host from a URI that has a port", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "Cannot remove the host from a URI that has a port", 0); return FAILURE; case URI_ERROR_SETHOST_USERINFO_SET: - zend_throw_exception(uri_invalid_uri_exception_ce, "Cannot remove the host from a URI that has a userinfo", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "Cannot remove the host from a URI that has a userinfo", 0); return FAILURE; case URI_ERROR_SYNTAX: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified host is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified host is malformed", 0); return FAILURE; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to update the host", 0); + zend_throw_exception(php_uri_ce_error, "Failed to update the host", 0); return FAILURE; } } @@ -324,14 +324,14 @@ static zend_result php_uri_parser_rfc3986_port_write(void *uri, zval *value, zva case URI_SUCCESS: return SUCCESS; case URI_ERROR_SETPORT_HOST_NOT_SET: - zend_throw_exception(uri_invalid_uri_exception_ce, "Cannot set a port without having a host", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "Cannot set a port without having a host", 0); return FAILURE; case URI_ERROR_SYNTAX: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified port is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified port is malformed", 0); return FAILURE; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to update the port", 0); + zend_throw_exception(php_uri_ce_error, "Failed to update the port", 0); return FAILURE; } } @@ -379,11 +379,11 @@ static zend_result php_uri_parser_rfc3986_path_write(void *uri, zval *value, zva case URI_SUCCESS: return SUCCESS; case URI_ERROR_SYNTAX: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified path is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified path is malformed", 0); return FAILURE; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to update the path", 0); + zend_throw_exception(php_uri_ce_error, "Failed to update the path", 0); return FAILURE; } } @@ -416,11 +416,11 @@ static zend_result php_uri_parser_rfc3986_query_write(void *uri, zval *value, zv case URI_SUCCESS: return SUCCESS; case URI_ERROR_SYNTAX: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified query is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified query is malformed", 0); return FAILURE; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to update the query", 0); + zend_throw_exception(php_uri_ce_error, "Failed to update the query", 0); return FAILURE; } } @@ -453,11 +453,11 @@ static zend_result php_uri_parser_rfc3986_fragment_write(void *uri, zval *value, case URI_SUCCESS: return SUCCESS; case URI_ERROR_SYNTAX: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified fragment is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified fragment is malformed", 0); return FAILURE; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to update the fragment", 0); + zend_throw_exception(php_uri_ce_error, "Failed to update the fragment", 0); return FAILURE; } } @@ -480,11 +480,11 @@ php_uri_parser_rfc3986_uris *php_uri_parser_rfc3986_parse_ex(const char *uri_str if (!silent) { switch (result) { case URI_ERROR_SYNTAX: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified URI is malformed", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified URI is malformed", 0); break; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to parse the specified URI", 0); + zend_throw_exception(php_uri_ce_error, "Failed to parse the specified URI", 0); break; } } @@ -502,11 +502,11 @@ php_uri_parser_rfc3986_uris *php_uri_parser_rfc3986_parse_ex(const char *uri_str if (!silent) { switch (result) { case URI_ERROR_ADDBASE_REL_BASE: - zend_throw_exception(uri_invalid_uri_exception_ce, "The specified base URI must be absolute", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified base URI must be absolute", 0); break; default: /* This should be unreachable in practice. */ - zend_throw_exception(uri_error_ce, "Failed to resolve the specified URI against the base URI", 0); + zend_throw_exception(php_uri_ce_error, "Failed to resolve the specified URI against the base URI", 0); break; } } @@ -525,7 +525,7 @@ php_uri_parser_rfc3986_uris *php_uri_parser_rfc3986_parse_ex(const char *uri_str if (has_text_range(&uri.portText) && get_text_range_length(&uri.portText) > 0) { if (port_str_to_zend_long_checked(uri.portText.first, get_text_range_length(&uri.portText)) == -1) { if (!silent) { - zend_throw_exception(uri_invalid_uri_exception_ce, "The port is out of range", 0); + zend_throw_exception(php_uri_ce_invalid_uri_exception, "The port is out of range", 0); } goto fail; diff --git a/ext/uri/uri_parser_whatwg.c b/ext/uri/uri_parser_whatwg.c index 99adaabc5b387..fab228a2d70cf 100644 --- a/ext/uri/uri_parser_whatwg.c +++ b/ext/uri/uri_parser_whatwg.c @@ -73,8 +73,8 @@ static const char *fill_errors(zval *errors) lexbor_plog_entry_t *lxb_error; while ((lxb_error = lexbor_array_obj_pop(&lexbor_parser.log->list)) != NULL) { zval error; - object_init_ex(&error, uri_whatwg_url_validation_error_ce); - zend_update_property_string(uri_whatwg_url_validation_error_ce, Z_OBJ(error), ZEND_STRL("context"), (const char *) lxb_error->data); + object_init_ex(&error, php_uri_ce_whatwg_url_validation_error); + zend_update_property_string(php_uri_ce_whatwg_url_validation_error, Z_OBJ(error), ZEND_STRL("context"), (const char *) lxb_error->data); const char *error_str; zval failure; @@ -199,10 +199,10 @@ static const char *fill_errors(zval *errors) } zval error_type; - ZVAL_OBJ(&error_type, zend_enum_get_case_cstr(uri_whatwg_url_validation_error_type_ce, error_str)); - zend_update_property_ex(uri_whatwg_url_validation_error_ce, Z_OBJ(error), ZSTR_KNOWN(ZEND_STR_TYPE), &error_type); + ZVAL_OBJ(&error_type, zend_enum_get_case_cstr(php_uri_ce_whatwg_url_validation_error_type, error_str)); + zend_update_property_ex(php_uri_ce_whatwg_url_validation_error, Z_OBJ(error), ZSTR_KNOWN(ZEND_STR_TYPE), &error_type); - zend_update_property(uri_whatwg_url_validation_error_ce, Z_OBJ(error), ZEND_STRL("failure"), &failure); + zend_update_property(php_uri_ce_whatwg_url_validation_error, Z_OBJ(error), ZEND_STRL("failure"), &failure); if (Z_TYPE(failure) == IS_TRUE) { result = error_str; @@ -219,7 +219,7 @@ static void throw_invalid_url_exception_during_write(zval *errors, const char *c zval err; const char *reason = fill_errors(&err); zend_object *exception = zend_throw_exception_ex( - uri_whatwg_invalid_url_exception_ce, + php_uri_ce_whatwg_invalid_url_exception, 0, "The specified %s is malformed%s%s%s", component, @@ -565,7 +565,7 @@ lxb_url_t *php_uri_parser_whatwg_parse_ex(const char *uri_str, size_t uri_str_le zval err; const char *reason = fill_errors(&err); if (url == NULL && !silent) { - zend_object *exception = zend_throw_exception_ex(uri_whatwg_invalid_url_exception_ce, 0, "The specified URI is malformed%s%s%s", reason ? " (" : "", reason ? reason : "", reason ? ")" : ""); + zend_object *exception = zend_throw_exception_ex(php_uri_ce_whatwg_invalid_url_exception, 0, "The specified URI is malformed%s%s%s", reason ? " (" : "", reason ? reason : "", reason ? ")" : ""); zend_update_property(exception->ce, exception, ZEND_STRL("errors"), &err); } if (errors != NULL) { From 125c4e725b7c0a202e0dbfedd86c3d36d79fa847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 23 Sep 2025 08:40:30 +0200 Subject: [PATCH 6/6] uri: Make the object handlers `static` and remove them from the header --- ext/uri/php_uri.c | 25 +++++++++++++------------ ext/uri/php_uri_common.h | 2 -- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index e02ff5a412e4e..b15114d09cc22 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -33,9 +33,7 @@ #include "uriparser/UriBase.h" zend_class_entry *php_uri_ce_rfc3986_uri; -zend_object_handlers uri_rfc3986_uri_object_handlers; zend_class_entry *php_uri_ce_whatwg_url; -zend_object_handlers uri_whatwg_uri_object_handlers; zend_class_entry *php_uri_ce_comparison_mode; zend_class_entry *php_uri_ce_exception; zend_class_entry *php_uri_ce_error; @@ -44,6 +42,9 @@ zend_class_entry *php_uri_ce_whatwg_invalid_url_exception; zend_class_entry *php_uri_ce_whatwg_url_validation_error_type; zend_class_entry *php_uri_ce_whatwg_url_validation_error; +static zend_object_handlers object_handlers_rfc3986_uri; +static zend_object_handlers object_handlers_whatwg_uri; + static const zend_module_dep uri_deps[] = { ZEND_MOD_REQUIRED("lexbor") ZEND_MOD_END @@ -1078,19 +1079,19 @@ static PHP_MINIT_FUNCTION(uri) { php_uri_ce_rfc3986_uri = register_class_Uri_Rfc3986_Uri(); php_uri_ce_rfc3986_uri->create_object = php_uri_object_create_rfc3986; - php_uri_ce_rfc3986_uri->default_object_handlers = &uri_rfc3986_uri_object_handlers; - memcpy(&uri_rfc3986_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - uri_rfc3986_uri_object_handlers.offset = XtOffsetOf(php_uri_object, std); - uri_rfc3986_uri_object_handlers.free_obj = php_uri_object_handler_free; - uri_rfc3986_uri_object_handlers.clone_obj = php_uri_object_handler_clone; + php_uri_ce_rfc3986_uri->default_object_handlers = &object_handlers_rfc3986_uri; + memcpy(&object_handlers_rfc3986_uri, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + object_handlers_rfc3986_uri.offset = XtOffsetOf(php_uri_object, std); + object_handlers_rfc3986_uri.free_obj = php_uri_object_handler_free; + object_handlers_rfc3986_uri.clone_obj = php_uri_object_handler_clone; php_uri_ce_whatwg_url = register_class_Uri_WhatWg_Url(); php_uri_ce_whatwg_url->create_object = php_uri_object_create_whatwg; - php_uri_ce_whatwg_url->default_object_handlers = &uri_whatwg_uri_object_handlers; - memcpy(&uri_whatwg_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - uri_whatwg_uri_object_handlers.offset = XtOffsetOf(php_uri_object, std); - uri_whatwg_uri_object_handlers.free_obj = php_uri_object_handler_free; - uri_whatwg_uri_object_handlers.clone_obj = php_uri_object_handler_clone; + php_uri_ce_whatwg_url->default_object_handlers = &object_handlers_whatwg_uri; + memcpy(&object_handlers_whatwg_uri, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + object_handlers_whatwg_uri.offset = XtOffsetOf(php_uri_object, std); + object_handlers_whatwg_uri.free_obj = php_uri_object_handler_free; + object_handlers_whatwg_uri.clone_obj = php_uri_object_handler_clone; php_uri_ce_comparison_mode = register_class_Uri_UriComparisonMode(); php_uri_ce_exception = register_class_Uri_UriException(zend_ce_exception); diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index bc70ae2073b15..109236879ae7f 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -18,9 +18,7 @@ #define PHP_URI_COMMON_H extern zend_class_entry *php_uri_ce_rfc3986_uri; -extern zend_object_handlers uri_rfc3986_uri_object_handlers; extern zend_class_entry *php_uri_ce_whatwg_url; -extern zend_object_handlers uri_whatwg_uri_object_handlers; extern zend_class_entry *php_uri_ce_comparison_mode; extern zend_class_entry *php_uri_ce_exception; extern zend_class_entry *php_uri_ce_error;