X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fmacros.h;h=718a3050ccb1b4b96b9a00cf84adeb35185bdae0;hb=1778c2a4134647150b199b2b57130817144446b0;hp=036b3e012b7fc47b360f63007501d5eea20ffe7d;hpb=55b71f05674d8c77a4f39709784707ddabe6177b;p=babeltrace.git diff --git a/src/common/macros.h b/src/common/macros.h index 036b3e01..718a3050 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -1,28 +1,11 @@ -#ifndef _BABELTRACE_INTERNAL_H -#define _BABELTRACE_INTERNAL_H - /* - * Copyright 2012 Mathieu Desnoyers + * SPDX-License-Identifier: MIT * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright 2012 Mathieu Desnoyers */ +#ifndef _BABELTRACE_INTERNAL_H +#define _BABELTRACE_INTERNAL_H #define bt_max_t(type, a, b) \ ((type) (a) > (type) (b) ? (type) (a) : (type) (b)) @@ -56,9 +39,36 @@ #define BT_MOVE_REF(ref) \ ({ \ - __auto_type _ref = ref; \ + typeof(ref) _ref = ref; \ ref = NULL; \ _ref; \ }) +/* + * Copied from: + * : + * + * * sizeof() ensures that the expression is not evaluated at all, so + * its side-effects don't happen. That is to be consistent with the + * usual behaviour of debug-only constructs, such as assert(). + * + * * `((_expr), 0)` uses the comma operator to swallow the actual type + * of `(_expr)`. This is to prevent VLAs from triggering evaluation. + * + * * `(void)` explicitly ignores the result of `(_expr)` and sizeof() so + * no "unused value" warning appears. + */ + +#define BT_USE_EXPR(_expr) ((void) sizeof((void) (_expr), 0)) +#define BT_USE_EXPR2(_expr1, _expr2) \ + ((void) sizeof((void) (_expr1), (void) (_expr2), 0)) +#define BT_USE_EXPR3(_expr1, _expr2, _expr3) \ + ((void) sizeof((void) (_expr1), (void) (_expr2), (void) (_expr3), 0)) +#define BT_USE_EXPR4(_expr1, _expr2, _expr3, _expr4) \ + ((void) sizeof((void) (_expr1), (void) (_expr2), \ + (void) (_expr3), (void) (_expr4), 0)) +#define BT_USE_EXPR5(_expr1, _expr2, _expr3, _expr4, _expr5) \ + ((void) sizeof((void) (_expr1), (void) (_expr2), \ + (void) (_expr3), (void) (_expr4), (void) (_expr5), 0)) + #endif