bt2: normalize the code to use some commonly used patterns
This patch changes some functions in the Python bindings native code to
use some error handling patterns that are used elsewhere in the project.
I think they help avoid some mistakes, and always using the same
patterns helps to spot mistakes more easily.
- Don't initialize status/ret variables to OK when declaring them. If
we do this and forget to assign them in some error path, we'll
wrongfully return OK. By not initializing them, if we forget to set
them on some error path, the compilers or static analyzers will be able
to identify it as a problem because the variable will be used without
being initialized on that path.
- When checking for Python API calls failure, check if the returned
pointer is NULL instead of checking PyErr_Occurred(). It is equivalent,
but it's preferable to do it the same way everywhere.
- After each API call, have an error check with a "goto end;".
Change-Id: I54e62a77a0a9ab3d778edceb85cbf280b134db88
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2223
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
This page took 0.026546 seconds and 4 git commands to generate.