From 8640042cb3aa88979261b70e007b6975724d08e1 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Thu, 7 Jan 2016 15:41:38 -0600 Subject: [PATCH] buffer clearing for the c code. Changes to the python code. Working on getting a reasonable python FFI example in place. --- FFI-tests/ffi_test.c | 7 +++++-- FFI-tests/ffi_test.py | 14 ++++++++------ FFI-tests/ffi_test_build.py | 25 ------------------------- 3 files changed, 13 insertions(+), 33 deletions(-) delete mode 100755 FFI-tests/ffi_test_build.py diff --git a/FFI-tests/ffi_test.c b/FFI-tests/ffi_test.c index 94e5c4c..4e26a60 100644 --- a/FFI-tests/ffi_test.c +++ b/FFI-tests/ffi_test.c @@ -72,8 +72,9 @@ int main() { //printf("Path: %s\n", imagePath); // Visually proving that the bytes stored are the correct representation - print_ustr_bytes(imagePath); - + //print_ustr_bytes(imagePath); + printf("Image: %s\n",imagePath); + // Printing information about the hashes of the provided images uint64_t imageAhash = get_ahash(imagePath); uint64_t imageDhash = get_dhash(imagePath); @@ -84,6 +85,7 @@ int main() { printf("phash: %llu \n", imagePhash); //cleanup + memset(imagePath,0,100); free(imagePath); } } @@ -101,5 +103,6 @@ void print_ustr_bytes(const char str[]) { sprintf(&strBuf[i*4], "\\x%02X", str[i]); } printf("String: '%s' -> Bytes: '%s'\n" , str, strBuf); + memset(strBuf,0,strLen*4); free(strBuf); } diff --git a/FFI-tests/ffi_test.py b/FFI-tests/ffi_test.py index 37015bd..50d0c21 100755 --- a/FFI-tests/ffi_test.py +++ b/FFI-tests/ffi_test.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 from ctypes import * -from _ffi_test_py import ffi, lib large_image1_path = "test_images/sample_01_large.jpg".encode(encoding="utf-8") medium_image1_path = "test_images/sample_01_medium.jpg".encode(encoding="utf-8") @@ -19,10 +18,13 @@ test_images=[large_image1_path, medium_image1_path, small_image1_path,large_imag def unsigned64(number): #return c_ulonglong(number).value - return bin(number) + return c_ulonglong(number).value print("starting ffi test") +# Load the shared library +lib = cdll.LoadLibrary("libpihash.so") + #initialize the library lib.init() @@ -31,10 +33,10 @@ lib.init() #print('\\x'+'\\x'.join('{:02x}'.format(x) for x in large_image_path)) for image in test_images: - print("Requesting hashes for:", image) - print("ahash:",unsigned64(lib.ext_get_ahash(image))) - print("dhash:",unsigned64(lib.ext_get_dhash(image))) - print("phash:",unsigned64(lib.ext_get_phash(image))) + print("Requesting hashes for: %s"% image) + print("ahash: %i"% lib.ext_get_ahash(image)) + print("dhash: %i"% lib.ext_get_dhash(image)) + print("phash: %i"% lib.ext_get_phash(image)) # Do cleanup #lib.teardown() diff --git a/FFI-tests/ffi_test_build.py b/FFI-tests/ffi_test_build.py deleted file mode 100755 index 44f79e8..0000000 --- a/FFI-tests/ffi_test_build.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 - -# A simple test script to confirm the C FFI for the rust library is working - -from cffi import FFI -ffi = FFI() - -ffi.set_source("_ffi_test_py" - ,""" - #include - """ - ,libraries=["pihash"] - ,library_dirs=["."] -) - -ffi.cdef(""" - void init(); - void teardown(); - uint64_t ext_get_ahash(const char *); - uint64_t ext_get_dhash(const char *); - uint64_t ext_get_phash(const char *); -""") - -if __name__ == "__main__": - ffi.compile()