Skip to content

Add Uri\WhatWg classes to ext/uri #18672

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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
61 changes: 25 additions & 36 deletions Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,42 +329,51 @@ ZEND_COLD ZEND_METHOD(Exception, __clone)
}
/* }}} */

/* {{{ Exception constructor */
ZEND_METHOD(Exception, __construct)
ZEND_API zend_result zend_update_exception_properties(INTERNAL_FUNCTION_PARAMETERS, zend_string *message, zend_long code, zval *previous)
{
zend_string *message = NULL;
zend_long code = 0;
zval tmp, *object, *previous = NULL;

object = ZEND_THIS;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
RETURN_THROWS();
}
zval tmp, *object = ZEND_THIS;

if (message) {
ZVAL_STR_COPY(&tmp, message);
zend_update_property_num_checked(NULL, Z_OBJ_P(object), ZEND_EXCEPTION_MESSAGE_OFF, ZSTR_KNOWN(ZEND_STR_MESSAGE), &tmp);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
return FAILURE;
}
}

if (code) {
ZVAL_LONG(&tmp, code);
zend_update_property_num_checked(NULL, Z_OBJ_P(object), ZEND_EXCEPTION_CODE_OFF, ZSTR_KNOWN(ZEND_STR_CODE), &tmp);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
return FAILURE;
}
}

if (previous) {
Z_ADDREF_P(previous);
zend_update_property_num_checked(zend_ce_exception, Z_OBJ_P(object), ZEND_EXCEPTION_PREVIOUS_OFF, ZSTR_KNOWN(ZEND_STR_PREVIOUS), previous);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
return FAILURE;
}
}

return SUCCESS;
}

/* {{{ Exception constructor */
ZEND_METHOD(Exception, __construct)
{
zend_string *message = NULL;
zend_long code = 0;
zval *previous = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
RETURN_THROWS();
}

if (zend_update_exception_properties(INTERNAL_FUNCTION_PARAM_PASSTHRU, message, code, previous) == FAILURE) {
RETURN_THROWS();
}
}
/* }}} */

Expand Down Expand Up @@ -401,28 +410,8 @@ ZEND_METHOD(ErrorException, __construct)

object = ZEND_THIS;

if (message) {
ZVAL_STR_COPY(&tmp, message);
zend_update_property_num_checked(NULL, Z_OBJ_P(object), ZEND_EXCEPTION_MESSAGE_OFF, ZSTR_KNOWN(ZEND_STR_MESSAGE), &tmp);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}
}

if (code) {
ZVAL_LONG(&tmp, code);
zend_update_property_num_checked(NULL, Z_OBJ_P(object), ZEND_EXCEPTION_CODE_OFF, ZSTR_KNOWN(ZEND_STR_CODE), &tmp);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}
}

if (previous) {
Z_ADDREF_P(previous);
zend_update_property_num_checked(zend_ce_exception, Z_OBJ_P(object), ZEND_EXCEPTION_PREVIOUS_OFF, ZSTR_KNOWN(ZEND_STR_PREVIOUS), previous);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}
if (zend_update_exception_properties(INTERNAL_FUNCTION_PARAM_PASSTHRU, message, code, previous) == FAILURE) {
RETURN_THROWS();
}

ZVAL_LONG(&tmp, severity);
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce,

extern ZEND_API void (*zend_throw_exception_hook)(zend_object *ex);

ZEND_API zend_result zend_update_exception_properties(INTERNAL_FUNCTION_PARAMETERS, zend_string *message, zend_long code, zval *previous);

