Skip to content

Commit 3399235

Browse files
kocsismatenielsdosTimWolla
authored
Add Uri\WhatWg classes to ext/uri (#18672)
Relates to #14461 and https://wiki.php.net/rfc/url_parsing_api Co-authored-by: Niels Dossche <[email protected]> Co-authored-by: Tim Düsterhus <[email protected]>
1 parent 7d24cce commit 3399235

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3565
-46
lines changed

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ PHP 8.5 INTERNALS UPGRADE NOTES
3434
. Added ZEND_NONSTRING attribute macro for character arrays that do not
3535
represent strings. This allows to silence the GCC 15.x
3636
`-Wunterminated-string-initialization` warning.
37+
. Added the zend_update_exception_properties() function for instantiating
38+
Exception child classes. It updates the $message, $code, and $previous
39+
properties.
3740

3841
========================
3942
2. Build system changes

Zend/zend_exceptions.c

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -329,42 +329,51 @@ ZEND_COLD ZEND_METHOD(Exception, __clone)
329329
}
330330
/* }}} */
331331

332-
/* {{{ Exception constructor */
333-
ZEND_METHOD(Exception, __construct)
332+
ZEND_API zend_result zend_update_exception_properties(INTERNAL_FUNCTION_PARAMETERS, zend_string *message, zend_long code, zval *previous)
334333
{
335-
zend_string *message = NULL;
336-
zend_long code = 0;
337-
zval tmp, *object, *previous = NULL;
338-
339-
object = ZEND_THIS;
340-
341-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
342-
RETURN_THROWS();
343-
}
334+
zval tmp, *object = ZEND_THIS;
344335

345336
if (message) {
346337
ZVAL_STR_COPY(&tmp, message);
347338
zend_update_property_num_checked(NULL, Z_OBJ_P(object), ZEND_EXCEPTION_MESSAGE_OFF, ZSTR_KNOWN(ZEND_STR_MESSAGE), &tmp);
348339
if (UNEXPECTED(EG(exception))) {
349-
RETURN_THROWS();
340+
return FAILURE;
350341
}
351342
}
352343

353344
if (code) {
354345
ZVAL_LONG(&tmp, code);
355346
zend_update_property_num_checked(NULL, Z_OBJ_P(object), ZEND_EXCEPTION_CODE_OFF, ZSTR_KNOWN(ZEND_STR_CODE), &tmp);
356347
if (UNEXPECTED(EG(exception))) {
357-
RETURN_THROWS();
348+
return FAILURE;
358349
}
359350
}
360351

361352
if (previous) {
362353
Z_ADDREF_P(previous);
363354
zend_update_property_num_checked(zend_ce_exception, Z_OBJ_P(object), ZEND_EXCEPTION_PREVIOUS_OFF, ZSTR_KNOWN(ZEND_STR_PREVIOUS), previous);
364355
if (UNEXPECTED(EG(exception))) {
365-
RETURN_THROWS();
356+
return FAILURE;
366357
}
367358
}
359+
360+
return SUCCESS;
361+
}
362+
363+
/* {{{ Exception constructor */
364+
ZEND_METHOD(Exception, __construct)
365+
{
366+
zend_string *message = NULL;
367+
zend_long code = 0;
368+
zval *previous = NULL;
369+
370+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
371+
RETURN_THROWS();
372+
}
373+
374+
if (zend_update_exception_properties(INTERNAL_FUNCTION_PARAM_PASSTHRU, message, code, previous) == FAILURE) {
375+
RETURN_THROWS();
376+
}
368377
}
369378
/* }}} */
370379

@@ -401,28 +410,8 @@ ZEND_METHOD(ErrorException, __construct)
401410

402411
object = ZEND_THIS;
403412

