8000 gh-128279: Enhance the NetBSD compatibility for thread naming by furkanonder · Pull Request #128280 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128279: Enhance the NetBSD compatibility for thread naming #128280

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 4 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,9 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
const char *name = PyBytes_AS_STRING(name_encoded);
#ifdef __APPLE__
int rc = pthread_setname_np(name);
#elif defined(__NetBSD__)
pthread_t thread = pthread_self();
int rc = pthread_setname_np(thread, "%s", (void *)name);
Copy link
Member

Choose a reason for hiding this comment

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

Is the cast to void* really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 75b34a8df76..259c08a0991 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -2438,6 +2438,9 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
     const char *name = PyBytes_AS_STRING(name_encoded);
 #ifdef __APPLE__
     int rc = pthread_setname_np(name);
+#elif defined(__NetBSD__)
+    pthread_t thread = pthread_self();
+    int rc = pthread_setname_np(thread, "%s", name);
 #else
     pthread_t thread = pthread_self();
     int rc = pthread_setname_np(thread, name);
(END)

The compiler generates a warning when there is no cast to the void*.

gcc -pthread  -fno-strict-overflow -Wsign-compare -g -Og -Wall  -O2  -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE_BUILTIN -c ./Modules/_threadmodule.c -o Modules/_threadmodule.o
./Modules/_threadmodule.c: In function '_thread_set_name_impl':
./Modules/_threadmodule.c:2443:47: warning: passing argument 3 of 'pthread_setname_np' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 2443 |     int rc = pthread_setname_np(thread, "%s", name);
      |                                               ^~~~
In file included from ./Include/cpython/pythread.h:17,
                 from ./Include/pythread.h:124,
                 from ./Include/Python.h:120,
                 from ./Modules/_threadmodule.c:4:
/usr/include/pthread.h:160:49: note: expected 'void *' but argument is of type 'const char *'
  160 | int pthread_setname_np(pthread_t, const char *, void *);
      |                                                 ^~~~~~
--- Modules/getbuildinfo.o ---

#else
pthread_t thread = pthread_self();
int rc = pthread_setname_np(thread, name);
Expand Down
1 change: 1 addition & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7514,6 +7514,7 @@ _RESTORE_VAR([CPPFLAGS])
case "$ac_sys_system" in
Linux*) PYTHREAD_NAME_MAXLEN=15;; # Linux and Android
SunOS*) PYTHREAD_NAME_MAXLEN=31;;
NetBSD*) PYTHREAD_NAME_MAXLEN=31;;
Darwin) PYTHREAD_NAME_MAXLEN=63;;
iOS) PYTHREAD_NAME_MAXLEN=63;;
FreeBSD*) PYTHREAD_NAME_MAXLEN=98;;
Expand Down
Loading
0