[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/24] introduce QEMU_AUTO_VFREE
From: |
Kevin Wolf |
Subject: |
[PULL 15/24] introduce QEMU_AUTO_VFREE |
Date: |
Wed, 30 Jun 2021 18:01:57 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Introduce a convenient macro, that works for qemu_memalign() like
g_autofree works with g_malloc.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210628121133.193984-2-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/qemu/osdep.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index c3656b755a..c91a78b5e6 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -386,6 +386,21 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align,
bool shared,
void qemu_vfree(void *ptr);
void qemu_anon_ram_free(void *ptr, size_t size);
+/*
+ * It's an analog of GLIB's g_autoptr_cleanup_generic_gfree(), used to define
+ * g_autofree macro.
+ */
+static inline void qemu_cleanup_generic_vfree(void *p)
+{
+ void **pp = (void **)p;
+ qemu_vfree(*pp);
+}
+
+/*
+ * Analog of g_autofree, but qemu_vfree is called on cleanup instead of g_free.
+ */
+#define QEMU_AUTO_VFREE __attribute__((cleanup(qemu_cleanup_generic_vfree)))
+
/*
* Abstraction of PROT_ and MAP_ flags as passed to mmap(), for example,
* consumed by qemu_ram_mmap().
--
2.31.1
- [PULL 06/24] block: introduce bdrv_remove_file_or_backing_child(), (continued)
- [PULL 06/24] block: introduce bdrv_remove_file_or_backing_child(), Kevin Wolf, 2021/06/30
- [PULL 08/24] block: bdrv_reopen_parse_backing(): don't check aio context, Kevin Wolf, 2021/06/30
- [PULL 07/24] block: introduce bdrv_set_file_or_backing_noperm(), Kevin Wolf, 2021/06/30
- [PULL 12/24] block: BDRVReopenState: drop replace_backing_bs field, Kevin Wolf, 2021/06/30
- [PULL 09/24] block: bdrv_reopen_parse_backing(): don't check frozen child, Kevin Wolf, 2021/06/30
- [PULL 10/24] block: bdrv_reopen_parse_backing(): simplify handling implicit filters, Kevin Wolf, 2021/06/30
- [PULL 11/24] block: move supports_backing check to bdrv_set_file_or_backing_noperm(), Kevin Wolf, 2021/06/30
- [PULL 13/24] block: Allow changing bs->file on reopen, Kevin Wolf, 2021/06/30
- [PULL 04/24] block: rename bdrv_replace_child to bdrv_replace_child_tran, Kevin Wolf, 2021/06/30
- [PULL 17/24] block/ssh: add support for sha256 host key fingerprints, Kevin Wolf, 2021/06/30
- [PULL 15/24] introduce QEMU_AUTO_VFREE,
Kevin Wolf <=
- [PULL 18/24] vhost: Add Error parameter to vhost_dev_init(), Kevin Wolf, 2021/06/30
- [PULL 16/24] block/commit: use QEMU_AUTO_VFREE, Kevin Wolf, 2021/06/30
- [PULL 22/24] vhost: Distinguish errors in vhost_dev_get_config(), Kevin Wolf, 2021/06/30
- [PULL 23/24] vhost-user-blk: Factor out vhost_user_blk_realize_connect(), Kevin Wolf, 2021/06/30
- [PULL 14/24] iotests: Test replacing files with x-blockdev-reopen, Kevin Wolf, 2021/06/30
- [PULL 20/24] vhost: Return 0/-errno in vhost_dev_init(), Kevin Wolf, 2021/06/30
- [PULL 24/24] vhost-user-blk: Implement reconnection during realize, Kevin Wolf, 2021/06/30
- [PULL 21/24] vhost-user-blk: Add Error parameter to vhost_user_blk_start(), Kevin Wolf, 2021/06/30
- [PULL 05/24] block: comment graph-modifying function not updating permissions, Kevin Wolf, 2021/06/30
- [PULL 19/24] vhost: Distinguish errors in vhost_backend_init(), Kevin Wolf, 2021/06/30