tree-wide: rename unref_and_replace_full to unref_and_replace_new_ref
We have a number of *_unref_and_replace macros. One could think that they are like the various free_and_replace variants, but they actually create a new ref to the passed object. The free_and_replace variants take ownership of the argument. This inconsistency is surprising. Rename all those functions to have "_new_ref" at the end to make the difference clear.
This commit is contained in:
@@ -19,13 +19,13 @@ typedef void* (*mfree_func_t)(void *p);
|
||||
|
||||
/* This is similar to free_and_replace_full(), but NULL is not assigned to 'b', and its reference counter is
|
||||
* increased. */
|
||||
#define unref_and_replace_full(a, b, ref_func, unref_func) \
|
||||
({ \
|
||||
typeof(a)* _a = &(a); \
|
||||
typeof(b) _b = ref_func(b); \
|
||||
unref_func(*_a); \
|
||||
*_a = _b; \
|
||||
0; \
|
||||
#define unref_and_replace_new_ref(a, b, ref_func, unref_func) \
|
||||
({ \
|
||||
typeof(a)* _a = &(a); \
|
||||
typeof(b) _b = ref_func(b); \
|
||||
unref_func(*_a); \
|
||||
*_a = _b; \
|
||||
0; \
|
||||
})
|
||||
|
||||
#define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope) \
|
||||
|
||||
@@ -97,5 +97,5 @@ void dhcp_lease_set_timestamp(sd_dhcp_lease *lease, const triple_timestamp *time
|
||||
int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease);
|
||||
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const sd_dhcp_client_id *client_id);
|
||||
|
||||
#define dhcp_lease_unref_and_replace(a, b) \
|
||||
unref_and_replace_full(a, b, sd_dhcp_lease_ref, sd_dhcp_lease_unref)
|
||||
#define dhcp_lease_unref_and_replace_new_ref(a, b) \
|
||||
unref_and_replace_new_ref(a, b, sd_dhcp_lease_ref, sd_dhcp_lease_unref)
|
||||
|
||||
@@ -1594,7 +1594,7 @@ static int client_handle_offer_or_rapid_ack(sd_dhcp_client *client, DHCPMessage
|
||||
|
||||
dhcp_lease_set_timestamp(lease, timestamp);
|
||||
|
||||
dhcp_lease_unref_and_replace(client->lease, lease);
|
||||
dhcp_lease_unref_and_replace_new_ref(client->lease, lease);
|
||||
|
||||
if (client->lease->rapid_commit) {
|
||||
log_dhcp_client(client, "ACK");
|
||||
@@ -1678,7 +1678,7 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *message, size_
|
||||
else
|
||||
r = SD_DHCP_CLIENT_EVENT_IP_CHANGE;
|
||||
|
||||
dhcp_lease_unref_and_replace(client->lease, lease);
|
||||
dhcp_lease_unref_and_replace_new_ref(client->lease, lease);
|
||||
|
||||
log_dhcp_client(client, "ACK");
|
||||
return r;
|
||||
@@ -2281,7 +2281,7 @@ sd_event* sd_dhcp_client_get_event(sd_dhcp_client *client) {
|
||||
int sd_dhcp_client_attach_device(sd_dhcp_client *client, sd_device *dev) {
|
||||
assert_return(client, -EINVAL);
|
||||
|
||||
return device_unref_and_replace(client->dev, dev);
|
||||
return device_unref_and_replace_new_ref(client->dev, dev);
|
||||
}
|
||||
|
||||
static sd_dhcp_client* dhcp_client_free(sd_dhcp_client *client) {
|
||||
|
||||
@@ -1533,7 +1533,7 @@ sd_event *sd_dhcp6_client_get_event(sd_dhcp6_client *client) {
|
||||
int sd_dhcp6_client_attach_device(sd_dhcp6_client *client, sd_device *dev) {
|
||||
assert_return(client, -EINVAL);
|
||||
|
||||
return device_unref_and_replace(client->dev, dev);
|
||||
return device_unref_and_replace_new_ref(client->dev, dev);
|
||||
}
|
||||
|
||||
static sd_dhcp6_client *dhcp6_client_free(sd_dhcp6_client *client) {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include "sd-forward.h"
|
||||
#include "log.h"
|
||||
|
||||
#define device_unref_and_replace(a, b) \
|
||||
unref_and_replace_full(a, b, sd_device_ref, sd_device_unref)
|
||||
#define device_unref_and_replace_new_ref(a, b) \
|
||||
unref_and_replace_new_ref(a, b, sd_device_ref, sd_device_unref)
|
||||
|
||||
#define FOREACH_DEVICE_PROPERTY(device, key, value) \
|
||||
for (const char *value, *key = sd_device_get_property_first(device, &value); \
|
||||
|
||||
@@ -364,7 +364,7 @@ static int dhcp6_lease_information_acquired(sd_dhcp6_client *client, Link *link)
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to get DHCPv6 lease: %m");
|
||||
|
||||
unref_and_replace_full(link->dhcp6_lease, lease, sd_dhcp6_lease_ref, sd_dhcp6_lease_unref);
|
||||
unref_and_replace_new_ref(link->dhcp6_lease, lease, sd_dhcp6_lease_ref, sd_dhcp6_lease_unref);
|
||||
|
||||
link_dirty(link);
|
||||
return 0;
|
||||
|
||||
@@ -1678,7 +1678,7 @@ static int link_initialized(Link *link, sd_device *device) {
|
||||
|
||||
/* Always replace with the new sd_device object. As the sysname (and possibly other properties
|
||||
* or sysattrs) may be outdated. */
|
||||
device_unref_and_replace(link->dev, device);
|
||||
device_unref_and_replace_new_ref(link->dev, device);
|
||||
|
||||
r = link_managed_by_us(link);
|
||||
if (r <= 0)
|
||||
|
||||
@@ -469,7 +469,7 @@ int manager_udev_process_wiphy(Manager *m, sd_device *device, sd_device_action_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
return device_unref_and_replace(w->dev, action == SD_DEVICE_REMOVE ? NULL : device);
|
||||
return device_unref_and_replace_new_ref(w->dev, action == SD_DEVICE_REMOVE ? NULL : device);
|
||||
}
|
||||
|
||||
int manager_udev_process_rfkill(Manager *m, sd_device *device, sd_device_action_t action) {
|
||||
@@ -501,5 +501,5 @@ int manager_udev_process_rfkill(Manager *m, sd_device *device, sd_device_action_
|
||||
return 0;
|
||||
}
|
||||
|
||||
return device_unref_and_replace(w->rfkill, action == SD_DEVICE_REMOVE ? NULL : device);
|
||||
return device_unref_and_replace_new_ref(w->rfkill, action == SD_DEVICE_REMOVE ? NULL : device);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ int block_device_new_from_fd(int fd, BlockDeviceLookupFlags flags, sd_device **r
|
||||
|
||||
r = block_device_get_originating(dev_whole_disk, &dev_origin, /* recursive= */ false);
|
||||
if (r >= 0)
|
||||
device_unref_and_replace(dev, dev_origin);
|
||||
device_unref_and_replace_new_ref(dev, dev_origin);
|
||||
else if (r != -ENOENT)
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -683,7 +683,7 @@ static void event_find_blocker(Event *event) {
|
||||
log_device_debug(event->dev, "SEQNUM=%" PRIu64 " blocked by SEQNUM=%" PRIu64,
|
||||
event->seqnum, e->seqnum);
|
||||
|
||||
unref_and_replace_full(event->blocker, e, event_ref, event_unref);
|
||||
unref_and_replace_new_ref(event->blocker, e, event_ref, event_unref);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user