chelper: Move logging_callback() to global scope

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-03-01 13:30:02 -05:00
parent e0db9f3a6e
commit 70a1b752c9
1 changed files with 6 additions and 4 deletions

View File

@ -218,6 +218,10 @@ FFI_main = None
FFI_lib = None
pyhelper_logging_callback = None
# Hepler invoked from C errorf() code to log errors
def logging_callback(msg):
logging.error(FFI_main.string(msg))
# Return the Foreign Function Interface api to the caller
def get_ffi():
global FFI_main, FFI_lib, pyhelper_logging_callback
@ -238,10 +242,8 @@ def get_ffi():
FFI_main.cdef(d)
FFI_lib = FFI_main.dlopen(destlib)
# Setup error logging
def logging_callback(msg):
logging.error(FFI_main.string(msg))
pyhelper_logging_callback = FFI_main.callback(
"void func(const char *)", logging_callback)
pyhelper_logging_callback = FFI_main.callback("void func(const char *)",
logging_callback)
FFI_lib.set_python_logging_callback(pyhelper_logging_callback)
return FFI_main, FFI_lib