qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yonggang Luo <luoyonggang@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Yonggang Luo" <luoyonggang@gmail.com>,
	"Richard Henderson" <richard.henderson@linaro.org>
Subject: [PATCH v6 4/5] plugins: Getting qemu-plugin.h can be included in multiple source file
Date: Tue, 13 Oct 2020 08:28:05 +0800	[thread overview]
Message-ID: <20201013002806.1447-5-luoyonggang@gmail.com> (raw)
In-Reply-To: <20201013002806.1447-1-luoyonggang@gmail.com>

If we only have a single .c file in a plugin, then define
QEMU_PLUGIN_EXTERN to empty is OK, but if we have multiple .c files
in a plugin, then we need distinguish the implementation and the
deceleration. only the main .c file should define the macro QEMU_PLUGIN_IMPLEMENTATION
other sources are user and should use extern

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 contrib/plugins/hotblocks.c | 1 +
 contrib/plugins/hotpages.c  | 1 +
 contrib/plugins/howvec.c    | 1 +
 contrib/plugins/lockstep.c  | 1 +
 include/qemu/qemu-plugin.h  | 6 ++++++
 plugins/core.c              | 1 +
 tests/plugin/bb.c           | 1 +
 tests/plugin/empty.c        | 1 +
 tests/plugin/insn.c         | 1 +
 tests/plugin/mem.c          | 1 +
 10 files changed, 15 insertions(+)

diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
index 37435a3fc7..39e77d2980 100644
--- a/contrib/plugins/hotblocks.c
+++ b/contrib/plugins/hotblocks.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
diff --git a/contrib/plugins/hotpages.c b/contrib/plugins/hotpages.c
index ecd6c18732..1ae3f44aed 100644
--- a/contrib/plugins/hotpages.c
+++ b/contrib/plugins/hotpages.c
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c
index 3b9a6939f2..db1b4e5780 100644
--- a/contrib/plugins/howvec.c
+++ b/contrib/plugins/howvec.c
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c
index a696673dff..7173b2910d 100644
--- a/contrib/plugins/lockstep.c
+++ b/contrib/plugins/lockstep.c
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <errno.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index af2f6ccb78..a6ebb295de 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -426,7 +426,11 @@ typedef void (*qemu_plugin_outs_t)(const char *string);
 
 #if !defined(QEMU_PLUGIN_API_IMPLEMENTATION)
 
+#if defined(QEMU_PLUGIN_IMPLEMENTATION)
 #define qemu_plugin_decl_symbol(symbol_name) symbol_name##_t symbol_name
+#else
+#define qemu_plugin_decl_symbol(symbol_name) extern symbol_name##_t symbol_name
+#endif
 
 #define qemu_plugin_load_symbol(info, symbol_name) do {\
     symbol_name = info->dlsym(info->context, #symbol_name); \
@@ -472,6 +476,7 @@ qemu_plugin_decl_symbol(qemu_plugin_n_vcpus);
 qemu_plugin_decl_symbol(qemu_plugin_n_max_vcpus);
 qemu_plugin_decl_symbol(qemu_plugin_outs);
 
+#if defined(QEMU_PLUGIN_IMPLEMENTATION)
 QEMU_PLUGIN_EXPORT int qemu_plugin_initialize(const qemu_info_t *info)
 {
     qemu_plugin_load_symbol(info, qemu_plugin_uninstall);
@@ -512,6 +517,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_initialize(const qemu_info_t *info)
     qemu_plugin_load_symbol(info, qemu_plugin_outs);
     return 0;
 }
+#endif /* QEMU_PLUGIN_IMPLEMENTATION */
 
 #endif /* QEMU_PLUGIN_API_IMPLEMENTATION */
 
diff --git a/plugins/core.c b/plugins/core.c
index 3df3e7d9af..dd1ec7b3fc 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -12,6 +12,7 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 #include "qemu/osdep.h"
+#define QEMU_PLUGIN_API_IMPLEMENTATION
 #include "qemu/error-report.h"
 #include "qemu/config-file.h"
 #include "qapi/error.h"
diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c
index de09bdde4e..cda3fbdde9 100644
--- a/tests/plugin/bb.c
+++ b/tests/plugin/bb.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
diff --git a/tests/plugin/empty.c b/tests/plugin/empty.c
index 8fa6bacd93..0c3adf7aa0 100644
--- a/tests/plugin/empty.c
+++ b/tests/plugin/empty.c
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <stdio.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c
index a9a6e41237..bf86fdafe6 100644
--- a/tests/plugin/insn.c
+++ b/tests/plugin/insn.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c
index 4725bd851d..f39be9c969 100644
--- a/tests/plugin/mem.c
+++ b/tests/plugin/mem.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
-- 
2.28.0.windows.1



  parent reply	other threads:[~2020-10-13  0:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-13  0:28 [PATCH v6 0/5] Enable plugin support on msys2/mingw Yonggang Luo
2020-10-13  0:28 ` [PATCH v6 1/5] plugins: getting qemu_plugin_get_hwaddr only expose one function prototype Yonggang Luo
2020-10-13  0:28 ` [PATCH v6 2/5] plugins: Fixes typo in qemu-plugin.h Yonggang Luo
2020-10-13  0:28 ` [PATCH v6 3/5] plugins: Getting qemu-plugin works under win32 Yonggang Luo
2020-10-13  0:28 ` Yonggang Luo [this message]
2020-10-13  0:28 ` [PATCH v6 5/5] cirrus: Enable plugins in cirrus for windows Yonggang Luo
2020-10-13  0:39 ` [PATCH v6 0/5] Enable plugin support on msys2/mingw no-reply
2021-03-12 17:15 ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201013002806.1447-5-luoyonggang@gmail.com \
    --to=luoyonggang@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).