From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, afaerber@suse.de, peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH for-2.5 1/2] tests: Use proper functions types instead of void (*fn)
Date: Wed, 2 Dec 2015 21:20:33 +0100 [thread overview]
Message-ID: <1449087634-30846-2-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1449087634-30846-1-git-send-email-armbru@redhat.com>
We have several function parameters declared as void (*fn). This is
just a stupid way to write void *, and the only purpose writing it
like that could serve is obscuring the sin of bypassing the type
system without need.
The original sin is commit 49ee359: its qtest_add_func() is a wrapper
for g_test_add_func(). Fix the parameter type to match
g_test_add_func()'s. This uncovers type errors in ide-test.c; fix
them.
Commit 7949c0e faithfully repeated the sin for qtest_add_data_func().
Fix it the same way, along with a harmless type error uncovered in
vhost-user-test.c.
Commit 063c23d repeated it for qtest_add_abrt_handler(). The screwy
parameter gets assigned to GHook member func, so change its type to
match. Requires wrapping kill_qemu() to keep the type checker happy.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
tests/ide-test.c | 4 ++--
tests/libqtest.c | 13 +++++++++----
tests/libqtest.h | 6 +++---
tests/vhost-user-test.c | 3 ++-
4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/tests/ide-test.c b/tests/ide-test.c
index c3aacd2..b864701 100644
--- a/tests/ide-test.c
+++ b/tests/ide-test.c
@@ -593,12 +593,12 @@ static void test_flush_nodev(void)
ide_test_quit();
}
-static void test_pci_retry_flush(const char *machine)
+static void test_pci_retry_flush(void)
{
test_retry_flush("pc");
}
-static void test_isa_retry_flush(const char *machine)
+static void test_isa_retry_flush(void)
{
test_retry_flush("isapc");
}
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 9753161..c52ceb2 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -110,6 +110,11 @@ static void kill_qemu(QTestState *s)
}
}
+static void kill_qemu_hook_func(void *s)
+{
+ kill_qemu(s);
+}
+
static void sigabrt_handler(int signo)
{
g_hook_list_invoke(&abrt_hooks, FALSE);
@@ -133,7 +138,7 @@ static void cleanup_sigabrt_handler(void)
sigaction(SIGABRT, &sigact_old, NULL);
}
-void qtest_add_abrt_handler(void (*fn), const void *data)
+void qtest_add_abrt_handler(GHookFunc fn, const void *data)
{
GHook *hook;
@@ -170,7 +175,7 @@ QTestState *qtest_init(const char *extra_args)
sock = init_socket(socket_path);
qmpsock = init_socket(qmp_socket_path);
- qtest_add_abrt_handler(kill_qemu, s);
+ qtest_add_abrt_handler(kill_qemu_hook_func, s);
s->qemu_pid = fork();
if (s->qemu_pid == 0) {
@@ -755,14 +760,14 @@ void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size)
g_strfreev(args);
}
-void qtest_add_func(const char *str, void (*fn))
+void qtest_add_func(const char *str, GTestFunc fn)
{
gchar *path = g_strdup_printf("/%s/%s", qtest_get_arch(), str);
g_test_add_func(path, fn);
g_free(path);
}
-void qtest_add_data_func(const char *str, const void *data, void (*fn))
+void qtest_add_data_func(const char *str, const void *data, GTestDataFunc fn)
{
gchar *path = g_strdup_printf("/%s/%s", qtest_get_arch(), str);
g_test_add_data_func(path, data, fn);
diff --git a/tests/libqtest.h b/tests/libqtest.h
index df08745..d11b5a4 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -416,7 +416,7 @@ const char *qtest_get_arch(void);
* The path is prefixed with the architecture under test, as
* returned by qtest_get_arch().
*/
-void qtest_add_func(const char *str, void (*fn));
+void qtest_add_func(const char *str, GTestFunc fn);
/**
* qtest_add_data_func:
@@ -428,7 +428,7 @@ void qtest_add_func(const char *str, void (*fn));
* The path is prefixed with the architecture under test, as
* returned by qtest_get_arch().
*/
-void qtest_add_data_func(const char *str, const void *data, void (*fn));
+void qtest_add_data_func(const char *str, const void *data, GTestDataFunc fn);
/**
* qtest_add:
@@ -450,7 +450,7 @@ void qtest_add_data_func(const char *str, const void *data, void (*fn));
g_free(path); \
} while (0)
-void qtest_add_abrt_handler(void (*fn), const void *data);
+void qtest_add_abrt_handler(GHookFunc fn, const void *data);
/**
* qtest_start:
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index e4c36af..814caf9 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -172,8 +172,9 @@ static void wait_for_fds(TestServer *s)
g_mutex_unlock(&s->data_mutex);
}
-static void read_guest_mem(TestServer *s)
+static void read_guest_mem(const void *data)
{
+ TestServer *s = (void *)data;
uint32_t *guest_mem;
int i, j;
size_t size;
--
2.4.3
next prev parent reply other threads:[~2015-12-02 20:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-02 20:20 [Qemu-devel] [PATCH for-2.5 0/2] tests: A cleanup and a fix Markus Armbruster
2015-12-02 20:20 ` Markus Armbruster [this message]
2015-12-02 20:42 ` [Qemu-devel] [PATCH for-2.5 1/2] tests: Use proper functions types instead of void (*fn) Eric Blake
2015-12-03 8:22 ` Markus Armbruster
2015-12-04 7:59 ` [Qemu-devel] [PATCH] fixup! " Markus Armbruster
2015-12-02 20:20 ` [Qemu-devel] [PATCH for-2.5 2/2] qom-test: fix qmp() leaks Markus Armbruster
2015-12-02 20:44 ` Eric Blake
2015-12-03 19:29 ` Andreas Färber
2015-12-03 10:54 ` [Qemu-devel] [PATCH for-2.5 0/2] tests: A cleanup and a fix Peter Maydell
2015-12-03 12:06 ` Markus Armbruster
2015-12-03 12:57 ` Andreas Färber
2015-12-03 13:06 ` Peter Maydell
2015-12-03 16:13 ` Markus Armbruster
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=1449087634-30846-2-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=afaerber@suse.de \
--cc=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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).