qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 02/28] glib-compat: Introduce g_memdup2() wrapper


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [PATCH 02/28] glib-compat: Introduce g_memdup2() wrapper
Date: Fri, 3 Sep 2021 15:03:33 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

03.09.2021 14:56, Daniel P. Berrangé wrote:
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.

Ah right, with macro, compiler doesn't see g_memdup2() invocations in code. 
Thanks!


This is documented in the include/glib-compat.h file that Philippe
is modifying.

Regards,
Daniel



--
Best regards,
Vladimir



reply via email to

[Prev in Thread] Current Thread [Next in Thread]