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

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

`

143

143

`} pthread_lock;

`

144

144

``

145

145

`#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; }

`

146

148

``

147

149

`/*

`

148

150

` * Initialization.

`

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

`

417

419

``

418

420

`status = pthread_mutex_init(&lock->mut,

`

419

421

`pthread_mutexattr_default);

`

420

``

`-

CHECK_STATUS("pthread_mutex_init");

`

``

422

`+

CHECK_STATUS_PTHREAD("pthread_mutex_init");

`

421

423

`/* Mark the pthread mutex underlying a Python mutex as

`

422

424

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

`

423

425

` Python-level mutex as a mutex because it can be

`

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

`

427

429

``

428

430

`status = pthread_cond_init(&lock->lock_released,

`

429

431

`pthread_condattr_default);

`

430

``

`-

CHECK_STATUS("pthread_cond_init");

`

``

432

`+

CHECK_STATUS_PTHREAD("pthread_cond_init");

`

431

433

``

432

434

`if (error) {

`

433

435

`PyMem_RawFree((void *)lock);

`

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

`

452

454

` * and must have the cond destroyed first.

`

453

455

` */

`

454

456

`status = pthread_cond_destroy( &thelock->lock_released );

`

455

``

`-

CHECK_STATUS("pthread_cond_destroy");

`

``

457

`+

CHECK_STATUS_PTHREAD("pthread_cond_destroy");

`

456

458

``

457

459

`status = pthread_mutex_destroy( &thelock->mut );

`

458

``

`-

CHECK_STATUS("pthread_mutex_destroy");

`

``

460

`+

CHECK_STATUS_PTHREAD("pthread_mutex_destroy");

`

459

461

``

460

462

`PyMem_RawFree((void *)thelock);

`

461

463

`}

`

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

`

472

474

`lock, microseconds, intr_flag));

`

473

475

``

474

476

`status = pthread_mutex_lock( &thelock->mut );

`

475

``

`-

CHECK_STATUS("pthread_mutex_lock[1]");

`

``

477

`+

CHECK_STATUS_PTHREAD("pthread_mutex_lock[1]");

`

476

478

``

477

479

`if (thelock->locked == 0) {

`

478

480

`success = PY_LOCK_ACQUIRED;

`

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

`

494

496

`&thelock->mut, &ts);

`

495

497

`if (status == ETIMEDOUT)

`

496

498

`break;

`

497

``

`-

CHECK_STATUS("pthread_cond_timed_wait");

`

``

499

`+

CHECK_STATUS_PTHREAD("pthread_cond_timed_wait");

`

498

500

` }

`

499

501

`else {

`

500

502

`status = pthread_cond_wait(

`

501

503

`&thelock->lock_released,

`

502

504

`&thelock->mut);

`

503

``

`-

CHECK_STATUS("pthread_cond_wait");

`

``

505

`+

CHECK_STATUS_PTHREAD("pthread_cond_wait");

`

504

506

` }

`

505

507

``

506

508

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

`

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

`

518

520

` }

`

519

521

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

`

520

522

`status = pthread_mutex_unlock( &thelock->mut );

`

521

``

`-

CHECK_STATUS("pthread_mutex_unlock[1]");

`

``

523

`+

CHECK_STATUS_PTHREAD("pthread_mutex_unlock[1]");

`

522

524

``

523

525

`if (error) success = PY_LOCK_FAILURE;

`

524

526

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

`

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

`

536

538

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

`

537

539

``

538

540

`status = pthread_mutex_lock( &thelock->mut );

`

539

``

`-

CHECK_STATUS("pthread_mutex_lock[3]");

`

``

541

`+

CHECK_STATUS_PTHREAD("pthread_mutex_lock[3]");

`

540

542

``

541

543

`thelock->locked = 0;

`

542

544

``

543

545

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

`

544

546

`status = pthread_cond_signal( &thelock->lock_released );

`

545

``

`-

CHECK_STATUS("pthread_cond_signal");

`

``

547

`+

CHECK_STATUS_PTHREAD("pthread_cond_signal");

`

546

548

``

547

549

`status = pthread_mutex_unlock( &thelock->mut );

`

548

``

`-

CHECK_STATUS("pthread_mutex_unlock[3]");

`

``

550

`+

CHECK_STATUS_PTHREAD("pthread_mutex_unlock[3]");

`

549

551

`}

`

550

552

``

551

553

`#endif /* USE_SEMAPHORES */

`