From: Daan De Meyer Date: Sun, 14 Dec 2025 15:40:20 +0000 (+0100) Subject: tree-wide: Introduce DECLARE_TRIVIAL_REF_UNREF_FUNC() and friends X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=daff8ea8bbb5374225722bd5ec534987db4f9c1c;p=thirdparty%2Fsystemd.git tree-wide: Introduce DECLARE_TRIVIAL_REF_UNREF_FUNC() and friends --- diff --git a/src/basic/cleanup-util.h b/src/basic/cleanup-util.h index dbe022295ad..4d6466e03ff 100644 --- a/src/basic/cleanup-util.h +++ b/src/basic/cleanup-util.h @@ -74,6 +74,16 @@ typedef void* (*mfree_func_t)(void *p); DEFINE_TRIVIAL_REF_FUNC(type, name); \ DEFINE_TRIVIAL_UNREF_FUNC(type, name, free_func); +#define DECLARE_TRIVIAL_REF_FUNC(type, name) \ + type* name##_ref(type *p) + +#define DECLARE_TRIVIAL_UNREF_FUNC(type, name) \ + type* name##_unref(type *p) + +#define DECLARE_TRIVIAL_REF_UNREF_FUNC(type, name) \ + DECLARE_TRIVIAL_REF_FUNC(type, name); \ + DECLARE_TRIVIAL_UNREF_FUNC(type, name) + #define DEFINE_PRIVATE_TRIVIAL_REF_UNREF_FUNC(type, name, free_func) \ DEFINE_PRIVATE_TRIVIAL_REF_FUNC(type, name); \ DEFINE_PRIVATE_TRIVIAL_UNREF_FUNC(type, name, free_func); diff --git a/src/basic/log-context.h b/src/basic/log-context.h index 009abe3bb17..ccff2eb572d 100644 --- a/src/basic/log-context.h +++ b/src/basic/log-context.h @@ -57,8 +57,7 @@ LogContext* log_context_new_iov(struct iovec *input_iovec, size_t n_input_iovec, LogContext* log_context_new_strv_consume(char **fields); LogContext* log_context_new_iov_consume(struct iovec *input_iovec, size_t n_input_iovec); -LogContext *log_context_ref(LogContext *c); -LogContext *log_context_unref(LogContext *c); +DECLARE_TRIVIAL_REF_UNREF_FUNC(LogContext, log_context); DEFINE_TRIVIAL_CLEANUP_FUNC(LogContext*, log_context_unref); diff --git a/src/core/dynamic-user.h b/src/core/dynamic-user.h index 0f923edfe91..5eda76e22c9 100644 --- a/src/core/dynamic-user.h +++ b/src/core/dynamic-user.h @@ -44,4 +44,4 @@ void dynamic_creds_close(DynamicCreds *creds); DEFINE_TRIVIAL_CLEANUP_FUNC(DynamicCreds*, dynamic_creds_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(DynamicCreds*, dynamic_creds_destroy); -DynamicUser *dynamic_user_ref(DynamicUser *user); +DECLARE_TRIVIAL_REF_FUNC(DynamicUser, dynamic_user); diff --git a/src/core/execute.h b/src/core/execute.h index 92a2c730fd9..2690f2336e3 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -569,7 +569,7 @@ void exec_status_reset(ExecStatus *s); int exec_shared_runtime_acquire(Manager *m, const ExecContext *c, const char *id, bool create, ExecSharedRuntime **ret); ExecSharedRuntime *exec_shared_runtime_destroy(ExecSharedRuntime *r); -ExecSharedRuntime *exec_shared_runtime_unref(ExecSharedRuntime *r); +DECLARE_TRIVIAL_UNREF_FUNC(ExecSharedRuntime, exec_shared_runtime); DEFINE_TRIVIAL_CLEANUP_FUNC(ExecSharedRuntime*, exec_shared_runtime_unref); int exec_shared_runtime_serialize(const Manager *m, FILE *f, FDSet *fds); diff --git a/src/home/homed-operation.h b/src/home/homed-operation.h index 9bb7aba59a2..f16f91bd5fc 100644 --- a/src/home/homed-operation.h +++ b/src/home/homed-operation.h @@ -48,8 +48,7 @@ typedef struct Operation { } Operation; Operation *operation_new(OperationType type, sd_bus_message *m); -Operation *operation_ref(Operation *operation); -Operation *operation_unref(Operation *operation); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Operation, operation); DEFINE_TRIVIAL_CLEANUP_FUNC(Operation*, operation_unref); diff --git a/src/journal-remote/journal-remote-write.h b/src/journal-remote/journal-remote-write.h index dd69a2ffcf5..f833140923b 100644 --- a/src/journal-remote/journal-remote-write.h +++ b/src/journal-remote/journal-remote-write.h @@ -20,8 +20,7 @@ typedef struct Writer { } Writer; int writer_new(RemoteServer *server, Writer **ret); -Writer* writer_ref(Writer *w); -Writer* writer_unref(Writer *w); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Writer, writer); DEFINE_TRIVIAL_CLEANUP_FUNC(Writer*, writer_unref); diff --git a/src/libsystemd/sd-journal/mmap-cache.h b/src/libsystemd/sd-journal/mmap-cache.h index 6361e52d096..3489d56e718 100644 --- a/src/libsystemd/sd-journal/mmap-cache.h +++ b/src/libsystemd/sd-journal/mmap-cache.h @@ -29,8 +29,7 @@ static inline MMapCacheCategory type_to_category(ObjectType type) { } MMapCache* mmap_cache_new(void); -MMapCache* mmap_cache_ref(MMapCache *m); -MMapCache* mmap_cache_unref(MMapCache *m); +DECLARE_TRIVIAL_REF_UNREF_FUNC(MMapCache, mmap_cache); DEFINE_TRIVIAL_CLEANUP_FUNC(MMapCache*, mmap_cache_unref); int mmap_cache_fd_get( diff --git a/src/network/netdev/netdev.h b/src/network/netdev/netdev.h index d36028e4376..7b97c59af3c 100644 --- a/src/network/netdev/netdev.h +++ b/src/network/netdev/netdev.h @@ -227,8 +227,7 @@ void netdev_drop(NetDev *netdev); void netdev_enter_failed(NetDev *netdev); int netdev_enter_ready(NetDev *netdev); -NetDev* netdev_unref(NetDev *netdev); -NetDev* netdev_ref(NetDev *netdev); +DECLARE_TRIVIAL_REF_UNREF_FUNC(NetDev, netdev); DEFINE_TRIVIAL_DESTRUCTOR(netdev_destroy_callback, NetDev, netdev_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref); diff --git a/src/network/networkd-address-generation.h b/src/network/networkd-address-generation.h index c08794f253a..5e49a84d360 100644 --- a/src/network/networkd-address-generation.h +++ b/src/network/networkd-address-generation.h @@ -3,8 +3,7 @@ #include "networkd-forward.h" -IPv6Token* ipv6_token_ref(IPv6Token *token); -IPv6Token* ipv6_token_unref(IPv6Token *token); +DECLARE_TRIVIAL_REF_UNREF_FUNC(IPv6Token, ipv6_token); int dhcp_pd_generate_addresses(Link *link, const struct in6_addr *prefix, Hashmap **ret); int ndisc_generate_addresses(Link *link, const struct in6_addr *prefix, uint8_t prefixlen, Hashmap **ret); diff --git a/src/network/networkd-address.h b/src/network/networkd-address.h index 1154aaf9477..286d35fc5d6 100644 --- a/src/network/networkd-address.h +++ b/src/network/networkd-address.h @@ -87,8 +87,7 @@ extern const struct hash_ops address_hash_ops; bool address_can_update(const Address *existing, const Address *requesting); -Address* address_ref(Address *address); -Address* address_unref(Address *address); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Address, address); int address_new(Address **ret); int address_new_static(Network *network, const char *filename, unsigned section_line, Address **ret); diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h index 51b6642bb64..e54c931e582 100644 --- a/src/network/networkd-link.h +++ b/src/network/networkd-link.h @@ -207,8 +207,7 @@ bool link_is_ready_to_configure_by_name(Manager *manager, const char *name, bool void link_ntp_settings_clear(Link *link); void link_dns_settings_clear(Link *link); -Link* link_unref(Link *link); -Link* link_ref(Link *link); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Link, link); DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref); DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref); diff --git a/src/network/networkd-neighbor.h b/src/network/networkd-neighbor.h index 088736fa5ff..04dda2477f1 100644 --- a/src/network/networkd-neighbor.h +++ b/src/network/networkd-neighbor.h @@ -19,8 +19,7 @@ typedef struct Neighbor { struct hw_addr_data ll_addr; } Neighbor; -Neighbor* neighbor_ref(Neighbor *neighbor); -Neighbor* neighbor_unref(Neighbor *neighbor); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Neighbor, neighbor); int neighbor_get(Link *link, const Neighbor *in, Neighbor **ret); int neighbor_remove(Neighbor *neighbor, Link *link); diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index f7e40915663..0efaf2b9fdc 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -416,8 +416,7 @@ typedef struct Network { char **ntp; } Network; -Network *network_ref(Network *network); -Network *network_unref(Network *network); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Network, network); DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref); int network_load(Manager *manager, OrderedHashmap **ret); diff --git a/src/network/networkd-queue.h b/src/network/networkd-queue.h index 16db5e3ba57..34187de80a0 100644 --- a/src/network/networkd-queue.h +++ b/src/network/networkd-queue.h @@ -83,8 +83,7 @@ typedef struct Request { bool waiting_reply; } Request; -Request *request_ref(Request *req); -Request *request_unref(Request *req); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Request, request); DEFINE_TRIVIAL_CLEANUP_FUNC(Request*, request_unref); void request_detach(Request *req); diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index 8470c5651cb..d22bb5ddb9d 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -74,8 +74,7 @@ void log_route_debug(const Route *route, const char *str, Manager *manager); extern const struct hash_ops route_hash_ops; extern const struct hash_ops route_hash_ops_unref; -Route* route_ref(Route *route); -Route* route_unref(Route *route); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Route, route); DEFINE_SECTION_CLEANUP_FUNCTIONS(Route, route_unref); void route_detach(Route *route); diff --git a/src/network/networkd-routing-policy-rule.h b/src/network/networkd-routing-policy-rule.h index 378455f0a43..1655273ed95 100644 --- a/src/network/networkd-routing-policy-rule.h +++ b/src/network/networkd-routing-policy-rule.h @@ -49,8 +49,7 @@ typedef struct RoutingPolicyRule { int fr_act_type_from_string(const char *s) _pure_; const char* fr_act_type_to_string(int t) _const_; -RoutingPolicyRule* routing_policy_rule_ref(RoutingPolicyRule *rule); -RoutingPolicyRule* routing_policy_rule_unref(RoutingPolicyRule *rule); +DECLARE_TRIVIAL_REF_UNREF_FUNC(RoutingPolicyRule, routing_policy_rule); void network_drop_invalid_routing_policy_rules(Network *network); diff --git a/src/network/tc/qdisc.h b/src/network/tc/qdisc.h index 207d59f47b1..49d52f4265f 100644 --- a/src/network/tc/qdisc.h +++ b/src/network/tc/qdisc.h @@ -74,8 +74,7 @@ extern const QDiscVTable * const qdisc_vtable[_QDISC_KIND_MAX]; DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(QDisc, qdisc); -QDisc* qdisc_ref(QDisc *qdisc); -QDisc* qdisc_unref(QDisc *qdisc); +DECLARE_TRIVIAL_REF_UNREF_FUNC(QDisc, qdisc); int qdisc_new_static(QDiscKind kind, Network *network, const char *filename, unsigned section_line, QDisc **ret); void qdisc_mark_recursive(QDisc *qdisc); diff --git a/src/network/tc/tclass.h b/src/network/tc/tclass.h index 2bba38be8d5..02ce213f6bf 100644 --- a/src/network/tc/tclass.h +++ b/src/network/tc/tclass.h @@ -53,8 +53,7 @@ extern const TClassVTable * const tclass_vtable[_TCLASS_KIND_MAX]; DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(TClass, tclass); -TClass* tclass_ref(TClass *tclass); -TClass* tclass_unref(TClass *tclass); +DECLARE_TRIVIAL_REF_UNREF_FUNC(TClass, tclass); int tclass_new_static(TClassKind kind, Network *network, const char *filename, unsigned section_line, TClass **ret); void tclass_mark_recursive(TClass *tclass); diff --git a/src/resolve/resolved-dns-browse-services.h b/src/resolve/resolved-dns-browse-services.h index 87e68b7a216..243d23cb2db 100644 --- a/src/resolve/resolved-dns-browse-services.h +++ b/src/resolve/resolved-dns-browse-services.h @@ -55,11 +55,8 @@ DnsServiceBrowser *dns_service_browser_free(DnsServiceBrowser *sb); void dns_remove_service(DnsServiceBrowser *sb, DnssdDiscoveredService *service); DnssdDiscoveredService *dns_service_free(DnssdDiscoveredService *service); -DnsServiceBrowser *dns_service_browser_ref(DnsServiceBrowser *sb); -DnsServiceBrowser *dns_service_browser_unref(DnsServiceBrowser *sb); - -DnssdDiscoveredService *dnssd_discovered_service_ref(DnssdDiscoveredService *service); -DnssdDiscoveredService *dnssd_discovered_service_unref(DnssdDiscoveredService *service); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsServiceBrowser, dns_service_browser); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnssdDiscoveredService, dnssd_discovered_service); void dns_browse_services_purge(Manager *m, int family); void dns_browse_services_restart(Manager *m); diff --git a/src/resolve/resolved-dns-query.h b/src/resolve/resolved-dns-query.h index f0c99ae94b9..925b4dc9b9d 100644 --- a/src/resolve/resolved-dns-query.h +++ b/src/resolve/resolved-dns-query.h @@ -130,8 +130,7 @@ enum { DNS_QUERY_CNAME, }; -DnsQueryCandidate* dns_query_candidate_ref(DnsQueryCandidate*); -DnsQueryCandidate* dns_query_candidate_unref(DnsQueryCandidate*); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsQueryCandidate, dns_query_candidate); DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQueryCandidate*, dns_query_candidate_unref); void dns_query_candidate_notify(DnsQueryCandidate *c); diff --git a/src/resolve/resolved-dns-search-domain.h b/src/resolve/resolved-dns-search-domain.h index 503f6bf3e6c..0fbd512f4b6 100644 --- a/src/resolve/resolved-dns-search-domain.h +++ b/src/resolve/resolved-dns-search-domain.h @@ -36,8 +36,7 @@ int dns_search_domain_new( DnsDelegate *delegate, const char *name); -DnsSearchDomain* dns_search_domain_ref(DnsSearchDomain *d); -DnsSearchDomain* dns_search_domain_unref(DnsSearchDomain *d); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsSearchDomain, dns_search_domain); void dns_search_domain_unlink(DnsSearchDomain *d); void dns_search_domain_move_back_and_unmark(DnsSearchDomain *d); diff --git a/src/resolve/resolved-dns-server.h b/src/resolve/resolved-dns-server.h index 403902da832..0752f228a9e 100644 --- a/src/resolve/resolved-dns-server.h +++ b/src/resolve/resolved-dns-server.h @@ -114,8 +114,7 @@ int dns_server_new( const char *server_name, ResolveConfigSource config_source); -DnsServer* dns_server_ref(DnsServer *s); -DnsServer* dns_server_unref(DnsServer *s); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsServer, dns_server); void dns_server_unlink(DnsServer *s); void dns_server_move_back_and_unmark(DnsServer *s); diff --git a/src/resolve/resolved-dns-stream.h b/src/resolve/resolved-dns-stream.h index 60cae3f51f1..f7174433812 100644 --- a/src/resolve/resolved-dns-stream.h +++ b/src/resolve/resolved-dns-stream.h @@ -102,8 +102,7 @@ int dns_stream_new( #if ENABLE_DNS_OVER_TLS int dns_stream_connect_tls(DnsStream *s, void *tls_session); #endif -DnsStream *dns_stream_unref(DnsStream *s); -DnsStream *dns_stream_ref(DnsStream *s); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsStream, dns_stream); DEFINE_TRIVIAL_CLEANUP_FUNC(DnsStream*, dns_stream_unref); diff --git a/src/shared/discover-image.h b/src/shared/discover-image.h index 881a59fdc23..30c399dea6f 100644 --- a/src/shared/discover-image.h +++ b/src/shared/discover-image.h @@ -46,9 +46,7 @@ typedef struct Image { void *userdata; } Image; -Image* image_unref(Image *i); -Image* image_ref(Image *i); - +DECLARE_TRIVIAL_REF_UNREF_FUNC(Image, image); DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref); int image_find(RuntimeScope scope, ImageClass class, const char *name, const char *root, Image **ret); diff --git a/src/shared/dns-answer.h b/src/shared/dns-answer.h index 7b12e9be526..191da345673 100644 --- a/src/shared/dns-answer.h +++ b/src/shared/dns-answer.h @@ -40,8 +40,7 @@ typedef struct DnsAnswer { } DnsAnswer; DnsAnswer *dns_answer_new(size_t n); -DnsAnswer *dns_answer_ref(DnsAnswer *a); -DnsAnswer *dns_answer_unref(DnsAnswer *a); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsAnswer, dns_answer); #define DNS_ANSWER_REPLACE(a, b) \ do { \ diff --git a/src/shared/dns-question.h b/src/shared/dns-question.h index 39650102787..4b0fc68fd64 100644 --- a/src/shared/dns-question.h +++ b/src/shared/dns-question.h @@ -23,8 +23,7 @@ typedef struct DnsQuestion { } DnsQuestion; DnsQuestion *dns_question_new(size_t n); -DnsQuestion *dns_question_ref(DnsQuestion *q); -DnsQuestion *dns_question_unref(DnsQuestion *q); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsQuestion, dns_question); int dns_question_new_address(DnsQuestion **ret, int family, const char *name, bool convert_idna); int dns_question_new_reverse(DnsQuestion **ret, int family, const union in_addr_union *a); diff --git a/src/shared/dns-rr.h b/src/shared/dns-rr.h index 56c30cf880e..4f3686878b3 100644 --- a/src/shared/dns-rr.h +++ b/src/shared/dns-rr.h @@ -334,8 +334,7 @@ DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char * DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname); int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name); DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name); -DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key); -DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsResourceKey, dns_resource_key); #define DNS_RESOURCE_KEY_REPLACE(a, b) \ do { \ @@ -374,8 +373,7 @@ bool dns_resource_key_reduce(DnsResourceKey **a, DnsResourceKey **b); DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key); DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name); -DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr); -DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr); +DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsResourceRecord, dns_resource_record); #define DNS_RR_REPLACE(a, b) \ do { \ diff --git a/src/shared/group-record.h b/src/shared/group-record.h index ba7ee01da6f..04f3e079976 100644 --- a/src/shared/group-record.h +++ b/src/shared/group-record.h @@ -34,8 +34,7 @@ typedef struct GroupRecord { } GroupRecord; GroupRecord* group_record_new(void); -GroupRecord* group_record_ref(GroupRecord *g); -GroupRecord* group_record_unref(GroupRecord *g); +DECLARE_TRIVIAL_REF_UNREF_FUNC(GroupRecord, group_record); DEFINE_TRIVIAL_CLEANUP_FUNC(GroupRecord*, group_record_unref); diff --git a/src/shared/loop-util.h b/src/shared/loop-util.h index d015c997511..ed02a69d878 100644 --- a/src/shared/loop-util.h +++ b/src/shared/loop-util.h @@ -36,8 +36,7 @@ int loop_device_open(sd_device *dev, int open_flags, int lock_op, LoopDevice **r int loop_device_open_from_fd(int fd, int open_flags, int lock_op, LoopDevice **ret); int loop_device_open_from_path(const char *path, int open_flags, int lock_op, LoopDevice **ret); -LoopDevice* loop_device_ref(LoopDevice *d); -LoopDevice* loop_device_unref(LoopDevice *d); +DECLARE_TRIVIAL_REF_UNREF_FUNC(LoopDevice, loop_device); DEFINE_TRIVIAL_CLEANUP_FUNC(LoopDevice*, loop_device_unref); void loop_device_relinquish(LoopDevice *d); diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h index b46bec03363..4600512db86 100644 --- a/src/shared/tpm2-util.h +++ b/src/shared/tpm2-util.h @@ -66,8 +66,7 @@ typedef struct Tpm2Context { int tpm2_context_new(const char *device, Tpm2Context **ret_context); int tpm2_context_new_or_warn(const char *device, Tpm2Context **ret_context); -Tpm2Context *tpm2_context_ref(Tpm2Context *context); -Tpm2Context *tpm2_context_unref(Tpm2Context *context); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Tpm2Context, tpm2_context); DEFINE_TRIVIAL_CLEANUP_FUNC(Tpm2Context*, tpm2_context_unref); typedef struct Tpm2Handle { diff --git a/src/shared/user-record.h b/src/shared/user-record.h index 34d08005767..b98b59f3ff9 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -418,8 +418,7 @@ typedef struct UserRecord { } UserRecord; UserRecord* user_record_new(void); -UserRecord* user_record_ref(UserRecord *h); -UserRecord* user_record_unref(UserRecord *h); +DECLARE_TRIVIAL_REF_UNREF_FUNC(UserRecord, user_record); DEFINE_TRIVIAL_CLEANUP_FUNC(UserRecord*, user_record_unref); diff --git a/src/systemd/_sd-common.h b/src/systemd/_sd-common.h index 36410c9e346..f9c9a2627d5 100644 --- a/src/systemd/_sd-common.h +++ b/src/systemd/_sd-common.h @@ -106,6 +106,16 @@ typedef void (*_sd_destroy_t)(void *userdata); } \ struct _sd_useless_struct_to_allow_trailing_semicolon_ +#define _SD_DECLARE_TRIVIAL_REF_FUNC(name) \ + name* name##_ref(name *p) + +#define _SD_DECLARE_TRIVIAL_UNREF_FUNC(name) \ + name* name##_unref(name *p) + +#define _SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(name) \ + _SD_DECLARE_TRIVIAL_REF_FUNC(name); \ + _SD_DECLARE_TRIVIAL_UNREF_FUNC(name) + /* The following macro should be used in all public enums, to force 64-bit wideness on them, so that we can * freely extend them later on, without breaking compatibility. */ #define _SD_ENUM_FORCE_S64(id) \ diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index b939ef1d0d7..30de2a185f7 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -93,8 +93,7 @@ int sd_bus_start(sd_bus *bus); int sd_bus_try_close(sd_bus *bus) _sd_deprecated_; void sd_bus_close(sd_bus *bus); -sd_bus* sd_bus_ref(sd_bus *bus); -sd_bus* sd_bus_unref(sd_bus *bus); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_bus); sd_bus* sd_bus_close_unref(sd_bus *bus); sd_bus* sd_bus_flush_close_unref(sd_bus *bus); @@ -151,8 +150,7 @@ int sd_bus_pending_method_calls(sd_bus *bus); /* Slot object */ -sd_bus_slot* sd_bus_slot_ref(sd_bus_slot *slot); -sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_bus_slot); sd_bus* sd_bus_slot_get_bus(sd_bus_slot *slot); void* sd_bus_slot_get_userdata(sd_bus_slot *slot); @@ -180,8 +178,7 @@ int sd_bus_message_new_method_errorf(sd_bus_message *call, sd_bus_message **ret, int sd_bus_message_new_method_errno(sd_bus_message *call, sd_bus_message **ret, int error, const sd_bus_error *e); int sd_bus_message_new_method_errnof(sd_bus_message *call, sd_bus_message **ret, int error, const char *format, ...) _sd_printf_(4, 5); -sd_bus_message* sd_bus_message_ref(sd_bus_message *m); -sd_bus_message* sd_bus_message_unref(sd_bus_message *m); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_bus_message); int sd_bus_message_seal(sd_bus_message *m, uint64_t cookie, uint64_t timeout_usec); @@ -316,8 +313,7 @@ int sd_bus_match_signal_async(sd_bus *bus, sd_bus_slot **ret, const char *sender int sd_bus_creds_new_from_pid(sd_bus_creds **ret, pid_t pid, uint64_t creds_mask); int sd_bus_creds_new_from_pidfd(sd_bus_creds **ret, int pidfd, uint64_t creds_mask); -sd_bus_creds* sd_bus_creds_ref(sd_bus_creds *c); -sd_bus_creds* sd_bus_creds_unref(sd_bus_creds *c); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_bus_creds); uint64_t sd_bus_creds_get_mask(const sd_bus_creds *c); uint64_t sd_bus_creds_get_augmented_mask(const sd_bus_creds *c); @@ -416,8 +412,7 @@ int sd_bus_path_decode_many(const char *path, const char *path_template, ...); /* Tracking peers */ int sd_bus_track_new(sd_bus *bus, sd_bus_track **ret, sd_bus_track_handler_t handler, void *userdata); -sd_bus_track* sd_bus_track_ref(sd_bus_track *track); -sd_bus_track* sd_bus_track_unref(sd_bus_track *track); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_bus_track); sd_bus* sd_bus_track_get_bus(sd_bus_track *track); void* sd_bus_track_get_userdata(sd_bus_track *track); diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h index 3a40c209927..8eb784b1cf8 100644 --- a/src/systemd/sd-device.h +++ b/src/systemd/sd-device.h @@ -50,8 +50,7 @@ typedef int (*sd_device_monitor_handler_t)(sd_device_monitor *m, sd_device *devi /* device */ -sd_device* sd_device_ref(sd_device *device); -sd_device* sd_device_unref(sd_device *device); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_device); int sd_device_new_from_syspath(sd_device **ret, const char *syspath); int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum); @@ -117,8 +116,7 @@ int sd_device_open(sd_device *device, int flags); /* device enumerator */ int sd_device_enumerator_new(sd_device_enumerator **ret); -sd_device_enumerator* sd_device_enumerator_ref(sd_device_enumerator *enumerator); -sd_device_enumerator* sd_device_enumerator_unref(sd_device_enumerator *enumerator); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_device_enumerator); sd_device* sd_device_enumerator_get_device_first(sd_device_enumerator *enumerator); sd_device* sd_device_enumerator_get_device_next(sd_device_enumerator *enumerator); @@ -139,8 +137,7 @@ int sd_device_enumerator_add_all_parents(sd_device_enumerator *enumerator); /* device monitor */ int sd_device_monitor_new(sd_device_monitor **ret); -sd_device_monitor* sd_device_monitor_ref(sd_device_monitor *m); -sd_device_monitor* sd_device_monitor_unref(sd_device_monitor *m); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_device_monitor); int sd_device_monitor_get_fd(sd_device_monitor *m); int sd_device_monitor_get_events(sd_device_monitor *m); diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h index 79dac0de6bf..9bcc00e145e 100644 --- a/src/systemd/sd-dhcp-client.h +++ b/src/systemd/sd-dhcp-client.h @@ -161,8 +161,7 @@ int sd_dhcp_client_send_renew(sd_dhcp_client *client); int sd_dhcp_client_set_ipv6_connectivity(sd_dhcp_client *client, int have); int sd_dhcp_client_interrupt_ipv6_only_mode(sd_dhcp_client *client); -sd_dhcp_client *sd_dhcp_client_ref(sd_dhcp_client *client); -sd_dhcp_client *sd_dhcp_client_unref(sd_dhcp_client *client); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp_client); /* NOTE: anonymize parameter is used to initialize PRL memory with different * options when using RFC7844 Anonymity Profiles */ diff --git a/src/systemd/sd-dhcp-lease.h b/src/systemd/sd-dhcp-lease.h index 8554e8dceac..3aa67c3fa54 100644 --- a/src/systemd/sd-dhcp-lease.h +++ b/src/systemd/sd-dhcp-lease.h @@ -30,8 +30,7 @@ typedef struct sd_dhcp_lease sd_dhcp_lease; typedef struct sd_dhcp_route sd_dhcp_route; typedef struct sd_dns_resolver sd_dns_resolver; -sd_dhcp_lease *sd_dhcp_lease_ref(sd_dhcp_lease *lease); -sd_dhcp_lease *sd_dhcp_lease_unref(sd_dhcp_lease *lease); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp_lease); __extension__ typedef enum _SD_ENUM_TYPE_S64(sd_dhcp_lease_server_type_t) { SD_DHCP_LEASE_DNS, diff --git a/src/systemd/sd-dhcp-option.h b/src/systemd/sd-dhcp-option.h index bfb5be8b2bd..edc671b1b57 100644 --- a/src/systemd/sd-dhcp-option.h +++ b/src/systemd/sd-dhcp-option.h @@ -25,8 +25,7 @@ _SD_BEGIN_DECLARATIONS; typedef struct sd_dhcp_option sd_dhcp_option; int sd_dhcp_option_new(uint8_t option, const void *data, size_t length, sd_dhcp_option **ret); -sd_dhcp_option *sd_dhcp_option_ref(sd_dhcp_option *ra); -sd_dhcp_option *sd_dhcp_option_unref(sd_dhcp_option *ra); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp_option); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_option, sd_dhcp_option_unref); diff --git a/src/systemd/sd-dhcp-server-lease.h b/src/systemd/sd-dhcp-server-lease.h index b5c9ba70d35..cb3faaa8165 100644 --- a/src/systemd/sd-dhcp-server-lease.h +++ b/src/systemd/sd-dhcp-server-lease.h @@ -23,8 +23,7 @@ _SD_BEGIN_DECLARATIONS; typedef struct sd_dhcp_server_lease sd_dhcp_server_lease; -sd_dhcp_server_lease *sd_dhcp_server_lease_ref(sd_dhcp_server_lease *lease); -sd_dhcp_server_lease *sd_dhcp_server_lease_unref(sd_dhcp_server_lease *lease); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp_server_lease); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_server_lease, sd_dhcp_server_lease_unref); diff --git a/src/systemd/sd-dhcp-server.h b/src/systemd/sd-dhcp-server.h index f8621d9f3ae..ef13776201a 100644 --- a/src/systemd/sd-dhcp-server.h +++ b/src/systemd/sd-dhcp-server.h @@ -38,8 +38,7 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex); int sd_dhcp_server_set_ifname(sd_dhcp_server *server, const char *ifname); int sd_dhcp_server_get_ifname(sd_dhcp_server *server, const char **ret); -sd_dhcp_server *sd_dhcp_server_ref(sd_dhcp_server *server); -sd_dhcp_server *sd_dhcp_server_unref(sd_dhcp_server *server); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp_server); int sd_dhcp_server_attach_event(sd_dhcp_server *server, sd_event *event, int64_t priority); int sd_dhcp_server_detach_event(sd_dhcp_server *server); diff --git a/src/systemd/sd-dhcp6-client.h b/src/systemd/sd-dhcp6-client.h index 546a68dd19d..e4b28b40e62 100644 --- a/src/systemd/sd-dhcp6-client.h +++ b/src/systemd/sd-dhcp6-client.h @@ -130,8 +130,7 @@ int sd_dhcp6_client_attach_event( int sd_dhcp6_client_detach_event(sd_dhcp6_client *client); sd_event *sd_dhcp6_client_get_event(sd_dhcp6_client *client); int sd_dhcp6_client_attach_device(sd_dhcp6_client *client, sd_device *dev); -sd_dhcp6_client *sd_dhcp6_client_ref(sd_dhcp6_client *client); -sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp6_client); int sd_dhcp6_client_new(sd_dhcp6_client **ret); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp6_client, sd_dhcp6_client_unref); diff --git a/src/systemd/sd-dhcp6-lease.h b/src/systemd/sd-dhcp6-lease.h index 02852fc5759..50e8f464897 100644 --- a/src/systemd/sd-dhcp6-lease.h +++ b/src/systemd/sd-dhcp6-lease.h @@ -83,8 +83,7 @@ int sd_dhcp6_lease_get_fqdn(sd_dhcp6_lease *lease, const char **ret); int sd_dhcp6_lease_get_captive_portal(sd_dhcp6_lease *lease, const char **ret); int sd_dhcp6_lease_get_vendor_options(sd_dhcp6_lease *lease, sd_dhcp6_option ***ret); -sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease); -sd_dhcp6_lease *sd_dhcp6_lease_unref(sd_dhcp6_lease *lease); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp6_lease); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp6_lease, sd_dhcp6_lease_unref); diff --git a/src/systemd/sd-dhcp6-option.h b/src/systemd/sd-dhcp6-option.h index b86441d93f7..94fb1972bb2 100644 --- a/src/systemd/sd-dhcp6-option.h +++ b/src/systemd/sd-dhcp6-option.h @@ -25,8 +25,7 @@ _SD_BEGIN_DECLARATIONS; typedef struct sd_dhcp6_option sd_dhcp6_option; int sd_dhcp6_option_new(uint16_t option, const void *data, size_t length, uint32_t enterprise_identifier, sd_dhcp6_option **ret); -sd_dhcp6_option *sd_dhcp6_option_ref(sd_dhcp6_option *ra); -sd_dhcp6_option *sd_dhcp6_option_unref(sd_dhcp6_option *ra); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp6_option); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp6_option, sd_dhcp6_option_unref); diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h index 57688058e77..f5c79acdfda 100644 --- a/src/systemd/sd-event.h +++ b/src/systemd/sd-event.h @@ -83,8 +83,7 @@ typedef _sd_destroy_t sd_event_destroy_t; int sd_event_default(sd_event **ret); int sd_event_new(sd_event **ret); -sd_event* sd_event_ref(sd_event *e); -sd_event* sd_event_unref(sd_event *e); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_event); int sd_event_add_io(sd_event *e, sd_event_source **ret, int fd, uint32_t events, sd_event_io_handler_t callback, void *userdata); int sd_event_add_time(sd_event *e, sd_event_source **ret, clockid_t clock, uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, void *userdata); @@ -119,8 +118,7 @@ int sd_event_set_signal_exit(sd_event *e, int b); int sd_event_set_exit_on_idle(sd_event *e, int b); int sd_event_get_exit_on_idle(sd_event *e); -sd_event_source* sd_event_source_ref(sd_event_source *s); -sd_event_source* sd_event_source_unref(sd_event_source *s); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_event_source); sd_event_source* sd_event_source_disable_unref(sd_event_source *s); sd_event* sd_event_source_get_event(sd_event_source *s); diff --git a/src/systemd/sd-hwdb.h b/src/systemd/sd-hwdb.h index ff880f15db4..4504c5b5b1d 100644 --- a/src/systemd/sd-hwdb.h +++ b/src/systemd/sd-hwdb.h @@ -23,8 +23,7 @@ _SD_BEGIN_DECLARATIONS; typedef struct sd_hwdb sd_hwdb; -sd_hwdb *sd_hwdb_ref(sd_hwdb *hwdb); -sd_hwdb *sd_hwdb_unref(sd_hwdb *hwdb); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_hwdb); int sd_hwdb_new(sd_hwdb **ret); int sd_hwdb_new_from_path(const char *path, sd_hwdb **ret); diff --git a/src/systemd/sd-ipv4acd.h b/src/systemd/sd-ipv4acd.h index a7b7083ec71..c77064cfef0 100644 --- a/src/systemd/sd-ipv4acd.h +++ b/src/systemd/sd-ipv4acd.h @@ -55,8 +55,7 @@ int sd_ipv4acd_is_running(sd_ipv4acd *acd); int sd_ipv4acd_is_bound(sd_ipv4acd *acd); __extension__ int sd_ipv4acd_start(sd_ipv4acd *acd, bool reset_conflicts); int sd_ipv4acd_stop(sd_ipv4acd *acd); -sd_ipv4acd *sd_ipv4acd_ref(sd_ipv4acd *acd); -sd_ipv4acd *sd_ipv4acd_unref(sd_ipv4acd *acd); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_ipv4acd); int sd_ipv4acd_new(sd_ipv4acd **ret); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ipv4acd, sd_ipv4acd_unref); diff --git a/src/systemd/sd-ipv4ll.h b/src/systemd/sd-ipv4ll.h index 9462f1779e1..8b1cc48cdb4 100644 --- a/src/systemd/sd-ipv4ll.h +++ b/src/systemd/sd-ipv4ll.h @@ -55,8 +55,7 @@ int sd_ipv4ll_is_running(sd_ipv4ll *ll); int sd_ipv4ll_restart(sd_ipv4ll *ll); int sd_ipv4ll_start(sd_ipv4ll *ll); int sd_ipv4ll_stop(sd_ipv4ll *ll); -sd_ipv4ll *sd_ipv4ll_ref(sd_ipv4ll *ll); -sd_ipv4ll *sd_ipv4ll_unref(sd_ipv4ll *ll); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_ipv4ll); int sd_ipv4ll_new(sd_ipv4ll **ret); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ipv4ll, sd_ipv4ll_unref); diff --git a/src/systemd/sd-lldp-rx.h b/src/systemd/sd-lldp-rx.h index 4772d390c60..99cbd0cd05f 100644 --- a/src/systemd/sd-lldp-rx.h +++ b/src/systemd/sd-lldp-rx.h @@ -41,8 +41,7 @@ __extension__ typedef enum _SD_ENUM_TYPE_S64(sd_lldp_rx_event_t) { typedef void (*sd_lldp_rx_callback_t)(sd_lldp_rx *lldp_rx, sd_lldp_rx_event_t event, sd_lldp_neighbor *n, void *userdata); int sd_lldp_rx_new(sd_lldp_rx **ret); -sd_lldp_rx *sd_lldp_rx_ref(sd_lldp_rx *lldp_rx); -sd_lldp_rx *sd_lldp_rx_unref(sd_lldp_rx *lldp_rx); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_lldp_rx); int sd_lldp_rx_start(sd_lldp_rx *lldp_rx); int sd_lldp_rx_stop(sd_lldp_rx *lldp_rx); @@ -64,8 +63,7 @@ int sd_lldp_rx_set_filter_address(sd_lldp_rx *lldp_rx, const struct ether_addr * int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret); -sd_lldp_neighbor *sd_lldp_neighbor_ref(sd_lldp_neighbor *n); -sd_lldp_neighbor *sd_lldp_neighbor_unref(sd_lldp_neighbor *n); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_lldp_neighbor); /* Access to LLDP frame metadata */ int sd_lldp_neighbor_get_source_address(sd_lldp_neighbor *n, struct ether_addr* address); diff --git a/src/systemd/sd-lldp-tx.h b/src/systemd/sd-lldp-tx.h index 3a9ea9d7ba1..b2e16599d6c 100644 --- a/src/systemd/sd-lldp-tx.h +++ b/src/systemd/sd-lldp-tx.h @@ -38,8 +38,7 @@ __extension__ typedef enum _SD_ENUM_TYPE_S64(sd_lldp_multicast_mode_t) { } sd_lldp_multicast_mode_t; int sd_lldp_tx_new(sd_lldp_tx **ret); -sd_lldp_tx *sd_lldp_tx_ref(sd_lldp_tx *lldp_tx); -sd_lldp_tx *sd_lldp_tx_unref(sd_lldp_tx *lldp_tx); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_lldp_tx); int sd_lldp_tx_start(sd_lldp_tx *lldp_tx); int sd_lldp_tx_stop(sd_lldp_tx *lldp_tx); diff --git a/src/systemd/sd-ndisc-neighbor.h b/src/systemd/sd-ndisc-neighbor.h index 750f048b870..6dec0a9ff66 100644 --- a/src/systemd/sd-ndisc-neighbor.h +++ b/src/systemd/sd-ndisc-neighbor.h @@ -26,8 +26,7 @@ struct ether_addr; typedef struct sd_ndisc_neighbor sd_ndisc_neighbor; -sd_ndisc_neighbor *sd_ndisc_neighbor_ref(sd_ndisc_neighbor *na); -sd_ndisc_neighbor *sd_ndisc_neighbor_unref(sd_ndisc_neighbor *na); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_ndisc_neighbor); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc_neighbor, sd_ndisc_neighbor_unref); int sd_ndisc_neighbor_get_sender_address(sd_ndisc_neighbor *na, struct in6_addr *ret); diff --git a/src/systemd/sd-ndisc-redirect.h b/src/systemd/sd-ndisc-redirect.h index 444ca8bcb91..41702ac3dcf 100644 --- a/src/systemd/sd-ndisc-redirect.h +++ b/src/systemd/sd-ndisc-redirect.h @@ -27,8 +27,7 @@ struct ip6_hdr; typedef struct sd_ndisc_redirect sd_ndisc_redirect; -sd_ndisc_redirect* sd_ndisc_redirect_ref(sd_ndisc_redirect *rd); -sd_ndisc_redirect* sd_ndisc_redirect_unref(sd_ndisc_redirect *rd); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_ndisc_redirect); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc_redirect, sd_ndisc_redirect_unref); int sd_ndisc_redirect_set_sender_address(sd_ndisc_redirect *rd, const struct in6_addr *addr); diff --git a/src/systemd/sd-ndisc-router-solicit.h b/src/systemd/sd-ndisc-router-solicit.h index 819f3b874ef..9836349d360 100644 --- a/src/systemd/sd-ndisc-router-solicit.h +++ b/src/systemd/sd-ndisc-router-solicit.h @@ -26,8 +26,7 @@ _SD_BEGIN_DECLARATIONS; typedef struct sd_ndisc_router_solicit sd_ndisc_router_solicit; -sd_ndisc_router_solicit *sd_ndisc_router_solicit_ref(sd_ndisc_router_solicit *rs); -sd_ndisc_router_solicit *sd_ndisc_router_solicit_unref(sd_ndisc_router_solicit *rs); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_ndisc_router_solicit); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc_router_solicit, sd_ndisc_router_solicit_unref); int sd_ndisc_router_solicit_get_sender_address(sd_ndisc_router_solicit *rs, struct in6_addr *ret); diff --git a/src/systemd/sd-ndisc-router.h b/src/systemd/sd-ndisc-router.h index 823f3aede8f..af581ac057c 100644 --- a/src/systemd/sd-ndisc-router.h +++ b/src/systemd/sd-ndisc-router.h @@ -27,8 +27,7 @@ struct in6_addr; typedef struct sd_ndisc_router sd_ndisc_router; typedef struct sd_dns_resolver sd_dns_resolver; -sd_ndisc_router *sd_ndisc_router_ref(sd_ndisc_router *rt); -sd_ndisc_router *sd_ndisc_router_unref(sd_ndisc_router *rt); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_ndisc_router); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc_router, sd_ndisc_router_unref); int sd_ndisc_router_set_sender_address(sd_ndisc_router *rt, const struct in6_addr *addr); diff --git a/src/systemd/sd-ndisc.h b/src/systemd/sd-ndisc.h index 1b2b2204c03..1b815651e42 100644 --- a/src/systemd/sd-ndisc.h +++ b/src/systemd/sd-ndisc.h @@ -46,8 +46,7 @@ __extension__ typedef enum _SD_ENUM_TYPE_S64(sd_ndisc_event_t) { typedef void (*sd_ndisc_callback_t)(sd_ndisc *nd, sd_ndisc_event_t event, void *message, void *userdata); int sd_ndisc_new(sd_ndisc **ret); -sd_ndisc *sd_ndisc_ref(sd_ndisc *nd); -sd_ndisc *sd_ndisc_unref(sd_ndisc *nd); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_ndisc); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc, sd_ndisc_unref); int sd_ndisc_start(sd_ndisc *nd); diff --git a/src/systemd/sd-netlink.h b/src/systemd/sd-netlink.h index 10705d3fe21..6bab94363c2 100644 --- a/src/systemd/sd-netlink.h +++ b/src/systemd/sd-netlink.h @@ -46,8 +46,7 @@ int sd_netlink_open(sd_netlink **ret); int sd_netlink_open_fd(sd_netlink **ret, int fd); int sd_netlink_increase_rxbuf(sd_netlink *nl, size_t size); -sd_netlink* sd_netlink_ref(sd_netlink *nl); -sd_netlink* sd_netlink_unref(sd_netlink *nl); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_netlink); int sd_netlink_send(sd_netlink *nl, sd_netlink_message *message, uint32_t *ret_serial); int sd_netlink_call_async(sd_netlink *nl, sd_netlink_slot **ret_slot, sd_netlink_message *message, @@ -129,8 +128,7 @@ int sd_netlink_message_rewind(sd_netlink_message *m, sd_netlink *nl); sd_netlink_message* sd_netlink_message_next(sd_netlink_message *m); -sd_netlink_message* sd_netlink_message_ref(sd_netlink_message *m); -sd_netlink_message* sd_netlink_message_unref(sd_netlink_message *m); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_netlink_message); int sd_netlink_message_set_request_dump(sd_netlink_message *m, int dump); int sd_netlink_message_is_error(sd_netlink_message *m); @@ -242,8 +240,7 @@ int sd_genl_add_match(sd_netlink *nl, sd_netlink_slot **ret_slot, const char *fa void *userdata, const char *description); /* slot */ -sd_netlink_slot *sd_netlink_slot_ref(sd_netlink_slot *slot); -sd_netlink_slot *sd_netlink_slot_unref(sd_netlink_slot *slot); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_netlink_slot); sd_netlink* sd_netlink_slot_get_netlink(sd_netlink_slot *slot); void* sd_netlink_slot_get_userdata(sd_netlink_slot *slot); diff --git a/src/systemd/sd-radv.h b/src/systemd/sd-radv.h index 7b0d96e8c22..9a968dfd3f8 100644 --- a/src/systemd/sd-radv.h +++ b/src/systemd/sd-radv.h @@ -30,8 +30,7 @@ typedef struct sd_event sd_event; typedef struct sd_radv sd_radv; int sd_radv_new(sd_radv **ret); -sd_radv *sd_radv_ref(sd_radv *ra); -sd_radv *sd_radv_unref(sd_radv *ra); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_radv); int sd_radv_attach_event(sd_radv *ra, sd_event *event, int64_t priority); int sd_radv_detach_event(sd_radv *ra); diff --git a/src/systemd/sd-resolve.h b/src/systemd/sd-resolve.h index 9e549050ba2..32080398efc 100644 --- a/src/systemd/sd-resolve.h +++ b/src/systemd/sd-resolve.h @@ -56,8 +56,7 @@ int sd_resolve_new(sd_resolve **ret); /* Free a sd-resolve session. This destroys all attached * sd_resolve_query objects automatically. */ -sd_resolve* sd_resolve_unref(sd_resolve *resolve); -sd_resolve* sd_resolve_ref(sd_resolve *resolve); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_resolve); /* Return the UNIX file descriptor to poll() for events on. Use this * function to integrate sd-resolve with your custom main loop. */ @@ -100,8 +99,7 @@ int sd_resolve_getaddrinfo(sd_resolve *resolve, sd_resolve_query **ret, const ch * if you want to query the hostname (resp. the service name). */ int sd_resolve_getnameinfo(sd_resolve *resolve, sd_resolve_query **ret, const struct sockaddr *sa, socklen_t salen, int flags, uint64_t get, sd_resolve_getnameinfo_handler_t callback, void *userdata); -sd_resolve_query *sd_resolve_query_ref(sd_resolve_query *q); -sd_resolve_query *sd_resolve_query_unref(sd_resolve_query *q); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_resolve_query); /* Returns non-zero when the query operation specified by q has been completed. */ int sd_resolve_query_is_done(sd_resolve_query *q); diff --git a/src/systemd/sd-varlink.h b/src/systemd/sd-varlink.h index 69ddde8e734..fff6ea8a36f 100644 --- a/src/systemd/sd-varlink.h +++ b/src/systemd/sd-varlink.h @@ -93,8 +93,7 @@ int sd_varlink_connect_url(sd_varlink **ret, const char *url); int sd_varlink_connect_fd(sd_varlink **ret, int fd); int sd_varlink_connect_fd_pair(sd_varlink **ret, int input_fd, int output_fd, const struct ucred *override_ucred); -sd_varlink* sd_varlink_ref(sd_varlink *link); -sd_varlink* sd_varlink_unref(sd_varlink *v); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_varlink); int sd_varlink_get_fd(sd_varlink *v); int sd_varlink_get_input_fd(sd_varlink *v); @@ -223,8 +222,7 @@ int sd_varlink_set_input_sensitive(sd_varlink *v); /* Create a varlink server */ int sd_varlink_server_new(sd_varlink_server **ret, sd_varlink_server_flags_t flags); -sd_varlink_server* sd_varlink_server_ref(sd_varlink_server *s); -sd_varlink_server* sd_varlink_server_unref(sd_varlink_server *s); +_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC(sd_varlink_server); int sd_varlink_server_set_info( sd_varlink_server *s, diff --git a/src/sysupdate/sysupdate-feature.h b/src/sysupdate/sysupdate-feature.h index fcd05c97085..b42df5c27e6 100644 --- a/src/sysupdate/sysupdate-feature.h +++ b/src/sysupdate/sysupdate-feature.h @@ -17,8 +17,7 @@ typedef struct Feature { Feature *feature_new(void); -Feature *feature_ref(Feature *f); -Feature *feature_unref(Feature *f); +DECLARE_TRIVIAL_REF_UNREF_FUNC(Feature, feature); DEFINE_TRIVIAL_CLEANUP_FUNC(Feature*, feature_unref); extern const struct hash_ops feature_hash_ops; diff --git a/src/test/generate-sym-test.py b/src/test/generate-sym-test.py index 5aaf372c1db..8fcf1752893 100755 --- a/src/test/generate-sym-test.py +++ b/src/test/generate-sym-test.py @@ -61,6 +61,23 @@ def process_header_file(file: IO[str]) -> str: text += f' {{ "{m[1]}", {m[1]} }},\n' continue + # Functions declared by ref/unref macros + m = re.search(r'_SD_DECLARE_TRIVIAL_REF_UNREF_FUNC\((\w+)\)', line) + if m: + text += f' {{ "{m[1]}_ref", {m[1]}_ref }},\n' + text += f' {{ "{m[1]}_unref", {m[1]}_unref }},\n' + continue + + m = re.search(r'_SD_DECLARE_TRIVIAL_REF_FUNC\((\w+)\)', line) + if m: + text += f' {{ "{m[1]}_ref", {m[1]}_ref }},\n' + continue + + m = re.search(r'_SD_DECLARE_TRIVIAL_UNREF_FUNC\((\w+)\)', line) + if m: + text += f' {{ "{m[1]}_unref", {m[1]}_unref }},\n' + continue + return text diff --git a/src/udev/udev-ctrl.h b/src/udev/udev-ctrl.h index efd500fd50c..83c66239d06 100644 --- a/src/udev/udev-ctrl.h +++ b/src/udev/udev-ctrl.h @@ -29,8 +29,7 @@ static inline int udev_ctrl_new(UdevCtrl **ret) { } int udev_ctrl_enable_receiving(UdevCtrl *uctrl); -UdevCtrl *udev_ctrl_ref(UdevCtrl *uctrl); -UdevCtrl *udev_ctrl_unref(UdevCtrl *uctrl); +DECLARE_TRIVIAL_REF_UNREF_FUNC(UdevCtrl, udev_ctrl); int udev_ctrl_attach_event(UdevCtrl *uctrl, sd_event *event); int udev_ctrl_start(UdevCtrl *uctrl, udev_ctrl_handler_t callback, void *userdata); sd_event_source *udev_ctrl_get_event_source(UdevCtrl *uctrl); diff --git a/src/udev/udev-event.h b/src/udev/udev-event.h index 61915ecf602..939a0ca8303 100644 --- a/src/udev/udev-event.h +++ b/src/udev/udev-event.h @@ -45,8 +45,7 @@ typedef struct UdevEvent { } UdevEvent; UdevEvent* udev_event_new(sd_device *dev, UdevWorker *worker, EventMode mode); -UdevEvent* udev_event_ref(UdevEvent *event); -UdevEvent* udev_event_unref(UdevEvent *event); +DECLARE_TRIVIAL_REF_UNREF_FUNC(UdevEvent, udev_event); DEFINE_TRIVIAL_CLEANUP_FUNC(UdevEvent*, udev_event_unref); int udev_event_execute_rules(UdevEvent *event, UdevRules *rules);