1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-23 04:50:28 +02:00

(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.
This commit is contained in:
Kevin Ryde 2006-12-13 23:55:51 +00:00
parent 60cf271ef1
commit 31a691a58e

View file

@ -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);