naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
Blob Blame History Raw
From 30725ba0d69c5ba935c64ce9c3892494687e4c9b Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Mon, 14 Oct 2013 04:59:26 +0200
Subject: [PATCH] util: allow trailing semicolons on
 define_trivial_cleanup_func lines

Emacs C indenting really gets confused by these lines if they carry no
trailing semicolon, hence let's make this nicer for good old emacs. The
other macros which define functions already do this too, so let's copy
the scheme here.

Also, let's use an uppercase name for the macro. So far our rough rule
was that macros that are totally not function-like (like this ones,
which define a function) are uppercase. (Well, admittedly it is a rough
rule only, for example function and variable decorators are all
lower-case SINCE THE CONSTANT YELLING IN THE SOURCES WOULD SUCK, and
also they at least got underscore prefixes.) Also, the macros that
define functions that we already have are all uppercase, so let's do the
same here...

(cherry-picked from cd7affaeea16d3904354b810a292e594dfef25dd)

Related: #1147524
---
 src/gpt-auto-generator/gpt-auto-generator.c |  2 +-
 src/journal/journal-internal.h              |  2 +-
 src/shared/fdset.h                          |  2 +-
 src/shared/hashmap.h                        |  8 ++++++++
 src/shared/label.c                          |  4 ++--
 src/shared/set.h                            |  4 ++--
 src/shared/strv.h                           |  2 +-
 src/shared/udev-util.h                      | 10 +++++-----
 src/shared/util.h                           | 19 ++++++++++---------
 src/tmpfiles/tmpfiles.c                     |  2 +-
 10 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index 6a4c9d8..eb281b5 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -51,7 +51,7 @@
 
 static const char *arg_dest = "/tmp";
 
