Skip to content
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

Move a few custom type checks to ZPP #6034

Closed
wants to merge 4 commits into from

Conversation

@kocsismate
Copy link
Member

@kocsismate kocsismate commented Aug 22, 2020

No description provided.

@kocsismate kocsismate changed the title Add more accurate type info for stubs again Move a few custom type checks to ZPP Aug 22, 2020
@kocsismate kocsismate force-pushed the kocsismate:more-accurate-types2 branch 2 times, most recently from 735e36d to ed8e8d8 Aug 22, 2020
ext/xml/xml.c Outdated Show resolved Hide resolved
@kocsismate kocsismate force-pushed the kocsismate:more-accurate-types2 branch from ed8e8d8 to edede27 Aug 22, 2020
zend_string *field_str;
zend_string *field_str, *pv_field_str;
zend_long pv_field_long;
Comment on lines -1739 to +1740

This comment has been minimized.

@carusogabriel

carusogabriel Aug 22, 2020
Member

Quick question: moving from zvals to zend_(string|int|etc..) types, are they cheaper?

Also, is that a good practice to follow?

This comment has been minimized.

@kocsismate

kocsismate Sep 1, 2020
Author Member

@carusogabriel I don't think they are noticably cheaper. The real benefit is being able to accept arguments whose type is validated according to the standard semantics, rather than in a custom way.

@kocsismate kocsismate force-pushed the kocsismate:more-accurate-types2 branch 3 times, most recently from d7e055e to fc60c36 Aug 23, 2020
ext/mysqli/mysqli_api.c Outdated Show resolved Hide resolved
@kocsismate kocsismate force-pushed the kocsismate:more-accurate-types2 branch 3 times, most recently from 16d3169 to 22abceb Aug 24, 2020
}
ret = mysql_options(mysql->mysql, mysql_option, (char *) &mysql_value_long);
} else {
ret = 1;

This comment has been minimized.

@nikic

nikic Aug 25, 2020
Member

I'm a bit unsure about this one. If we consider a call like mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, '100'), this was previously valid and the '100' was interpreted as 100. Now it will throw instead. That is, it's now necessary to match the type of the option, rather than the option forcing the type of the value.

This comment has been minimized.

@kocsismate

kocsismate Aug 27, 2020
Author Member

Yeah, it's a valid critique against the (former) implementation. Now, I've just pushed a change which tries to address this by trying to convert the type to the expected one if necessary. I like this solution, but I'm curious whether you see any problem with this approach.

This comment has been minimized.

@nikic

nikic Sep 1, 2020
Member

Not a fan of this. This has made the implementation more complicated than it was before.

I think it is better to keep this as a mixed argument. The fact that only int|string is accepted is rather incidential imho (e.g. there's no reason why in the future an option using float or bool value couldn't be added).

This comment has been minimized.

@kocsismate

kocsismate Sep 1, 2020
Author Member

I reverted all these changes (from mysqli and xml both), but stayed with the string|int PHPDoc type hints.

ext/xml/xml.c Outdated Show resolved Hide resolved
@kocsismate kocsismate force-pushed the kocsismate:more-accurate-types2 branch from 22abceb to 0126355 Aug 27, 2020
ext/mysqli/mysqli_api.c Outdated Show resolved Hide resolved
@kocsismate kocsismate force-pushed the kocsismate:more-accurate-types2 branch 2 times, most recently from 9408fe8 to 7a26727 Aug 31, 2020

if (str_headers) {
tmp_headers = zend_string_init(ZSTR_VAL(str_headers), ZSTR_LEN(str_headers), 0);
MAIL_ASCIIZ_CHECK_MBSTRING(ZSTR_VAL(tmp_headers), ZSTR_LEN(tmp_headers));

This comment has been minimized.

@nikic

nikic Sep 1, 2020
Member

Drive-by note: I think the MAIL_ASCIIZ_CHECK_MBSTRING calls above are corrupting the argument strings :(

}
ret = mysql_options(mysql->mysql, mysql_option, (char *) &mysql_value_long);
} else {
ret = 1;

This comment has been minimized.

@nikic

nikic Sep 1, 2020
Member

Not a fan of this. This has made the implementation more complicated than it was before.

I think it is better to keep this as a mixed argument. The fact that only int|string is accepted is rather incidential imho (e.g. there's no reason why in the future an option using float or bool value couldn't be added).

kocsismate added 3 commits Aug 24, 2020
@kocsismate kocsismate force-pushed the kocsismate:more-accurate-types2 branch 4 times, most recently from 44a5c7a to 05ba96f Sep 1, 2020
@kocsismate kocsismate force-pushed the kocsismate:more-accurate-types2 branch from 05ba96f to 8b07b3e Sep 1, 2020
@nikic
nikic approved these changes Sep 2, 2020
@php-pulls php-pulls closed this in 3e800e9 Sep 2, 2020
@kocsismate kocsismate deleted the kocsismate:more-accurate-types2 branch Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants