From 21b6a47ce9b352ef002a43a216d552ba5505da20 Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Thu, 26 Jan 2017 13:57:38 -0800 Subject: [PATCH] PYTHON-1202 - Fix time64 compilation with -std=c99 Python 2.6 on Solaris 11 is built with -std=c99. That causes build issues for our time64 code, which needs localtime_r and tzset. Including Python.h in time64.c provides the necessary magic. --- bson/time64.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/bson/time64.c b/bson/time64.c index 4b5ba0fd2..6b49206b9 100644 --- a/bson/time64.c +++ b/bson/time64.c @@ -43,12 +43,10 @@ gmtime64_r() is a 64-bit equivalent of gmtime_r(). #define _CRT_SECURE_NO_WARNINGS #endif -#include -#include -#include -#include +/* Including Python.h fixes issues with interpreters built with -std=c99. */ +#include "Python.h" + #include -#include #include "time64.h" #include "time64_limits.h" @@ -112,7 +110,7 @@ static const int safe_years_low[SOLAR_CYCLE_LENGTH] = { #define CHEAT_YEARS 108 #define IS_LEAP(n) ((!(((n) + 1900) % 400) || (!(((n) + 1900) % 4) && (((n) + 1900) % 100))) != 0) -#define WRAP(a,b,m) ((a) = ((a) < 0 ) ? ((b)--, (a) + (m)) : (a)) +#define _TIME64_WRAP(a,b,m) ((a) = ((a) < 0 ) ? ((b)--, (a) + (m)) : (a)) #ifdef USE_SYSTEM_LOCALTIME # define SHOULD_USE_SYSTEM_LOCALTIME(a) ( \ @@ -574,9 +572,9 @@ struct TM *gmtime64_r (const Time64_T *in_time, struct TM *p) time /= 24; v_tm_tday = time; - WRAP (v_tm_sec, v_tm_min, 60); - WRAP (v_tm_min, v_tm_hour, 60); - WRAP (v_tm_hour, v_tm_tday, 24); + _TIME64_WRAP (v_tm_sec, v_tm_min, 60); + _TIME64_WRAP (v_tm_min, v_tm_hour, 60); + _TIME64_WRAP (v_tm_hour, v_tm_tday, 24); v_tm_wday = (int)((v_tm_tday + 4) % 7); if (v_tm_wday < 0)