Skip to content

Commit cb49281

Browse files
authored
uri: Pass uri_object_t instead of zend_object where possible (#19854)
* uri: Take `uri_object_t` in `uri_get_debug_properties()` * uri: Take `uri_object_t` as `base_url_object` in `php_uri_instantiate_uri()` * uri: Take `uri_object_t` as `that_object` in `uri_equals()` * uri: Take `this_object` a `uri_object_t` in `uri_equals()` * uri: Take `uri_object_t` in `throw_cannot_recompose_uri_to_string()`
1 parent 2b637df commit cb49281

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

ext/uri/php_uri.c

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ static const zend_module_dep uri_deps[] = {
5151

5252
static zend_array uri_parsers;
5353

54-
static HashTable *uri_get_debug_properties(zend_object *object)
54+
static HashTable *uri_get_debug_properties(uri_object_t *object)
5555
{
56-
uri_internal_t *internal_uri = uri_internal_from_obj(object);
56+
uri_internal_t *internal_uri = &object->internal;
5757
ZEND_ASSERT(internal_uri != NULL);
5858

59-
HashTable *std_properties = zend_std_get_properties(object);
59+
const HashTable *std_properties = zend_std_get_properties(&object->std);
6060
HashTable *result = zend_array_dup(std_properties);
6161

6262
const php_uri_parser * const parser = internal_uri->parser;
@@ -317,7 +317,7 @@ static zend_result pass_errors_by_ref_and_free(zval *errors_zv, zval *errors)
317317
}
318318

319319
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri(
320-
INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const zend_object *base_url_object,
320+
INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const uri_object_t *base_url_object,
321321
bool should_throw, bool should_update_this_object, zval *errors_zv
322322
) {
323323

@@ -344,8 +344,8 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri(
344344

345345
void *base_url = NULL;
346346
if (base_url_object != NULL) {
347-
ZEND_ASSERT(base_url_object->ce == uri_object->std.ce);
348-
uri_internal_t *internal_base_url = uri_internal_from_obj(base_url_object);
347+
ZEND_ASSERT(base_url_object->std.ce == uri_object->std.ce);
348+
const uri_internal_t *internal_base_url = &base_url_object->internal;
349349
URI_ASSERT_INITIALIZATION(internal_base_url);
350350
ZEND_ASSERT(internal_base_url->parser == uri_parser);
351351
base_url = internal_base_url->uri;
@@ -384,7 +384,8 @@ static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor
384384
Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, uri_rfc3986_uri_ce)
385385
ZEND_PARSE_PARAMETERS_END();
386386

387-
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_str, base_url_object, is_constructor, is_constructor, NULL);
387+
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU,
388+
uri_str, base_url_object ? uri_object_from_obj(base_url_object) : NULL, is_constructor, is_constructor, NULL);
388389
}
389390

390391
static bool is_list_of_whatwg_validation_errors(const HashTable *array)
@@ -497,7 +498,8 @@ static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
497498
Z_PARAM_ZVAL(errors)
498499
ZEND_PARSE_PARAMETERS_END();
499500

500-
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_str, base_url_object, is_constructor, is_constructor, errors);
501+
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU,
502+
uri_str, base_url_object ? uri_object_from_obj(base_url_object) : NULL, is_constructor, is_constructor, errors);
501503
}
502504

503505
PHP_METHOD(Uri_WhatWg_Url, parse)
@@ -674,23 +676,23 @@ PHP_METHOD(Uri_Rfc3986_Uri, withFragment)
674676
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT);
675677
}
676678

677-
static void throw_cannot_recompose_uri_to_string(zend_object *object)
679+
static void throw_cannot_recompose_uri_to_string(uri_object_t *object)
678680
{
679-
zend_throw_exception_ex(uri_error_ce, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->ce->name));
681+
zend_throw_exception_ex(uri_error_ce, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->std.ce->name));
680682
}
681683

682-
static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, zend_object *comparison_mode)
684+
static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, uri_object_t *that_object, zend_object *comparison_mode)
683685
{
684-
zend_object *this_object = Z_OBJ_P(ZEND_THIS);
685-
uri_internal_t *this_internal_uri = uri_internal_from_obj(this_object);
686+
uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS);
687+
uri_internal_t *this_internal_uri = &this_object->internal;
686688
URI_ASSERT_INITIALIZATION(this_internal_uri);
687689

688-
uri_internal_t *that_internal_uri = uri_internal_from_obj(that_object);
690+
uri_internal_t *that_internal_uri = &that_object->internal;
689691
URI_ASSERT_INITIALIZATION(that_internal_uri);
690692

691-
if (this_object->ce != that_object->ce &&
692-
!instanceof_function(this_object->ce, that_object->ce) &&
693-
!instanceof_function(that_object->ce, this_object->ce)
693+
if (this_object->std.ce != that_object->std.ce &&
694+
!instanceof_function(this_object->std.ce, that_object->std.ce) &&
695+
!instanceof_function(that_object->std.ce, this_object->std.ce)
694696
) {
695697
RETURN_FALSE;
696698
}
@@ -733,15 +735,15 @@ PHP_METHOD(Uri_Rfc3986_Uri, equals)
733735
Z_PARAM_OBJ_OF_CLASS(comparison_mode, uri_comparison_mode_ce)
734736
ZEND_PARSE_PARAMETERS_END();
735737

736-
uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, that_object, comparison_mode);
738+
uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_object_from_obj(that_object), comparison_mode);
737739
}
738740

739741
PHP_METHOD(Uri_Rfc3986_Uri, toRawString)
740742
{
741743
ZEND_PARSE_PARAMETERS_NONE();
742744

743-
zend_object *this_object = Z_OBJ_P(ZEND_THIS);
744-
uri_internal_t *internal_uri = uri_internal_from_obj(this_object);
745+
uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS);
746+
uri_internal_t *internal_uri = &this_object->internal;
745747
URI_ASSERT_INITIALIZATION(internal_uri);
746748

