Skip to content

Conversation

TimWolla
Copy link
Member

@TimWolla TimWolla commented Sep 21, 2025

This PR includes and depends on #19903 with the first 2 commits. The PRs are independent for better commit history after merging.

The purpose of this change is to improve readability of the code by avoiding:

  • Having multiple local variables to refer to the same “object”.
  • Avoiding the .internal member that does not provide a value-add when already dealing with URI objects and just adds needless verbosity.

Comment on lines -348 to +347
const uri_internal_t *internal_base_url = &base_url_object->internal;
URI_ASSERT_INITIALIZATION(internal_base_url);
ZEND_ASSERT(internal_base_url->parser == uri_parser);
base_url = internal_base_url->uri;
ZEND_ASSERT(base_url_object->uri != NULL);
ZEND_ASSERT(base_url_object->parser == uri_parser);
base_url = base_url_object->uri;
Copy link
Member Author

Choose a reason for hiding this comment

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

I think the improvement is particularly visible here, since the assertions are no longer mixed with declarations.

Changes performed with Coccinelle with some minor adjustments in places where
it choked due to macros:

    @@
    expression e;
    @@

    - Z_URI_INTERNAL_P(e)
    + &Z_URI_OBJECT_P(e)->internal

    @@
    expression e;
    @@

    - uri_internal_from_obj(e)
    + &uri_object_from_obj(e)->internal
While a `NULL` pointer to `zend_object` would result in `->internal` also
sitting at `0`, this is not a particularly useful assertion to have. Instead
just assert that we have a parsed `->uri` available.

Changes made with Coccinelle + some manual adjustments:

    @@
    uri_internal_t *u;
    expression e;
    @@

     u = &Z_URI_OBJECT_P(e)->internal
    ... when != u
    - URI_ASSERT_INITIALIZATION(u);
    + ZEND_ASSERT(u->uri != NULL);

    @@
    uri_internal_t *u;
    expression e;
    @@

     u = &uri_object_from_obj(e)->internal
    ... when != u
    - URI_ASSERT_INITIALIZATION(u);
    + ZEND_ASSERT(u->uri != NULL);
After this, `uri_internal_t` will only be used when interacting with the URI
parsers without having a full-blown URI object.

Changes made with Coccinelle and some manual adjustments:

    @@
    identifier u;
    expression e;
    @@

    - uri_internal_t *u = &e->internal;
    + uri_object_t *u = e;

    @@
    uri_object_t *u;
    identifier t;
    @@

    - u->internal.t
    + u->t
@TimWolla
Copy link
Member Author

Rebased after the merge of #19903.

@TimWolla TimWolla requested a review from a team September 22, 2025 07:00
Copy link
Member

@edorian edorian left a comment

Choose a reason for hiding this comment

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

RM approval 👍 No technical review performed

@TimWolla TimWolla merged commit 707f785 into php:master Sep 22, 2025
9 checks passed
@TimWolla TimWolla deleted the uri-internal-t branch September 22, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants