From e693822d3c00dbca7336ee2f9ba8f756599c7a3b Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 22 Jul 2015 17:05:36 -0400 Subject: [PATCH] ir: add BT_CTF_MOVE() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- include/babeltrace/ctf-ir/ref.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/babeltrace/ctf-ir/ref.h b/include/babeltrace/ctf-ir/ref.h index fa612ca0..acc89d17 100644 --- a/include/babeltrace/ctf-ir/ref.h +++ b/include/babeltrace/ctf-ir/ref.h @@ -50,6 +50,22 @@ (_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. * -- 2.34.1