tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable
This commit is contained in:
@@ -874,30 +874,7 @@ int bus_message_new_synthetic_error(
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ sd_bus_message* sd_bus_message_ref(sd_bus_message *m) {
|
||||
|
||||
if (!m)
|
||||
return NULL;
|
||||
|
||||
assert(m->n_ref > 0);
|
||||
m->n_ref++;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
_public_ sd_bus_message* sd_bus_message_unref(sd_bus_message *m) {
|
||||
|
||||
if (!m)
|
||||
return NULL;
|
||||
|
||||
assert(m->n_ref > 0);
|
||||
m->n_ref--;
|
||||
|
||||
if (m->n_ref > 0)
|
||||
return NULL;
|
||||
|
||||
return message_free(m);
|
||||
}
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_bus_message, sd_bus_message, message_free);
|
||||
|
||||
_public_ int sd_bus_message_get_type(sd_bus_message *m, uint8_t *type) {
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
@@ -37,17 +37,6 @@ sd_bus_slot *bus_slot_allocate(
|
||||
return slot;
|
||||
}
|
||||
|
||||
_public_ sd_bus_slot* sd_bus_slot_ref(sd_bus_slot *slot) {
|
||||
|
||||
if (!slot)
|
||||
return NULL;
|
||||
|
||||
assert(slot->n_ref > 0);
|
||||
|
||||
slot->n_ref++;
|
||||
return slot;
|
||||
}
|
||||
|
||||
void bus_slot_disconnect(sd_bus_slot *slot, bool unref) {
|
||||
sd_bus *bus;
|
||||
|
||||
@@ -187,17 +176,8 @@ void bus_slot_disconnect(sd_bus_slot *slot, bool unref) {
|
||||
sd_bus_slot_unref(slot);
|
||||
}
|
||||
|
||||
_public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) {
|
||||
|
||||
if (!slot)
|
||||
return NULL;
|
||||
|
||||
assert(slot->n_ref > 0);
|
||||
|
||||
if (slot->n_ref > 1) {
|
||||
slot->n_ref--;
|
||||
return NULL;
|
||||
}
|
||||
static sd_bus_slot* bus_slot_free(sd_bus_slot *slot) {
|
||||
assert(slot);
|
||||
|
||||
bus_slot_disconnect(slot, false);
|
||||
|
||||
@@ -208,6 +188,8 @@ _public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) {
|
||||
return mfree(slot);
|
||||
}
|
||||
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_bus_slot, sd_bus_slot, bus_slot_free);
|
||||
|
||||
_public_ sd_bus* sd_bus_slot_get_bus(sd_bus_slot *slot) {
|
||||
assert_return(slot, NULL);
|
||||
|
||||
|
||||
@@ -143,27 +143,8 @@ _public_ int sd_bus_track_new(
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ sd_bus_track* sd_bus_track_ref(sd_bus_track *track) {
|
||||
|
||||
if (!track)
|
||||
return NULL;
|
||||
|
||||
assert(track->n_ref > 0);
|
||||
|
||||
track->n_ref++;
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
_public_ sd_bus_track* sd_bus_track_unref(sd_bus_track *track) {
|
||||
if (!track)
|
||||
return NULL;
|
||||
|
||||
assert(track->n_ref > 0);
|
||||
track->n_ref--;
|
||||
|
||||
if (track->n_ref > 0)
|
||||
return NULL;
|
||||
static sd_bus_track *track_free(sd_bus_track *track) {
|
||||
assert(track);
|
||||
|
||||
if (track->in_list)
|
||||
LIST_REMOVE(tracks, track->bus->tracks, track);
|
||||
@@ -178,6 +159,8 @@ _public_ sd_bus_track* sd_bus_track_unref(sd_bus_track *track) {
|
||||
return mfree(track);
|
||||
}
|
||||
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_bus_track, sd_bus_track, track_free);
|
||||
|
||||
static int on_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
sd_bus_track *track = userdata;
|
||||
const char *name, *old, *new;
|
||||
|
||||
@@ -57,37 +57,29 @@ _public_ int sd_device_enumerator_new(sd_device_enumerator **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ sd_device_enumerator *sd_device_enumerator_ref(sd_device_enumerator *enumerator) {
|
||||
assert_return(enumerator, NULL);
|
||||
static sd_device_enumerator *device_enumerator_free(sd_device_enumerator *enumerator) {
|
||||
sd_device *device;
|
||||
|
||||
assert_se((++ enumerator->n_ref) >= 2);
|
||||
assert(enumerator);
|
||||
|
||||
return enumerator;
|
||||
while ((device = prioq_pop(enumerator->devices)))
|
||||
sd_device_unref(device);
|
||||
|
||||
prioq_free(enumerator->devices);
|
||||
|
||||
set_free_free(enumerator->match_subsystem);
|
||||
set_free_free(enumerator->nomatch_subsystem);
|
||||
hashmap_free_free_free(enumerator->match_sysattr);
|
||||
hashmap_free_free_free(enumerator->nomatch_sysattr);
|
||||
hashmap_free_free_free(enumerator->match_property);
|
||||
set_free_free(enumerator->match_sysname);
|
||||
set_free_free(enumerator->match_tag);
|
||||
sd_device_unref(enumerator->match_parent);
|
||||
|
||||
return mfree(enumerator);
|
||||
}
|
||||
|
||||
_public_ sd_device_enumerator *sd_device_enumerator_unref(sd_device_enumerator *enumerator) {
|
||||
if (enumerator && (-- enumerator->n_ref) == 0) {
|
||||
sd_device *device;
|
||||
|
||||
while ((device = prioq_pop(enumerator->devices)))
|
||||
sd_device_unref(device);
|
||||
|
||||
prioq_free(enumerator->devices);
|
||||
|
||||
set_free_free(enumerator->match_subsystem);
|
||||
set_free_free(enumerator->nomatch_subsystem);
|
||||
hashmap_free_free_free(enumerator->match_sysattr);
|
||||
hashmap_free_free_free(enumerator->nomatch_sysattr);
|
||||
hashmap_free_free_free(enumerator->match_property);
|
||||
set_free_free(enumerator->match_sysname);
|
||||
set_free_free(enumerator->match_tag);
|
||||
sd_device_unref(enumerator->match_parent);
|
||||
|
||||
free(enumerator);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_device_enumerator, sd_device_enumerator, device_enumerator_free);
|
||||
|
||||
_public_ int sd_device_enumerator_add_match_subsystem(sd_device_enumerator *enumerator, const char *subsystem, int match) {
|
||||
Set **set;
|
||||
|
||||
@@ -43,39 +43,32 @@ int device_new_aux(sd_device **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ sd_device *sd_device_ref(sd_device *device) {
|
||||
if (device)
|
||||
assert_se(++ device->n_ref >= 2);
|
||||
static sd_device *device_free(sd_device *device) {
|
||||
assert(device);
|
||||
|
||||
return device;
|
||||
sd_device_unref(device->parent);
|
||||
free(device->syspath);
|
||||
free(device->sysname);
|
||||
free(device->devtype);
|
||||
free(device->devname);
|
||||
free(device->subsystem);
|
||||
free(device->driver_subsystem);
|
||||
free(device->driver);
|
||||
free(device->id_filename);
|
||||
free(device->properties_strv);
|
||||
free(device->properties_nulstr);
|
||||
|
||||
ordered_hashmap_free_free_free(device->properties);
|
||||
ordered_hashmap_free_free_free(device->properties_db);
|
||||
hashmap_free_free_free(device->sysattr_values);
|
||||
set_free_free(device->sysattrs);
|
||||
set_free_free(device->tags);
|
||||
set_free_free(device->devlinks);
|
||||
|
||||
return mfree(device);
|
||||
}
|
||||
|
||||
_public_ sd_device *sd_device_unref(sd_device *device) {
|
||||
if (device && -- device->n_ref == 0) {
|
||||
sd_device_unref(device->parent);
|
||||
free(device->syspath);
|
||||
free(device->sysname);
|
||||
free(device->devtype);
|
||||
free(device->devname);
|
||||
free(device->subsystem);
|
||||
free(device->driver_subsystem);
|
||||
free(device->driver);
|
||||
free(device->id_filename);
|
||||
free(device->properties_strv);
|
||||
free(device->properties_nulstr);
|
||||
|
||||
ordered_hashmap_free_free_free(device->properties);
|
||||
ordered_hashmap_free_free_free(device->properties_db);
|
||||
hashmap_free_free_free(device->sysattr_values);
|
||||
set_free_free(device->sysattrs);
|
||||
set_free_free(device->tags);
|
||||
set_free_free(device->devlinks);
|
||||
|
||||
free(device);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_device, sd_device, device_free);
|
||||
|
||||
int device_add_property_aux(sd_device *device, const char *_key, const char *_value, bool db) {
|
||||
OrderedHashmap **properties;
|
||||
|
||||
@@ -456,7 +456,7 @@ static void free_clock_data(struct clock_data *d) {
|
||||
prioq_free(d->latest);
|
||||
}
|
||||
|
||||
static void event_free(sd_event *e) {
|
||||
static sd_event *event_free(sd_event *e) {
|
||||
sd_event_source *s;
|
||||
|
||||
assert(e);
|
||||
@@ -492,7 +492,8 @@ static void event_free(sd_event *e) {
|
||||
|
||||
hashmap_free(e->child_sources);
|
||||
set_free(e->post_sources);
|
||||
free(e);
|
||||
|
||||
return mfree(e);
|
||||
}
|
||||
|
||||
_public_ int sd_event_new(sd_event** ret) {
|
||||
@@ -553,30 +554,7 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
_public_ sd_event* sd_event_ref(sd_event *e) {
|
||||
|
||||
if (!e)
|
||||
return NULL;
|
||||
|
||||
assert(e->n_ref >= 1);
|
||||
e->n_ref++;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
_public_ sd_event* sd_event_unref(sd_event *e) {
|
||||
|
||||
if (!e)
|
||||
return NULL;
|
||||
|
||||
assert(e->n_ref >= 1);
|
||||
e->n_ref--;
|
||||
|
||||
if (e->n_ref <= 0)
|
||||
event_free(e);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_event, sd_event, event_free);
|
||||
|
||||
static bool event_pid_changed(sd_event *e) {
|
||||
assert(e);
|
||||
@@ -1926,46 +1904,31 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
_public_ sd_event_source* sd_event_source_ref(sd_event_source *s) {
|
||||
|
||||
static sd_event_source* event_source_free(sd_event_source *s) {
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
assert(s->n_ref >= 1);
|
||||
s->n_ref++;
|
||||
/* Here's a special hack: when we are called from a
|
||||
* dispatch handler we won't free the event source
|
||||
* immediately, but we will detach the fd from the
|
||||
* epoll. This way it is safe for the caller to unref
|
||||
* the event source and immediately close the fd, but
|
||||
* we still retain a valid event source object after
|
||||
* the callback. */
|
||||
|
||||
return s;
|
||||
}
|
||||
if (s->dispatching) {
|
||||
if (s->type == SOURCE_IO)
|
||||
source_io_unregister(s);
|
||||
|
||||
_public_ sd_event_source* sd_event_source_unref(sd_event_source *s) {
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
assert(s->n_ref >= 1);
|
||||
s->n_ref--;
|
||||
|
||||
if (s->n_ref <= 0) {
|
||||
/* Here's a special hack: when we are called from a
|
||||
* dispatch handler we won't free the event source
|
||||
* immediately, but we will detach the fd from the
|
||||
* epoll. This way it is safe for the caller to unref
|
||||
* the event source and immediately close the fd, but
|
||||
* we still retain a valid event source object after
|
||||
* the callback. */
|
||||
|
||||
if (s->dispatching) {
|
||||
if (s->type == SOURCE_IO)
|
||||
source_io_unregister(s);
|
||||
|
||||
source_disconnect(s);
|
||||
} else
|
||||
source_free(s);
|
||||
}
|
||||
source_disconnect(s);
|
||||
} else
|
||||
source_free(s);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_event_source, sd_event_source, event_source_free);
|
||||
|
||||
_public_ int sd_event_source_set_description(sd_event_source *s, const char *description) {
|
||||
assert_return(s, -EINVAL);
|
||||
assert_return(!event_pid_changed(s->event), -ECHILD);
|
||||
|
||||
@@ -543,7 +543,7 @@ _public_ int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid) {
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
static void resolve_free(sd_resolve *resolve) {
|
||||
static sd_resolve *resolve_free(sd_resolve *resolve) {
|
||||
PROTECT_ERRNO;
|
||||
sd_resolve_query *q;
|
||||
unsigned i;
|
||||
@@ -582,30 +582,11 @@ static void resolve_free(sd_resolve *resolve) {
|
||||
|
||||
/* Close all communication channels */
|
||||
close_many(resolve->fds, _FD_MAX);
|
||||
free(resolve);
|
||||
|
||||
return mfree(resolve);
|
||||
}
|
||||
|
||||
_public_ sd_resolve* sd_resolve_ref(sd_resolve *resolve) {
|
||||
assert_return(resolve, NULL);
|
||||
|
||||
assert(resolve->n_ref >= 1);
|
||||
resolve->n_ref++;
|
||||
|
||||
return resolve;
|
||||
}
|
||||
|
||||
_public_ sd_resolve* sd_resolve_unref(sd_resolve *resolve) {
|
||||
if (!resolve)
|
||||
return NULL;
|
||||
|
||||
assert(resolve->n_ref >= 1);
|
||||
resolve->n_ref--;
|
||||
|
||||
if (resolve->n_ref <= 0)
|
||||
resolve_free(resolve);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_resolve, sd_resolve, resolve_free);
|
||||
|
||||
_public_ int sd_resolve_get_fd(sd_resolve *resolve) {
|
||||
assert_return(resolve, -EINVAL);
|
||||
@@ -1070,15 +1051,6 @@ static int getnameinfo_done(sd_resolve_query *q) {
|
||||
return q->getnameinfo_handler(q, q->ret, q->host, q->serv, q->userdata);
|
||||
}
|
||||
|
||||
_public_ sd_resolve_query* sd_resolve_query_ref(sd_resolve_query *q) {
|
||||
assert_return(q, NULL);
|
||||
|
||||
assert(q->n_ref >= 1);
|
||||
q->n_ref++;
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
static void resolve_freeaddrinfo(struct addrinfo *ai) {
|
||||
while (ai) {
|
||||
struct addrinfo *next = ai->ai_next;
|
||||
@@ -1118,7 +1090,7 @@ static void resolve_query_disconnect(sd_resolve_query *q) {
|
||||
sd_resolve_unref(resolve);
|
||||
}
|
||||
|
||||
static void resolve_query_free(sd_resolve_query *q) {
|
||||
static sd_resolve_query *resolve_query_free(sd_resolve_query *q) {
|
||||
assert(q);
|
||||
|
||||
resolve_query_disconnect(q);
|
||||
@@ -1126,21 +1098,11 @@ static void resolve_query_free(sd_resolve_query *q) {
|
||||
resolve_freeaddrinfo(q->addrinfo);
|
||||
free(q->host);
|
||||
free(q->serv);
|
||||
free(q);
|
||||
|
||||
return mfree(q);
|
||||
}
|
||||
|
||||
_public_ sd_resolve_query* sd_resolve_query_unref(sd_resolve_query* q) {
|
||||
if (!q)
|
||||
return NULL;
|
||||
|
||||
assert(q->n_ref >= 1);
|
||||
q->n_ref--;
|
||||
|
||||
if (q->n_ref <= 0)
|
||||
resolve_query_free(q);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_resolve_query, sd_resolve_query, resolve_query_free);
|
||||
|
||||
_public_ int sd_resolve_query_is_done(sd_resolve_query *q) {
|
||||
assert_return(q, -EINVAL);
|
||||
|
||||
Reference in New Issue
Block a user