Skip to content

Commit 4fcc6ae

Browse files
committed
uri: Inline implementation of php_uri_implementation_set_object_handlers()
There is no one time fits all solution to initialization of the object handlers. A follow-up commit will use distinct `create_object` handlers for each parser class. Explicitly spelling out the handlers is a well-established pattern in php-src and I don't see a reason to diverge from that with an intransparent helper method.
1 parent b90ab81 commit 4fcc6ae

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

ext/uri/php_uri.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,16 +1000,6 @@ static zend_object *uri_clone_obj_handler(zend_object *object)
10001000
return &new_uri_object->std;
10011001
}
10021002

1003-
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_implementation_set_object_handlers(zend_class_entry *ce, zend_object_handlers *object_handlers)
1004-
{
1005-
ce->create_object = uri_create_object_handler;
1006-
ce->default_object_handlers = object_handlers;
1007-
memcpy(object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
1008-
object_handlers->offset = XtOffsetOf(uri_object_t, std);
1009-
object_handlers->free_obj = uri_free_obj_handler;
1010-
object_handlers->clone_obj = uri_clone_obj_handler;
1011-
}
1012-
10131003
PHPAPI zend_result php_uri_parser_register(const uri_parser_t *uri_parser)
10141004
{
10151005
zend_string *key = zend_string_init_interned(uri_parser->name, strlen(uri_parser->name), true);
@@ -1030,10 +1020,20 @@ PHPAPI zend_result php_uri_parser_register(const uri_parser_t *uri_parser)
10301020
static PHP_MINIT_FUNCTION(uri)
10311021
{
10321022
uri_rfc3986_uri_ce = register_class_Uri_Rfc3986_Uri();
1033-
php_uri_implementation_set_object_handlers(uri_rfc3986_uri_ce, &uri_rfc3986_uri_object_handlers);
1023+
uri_rfc3986_uri_ce->create_object = uri_create_object_handler;
1024+
uri_rfc3986_uri_ce->default_object_handlers = &uri_rfc3986_uri_object_handlers;
1025+
memcpy(&uri_rfc3986_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1026+
uri_rfc3986_uri_object_handlers.offset = XtOffsetOf(uri_object_t, std);
1027+
uri_rfc3986_uri_object_handlers.free_obj = uri_free_obj_handler;
1028+
uri_rfc3986_uri_object_handlers.clone_obj = uri_clone_obj_handler;
10341029

10351030
uri_whatwg_url_ce = register_class_Uri_WhatWg_Url();
1036-
php_uri_implementation_set_object_handlers(uri_whatwg_url_ce, &uri_whatwg_uri_object_handlers);
1031+
uri_whatwg_url_ce->create_object = uri_create_object_handler;
1032+
uri_whatwg_url_ce->default_object_handlers = &uri_whatwg_uri_object_handlers;
1033+
memcpy(&uri_whatwg_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1034+
uri_whatwg_uri_object_handlers.offset = XtOffsetOf(uri_object_t, std);
1035+
uri_whatwg_uri_object_handlers.free_obj = uri_free_obj_handler;
1036+
uri_whatwg_uri_object_handlers.clone_obj = uri_clone_obj_handler;
10371037

10381038
uri_comparison_mode_ce = register_class_Uri_UriComparisonMode();
10391039
uri_exception_ce = register_class_Uri_UriException(zend_ce_exception);

ext/uri/php_uri.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,4 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri(
209209
bool should_throw, bool should_update_this_object, zval *errors_zv
210210
);
211211

212-
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_implementation_set_object_handlers(zend_class_entry *ce, zend_object_handlers *object_handlers);
213-
214212
#endif

0 commit comments

Comments
 (0)