Skip to content

Convert return type of various object handlers from int to zend_result #8755

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 1 commit into from
Jun 25, 2022

Conversation

iluuu1994
Copy link
Member

No description provided.

@Girgias
Copy link
Member

Girgias commented Jun 11, 2022

I hesitated doing such a change as this risks breaking more or less every extension which uses objects.

But if we are going to do this, wouldn't it make more sense to convert all relevant object handlers to zend_result?

@iluuu1994
Copy link
Member Author

zend_result has the same size as int on x64. I'm not sure how it is for other architectures but on x64 + Linux the compiler is perfectly happy keeping the implementation as int.

I converted all handlers that return zend_result typed as int, unless I missed any. I in turn didn't change int params to bools because that actually fails compilation because of different sizing.

@Girgias
Copy link
Member

Girgias commented Jun 12, 2022

zend_result has the same size as int on x64. I'm not sure how it is for other architectures but on x64 + Linux the compiler is perfectly happy keeping the implementation as int.

I converted all handlers that return zend_result typed as int, unless I missed any. I in turn didn't change int params to bools because that actually fails compilation because of different sizing.

MSVC is more strict about function pointers and will complain about them, case in point the build currently fails on Windows because of:

ext\simplexml\simplexml.c(2382): error C2220: the following warning is treated as an error
ext\simplexml\simplexml.c(2382): warning C4133: 'initializing': incompatible types - from 'zend_result (__cdecl *)(zend_object_iterator *)' to 'int (__cdecl *)(zend_object_iterator *)'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe"' : return code '0x2'
Stop.

I do think this change is a good change as we have this weird situation where some stuff expects boolean returns and others zend_result and using the appropriate type makes it explicit.

@iluuu1994
Copy link
Member Author

case in point the build currently fails on Windows because of

Yeah, it's just a warning though, it would compile without -Werror. But I see your point.

@iluuu1994
Copy link
Member Author

Nevertheless, @Girgias objections to merging this? (after I fix the Windows build of course)

@Girgias
Copy link
Member

Girgias commented Jun 22, 2022

Nope I'm good, but I think it might make sense to change all object handlers in that case instead of just those, but that can be done as a follow up PR.

@iluuu1994
Copy link
Member Author

Which are left? I checked all of them, maybe I missed some.

@Girgias
Copy link
Member

Girgias commented Jun 23, 2022

Oh yes indeed, I think it's the various object handlers which lead me to believe there where still some other ones which could be changed to zend_result but those are bool (which also might make sense as a follow up)

@iluuu1994
Copy link
Member Author

@Girgias Yes. As mentioned, converting int to bool does require changing your implementation to bool or you'll get a compilation error. I'm fine with that, as long as others are too 🙂 I'll create a follow up PR for that though.

@iluuu1994 iluuu1994 force-pushed the object-handlers-int-to-zend_result branch 4 times, most recently from c2c9a04 to f2d844e Compare June 24, 2022 20:50
@iluuu1994 iluuu1994 force-pushed the object-handlers-int-to-zend_result branch from f2d844e to 62dba74 Compare June 25, 2022 11:12
@iluuu1994 iluuu1994 force-pushed the object-handlers-int-to-zend_result branch from 62dba74 to 7f6cae0 Compare June 25, 2022 21:38
@iluuu1994 iluuu1994 merged commit 3b92a96 into php:master Jun 25, 2022
iluuu1994 added a commit to iluuu1994/PHP-Internals-Book that referenced this pull request Aug 27, 2022
nikic pushed a commit to phpinternalsbook/PHP-Internals-Book that referenced this pull request Aug 28, 2022
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