Browse Source

buffer clearing for the c code. Changes to the python code. Working on getting a reasonable python FFI example in place.

develop
Drew Short 9 years ago
parent
commit
8640042cb3
  1. 5
      FFI-tests/ffi_test.c
  2. 14
      FFI-tests/ffi_test.py
  3. 25
      FFI-tests/ffi_test_build.py

5
FFI-tests/ffi_test.c

@ -72,7 +72,8 @@ int main() {
//printf("Path: %s\n", imagePath); //printf("Path: %s\n", imagePath);
// Visually proving that the bytes stored are the correct representation // 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 // Printing information about the hashes of the provided images
uint64_t imageAhash = get_ahash(imagePath); uint64_t imageAhash = get_ahash(imagePath);
@ -84,6 +85,7 @@ int main() {
printf("phash: %llu \n", imagePhash); printf("phash: %llu \n", imagePhash);
//cleanup //cleanup
memset(imagePath,0,100);
free(imagePath); free(imagePath);
} }
} }
@ -101,5 +103,6 @@ void print_ustr_bytes(const char str[]) {
sprintf(&strBuf[i*4], "\\x%02X", str[i]); sprintf(&strBuf[i*4], "\\x%02X", str[i]);
} }
printf("String: '%s' -> Bytes: '%s'\n" , str, strBuf); printf("String: '%s' -> Bytes: '%s'\n" , str, strBuf);
memset(strBuf,0,strLen*4);
free(strBuf); free(strBuf);
} }

14
FFI-tests/ffi_test.py

@ -1,7 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from ctypes import * from ctypes import *
from _ffi_test_py import ffi, lib
large_image1_path = "test_images/sample_01_large.jpg".encode(encoding="utf-8") 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") 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): def unsigned64(number):
#return c_ulonglong(number).value #return c_ulonglong(number).value
return bin(number)
return c_ulonglong(number).value
print("starting ffi test") print("starting ffi test")
# Load the shared library
lib = cdll.LoadLibrary("libpihash.so")
#initialize the library #initialize the library
lib.init() lib.init()
@ -31,10 +33,10 @@ lib.init()
#print('\\x'+'\\x'.join('{:02x}'.format(x) for x in large_image_path)) #print('\\x'+'\\x'.join('{:02x}'.format(x) for x in large_image_path))
for image in test_images: 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 # Do cleanup
#lib.teardown() #lib.teardown()

25
FFI-tests/ffi_test_build.py

@ -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 <stdint.h>
"""
,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()
Loading…
Cancel
Save