dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
84b277
From 30725ba0d69c5ba935c64ce9c3892494687e4c9b Mon Sep 17 00:00:00 2001
84b277
From: Lennart Poettering <lennart@poettering.net>
84b277
Date: Mon, 14 Oct 2013 04:59:26 +0200
84b277
Subject: [PATCH] util: allow trailing semicolons on
84b277
 define_trivial_cleanup_func lines
84b277
84b277
Emacs C indenting really gets confused by these lines if they carry no
84b277
trailing semicolon, hence let's make this nicer for good old emacs. The
84b277
other macros which define functions already do this too, so let's copy
84b277
the scheme here.
84b277
84b277
Also, let's use an uppercase name for the macro. So far our rough rule
84b277
was that macros that are totally not function-like (like this ones,
84b277
which define a function) are uppercase. (Well, admittedly it is a rough
84b277
rule only, for example function and variable decorators are all
84b277
lower-case SINCE THE CONSTANT YELLING IN THE SOURCES WOULD SUCK, and
84b277
also they at least got underscore prefixes.) Also, the macros that
84b277
define functions that we already have are all uppercase, so let's do the
84b277
same here...
84b277
84b277
(cherry-picked from cd7affaeea16d3904354b810a292e594dfef25dd)
84b277
84b277
Related: #1147524
84b277
---
84b277
 src/gpt-auto-generator/gpt-auto-generator.c |  2 +-
84b277
 src/journal/journal-internal.h              |  2 +-
84b277
 src/shared/fdset.h                          |  2 +-
84b277
 src/shared/hashmap.h                        |  8 ++++++++
84b277
 src/shared/label.c                          |  4 ++--
84b277
 src/shared/set.h                            |  4 ++--
84b277
 src/shared/strv.h                           |  2 +-
84b277
 src/shared/udev-util.h                      | 10 +++++-----
84b277
 src/shared/util.h                           | 19 ++++++++++---------
84b277
 src/tmpfiles/tmpfiles.c                     |  2 +-
84b277
 10 files changed, 32 insertions(+), 23 deletions(-)
84b277
84b277
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
84b277
index 6a4c9d8..eb281b5 100644
84b277
--- a/src/gpt-auto-generator/gpt-auto-generator.c
84b277
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
84b277
@@ -51,7 +51,7 @@
84b277
 
84b277
 static const char *arg_dest = "/tmp";
84b277
 
84b277
-define_trivial_cleanup_func(blkid_probe, blkid_free_probe)
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(blkid_probe, blkid_free_probe);
84b277
 #define _cleanup_blkid_freep_probe_ _cleanup_(blkid_free_probep)
84b277
 
84b277
 static int verify_gpt_partition(const char *node, sd_id128_t *type, unsigned *nr, char **fstype) {
84b277
diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
84b277
index 1bc912c..3355fca 100644
84b277
--- a/src/journal/journal-internal.h
84b277
+++ b/src/journal/journal-internal.h
84b277
@@ -135,7 +135,7 @@ struct sd_journal {
84b277
 char *journal_make_match_string(sd_journal *j);
84b277
 void journal_print_header(sd_journal *j);
84b277
 
84b277
-define_trivial_cleanup_func(sd_journal*, sd_journal_close)
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(sd_journal*, sd_journal_close);
84b277
 #define _cleanup_journal_close_ _cleanup_(sd_journal_closep)
84b277
 
84b277
 #define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval)                     \
84b277
diff --git a/src/shared/fdset.h b/src/shared/fdset.h
84b277
index 6277e46..907acd7 100644
84b277
--- a/src/shared/fdset.h
84b277
+++ b/src/shared/fdset.h
84b277
@@ -49,5 +49,5 @@ int fdset_iterate(FDSet *s, Iterator *i);
84b277
 #define FDSET_FOREACH(fd, fds, i) \
84b277
         for ((i) = ITERATOR_FIRST, (fd) = fdset_iterate((fds), &(i)); (fd) >= 0; (fd) = fdset_iterate((fds), &(i)))
84b277
 
84b277
-define_trivial_cleanup_func(FDSet*, fdset_free)
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(FDSet*, fdset_free);
84b277
 #define _cleanup_fdset_free_ _cleanup_(fdset_freep)
84b277
diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h
84b277
index 3d4f672..b912af8 100644
84b277
--- a/src/shared/hashmap.h
84b277
+++ b/src/shared/hashmap.h
84b277
@@ -24,6 +24,7 @@
84b277
 #include <stdbool.h>
84b277
 
84b277
 #include "macro.h"
84b277
+#include "util.h"
84b277
 
84b277
 /* Pretty straightforward hash table implementation. As a minor
84b277
  * optimization a NULL hashmap object will be treated as empty hashmap
84b277
@@ -104,3 +105,10 @@ char **hashmap_get_strv(Hashmap *h);
84b277
 
84b277
 #define HASHMAP_FOREACH_BACKWARDS(e, h, i) \
84b277
         for ((i) = ITERATOR_LAST, (e) = hashmap_iterate_backwards((h), &(i), NULL); (e); (e) = hashmap_iterate_backwards((h), &(i), NULL))
84b277
+
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free_free);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free_free_free);
84b277
+#define _cleanup_hashmap_free_ _cleanup_(hashmap_freep)
84b277
+#define _cleanup_hashmap_free_free_ _cleanup_(hashmap_free_freep)
84b277
+#define _cleanup_hashmap_free_free_free_ _cleanup_(hashmap_free_free_freep)
84b277
diff --git a/src/shared/label.c b/src/shared/label.c
84b277
index 4dab93e..8f7dfb4 100644
84b277
--- a/src/shared/label.c
84b277
+++ b/src/shared/label.c
84b277
@@ -40,8 +40,8 @@
84b277
 #include <selinux/label.h>
84b277
 #include <selinux/context.h>
84b277
 
84b277
-define_trivial_cleanup_func(security_context_t, freecon);
84b277
-define_trivial_cleanup_func(context_t, context_free);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(security_context_t, freecon);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free);
84b277
 
84b277
 #define _cleanup_security_context_free_ _cleanup_(freeconp)
84b277
 #define _cleanup_context_free_ _cleanup_(context_freep)
84b277
diff --git a/src/shared/set.h b/src/shared/set.h
84b277
index a291470..5612478 100644
84b277
--- a/src/shared/set.h
84b277
+++ b/src/shared/set.h
84b277
@@ -73,7 +73,7 @@ char **set_get_strv(Set *s);
84b277
 #define SET_FOREACH_BACKWARDS(e, s, i) \
84b277
         for ((i) = ITERATOR_LAST, (e) = set_iterate_backwards((s), &(i)); (e); (e) = set_iterate_backwards((s), &(i)))
84b277
 
84b277
-define_trivial_cleanup_func(Set*, set_free)
84b277
-define_trivial_cleanup_func(Set*, set_free_free)
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free_free);
84b277
 #define _cleanup_set_free_ _cleanup_(set_freep)
84b277
 #define _cleanup_set_free_free_ _cleanup_(set_free_freep)
84b277
diff --git a/src/shared/strv.h b/src/shared/strv.h
84b277
index 4d117f8..f6fb033 100644
84b277
--- a/src/shared/strv.h
84b277
+++ b/src/shared/strv.h
84b277
@@ -30,7 +30,7 @@ char *strv_find(char **l, const char *name) _pure_;
84b277
 char *strv_find_prefix(char **l, const char *name) _pure_;
84b277
 
84b277
 void strv_free(char **l);
84b277
-define_trivial_cleanup_func(char**, strv_free)
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
84b277
 #define _cleanup_strv_free_ _cleanup_(strv_freep)
84b277
 
84b277
 char **strv_copy(char * const *l);
84b277
diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h
84b277
index bff8f5f..27677af 100644
84b277
--- a/src/shared/udev-util.h
84b277
+++ b/src/shared/udev-util.h
84b277
@@ -24,11 +24,11 @@
84b277
 #include "udev.h"
84b277
 #include "util.h"
84b277
 
84b277
-define_trivial_cleanup_func(struct udev*, udev_unref)
84b277
-define_trivial_cleanup_func(struct udev_device*, udev_device_unref)
84b277
-define_trivial_cleanup_func(struct udev_enumerate*, udev_enumerate_unref)
84b277
-define_trivial_cleanup_func(struct udev_event*, udev_event_unref)
84b277
-define_trivial_cleanup_func(struct udev_rules*, udev_rules_unref)
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev*, udev_unref);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_device*, udev_device_unref);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_enumerate*, udev_enumerate_unref);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_event*, udev_event_unref);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_rules*, udev_rules_unref);
84b277
 
84b277
 #define _cleanup_udev_unref_ _cleanup_(udev_unrefp)
84b277
 #define _cleanup_udev_device_unref_ _cleanup_(udev_device_unrefp)
84b277
diff --git a/src/shared/util.h b/src/shared/util.h
84b277
index 5a9bc99..d68f385 100644
84b277
--- a/src/shared/util.h
84b277
+++ b/src/shared/util.h
84b277
@@ -558,11 +558,12 @@ static inline void freep(void *p) {
84b277
         free(*(void**) p);
84b277
 }
84b277
 
84b277
-#define define_trivial_cleanup_func(type, func) \
84b277
-        static inline void func##p(type *p) {   \
84b277
-        if (*p)                                 \
84b277
-                func(*p);                       \
84b277
-        }                                       \
84b277
+#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func)                 \
84b277
+        static inline void func##p(type *p) {                   \
84b277
+                if (*p)                                         \
84b277
+                        func(*p);                               \
84b277
+        }                                                       \
84b277
+        struct __useless_struct_to_allow_trailing_semicolon__
84b277
 
84b277
 static inline void closep(int *fd) {
84b277
         if (*fd >= 0)
84b277
@@ -573,10 +574,10 @@ static inline void umaskp(mode_t *u) {
84b277
         umask(*u);
84b277
 }
84b277
 
84b277
-define_trivial_cleanup_func(FILE*, fclose)
84b277
-define_trivial_cleanup_func(FILE*, pclose)
84b277
-define_trivial_cleanup_func(DIR*, closedir)
84b277
-define_trivial_cleanup_func(FILE*, endmntent)
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, fclose);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent);
84b277
 
84b277
 #define _cleanup_free_ _cleanup_(freep)
84b277
 #define _cleanup_close_ _cleanup_(closep)
84b277
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
84b277
index df6c99a..9917514 100644
84b277
--- a/src/tmpfiles/tmpfiles.c
84b277
+++ b/src/tmpfiles/tmpfiles.c
84b277
@@ -999,7 +999,7 @@ static void item_free(Item *i) {
84b277
         free(i);
84b277
 }
84b277
 
84b277
-define_trivial_cleanup_func(Item*, item_free)
84b277
+DEFINE_TRIVIAL_CLEANUP_FUNC(Item*, item_free);
84b277
 #define _cleanup_item_free_ _cleanup_(item_freep)
84b277
 
84b277
 static bool item_equal(Item *a, Item *b) {