]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: Introduce conf-parser-forward.h
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 May 2025 07:20:27 +0000 (09:20 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 May 2025 08:49:42 +0000 (10:49 +0200)
conf-parser.h pulls in a lot of other headers as needed by all the
macros it defines. We can't easily move the implementations of these
macro to conf-parser.c, so let's instead introduce conf-parser-forward.h
with just the stuff in it needed by other header files.

We'll make use of this when cleaning up includes to only include the
minimal parts of conf-parser.h that are required by other headers without
pulling in the kitchen sink.

src/shared/conf-parser-forward.h [new file with mode: 0644]
src/shared/conf-parser.h

diff --git a/src/shared/conf-parser-forward.h b/src/shared/conf-parser-forward.h
new file mode 100644 (file)
index 0000000..f534e5e
--- /dev/null
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "cleanup-util.h"
+
+/* Argument list for parsers of specific configuration settings. */
+#define CONFIG_PARSER_ARGUMENTS                 \
+        const char *unit,                       \
+        const char *filename,                   \
+        unsigned line,                          \
+        const char *section,                    \
+        unsigned section_line,                  \
+        const char *lvalue,                     \
+        int ltype,                              \
+        const char *rvalue,                     \
+        void *data,                             \
+        void *userdata
+
+/* Prototype for a parser for a specific configuration setting */
+typedef int (*ConfigParserCallback)(CONFIG_PARSER_ARGUMENTS);
+
+/* A macro declaring a function prototype, following the typedef above, simply because it's so cumbersomely long
+ * otherwise. (And current emacs gets irritatingly slow when editing files that contain lots of very long function
+ * prototypes on the same screen…) */
+#define CONFIG_PARSER_PROTOTYPE(name) int name(CONFIG_PARSER_ARGUMENTS)
+
+typedef struct ConfigSection {
+        unsigned line;
+        bool invalid;
+        char filename[];
+} ConfigSection;
+
+#define DEFINE_SECTION_CLEANUP_FUNCTIONS(type, free_func)               \
+        static inline type* free_func##_or_set_invalid(type *p) {       \
+                assert(p);                                              \
+                                                                        \
+                if (p->section)                                         \
+                        p->section->invalid = true;                     \
+                else                                                    \
+                        free_func(p);                                   \
+                return NULL;                                            \
+        }                                                               \
+        DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func);                  \
+        DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid);
index fdc6c3755b48ddb4a3795fa76be53b368019e194..2a60eb6ab8247a3453034dc1a9673f8fb9b60ad5 100644 (file)
@@ -8,6 +8,7 @@
 #include <sys/stat.h>
 #include <syslog.h>
 
+#include "conf-parser-forward.h"
 #include "hashmap.h"
 #include "log.h"
 #include "memory-util.h"
@@ -19,27 +20,6 @@ typedef enum ConfigParseFlags {
         CONFIG_PARSE_WARN          = 1 << 1, /* Emit non-debug messages */
 } ConfigParseFlags;
 
-/* Argument list for parsers of specific configuration settings. */
-#define CONFIG_PARSER_ARGUMENTS                 \
-        const char *unit,                       \
-        const char *filename,                   \
-        unsigned line,                          \
-        const char *section,                    \
-        unsigned section_line,                  \
-        const char *lvalue,                     \
-        int ltype,                              \
-        const char *rvalue,                     \
-        void *data,                             \
-        void *userdata
-
-/* Prototype for a parser for a specific configuration setting */
-typedef int (*ConfigParserCallback)(CONFIG_PARSER_ARGUMENTS);
-
-/* A macro declaring a function prototype, following the typedef above, simply because it's so cumbersomely long
- * otherwise. (And current emacs gets irritatingly slow when editing files that contain lots of very long function
- * prototypes on the same screen…) */
-#define CONFIG_PARSER_PROTOTYPE(name) int name(CONFIG_PARSER_ARGUMENTS)
-
 /* Wraps information for parsing a specific configuration variable, to
  * be stored in a simple array */
 typedef struct ConfigTableItem {
@@ -164,12 +144,6 @@ int config_section_parse(
                 const char *rvalue,
                 void *userdata);
 
-typedef struct ConfigSection {
-        unsigned line;
-        bool invalid;
-        char filename[];
-} ConfigSection;
-
 static inline ConfigSection* config_section_free(ConfigSection *cs) {
         return mfree(cs);
 }
@@ -207,19 +181,6 @@ static inline bool section_is_invalid(ConfigSection *section) {
         return section->invalid;
 }
 
-#define DEFINE_SECTION_CLEANUP_FUNCTIONS(type, free_func)               \
-        static inline type* free_func##_or_set_invalid(type *p) {       \
-                assert(p);                                              \
-                                                                        \
-                if (p->section)                                         \
-                        p->section->invalid = true;                     \
-                else                                                    \
-                        free_func(p);                                   \
-                return NULL;                                            \
-        }                                                               \
-        DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func);                  \
-        DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid);
-
 #define log_section_full_errno_zerook(section, level, error, ...)       \
         ({                                                              \
                 const ConfigSection *_s = (section);                    \