From 31a691a58e159fc759ffa08458174889f2046190 Mon Sep 17 00:00:00 2001 From: Kevin Ryde Date: Wed, 13 Dec 2006 23:55:51 +0000 Subject: [PATCH] (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. --- libguile/threads.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 ("#pthread, 10, port); + scm_uintprint (id, 10, port); scm_puts (" (", port); scm_uintprint ((scm_t_bits)t, 16, port); scm_puts (")>", port);