Commit 7d5f3f05 authored by Peter Hutterer's avatar Peter Hutterer
Browse files

map: rename pw_map_insert_at to pw_map_replace_at

See commit c07f0ccb, this function must not be used to actually insert
new data, it can only replace existing data in the map. Let's rename the
function and mark the old one as deprecated.

Related !975
parent a84cfac2
Pipeline #444166 passed with stages
in 3 minutes and 40 seconds
......@@ -2833,8 +2833,8 @@ static void registry_event_global(void *data, uint32_t id,
pthread_mutex_lock(&c->context.lock);
size = pw_map_get_size(&c->context.globals);
while (id > size)
pw_map_insert_at(&c->context.globals, size++, NULL);
pw_map_insert_at(&c->context.globals, id, o);
pw_map_replace_at(&c->context.globals, size++, NULL);
pw_map_replace_at(&c->context.globals, id, o);
pthread_mutex_unlock(&c->context.lock);
switch (o->type) {
......@@ -2938,7 +2938,7 @@ static void registry_event_global_remove(void *object, uint32_t id)
/* we keep the object available with the id because jack clients
* tend to access the objects with it later.
*
* pw_map_insert_at(&c->context.globals, id, NULL);
* pw_map_replace_at(&c->context.globals, id, NULL);
*/
return;
......
......@@ -950,7 +950,7 @@ client_node_get_node(void *data,
impl->bind_node_version = version;
impl->bind_node_id = new_id;
pw_map_insert_at(&this->client->objects, new_id, NULL);
pw_map_replace_at(&this->client->objects, new_id, NULL);
return NULL;
}
......
......@@ -792,7 +792,7 @@ static int core_demarshal_update_types_server(void *object, const struct pw_prot
uint32_t type_id = pw_protocol_native0_find_type(client, types[i]);
if (type_id == SPA_ID_INVALID)
continue;
if (pw_map_insert_at(&compat_v2->types, first_id, PW_MAP_ID_TO_PTR(type_id)) < 0)
if (pw_map_replace_at(&compat_v2->types, first_id, PW_MAP_ID_TO_PTR(type_id)) < 0)
pw_log_error("can't add type %d->%d for client", first_id, type_id);
}
return 0;
......
......@@ -305,7 +305,7 @@ error_bind:
error_exit:
pw_log_error("%p: can't bind global %u/%u: %d (%s)", global, id,
version, res, spa_strerror(res));
pw_map_insert_at(&client->objects, id, NULL);
pw_map_replace_at(&client->objects, id, NULL);
if (client->core_resource)
pw_core_resource_remove_id(client->core_resource, id);
return res;
......
......@@ -87,7 +87,7 @@ error_exit_clean:
/* unmark the new_id the map, the client does not yet know about the failed
* bind and will choose the next id, which we would refuse when we don't mark
* new_id as 'used and freed' */
pw_map_insert_at(&client->objects, new_id, NULL);
pw_map_replace_at(&client->objects, new_id, NULL);
pw_core_resource_remove_id(client->core_resource, new_id);
return NULL;
}
......@@ -281,7 +281,7 @@ error_resource:
client->recv_seq, res,
"can't create registry resource: %d (%s)",
res, spa_strerror(res));
pw_map_insert_at(&client->objects, new_id, NULL);
pw_map_replace_at(&client->objects, new_id, NULL);
pw_core_resource_remove_id(client->core_resource, new_id);
errno = -res;
return NULL;
......@@ -351,7 +351,7 @@ error_create_failed:
res = -errno;
goto error_exit;
error_exit:
pw_map_insert_at(&client->objects, new_id, NULL);
pw_map_replace_at(&client->objects, new_id, NULL);
pw_core_resource_remove_id(client->core_resource, new_id);
errno = -res;
return NULL;
......
......@@ -953,7 +953,7 @@ int pw_impl_port_add(struct pw_impl_port *port, struct pw_impl_node *node)
if (find != NULL)
return -EEXIST;
if ((res = pw_map_insert_at(portmap, port_id, port)) < 0)
if ((res = pw_map_replace_at(portmap, port_id, port)) < 0)
return res;
port->node = node;
......@@ -1067,10 +1067,10 @@ static void pw_impl_port_remove(struct pw_impl_port *port)
}
if (port->direction == PW_DIRECTION_INPUT) {
pw_map_insert_at(&node->input_port_map, port->port_id, NULL);
pw_map_replace_at(&node->input_port_map, port->port_id, NULL);
node->info.n_input_ports--;
} else {
pw_map_insert_at(&node->output_port_map, port->port_id, NULL);
pw_map_replace_at(&node->output_port_map, port->port_id, NULL);
node->info.n_output_ports--;
}
......
......@@ -168,9 +168,11 @@ static inline uint32_t pw_map_insert_new(struct pw_map *map, void *data)
* \param map the map to insert into
* \param id the index to insert at, must be less or equal to pw_map_get_size()
* \param data the data to insert
* \return 0 on success, -ENOSPC value when the index is invalid or a negative errno
* \return 0 on success or a negative errno otherwise
* \retval -ENOSPC index is invalid
* \retval -EINVAL the given id is not a currently valid ID
*/
static inline int pw_map_insert_at(struct pw_map *map, uint32_t id, void *data)
static inline int pw_map_replace_at(struct pw_map *map, uint32_t id, void *data)
{
size_t size = pw_map_get_size(map);
union pw_map_item *item;
......@@ -190,6 +192,15 @@ static inline int pw_map_insert_at(struct pw_map *map, uint32_t id, void *data)
return 0;
}
/**
* \deprecated Use pw_map_replace_at() instead
*/
SPA_DEPRECATED
static inline int pw_map_insert_at(struct pw_map *map, uint32_t id, void *data)
{
return pw_map_replace_at(map, id, data);
}
/** Remove an item at index. The id may get re-used in the future.
*
* \param map the map to remove from
......
......@@ -72,7 +72,7 @@ struct pw_resource *pw_resource_new(struct pw_impl_client *client,
goto error_clean;
}
if ((res = pw_map_insert_at(&client->objects, id, this)) < 0) {
if ((res = pw_map_replace_at(&client->objects, id, this)) < 0) {
pw_log_error("%p: can't add id %u for client %p: %s",
this, id, client, spa_strerror(res));
goto error_clean;
......@@ -274,7 +274,7 @@ void pw_resource_destroy(struct pw_resource *resource)
pw_log_debug("%p: destroy %u", resource, resource->id);
pw_resource_emit_destroy(resource);
pw_map_insert_at(&client->objects, resource->id, NULL);
pw_map_replace_at(&client->objects, resource->id, NULL);
pw_impl_client_emit_resource_removed(client, resource);
if (client->core_resource && !resource->removed)
......
......@@ -350,8 +350,8 @@ static void registry_event_global(void *data, uint32_t id,
size = pw_map_get_size(&rd->globals);
while (id > size)
pw_map_insert_at(&rd->globals, size++, NULL);
pw_map_insert_at(&rd->globals, id, global);
pw_map_replace_at(&rd->globals, size++, NULL);
pw_map_replace_at(&rd->globals, id, global);
/* immediately bind the object always */
ret = bind_global(rd, global, &error);
......@@ -371,7 +371,7 @@ static int destroy_global(void *obj, void *data)
if (global->proxy)
pw_proxy_destroy(global->proxy);
pw_map_insert_at(&global->rd->globals, global->id, NULL);
pw_map_replace_at(&global->rd->globals, global->id, NULL);
pw_properties_free(global->properties);
free(global->type);
free(global);
......
......@@ -99,25 +99,25 @@ PWTEST(map_insert)
pwtest_int_eq(sz, 3U);
/* overwrite */
rc = pw_map_insert_at(&map, idx1, p4);
rc = pw_map_replace_at(&map, idx1, p4);
pwtest_neg_errno_ok(rc);
pwtest_ptr_eq(p4, pw_map_lookup(&map, idx1));
sz = pw_map_get_size(&map);
pwtest_int_eq(sz, 3U);
/* overwrite */
rc = pw_map_insert_at(&map, idx2, p4);
rc = pw_map_replace_at(&map, idx2, p4);
pwtest_neg_errno_ok(rc);
pwtest_ptr_eq(p4, pw_map_lookup(&map, idx2));
sz = pw_map_get_size(&map);
pwtest_int_eq(sz, 3U);
/* out of bounds */
rc = pw_map_insert_at(&map, 10000, p4);
rc = pw_map_replace_at(&map, 10000, p4);
pwtest_neg_errno(rc, -ENOSPC);
/* if id is the map size, the item is appended */
rc = pw_map_insert_at(&map, idx3 + 1, &p4);
rc = pw_map_replace_at(&map, idx3 + 1, &p4);
pwtest_neg_errno_ok(rc);
sz = pw_map_get_size(&map);
pwtest_int_eq(sz, 4U);
......@@ -223,7 +223,7 @@ PWTEST(map_insert_at_free)
pw_map_remove(&map, after_idx);
}
rc = pw_map_insert_at(&map, item_idx, &new_data);
rc = pw_map_replace_at(&map, item_idx, &new_data);
pwtest_neg_errno(rc, -EINVAL);
pw_map_clear(&map);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment