+2006-05-05 Wim Taymans <wim@fluendo.com>
+
+ * gst/glib-compat.c:
+ * gst/gst.c: (init_pre):
+ * gst/gstobject.c: (gst_object_init), (gst_object_ref),
+ (gst_object_unref), (gst_object_replace), (gst_object_dispose),
+ (gst_object_dispatch_properties_changed):
+ * gst/gstobject.h:
+ * gst/gstregistryxml.c: (gst_registry_xml_read_cache):
+ * gst/gststructure.c: (gst_structure_set_valist):
+ * gst/gstvalue.c: (gst_date_get_type), (_gst_value_initialize):
+ Remove pre glib2.8 compatibility, fixes #340508
+
2006-05-04 Tim-Philipp Müller <tim at centricular dot net>
* gst/gsttaglist.h:
#endif
-#if !GLIB_CHECK_VERSION (2, 8, 0)
-/**
- * g_mkdir_with_parents:
- * @pathname: a pathname in the GLib file name encoding
- * @mode: permissions to use for newly created directories
- *
- * Create a directory if it doesn't already exist. Create intermediate
- * parent directories as needed, too.
- *
- * Returns: 0 if the directory already exists, or was successfully
- * created. Returns -1 if an error occurred, with errno set.
- *
- * Since: 2.8
- */
-int
-g_mkdir_with_parents (const gchar * pathname, int mode)
-{
- gchar *fn, *p;
-
- if (pathname == NULL || *pathname == '\0') {
- errno = EINVAL;
- return -1;
- }
-
- fn = g_strdup (pathname);
-
- if (g_path_is_absolute (fn))
- p = (gchar *) g_path_skip_root (fn);
- else
- p = fn;
-
- do {
- while (*p && !G_IS_DIR_SEPARATOR (*p))
- p++;
-
- if (!*p)
- p = NULL;
- else
- *p = '\0';
-
- if (!g_file_test (fn, G_FILE_TEST_EXISTS)) {
- if (g_mkdir (fn, mode) == -1) {
- int errno_save = errno;
-
- g_free (fn);
- errno = errno_save;
- return -1;
- }
- } else if (!g_file_test (fn, G_FILE_TEST_IS_DIR)) {
- g_free (fn);
- errno = ENOTDIR;
- return -1;
- }
- if (p) {
- *p++ = G_DIR_SEPARATOR;
- while (*p && G_IS_DIR_SEPARATOR (*p))
- p++;
- }
- }
- while (p);
-
- g_free (fn);
-
- return 0;
-}
-#endif
-
-
/**
* gst_flags_get_first_value:
* @flags_class: a #GFlagsClass
}
#endif
-#ifndef GST_HAVE_GLIB_2_8
-#define G_OPTION_FLAG_NO_ARG 0
-#endif
-
/**
* gst_init_get_option_group:
*
static gboolean
init_pre (void)
{
-#ifdef GST_HAVE_GLIB_2_8
/* GStreamer was built against a GLib >= 2.8 and is therefore not doing
* the refcount hack. Check that it isn't being run against an older GLib */
if (glib_major_version < 2 ||
(glib_major_version == 2 && glib_minor_version < 8)) {
-#else
- /* GStreamer was built against a GLib < 2.8 and is therefore doing
- * the refcount hack. Check that it isn't being run against a newer GLib */
- if (glib_major_version > 2 ||
- (glib_major_version == 2 && glib_minor_version >= 8)) {
-#endif
g_warning ("GStreamer was compiled against GLib %d.%d.%d but is running"
" against %d.%d.%d. This will cause reference counting issues",
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION,
#endif
#define DEBUG_REFCOUNT
-#ifndef GST_HAVE_GLIB_2_8
-#define REFCOUNT_HACK
-#endif
-
-/* Refcount hack: since glib < 2.8 is not threadsafe, the glib refcounter can be
- * screwed up and the object can be freed unexpectedly. We use an evil hack
- * to work around this problem. We set the glib refcount to a high value so
- * that glib will never unref the object under realistic circumstances. Then
- * we use our own atomic refcounting to do proper MT safe refcounting.
- *
- * The hack has several side-effect. At first you should use
- * gst_object_ref/unref() whenever you can. Next when using
- * g_value_set/get_object(); you need to manually fix the refcount.
- *
- * A proper fix is of course to upgrade to glib 2.8
- */
-#ifdef REFCOUNT_HACK
-#define PATCH_REFCOUNT(obj) ((GObject*)(obj))->ref_count = 100000;
-#define PATCH_REFCOUNT1(obj) ((GObject*)(obj))->ref_count = 1;
-#else
-#define PATCH_REFCOUNT(obj)
-#define PATCH_REFCOUNT1(obj)
-#endif
/* Object signals and args */
enum
object->parent = NULL;
object->name = NULL;
GST_CAT_LOG_OBJECT (GST_CAT_REFCOUNTING, object, "%p new", object);
-#ifdef REFCOUNT_HACK
- gst_atomic_int_set (&object->refcount, 1);
-#endif
- PATCH_REFCOUNT (object);
#ifndef GST_DISABLE_TRACE
gst_alloc_trace_new (_gst_object_trace, object);
gpointer
gst_object_ref (gpointer object)
{
-#ifdef REFCOUNT_HACK
- gint old;
-#endif
-
g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
-#ifdef REFCOUNT_HACK
- old = g_atomic_int_exchange_and_add (&((GstObject *) object)->refcount, 1);
-# ifdef DEBUG_REFCOUNT
- GST_CAT_LOG_OBJECT (GST_CAT_REFCOUNTING, object, "%p ref %d->%d",
- object, old, old + 1);
-# endif
- PATCH_REFCOUNT (object);
-#else
-# ifdef DEBUG_REFCOUNT
+#ifdef DEBUG_REFCOUNT
GST_CAT_LOG_OBJECT (GST_CAT_REFCOUNTING, object, "%p ref %d->%d",
object,
((GObject *) object)->ref_count, ((GObject *) object)->ref_count + 1);
-# endif
- g_object_ref (object);
#endif
+ g_object_ref (object);
return object;
}
void
gst_object_unref (gpointer object)
{
-#ifdef REFCOUNT_HACK
- gint old;
-#endif
g_return_if_fail (GST_IS_OBJECT (object));
-
-#ifdef REFCOUNT_HACK
- g_return_if_fail (GST_OBJECT_REFCOUNT_VALUE (object) > 0);
-
- old = g_atomic_int_exchange_and_add (&((GstObject *) object)->refcount, -1);
-
-# ifdef DEBUG_REFCOUNT
- GST_CAT_LOG_OBJECT (GST_CAT_REFCOUNTING, object, "%p unref %d->%d",
- object, old, old - 1);
-#endif
- if (G_UNLIKELY (old == 1)) {
- PATCH_REFCOUNT1 (object);
- g_object_unref (object);
- } else {
- PATCH_REFCOUNT (object);
- }
-#else
g_return_if_fail (((GObject *) object)->ref_count > 0);
#ifdef DEBUG_REFCOUNT
((GObject *) object)->ref_count, ((GObject *) object)->ref_count - 1);
#endif
g_object_unref (object);
-#endif
}
/**
g_return_if_fail (newobj == NULL || GST_IS_OBJECT (newobj));
#ifdef DEBUG_REFCOUNT
-#ifdef REFCOUNT_HACK
- GST_CAT_LOG (GST_CAT_REFCOUNTING, "replace %s (%d) with %s (%d)",
- *oldobj ? GST_STR_NULL (GST_OBJECT_NAME (*oldobj)) : "(NONE)",
- *oldobj ? GST_OBJECT_REFCOUNT_VALUE (*oldobj) : 0,
- newobj ? GST_STR_NULL (GST_OBJECT_NAME (newobj)) : "(NONE)",
- newobj ? GST_OBJECT_REFCOUNT_VALUE (newobj) : 0);
-#else
GST_CAT_LOG (GST_CAT_REFCOUNTING, "replace %s (%d) with %s (%d)",
*oldobj ? GST_STR_NULL (GST_OBJECT_NAME (*oldobj)) : "(NONE)",
*oldobj ? G_OBJECT (*oldobj)->ref_count : 0,
newobj ? GST_STR_NULL (GST_OBJECT_NAME (newobj)) : "(NONE)",
newobj ? G_OBJECT (newobj)->ref_count : 0);
#endif
-#endif
if (G_LIKELY (*oldobj != newobj)) {
if (newobj)
GST_OBJECT_PARENT (object) = NULL;
GST_OBJECT_UNLOCK (object);
- /* need to patch refcount so it is finalized */
- PATCH_REFCOUNT1 (object);
-
parent_class->dispose (object);
return;
"object instead of unreffing the object directly.\n",
GST_OBJECT_NAME (object), GST_OBJECT_NAME (parent));
GST_OBJECT_UNLOCK (object);
+ /* ref the object again to revive it in this error case */
object = gst_object_ref (object);
return;
}
klass = GST_OBJECT_GET_CLASS (object);
-#ifndef GST_HAVE_GLIB_2_8
- GST_CLASS_LOCK (klass);
-#endif
-
/* do the standard dispatching */
- PATCH_REFCOUNT (object);
G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object, n_pspecs,
pspecs);
- PATCH_REFCOUNT (object);
gst_object = GST_OBJECT_CAST (object);
name = gst_object_get_name (gst_object);
GST_CAT_LOG (GST_CAT_EVENT, "deep notification from %s to %s (%s)",
debug_name, debug_parent_name, pspecs[i]->name);
- /* not MT safe because of glib, fixed by taking class lock higher up */
- PATCH_REFCOUNT (parent);
- PATCH_REFCOUNT (object);
g_signal_emit (parent, gst_object_signals[DEEP_NOTIFY],
g_quark_from_string (pspecs[i]->name), GST_OBJECT_CAST (object),
pspecs[i]);
- PATCH_REFCOUNT (parent);
- PATCH_REFCOUNT (object);
}
g_free (parent_name);
gst_object_unref (old_parent);
}
g_free (name);
-
-#ifndef GST_HAVE_GLIB_2_8
- GST_CLASS_UNLOCK (klass);
-#endif
}
/**
GST_OBJECT_FLAG_LAST = (1<<4)
} GstObjectFlags;
-#ifdef GST_HAVE_GLIB_2_8
/**
* GST_OBJECT_REFCOUNT:
* @obj: a #GstObject
*
* Get the reference count value of the object.
*/
-#define GST_OBJECT_REFCOUNT_VALUE(obj) GST_OBJECT_REFCOUNT(obj)
-#else
-#define GST_OBJECT_REFCOUNT(obj) ((GST_OBJECT_CAST(obj))->refcount)
-#define GST_OBJECT_REFCOUNT_VALUE(obj) (g_atomic_int_get (&(GST_OBJECT_CAST(obj))->refcount))
-#endif /* GST_HAVE_GLIB_2_8 */
+#define GST_OBJECT_REFCOUNT_VALUE(obj) g_atomic_int_get (&GST_OBJECT_REFCOUNT(obj))
/* we do a GST_OBJECT_CAST to avoid type checking, better call these
* function with a valid object! */
/**
* GstObject:
- * @refcount: only used ifndef GST_HAVE_GLIB_2_8
+ * @refcount: unused
* @lock: object LOCK
* @name: The name of the object
* @name_prefix: used for debugging
gboolean
gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
{
-#if GLIB_CHECK_VERSION(2,8,0)
GMappedFile *mapped = NULL;
-#endif
GTimer *timer;
gdouble seconds;
xmlTextReaderPtr reader = NULL;
timer = g_timer_new ();
-#if GLIB_CHECK_VERSION(2,8,0)
mapped = g_mapped_file_new (location, FALSE, NULL);
if (mapped) {
reader = xmlReaderForMemory (g_mapped_file_get_contents (mapped),
mapped = NULL;
}
}
-#endif
if (reader == NULL) {
file = fopen (location, "r");
xmlFreeTextReader (reader);
if (ret != 0) {
GST_ERROR ("parsing registry cache: %s", location);
-#if GLIB_CHECK_VERSION(2,8,0)
if (mapped)
g_mapped_file_free (mapped);
-#endif
if (file)
fclose (file);
g_timer_destroy (timer);
GST_INFO ("loaded %s in %f seconds", location, seconds);
-#if GLIB_CHECK_VERSION(2,8,0)
if (mapped)
g_mapped_file_free (mapped);
-#endif
if (file)
fclose (file);
type = va_arg (varargs, GType);
-#if GLIB_CHECK_VERSION(2,8,0)
if (type == G_TYPE_DATE) {
g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n");
type = GST_TYPE_DATE;
}
-#endif
g_value_init (&field.value, type);
G_VALUE_COLLECT (&field.value, varargs, 0, &err);
/* Not using G_TYPE_DATE here on purpose, even if we could
* if GLIB_CHECK_VERSION(2,8,0) was true: we don't want the
* serialised strings to have different type strings depending
- * on what version is used, so FIXME in 0.11 when we
+ * on what version is used, so FIXME when we
* require GLib-2.8 */
gst_date_type = g_boxed_type_register_static ("GstDate",
(GBoxedCopyFunc) gst_date_copy, (GBoxedFreeFunc) g_date_free);
GST_TYPE_FRACTION_RANGE,
gst_value_subtract_fraction_range_fraction_range);
-#if GLIB_CHECK_VERSION(2,8,0)
/* see bug #317246, #64994, #65041 */
{
volatile GType date_type = G_TYPE_DATE;
g_type_name (date_type);
}
-#endif
gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
gst_value_union_int_int_range);