bt2: update object model
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 29 Apr 2019 16:12:36 +0000 (12:12 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:12:56 +0000 (00:12 -0400)
commit7542c30dcccf30818e255f25fd5c8f3e6f5d576b
tree1f3e3ffb0995d7f0bb7c0c7ab450a104436ea86f
parentc6a70ac31c44e83e1b41d062a68d026c7e73f5a3
bt2: update object model

This patch updates the Babeltrace Python object model (what all
Babeltrace Python objects inherit from) to match the current status of
the API.

We have both Shared and Unique objects.  Both types have a _ptr
member, a SWIG Python object wrapping a typed pointer (e.g. pointer to
struct bt_value).

A Shared object type is defined by inheriting from _SharedObject.  It
wraps and owns a reference to a Babeltrace object that is reference
counted.  The reference count is dropped when the Python object gets
deleted.  The _SharedObject base class defines two class methods,
_get_ref and _put_ref, which must be implemented by subclasses.  These
implementations must respectively get and put a reference of the
specialized pointer (_ptr) they wrap.

A Unique object type is defined by inheriting from _UniqueObject.  It is
not refcounted.  Rather, it is wholly owned by another object (the
owner) that is itself refcounted.  A Unique object, in the Babeltrace
API, is destroyed when its parent is destroyed.  There is therefore a
risk that someone would keep a (Python) reference to a unique object
that got destroyed, because its parent got destroyed, resulting in some
use-after-free bug.  To avoid this, we make it so that when a Python
object representing a Babeltrace Unique object is created, that Python
object obtains a reference on the owner Shared object.  When the Unique
Python object is destroyed, the reference on the Shared parent is
dropped.

The concepts of Freezable and Private objects don't exist anymore, so
they are removed.  I have also removed the _PrivateConnection class,
since it won't be needed in the end and inherited from _PrivateObject.
For other classes representing Babeltrace concepts, I have made them
inherit the object type they'll need to inherit in the end (when all the
Python bindings will be fixed), even though none of these classes is
functional at the moment.

Change-Id: I9ab743dd7a28407913945648c1d74c467550df14
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1021
Tested-by: jenkins
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 files changed:
bindings/python/bt2/bt2/__init__.py.in
bindings/python/bt2/bt2/clock_class.py
bindings/python/bt2/bt2/clock_snapshot.py
bindings/python/bt2/bt2/component.py
bindings/python/bt2/bt2/connection.py
bindings/python/bt2/bt2/ctf_writer.py
bindings/python/bt2/bt2/event.py
bindings/python/bt2/bt2/event_class.py
bindings/python/bt2/bt2/field.py
bindings/python/bt2/bt2/field_class.py
bindings/python/bt2/bt2/graph.py
bindings/python/bt2/bt2/message.py
bindings/python/bt2/bt2/message_iterator.py
bindings/python/bt2/bt2/object.py
bindings/python/bt2/bt2/packet.py
bindings/python/bt2/bt2/plugin.py
bindings/python/bt2/bt2/port.py
bindings/python/bt2/bt2/query_executor.py
bindings/python/bt2/bt2/stream.py
bindings/python/bt2/bt2/stream_class.py
bindings/python/bt2/bt2/trace.py
bindings/python/bt2/bt2/value.py
This page took 0.025683 seconds and 5 git commands to generate.