Don't leak changes to textdomain and friends across requests#6641
Don't leak changes to textdomain and friends across requests#6641cmb69 wants to merge 1 commit intophp:PHP-7.4from
Conversation
|
Any thoughts? Just leave it as it is, and document the issue? |
|
My inclination here is probably "leave it as is", especially in conjunction with your thread-safety comment. As far as I can tell, gettext() is actually thread-safe in that, say, calling textdomain() from multiple threads will not result in undefined behavior -- the global state modification occurs behind a global lock. This means that using gettext in a multi-threaded context is still "safe" if all threads call textdomain() (or other functions) with the same value. However, if we were to start restoring values on RINIT, then threads would randomly see the value change, even if they have consistent calls to textdomain(). There's really no good way to handle this, as the underlying library is simply bad, but sticking with the current behavior seems like the least bad approach at least. |
gettext leaks global state across requests, so don't repeat these tests. See also GH-6641.
|
Ah, right! Documented as php/doc-en@59e6c12. |
For
textdomain(), this is trivial; we just retrieve the default value in MINIT, and store it in a true global, and set it in RINIT.For
bind_textdomain()it is not quite as trivial; we need a module global HashTable where we store all changed domains with their original directory, and reset everything in RINIT.For
bind_textdomain_codeset(), however, there seems to be no solution, since the default value of the codeset isNULL, but when passing NULL as codeset tobind_textdomain_codeset(3), the function returns the current codeset.I'm not sure how to proceed with this. Any ideas?
Also we should probably document that ext/gettext is not thread safe …