747749
zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false);
@@ -757,8 +759,8 @@ PHP_METHOD(Uri_Rfc3986_Uri, toString)
757759
{
758760
ZEND_PARSE_PARAMETERS_NONE();
759761

760-
zend_object *this_object = Z_OBJ_P(ZEND_THIS);
761-
uri_internal_t *internal_uri = uri_internal_from_obj(this_object);
762+
uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS);
763+
uri_internal_t *internal_uri = &this_object->internal;
762764
URI_ASSERT_INITIALIZATION(internal_uri);
763765

764766
zend_string *uri_str = internal_uri->parser->to_string(internal_uri->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, false);
@@ -778,15 +780,16 @@ PHP_METHOD(Uri_Rfc3986_Uri, resolve)
778780
Z_PARAM_PATH_STR(uri_str)
779781
ZEND_PARSE_PARAMETERS_END();
780782

781-
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_str, Z_OBJ_P(ZEND_THIS), true, false, NULL);
783+
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU,
784+
uri_str, Z_URI_OBJECT_P(ZEND_THIS), true, false, NULL);
782785
}
783786

784787
PHP_METHOD(Uri_Rfc3986_Uri, __serialize)
785788
{
786789
ZEND_PARSE_PARAMETERS_NONE();
787790

788-
zend_object *this_object = Z_OBJ_P(ZEND_THIS);
789-
uri_internal_t *internal_uri = uri_internal_from_obj(this_object);
791+
uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS);
792+
uri_internal_t *internal_uri = &this_object->internal;
790793
URI_ASSERT_INITIALIZATION(internal_uri);
791794

792795
/* Serialize state: "uri" key in the first array */
@@ -806,7 +809,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize)
806809
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
807810

808811
/* Serialize regular properties: second array */
809-
ZVAL_ARR(&arr, this_object->handlers->get_properties(this_object));
812+
ZVAL_ARR(&arr, this_object->std.handlers->get_properties(&this_object->std));
810813
Z_TRY_ADDREF(arr);
811814
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
812815
}
@@ -882,9 +885,9 @@ PHP_METHOD(Uri_Rfc3986_Uri, __debugInfo)
882885
{
883886
ZEND_PARSE_PARAMETERS_NONE();
884887

885-
zend_object *object = Z_OBJ_P(ZEND_THIS);
888+
uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS);
886889

887-
RETURN_ARR(uri_get_debug_properties(object));
890+
RETURN_ARR(uri_get_debug_properties(uri_object));
888891
}
889892

890893
PHP_METHOD(Uri_WhatWg_Url, getScheme)
@@ -933,7 +936,7 @@ PHP_METHOD(Uri_WhatWg_Url, equals)
933936
Z_PARAM_OBJ_OF_CLASS(comparison_mode, uri_comparison_mode_ce)
934937
ZEND_PARSE_PARAMETERS_END();
935938

936-
uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, that_object, comparison_mode);
939+
uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_object_from_obj(that_object), comparison_mode);
937940
}
938941

939942
PHP_METHOD(Uri_WhatWg_Url, toUnicodeString)
@@ -969,15 +972,16 @@ PHP_METHOD(Uri_WhatWg_Url, resolve)
969972
Z_PARAM_ZVAL(errors)
970973
ZEND_PARSE_PARAMETERS_END();
971974

972-
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_str, Z_OBJ_P(ZEND_THIS), true, false, errors);
975+
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU,
976+
uri_str, Z_URI_OBJECT_P(ZEND_THIS), true, false, errors);
973977
}
974978

975979
PHP_METHOD(Uri_WhatWg_Url, __serialize)
976980
{
977981
ZEND_PARSE_PARAMETERS_NONE();
978982

979-
zend_object *this_object = Z_OBJ_P(ZEND_THIS);
980-
uri_internal_t *internal_uri = uri_internal_from_obj(this_object);
983+
uri_object_t *this_object = Z_URI_OBJECT_P(ZEND_THIS);
984+
uri_internal_t *internal_uri = &this_object->internal;
981985
URI_ASSERT_INITIALIZATION(internal_uri);
982986

983987
/* Serialize state: "uri" key in the first array */
@@ -997,7 +1001,7 @@ PHP_METHOD(Uri_WhatWg_Url, __serialize)
9971001
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
9981002

9991003
/* Serialize regular properties: second array */
1000-
ZVAL_ARR(&arr, this_object->handlers->get_properties(this_object));
1004+
ZVAL_ARR(&arr, this_object->std.handlers->get_properties(&this_object->std));
10011005
Z_ADDREF(arr);
10021006
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
10031007
}
@@ -1011,9 +1015,9 @@ PHP_METHOD(Uri_WhatWg_Url, __debugInfo)
10111015
{
10121016
ZEND_PARSE_PARAMETERS_NONE();
10131017

1014-
zend_object *object = Z_OBJ_P(ZEND_THIS);
1018+
uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS);
10151019

1016-
RETURN_ARR(uri_get_debug_properties(object));
1020+
RETURN_ARR(uri_get_debug_properties(uri_object));
10171021
}
10181022

10191023
PHPAPI uri_object_t *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser)

ext/uri/php_uri.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI php_uri *php_uri_parse_to_struct(
205205
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_struct_free(php_uri *uri);
206206

207207
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri(
208-
INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const zend_object *base_url_object,
208+
INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const uri_object_t *base_url_object,
209209
bool should_throw, bool should_update_this_object, zval *errors_zv
210210
);
211211

0 commit comments

Comments
 (0)