From 9dff1ff28e97e1d721c46f2aaefae1728681143e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Sat, 15 Apr 2023 15:45:35 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Workaround=20for=20buggy=20int64?=
 =?UTF-8?q?=5FT=20and=20uint64=5FT=20types=20under=20Windows=20with=20MATL?=
 =?UTF-8?q?AB=20<=20R2015b?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This bug would impact the qmc_sequence MEX, which manipulates an int64
input/output argument (the seed). Thanks to little-endianness, the bug would
however only manifest for seeds > 2³¹.
---
 mex/sources/dynmex.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/mex/sources/dynmex.h b/mex/sources/dynmex.h
index 2bd07760c9..a4a635e838 100644
--- a/mex/sources/dynmex.h
+++ b/mex/sources/dynmex.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2009-2020 Dynare Team
+ * Copyright © 2009-2023 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -30,4 +30,18 @@
 # define mxIsScalar(x) (mxGetM(x) == 1 && mxGetN(x) == 1)
 #endif
 
+/* The int64_T and uint64_T type are broken under MinGW for MATLAB < R2015b
+   (they actually alias long integer types, which are 32-bit) */
+#if defined(MATLAB_MEX_FILE) && defined(__MINGW64__) && MATLAB_VERSION < 0x0806
+# define int64_T long long
+# define uint64_T unsigned long long
+#endif
+#ifdef __cplusplus
+static_assert(sizeof(int64_T) == 8, "The int64_T type is buggy");
+static_assert(sizeof(uint64_T) == 8, "The uint64_T type is buggy");
+#else
+_Static_assert(sizeof(int64_T) == 8, "The int64_T type is buggy");
+_Static_assert(sizeof(uint64_T) == 8, "The uint64_T type is buggy");
+#endif
+
 #endif
-- 
GitLab