From 4e4c40ae8c1e0640412a85beea0b0cbc871752a9 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 17 Jan 2012 16:01:40 -0700 Subject: [PATCH] Mac OS X: work around a localtime() bug in 64-bit 10.6.8 For numbers around -67768122973228093, localtime() doesn't return in 10.6.8, while it returns NULL for 10.7.2. Work around the bug by setting a lower bound that seems to be high enough to avoid the problem (and that's lower than the lowest value that succeeds, so no results are lost, at least for now). Merge to 5.2.1 --- src/racket/sconfig.h | 7 +++++++ src/racket/src/fun.c | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/racket/sconfig.h b/src/racket/sconfig.h index fc2a524c35..e101001619 100644 --- a/src/racket/sconfig.h +++ b/src/racket/sconfig.h @@ -766,6 +766,11 @@ #endif # define MZ_JIT_USE_MPROTECT +#if defined(__x86_64__) +/* work around a bug in localtime() in 10.6.8 */ +# define MIN_VALID_DATE_SECONDS -67768122973193999 +#endif + # define FLAGS_ALREADY_SET #endif @@ -1026,6 +1031,8 @@ /* TIME_TYPE_IS_UNSIGNED converts time_t values as unsigned. */ + /* MIN_VALID_DATE_SECONDS sets a minimum vald time in seconds. */ + /* PROCESS_FUNCTION adds (process ...) and (system ...) functions */ /* DIR_FUNCTION adds (current-directory ...) function */ diff --git a/src/racket/src/fun.c b/src/racket/src/fun.c index ccdc0c901c..77877f45f2 100644 --- a/src/racket/src/fun.c +++ b/src/racket/src/fun.c @@ -8320,6 +8320,12 @@ static int month_offsets[12] = { 0, 31, 59, 90, 243, 273, 304, 334 }; #endif +#ifdef MIN_VALID_DATE_SECONDS +# define VALID_TIME_RANGE(x) ((x) >= MIN_VALID_DATE_SECONDS) +#else +# define VALID_TIME_RANGE(x) 1 +#endif + static Scheme_Object *seconds_to_date(int argc, Scheme_Object **argv) { UNBUNDLE_TIME_TYPE lnow; @@ -8371,7 +8377,8 @@ static Scheme_Object *seconds_to_date(int argc, Scheme_Object **argv) } if (scheme_get_time_val(secs, &lnow) - && ((UNBUNDLE_TIME_TYPE)(now = (CHECK_TIME_T)lnow)) == lnow) { + && (((UNBUNDLE_TIME_TYPE)(now = (CHECK_TIME_T)lnow)) == lnow) + && VALID_TIME_RANGE(lnow)) { int success; #ifdef USE_MACTIME