Adds semantics to ownership transfers of CTF IR objects.
This is something that is done often enough to justify the
existence of this macro:
struct bt_ctf_field_type *type;
struct bt_ctf_field_type *ret_type;
/* ... */
/* move ownership */
ret_type = type;
type = NULL;
/* ... */
/* put both (safe since type was set to NULL) */
bt_ctf_put(ret_type);
bt_ctf_put(type);
With BT_CTF_MOVE():
struct bt_ctf_field_type *type;
struct bt_ctf_field_type *ret_type;
/* ... */
/* move ownership */
BT_CTF_MOVE(ret_type, type);
/* ... */
/* put both (safe since ownership was moved) */
bt_ctf_put(ret_type);
bt_ctf_put(type);
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
(_obj) = NULL; \
} while (0)
+/*
+ * BT_CTF_MOVE: moves the ownership of a CTF object, setting the old
+ * owner to NULL.
+ *
+ * This macro sets the variable _dst to the value of the variable _src,
+ * then sets _src to NULL, effectively moving the ownership of a CTF
+ * object from one variable to the other.
+ *
+ * @param obj CTF IR object.
+ */
+#define BT_CTF_MOVE(_dst, _src) \
+ do { \
+ (_dst) = (_src); \
+ (_src) = NULL; \
+ } while (0)
+
/*
* bt_ctf_get: increments the reference count of a CTF IR object.
*