/* show an exception using zend_error(severity,...), severity should be E_ERROR */
ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *exception, int severity);
ZEND_NORETURN void zend_exception_uncaught_error(const char *prefix, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,9 @@ EMPTY_SWITCH_DEFAULT_CASE()
_(ZEND_STR_HOST, "host") \
_(ZEND_STR_PORT, "port") \
_(ZEND_STR_USER, "user") \
_(ZEND_STR_USERNAME, "username") \
_(ZEND_STR_PASS, "pass") \
_(ZEND_STR_PASSWORD, "password") \
_(ZEND_STR_PATH, "path") \
_(ZEND_STR_QUERY, "query") \
_(ZEND_STR_FRAGMENT, "fragment") \
Expand Down
2 changes: 2 additions & 0 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3054,6 +3054,8 @@ class PropertyInfo extends VariableLike
private const PHP_85_KNOWN = [
"self" => "ZEND_STR_SELF",
"parent" => "ZEND_STR_PARENT",
"username" => "ZEND_STR_USERNAME",
"password" => "ZEND_STR_PASSWORD",
];

/**
Expand Down
27 changes: 23 additions & 4 deletions ext/lexbor/lexbor/url/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -4442,9 +4442,9 @@ lxb_url_api_hash_set(lxb_url_t *url, lxb_url_parser_t *parser,
return status;
}

lxb_status_t
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
bool exclude_fragment)
static lxb_status_t
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relevant PR: lexbor/lexbor#281

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR was merged as-is, so this piece of code doesn't need a patch anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to update Lexbor already in a different PR and then rebase this one / merge master to remove the changes from this one (since they are effectively unrelated)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, doing this would make more sense if it was a huge change, but since we are talking about ~ 1 function, I think it's acceptable not to create a separate PR. but 🤷 , @nielsdos wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly care either way

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me resolve this thread, unless Tim insists on doing the lexbor changes separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer landing the changes separately to make it easier to “track” changes to bundled libraries (for supply chain verification reasons). But I'd also be fine with just committing them directly without a PR.

lxb_url_serialize_body(lxb_unicode_idna_t *idna, const lxb_url_t *url, lexbor_serialize_cb_f cb,
void *ctx, bool exclude_fragment)
{
lxb_status_t status;
const lexbor_str_t *str;
Expand Down Expand Up @@ -4484,7 +4484,12 @@ lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
lexbor_serialize_write(cb, at_str.data, at_str.length, ctx, status);
}

status = lxb_url_serialize_host(&url->host, cb, ctx);
if (idna != NULL) {
status = lxb_url_serialize_host_unicode(idna, &url->host, cb, ctx);
} else {
status = lxb_url_serialize_host(&url->host, cb, ctx);
}

if (status != LXB_STATUS_OK) {
return status;
}
Expand Down Expand Up @@ -4529,6 +4534,20 @@ lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
return LXB_STATUS_OK;
}

lxb_status_t
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
bool exclude_fragment)
{
return lxb_url_serialize_body(NULL, url, cb, ctx, exclude_fragment);
}

lxb_status_t
lxb_url_serialize_idna(lxb_unicode_idna_t *idna, const lxb_url_t *url, lexbor_serialize_cb_f cb,
void *ctx, bool exclude_fragment)
{
return lxb_url_serialize_body(idna, url, cb, ctx, exclude_fragment);
}

lxb_status_t
lxb_url_serialize_scheme(const lxb_url_t *url,
lexbor_serialize_cb_f cb, void *ctx)
Expand Down
4 changes: 4 additions & 0 deletions ext/lexbor/lexbor/url/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ LXB_API lxb_status_t
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
bool exclude_fragment);

LXB_API lxb_status_t
lxb_url_serialize_idna(lxb_unicode_idna_t *idna, const lxb_url_t *url, lexbor_serialize_cb_f cb,
void *ctx, bool exclude_fragment);

LXB_API lxb_status_t
lxb_url_serialize_scheme(const lxb_url_t *url,
lexbor_serialize_cb_f cb, void *ctx);
Expand Down
4 changes: 3 additions & 1 deletion ext/uri/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ dnl Configure options
dnl

PHP_INSTALL_HEADERS([ext/uri], m4_normalize([
php_lexbor.h
php_uri.h
php_uri_common.h
]))

AC_DEFINE([URI_ENABLE_ANSI], [1], [Define to 1 for enabling ANSI support of uriparser.])
Expand All @@ -15,6 +17,6 @@ $URIPARSER_DIR/src/UriMemory.c $URIPARSER_DIR/src/UriNormalize.c $URIPARSER_DIR/
$URIPARSER_DIR/src/UriParse.c $URIPARSER_DIR/src/UriParseBase.c $URIPARSER_DIR/src/UriQuery.c \
$URIPARSER_DIR/src/UriRecompose.c $URIPARSER_DIR/src/UriResolve.c $URIPARSER_DIR/src/UriShorten.c"

PHP_NEW_EXTENSION(uri, [php_uri.c $URIPARSER_SOURCES], [no],,[-I$ext_srcdir/$URIPARSER_DIR/include -DURI_STATIC_BUILD -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
PHP_NEW_EXTENSION(uri, [php_lexbor.c php_uri.c php_uri_common.c $URIPARSER_SOURCES], [no],,[-I$ext_srcdir/$URIPARSER_DIR/include -DURI_STATIC_BUILD -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
PHP_ADD_EXTENSION_DEP(uri, lexbor)
PHP_ADD_BUILD_DIR($ext_builddir/$URIPARSER_DIR/src $ext_builddir/$URIPARSER_DIR/include)
4 changes: 2 additions & 2 deletions ext/uri/config.w32
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
EXTENSION("uri", "php_uri.c", false /* never shared */, "/I ext/lexbor /I ext/uri/uriparser/include /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
EXTENSION("uri", "php_lexbor.c php_uri.c php_uri_common.c", false /* never shared */, "/I ext/lexbor /I ext/uri/uriparser/include /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");

AC_DEFINE("URI_ENABLE_ANSI", 1, "Define to 1 for enabling ANSI support of uriparser.")
AC_DEFINE("URI_NO_UNICODE", 1, "Define to 1 for disabling unicode support of uriparser.")
ADD_FLAG("CFLAGS_URI", "/D URI_STATIC_BUILD");

ADD_EXTENSION_DEP('uri', 'lexbor');
ADD_SOURCES("ext/uri/uriparser/src", "UriCommon.c UriCompare.c UriEscape.c UriFile.c UriIp4.c UriIp4Base.c UriMemory.c UriNormalize.c UriNormalizeBase.c UriParse.c UriParseBase.c UriQuery.c UriRecompose.c UriShorten.c", "uri");
PHP_INSTALL_HEADERS("ext/uri", "php_uri.h uriparser/src uriparser/include");
PHP_INSTALL_HEADERS("ext/uri", "php_lexbor.h php_uri.h php_uri_common.h uriparser/src uriparser/include");
Loading