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)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 30 Oct 2019 19:14:52 +0000 (15:14 -0400)
commit7f3ee93db71f587960cf8c0bc12536457c413e45
tree9f14d8d211f558cf129b200566a0c2386d7f0518
parent27ba49f1181a4d1a046f1bc6116b4a8715e8ed37
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.026044 seconds and 4 git commands to generate.