gh-128279: Enhance the NetBSD compatibility for thread naming - #128280
Merged
Conversation
furkanonder
requested review from
corona10 and
erlend-aasland
as code owners
December 27, 2024 00:34
vstinner
reviewed
Dec 28, 2024
| int rc = pthread_setname_np(name); | ||
| #elif defined(__NetBSD__) | ||
| pthread_t thread = pthread_self(); | ||
| int rc = pthread_setname_np(thread, "%s", (void *)name); |
Member
There was a problem hiding this comment.
Is the cast to void* really needed?
Contributor
Author
There was a problem hiding this comment.
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 ---
Member
|
Merged, thank you! |
Contributor
Author
You're welcome. |
srinivasreddy
pushed a commit
to srinivasreddy/cpython
that referenced
this pull request
Jan 8, 2025
…ython#128280) Enhance NetBSD compatibility for thread naming in _threadmodule.c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.