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
Make zend_parse_parameters share fast zpp implementation where possible #956
Make zend_parse_parameters share fast zpp implementation where possible #956
Conversation
|
Hey @dstogov, what do you think about this? |
ec84dfd
to
81ed9b0
Compare
This apparently broke some tests, need to look into that. |
I didn't verifiy all the code, but I like the idea On Mon, Dec 15, 2014 at 5:47 AM, Andrea Faulds notifications@github.com
|
If we were to share code, it'd probably be better to rename these functions so they don't have the leading underscore. Would |
Maybe, to go along with |
both look good. Thanks. Dmitry. On Mon, Dec 15, 2014 at 11:33 PM, Andrea Faulds notifications@github.com
|
6e68d1b
to
7a4b9c7
Compare
Hey @dstogov, I'm confused about something: Why does fast zpp check if paths aren't zero-length, yet normal zpp doesn't? It seems pretty important, since me removing that check in fast zpp for symmetry with zpp made loads of stuff segfault. |
Hi Andrea, Do you mean this line - zend_API.h:1190 - (check_null && It actually, was introduced by Anatol with commit 993d475. Anatol? Thanks. Dmitry. On Thu, Dec 18, 2014 at 5:49 AM, Andrea Faulds notifications@github.com
|
Andrea, Dmitry, zend_string's member to hold the actualy string is defined as val[1], not *val. Consequently check like if (str->val) {...} is always true, hence the change. I mean if that check is needed, which what it was looking like at the time of changing, so it should be if (str->val[0]) to dereference the first char from the string. The flow shows that the passed string is at least allocated to that time. Cheers anatol |
Hm, but i think Andrea was asking why that check is present at all. @TazeTSchnitzel in general it looks like to be making sense, as a zero length path could cause bad situations. Except you're moving it somewhere else appropriately. |
I didn't get it anyway. "empty string" is not the same as "NULL". why empty string should behave as Thanks. Dmitry. On Thu, Dec 18, 2014 at 12:42 PM, Anatol Belski notifications@github.com
|
Ah, now i see, the check_null argument regards to the subsequent check in _z_param_str(). The particular condition i was fixing (but actually not introduced) was looking like one wanted to check whether the str->val itself were NULL. Actually there are some places i see like Zend/zend_API.h:1177 if (check_null && UNEXPECTED(!str)) { but despite it has nothing to do with the zval's IS_NULL, it is technically correct. I don't think "empty string" should be the same as "NULL", just it seemed to be logic to fix the condition that way. The subsequent check in that condition line 1191 does UNEXPECTED(CHECK_NULL_PATH((_dest)->val, (_dest)->len))) { and that's using strlen(str->val) . So this place, if check_null should be used at all, should rather check zend_string pointer as whole, so !str, not str->val. |
@weltling why not if (!str->len) ? |
@laruence yes, principally it were the same as !str->val[0], so check for an empty string. But on the next line it does
so possibly it would dereference NULL which could come back from _z_param_str(). So imho it would be correct to do
on that line. |
I don't understand: You realise that |
More importantly, why does removing this check for fast zpp cause segfaults, yet zpp gets away fine without doing this check at all? |
@TazeTSchnitzel the story from the start:
The check_null is currently passed always as To the third variant - _z_param_path_str() calls _z_param_str() which can ocassionally set *dest to NULL. That's why i think thi third variant is right and should be. |
If |
Unless |
For other similar parameters, we error on NULL unless |
Yes, it seems correct. Say passing check_null you explicitly request to fail. Say placing Z_PARAM_PATH_STR_EX(str, 1, 0) would explicitly check the path correctness. |
But |
yeah, i see now what you mean ... but for _z_param_long for example it's kinda different situation. For a path i could imagine some ext dev using explicitly Z_PARAM_PATH_STR_EX for example to ensure the correct path and that would be actually correlate with 'p' or 'P'. No? |
why it makes it not fail on NULL, if it were static zend_always_inline int _z_param_path_str(zval _arg, zend_string *_dest, int check_null) |
pah, when do i learn that md |
Alright, AIUI, |
So the condition should actually be |
Wait, no, argh... I'm confused. |
be78734
to
df9a37c
Compare
9dbd3a6
to
336d15c
Compare
Aha, I finally fixed the patch! This can be merged, then :) Will do if no objections. |
I think I figured out what the segfault issue was with the NULL string check. If the string is NULL, then dereferencing it to do a nul-byte path check will segfault. It shouldn't cause zpp failure, though, as we never do this for NULL. So I've rewritten it like this:
This way, if the string is NULL, it won't do the null path check and hence won't segfault. The string isn't usually NULL. By default, we convert IS_NULL to an empty string. However, with I'd looked at ZPP to see what it did, and was confused at why it lacked this check. I see now that this wasn't a problem in ZPP, because it'd So, yeah, I think I've solved this. ^^ |
c2bb1c9
to
43196bf
Compare
Aha, yes, it's green on Travis. It works. ^^ |
@dstogov any objections to merging? I feel I double-check with you since you're the FAST_ZPP expert. |
go forward. everything looks fine. Thanks. Dmitry. On Sun, Dec 28, 2014 at 9:51 PM, Andrea Faulds notifications@github.com
|
43196bf
to
41e3fdb
Compare
Since I don't like duplication, here's a patch that makes zend_parse_parameters use the fast zpp internal functions to do parameter parsing where possible, which so zpp and fast zpp share implementations. I think that'd be good as it'd mean that for most parameter types there's only one implementation of the parsing code.
This currently can't be safely merged, since if PHP's compiled with FAST_ZPP set to 0, then the fast zpp functions don't exist. Would it be reasonable to make the internal fast zpp functions always be available, and make FAST_ZPP only control the presence of the macros? :)