apt 3.0.3
commandline package manager
macros.h
1// -*- mode: cpp; mode: fold -*-
2// SPDX-License-Identifier: GPL-2.0+
3// Description /*{{{*/
4/* ######################################################################
5
6 Macros Header - Various useful macro definitions
7
8 This file had this historic note, but now includes further changes
9 under the GPL-2.0+:
10
11 This source is placed in the Public Domain, do with it what you will
12 It was originally written by Brian C. White.
13
14 ##################################################################### */
15 /*}}}*/
16// Private header
17#ifndef MACROS_H
18#define MACROS_H
19
20#ifdef __GNUC__
21#define APT_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
22#else
23#define APT_GCC_VERSION 0
24#endif
25
26#ifdef APT_COMPILING_APT
27/* likely() and unlikely() can be used to mark boolean expressions
28 as (not) likely true which will help the compiler to optimise */
29#if APT_GCC_VERSION >= 0x0300
30 #define likely(x) __builtin_expect (!!(x), 1)
31 #define unlikely(x) __builtin_expect (!!(x), 0)
32#else
33 #define likely(x) (x)
34 #define unlikely(x) (x)
35#endif
36#endif
37
38#if APT_GCC_VERSION >= 0x0300
39 // __attribute__((const)) is too dangerous for us, we end up using it wrongly
40 #define APT_PURE __attribute__((pure))
41 #define APT_PRINTF(n) __attribute__((format(printf, n, n + 1)))
42 #define APT_WEAK __attribute__((weak));
43#else
44 #define APT_PURE
45 #define APT_PRINTF(n)
46 #define APT_WEAK
47#endif
48
49#if APT_GCC_VERSION > 0x0302
50 #define APT_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
51#else
52 #define APT_NONNULL(...)
53#endif
54
55#if APT_GCC_VERSION >= 0x0400
56 #define APT_SENTINEL __attribute__((sentinel))
57 #define APT_PUBLIC __attribute__ ((visibility ("default")))
58 #define APT_HIDDEN __attribute__ ((visibility ("hidden")))
59#else
60 #define APT_SENTINEL
61 #define APT_PUBLIC
62 #define APT_HIDDEN
63#endif
64
65// cold functions are unlikely() to be called
66#if APT_GCC_VERSION >= 0x0403
67 #define APT_COLD __attribute__ ((__cold__))
68 #define APT_HOT __attribute__ ((__hot__))
69#else
70 #define APT_COLD
71 #define APT_HOT
72#endif
73
74
75#if __GNUC__ >= 4
76 #define APT_IGNORE_DEPRECATED_PUSH \
77 _Pragma("GCC diagnostic push") \
78 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
79 #define APT_IGNORE_DEPRECATED_POP \
80 _Pragma("GCC diagnostic pop")
81#else
82 #define APT_IGNORE_DEPRECATED_PUSH
83 #define APT_IGNORE_DEPRECATED_POP
84#endif
85
86// These lines are extracted by the makefiles and the buildsystem
87// Increasing MAJOR or MINOR results in the need of recompiling all
88// reverse-dependencies of libapt-pkg against the new SONAME.
89// Non-ABI-Breaks should only increase RELEASE number.
90// See also buildlib/libversion.mak
91#define APT_PKG_MAJOR 7
92#define APT_PKG_MINOR 0
93#define APT_PKG_RELEASE 0
94#define APT_PKG_ABI ((APT_PKG_MAJOR * 100) + APT_PKG_MINOR)
95
96/* Should be a multiple of the common page size (4096) */
97static constexpr unsigned long long APT_BUFFER_SIZE = 64 * 1024;
98
99template <class F>
101 F func;
102 ~AptScopeWrapper() { func(); }
103};
104template <class F>
106#define APT_PASTE2(a, b) a##b
107#define APT_PASTE(a, b) APT_PASTE2(a, b)
108#define DEFER(lambda) AptScopeWrapper APT_PASTE(defer, __LINE__){lambda};
109
110
111#ifndef APT_COMPILING_APT
112#endif
113#endif
Definition macros.h:100