Skip to content

pam_fprintd: Implement auto-pointers and use early-return more around

Marco Trevisan requested to merge 3v1n0/fprintd:pam-auto-pointers into master

Implement simple auto-pointers for the types we use in pam_fprintd with a basic implementation based on GLib one so that we can have the same features without having neither an header-dependency on it.

Just to make it readable, as per gcc -E it generates:

typedef sd_bus *sd_bus_pf_autoptr;
static __attribute__((__unused__)) inline void
pf_autoptr_cleanup_sd_bus (sd_bus **_ptr) {
    if (_ptr) (sd_bus_unref) (*_ptr);
}

typedef sd_bus_message *sd_bus_message_pf_autoptr;
static __attribute__((__unused__)) inline void
pf_autoptr_cleanup_sd_bus_message (sd_bus_message **_ptr) {
    if (_ptr) (sd_bus_message_unref) (*_ptr);
}

typedef sd_bus_slot *sd_bus_slot_pf_autoptr;
static __attribute__((__unused__)) inline void
pf_autoptr_cleanup_sd_bus_slot (sd_bus_slot **_ptr) {
    if (_ptr) (sd_bus_slot_unref) (*_ptr);
}

static __attribute__((__unused__)) inline void
pf_autoptr_cleanup_sd_bus_error (sd_bus_error *_ptr) {
    sd_bus_error_free (_ptr);
}

So definitions will be:

__attribute__((cleanup(pf_autoptr_cleanup_sd_bus_error))) sd_bus_error error = SD_BUS_ERROR_NULL;
__attribute__((cleanup(pf_autoptr_cleanup_sd_bus_message))) sd_bus_message_pf_autoptr message = NULL;
Edited by Marco Trevisan

Merge request reports

Loading