From 3baf6b531990dda109b9af065c94cf9eb9c0aac6 Mon Sep 17 00:00:00 2001
From: stijn <stinos@zoho.com>
Date: Fri, 20 Nov 2015 15:59:06 +0100
Subject: [PATCH] windows/py: Support 64bit mingw-w64 builds

- add mp_int_t/mp_uint_t typedefs in mpconfigport.h
- fix integer suffixes/formatting in mpconfig.h and mpz.h
- use MICROPY_NLR_SETJMP=1 in Makefile since the current nlrx64.S
  implementation causes segfaults in gc_free()
- update README
---
 py/mpconfig.h          | 6 +++++-
 py/mpz.h               | 6 +++++-
 windows/Makefile       | 4 ++++
 windows/README         | 6 +++++-
 windows/mpconfigport.h | 5 +++++
 5 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/py/mpconfig.h b/py/mpconfig.h
index d3a57dda4..1453560e0 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -849,10 +849,14 @@ typedef double mp_float_t;
 
 // printf format spec to use for mp_int_t and friends
 #ifndef INT_FMT
-#ifdef __LP64__
+#if defined(__LP64__)
 // Archs where mp_int_t == long, long != int
 #define UINT_FMT "%lu"
 #define INT_FMT "%ld"
+#elif defined(_WIN64)
+#include <inttypes.h>
+#define UINT_FMT "%"PRIu64
+#define INT_FMT "%"PRId64
 #else
 // Archs where mp_int_t == int
 #define UINT_FMT "%u"
diff --git a/py/mpz.h b/py/mpz.h
index b2dd88acf..63ac772ff 100644
--- a/py/mpz.h
+++ b/py/mpz.h
@@ -73,7 +73,11 @@ typedef int8_t mpz_dbl_dig_signed_t;
 #endif
 
 #ifdef _WIN64
-  #define MPZ_LONG_1 1i64
+  #ifdef __MINGW32__
+    #define MPZ_LONG_1 1LL
+  #else
+    #define MPZ_LONG_1 1i64
+  #endif
 #else
   #define MPZ_LONG_1 1L
 #endif
diff --git a/windows/Makefile b/windows/Makefile
index ca3c08c1f..10c5f2ba7 100644
--- a/windows/Makefile
+++ b/windows/Makefile
@@ -49,6 +49,10 @@ CFLAGS_MOD += -DMICROPY_USE_READLINE=2
 LDFLAGS_MOD += -lreadline
 endif
 
+ifeq ($(CROSS_COMPILE),x86_64-w64-mingw32-)
+CFLAGS_MOD += -DMICROPY_NLR_SETJMP=1
+endif
+
 LIB += -lws2_32
 
 include ../py/mkrules.mk
diff --git a/windows/README b/windows/README
index e9ccc33f5..ca26c4629 100644
--- a/windows/README
+++ b/windows/README
@@ -20,11 +20,15 @@ make CROSS_COMPILE=i586-mingw32msvc-
 To compile under Cygwin:
 
 Install following packages using cygwin's setup.exe:
-mingw64-i686-gcc-core, make
+mingw64-i686-gcc-core, mingw64-x86_64-gcc-core, make
 Build using:
 
 make CROSS_COMPILE=i686-w64-mingw32-
 
+or for 64bit:
+
+make CROSS_COMPILE=x86_64-w64-mingw32-
+
 
 To compile using Visual Studio 2013 (or higher):
 
diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h
index fe13a6876..4b13fedad 100644
--- a/windows/mpconfigport.h
+++ b/windows/mpconfigport.h
@@ -108,6 +108,11 @@
 #if defined( __MINGW32__ ) && defined( __LP64__ )
 typedef long mp_int_t; // must be pointer size
 typedef unsigned long mp_uint_t; // must be pointer size
+#elif defined ( __MINGW32__ ) && defined( _WIN64 )
+#include <stdint.h>
+typedef __int64 mp_int_t;
+typedef unsigned __int64 mp_uint_t;
+#define MP_SSIZE_MAX __INT64_MAX__
 #elif defined ( _MSC_VER ) && defined( _WIN64 )
 typedef __int64 mp_int_t;
 typedef unsigned __int64 mp_uint_t;
-- 
GitLab