Subject: bug#11456: add time.h in threads.c ,but it still don't work

From: gnuemacser <[email-masked]>
Date: Fri, 6 Jul 2012 21:26:26 +0800

i checked the libguile/scmconfig.h for scm_t_timespec

/* same as POSIX "struct timespec" -- always defined */
typedef struct timespec scm_t_timespec;

it seems normal. then i add 
#include <time.h>
in libguile/threads.c, but it still wrong.

make  all-am
make[3]: Entering directory `/e/temp/files/guile/guile-2.0.5/build/libguile'
  CC     libguile_2.0_la-threads.lo
../../libguile/threads.c: In function 'to_timespec':
../../libguile/threads.c:268:15: error: dereferencing pointer to incomplete type
../../libguile/threads.c:269:15: error: dereferencing pointer to incomplete type
../../libguile/threads.c:276:15: error: dereferencing pointer to incomplete type
../../libguile/threads.c:277:15: error: dereferencing pointer to incomplete type
../../libguile/threads.c: In function 'scm_cancel_thread':
../../libguile/threads.c:1166:7: warning: statement with no effect [-Wunused-value]
../../libguile/threads.c: In function 'scm_join_thread_timed':
../../libguile/threads.c:1230:18: error: storage size of 'ctimeout' isn't known
../../libguile/threads.c:1230:18: warning: unused variable 'ctimeout' [-Wunused-variable]
../../libguile/threads.c: In function 'fat_mutex_lock':
../../libguile/threads.c:1454:41: error: dereferencing pointer to incomplete type
../../libguile/threads.c:1455:36: error: dereferencing pointer to incomplete type
../../libguile/threads.c:1456:43: error: dereferencing pointer to incomplete type
../../libguile/threads.c: In function 'scm_lock_mutex_timed':
../../libguile/threads.c:1488:18: error: storage size of 'cwaittime' isn't known
../../libguile/threads.c:1488:18: warning: unused variable 'cwaittime' [-Wunused-variable]
../../libguile/threads.c: In function 'scm_try_mutex':
../../libguile/threads.c:1537:18: error: storage size of 'cwaittime' isn't known
../../libguile/threads.c:1537:18: warning: unused variable 'cwaittime' [-Wunused-variable]
../../libguile/threads.c: In function 'scm_unlock_mutex_timed':
../../libguile/threads.c:1680:18: error: storage size of 'cwaittime' isn't known
../../libguile/threads.c:1680:18: warning: unused variable 'cwaittime' [-Wunused-variable]
../../libguile/threads.c: In function 'scm_timed_wait_condition_variable':
../../libguile/threads.c:1784:18: error: storage size of 'waittime' isn't known
../../libguile/threads.c:1784:18: warning: unused variable 'waittime' [-Wunused-variable]
make[3]: *** [libguile_2.0_la-threads.lo] Error 1
make[3]: Leaving directory `/e/temp/files/guile/guile-2.0.5/build/libguile'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/e/temp/files/guile/guile-2.0.5/build/libguile'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/e/temp/files/guile/guile-2.0.5/build'
make: *** [all] Error 2

the error is very strange, several months ago ,i found this error . and not only mingw but also cygwin will get this error .
i build guile-2.0.5 in slackware-current ,and it successed. 
i checked the source files like threads.h, scmconfig.h __scm.h _scm.h and pthread.h in mingw/include . i can't see why scmconfig.h will influence the threads.c.
i do find the _scm.h has the relevance with threads.h. here is in _scm.h:
/* Undefine HAVE_STRUCT_TIMESPEC, because the libguile C code doesn't
   need it anymore, and because on MinGW:

   - the definition of struct timespec is provided (if at all) by
     pthread.h

   - pthread.h will _not_ define struct timespec if
     HAVE_STRUCT_TIMESPEC is 1, because then it thinks that it doesn't
     need to.

   The libguile C code doesn't need HAVE_STRUCT_TIMESPEC anymore,
   because the value of HAVE_STRUCT_TIMESPEC has already been
   incorporated in how scm_t_timespec is defined (in scmconfig.h), and
   the rest of the libguile C code now just uses scm_t_timespec.
 */
#ifdef HAVE_STRUCT_TIMESPEC
#undef HAVE_STRUCT_TIMESPEC
#endif

then i checked pthread.h in mingw/include ,it says:
#ifdef _UWIN
#   define HAVE_STRUCT_TIMESPEC 1
#   define HAVE_SIGNAL_H        1
#   undef HAVE_PTW32_CONFIG_H
#   pragma comment(lib, "pthread")
#endif

...............................

#ifndef HAVE_STRUCT_TIMESPEC
#define HAVE_STRUCT_TIMESPEC
#ifndef _TIMESPEC_DEFINED
#define _TIMESPEC_DEFINED
struct timespec {
        time_t tv_sec;
        long tv_nsec;
};
#endif /* _TIMESPEC_DEFINED */
#endif /* HAVE_STRUCT_TIMESPEC */

i can't understand :why all the declarations are ok ,but the gcc still don't know 
the struct scm_t_timespec