[minicoredumper] [PATCH 1/6] Make libminicoredumper usable from a C++ program

Simon Marchi simon.marchi at ericsson.com
Tue Oct 13 23:56:19 CEST 2015


1. Add extern "C".
2. When building in C++ mode, define a custom operator| for
   enum mcd_dump_data_flags.  This fixes these errors:

test.cxx: In function ‘int main()’:
test.cxx:13:95: error: invalid conversion from ‘int’ to ‘mcd_dump_data_flags’ [-fpermissive]
   mcd_dump_data_register_bin(NULL, 0, &save, buf, MCD_DATA_PTR_DIRECT | MCD_LENGTH_DIRECT, 512);
                                                                                               ^
In file included from test.cxx:1:0:
/opt/minicoredump/include/minicoredumper.h:131:12: error:   initializing argument 5 of ‘int mcd_dump_data_register_bin(const char*, long unsigned int, mcd_dump_data**, void*, mcd_dump_data_flags, size_t)’ [-fpermissive]
 extern int mcd_dump_data_register_bin(const char *ident,
            ^

Signed-off-by: Simon Marchi <simon.marchi at ericsson.com>
---
 src/api/minicoredumper.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/api/minicoredumper.h b/src/api/minicoredumper.h
index 79684bb..7d8f02e 100644
--- a/src/api/minicoredumper.h
+++ b/src/api/minicoredumper.h
@@ -31,6 +31,10 @@
 #include <stdarg.h>
 #include <sys/types.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* opaque data types */
 struct mcd_dump_data;
 typedef struct mcd_dump_data *mcd_dump_data_t;
@@ -51,6 +55,15 @@ enum mcd_dump_data_flags {
 	MCD_LENGTH_INDIRECT = 8,
 };
 
+#ifdef __cplusplus
+static mcd_dump_data_flags operator|(mcd_dump_data_flags lhs,
+				     mcd_dump_data_flags rhs)
+{
+	return static_cast<mcd_dump_data_flags>(
+	    static_cast<int>(lhs) | static_cast<int>(rhs));
+}
+#endif
+
 /*
  * global_dump_init - Initialize D-Bus connection
  * Must be called if D-Bus notification is to be used.
@@ -138,4 +151,8 @@ extern int mcd_dump_data_register_bin(const char *ident,
  */
 extern int mcd_dump_data_unregister(struct mcd_dump_data *dd);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __MINICOREDUMPER_H__ */
-- 
2.5.1





More information about the minicoredumper mailing list