2014-05-14 15:27:11

by Andrzej Kaczmarek

[permalink] [raw]
Subject: [PATCH 1/2] shared: Fix queue_find to accept const ptr as match data

This patch fixes queue_find definition to have const pointer as data to
be matched against. Match function already does have const pointers as
arguments. Also parameter name is updated to be 'match_data' since this
actually is not user_data, just data to be matched against.
---
src/shared/queue.c | 4 ++--
src/shared/queue.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/shared/queue.c b/src/shared/queue.c
index 8a69729..ea4ff96 100644
--- a/src/shared/queue.c
+++ b/src/shared/queue.c
@@ -188,7 +188,7 @@ void queue_foreach(struct queue *queue, queue_foreach_func_t function,
}

void *queue_find(struct queue *queue, queue_match_func_t function,
- void *user_data)
+ const void *match_data)
{
struct queue_entry *entry;

@@ -196,7 +196,7 @@ void *queue_find(struct queue *queue, queue_match_func_t function,
return NULL;

for (entry = queue->head; entry; entry = entry->next)
- if (function(entry->data, user_data))
+ if (function(entry->data, match_data))
return entry->data;

return NULL;
diff --git a/src/shared/queue.h b/src/shared/queue.h
index 8201ff8..709590b 100644
--- a/src/shared/queue.h
+++ b/src/shared/queue.h
@@ -44,7 +44,7 @@ void queue_foreach(struct queue *queue, queue_foreach_func_t function,
typedef bool (*queue_match_func_t)(const void *a, const void *b);

void *queue_find(struct queue *queue, queue_match_func_t function,
- void *user_data);
+ const void *match_data);

bool queue_remove(struct queue *queue, void *data);
void *queue_remove_if(struct queue *queue, queue_match_func_t function,
--
1.9.3



2014-05-21 07:16:32

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 1/2] shared: Fix queue_find to accept const ptr as match data

Hi Andrzej,

On Wed, May 14, 2014, Andrzej Kaczmarek wrote:
> This patch fixes queue_find definition to have const pointer as data to
> be matched against. Match function already does have const pointers as
> arguments. Also parameter name is updated to be 'match_data' since this
> actually is not user_data, just data to be matched against.
> ---
> src/shared/queue.c | 4 ++--
> src/shared/queue.h | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)

Both patches in this set have been applied. Thanks.

Johan

2014-05-14 15:27:12

by Andrzej Kaczmarek

[permalink] [raw]
Subject: [PATCH 2/2] android/gatt: Remove unnecessary const to non-const casts

---
android/gatt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index ebda377..bfc41e0 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -384,7 +384,7 @@ static bool match_connection_by_app(const void *data, const void *user_data)

static struct gatt_device *find_device_by_addr(const bdaddr_t *addr)
{
- return queue_find(gatt_devices, match_device_by_bdaddr, (void *)addr);
+ return queue_find(gatt_devices, match_device_by_bdaddr, addr);
}

static struct gatt_device *find_pending_device()
@@ -607,7 +607,7 @@ static int register_app(const uint8_t *uuid, gatt_app_type_t app_type)
static int32_t application_id = 1;
struct gatt_app *app;

- if (queue_find(gatt_apps, match_app_by_uuid, (void *) uuid)) {
+ if (queue_find(gatt_apps, match_app_by_uuid, uuid)) {
error("gatt: app uuid is already on list");
return 0;
}
--
1.9.3