From fd85657321a5ee59632119a8b2e596c0dd072ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 12 Jan 2016 13:16:51 +0100 Subject: [PATCH 1/2] Add support for building with mingw-gcc. MinGW GCC compiler is needed to build Python extension for Windows. Visual Studio for Python 2.7 cannot handle C99 standard. --- setup.py | 2 +- src/libethash/endian.h | 5 ++++- src/libethash/io_win32.c | 8 ++++++++ src/libethash/util_win32.c | 4 ++++ src/python/core.c | 5 ----- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 18aa20f6..07ab41b1 100755 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ pyethash = Extension('pyethash', sources=sources, depends=depends, - extra_compile_args=["-Isrc/", "-std=gnu99", "-Wall"]) + extra_compile_args=["-Isrc/", "-std=gnu99"]) setup( name='pyethash', diff --git a/src/libethash/endian.h b/src/libethash/endian.h index 849325a5..395351b0 100644 --- a/src/libethash/endian.h +++ b/src/libethash/endian.h @@ -24,7 +24,10 @@ # include #endif -#if defined(_WIN32) +#if defined(__GNUC__) +#define ethash_swap_u32 __builtin_bswap32 +#define ethash_swap_u64 __builtin_bswap64 +#elif defined(_WIN32) #include #define ethash_swap_u32(input_) _byteswap_ulong(input_) #define ethash_swap_u64(input_) _byteswap_uint64(input_) diff --git a/src/libethash/io_win32.c b/src/libethash/io_win32.c index 34f1aaa7..f5d248b7 100644 --- a/src/libethash/io_win32.c +++ b/src/libethash/io_win32.c @@ -29,13 +29,21 @@ FILE* ethash_fopen(char const* file_name, char const* mode) { +#if __GNUC__ + return fopen(file_name, mode); +#else FILE* f; return fopen_s(&f, file_name, mode) == 0 ? f : NULL; +#endif } char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) { +#if __GNUC__ + return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL; +#else return strncat_s(dest, dest_size, src, count) == 0 ? dest : NULL; +#endif } bool ethash_mkdir(char const* dirname) diff --git a/src/libethash/util_win32.c b/src/libethash/util_win32.c index 268e6db0..90b83593 100644 --- a/src/libethash/util_win32.c +++ b/src/libethash/util_win32.c @@ -18,6 +18,8 @@ * @author Tim Hughes * @date 2015 */ +#ifdef _MSC_VER + #include #include #include "util.h" @@ -36,3 +38,5 @@ void debugf(char const* str, ...) buf[sizeof(buf)-1] = '\0'; OutputDebugStringA(buf); } + +#endif diff --git a/src/python/core.c b/src/python/core.c index c66e03c5..5879413c 100644 --- a/src/python/core.c +++ b/src/python/core.c @@ -1,8 +1,4 @@ #include -#include -#include -#include -#include #include "../libethash/ethash.h" #include "../libethash/internal.h" @@ -19,7 +15,6 @@ static PyObject * mkcache_bytes(PyObject *self, PyObject *args) { unsigned long block_number; - unsigned long cache_size; if (!PyArg_ParseTuple(args, "k", &block_number)) return 0; From 88c073edae43e08f8e95eec4c178a40998bd6778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 12 Jan 2016 13:28:42 +0100 Subject: [PATCH 2/2] Python: switch to setuptools (instead of older disutils). This change allows building binary distribution of the Python package (wheel). --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 07ab41b1..91eee32f 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import os -from distutils.core import setup, Extension +from setuptools import setup, Extension sources = [ 'src/python/core.c', 'src/libethash/io.c',