[Libguestfs] [PATCH 1/2] lib: Allow the COMPILE_REGEXP macro to be used everywhere.

Richard W.M. Jones rjones at redhat.com
Tue Feb 23 09:17:42 UTC 2016


Since the daemon links to pcre and use regular expressions, and since
the COMPILE_REGEXP macro doesn't depend on any aspects of the
library-side code (eg. the guestfs_h handle etc), we can allow the
daemon to use the COMPILE_REGEXP macro.  Move the macro to
"guestfs-internal-all.h" to permit this.
---
 src/guestfs-internal-all.h | 26 ++++++++++++++++++++++++++
 src/guestfs-internal.h     | 24 ------------------------
 2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/src/guestfs-internal-all.h b/src/guestfs-internal-all.h
index 84b8fd6..af30e58 100644
--- a/src/guestfs-internal-all.h
+++ b/src/guestfs-internal-all.h
@@ -65,6 +65,32 @@
 #define xdr_uint32_t xdr_u_int32_t
 #endif
 
+/* Macro which compiles the regexp once when the program/library is
+ * loaded, and frees it when the library is unloaded.
+ */
+#define COMPILE_REGEXP(name,pattern,options)                            \
+  static void compile_regexp_##name (void) __attribute__((constructor)); \
+  static void free_regexp_##name (void) __attribute__((destructor));    \
+  static pcre *name;                                                    \
+                                                                        \
+  static void                                                           \
+  compile_regexp_##name (void)                                          \
+  {                                                                     \
+    const char *err;                                                    \
+    int offset;                                                         \
+    name = pcre_compile ((pattern), (options), &err, &offset, NULL);    \
+    if (name == NULL) {                                                 \
+      ignore_value (write (2, err, strlen (err)));                      \
+      abort ();                                                         \
+    }                                                                   \
+  }                                                                     \
+                                                                        \
+  static void                                                           \
+  free_regexp_##name (void)                                             \
+  {                                                                     \
+    pcre_free (name);                                                   \
+  }
+
 /* The type field of a parsed mountable.
  *
  * This is used both by mountable_t in the daemon, and
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 22b6c6c..3707c1b 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -710,30 +710,6 @@ extern int guestfs_int_match6 (guestfs_h *g, const char *str, const pcre *re, ch
 #define match4 guestfs_int_match4
 #define match6 guestfs_int_match6
 
-/* Macro which compiles the regexp once when the library is loaded,
- * and frees it when the library is unloaded.
- */
-#define COMPILE_REGEXP(name,pattern,options)                            \
-  static void compile_regexp_##name (void) __attribute__((constructor)); \
-  static void free_regexp_##name (void) __attribute__((destructor));    \
-  static pcre *name;                                                    \
-  static void                                                           \
-  compile_regexp_##name (void)                                          \
-  {                                                                     \
-    const char *err;                                                    \
-    int offset;                                                         \
-    name = pcre_compile ((pattern), (options), &err, &offset, NULL);    \
-    if (name == NULL) {                                                 \
-      ignore_value (write (2, err, strlen (err)));                      \
-      abort ();                                                         \
-    }                                                                   \
-  }                                                                     \
-  static void                                                           \
-  free_regexp_##name (void)                                             \
-  {                                                                     \
-    pcre_free (name);                                                   \
-  }
-
 /* stringsbuf.c */
 struct stringsbuf {
   char **argv;
-- 
2.5.0




More information about the Libguestfs mailing list