From df4b92bd1df204e7fb0d22e73e143d205d74aea6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2020 22:37:36 +0100 Subject: Rename _count() macro to APT_ARRAY_SIZE() --- apt-pkg/contrib/macros.h | 2 +- apt-pkg/edsp.cc | 4 ++-- apt-pkg/pkgcache.cc | 2 +- methods/gpgv.cc | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index c19cb313d..e914b7298 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -46,7 +46,7 @@ /* Useful count macro, use on an array of things and it will return the number of items in the array */ -#define _count(a) (sizeof(a)/sizeof(a[0])) +#define APT_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) // Flag Macros #define FLAG(f) (1L << (f)) diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 0d5fe150b..fe6f55dcb 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -94,7 +94,7 @@ static bool WriteScenarioVersion(FileFd &output, pkgCache::PkgIterator const &Pk // WriteScenarioDependency /*{{{*/ static bool WriteScenarioDependency(FileFd &output, pkgCache::VerIterator const &Ver, bool const OnlyCritical) { - std::array dependencies; + std::array dependencies; bool orGroup = false; for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep) { @@ -141,7 +141,7 @@ static bool WriteScenarioLimitedDependency(FileFd &output, std::vector const &pkgset, bool const OnlyCritical) { - std::array dependencies; + std::array dependencies; bool orGroup = false; for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep) { diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 160c58273..f8ab423ae 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -381,7 +381,7 @@ const char *pkgCache::Priority(unsigned char Prio) { const char *Mapping[] = {0,_("required"),_("important"),_("standard"), _("optional"),_("extra")}; - if (Prio < _count(Mapping)) + if (Prio < APT_ARRAY_SIZE(Mapping)) return Mapping[Prio]; return 0; } diff --git a/methods/gpgv.cc b/methods/gpgv.cc index 660041764..1ca62557c 100644 --- a/methods/gpgv.cc +++ b/methods/gpgv.cc @@ -83,7 +83,8 @@ static constexpr Digest Digests[] = { static Digest FindDigest(std::string const & Digest) { int id = atoi(Digest.c_str()); - if (id >= 0 && static_cast(id) < _count(Digests)) { + if (id >= 0 && static_cast(id) < APT_ARRAY_SIZE(Digests)) + { return Digests[id]; } else { return Digests[0]; -- cgit v1.2.3 From 3732fa6e73c8c0c80e8d2b03c002ad66f4e75183 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2020 22:38:45 +0100 Subject: Remove various unused macros like MAX/MIN/ABS/APT_CONST We don't use them, APT_CONST is APT_PURE now, and MAX/MIN/etc are available as proper templates in the C++ standard library. --- apt-pkg/contrib/macros.h | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index e914b7298..3f2638070 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -13,37 +13,6 @@ #ifndef MACROS_H #define MACROS_H -// MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF -#define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) ))) -#define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1))) - -// Min/Max functions -#if !defined(MIN) -#if defined(__HIGHC__) -#define MIN(x,y) _min(x,y) -#define MAX(x,y) _max(x,y) -#endif - -// GNU C++ has a min/max operator -#if defined(__GNUG__) -#define MIN(A,B) ((A) ? (B)) -#endif - -/* Templates tend to mess up existing code that uses min/max because of the - strict matching requirements */ -#if !defined(MIN) -#define MIN(A,B) ((A) < (B)?(A):(B)) -#define MAX(A,B) ((A) > (B)?(A):(B)) -#endif -#endif - -/* Bound functions, bound will return the value b within the limits a-c - bounv will change b so that it is within the limits of a-c. */ -#define _bound(a,b,c) MIN(c,MAX(b,a)) -#define _boundv(a,b,c) b = _bound(a,b,c) -#define ABS(a) (((a) < (0)) ?-(a) : (a)) - /* Useful count macro, use on an array of things and it will return the number of items in the array */ #define APT_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) @@ -74,7 +43,6 @@ #define APT_DEPRECATED __attribute__ ((deprecated)) #define APT_DEPRECATED_MSG(X) __attribute__ ((deprecated(X))) // __attribute__((const)) is too dangerous for us, we end up using it wrongly - #define APT_CONST __attribute__((pure)) #define APT_PURE __attribute__((pure)) #define APT_NORETURN __attribute__((noreturn)) #define APT_PRINTF(n) __attribute__((format(printf, n, n + 1))) @@ -83,7 +51,6 @@ #else #define APT_DEPRECATED #define APT_DEPRECATED_MSG - #define APT_CONST #define APT_PURE #define APT_NORETURN #define APT_PRINTF(n) -- cgit v1.2.3 From b911b2f6edaa8ee45b1f860ddf0cf061ccc96e1f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2020 22:39:29 +0100 Subject: Only define likely/unlikely if APT_COMPILING_APT set This ensures that we do not leak simple words like that. --- CMake/config.h.in | 3 +++ apt-pkg/contrib/macros.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/CMake/config.h.in b/CMake/config.h.in index b89f7297d..911d42464 100644 --- a/CMake/config.h.in +++ b/CMake/config.h.in @@ -64,6 +64,9 @@ /* The mail address to reach upstream */ #define PACKAGE_MAIL "${PACKAGE_MAIL}" +/* Guard for code that should only be emitted when compiling apt */ +#define APT_COMPILING_APT + /* Various directories */ #cmakedefine CMAKE_INSTALL_FULL_BINDIR "${CMAKE_INSTALL_FULL_BINDIR}" #cmakedefine STATE_DIR "${STATE_DIR}" diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index 3f2638070..340549fbd 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -29,6 +29,7 @@ #define APT_GCC_VERSION 0 #endif +#ifdef APT_COMPILING_APT /* likely() and unlikely() can be used to mark boolean expressions as (not) likely true which will help the compiler to optimise */ #if APT_GCC_VERSION >= 0x0300 @@ -38,6 +39,7 @@ #define likely(x) (x) #define unlikely(x) (x) #endif +#endif #if APT_GCC_VERSION >= 0x0300 #define APT_DEPRECATED __attribute__ ((deprecated)) -- cgit v1.2.3