When calling a wrapped c function as such:
f = io.BytesIO()
with stdout_redirector(f):
r = _wrapped_c_function(in_file, out_file)
the return code is returned in r
, where return codes are given based on the errors raise inside the C function, however if an error occurs in the C function that is NOT caught by the C function r
exits as 0 and the Python program silently exits as 0 indicating as if nothing was wrong. However in stdoutt a message such as malloc(): invalid size (unsorted)
will get printed.
How can I catch these error messages, as the function call should print nothing if it all works. The issue with using the redirector is that when _wrapped_c_function
fails it exits the Python function before anything can get written into the buffer f
.