[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 02/28] glib-compat: Introduce g_memdup2() wrapper
From: |
Daniel P . Berrangé |
Subject: |
Re: [PATCH 02/28] glib-compat: Introduce g_memdup2() wrapper |
Date: |
Fri, 3 Sep 2021 12:56:22 +0100 |
User-agent: |
Mutt/2.0.7 (2021-05-04) |
On Fri, Sep 03, 2021 at 02:51:21PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> That was most probably already discussed, so sorry my question:
>
> Why we can't just do
>
> #if ! GLIB_CHECK_VERSION(2, 68, 0)
> static inline gpointer g_memdup2(gconstpointer mem, gsize byte_size)
> {
> gpointer new_mem;
>
> if (mem && byte_size != 0) {
> new_mem = g_malloc(byte_size);
> memcpy(new_mem, mem, byte_size);
> } else {
> new_mem = NULL;
> }
>
> return new_mem;
> }
> #endif
>
> ?
This doesn't play with GLIB_VERSION_MAX_ALLOWED - any use of
g_memdup2 will trigger compile warnings since we're using an
API that only exists in a glib version newer than our declared
baseline.
The inline wrapper + macro is a trick that lets us backport
new features, while avoiding the compile warnings.
This is documented in the include/glib-compat.h file that Philippe
is modifying.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
[PATCH 03/28] qapi: Replace g_memdup() by g_memdup2_qemu(), Philippe Mathieu-Daudé, 2021/09/03
[PATCH 04/28] accel/tcg: Replace g_memdup() by g_memdup2_qemu(), Philippe Mathieu-Daudé, 2021/09/03
[PATCH 05/28] block/qcow2-bitmap: Replace g_memdup() by g_memdup2_qemu(), Philippe Mathieu-Daudé, 2021/09/03
[PATCH 06/28] softmmu: Replace g_memdup() by g_memdup2_qemu(), Philippe Mathieu-Daudé, 2021/09/03
[PATCH 07/28] hw/9pfs: Replace g_memdup() by g_memdup2_qemu(), Philippe Mathieu-Daudé, 2021/09/03
[PATCH 08/28] hw/acpi: Avoid truncating acpi_data_len() to 32-bit, Philippe Mathieu-Daudé, 2021/09/03