Update version to v2.1.0-rc7
[lttng-tools.git] / src / common / macros.h
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#ifndef _MACROS_H
20#define _MACROS_H
21
22#include <stdlib.h>
23
24/*
25 * Takes a pointer x and transform it so we can use it to access members
26 * without a function call. Here an example:
27 *
28 * #define GET_SIZE(x) LTTNG_REF(x)->size
29 *
30 * struct { int size; } s;
31 *
32 * printf("size : %d\n", GET_SIZE(&s));
33 *
34 * For this example we can't use something like this for compatibility purpose
35 * since this will fail:
36 *
37 * #define GET_SIZE(x) x->size;
38 *
39 * This is mostly use for the compatibility layer of lttng-tools. See
40 * poll/epoll for a good example. Since x can be on the stack or allocated
41 * memory using malloc(), we must use generic accessors for compat in order to
42 * *not* use a function to access members and not the variable name.
43 */
44#define LTTNG_REF(x) ((typeof(*x) *)(x))
45
46/*
47 * Memory allocation zeroed
48 */
49#define zmalloc(x) calloc(1, x)
50
51#ifndef ARRAY_SIZE
52#define ARRAY_SIZE(array) (sizeof(array) / (sizeof((array)[0])))
53#endif
54
55#endif /* _MACROS_H */
This page took 0.025139 seconds and 5 git commands to generate.