Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python extension for Windows #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion src/libethash/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
# include <endian.h>
#endif

#if defined(_WIN32)
#if defined(__GNUC__)
#define ethash_swap_u32 __builtin_bswap32
#define ethash_swap_u64 __builtin_bswap64
#elif defined(_WIN32)
#include <stdlib.h>
#define ethash_swap_u32(input_) _byteswap_ulong(input_)
#define ethash_swap_u64(input_) _byteswap_uint64(input_)
Expand Down
8 changes: 8 additions & 0 deletions src/libethash/io_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/libethash/util_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @author Tim Hughes <[email protected]>
* @date 2015
*/
#ifdef _MSC_VER

#include <stdarg.h>
#include <stdio.h>
#include "util.h"
Expand All @@ -36,3 +38,5 @@ void debugf(char const* str, ...)
buf[sizeof(buf)-1] = '\0';
OutputDebugStringA(buf);
}

#endif
5 changes: 0 additions & 5 deletions src/python/core.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#include <Python.h>
#include <alloca.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include "../libethash/ethash.h"
#include "../libethash/internal.h"

Expand All @@ -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;
Expand Down