Explicitly specify that timezone is a struct v2017.06.26.00
authorChristopher Dykes <cdykes@fb.com>
Sun, 25 Jun 2017 00:00:32 +0000 (17:00 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 25 Jun 2017 00:08:05 +0000 (17:08 -0700)
Summary: In the parameter declarations for the `gettimeofday` portability header implementation. More details on exactly why can be found in the newly added comment on the function.

Reviewed By: yfeldblum

Differential Revision: D5281301

fbshipit-source-id: 1b246adc7743b5470201e452c008418429f7f142

folly/portability/SysTime.cpp
folly/portability/SysTime.h

index 48b343f420f57f51f6af0749af9f9bf22fa98cb3..c3a965f2c8f774aa239a4da3472b193f30522a5d 100644 (file)
 
 #include <cstdint>
 
 
 #include <cstdint>
 
-#include <Windows.h>
-
 extern "C" {
 extern "C" {
-int gettimeofday(timeval* tv, timezone*) {
+int gettimeofday(timeval* tv, struct timezone*) {
   constexpr auto posixWinFtOffset = 116444736000000000ULL;
 
   if (tv) {
   constexpr auto posixWinFtOffset = 116444736000000000ULL;
 
   if (tv) {
index ef0293e9e9d854ad0a85830ff8cd788b07199dc3..2b66dbdd377355d9ccb46370f597114ec33893de 100755 (executable)
@@ -27,7 +27,15 @@ struct timezone {
 };
 
 extern "C" {
 };
 
 extern "C" {
-int gettimeofday(timeval* tv, timezone*);
+// Note that this needs to explicitly be `struct timezone` due to the fact that
+// the python 3 headers `#define timezone _timezone` on Windows. `_timezone` is
+// a global field that contains information on the current timezone. By
+// explicitly specifying that this is a `struct`, we ensure that it's treated as
+// a type, regardless of what name that type actually is :)
+// Note that this will break if `gettimeofday` ever becomes declared as anything
+// other than `extern "C"`, as the mangled name would be dependent on whether
+// python had been included before this header.
+int gettimeofday(timeval* tv, struct timezone*);
 void timeradd(timeval* a, timeval* b, timeval* res);
 void timersub(timeval* a, timeval* b, timeval* res);
 }
 void timeradd(timeval* a, timeval* b, timeval* res);
 void timersub(timeval* a, timeval* b, timeval* res);
 }