From a8053195ea5c95f62645b583681a7ff37b6b758d Mon Sep 17 00:00:00 2001 From: mailchuck Date: Thu, 17 Dec 2015 22:58:52 +0100 Subject: [PATCH] Fix cdecl/stdcall DLL detection Fixes #146 --- src/proofofwork.py | 78 ++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/src/proofofwork.py b/src/proofofwork.py index 39999212..57c18679 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -11,38 +11,6 @@ import tr import os import ctypes -bitmsglib = 'bitmsghash.so' -if "win32" == sys.platform: - if ctypes.sizeof(ctypes.c_voidp) == 4: - bitmsglib = 'bitmsghash32.dll' - else: - bitmsglib = 'bitmsghash64.dll' - try: - # MSVS - bso = ctypes.WinDLL(os.path.join(codePath(), "bitmsghash", bitmsglib)) - logger.info("Loaded C PoW DLL (stdcall) %s", bitmsglib) - except: - try: - # MinGW - bso = ctypes.CDLL(os.path.join(codePath(), "bitmsghash", bitmsglib)) - logger.info("Loaded C PoW DLL (cdecl) %s", bitmsglib) - except: - bso = None -else: - try: - bso = ctypes.CDLL(os.path.join(codePath(), "bitmsghash", bitmsglib)) - logger.info("Loaded C PoW DLL %s", bitmsglib) - except: - bso = None -if bso: - try: - bmpow = bso.BitmessagePOW - bmpow.restype = ctypes.c_ulonglong - except: - bmpow = None -else: - bmpow = None - def _set_idle(): if 'linux' in sys.platform: import os @@ -185,4 +153,48 @@ def run(target, initialHash): return _doFastPoW(target, initialHash) except: pass #fallback - return _doSafePoW(target, initialHash) \ No newline at end of file + return _doSafePoW(target, initialHash) + +# init +bitmsglib = 'bitmsghash.so' +if "win32" == sys.platform: + if ctypes.sizeof(ctypes.c_voidp) == 4: + bitmsglib = 'bitmsghash32.dll' + else: + bitmsglib = 'bitmsghash64.dll' + try: + # MSVS + bso = ctypes.WinDLL(os.path.join(codePath(), "bitmsghash", bitmsglib)) + logger.info("Loaded C PoW DLL (stdcall) %s", bitmsglib) + bmpow = bso.BitmessagePOW + bmpow.restype = ctypes.c_ulonglong + _doCPoW(2**63, "") + logger.info("Successfully tested C PoW DLL (stdcall) %s", bitmsglib) + except: + logger.error("C PoW test fail.", exc_info=True) + try: + # MinGW + bso = ctypes.CDLL(os.path.join(codePath(), "bitmsghash", bitmsglib)) + logger.info("Loaded C PoW DLL (cdecl) %s", bitmsglib) + bmpow = bso.BitmessagePOW + bmpow.restype = ctypes.c_ulonglong + _doCPoW(2**63, "") + logger.info("Successfully tested C PoW DLL (cdecl) %s", bitmsglib) + except: + logger.error("C PoW test fail.", exc_info=True) + bso = None +else: + try: + bso = ctypes.CDLL(os.path.join(codePath(), "bitmsghash", bitmsglib)) + logger.info("Loaded C PoW DLL %s", bitmsglib) + except: + bso = None +if bso: + try: + bmpow = bso.BitmessagePOW + bmpow.restype = ctypes.c_ulonglong + except: + bmpow = None +else: + bmpow = None +