mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
map: handle more error cases
This commit is contained in:
parent
448c1937ad
commit
c348790ca1
4 changed files with 29 additions and 19 deletions
|
|
@ -233,7 +233,9 @@ struct spa_bt_transport {
|
||||||
#define spa_bt_transport_impl(t,m,v,...) \
|
#define spa_bt_transport_impl(t,m,v,...) \
|
||||||
({ \
|
({ \
|
||||||
int res = 0; \
|
int res = 0; \
|
||||||
spa_callbacks_call_res(&(t)->impl, struct spa_bt_transport_implementation, res, m, v, ##__VA_ARGS__); \
|
spa_callbacks_call_res(&(t)->impl, \
|
||||||
|
struct spa_bt_transport_implementation, \
|
||||||
|
res, m, v, ##__VA_ARGS__); \
|
||||||
res; \
|
res; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <spa/utils/defs.h>
|
#include <spa/utils/defs.h>
|
||||||
|
|
||||||
/** \class pw_array
|
/** \class pw_array
|
||||||
|
|
@ -94,7 +96,7 @@ static inline void pw_array_reset(struct pw_array *arr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make sure \a size bytes can be added to the array \memberof pw_array */
|
/** Make sure \a size bytes can be added to the array \memberof pw_array */
|
||||||
static inline bool pw_array_ensure_size(struct pw_array *arr, size_t size)
|
static inline int pw_array_ensure_size(struct pw_array *arr, size_t size)
|
||||||
{
|
{
|
||||||
size_t alloc, need;
|
size_t alloc, need;
|
||||||
|
|
||||||
|
|
@ -107,11 +109,11 @@ static inline bool pw_array_ensure_size(struct pw_array *arr, size_t size)
|
||||||
while (alloc < need)
|
while (alloc < need)
|
||||||
alloc *= 2;
|
alloc *= 2;
|
||||||
if (SPA_UNLIKELY((data = realloc(arr->data, alloc)) == NULL))
|
if (SPA_UNLIKELY((data = realloc(arr->data, alloc)) == NULL))
|
||||||
return false;
|
return -errno;
|
||||||
arr->data = data;
|
arr->data = data;
|
||||||
arr->alloc = alloc;
|
arr->alloc = alloc;
|
||||||
}
|
}
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add \a ref size bytes to \a arr. A pointer to memory that can
|
/** Add \a ref size bytes to \a arr. A pointer to memory that can
|
||||||
|
|
@ -120,7 +122,7 @@ static inline void *pw_array_add(struct pw_array *arr, size_t size)
|
||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
if (!pw_array_ensure_size(arr, size))
|
if (pw_array_ensure_size(arr, size) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
p = SPA_MEMBER(arr->data, arr->size, void);
|
p = SPA_MEMBER(arr->data, arr->size, void);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <spa/utils/defs.h>
|
#include <spa/utils/defs.h>
|
||||||
#include <pipewire/array.h>
|
#include <pipewire/array.h>
|
||||||
|
|
@ -97,7 +98,8 @@ static inline void pw_map_reset(struct pw_map *map)
|
||||||
/** Insert data in the map
|
/** Insert data in the map
|
||||||
* \param map the map to insert into
|
* \param map the map to insert into
|
||||||
* \param data the item to add
|
* \param data the item to add
|
||||||
* \return the id where the item was inserted
|
* \return the id where the item was inserted or SPA_ID_INVALID when the
|
||||||
|
* item can not be inserted.
|
||||||
* \memberof pw_map
|
* \memberof pw_map
|
||||||
*/
|
*/
|
||||||
static inline uint32_t pw_map_insert_new(struct pw_map *map, void *data)
|
static inline uint32_t pw_map_insert_new(struct pw_map *map, void *data)
|
||||||
|
|
@ -111,7 +113,7 @@ static inline uint32_t pw_map_insert_new(struct pw_map *map, void *data)
|
||||||
map->free_list = item->next;
|
map->free_list = item->next;
|
||||||
} else {
|
} else {
|
||||||
item = (union pw_map_item *) pw_array_add(&map->items, sizeof(union pw_map_item));
|
item = (union pw_map_item *) pw_array_add(&map->items, sizeof(union pw_map_item));
|
||||||
if (!item)
|
if (item == NULL)
|
||||||
return SPA_ID_INVALID;
|
return SPA_ID_INVALID;
|
||||||
start = (union pw_map_item *) map->items.data;
|
start = (union pw_map_item *) map->items.data;
|
||||||
}
|
}
|
||||||
|
|
@ -124,23 +126,27 @@ static inline uint32_t pw_map_insert_new(struct pw_map *map, void *data)
|
||||||
* \param map the map to inser into
|
* \param map the map to inser into
|
||||||
* \param id the index to insert at
|
* \param id the index to insert at
|
||||||
* \param data the data to insert
|
* \param data the data to insert
|
||||||
* \return true on success, false when the index is invalid
|
* \return 0 on success, -ENOSPC value when the index is invalid or a < 0
|
||||||
|
* errno value.
|
||||||
* \memberof pw_map
|
* \memberof pw_map
|
||||||
*/
|
*/
|
||||||
static inline bool pw_map_insert_at(struct pw_map *map, uint32_t id, void *data)
|
static inline int pw_map_insert_at(struct pw_map *map, uint32_t id, void *data)
|
||||||
{
|
{
|
||||||
size_t size = pw_map_get_size(map);
|
size_t size = pw_map_get_size(map);
|
||||||
union pw_map_item *item;
|
union pw_map_item *item;
|
||||||
|
|
||||||
if (id > size)
|
if (id > size)
|
||||||
return false;
|
return -ENOSPC;
|
||||||
else if (id == size)
|
else if (id == size) {
|
||||||
item = (union pw_map_item *) pw_array_add(&map->items, sizeof(union pw_map_item));
|
item = (union pw_map_item *) pw_array_add(&map->items, sizeof(union pw_map_item));
|
||||||
else
|
if (item == NULL)
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
else {
|
||||||
item = pw_map_get_item(map, id);
|
item = pw_map_get_item(map, id);
|
||||||
|
}
|
||||||
item->data = data;
|
item->data = data;
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove an item at index
|
/** Remove an item at index
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ struct pw_resource *pw_resource_new(struct pw_client *client,
|
||||||
|
|
||||||
if (id == SPA_ID_INVALID) {
|
if (id == SPA_ID_INVALID) {
|
||||||
id = pw_map_insert_new(&client->objects, this);
|
id = pw_map_insert_new(&client->objects, this);
|
||||||
} else if (!pw_map_insert_at(&client->objects, id, this))
|
} else if (pw_map_insert_at(&client->objects, id, this) < 0)
|
||||||
goto in_use;
|
goto in_use;
|
||||||
|
|
||||||
this->id = id;
|
this->id = id;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue