Skip to contentSkip to conversation

shared/util: Add MIN/MAX implementations

PATCH Superseded Bastien Nocera 2 participants 4 messages Mar 30 – Mar 31 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 shared/util: Add MIN/MAX implementations

And remove it from src/sdpd-request.c to avoid a redefinition warning at compile-time.

---
 src/sdpd-request.c | 2 --
 src/shared/util.h  | 6 ++++++
 2 files changed, 6 insertions(+), 2 deletions(-)
src/sdpd-request.c +0 -2
index 1fc07e97bfe0..7c632c2aaf62 100644
@@ -40,8 +40,6 @@ typedef struct {
 
 #define SDP_CONT_STATE_SIZE (sizeof(uint8_t) + sizeof(sdp_cont_state_t))
 
-#define MIN(x, y) ((x) < (y)) ? (x): (y)
-
 typedef struct sdp_cont_info sdp_cont_info_t;
 
 struct sdp_cont_info {
src/shared/util.h +6 -0
index c480351d6e9f..99a5aa2daf32 100644
@@ -22,6 +22,12 @@
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #define BIT(n)  (1 << (n))
 
+#undef MIN
+#define MIN(a, b) ((a) > (b) ? (a) : (b))
+
+#undef MAX
+#define MAX(a, b) ((a) < (b) ? (a) : (b))
+
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define le16_to_cpu(val) (val)
 #define le32_to_cpu(val) (val)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/2 emulator: Remove compile-time header only glib dep

btvirt relied on a glib header macro to use MIN/MAX, but didn't link against it, meaning that it was dependent on other programs in the project using glib to compile correctly.

Remove the include and use our own implementation instead.

---
 emulator/btdev.c | 2 --
 1 file changed, 2 deletions(-)
emulator/btdev.c +0 -2
index d3a9c6735ff1..3a295b679f34 100644
@@ -25,8 +25,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include <glib.h>
-
 #include "bluetooth/bluetooth.h"
 #include "bluetooth/hci.h"
 
Signature · 1 line
2.53.0
#2 lore raw
In reply to Bastien Nocera

Hi Bastien,

Quoted 26 lines · Bastien Nocera

And remove it from src/sdpd-request.c to avoid a redefinition warning at compile-time.

---
 src/sdpd-request.c | 2 --
 src/shared/util.h  | 6 ++++++
 2 files changed, 6 insertions(+), 2 deletions(-)
src/sdpd-request.c +0 -2
index 1fc07e97bfe0..7c632c2aaf62 100644
@@ -40,8 +40,6 @@ typedef struct {
 
 #define SDP_CONT_STATE_SIZE (sizeof(uint8_t) + sizeof(sdp_cont_state_t))
 
-#define MIN(x, y) ((x) < (y)) ? (x): (y)
-
 typedef struct sdp_cont_info sdp_cont_info_t;
 
 struct sdp_cont_info {
src/shared/util.h +0 -0
index c480351d6e9f..99a5aa2daf32 100644

src/shared/util.h line 29

Quoted 8 lines
src/shared/util.h +5 -0
@@ -22,6 +22,12 @@
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #define BIT(n)  (1 << (n))
 
+#undef MIN
+#define MIN(a, b) ((a) > (b) ? (a) : (b))
+
+#undef MAX
+#define MAX(a, b) ((a) < (b) ? (a) : (b))

This is causing many tests to fail with make check. It looks like the conditions are wrong, so MIN works as MAX and vice versa.

Quoted 7 lines
src/shared/util.h +0 -1
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define le16_to_cpu(val) (val)
 #define le32_to_cpu(val) (val)
--

2.53.0

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw
Quoted 35 lines · Luiz Augusto von Dentz

Hi Bastien,

Quoted 31 lines · Bastien Nocera

And remove it from src/sdpd-request.c to avoid a redefinition warning
at compile-time.
---
 src/sdpd-request.c | 2 --
 src/shared/util.h  | 6 ++++++

 2 files changed, 6 insertions(+), 2 deletions(-)
src/sdpd-request.c +0 -2
index 1fc07e97bfe0..7c632c2aaf62 100644
@@ -40,8 +40,6 @@ typedef struct {
 
  #define SDP_CONT_STATE_SIZE (sizeof(uint8_t) +
 sizeof(sdp_cont_state_t))
 
-#define MIN(x, y) ((x) < (y)) ? (x): (y)
-
  typedef struct sdp_cont_info sdp_cont_info_t;
 

 struct sdp_cont_info {

src/shared/util.h +0 -0
index c480351d6e9f..99a5aa2daf32 100644
@@ -22,6 +22,12 @@
  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  #define BIT(n)  (1 << (n))
 
Quoted 8 lines

src/shared/util.h line 29

Quoted 5 lines
src/shared/util.h +5 -0
+#undef MIN
+#define MIN(a, b) ((a) > (b) ? (a) : (b))
+
+#undef MAX
+#define MAX(a, b) ((a) < (b) ? (a) : (b))

This is causing many tests to fail with make check. It looks like the conditions are wrong, so MIN works as MAX and vice versa.

Whoops, fixed.

Quoted 9 lines
Quoted 8 lines
src/shared/util.h +0 -1
  #if __BYTE_ORDER == __LITTLE_ENDIAN
  #define le16_to_cpu(val) (val)
  #define le32_to_cpu(val) (val)
--

2.53.0