Use g_memdup2() where available and add fallback for older GLib versions

g_memdup() is deprecated since GLib 2.68 and we want to avoid
deprecation warnings with recent versions of GLib.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1171>
This commit is contained in:
Tim-Philipp Müller 2021-05-23 23:51:27 +01:00 committed by GStreamer Marge Bot
parent eb47c5aa2d
commit 577dabf7b1
11 changed files with 20 additions and 16 deletions

View file

@ -420,7 +420,7 @@ push_buffer (GstAlsaMidiSrc * alsamidisrc, gpointer data, guint size,
GST_BUFFER_DTS (buffer) = time;
GST_BUFFER_PTS (buffer) = time;
local_data = g_memdup (data, size);
local_data = g_memdup2 (data, size);
gst_buffer_append_memory (buffer,
gst_memory_new_wrapped (0, local_data, size, 0, size, local_data,

View file

@ -87,7 +87,7 @@ _ogg_packet_copy (const ogg_packet * packet)
ogg_packet *ret = g_slice_new (ogg_packet);
*ret = *packet;
ret->packet = g_memdup (packet->packet, packet->bytes);
ret->packet = g_memdup2 (packet->packet, packet->bytes);
return ret;
}
@ -105,9 +105,9 @@ gst_ogg_page_copy (ogg_page * page)
ogg_page *p = g_slice_new (ogg_page);
/* make a copy of the page */
p->header = g_memdup (page->header, page->header_len);
p->header = g_memdup2 (page->header, page->header_len);
p->header_len = page->header_len;
p->body = g_memdup (page->body, page->body_len);
p->body = g_memdup2 (page->body, page->body_len);
p->body_len = page->body_len;
return p;

View file

@ -512,7 +512,7 @@ fb_config_attributes_from_structure (GstStructure * config)
None
};
return g_memdup (attribs, sizeof (attribs));
return g_memdup2 (attribs, sizeof (attribs));
}
n = gst_structure_n_fields (config) * 2 + 1;

View file

@ -293,7 +293,7 @@ gst_riff_parse_strh (GstElement * element,
if (info.size < sizeof (gst_riff_strh))
goto too_small;
strh = g_memdup (info.data, info.size);
strh = g_memdup2 (info.data, info.size);
gst_buffer_unmap (buf, &info);
gst_buffer_unref (buf);
@ -384,7 +384,7 @@ gst_riff_parse_strf_vids (GstElement * element,
if (info.size < sizeof (gst_riff_strf_vids))
goto too_small;
strf = g_memdup (info.data, info.size);
strf = g_memdup2 (info.data, info.size);
gst_buffer_unmap (buf, &info);
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
@ -482,7 +482,7 @@ gst_riff_parse_strf_auds (GstElement * element,
if (info.size < sizeof (gst_riff_strf_auds))
goto too_small;
strf = g_memdup (info.data, info.size);
strf = g_memdup2 (info.data, info.size);
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
strf->format = GUINT16_FROM_LE (strf->format);
@ -574,7 +574,7 @@ gst_riff_parse_strf_iavs (GstElement * element,
if (info.size < sizeof (gst_riff_strf_iavs))
goto too_small;
strf = g_memdup (info.data, info.size);
strf = g_memdup2 (info.data, info.size);
gst_buffer_unmap (buf, &info);
gst_buffer_unref (buf);

View file

@ -84,7 +84,7 @@ gst_rtcp_buffer_new_take_data (gpointer data, guint len)
GstBuffer *
gst_rtcp_buffer_new_copy_data (gconstpointer data, guint len)
{
return gst_rtcp_buffer_new_take_data (g_memdup (data, len), len);
return gst_rtcp_buffer_new_take_data (g_memdup2 (data, len), len);
}
static gboolean
@ -1213,7 +1213,7 @@ gst_rtcp_packet_copy_profile_specific_ext (GstRTCPPacket * packet,
if (data != NULL) {
guint8 *ptr = packet->rtcp->map.data + packet->offset;
ptr += ((packet->length + 1 - pse_len) * sizeof (guint32));
*data = g_memdup (ptr, pse_len * sizeof (guint32));
*data = g_memdup2 (ptr, pse_len * sizeof (guint32));
}
return TRUE;

View file

@ -184,7 +184,7 @@ gst_rtp_buffer_new_take_data (gpointer data, gsize len)
GstBuffer *
gst_rtp_buffer_new_copy_data (gconstpointer data, gsize len)
{
return gst_rtp_buffer_new_take_data (g_memdup (data, len), len);
return gst_rtp_buffer_new_take_data (g_memdup2 (data, len), len);
}
/**

View file

@ -4519,7 +4519,7 @@ gst_rtsp_watch_write_serialized_messages (GstRTSPWatch * watch,
* we don't own them here */
if (local_message.body_data) {
local_message.body_data =
g_memdup (local_message.body_data, local_message.body_data_size);
g_memdup2 (local_message.body_data, local_message.body_data_size);
} else if (local_message.body_buffer) {
gst_buffer_ref (local_message.body_buffer);
}

View file

@ -943,7 +943,7 @@ gst_rtsp_message_set_body (GstRTSPMessage * msg, const guint8 * data,
{
g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL);
return gst_rtsp_message_take_body (msg, g_memdup (data, size), size);
return gst_rtsp_message_take_body (msg, g_memdup2 (data, size), size);
}
/**

View file

@ -66,7 +66,7 @@ G_STMT_START { \
#define INIT_MEMDUP(field, data, len) \
G_STMT_START { \
g_free ((field)); \
(field) = g_memdup (data, len); \
(field) = g_memdup2 (data, len); \
} G_STMT_END
#define FREE_MEMDUP(field) \
G_STMT_START { \

View file

@ -1031,7 +1031,7 @@ gst_buffer_add_video_caption_meta (GstBuffer * buffer,
g_return_val_if_fail (meta != NULL, NULL);
meta->caption_type = caption_type;
meta->data = g_memdup (data, size);
meta->data = g_memdup2 (data, size);
meta->size = size;
return meta;

View file

@ -527,6 +527,10 @@ if gst_version_nano == 0
endif
endif
if gio_dep.version().version_compare('< 2.67.4')
core_conf.set('g_memdup2(ptr,sz)', '(G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL)')
endif
# Use core_conf after all subdirs have set values
configure_file(output : 'config.h', configuration : core_conf)