]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/macros.h
Compare size before data when ordering cache bucket entries
[apt.git] / apt-pkg / contrib / macros.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
578bfd0a
AL
3/* ######################################################################
4
5c0d3668 5 Macros Header - Various useful macro definitions
578bfd0a
AL
6
7 This source is placed in the Public Domain, do with it what you will
8 It was originally written by Brian C. White.
9
10 ##################################################################### */
11 /*}}}*/
12// Private header
5c0d3668
DK
13#ifndef MACROS_H
14#define MACROS_H
578bfd0a
AL
15
16// MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF
17#define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) )))
18#define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1)))
19
20// Min/Max functions
1ae93c94 21#if !defined(MIN)
578bfd0a
AL
22#if defined(__HIGHC__)
23#define MIN(x,y) _min(x,y)
24#define MAX(x,y) _max(x,y)
25#endif
26
27// GNU C++ has a min/max operator <coolio>
28#if defined(__GNUG__)
29#define MIN(A,B) ((A) <? (B))
30#define MAX(A,B) ((A) >? (B))
31#endif
32
33/* Templates tend to mess up existing code that uses min/max because of the
34 strict matching requirements */
35#if !defined(MIN)
36#define MIN(A,B) ((A) < (B)?(A):(B))
37#define MAX(A,B) ((A) > (B)?(A):(B))
38#endif
1ae93c94 39#endif
578bfd0a
AL
40
41/* Bound functions, bound will return the value b within the limits a-c
42 bounv will change b so that it is within the limits of a-c. */
43#define _bound(a,b,c) MIN(c,MAX(b,a))
44#define _boundv(a,b,c) b = _bound(a,b,c)
45#define ABS(a) (((a) < (0)) ?-(a) : (a))
46
1e3f4083 47/* Useful count macro, use on an array of things and it will return the
578bfd0a
AL
48 number of items in the array */
49#define _count(a) (sizeof(a)/sizeof(a[0]))
50
51// Flag Macros
52#define FLAG(f) (1L << (f))
53#define SETFLAG(v,f) ((v) |= FLAG(f))
54#define CLRFLAG(v,f) ((v) &=~FLAG(f))
55#define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false)
56
54298f49
DK
57#ifdef __GNUC__
58#define APT_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
59#else
60#define APT_GCC_VERSION 0
61#endif
62
63/* likely() and unlikely() can be used to mark boolean expressions
64 as (not) likely true which will help the compiler to optimise */
65#if APT_GCC_VERSION >= 0x0300
7d15572b
DK
66 #define likely(x) __builtin_expect (!!(x), 1)
67 #define unlikely(x) __builtin_expect (!!(x), 0)
3d43e539 68#else
7d15572b
DK
69 #define likely(x) (x)
70 #define unlikely(x) (x)
3d43e539
DK
71#endif
72
54298f49 73#if APT_GCC_VERSION >= 0x0300
453b82a3 74 #define APT_DEPRECATED __attribute__ ((deprecated))
5dd00edb 75 #define APT_DEPRECATED_MSG(X) __attribute__ ((deprecated(X)))
54298f49
DK
76 #define APT_CONST __attribute__((const))
77 #define APT_PURE __attribute__((pure))
78 #define APT_NORETURN __attribute__((noreturn))
79 #define APT_PRINTF(n) __attribute__((format(printf, n, n + 1)))
dca07c4d 80 #define APT_WEAK __attribute__((weak));
54298f49 81#else
453b82a3 82 #define APT_DEPRECATED
5dd00edb 83 #define APT_DEPRECATED_MSG
54298f49
DK
84 #define APT_CONST
85 #define APT_PURE
86 #define APT_NORETURN
87 #define APT_PRINTF(n)
dca07c4d 88 #define APT_WEAK
54298f49
DK
89#endif
90
91#if APT_GCC_VERSION > 0x0302
92 #define APT_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
93 #define APT_MUSTCHECK __attribute__((warn_unused_result))
94#else
95 #define APT_NONNULL(...)
ad5a4ac2 96 #define APT_MUSTCHECK
54298f49
DK
97#endif
98
99#if APT_GCC_VERSION >= 0x0400
100 #define APT_SENTINEL __attribute__((sentinel))
63ff4208
DK
101 #define APT_PUBLIC __attribute__ ((visibility ("default")))
102 #define APT_HIDDEN __attribute__ ((visibility ("hidden")))
54298f49
DK
103#else
104 #define APT_SENTINEL
63ff4208
DK
105 #define APT_PUBLIC
106 #define APT_HIDDEN
54298f49
DK
107#endif
108
3d43e539 109// cold functions are unlikely() to be called
54298f49
DK
110#if APT_GCC_VERSION >= 0x0403
111 #define APT_COLD __attribute__ ((__cold__))
112 #define APT_HOT __attribute__ ((__hot__))
3d43e539 113#else
453b82a3
DK
114 #define APT_COLD
115 #define APT_HOT
3d43e539
DK
116#endif
117
54298f49
DK
118#ifndef APT_10_CLEANER_HEADERS
119#if APT_GCC_VERSION >= 0x0300
120 #define __must_check __attribute__ ((warn_unused_result))
121 #define __deprecated __attribute__ ((deprecated))
122 #define __attrib_const __attribute__ ((__const__))
6dc60370 123 #define __like_printf(n) __attribute__((format(printf, n, n + 1)))
8f3d83ee 124#else
54298f49
DK
125 #define __must_check /* no warn_unused_result */
126 #define __deprecated /* no deprecated */
127 #define __attrib_const /* no const attribute */
6dc60370 128 #define __like_printf(n) /* no like-printf */
8f3d83ee 129#endif
54298f49
DK
130#if APT_GCC_VERSION >= 0x0403
131 #define __cold __attribute__ ((__cold__))
132 #define __hot __attribute__ ((__hot__))
133#else
134 #define __cold /* no cold marker */
135 #define __hot /* no hot marker */
136#endif
137#endif
138
586d8704
DK
139#if __GNUC__ >= 4
140 #define APT_IGNORE_DEPRECATED_PUSH \
141 _Pragma("GCC diagnostic push") \
142 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
143 #define APT_IGNORE_DEPRECATED_POP \
144 _Pragma("GCC diagnostic pop")
145 #define APT_IGNORE_DEPRECATED(XXX) \
146 APT_IGNORE_DEPRECATED_PUSH \
147 XXX \
148 APT_IGNORE_DEPRECATED_POP
149#else
150 #define APT_IGNORE_DEPRECATED_PUSH
151 #define APT_IGNORE_DEPRECATED_POP
152 #define APT_IGNORE_DEPRECATED(XXX) XXX
153#endif
154
28933259
DK
155#if __cplusplus >= 201103L
156 #define APT_OVERRIDE override
157#else
158 #define APT_OVERRIDE /* no c++11 standard */
159#endif
160
54298f49
DK
161// These lines are extracted by the makefiles and the buildsystem
162// Increasing MAJOR or MINOR results in the need of recompiling all
163// reverse-dependencies of libapt-pkg against the new SONAME.
164// Non-ABI-Breaks should only increase RELEASE number.
165// See also buildlib/libversion.mak
ae97af1f
DK
166#define APT_PKG_MAJOR 5
167#define APT_PKG_MINOR 0
c5f22e48 168#define APT_PKG_RELEASE 1
ccf6bdb3 169#define APT_PKG_ABI ((APT_PKG_MAJOR * 100) + APT_PKG_MINOR)
8f3d83ee 170
578bfd0a 171#endif