logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-Use-static-inline-functions-for-min-and-max.patch (4033B)


  1. From 5205a990e10f9bf1102c719198f82aba342cbca5 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Sun, 11 Aug 2019 05:05:09 +0000
  4. Subject: [PATCH] Use static inline functions for min and max
  5. These generic macros were only ever used with type `int`, and making
  6. them inline functions avoids the use of non-standard statement
  7. expressions.
  8. ---
  9. include/netlink-private/netlink.h | 27 +++++++++++----------------
  10. lib/attr.c | 2 +-
  11. lib/msg.c | 2 +-
  12. lib/route/cls/ematch_syntax.y | 2 +-
  13. lib/route/link/inet.c | 2 +-
  14. lib/route/link/inet6.c | 2 +-
  15. 6 files changed, 16 insertions(+), 21 deletions(-)
  16. diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h
  17. index 5f6e3f7..fca3133 100644
  18. --- a/include/netlink-private/netlink.h
  19. +++ b/include/netlink-private/netlink.h
  20. @@ -158,22 +158,17 @@ static inline int nl_cb_call(struct nl_cb *cb, enum nl_cb_type type, struct nl_m
  21. #undef __deprecated
  22. #define __deprecated __attribute__ ((deprecated))
  23. -#define min(x,y) ({ \
  24. - __typeof__(x) _x = (x); \
  25. - __typeof__(y) _y = (y); \
  26. - (void) (&_x == &_y); \
  27. - _x < _y ? _x : _y; })
  28. -
  29. -#define max(x,y) ({ \
  30. - __typeof__(x) _x = (x); \
  31. - __typeof__(y) _y = (y); \
  32. - (void) (&_x == &_y); \
  33. - _x > _y ? _x : _y; })
  34. -
  35. -#define min_t(type,x,y) \
  36. - ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
  37. -#define max_t(type,x,y) \
  38. - ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
  39. +static inline int
  40. +min(int x, int y)
  41. +{
  42. + return x < y ? x : y;
  43. +}
  44. +
  45. +static inline int
  46. +max(int x, int y)
  47. +{
  48. + return x > y ? x : y;
  49. +}
  50. extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
  51. struct nlmsghdr *, struct nl_parser_param *);
  52. diff --git a/lib/attr.c b/lib/attr.c
  53. index a4f5852..025627e 100644
  54. --- a/lib/attr.c
  55. +++ b/lib/attr.c
  56. @@ -358,7 +358,7 @@ int nla_memcpy(void *dest, const struct nlattr *src, int count)
  57. if (!src)
  58. return 0;
  59. - minlen = min_t(int, count, nla_len(src));
  60. + minlen = min(count, nla_len(src));
  61. memcpy(dest, nla_data(src), minlen);
  62. return minlen;
  63. diff --git a/lib/msg.c b/lib/msg.c
  64. index c08b3a4..d854df3 100644
  65. --- a/lib/msg.c
  66. +++ b/lib/msg.c
  67. @@ -155,7 +155,7 @@ struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh, int hdrlen)
  68. */
  69. int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
  70. {
  71. - return max_t(int, nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0);
  72. + return max(nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0);
  73. }
  74. /** @} */
  75. diff --git a/lib/route/cls/ematch_syntax.y b/lib/route/cls/ematch_syntax.y
  76. index 82d753d..88665cc 100644
  77. --- a/lib/route/cls/ematch_syntax.y
  78. +++ b/lib/route/cls/ematch_syntax.y
  79. @@ -411,7 +411,7 @@ pattern:
  80. if (nl_addr_parse($1, AF_UNSPEC, &addr) == 0) {
  81. $$.len = nl_addr_get_len(addr);
  82. - $$.index = min_t(int, $$.len, nl_addr_get_prefixlen(addr)/8);
  83. + $$.index = min($$.len, nl_addr_get_prefixlen(addr)/8);
  84. if (!($$.data = calloc(1, $$.len))) {
  85. nl_addr_put(addr);
  86. diff --git a/lib/route/link/inet.c b/lib/route/link/inet.c
  87. index 6651bc3..e33a3fe 100644
  88. --- a/lib/route/link/inet.c
  89. +++ b/lib/route/link/inet.c
  90. @@ -110,7 +110,7 @@ static int inet_parse_af(struct rtnl_link *link, struct nlattr *attr, void *data
  91. if (tb[IFLA_INET_CONF]) {
  92. int i;
  93. - int len = min_t(int, IPV4_DEVCONF_MAX, nla_len(tb[IFLA_INET_CONF]) / 4);
  94. + int len = min(IPV4_DEVCONF_MAX, nla_len(tb[IFLA_INET_CONF]) / 4);
  95. for (i = 0; i < len; i++)
  96. id->i_confset[i] = 1;
  97. diff --git a/lib/route/link/inet6.c b/lib/route/link/inet6.c
  98. index f02792c..8a3de01 100644
  99. --- a/lib/route/link/inet6.c
  100. +++ b/lib/route/link/inet6.c
  101. @@ -199,7 +199,7 @@ static int inet6_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
  102. map_stat_id = map_stat_id_from_IPSTATS_MIB_v1;
  103. }
  104. - len = min_t(int, __IPSTATS_MIB_MAX, len);
  105. + len = min(__IPSTATS_MIB_MAX, len);
  106. for (i = 1; i < len; i++) {
  107. memcpy(&stat, &cnt[i * sizeof(stat)], sizeof(stat));
  108. rtnl_link_set_stat(link, map_stat_id[i], stat);
  109. --
  110. 2.23.0