Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Thread-unsafe libc functions #127081

Open
Open
Labels
@colesbury

Description

@colesbury

Bug report

There are a a few non thread-safe libc functions used in Python that can be an issue for free threading, isolated subinterpreters, or sometimes even with the GIL.

In#126316,@vstinner fixed the usesetgrent /getgrent. It's probably a good time to look for other similar issues.

clang-tidy

clang-tidy has aconcurrency-mt-unsafe check that looks for "known-to-be-unsafe functions".

clang-tidy notes

Prerequisites: installclang-tidy-18 andbear.

./configure -C --with-pydebug --disable-gil# generate compile_commands.jsonbear -- make -j run-clang-tidy-18 -checks='-*,concurrency-mt-unsafe' -p.

Unsafe libc functions

  • localeconv(): not thread-safe, seeglibc's manual. Isnl_langinfo a substitue?
  • setlocale
  • setpwent,getpwent, andendpwent inpwdmodule.c. These are similar togrpmodule.c and can likely be addressed the same way.
  • getservbyname,getservbyport,getprotobyname inModules/socketmodule.c: usegetservbyname_r, etc.? Note these thread-safety issues affect the default build because we release the GIL around the relevant calls.
  • dbm_open,dbm_close, etc. inModules/_dbmmodule.c
  • getlogin: usegetlogin_r if available?

Unfixable by us?

Safe due to our usage

  • getc_unlocked, safe because we use it within aflockfile() call.
  • mbrtowc() - safe as long as the passed inmbstate_t * is non-NULL, which is the case in CPython.

Safe in glibc

These functions are flagged by clang-tidy because they are not guaranteed to be safe by POSIX, but they are safe in glibc. It'd be nice to verify that they are safe in other libc implementations. I don't think it's worth changing them:

Other

  • exit(): apparently concurrent calls toexit() arenot thread-safe, but I don't think it matters for our usages.
  • ptsname(): we already useptsname_r(), but the static analyzer gets confused

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp