comparison Python/thread_pthread.h @ 13210:ff243b0f16ee legacy-trunk

Trent Mick <trentm@activestate.com>: The common technique for printing out a pointer has been to cast to a long and use the "%lx" printf modifier. This is incorrect on Win64 where casting to a long truncates the pointer. The "%p" formatter should be used instead. The problem as stated by Tim: > Unfortunately, the C committee refused to define what %p conversion "looks > like" -- they explicitly allowed it to be implementation-defined. Older > versions of Microsoft C even stuck a colon in the middle of the address (in > the days of segment+offset addressing)! The result is that the hex value of a pointer will maybe/maybe not have a 0x prepended to it. Notes on the patch: There are two main classes of changes: - in the various repr() functions that print out pointers - debugging printf's in the various thread_*.h files (these are why the patch is large) Closes SourceForge patch #100505.
author Fred Drake <fdrake@acm.org>
date Fri, 30 Jun 2000 15:01:00 +0000
parents 94ad90fd2712
children 916fb024ce94
comparison
equal deleted inserted replaced
13209:b11e0a898de0 13210:ff243b0f16ee
270 free((void *)lock); 270 free((void *)lock);
271 lock = 0; 271 lock = 0;
272 } 272 }
273 } 273 }
274 274
275 dprintf(("PyThread_allocate_lock() -> %lx\n", (long)lock)); 275 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
276 return (PyThread_type_lock) lock; 276 return (PyThread_type_lock) lock;
277 } 277 }
278 278
279 void PyThread_free_lock _P1(lock, PyThread_type_lock lock) 279 void PyThread_free_lock _P1(lock, PyThread_type_lock lock)
280 { 280 {
281 pthread_lock *thelock = (pthread_lock *)lock; 281 pthread_lock *thelock = (pthread_lock *)lock;
282 int status, error = 0; 282 int status, error = 0;
283 283
284 dprintf(("PyThread_free_lock(%lx) called\n", (long)lock)); 284 dprintf(("PyThread_free_lock(%p) called\n", lock));
285 285
286 status = pthread_mutex_destroy( &thelock->mut ); 286 status = pthread_mutex_destroy( &thelock->mut );
287 CHECK_STATUS("pthread_mutex_destroy"); 287 CHECK_STATUS("pthread_mutex_destroy");
288 288
289 status = pthread_cond_destroy( &thelock->lock_released ); 289 status = pthread_cond_destroy( &thelock->lock_released );
296 { 296 {
297 int success; 297 int success;
298 pthread_lock *thelock = (pthread_lock *)lock; 298 pthread_lock *thelock = (pthread_lock *)lock;
299 int status, error = 0; 299 int status, error = 0;
300 300
301 dprintf(("PyThread_acquire_lock(%lx, %d) called\n", (long)lock, waitflag)); 301 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
302 302
303 status = pthread_mutex_lock( &thelock->mut ); 303 status = pthread_mutex_lock( &thelock->mut );
304 CHECK_STATUS("pthread_mutex_lock[1]"); 304 CHECK_STATUS("pthread_mutex_lock[1]");
305 success = thelock->locked == 0; 305 success = thelock->locked == 0;
306 if (success) thelock->locked = 1; 306 if (success) thelock->locked = 1;
323 status = pthread_mutex_unlock( &thelock->mut ); 323 status = pthread_mutex_unlock( &thelock->mut );
324 CHECK_STATUS("pthread_mutex_unlock[2]"); 324 CHECK_STATUS("pthread_mutex_unlock[2]");
325 success = 1; 325 success = 1;
326 } 326 }
327 if (error) success = 0; 327 if (error) success = 0;
328 dprintf(("PyThread_acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success)); 328 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
329 return success; 329 return success;
330 } 330 }
331 331
332 void PyThread_release_lock _P1(lock, PyThread_type_lock lock) 332 void PyThread_release_lock _P1(lock, PyThread_type_lock lock)
333 { 333 {
334 pthread_lock *thelock = (pthread_lock *)lock; 334 pthread_lock *thelock = (pthread_lock *)lock;
335 int status, error = 0; 335 int status, error = 0;
336 336
337 dprintf(("PyThread_release_lock(%lx) called\n", (long)lock)); 337 dprintf(("PyThread_release_lock(%p) called\n", lock));
338 338
339 status = pthread_mutex_lock( &thelock->mut ); 339 status = pthread_mutex_lock( &thelock->mut );
340 CHECK_STATUS("pthread_mutex_lock[3]"); 340 CHECK_STATUS("pthread_mutex_lock[3]");
341 341
342 thelock->locked = 0; 342 thelock->locked = 0;
380 if (error) { 380 if (error) {
381 free((void *) sema); 381 free((void *) sema);
382 sema = NULL; 382 sema = NULL;
383 } 383 }
384 } 384 }
385 dprintf(("PyThread_allocate_sema() -> %lx\n", (long) sema)); 385 dprintf(("PyThread_allocate_sema() -> %p\n", sema));
386 return (PyThread_type_sema) sema; 386 return (PyThread_type_sema) sema;
387 } 387 }
388 388
389 void PyThread_free_sema _P1(sema, PyThread_type_sema sema) 389 void PyThread_free_sema _P1(sema, PyThread_type_sema sema)
390 { 390 {
391 int status, error = 0; 391 int status, error = 0;
392 struct semaphore *thesema = (struct semaphore *) sema; 392 struct semaphore *thesema = (struct semaphore *) sema;
393 393
394 dprintf(("PyThread_free_sema(%lx) called\n", (long) sema)); 394 dprintf(("PyThread_free_sema(%p) called\n", sema));
395 status = pthread_cond_destroy(&thesema->cond); 395 status = pthread_cond_destroy(&thesema->cond);
396 CHECK_STATUS("pthread_cond_destroy"); 396 CHECK_STATUS("pthread_cond_destroy");
397 status = pthread_mutex_destroy(&thesema->mutex); 397 status = pthread_mutex_destroy(&thesema->mutex);
398 CHECK_STATUS("pthread_mutex_destroy"); 398 CHECK_STATUS("pthread_mutex_destroy");
399 free((void *) thesema); 399 free((void *) thesema);
402 int PyThread_down_sema _P2(sema, PyThread_type_sema sema, waitflag, int waitflag) 402 int PyThread_down_sema _P2(sema, PyThread_type_sema sema, waitflag, int waitflag)
403 { 403 {
404 int status, error = 0, success; 404 int status, error = 0, success;
405 struct semaphore *thesema = (struct semaphore *) sema; 405 struct semaphore *thesema = (struct semaphore *) sema;
406 406
407 dprintf(("PyThread_down_sema(%lx, %d) called\n", (long) sema, waitflag)); 407 dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag));
408 status = pthread_mutex_lock(&thesema->mutex); 408 status = pthread_mutex_lock(&thesema->mutex);
409 CHECK_STATUS("pthread_mutex_lock"); 409 CHECK_STATUS("pthread_mutex_lock");
410 if (waitflag) { 410 if (waitflag) {
411 while (!error && thesema->value <= 0) { 411 while (!error && thesema->value <= 0) {
412 status = pthread_cond_wait(&thesema->cond, 412 status = pthread_cond_wait(&thesema->cond,
422 } 422 }
423 else 423 else
424 success = 0; 424 success = 0;
425 status = pthread_mutex_unlock(&thesema->mutex); 425 status = pthread_mutex_unlock(&thesema->mutex);
426 CHECK_STATUS("pthread_mutex_unlock"); 426 CHECK_STATUS("pthread_mutex_unlock");
427 dprintf(("PyThread_down_sema(%lx) return\n", (long) sema)); 427 dprintf(("PyThread_down_sema(%p) return\n", sema));
428 return success; 428 return success;
429 } 429 }
430 430
431 void PyThread_up_sema _P1(sema, PyThread_type_sema sema) 431 void PyThread_up_sema _P1(sema, PyThread_type_sema sema)
432 { 432 {
433 int status, error = 0; 433 int status, error = 0;
434 struct semaphore *thesema = (struct semaphore *) sema; 434 struct semaphore *thesema = (struct semaphore *) sema;
435 435
436 dprintf(("PyThread_up_sema(%lx)\n", (long) sema)); 436 dprintf(("PyThread_up_sema(%p)\n", sema));
437 status = pthread_mutex_lock(&thesema->mutex); 437 status = pthread_mutex_lock(&thesema->mutex);
438 CHECK_STATUS("pthread_mutex_lock"); 438 CHECK_STATUS("pthread_mutex_lock");
439 thesema->value++; 439 thesema->value++;
440 status = pthread_cond_signal(&thesema->cond); 440 status = pthread_cond_signal(&thesema->cond);
441 CHECK_STATUS("pthread_cond_signal"); 441 CHECK_STATUS("pthread_cond_signal");