-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
ext/phar: Use HASH_FOREACH macros and other refactorings #16073
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fairly good; only small remarks
ext/phar/dirstream.c
Outdated
if (ZSTR_LEN(str_key) > path_len && | ||
memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource->path)+1, path_len) == 0 && | ||
IS_SLASH(ZSTR_VAL(str_key)[path_len])) { | ||
ZEND_HASH_FOREACH_STR_KEY(&phar->manifest, str_key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be ZEND_HASH_MAP_FOREACH_STR_KEY
? I see there's already other code that assumes it's a map type array, which makes sense to me as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about this macro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just gonna say also: You may only use this if you know 100% sure it's not a packed array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it seems to be passing all the tests locally, and I don't see how it could be packed.
ext/phar/dirstream.c
Outdated
IS_SLASH(ZSTR_VAL(str_key)[path_len])) { | ||
} ZEND_HASH_FOREACH_END(); | ||
|
||
ZEND_HASH_FOREACH_STR_KEY(&phar->virtual_dirs, str_key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here
ext/phar/dirstream.c
Outdated
|
||
if (SUCCESS != zend_hash_move_forward(&phar->manifest)) { | ||
break; | ||
ZEND_HASH_FOREACH_STR_KEY(&phar->manifest, str_key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ZEND_HASH_MAP_FOREACH_STR_KEY
remark
ext/phar/dirstream.c
Outdated
break; | ||
} | ||
zend_string *str_key; | ||
ZEND_HASH_FOREACH_STR_KEY(manifest, str_key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ZEND_HASH_MAP_FOREACH_STR_KEY
remark
ext/phar/dirstream.c
Outdated
} | ||
entry = (char *) safe_emalloc(keylen, 1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to cast this to char *
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied and pasted from the original code but will remove.
ext/phar/dirstream.c
Outdated
@@ -260,17 +223,22 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest) /* {{{ */ | |||
entry[keylen - dirlen - 1] = '\0'; | |||
keylen = keylen - dirlen - 1; | |||
} | |||
PHAR_ADD_ENTRY: | |||
PHAR_ADD_ENTRY: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make a rule for labels, AFAIK Tim you and I all indent differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fair, this was CLion autocorrecting it. But yes a rule would be good.
Also simplify the inner if condition
This makes it more obvious that the host_len is that of resource->host
Also simplify the inner if condition
Also simplify and refactor the inside of the loop
…am() And also pass in the known string length
86b7fdf
to
cd64aab
Compare
I have fixed the commits in place and forced pushed. |
if (keylen <= dirlen) { | ||
if (keylen == 0 || keylen < dirlen || !strncmp(ZSTR_VAL(str_key), dir, dirlen)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't exactly understand what these conditions are doing, but it feels like it can be refactored to use one of the zend_string APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have to dig deeper to understand how this works, but let's cut the PR here.
} | ||
entry = safe_emalloc(keylen, 1, 1); | ||
memcpy(entry, ZSTR_VAL(str_key), keylen); | ||
entry[keylen] = '\0'; | ||
|
||
goto PHAR_ADD_ENTRY; | ||
} else { | ||
if (0 != memcmp(ZSTR_VAL(str_key), dir, dirlen)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And ditto here
Commits should be reviewed individually.