@@ -2392,8 +2392,16 @@ PyDoc_STRVAR(thread__get_main_thread_ident_doc,
2392
2392
Internal only. Return a non-zero integer that uniquely identifies the main thread\n\
2393
2393
of the main interpreter." );
2394
2394
2395
+ #if defined(__OpenBSD__ )
2396
+ /* pthread_*_np functions, especially pthread_{get,set}_name_np().
2397
+ pthread_np.h exists on both OpenBSD and FreeBSD but the latter declares
2398
+ pthread_getname_np() and pthread_setname_np() in pthread.h as long as
2399
+ __BSD_VISIBLE remains set.
2400
+ */
2401
+ # include <pthread_np.h>
2402
+ #endif
2395
2403
2396
- #if defined(HAVE_PTHREAD_GETNAME_NP ) || defined(MS_WINDOWS )
2404
+ #if defined(HAVE_PTHREAD_GETNAME_NP ) || defined(HAVE_PTHREAD_GET_NAME_NP ) || defined( MS_WINDOWS )
2397
2405
/*[clinic input]
2398
2406
_thread._get_name
2399
2407
@@ -2408,7 +2416,12 @@ _thread__get_name_impl(PyObject *module)
2408
2416
// Linux and macOS are limited to respectively 16 and 64 bytes
2409
2417
char name [100 ];
2410
2418
pthread_t thread = pthread_self ();
2419
+ #ifdef HAVE_PTHREAD_GETNAME_NP
2411
2420
int rc = pthread_getname_np (thread , name , Py_ARRAY_LENGTH (name ));
2421
+ #else /* defined(HAVE_PTHREAD_GET_NAME_NP) */
2422
+ int rc = 0 ; /* pthread_get_name_np() returns void */
2423
+ pthread_get_name_np (thread , name , Py_ARRAY_LENGTH (name ));
2424
+ #endif
2412
2425
if (rc ) {
2413
2426
errno = rc ;
2414
2427
return PyErr_SetFromErrno (PyExc_OSError );
@@ -2435,10 +2448,10 @@ _thread__get_name_impl(PyObject *module)
2435
2448
return name_obj ;
2436
2449
#endif
2437
2450
}
2438
- #endif // HAVE_PTHREAD_GETNAME_NP
2451
+ #endif // HAVE_PTHREAD_GETNAME_NP || HAVE_PTHREAD_GET_NAME_NP || MS_WINDOWS
2439
2452
2440
2453
2441
- #if defined(HAVE_PTHREAD_SETNAME_NP ) || defined(MS_WINDOWS )
2454
+ #if defined(HAVE_PTHREAD_SETNAME_NP ) || defined(HAVE_PTHREAD_SET_NAME_NP ) || defined( MS_WINDOWS )
2442
2455
/*[clinic input]
2443
2456
_thread.set_name
2444
2457
@@ -2487,9 +2500,13 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
2487
2500
#elif defined(__NetBSD__ )
2488
2501
pthread_t thread = pthread_self ();
2489
2502
int rc = pthread_setname_np (thread , "%s" , (void * )name );
2490
- #else
2503
+ #elif defined( HAVE_PTHREAD_SETNAME_NP )
2491
2504
pthread_t thread = pthread_self ();
2492
2505
int rc = pthread_setname_np (thread , name );
2506
+ #else /* defined(HAVE_PTHREAD_SET_NAME_NP) */
2507
+ pthread_t thread = pthread_self ();
2508
+ int rc = 0 ; /* pthread_set_name_np() returns void */
2509
+ pthread_set_name_np (thread , name );
2493
2510
#endif
2494
2511
Py_DECREF (name_encoded );
2495
2512
if (rc ) {
@@ -2527,7 +2544,7 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
2527
2544
Py_RETURN_NONE ;
2528
2545
#endif
2529
2546
}
2530
- #endif // HAVE_PTHREAD_SETNAME_NP
2547
+ #endif // HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP || MS_WINDOWS
2531
2548
2532
2549
2533
2550
static PyMethodDef thread_methods [] = {
0 commit comments