Skip to content

Zend: Remove returns after zend_error_noreturn - #23285

Merged
kamil-tekiela merged 4 commits into
php:masterfrom
kamil-tekiela:Remove-code-comments
Oct 1, 2026
Merged

kamil-tekiela merged 4 commits into
php:masterfrom
kamil-tekiela:Remove-code-comments

Conversation

@kamil-tekiela

Copy link
Copy Markdown
Member

@NattyNarwhal

Copy link
Copy Markdown
Member

To be honest, I think we could just get rid of those reimplementation functions? unsetenv/setenv are standard on anything Unix shaped (as in, available on v7), and since we don't care about Windows in FPM, we don't ned to worry about that case.

N.B.: clearenv is not standard; it seems to be from a rejected POSIX proposal seemingly only glibc implemented?

@kamil-tekiela

Copy link
Copy Markdown
Member Author

To be honest, I think we could just get rid of those reimplementation functions? unsetenv/setenv are standard on anything Unix shaped (as in, available on v7), and since we don't care about Windows in FPM, we don't ned to worry about that case.

N.B.: clearenv is not standard; it seems to be from a rejected POSIX proposal seemingly only glibc implemented?

Ok, well, I don't know anything about FPM. I was just trying to fix a superficial problem. But if these functions should be removed, can you open a separate PR and I will drop the commit from my PR?

@NattyNarwhal

Copy link
Copy Markdown
Member

Ok, well, I don't know anything about FPM. I was just trying to fix a superficial problem. But if these functions should be removed, can you open a separate PR and I will drop the commit from my PR?

Just did so. Also looking at other instances of this, and I think I found a similar "fun" comment related to these functions already...

#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV)
        /*  if cgi, or fastcgi and not found in fcgi env
                check the regular environment
                this leaks, but it's only cgi anyway, we'll fix
                it for 5.0
        */              
        len = name_len + (value ? strlen(value) : 0) + sizeof("=") + 2;
        buf = (char *) malloc(len);     
        if (buf == NULL) {
                return getenv(name);            
        }                                               
#endif                  

NattyNarwhal added a commit that referenced this pull request Sep 28, 2026
These are functions that have existed since Unix V7. Windows doesn't
have them, but we don't support FPM on Windows (and in ext/standard,
there are other ways to emulate it that don't involve WTF comments).

clearenv is kept as this was from a rejected POSIX proposal that only
some systems implement (Linux, FreeBSD, some 90s Unices).

Also removes the WTF comment incidentally; see GH-23285.
@kamil-tekiela kamil-tekiela changed the title Remove code comments Zend: Remove returns after zend_error_noreturn Sep 29, 2026

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Several of the functions “now” had a constant return value of SUCCESS. Should we voidify them at the same time? This will likely allow removing (dead) checks in callers as well.

I'm also noting they also wrongly use int instead of zend_result as the return type, which would implicitly be cleaned up when voidifying them.

@kamil-tekiela

Copy link
Copy Markdown
Member Author

Several of the functions “now” had a constant return value of SUCCESS. Should we voidify them at the same time? This will likely allow removing (dead) checks in callers as well.

I'm also noting they also wrongly use int instead of zend_result as the return type, which would implicitly be cleaned up when voidifying them.

Should I do it in this PR or in a separate one?

@TimWolla

Copy link
Copy Markdown
Member

For me adjusting the return type logically belongs to this change / PR. It's already removing return statements, and adjusting the return type is just the final consequence.

@kamil-tekiela

Copy link
Copy Markdown
Member Author

Several of the functions “now” had a constant return value of SUCCESS. Should we voidify them at the same time? This will likely allow removing (dead) checks in callers as well.

I'm also noting they also wrongly use int instead of zend_result as the return type, which would implicitly be cleaned up when voidifying them.

I changed it to zend_result but I could not vodidify them because of zend_implement_serializable which is the only one that returns FAILURE.

@TimWolla

Copy link
Copy Markdown
Member

but I could not vodidify them because of zend_implement_serializable which is the only one that returns FAILURE.

Ah, I didn't realize that the signature needs to match a function pointer signature. That's unfortunate, but zend_result is an improvement.

@TimWolla

Copy link
Copy Markdown
Member

Actually, looking at how interface_gets_implemented() is used: A FAILURE will just result in a generic zend_error_noreturn(), so voidifying that callback and expecting implementers to zend_error_noreturn() themselves would be reasonable. Changing the int to zend_result is already a breaking change anyway.

@TimWolla
TimWolla requested a review from Girgias September 30, 2026 20:29
@ndossche

ndossche commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

I think these kinds of changes are pointless on its own, unless you also take into account what Tim says wrt voidifying. Right now the value of the PR (except for the zend_result type) is still questionable.
Removing returns after the noreturns is of course technically correct, but may warn on some compilers (which was the reason why some returns were added), and don't create more optimization opportunities.
It's only really good to uncover the cases that Tim points out.

@kamil-tekiela

Copy link
Copy Markdown
Member Author

Makes sense. Both of you have very good points. I have moved the error inside zend_implement_serializable and made the signature void.

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM except for Changelog remark, thanks.

Comment thread UPGRADING.INTERNALS
This might have been an issue on older MSVC but presumably it's no longer the case as zend_mark_internal_attribute has not had a return for the past 4 years and nobody complained.
@kamil-tekiela
kamil-tekiela merged commit 4ab0ffb into php:master Oct 1, 2026
18 checks passed
@kamil-tekiela
kamil-tekiela deleted the Remove-code-comments branch October 2, 2026 12:38
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.

4 participants