OSDN Git Service

Updated Python bindings.
authorLoRd_MuldeR <mulder2@gmx.de>
Fri, 25 Mar 2016 17:51:53 +0000 (18:51 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Fri, 25 Mar 2016 17:51:53 +0000 (18:51 +0100)
.gitignore
Make.cmd
bindings/Python/example/Example.py
bindings/Python/native/MHashPy384_Native.sln [moved from bindings/Python/wrapper/MHashPy384.sln with 88% similarity]
bindings/Python/native/MHashPy384_Native.vcxproj [moved from bindings/Python/wrapper/MHashPy384.vcxproj with 98% similarity]
bindings/Python/native/MHashPy384_Native.vcxproj.filters [moved from bindings/Python/wrapper/MHashPy384.vcxproj.filters with 100% similarity]
bindings/Python/native/src/MHashPy384.cpp [moved from bindings/Python/wrapper/src/MHashPy384.cpp with 84% similarity]
bindings/Python/native/src/dllmain.cpp [moved from bindings/Python/wrapper/src/dllmain.cpp with 100% similarity]
bindings/Python/wrapper/MHashPy384_Wrapper.py [moved from bindings/Python/include/MHashPy384.py with 91% similarity]
bindings/Python/wrapper/mhash.pth [moved from bindings/Python/include/mhash.pth with 100% similarity]

index 8f5f94f..15062ba 100644 (file)
@@ -15,8 +15,8 @@
 /bindings/Microsoft.NET/MHashDotNet384.Wrapper/obj
 /bindings/Microsoft.NET/bin
 /bindings/Microsoft.NET/ipch
-/bindings/Python/wrapper/bin
-/bindings/Python/wrapper/obj
+/bindings/Python/native/bin
+/bindings/Python/native/obj
 /ipch
 /obj
 /out
index 35689e4..1b6ec3e 100644 (file)
--- a/Make.cmd
+++ b/Make.cmd
@@ -101,7 +101,7 @@ for %%i in (native\obj,native\bin,warapper\bin,warapper\out) do (
        del /Q /S /F "%~dp0\bindings\Java\%%i\*.*"
 )
 
-for %%i in (wrapper\obj,wrapper\out) do (
+for %%i in (native\obj,native\out) do (
        del /Q /S /F "%~dp0\bindings\Python\%%i\*.*"
 )
 
@@ -119,7 +119,7 @@ call "%MSVC_PATH%\vcvarsall.bat"
 set "MSVC_PROJECTS=MHashLib.sln"
 set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Microsoft.NET\MHashDotNet384.sln"
 set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Java\native\MHashJava384.sln"
-set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Python\wrapper\MHashPy384.sln"
+set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Python\native\MHashPy384_Native.sln"
 
 for %%q in (%MSVC_PROJECTS%) do (
        for %%p in (x86,x64) do (
@@ -197,8 +197,8 @@ REM ///////////////////////////////////////////////////////////////////////////
 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_JNI_X86%" "%~dp0\bindings\Java\native\bin\x86\Release\MHashJava384.x86.dll" "%~dp0\bindings\Java\wrapper\out\MHashJava384-Wrapper.jar" "%~dp0\bindings\Java\example\out\MHashJava384-Example.jar" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_JNI_X64%" "%~dp0\bindings\Java\native\bin\x64\Release\MHashJava384.x64.dll" "%~dp0\bindings\Java\wrapper\out\MHashJava384-Wrapper.jar" "%~dp0\bindings\Java\example\out\MHashJava384-Example.jar" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
 
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X86%" "%~dp0\bindings\Python\wrapper\bin\x86\Release\MHashPy384_Impl.x86.pyd" "%~dp0\bindings\Python\include\MHashPy384.py" "%~dp0\bindings\Python\include\mhash.pth" "%~dp0\bindings\Python\example\Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X64%" "%~dp0\bindings\Python\wrapper\bin\x64\Release\MHashPy384_Impl.x64.pyd" "%~dp0\bindings\Python\include\MHashPy384.py" "%~dp0\bindings\Python\include\mhash.pth" "%~dp0\bindings\Python\example\Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X86%" "%~dp0\bindings\Python\native\bin\x86\Release\MHashPy384_Native.x86.pyd" "%~dp0\bindings\Python\wrapper\MHashPy384_Wrapper.py" "%~dp0\bindings\Python\wrapper\mhash.pth" "%~dp0\bindings\Python\example\Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X64%" "%~dp0\bindings\Python\native\bin\x64\Release\MHashPy384_Native.x64.pyd" "%~dp0\bindings\Python\wrapper\MHashPy384_Wrapper.py" "%~dp0\bindings\Python\wrapper\mhash.pth" "%~dp0\bindings\Python\example\Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
 
 "%GIT2_PATH%\git.exe" archive --format tar.gz -9 --verbose --output "%OUT_PATH_SRC_GEN%" HEAD
 
index 9af5aae..53cfca3 100644 (file)
@@ -20,8 +20,7 @@
 
 import sys
 import binascii
-
-from MHashPy384 import MHash384
+from MHashPy384_Wrapper import MHash384
 
 def read_chunks(fs, chunk_size=4096):
     while True:
@@ -30,12 +29,15 @@ def read_chunks(fs, chunk_size=4096):
             break
         yield data
 
-def main():
+def main(argv):
+    if(len(argv) < 1):
+        print("Command-line argument is missing!")
+        return
     with MHash384() as digest:
-        with open('E:\\ViDeOz\\Helges gitarrensolo in Texas.mp4', 'rb') as fs:
+        with open(argv[0], 'rb') as fs:
             for chunk in read_chunks(fs):
                 digest.update(chunk)
             print(binascii.hexlify(digest.result()))
 
 if __name__ == "__main__":
-    main()
+    main(sys.argv[1:])
similarity index 88%
rename from bindings/Python/wrapper/MHashPy384.sln
rename to bindings/Python/native/MHashPy384_Native.sln
index b2f3688..7ac3912 100644 (file)
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 14
 VisualStudioVersion = 14.0.24720.0
 MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MHashPy384", "MHashPy384.vcxproj", "{98971AF0-1B4D-4B5A-A174-9B099F7977B8}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MHashPy384_Native", "MHashPy384_Native.vcxproj", "{98971AF0-1B4D-4B5A-A174-9B099F7977B8}"
 EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -25,9 +25,9 @@
   <PropertyGroup Label="Globals">
     <ProjectGuid>{98971AF0-1B4D-4B5A-A174-9B099F7977B8}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
-    <RootNamespace>MHashPy384_Impl</RootNamespace>
+    <RootNamespace>MHashPy384_Native</RootNamespace>
     <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
-    <ProjectName>MHashPy384_Impl</ProjectName>
+    <ProjectName>MHashPy384_Native</ProjectName>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
similarity index 84%
rename from bindings/Python/wrapper/src/MHashPy384.cpp
rename to bindings/Python/native/src/MHashPy384.cpp
index 8175924..3b8da7e 100644 (file)
@@ -34,16 +34,26 @@ static PyObject *MHashPy384_Create(PyObject *const self, PyObject *const args)
 
 static PyObject *MHashPy384_Update(PyObject *const self, PyObject *const args)
 {
-       PyObject *instance = NULL, *data = NULL;
-       if (PyArg_UnpackTuple(args, "MHash384_Update", 2, 2, &instance, &data))
+       PyObject *instance = NULL, *data = NULL, *offset = NULL, *len = NULL;
+       if (PyArg_UnpackTuple(args, "MHash384_Update", 2, 4, &instance, &data, &offset, &len))
        {
                if (PyLong_Check(instance) && PyBytes_Check(data))
                {
                        void *const inst_ptr = PyLong_AsVoidPtr(instance);
                        if (inst_ptr)
                        {
-                               reinterpret_cast<mhash::MHash384*>(inst_ptr)->update(reinterpret_cast<uint8_t*>(PyBytes_AsString(data)), PyBytes_Size(data));
-                               Py_RETURN_TRUE;
+                               const size_t total_size = PyBytes_Size(data);
+                               const size_t offset_val = offset ? PyLong_AsSize_t(offset) : 0U;
+                               if (offset_val < total_size)
+                               {
+                                       const size_t len_val = len ? PyLong_AsSize_t(len) : (total_size - offset_val);
+                                       const size_t sum = offset_val + len_val;
+                                       if ((sum >= offset_val) && (sum >= len_val) && (sum < total_size))
+                                       {
+                                               reinterpret_cast<mhash::MHash384*>(inst_ptr)->update(reinterpret_cast<uint8_t*>(PyBytes_AsString(data)) + offset_val, len_val);
+                                               Py_RETURN_TRUE;
+                                       }
+                               }
                        }
                }
        }
@@ -102,11 +112,11 @@ static PyMethodDef MHashPy384_Methods[] =
 
 static struct PyModuleDef MHash384_ModuleDef =
 {
-       PyModuleDef_HEAD_INIT, "MHashPy384_Impl", "", -1, MHashPy384_Methods
+       PyModuleDef_HEAD_INIT, "MHashPy384_Native", "", -1, MHashPy384_Methods
 };
 
 PyMODINIT_FUNC
-PyInit_MHashPy384_Impl(void)
+PyInit_MHashPy384_Native(void)
 {
        return PyModule_Create(&MHash384_ModuleDef);
 }
similarity index 91%
rename from bindings/Python/include/MHashPy384.py
rename to bindings/Python/wrapper/MHashPy384_Wrapper.py
index aa8a63f..15ee067 100644 (file)
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.        #
 ##################################################################################################
 
-import MHashPy384_Impl as impl
+import MHashPy384_Native as native
 
 class MHash384:
     def __init__(self):
         self.__handle = None
     def __enter__(self):
-        self.__handle = impl.create()
+        self.__handle = native.create()
         return self
     def update(self, data):
-        impl.update(self.__handle, data)
+        native.update(self.__handle, data)
     def result(self):
-        return impl.result(self.__handle)
+        return native.result(self.__handle)
     def __exit__(self, type, value, traceback):
-        impl.freeup(self.__handle)
+        native.freeup(self.__handle)