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. 7
      FFI-tests/ffi_test.c
  2. 14
      FFI-tests/ffi_test.py
  3. 25
      FFI-tests/ffi_test_build.py

7
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);
}

14
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()

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