mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 16:26:39 +00:00
gst/glib-compat-private.h: Add compatibility macro for g_intern_string() for
Original commit message from CVS: * gst/glib-compat-private.h: Add compatibility macro for g_intern_string() for GLib-2.8 (any reason we can't just bump the requirement to at least 2.10?) * gst/gstpadtemplate.h: * gst/gstelementfactory.c: * gst/gstregistryxml.c: * gst/gstregistrybinary.c: Make GstStaticPadTemplate's templ_name field a const gchar * and fix up the internal code accordingly. This shouldn't be a problem, since there is no reason external code could ever assume the string in such a structure is dynamically allocated unless it did that itself; the use of g_strdup() is private to element factories. The new code also saves some memory by putting pad template name strings into the GLib quark table instead of allocating them dynamically. Declaring this field constant fixes warnings with g++-4.2 when using the GST_STATIC_PAD_TEMPLATE macro in c++ code (#478092).
This commit is contained in:
parent
1740781a70
commit
7a478fbdbd
6 changed files with 45 additions and 12 deletions
21
ChangeLog
21
ChangeLog
|
@ -1,3 +1,24 @@
|
||||||
|
2007-09-19 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
|
* gst/glib-compat-private.h:
|
||||||
|
Add compatibility macro for g_intern_string() for
|
||||||
|
GLib-2.8 (any reason we can't just bump the
|
||||||
|
requirement to at least 2.10?)
|
||||||
|
|
||||||
|
* gst/gstpadtemplate.h:
|
||||||
|
* gst/gstelementfactory.c:
|
||||||
|
* gst/gstregistryxml.c:
|
||||||
|
* gst/gstregistrybinary.c:
|
||||||
|
Make GstStaticPadTemplate's templ_name field a const gchar * and fix
|
||||||
|
up the internal code accordingly. This shouldn't be a problem, since
|
||||||
|
there is no reason external code could ever assume the string in such
|
||||||
|
a structure is dynamically allocated unless it did that itself; the
|
||||||
|
use of g_strdup() is private to element factories. The new code also
|
||||||
|
saves some memory by putting pad template name strings into the GLib
|
||||||
|
quark table instead of allocating them dynamically.
|
||||||
|
Declaring this field constant fixes warnings with g++-4.2 when using
|
||||||
|
the GST_STATIC_PAD_TEMPLATE macro in c++ code (#478092).
|
||||||
|
|
||||||
2007-09-19 Stefan Kost <ensonic@users.sf.net>
|
2007-09-19 Stefan Kost <ensonic@users.sf.net>
|
||||||
|
|
||||||
* gst/gstelementfactory.c:
|
* gst/gstelementfactory.c:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* glib-compat.c
|
* glib-compat.c
|
||||||
* Functions copied from glib 2.8
|
* Functions copied from glib 2.10
|
||||||
*
|
*
|
||||||
* Copyright 2005 David Schleef <ds@schleef.org>
|
* Copyright 2005 David Schleef <ds@schleef.org>
|
||||||
*/
|
*/
|
||||||
|
@ -14,4 +14,9 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
/* adaptations */
|
/* adaptations */
|
||||||
|
|
||||||
|
/* FIXME: remove once we depend on GLib 2.10 */
|
||||||
|
#if (!GLIB_CHECK_VERSION (2, 10, 0))
|
||||||
|
#define g_intern_string(s) g_quark_to_string(g_quark_from_string(s))
|
||||||
|
#endif
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
@ -61,6 +61,8 @@
|
||||||
#include "gsturi.h"
|
#include "gsturi.h"
|
||||||
#include "gstregistry.h"
|
#include "gstregistry.h"
|
||||||
|
|
||||||
|
#include "glib-compat-private.h"
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (element_factory_debug);
|
GST_DEBUG_CATEGORY_STATIC (element_factory_debug);
|
||||||
#define GST_CAT_DEFAULT element_factory_debug
|
#define GST_CAT_DEFAULT element_factory_debug
|
||||||
|
|
||||||
|
@ -219,7 +221,6 @@ gst_element_factory_cleanup (GstElementFactory * factory)
|
||||||
GstStaticPadTemplate *templ = item->data;
|
GstStaticPadTemplate *templ = item->data;
|
||||||
GstCaps *caps = (GstCaps *) & (templ->static_caps);
|
GstCaps *caps = (GstCaps *) & (templ->static_caps);
|
||||||
|
|
||||||
g_free (templ->name_template);
|
|
||||||
g_free ((gchar *) templ->static_caps.string);
|
g_free ((gchar *) templ->static_caps.string);
|
||||||
|
|
||||||
/* FIXME: this is not threadsafe */
|
/* FIXME: this is not threadsafe */
|
||||||
|
@ -293,7 +294,7 @@ gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
|
||||||
GstStaticPadTemplate *newt;
|
GstStaticPadTemplate *newt;
|
||||||
|
|
||||||
newt = g_new0 (GstStaticPadTemplate, 1);
|
newt = g_new0 (GstStaticPadTemplate, 1);
|
||||||
newt->name_template = g_strdup (templ->name_template);
|
newt->name_template = g_intern_string (templ->name_template);
|
||||||
newt->direction = templ->direction;
|
newt->direction = templ->direction;
|
||||||
newt->presence = templ->presence;
|
newt->presence = templ->presence;
|
||||||
newt->static_caps.string = gst_caps_to_string (templ->caps);
|
newt->static_caps.string = gst_caps_to_string (templ->caps);
|
||||||
|
|
|
@ -151,15 +151,15 @@ struct _GstPadTemplateClass {
|
||||||
* Structure describing the #GstStaticPadTemplate.
|
* Structure describing the #GstStaticPadTemplate.
|
||||||
*/
|
*/
|
||||||
struct _GstStaticPadTemplate {
|
struct _GstStaticPadTemplate {
|
||||||
gchar *name_template;
|
const gchar *name_template;
|
||||||
GstPadDirection direction;
|
GstPadDirection direction;
|
||||||
GstPadPresence presence;
|
GstPadPresence presence;
|
||||||
GstStaticCaps static_caps;
|
GstStaticCaps static_caps;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GST_STATIC_PAD_TEMPLATE:
|
* GST_STATIC_PAD_TEMPLATE:
|
||||||
* @padname: the name template of pad
|
* @padname: the name template of the pad
|
||||||
* @dir: the GstPadDirection of the pad
|
* @dir: the GstPadDirection of the pad
|
||||||
* @pres: the GstPadPresence of the pad
|
* @pres: the GstPadPresence of the pad
|
||||||
* @caps: the GstStaticCaps of the pad
|
* @caps: the GstStaticCaps of the pad
|
||||||
|
|
|
@ -65,6 +65,8 @@
|
||||||
|
|
||||||
#include <glib/gstdio.h> /* for g_stat(), g_mapped_file(), ... */
|
#include <glib/gstdio.h> /* for g_stat(), g_mapped_file(), ... */
|
||||||
|
|
||||||
|
#include "glib-compat-private.h"
|
||||||
|
|
||||||
|
|
||||||
#define GST_CAT_DEFAULT GST_CAT_REGISTRY
|
#define GST_CAT_DEFAULT GST_CAT_REGISTRY
|
||||||
|
|
||||||
|
@ -74,6 +76,10 @@
|
||||||
_outptr = (_element *)_inptr; \
|
_outptr = (_element *)_inptr; \
|
||||||
_inptr += sizeof (_element)
|
_inptr += sizeof (_element)
|
||||||
|
|
||||||
|
#define unpack_const_string(_inptr, _outptr) \
|
||||||
|
_outptr = g_intern_string ((const gchar *)_inptr); \
|
||||||
|
_inptr += strlen(_outptr) + 1
|
||||||
|
|
||||||
#define unpack_string(_inptr, _outptr) \
|
#define unpack_string(_inptr, _outptr) \
|
||||||
_outptr = g_strdup ((gchar *)_inptr); \
|
_outptr = g_strdup ((gchar *)_inptr); \
|
||||||
_inptr += strlen(_outptr) + 1
|
_inptr += strlen(_outptr) + 1
|
||||||
|
@ -151,12 +157,12 @@ gst_registry_binary_initialize_magic (GstBinaryRegistryMagic * m)
|
||||||
* Returns: %TRUE for success
|
* Returns: %TRUE for success
|
||||||
*/
|
*/
|
||||||
inline static gboolean
|
inline static gboolean
|
||||||
gst_registry_binary_save_const_string (GList ** list, gchar * str)
|
gst_registry_binary_save_const_string (GList ** list, const gchar * str)
|
||||||
{
|
{
|
||||||
GstBinaryChunk *chunk;
|
GstBinaryChunk *chunk;
|
||||||
|
|
||||||
chunk = g_malloc (sizeof (GstBinaryChunk));
|
chunk = g_malloc (sizeof (GstBinaryChunk));
|
||||||
chunk->data = str;
|
chunk->data = (gpointer) str;
|
||||||
chunk->size = strlen ((gchar *) chunk->data) + 1;
|
chunk->size = strlen ((gchar *) chunk->data) + 1;
|
||||||
chunk->flags = GST_BINARY_REGISTRY_FLAG_CONST;
|
chunk->flags = GST_BINARY_REGISTRY_FLAG_CONST;
|
||||||
chunk->align = FALSE;
|
chunk->align = FALSE;
|
||||||
|
@ -624,7 +630,7 @@ gst_registry_binary_load_pad_template (GstElementFactory * factory, gchar ** in)
|
||||||
template->direction = pt->direction;
|
template->direction = pt->direction;
|
||||||
|
|
||||||
/* unpack pad template strings */
|
/* unpack pad template strings */
|
||||||
unpack_string (*in, template->name_template);
|
unpack_const_string (*in, template->name_template);
|
||||||
unpack_string (*in, template->static_caps.string);
|
unpack_string (*in, template->static_caps.string);
|
||||||
|
|
||||||
__gst_element_factory_add_static_pad_template (factory, template);
|
__gst_element_factory_add_static_pad_template (factory, template);
|
||||||
|
|
|
@ -208,7 +208,7 @@ load_pad_template (xmlTextReaderPtr reader)
|
||||||
GstStaticPadTemplate *template;
|
GstStaticPadTemplate *template;
|
||||||
|
|
||||||
template = g_new0 (GstStaticPadTemplate, 1);
|
template = g_new0 (GstStaticPadTemplate, 1);
|
||||||
template->name_template = name;
|
template->name_template = g_intern_string (name);
|
||||||
template->presence = presence;
|
template->presence = presence;
|
||||||
template->direction = direction;
|
template->direction = direction;
|
||||||
template->static_caps.string = caps_str;
|
template->static_caps.string = caps_str;
|
||||||
|
@ -585,8 +585,8 @@ gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
|
||||||
* Save
|
* Save
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_registry_save_escaped (GstRegistry * registry, char *prefix, char *tag,
|
gst_registry_save_escaped (GstRegistry * registry, const char *prefix,
|
||||||
char *value)
|
const char *tag, const char *value)
|
||||||
{
|
{
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue