Add the Uri\Rfc3986\Uri class to ext/uri without wither support#18836
Add the Uri\Rfc3986\Uri class to ext/uri without wither support#18836kocsismate merged 15 commits intophp:masterfrom
Conversation
43c1d9f to
155e070
Compare
ndossche
left a comment
There was a problem hiding this comment.
Cursory glance, I see there's some todos wrt memory management as well so maybe I'll wait a bit on that
TimWolla
left a comment
There was a problem hiding this comment.
Some first remarks from just looking at the diff on GitHub.
There was a problem hiding this comment.
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.
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.
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 |
TimWolla
left a comment
There was a problem hiding this comment.
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.
I don't particularly like that you reordered these. It makes the diff hard to read.
There was a problem hiding this comment.
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.
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.
Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
TimWolla
left a comment
There was a problem hiding this comment.
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.
| 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 are a few WIP parts but the PR can already be reviewed.
Relates to #14461 and https://wiki.php.net/rfc/url_parsing_api