Last active
May 7, 2020 07:03
-
-
Save csghone/9044d1bc0aa62df77ccbba6d2e046eb6 to your computer and use it in GitHub Desktop.
CFFI Python Example - Part 1/2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate module `cffi_example` using `python3 generate_cffi_example_module.py` | |
import os | |
from cffi import FFI | |
ffi = FFI() | |
person_header = """ | |
unsigned int decompress(const uint8_t* raw_data, size_t compressed_size, uint8_t* decompressed_data); | |
""" | |
ffi.set_source("cffi_example.lzo_ext", person_header + """ | |
#include "lzo/lzo1z.h" | |
unsigned int decompress(const uint8_t* raw_data, size_t compressed_size, uint8_t* decompressed_data) | |
{ | |
long unsigned int decompressed_length_size = 0; | |
lzo1z_decompress ((const unsigned char *) raw_data, compressed_size, | |
(unsigned char *) decompressed_data, &decompressed_length_size, NULL); | |
return decompressed_length_size; | |
} | |
""", libraries=["lzo2"]) | |
ffi.cdef(person_header) | |
if __name__ == "__main__": | |
ffi.compile() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment