bt2: remove utils._handle_ptr
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 23 Jul 2019 03:37:03 +0000 (23:37 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 24 Jul 2019 04:18:54 +0000 (00:18 -0400)
A future patch will want to get rid of spots that raise bt2.Error, which
are not in direct response to a failed Babeltrace API call.  The
utils._handle_ptr is one such spot.  It turns out that the usages of
utils._handle_ptr are not useful anymore, because they check
situations that can either never happen, or are check by pre-condition
checks.

In connection.py, it's not possible anymore for
bt_connection_borrow_downstream_port_const or
bt_connection_borrow_upstream_port_const to return NULL/None, as
connections always have both ports set.

In field.py, the call in _create_field_from_ptr after
bt_field_borrow_class_const can be removed, as it's impossible for this
function to legitimately return NULL/None.

The call in _VariantField.selected_option is unnecessary, as it is after
a pre-condition check that the variant's selected option is non-NULL.
If we want to make Python bindings user-friendly (avoid hitting
pre-condition checks), we check before the call if the variant has a
currently selection option, and raise ValueError otherwise.  However,
there does not seem to be an API for that at the moment.

Change-Id: I585e57030d58256cbf51161e75394503c281addf
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1743
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/bindings/python/bt2/bt2/connection.py
src/bindings/python/bt2/bt2/field.py
src/bindings/python/bt2/bt2/utils.py

index 9ffd7bb1ed3b4d19697d4cf2ce48161ab1eb3b31..0dc578265c584f736fff513751e3b830b180715d 100644 (file)
@@ -33,9 +33,6 @@ class _Connection(bt2.object._SharedObject):
     @property
     def downstream_port(self):
         port_ptr = native_bt.connection_borrow_downstream_port_const(self._ptr)
-        utils._handle_ptr(
-            port_ptr, "cannot get connection object's downstream port object"
-        )
         return bt2.port._create_from_ptr_and_get_ref(
             port_ptr, native_bt.PORT_TYPE_INPUT
         )
@@ -43,9 +40,6 @@ class _Connection(bt2.object._SharedObject):
     @property
     def upstream_port(self):
         port_ptr = native_bt.connection_borrow_upstream_port_const(self._ptr)
-        utils._handle_ptr(
-            port_ptr, "cannot get connection object's upstream port object"
-        )
         return bt2.port._create_from_ptr_and_get_ref(
             port_ptr, native_bt.PORT_TYPE_OUTPUT
         )
index a98357f1e5099c07d989284bb582c125c7cdcdad..0cdffb1abfbc3ce41c5becbca6d1ceeec40aa823 100644 (file)
@@ -31,7 +31,6 @@ import bt2
 
 def _create_field_from_ptr(ptr, owner_ptr, owner_get_ref, owner_put_ref):
     field_class_ptr = native_bt.field_borrow_class_const(ptr)
-    utils._handle_ptr(field_class_ptr, "cannot get field object's class")
     typeid = native_bt.field_class_get_type(field_class_ptr)
     field = _TYPE_ID_TO_OBJ[typeid]._create_from_ptr_and_get_ref(
         ptr, owner_ptr, owner_get_ref, owner_put_ref
@@ -465,8 +464,10 @@ class _VariantField(_ContainerField, _Field):
 
     @property
     def selected_option(self):
+        # TODO: Is there a way to check if the variant field has a selected_option,
+        # so we can raise an exception instead of hitting a pre-condition check?
+        # If there is something, that check should be added to selected_option_index too.
         field_ptr = native_bt.field_variant_borrow_selected_option_field(self._ptr)
-        utils._handle_ptr(field_ptr, "cannot get variant field's selected option")
 
         return _create_field_from_ptr(
             field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref
index 1d983215eac26e4ad800d08885fdcc5b09fffc62..2da3c31902ebc17d5d9b5adf1316a2dab52f1626 100644 (file)
@@ -120,11 +120,6 @@ def _raise_bt2_error(msg):
         raise bt2.Error(msg)
 
 
-def _handle_ptr(ptr, msg=None):
-    if ptr is None:
-        _raise_bt2_error(msg)
-
-
 def _check_log_level(log_level):
     _check_int(log_level)
 
This page took 0.027438 seconds and 4 git commands to generate.