-
Notifications
You must be signed in to change notification settings - Fork 123
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
Replace non-thread-safe functions #4870
Comments
Small update:
|
Correction to point 4 in the comment above:
So only locale_t loc = newlocale (LC_ALL, setlocale (LC_ALL, NULL), NULL);
// nl_langinfo line with nl_langinfo(X) replaced by nl_langinfo_l(X, loc)
freelocale (loc); (*1) not across different scopes, not switching delimiters, etc. |
I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue. |
I closed this now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. |
Using the list of functions for which POSIX does not guarantee thread-safety from here, I have now found that we use (with usage counts):
basename
: 1dirname
: 3dlerror
: 1getenv
: 9getopt
: 1getpwnam
: 1getservbyname
: 1localeconv
: 1nl_langinfo
: 1rand
: 1setenv
: 2setlocale
: 3strerror
: 18strsignal
: 1strtok
: 3system
: 1unsetenv
: 1wctomb
: 1Full results here
I found these replacement functions
getpwnam
->getpwnam_r
getservbyname
->getaddrinfo
localeconv
->nl_langinfo_l
nl_langinfo
->nl_langinfo_l
strerror
->strerror_r
strsignal
->strdescr_np
(GNU)strtok
->strtok_r
The other functions listed above have no options at all AFAICT. However, that's not so bad. If we ignore test and example code, as well as the functions which alternatives, we're left with:
basename
:dirname
:getservbyname
:getopt
:getenv
:I will write a
tree-surgeon
script forgetpwnam
->getpwnam_r
,getservbyname
->getaddrinfo
,localeconv
->nl_langinfo_l
,nl_langinfo
->nl_langinfo_l
,strerror
->strerror_r
andstrtok
->strtok_r
.basename
anddirname
are marked thread-safe on Linux and I don't know why they wouldn't be on any platform, AFAIKgetenv
can only race withsetenv
, which we only use in tests, andgetopt
is only used in the deprecated pythongen code. So I think we can ignore all of these.The text was updated successfully, but these errors were encountered: