bt2: normalize the code to use some commonly used patterns
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 18 Oct 2019 22:09:55 +0000 (18:09 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 21 Oct 2019 21:05:52 +0000 (17:05 -0400)
commit6dbc193813652398f803c5c3585710222f5335f6
tree9f03fef6b588e5d343a8d675b1c04117439b342b
parent84e438afc1b27f23047613c413e2caec283af065
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>
src/bindings/python/bt2/bt2/native_bt_component_class.i.h
src/bindings/python/bt2/bt2/native_bt_graph.i.h
src/bindings/python/bt2/bt2/native_bt_trace.i.h
src/bindings/python/bt2/bt2/native_bt_trace_class.i.h
This page took 0.024432 seconds and 4 git commands to generate.