404-
if (message) {
405-
ZVAL_STR_COPY(&tmp, message);
406-
zend_update_property_num_checked(NULL, Z_OBJ_P(object), ZEND_EXCEPTION_MESSAGE_OFF, ZSTR_KNOWN(ZEND_STR_MESSAGE), &tmp);
407-
if (UNEXPECTED(EG(exception))) {
408-
RETURN_THROWS();
409-
}
410-
}
411-
412-
if (code) {
413-
ZVAL_LONG(&tmp, code);
414-
zend_update_property_num_checked(NULL, Z_OBJ_P(object), ZEND_EXCEPTION_CODE_OFF, ZSTR_KNOWN(ZEND_STR_CODE), &tmp);
415-
if (UNEXPECTED(EG(exception))) {
416-
RETURN_THROWS();
417-
}
418-
}
419-
420-
if (previous) {
421-
Z_ADDREF_P(previous);
422-
zend_update_property_num_checked(zend_ce_exception, Z_OBJ_P(object), ZEND_EXCEPTION_PREVIOUS_OFF, ZSTR_KNOWN(ZEND_STR_PREVIOUS), previous);
423-
if (UNEXPECTED(EG(exception))) {
424-
RETURN_THROWS();
425-
}
413+
if (zend_update_exception_properties(INTERNAL_FUNCTION_PARAM_PASSTHRU, message, code, previous) == FAILURE) {
414+
RETURN_THROWS();
426415
}
427416

428417
ZVAL_LONG(&tmp, severity);

Zend/zend_exceptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce,
6969

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

72+
ZEND_API zend_result zend_update_exception_properties(INTERNAL_FUNCTION_PARAMETERS, zend_string *message, zend_long code, zval *previous);
73+
7274
/* show an exception using zend_error(severity,...), severity should be E_ERROR */
7375
ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *exception, int severity);
7476
ZEND_NORETURN void zend_exception_uncaught_error(const char *prefix, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);

Zend/zend_string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,9 @@ EMPTY_SWITCH_DEFAULT_CASE()
597597
_(ZEND_STR_HOST, "host") \
598598
_(ZEND_STR_PORT, "port") \
599599
_(ZEND_STR_USER, "user") \
600+
_(ZEND_STR_USERNAME, "username") \
600601
_(ZEND_STR_PASS, "pass") \
602+
_(ZEND_STR_PASSWORD, "password") \
601603
_(ZEND_STR_PATH, "path") \
602604
_(ZEND_STR_QUERY, "query") \
603605
_(ZEND_STR_FRAGMENT, "fragment") \

build/gen_stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,8 @@ class PropertyInfo extends VariableLike
30553055
private const PHP_85_KNOWN = [
30563056
"self" => "ZEND_STR_SELF",
30573057
"parent" => "ZEND_STR_PARENT",
3058+
"username" => "ZEND_STR_USERNAME",
3059+
"password" => "ZEND_STR_PASSWORD",
30583060
];
30593061

30603062
/**

ext/uri/config.m4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ dnl Configure options
22
dnl
33

44
PHP_INSTALL_HEADERS([ext/uri], m4_normalize([
5+
php_lexbor.h
56
php_uri.h
7+
php_uri_common.h
68
]))
79

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

18-
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])
20+
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])
1921
PHP_ADD_EXTENSION_DEP(uri, lexbor)
2022
PHP_ADD_BUILD_DIR($ext_builddir/$URIPARSER_DIR/src $ext_builddir/$URIPARSER_DIR/include)

ext/uri/config.w32

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
EXTENSION("uri", "php_uri.c", false /* never shared */, "/I ext/lexbor /I ext/uri/uriparser/include /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
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");
22

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

77
ADD_EXTENSION_DEP('uri', 'lexbor');
88
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");
9-
PHP_INSTALL_HEADERS("ext/uri", "php_uri.h uriparser/src uriparser/include");
9+
PHP_INSTALL_HEADERS("ext/uri", "php_lexbor.h php_uri.h php_uri_common.h uriparser/src uriparser/include");

0 commit comments

Comments
 (0)