Skip to content

ext/phar: Do some refactoring to make the code easier to understand #15426

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

Merged
merged 10 commits into from
Aug 23, 2024

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Aug 15, 2024

No description provided.

@Girgias Girgias force-pushed the phar-refactoring branch 4 times, most recently from 0619888 to aea37bf Compare August 16, 2024 23:40
@Girgias Girgias marked this pull request as ready for review August 17, 2024 01:34
@Girgias Girgias requested a review from kocsismate as a code owner August 17, 2024 01:34
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

Mostly good, see comments

}

if (ZSTR_LEN(new_alias) == 0) {
zend_argument_value_error(1, "cannot be empty");
Copy link
Member

Choose a reason for hiding this comment

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

Use that new fancy helper function with consistent wording please.

int old_temp, readd = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &alias, &alias_len) == FAILURE) {
// TODO Should this be using a "P" modifier?
Copy link
Member

Choose a reason for hiding this comment

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

Possibly, but let's not concern ourselves with that in this PR.

RETURN_THROWS();
}

if (ZSTR_LEN(new_alias) == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Adding this check will make it impossible to unset an alias, i.e. you can now do setAlias("") to throw away the alias. I think that behaviour should be kept because there's no other way to do it otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I am confused how this is handled tho? As it feels like if you try to call setAlias() on two different `PharObject's you'll get an exception? But I didn't try it nor added tests, so I'm shunting this for later.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I am confused how this is handled tho? As it feels like if you try to call setAlias() on two different `PharObject's you'll get an exception?

I don't understand the question

Copy link
Member Author

Choose a reason for hiding this comment

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

From a quick glance it seems like trying to set an empty string as an alias for two different PharObjects would cause a PharException, but I might be missing something.

zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot create any files in magic \".phar\" directory");
return;
}
}

/* TODO How to handle Windows path normalisation with zend_string ? */
Copy link
Member

Choose a reason for hiding this comment

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

This isn't that bad compared to some other stuff I've seen

php_stream *resource;
zval zresource;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s!", &fname, &fname_len, &localname, &localname_len) == FAILURE) {
// TODO Should local_name use "P" modifier?
Copy link
Member

Choose a reason for hiding this comment

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

Probably, but not for this PR

@Girgias Girgias merged commit f9c69bc into php:master Aug 23, 2024
10 checks passed
@Girgias Girgias deleted the phar-refactoring branch August 23, 2024 16:42
Ayesh added a commit to Ayesh/php-src that referenced this pull request Aug 24, 2024
Ayesh added a commit to Ayesh/php-src that referenced this pull request Aug 24, 2024
Ayesh added a commit to Ayesh/php-src that referenced this pull request Aug 25, 2024
…nges

Follow-up to phpGH-15426 (6836cae)

Co-Authored-By: Gina Peter Banyard <girgias@php.net>
Girgias added a commit that referenced this pull request Aug 25, 2024
…n type changes (#15566)

Follow-up to GH-15426 (6836cae)

Co-authored-by: Gina Peter Banyard <girgias@php.net>
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.

2 participants