From fcc5d734fcb491548c6a9380c1a2a09502fed994 Mon Sep 17 00:00:00 2001 From: Stefan Jahn Date: Sat, 14 Jun 2003 05:36:02 +0000 Subject: [PATCH] 2003-06-14 Stefan Jahn * configure.in: Checking for __int64 as possible candidate for the SCM_I_GSC_T_INT64 define. 2003-06-14 Stefan Jahn * threads.h: Redefined scm_getspecific() and scm_setspecific() to be functions instead of macros. * threads.c: Conditionalized inclusion of and . (scm_getspecific, scm_setspecific): Made these two function real part of the API. * posix.c (s_scm_putenv): Added some code to make a (putenv "FOO="), i.e. setting an empty string, work also on Win32 systems. Thanks to Kevin Ryde for the proposal. --- ChangeLog | 5 +++++ configure.in | 10 ++++++++-- libguile/ChangeLog | 14 ++++++++++++++ libguile/deprecated.h | 5 +++++ libguile/gen-scmconfig.c | 2 ++ libguile/posix.c | 39 ++++++++++++++++++++++++++++++++++++++- libguile/threads.c | 16 ++++++++++++++++ libguile/threads.h | 18 +++++++++--------- 8 files changed, 97 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04addeba9..5242e5a67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-06-14 Stefan Jahn + + * configure.in: Checking for __int64 as possible candidate for + the SCM_I_GSC_T_INT64 define. + 2003-05-30 Stefan Jahn * configure.in: Checking for unsetenv(). diff --git a/configure.in b/configure.in index 323322a07..717611aa7 100644 --- a/configure.in +++ b/configure.in @@ -242,6 +242,8 @@ AC_CHECK_SIZEOF(unsigned long) AC_CHECK_SIZEOF(size_t) AC_CHECK_SIZEOF(long long) AC_CHECK_SIZEOF(unsigned long long) +AC_CHECK_SIZEOF(__int64) +AC_CHECK_SIZEOF(unsigned __int64) AC_CHECK_SIZEOF(void *) AC_CHECK_SIZEOF(intptr_t) AC_CHECK_SIZEOF(uintptr_t) @@ -419,7 +421,7 @@ fi AC_SUBST([SCM_I_GSC_T_UINT32]) ### Optional type scm_t_int64 (ANSI C says int, short, or long might work) -### Also try long long if we have it. +### Also try 'long long' and '__int64' if we have it. SCM_I_GSC_T_INT64=0 if test "$ac_cv_sizeof_int" -eq 8; then SCM_I_GSC_T_INT64='"int"' @@ -429,6 +431,8 @@ elif test "$ac_cv_sizeof_short" -eq 8; then SCM_I_GSC_T_INT64='"short"' elif test "$ac_cv_sizeof_long_long" -eq 8; then SCM_I_GSC_T_INT64='"long long"' +elif test "$ac_cv_sizeof___int64" -eq 8; then + SCM_I_GSC_T_INT64='"__int64"' elif test "$scm_stdint_has_int64"; then SCM_I_GSC_T_INT64='"int64_t"' SCM_I_GSC_NEEDS_STDINT_H=1 @@ -441,7 +445,7 @@ fi AC_SUBST([SCM_I_GSC_T_INT64]) ### Optional type scm_t_uint64 (ANSI C says int, short, or long might work) -### Also try long long if we have it. +### Also try 'long long' and '__int64' if we have it. SCM_I_GSC_T_UINT64=0 if test "$ac_cv_sizeof_unsigned_int" -eq 8; then SCM_I_GSC_T_UINT64='"unsigned int"' @@ -451,6 +455,8 @@ elif test "$ac_cv_sizeof_unsigned_short" -eq 8; then SCM_I_GSC_T_UINT64='"unsigned short"' elif test "$ac_cv_sizeof_unsigned_long_long" -eq 8; then SCM_I_GSC_T_UINT64='"unsigned long long"' +elif test "$ac_cv_sizeof_unsigned___int64" -eq 8; then + SCM_I_GSC_T_UINT64='"unsigned __int64"' elif test "$scm_stdint_has_uint64"; then SCM_I_GSC_T_UINT64='"uint64_t"' SCM_I_GSC_NEEDS_STDINT_H=1 diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 96762b090..3447bca5e 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,17 @@ +2003-06-14 Stefan Jahn + + * threads.h: Redefined scm_getspecific() and scm_setspecific() + to be functions instead of macros. + + * threads.c: Conditionalized inclusion of and + . + (scm_getspecific, scm_setspecific): Made these two function + real part of the API. + + * posix.c (s_scm_putenv): Added some code to make a + (putenv "FOO="), i.e. setting an empty string, work also on + Win32 systems. Thanks to Kevin Ryde for the proposal. + 2003-06-12 Kevin Ryde * posix.c (scm_putenv): Free temporary ptr in mingw unset. Add diff --git a/libguile/deprecated.h b/libguile/deprecated.h index 981e9823d..4462729e5 100644 --- a/libguile/deprecated.h +++ b/libguile/deprecated.h @@ -68,8 +68,13 @@ SCM_API const char scm_s_formals[]; #define scm_substring_move_left_x scm_substring_move_x #define scm_substring_move_right_x scm_substring_move_x +#if SCM_SIZEOF_LONG_LONG != 0 typedef long long long_long; typedef unsigned long long ulong_long; +#elif SCM_SIZEOF___INT64 != 0 +typedef __int64 long_long; +typedef unsigned __int64 ulong_long; +#endif #define scm_sizet size_t diff --git a/libguile/gen-scmconfig.c b/libguile/gen-scmconfig.c index d2f0778a5..4384b36eb 100644 --- a/libguile/gen-scmconfig.c +++ b/libguile/gen-scmconfig.c @@ -276,6 +276,8 @@ main (int argc, char *argv[]) " be more likely to be what you want */\n"); pf ("#define SCM_SIZEOF_LONG_LONG %d\n", SIZEOF_LONG_LONG); pf ("#define SCM_SIZEOF_UNSIGNED_LONG_LONG %d\n", SIZEOF_UNSIGNED_LONG_LONG); + pf ("#define SCM_SIZEOF___INT64 %d\n", SIZEOF___INT64); + pf ("#define SCM_SIZEOF_UNSIGNED___INT64 %d\n", SIZEOF_UNSIGNED___INT64); pf ("\n"); pf ("/* These are always defined. */\n"); diff --git a/libguile/posix.c b/libguile/posix.c index bd3c2fe97..60ad33d05 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1175,6 +1175,8 @@ SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0, environment variable 'name'. */ int e; ptr = scm_malloc (SCM_STRING_LENGTH (str) + 2); + if (ptr == NULL) + SCM_MEMORY_ERROR; strncpy (ptr, SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str)); ptr[SCM_STRING_LENGTH (str)] = '='; ptr[SCM_STRING_LENGTH (str) + 1] = 0; @@ -1182,7 +1184,7 @@ SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0, e = errno; free (ptr); errno = e; if (rv < 0) SCM_SYSERROR; -#endif +#endif /* !HAVE_UNSETENV */ } else { @@ -1191,6 +1193,41 @@ SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0, if (ptr == NULL) SCM_MEMORY_ERROR; strncpy (ptr, SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str)); + +#ifdef __MINGW32__ + /* If str is "FOO=", ie. attempting to set an empty string, then + we need to see if it's been successful. On MINGW, "FOO=" + means remove FOO from the environment. As a workaround, we + set "FOO= ", ie. a space, and then modify the string returned + by getenv. It's not enough just to modify the string we set, + because MINGW putenv copies it. */ + if (ptr[SCM_STRING_LENGTH (str) - 1] == '=') + { + char *alt; + SCM name = scm_substring (str, SCM_MAKINUM (0), + SCM_MAKINUM (SCM_STRING_LENGTH (str) - 1)); + if (getenv (SCM_STRING_CHARS (name)) == NULL) + { + alt = scm_malloc (SCM_STRING_LENGTH (str) + 2); + if (alt == NULL) + { + free (ptr); + SCM_MEMORY_ERROR; + } + memcpy (alt, SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str)); + alt[SCM_STRING_LENGTH (str)] = ' '; + alt[SCM_STRING_LENGTH (str) + 1] = '\0'; + rv = putenv (alt); + if (rv < 0) + SCM_SYSERROR; + free (ptr); /* don't need the old string we gave to putenv */ + } + alt = getenv (SCM_STRING_CHARS (name)); + alt[0] = '\0'; + return SCM_UNSPECIFIED; + } +#endif /* __MINGW32__ */ + ptr[SCM_STRING_LENGTH (str)] = 0; rv = putenv (ptr); if (rv < 0) diff --git a/libguile/threads.c b/libguile/threads.c index 26d613ee2..5be5b8267 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -24,10 +24,14 @@ #include "libguile/_scm.h" +#if HAVE_UNISTD_H #include +#endif #include #include +#if HAVE_SYS_TIME_H #include +#endif #include "libguile/validate.h" #include "libguile/root.h" @@ -1088,6 +1092,18 @@ scm_cond_timedwait (scm_t_cond *c, scm_t_mutex *m, const scm_t_timespec *wt) return res; } +void * +scm_getspecific (scm_t_key k) +{ + return scm_i_plugin_getspecific (k); +} + +int +scm_setspecific (scm_t_key k, void *s) +{ + return scm_i_plugin_setspecific (k, s); +} + void scm_enter_guile () { diff --git a/libguile/threads.h b/libguile/threads.h index cebdc7b69..cb08b72d1 100644 --- a/libguile/threads.h +++ b/libguile/threads.h @@ -63,6 +63,12 @@ SCM_API void scm_threads_mark_stacks (void); SCM_API void scm_init_threads (SCM_STACKITEM *); SCM_API void scm_init_thread_procs (void); +#if SCM_USE_PTHREAD_THREADS +# include "libguile/pthread-threads.h" +#else +# include "libguile/null-threads.h" +#endif + /*----------------------------------------------------------------------*/ /* Low-level C API */ @@ -130,8 +136,8 @@ SCM_API int scm_cond_timedwait (scm_t_cond *c, #define scm_key_create scm_i_plugin_key_create #define scm_key_delete scm_i_plugin_key_delete -#define scm_setspecific scm_i_plugin_setspecific -#define scm_getspecific scm_i_plugin_getspecific +SCM_API int scm_setspecific (scm_t_key k, void *s); +SCM_API void *scm_getspecific (scm_t_key k); #define scm_thread_select scm_internal_select @@ -224,19 +230,13 @@ SCM_API SCM scm_thread_exited_p (SCM thread); SCM_API scm_root_state *scm_i_thread_root (SCM thread); -#if SCM_USE_PTHREAD_THREADS -# include "libguile/pthread-threads.h" -#else -# include "libguile/null-threads.h" -#endif - #define SCM_CURRENT_THREAD \ ((scm_thread *) scm_i_plugin_getspecific (scm_i_thread_key)) extern scm_t_key scm_i_thread_key; /* These macros have confusing names. They really refer to the root state of the running thread. */ -#define SCM_THREAD_LOCAL_DATA (scm_i_plugin_getspecific (scm_i_root_state_key)) +#define SCM_THREAD_LOCAL_DATA (scm_getspecific (scm_i_root_state_key)) #define SCM_SET_THREAD_LOCAL_DATA(x) scm_i_set_thread_data(x) SCM_API scm_t_key scm_i_root_state_key; SCM_API void scm_i_set_thread_data (void *); -- 2.20.1