Skip to content

Commit bf67f0d

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 243aedd commit bf67f0d

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
@@ -1002,16 +1002,6 @@ zend_object *uri_clone_obj_handler(zend_object *object)
10021002
return &new_uri_object->std;
10031003
}
10041004

1005-
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_implementation_set_object_handlers(zend_class_entry *ce, zend_object_handlers *object_handlers)
1006-
{
1007-
ce->create_object = uri_create_object_handler;
1008-
ce->default_object_handlers = object_handlers;
1009-
memcpy(object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
1010-
object_handlers->offset = XtOffsetOf(uri_object_t, std);
1011-
object_handlers->free_obj = uri_free_obj_handler;
1012-
object_handlers->clone_obj = uri_clone_obj_handler;
1013-
}
1014-
10151005
PHPAPI zend_result php_uri_parser_register(const uri_parser_t *uri_parser)
10161006
{
10171007
zend_string *key = zend_string_init_interned(uri_parser->name, strlen(uri_parser->name), true);
@@ -1032,10 +1022,20 @@ PHPAPI zend_result php_uri_parser_register(const uri_parser_t *uri_parser)
10321022
static PHP_MINIT_FUNCTION(uri)
10331023
{
10341024
uri_rfc3986_uri_ce = register_class_Uri_Rfc3986_Uri();
1035-
php_uri_implementation_set_object_handlers(uri_rfc3986_uri_ce, &uri_rfc3986_uri_object_handlers);
1025+
uri_rfc3986_uri_ce->create_object = uri_create_object_handler;
1026+
uri_rfc3986_uri_ce->default_object_handlers = &uri_rfc3986_uri_object_handlers;
1027+
memcpy(&uri_rfc3986_uri_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1028+
uri_rfc3986_uri_object_handlers.offset = XtOffsetOf(uri_object_t, std);
1029+
uri_rfc3986_uri_object_handlers.free_obj = uri_free_obj_handler;
1030+
uri_rfc3986_uri_object_handlers.clone_obj = uri_clone_obj_handler;
10361031

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

10401040
uri_comparison_mode_ce = register_class_Uri_UriComparisonMode();
10411041
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)