From: Philippe Proulx Date: Wed, 22 Jul 2015 21:05:36 +0000 (-0400) Subject: ir: add BT_CTF_MOVE() X-Git-Tag: v2.0.0-pre1~1207 X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=e693822d3c00dbca7336ee2f9ba8f756599c7a3b;p=babeltrace.git ir: add BT_CTF_MOVE() 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 --- 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. *