* [Qemu-devel] [PATCH] block: Use g_new0() for a bit of extra type checking
@ 2014-12-04 12:55 Markus Armbruster
2014-12-04 13:03 ` Max Reitz
0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2014-12-04 12:55 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, mreitz
g_new(T, 1) is safer than g_malloc(sizeof(T)), because it returns T *
rather than void *, which lets the compiler catch more type errors.
Missed in commit 02c4f26.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
aio-posix.c | 2 +-
aio-win32.c | 4 ++--
async.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/aio-posix.c b/aio-posix.c
index d3ac06e..cbd4c34 100644
--- a/aio-posix.c
+++ b/aio-posix.c
@@ -73,7 +73,7 @@ void aio_set_fd_handler(AioContext *ctx,
} else {
if (node == NULL) {
/* Alloc and insert if it's not already there */
- node = g_malloc0(sizeof(AioHandler));
+ node = g_new0(AioHandler, 1);
node->pfd.fd = fd;
QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);
diff --git a/aio-win32.c b/aio-win32.c
index d81313b..e6f4ced 100644
--- a/aio-win32.c
+++ b/aio-win32.c
@@ -67,7 +67,7 @@ void aio_set_fd_handler(AioContext *ctx,
if (node == NULL) {
/* Alloc and insert if it's not already there */
- node = g_malloc0(sizeof(AioHandler));
+ node = g_new0(AioHandler, 1);
node->pfd.fd = fd;
QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);
}
@@ -129,7 +129,7 @@ void aio_set_event_notifier(AioContext *ctx,
} else {
if (node == NULL) {
/* Alloc and insert if it's not already there */
- node = g_malloc0(sizeof(AioHandler));
+ node = g_new0(AioHandler, 1);
node->e = e;
node->pfd.fd = (uintptr_t)event_notifier_get_handle(e);
node->pfd.events = G_IO_IN;
diff --git a/async.c b/async.c
index 6e1b282..3939b79 100644
--- a/async.c
+++ b/async.c
@@ -44,7 +44,7 @@ struct QEMUBH {
QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
{
QEMUBH *bh;
- bh = g_malloc0(sizeof(QEMUBH));
+ bh = g_new0(QEMUBH, 1);
bh->ctx = ctx;
bh->cb = cb;
bh->opaque = opaque;
--
1.9.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Use g_new0() for a bit of extra type checking
2014-12-04 12:55 [Qemu-devel] [PATCH] block: Use g_new0() for a bit of extra type checking Markus Armbruster
@ 2014-12-04 13:03 ` Max Reitz
0 siblings, 0 replies; 2+ messages in thread
From: Max Reitz @ 2014-12-04 13:03 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: kwolf, stefanha
On 2014-12-04 at 13:55, Markus Armbruster wrote:
> g_new(T, 1) is safer than g_malloc(sizeof(T)), because it returns T *
> rather than void *, which lets the compiler catch more type errors.
>
> Missed in commit 02c4f26.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> aio-posix.c | 2 +-
> aio-win32.c | 4 ++--
> async.c | 2 +-
> 3 files changed, 4 insertions(+), 4 deletions(-)
Thanks, applied to my block-next tree:
https://github.com/XanClic/qemu/commits/block-next
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-12-04 13:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-04 12:55 [Qemu-devel] [PATCH] block: Use g_new0() for a bit of extra type checking Markus Armbruster
2014-12-04 13:03 ` Max Reitz
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).