-define_trivial_cleanup_func(blkid_probe, blkid_free_probe)
+DEFINE_TRIVIAL_CLEANUP_FUNC(blkid_probe, blkid_free_probe);
 #define _cleanup_blkid_freep_probe_ _cleanup_(blkid_free_probep)
 
 static int verify_gpt_partition(const char *node, sd_id128_t *type, unsigned *nr, char **fstype) {
diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
index 1bc912c..3355fca 100644
--- a/src/journal/journal-internal.h
+++ b/src/journal/journal-internal.h
@@ -135,7 +135,7 @@ struct sd_journal {
 char *journal_make_match_string(sd_journal *j);
 void journal_print_header(sd_journal *j);
 
-define_trivial_cleanup_func(sd_journal*, sd_journal_close)
+DEFINE_TRIVIAL_CLEANUP_FUNC(sd_journal*, sd_journal_close);
 #define _cleanup_journal_close_ _cleanup_(sd_journal_closep)
 
 #define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval)                     \
diff --git a/src/shared/fdset.h b/src/shared/fdset.h
index 6277e46..907acd7 100644
--- a/src/shared/fdset.h
+++ b/src/shared/fdset.h
@@ -49,5 +49,5 @@ int fdset_iterate(FDSet *s, Iterator *i);
 #define FDSET_FOREACH(fd, fds, i) \
         for ((i) = ITERATOR_FIRST, (fd) = fdset_iterate((fds), &(i)); (fd) >= 0; (fd) = fdset_iterate((fds), &(i)))
 
-define_trivial_cleanup_func(FDSet*, fdset_free)
+DEFINE_TRIVIAL_CLEANUP_FUNC(FDSet*, fdset_free);
 #define _cleanup_fdset_free_ _cleanup_(fdset_freep)
diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h
index 3d4f672..b912af8 100644
--- a/src/shared/hashmap.h
+++ b/src/shared/hashmap.h
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 
 #include "macro.h"
+#include "util.h"
 
 /* Pretty straightforward hash table implementation. As a minor
  * optimization a NULL hashmap object will be treated as empty hashmap
@@ -104,3 +105,10 @@ char **hashmap_get_strv(Hashmap *h);
 
 #define HASHMAP_FOREACH_BACKWARDS(e, h, i) \
         for ((i) = ITERATOR_LAST, (e) = hashmap_iterate_backwards((h), &(i), NULL); (e); (e) = hashmap_iterate_backwards((h), &(i), NULL))
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free_free_free);
+#define _cleanup_hashmap_free_ _cleanup_(hashmap_freep)
+#define _cleanup_hashmap_free_free_ _cleanup_(hashmap_free_freep)
+#define _cleanup_hashmap_free_free_free_ _cleanup_(hashmap_free_free_freep)
diff --git a/src/shared/label.c b/src/shared/label.c
index 4dab93e..8f7dfb4 100644
--- a/src/shared/label.c
+++ b/src/shared/label.c
@@ -40,8 +40,8 @@
 #include <selinux/label.h>
 #include <selinux/context.h>
 
-define_trivial_cleanup_func(security_context_t, freecon);
-define_trivial_cleanup_func(context_t, context_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(security_context_t, freecon);
+DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free);
 
 #define _cleanup_security_context_free_ _cleanup_(freeconp)
 #define _cleanup_context_free_ _cleanup_(context_freep)
diff --git a/src/shared/set.h b/src/shared/set.h
index a291470..5612478 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -73,7 +73,7 @@ char **set_get_strv(Set *s);
 #define SET_FOREACH_BACKWARDS(e, s, i) \
         for ((i) = ITERATOR_LAST, (e) = set_iterate_backwards((s), &(i)); (e); (e) = set_iterate_backwards((s), &(i)))
 
-define_trivial_cleanup_func(Set*, set_free)
-define_trivial_cleanup_func(Set*, set_free_free)
+DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free_free);
 #define _cleanup_set_free_ _cleanup_(set_freep)
 #define _cleanup_set_free_free_ _cleanup_(set_free_freep)
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 4d117f8..f6fb033 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -30,7 +30,7 @@ char *strv_find(char **l, const char *name) _pure_;
 char *strv_find_prefix(char **l, const char *name) _pure_;
 
 void strv_free(char **l);
-define_trivial_cleanup_func(char**, strv_free)
+DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
 #define _cleanup_strv_free_ _cleanup_(strv_freep)
 
 char **strv_copy(char * const *l);
diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h
index bff8f5f..27677af 100644
--- a/src/shared/udev-util.h
+++ b/src/shared/udev-util.h
@@ -24,11 +24,11 @@
 #include "udev.h"
 #include "util.h"
 
-define_trivial_cleanup_func(struct udev*, udev_unref)
-define_trivial_cleanup_func(struct udev_device*, udev_device_unref)
-define_trivial_cleanup_func(struct udev_enumerate*, udev_enumerate_unref)
-define_trivial_cleanup_func(struct udev_event*, udev_event_unref)
-define_trivial_cleanup_func(struct udev_rules*, udev_rules_unref)
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev*, udev_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_device*, udev_device_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_enumerate*, udev_enumerate_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_event*, udev_event_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_rules*, udev_rules_unref);
 
 #define _cleanup_udev_unref_ _cleanup_(udev_unrefp)
 #define _cleanup_udev_device_unref_ _cleanup_(udev_device_unrefp)
diff --git a/src/shared/util.h b/src/shared/util.h
index 5a9bc99..d68f385 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -558,11 +558,12 @@ static inline void freep(void *p) {
         free(*(void**) p);
 }
 
-#define define_trivial_cleanup_func(type, func) \
-        static inline void func##p(type *p) {   \
-        if (*p)                                 \
-                func(*p);                       \
-        }                                       \
+#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func)                 \
+        static inline void func##p(type *p) {                   \
+                if (*p)                                         \
+                        func(*p);                               \
+        }                                                       \
+        struct __useless_struct_to_allow_trailing_semicolon__
 
 static inline void closep(int *fd) {
         if (*fd >= 0)
@@ -573,10 +574,10 @@ static inline void umaskp(mode_t *u) {
         umask(*u);
 }
 
-define_trivial_cleanup_func(FILE*, fclose)
-define_trivial_cleanup_func(FILE*, pclose)
-define_trivial_cleanup_func(DIR*, closedir)
-define_trivial_cleanup_func(FILE*, endmntent)
+DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, fclose);
+DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose);
+DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
+DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent);
 
 #define _cleanup_free_ _cleanup_(freep)
 #define _cleanup_close_ _cleanup_(closep)
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index df6c99a..9917514 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -999,7 +999,7 @@ static void item_free(Item *i) {
         free(i);
 }
 
-define_trivial_cleanup_func(Item*, item_free)
+DEFINE_TRIVIAL_CLEANUP_FUNC(Item*, item_free);
 #define _cleanup_item_free_ _cleanup_(item_freep)
 
 static bool item_equal(Item *a, Item *b) {