bpo-29859: Fix error messages from return codes for pthread_* calls (… · python/cpython@fe30339

@@ -143,6 +143,8 @@ typedef struct {

143143

} pthread_lock;

144144145145

#define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; }

146+

#define CHECK_STATUS_PTHREAD(name) if (status != 0) { fprintf(stderr, \

147+

"%s: %s\n", name, strerror(status)); error = 1; }

146148147149

/*

148150

* Initialization.

@@ -417,7 +419,7 @@ PyThread_allocate_lock(void)

417419418420

status = pthread_mutex_init(&lock->mut,

419421

pthread_mutexattr_default);

420-

CHECK_STATUS("pthread_mutex_init");

422+

CHECK_STATUS_PTHREAD("pthread_mutex_init");

421423

/* Mark the pthread mutex underlying a Python mutex as

422424

pure happens-before. We can't simply mark the

423425

Python-level mutex as a mutex because it can be

@@ -427,7 +429,7 @@ PyThread_allocate_lock(void)

427429428430

status = pthread_cond_init(&lock->lock_released,

429431

pthread_condattr_default);

430-

CHECK_STATUS("pthread_cond_init");

432+

CHECK_STATUS_PTHREAD("pthread_cond_init");

431433432434

if (error) {

433435

PyMem_RawFree((void *)lock);

@@ -452,10 +454,10 @@ PyThread_free_lock(PyThread_type_lock lock)

452454

* and must have the cond destroyed first.

453455

*/

454456

status = pthread_cond_destroy( &thelock->lock_released );

455-

CHECK_STATUS("pthread_cond_destroy");

457+

CHECK_STATUS_PTHREAD("pthread_cond_destroy");

456458457459

status = pthread_mutex_destroy( &thelock->mut );

458-

CHECK_STATUS("pthread_mutex_destroy");

460+

CHECK_STATUS_PTHREAD("pthread_mutex_destroy");

459461460462

PyMem_RawFree((void *)thelock);

461463

}

@@ -472,7 +474,7 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,

472474

lock, microseconds, intr_flag));

473475474476

status = pthread_mutex_lock( &thelock->mut );

475-

CHECK_STATUS("pthread_mutex_lock[1]");

477+

CHECK_STATUS_PTHREAD("pthread_mutex_lock[1]");

476478477479

if (thelock->locked == 0) {

478480

success = PY_LOCK_ACQUIRED;

@@ -494,13 +496,13 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,

494496

&thelock->mut, &ts);

495497

if (status == ETIMEDOUT)

496498

break;

497-

CHECK_STATUS("pthread_cond_timed_wait");

499+

CHECK_STATUS_PTHREAD("pthread_cond_timed_wait");

498500

}

499501

else {

500502

status = pthread_cond_wait(

501503

&thelock->lock_released,

502504

&thelock->mut);

503-

CHECK_STATUS("pthread_cond_wait");

505+

CHECK_STATUS_PTHREAD("pthread_cond_wait");

504506

}

505507506508

if (intr_flag && status == 0 && thelock->locked) {

@@ -518,7 +520,7 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,

518520

}

519521

if (success == PY_LOCK_ACQUIRED) thelock->locked = 1;

520522

status = pthread_mutex_unlock( &thelock->mut );

521-

CHECK_STATUS("pthread_mutex_unlock[1]");

523+

CHECK_STATUS_PTHREAD("pthread_mutex_unlock[1]");

522524523525

if (error) success = PY_LOCK_FAILURE;

524526

dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) -> %d\n",

@@ -536,16 +538,16 @@ PyThread_release_lock(PyThread_type_lock lock)

536538

dprintf(("PyThread_release_lock(%p) called\n", lock));

537539538540

status = pthread_mutex_lock( &thelock->mut );

539-

CHECK_STATUS("pthread_mutex_lock[3]");

541+

CHECK_STATUS_PTHREAD("pthread_mutex_lock[3]");

540542541543

thelock->locked = 0;

542544543545

/* wake up someone (anyone, if any) waiting on the lock */

544546

status = pthread_cond_signal( &thelock->lock_released );

545-

CHECK_STATUS("pthread_cond_signal");

547+

CHECK_STATUS_PTHREAD("pthread_cond_signal");

546548547549

status = pthread_mutex_unlock( &thelock->mut );

548-

CHECK_STATUS("pthread_mutex_unlock[3]");

550+

CHECK_STATUS_PTHREAD("pthread_mutex_unlock[3]");

549551

}

550552551553

#endif /* USE_SEMAPHORES */