diff options
author | Kevin Ryde <user42@zip.com.au> | 2006-12-13 23:55:51 +0000 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2006-12-13 23:55:51 +0000 |
commit | 31a691a58e159fc759ffa08458174889f2046190 (patch) | |
tree | 31c67bc3f5ce91e440e16e8f7c87615e79949f0c | |
parent | 60cf271ef17082f724649b61f0754c5fb67e5caa (diff) | |
download | guile-31a691a58e159fc759ffa08458174889f2046190.tar.gz |
(thread_print): Cope with the case where pthread_t is a
struct, as found on mingw. Can't just cast to size_t for printing.
-rw-r--r-- | libguile/threads.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libguile/threads.c b/libguile/threads.c index 428133d8a..94ae65f95 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -141,9 +141,32 @@ thread_mark (SCM obj) static int thread_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED) { + /* On a Gnu system pthread_t is an unsigned long, but on mingw it's a + struct. A cast like "(unsigned long) t->pthread" is a syntax error in + the struct case, hence we go via a union, and extract according to the + size of pthread_t. */ + union { + pthread_t p; + unsigned short us; + unsigned int ui; + unsigned long ul; + scm_t_uintmax um; + } u; scm_i_thread *t = SCM_I_THREAD_DATA (exp); + scm_i_pthread_t p = t->pthread; + scm_t_uintmax id; + u.p = p; + if (sizeof (p) == sizeof (unsigned short)) + id = u.us; + else if (sizeof (p) == sizeof (unsigned int)) + id = u.ui; + else if (sizeof (p) == sizeof (unsigned long)) + id = u.ul; + else + id = u.um; + scm_puts ("#<thread ", port); - scm_uintprint ((size_t)t->pthread, 10, port); + scm_uintprint (id, 10, port); scm_puts (" (", port); scm_uintprint ((scm_t_bits)t, 16, port); scm_puts (")>", port); |