-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add the Uri\Rfc3986\Uri class to ext/uri without wither support #18836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
43c1d9f
to
155e070
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursory glance, I see there's some todos wrt memory management as well so maybe I'll wait a bit on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some first remarks from just looking at the diff on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I'm only noticing now: I think this should rather be called ext/uri/parser_rfc3986.c
and php_lexbor.c
would be ext/uri/parser_whatwg.c
. The php_uriparser.c
name is confusing to me, because uriparser
is an extremely generic term.
To give another comparison with ext/random, since it is architecturally similar: Each engine has its own engine_enginename.c
file, e.g. engine_xoshiro256starstar.c
.
efree(uriparser_uris); | ||
} | ||
|
||
const uri_handler_t uriparser_uri_handler = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And similarly the public symbols in the file should also be prefixed with php_uri_
. Just uriparser_
can conflict with the uriparser library itself.
Here I would suggest php_uri_rfc3986_handler
.
But I'm also happy to leave this to a follow-up to not introduce too much churn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this and the file renaming is something that I'm happy to do after most parts are merged.
This comment was marked as resolved.
This comment was marked as resolved.
@TimWolla Thanks for the patch, it's awesome! TBH I didn't even think about using the |
@kocsismate When stack allocating the struct the code should become even simpler (and possibly faster, due to fewer pointer indirection). |
0b3cfd8
to
062dc4d
Compare
226735b
to
7541b33
Compare
I have no further suggestions, but don't feel qualified to approve this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly okay for an initial merge now. The additional clean-up can happen in a follow-up to move forward. The leak should be fixed, though.
PHP_METHOD(Uri_WhatWg_InvalidUrlException, __construct) | ||
{ | ||
zend_string *message = NULL; | ||
zval *errors = NULL; | ||
zend_long code = 0; | ||
zval *previous = NULL; | ||
|
||
ZEND_PARSE_PARAMETERS_START(0, 4) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_STR(message) | ||
Z_PARAM_ARRAY(errors) | ||
Z_PARAM_LONG(code) | ||
Z_PARAM_OBJECT_OF_CLASS_OR_NULL(previous, zend_ce_throwable) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
if (zend_update_exception_properties(INTERNAL_FUNCTION_PARAM_PASSTHRU, message, code, previous) == FAILURE) { | ||
RETURN_THROWS(); | ||
} | ||
|
||
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); | ||
} else { | ||
zend_update_property(uri_whatwg_invalid_url_exception_ce, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), errors); | ||
} | ||
if (EG(exception)) { | ||
RETURN_THROWS(); | ||
} | ||
} | ||
|
||
PHP_METHOD(Uri_WhatWg_UrlValidationError, __construct) | ||
{ | ||
zend_string *context; | ||
zval *type; | ||
bool failure; | ||
|
||
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_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); | ||
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); | ||
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); | ||
if (EG(exception)) { | ||
RETURN_THROWS(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't particularly like that you reordered these. It makes the diff hard to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I should have waited a little bit, sorry! A few methods had to be removed due to the added implementation aliases, and that was the point I think when I moved a few methods.
PHP_METHOD(Uri_Rfc3986_Uri, equals) | ||
{ | ||
zend_object *that_object; | ||
zend_object *comparison_mode = NULL; | ||
|
||
ZEND_PARSE_PARAMETERS_START(1, 2) | ||
Z_PARAM_OBJ_OF_CLASS(that_object, uri_rfc3986_uri_ce) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_OBJ_OF_CLASS(comparison_mode, uri_comparison_mode_ce) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, that_object, comparison_mode); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to the other remark about file naming and organization, it might make sense to move the PHP_METHOD
implementations into the matching source file to keep php_uri.c
slim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the things that Tim said, here some small remarks
Co-authored-by: Tim Düsterhus <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor suggestions, but this is good to merge for me now. Anything else can be done in follow-ups.
ext/uri/php_uriparser.c
Outdated
static size_t str_to_int(const char *str, size_t len) | ||
{ | ||
int result = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static size_t str_to_int(const char *str, size_t len) | |
{ | |
int result = 0; | |
static zend_long str_to_int(const char *str, size_t len) | |
{ | |
zend_long result = 0; |
It's being stored in a zend_long
, so should return a zend_long
. But perhaps @nielsdos has other suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No your suggestion is fine
There are a few WIP parts but the PR can already be reviewed.
Relates to #14461 and https://wiki.php.net/rfc/url_parsing_api