apt 2.9.14 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/* Useful count macro, use on an array of things and it will return the
21 number of items in the array */
22#define APT_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
23
24// Flag Macros
25#define FLAG(f) (1L << (f))
26#define SETFLAG(v,f) ((v) |= FLAG(f))
27#define CLRFLAG(v,f) ((v) &=~FLAG(f))
28#define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false)
29
30#ifdef __GNUC__
31#define APT_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
32#else
33#define APT_GCC_VERSION 0
34#endif
35
36#ifdef APT_COMPILING_APT
37/* likely() and unlikely() can be used to mark boolean expressions
38 as (not) likely true which will help the compiler to optimise */
39#if APT_GCC_VERSION >= 0x0300
40 #define likely(x) __builtin_expect (!!(x), 1)
41 #define unlikely(x) __builtin_expect (!!(x), 0)
42#else
43 #define likely(x) (x)
44 #define unlikely(x) (x)
45#endif
46#endif
47
48#if APT_GCC_VERSION >= 0x0300
49 #define APT_DEPRECATED __attribute__ ((deprecated))
50 #define APT_DEPRECATED_MSG(X) __attribute__ ((deprecated(X)))
51 // __attribute__((const)) is too dangerous for us, we end up using it wrongly
52 #define APT_PURE __attribute__((pure))
53 #define APT_NORETURN __attribute__((noreturn))
54 #define APT_PRINTF(n) __attribute__((format(printf, n, n + 1)))
55 #define APT_WEAK __attribute__((weak));
56 #define APT_UNUSED __attribute__((unused))
57#else
58 #define APT_DEPRECATED
59 #define APT_DEPRECATED_MSG
60 #define APT_PURE
61 #define APT_NORETURN
62 #define APT_PRINTF(n)
63 #define APT_WEAK
64 #define APT_UNUSED
65#endif
66
67#if APT_GCC_VERSION > 0x0302
68 #define APT_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
69 #define APT_MUSTCHECK __attribute__((warn_unused_result))
70#else
71 #define APT_NONNULL(...)
72 #define APT_MUSTCHECK
73#endif
74
75#if APT_GCC_VERSION >= 0x0400
76 #define APT_SENTINEL __attribute__((sentinel))
77 #define APT_PUBLIC __attribute__ ((visibility ("default")))
78 #define APT_HIDDEN __attribute__ ((visibility ("hidden")))
79#else
80 #define APT_SENTINEL
81 #define APT_PUBLIC
82 #define APT_HIDDEN
83#endif
84
85// cold functions are unlikely() to be called
86#if APT_GCC_VERSION >= 0x0403
87 #define APT_COLD __attribute__ ((__cold__))
88 #define APT_HOT __attribute__ ((__hot__))
89#else
90 #define APT_COLD
91 #define APT_HOT
92#endif
93
94
95#if __GNUC__ >= 4
96 #define APT_IGNORE_DEPRECATED_PUSH \
97 _Pragma("GCC diagnostic push") \
98 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
99 #define APT_IGNORE_DEPRECATED_POP \
100 _Pragma("GCC diagnostic pop")
101 /* gcc has various problems with this shortcut, so prefer the long form */
102 #define APT_IGNORE_DEPRECATED(XXX) \
103 APT_IGNORE_DEPRECATED_PUSH \
104 XXX \
105 APT_IGNORE_DEPRECATED_POP
106#else
107 #define APT_IGNORE_DEPRECATED_PUSH
108 #define APT_IGNORE_DEPRECATED_POP
109 #define APT_IGNORE_DEPRECATED(XXX) XXX
110#endif
111
112#if __cplusplus >= 201103L
113 #define APT_OVERRIDE override
114#else
115 #define APT_OVERRIDE /* no c++11 standard */
116#endif
117
118// These lines are extracted by the makefiles and the buildsystem
119// Increasing MAJOR or MINOR results in the need of recompiling all
120// reverse-dependencies of libapt-pkg against the new SONAME.
121// Non-ABI-Breaks should only increase RELEASE number.
122// See also buildlib/libversion.mak
123#define APT_PKG_MAJOR 6
124#define APT_PKG_MINOR 0
125#define APT_PKG_RELEASE 0
126#define APT_PKG_ABI ((APT_PKG_MAJOR * 100) + APT_PKG_MINOR)
127
128/* Should be a multiple of the common page size (4096) */
129 static constexpr unsigned long long APT_BUFFER_SIZE = 64 * 1024;
130
131 template <class F>
132 struct AptScopeWrapper {
133 F func;
134 ~AptScopeWrapper() { func(); }
135};
136 template <class F>
137 AptScopeWrapper(F) -> AptScopeWrapper<F>;
138#define PASTE2(a, b) a##b
139#define PASTE(a, b) PASTE2(a, b)
140#define DEFER(lambda) AptScopeWrapper PASTE(defer, __LINE__){lambda};
141
142#endif
AptScopeWrapper
Definition macros.h:132