def __init__(self):
# Store these on the class since they should only ever be called once
if _LibUUID._ffi is None or _LibUUID._libuuid is None:
_LibUUID._ffi = FFI()
# These definitions are from uuid.h
_LibUUID._ffi.cdef("""
typedef unsigned char uuid_t[16];
void uuid_generate(uuid_t out);
void uuid_generate_random(uuid_t out);
void uuid_generate_time(uuid_t out);
""")
# By opening the library with dlopen, the compile step is skipped
# dodging a class of errors, since headers aren't needed, just the
# installed library.
_LibUUID._libuuid = _LibUUID._ffi.dlopen(
ctypes.util.find_library("uuid")
)
get_config().logger.debug(
"FastUUID Created - FFI: ({}), LIBUUID: ({})".format(
_LibUUID._ffi,
_LibUUID._libuuid
)
)
# Keeping only one copy of this around does result in
# pretty substantial performance improvements - in the 10,000s of
# messages per second range
self.output = _LibUUID._ffi.new("uuid_t")
评论列表
文章目录