[0.11] gstreamer: miniobject: cleanups
Wim Taymans
wtay at kemper.freedesktop.org
Thu Feb 24 05:00:59 PST 2011
Module: gstreamer
Branch: 0.11
Commit: b108e3b9992e7f31fdc84b6cf2344d87502bbd2d
URL: http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=b108e3b9992e7f31fdc84b6cf2344d87502bbd2d
Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date: Wed Feb 23 16:48:00 2011 +0100
miniobject: cleanups
Use the stored size in the miniobject to free the miniobject.
Refactor some init methods.
---
gst/gstbuffer.c | 29 +++++++++++++++++------------
gst/gstbufferlist.c | 20 +++++++++++++-------
gst/gstcaps.c | 13 ++++++-------
gst/gstevent.c | 13 ++++++-------
gst/gstmessage.c | 2 +-
gst/gstminiobject.h | 8 ++++++++
gst/gstquery.c | 2 +-
7 files changed, 52 insertions(+), 35 deletions(-)
diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c
index b51d19c..e0942fe 100644
--- a/gst/gstbuffer.c
+++ b/gst/gstbuffer.c
@@ -282,7 +282,22 @@ _gst_buffer_free (GstBuffer * buffer)
if (buffer->parent)
gst_buffer_unref (buffer->parent);
- g_slice_free (GstBuffer, buffer);
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (buffer), buffer);
+}
+
+static void
+gst_buffer_init (GstBuffer * buffer, gsize size)
+{
+ gst_mini_object_init (GST_MINI_OBJECT_CAST (buffer), _gst_buffer_type, size);
+
+ buffer->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_copy;
+ buffer->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_free;
+
+ GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
+ GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
+ GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
+ GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
+ GST_BUFFER_FREE_FUNC (buffer) = g_free;
}
/**
@@ -302,17 +317,7 @@ gst_buffer_new (void)
newbuf = g_slice_new0 (GstBuffer);
GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf);
- gst_mini_object_init (GST_MINI_OBJECT_CAST (newbuf),
- _gst_buffer_type, sizeof (GstBuffer));
-
- newbuf->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_copy;
- newbuf->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_free;
-
- GST_BUFFER_TIMESTAMP (newbuf) = GST_CLOCK_TIME_NONE;
- GST_BUFFER_DURATION (newbuf) = GST_CLOCK_TIME_NONE;
- GST_BUFFER_OFFSET (newbuf) = GST_BUFFER_OFFSET_NONE;
- GST_BUFFER_OFFSET_END (newbuf) = GST_BUFFER_OFFSET_NONE;
- GST_BUFFER_FREE_FUNC (newbuf) = g_free;
+ gst_buffer_init (newbuf, sizeof (GstBuffer));
return newbuf;
}
diff --git a/gst/gstbufferlist.c b/gst/gstbufferlist.c
index b801c0d..02c6aaa 100644
--- a/gst/gstbufferlist.c
+++ b/gst/gstbufferlist.c
@@ -212,7 +212,17 @@ _gst_buffer_list_free (GstBufferList * list)
}
g_list_free (list->buffers);
- g_slice_free (GstBufferList, list);
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (list), list);
+}
+
+static void
+gst_buffer_list_init (GstBufferList * list, gsize size)
+{
+ gst_mini_object_init (GST_MINI_OBJECT_CAST (list), _gst_buffer_list_type,
+ size);
+
+ list->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_list_copy;
+ list->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_list_free;
}
/**
@@ -235,14 +245,10 @@ gst_buffer_list_new (void)
list = g_slice_new0 (GstBufferList);
- gst_mini_object_init (GST_MINI_OBJECT_CAST (list), _gst_buffer_list_type,
- sizeof (GstBufferList));
-
- list->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_list_copy;
- list->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_list_free;
-
GST_LOG ("new %p", list);
+ gst_buffer_list_init (list, sizeof (GstBufferList));
+
return list;
}
diff --git a/gst/gstcaps.c b/gst/gstcaps.c
index 45364cd..aea103f 100644
--- a/gst/gstcaps.c
+++ b/gst/gstcaps.c
@@ -181,14 +181,13 @@ _gst_caps_free (GstCaps * caps)
#ifdef DEBUG_REFCOUNT
GST_CAT_LOG (GST_CAT_CAPS, "freeing caps %p", caps);
#endif
- g_slice_free (GstCaps, caps);
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (caps), caps);
}
static void
-gst_caps_init (GstCaps * caps)
+gst_caps_init (GstCaps * caps, gsize size)
{
- gst_mini_object_init (GST_MINI_OBJECT_CAST (caps),
- _gst_caps_type, sizeof (GstCaps));
+ gst_mini_object_init (GST_MINI_OBJECT_CAST (caps), _gst_caps_type, size);
caps->mini_object.copy = (GstMiniObjectCopyFunction) _gst_caps_copy;
caps->mini_object.dispose = NULL;
@@ -218,7 +217,7 @@ gst_caps_new_empty (void)
caps = g_slice_new (GstCaps);
- gst_caps_init (caps);
+ gst_caps_init (caps, sizeof (GstCaps));
#ifdef DEBUG_REFCOUNT
GST_CAT_LOG (GST_CAT_CAPS, "created caps %p", caps);
@@ -415,13 +414,13 @@ gst_static_caps_get (GstStaticCaps * static_caps)
* real caps, refcount last. We do this because we must leave the refcount
* of the result caps to 0 so that other threads don't run away with the
* caps while we are constructing it. */
- gst_caps_init (&temp);
+ gst_caps_init (&temp, sizeof (GstCaps));
/* convert to string */
if (G_UNLIKELY (!gst_caps_from_string_inplace (&temp, string)))
g_critical ("Could not convert static caps \"%s\"", string);
- gst_caps_init (caps);
+ gst_caps_init (caps, sizeof (GstCaps));
/* now copy stuff over to the real caps. */
GST_CAPS_FLAGS (caps) = GST_CAPS_FLAGS (&temp);
caps->structs = temp.structs;
diff --git a/gst/gstevent.c b/gst/gstevent.c
index b7d0eaf..9f7057b 100644
--- a/gst/gstevent.c
+++ b/gst/gstevent.c
@@ -216,10 +216,10 @@ _gst_event_free (GstEvent * event)
gst_structure_free (event->structure);
}
- g_slice_free (GstEvent, event);
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event);
}
-static void gst_event_init (GstEvent * event, GstEventType type);
+static void gst_event_init (GstEvent * event, gsize size, GstEventType type);
static GstEvent *
_gst_event_copy (GstEvent * event)
@@ -228,7 +228,7 @@ _gst_event_copy (GstEvent * event)
copy = g_slice_new0 (GstEvent);
- gst_event_init (copy, GST_EVENT_TYPE (event));
+ gst_event_init (copy, sizeof (GstEvent), GST_EVENT_TYPE (event));
GST_EVENT_TIMESTAMP (copy) = GST_EVENT_TIMESTAMP (event);
GST_EVENT_SEQNUM (copy) = GST_EVENT_SEQNUM (event);
@@ -245,10 +245,9 @@ _gst_event_copy (GstEvent * event)
}
static void
-gst_event_init (GstEvent * event, GstEventType type)
+gst_event_init (GstEvent * event, gsize size, GstEventType type)
{
- gst_mini_object_init (GST_MINI_OBJECT_CAST (event),
- _gst_event_type, sizeof (GstEvent));
+ gst_mini_object_init (GST_MINI_OBJECT_CAST (event), _gst_event_type, size);
event->mini_object.copy = (GstMiniObjectCopyFunction) _gst_event_copy;
event->mini_object.free = (GstMiniObjectFreeFunction) _gst_event_free;
@@ -268,7 +267,7 @@ gst_event_new (GstEventType type)
GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event,
gst_event_type_get_name (type), type);
- gst_event_init (event, type);
+ gst_event_init (event, sizeof (GstEvent), type);
return event;
}
diff --git a/gst/gstmessage.c b/gst/gstmessage.c
index c33d469..6750f2a 100644
--- a/gst/gstmessage.c
+++ b/gst/gstmessage.c
@@ -191,7 +191,7 @@ _gst_message_free (GstMessage * message)
gst_structure_free (message->structure);
}
- g_slice_free (GstMessage, message);
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message);
}
static GstMessage *
diff --git a/gst/gstminiobject.h b/gst/gstminiobject.h
index faf10c4..eef6dd9 100644
--- a/gst/gstminiobject.h
+++ b/gst/gstminiobject.h
@@ -134,6 +134,14 @@ typedef enum
#define GST_MINI_OBJECT_REFCOUNT_VALUE(obj) (g_atomic_int_get (&(GST_MINI_OBJECT_CAST(obj))->refcount))
/**
+ * GST_MINI_OBJECT_SIZE:
+ * @obj: a #GstMiniObject
+ *
+ * Get the allocated size of @obj.
+ */
+#define GST_MINI_OBJECT_SIZE(obj) ((GST_MINI_OBJECT_CAST(obj))->size)
+
+/**
* GstMiniObject:
* @instance: type instance
* @refcount: atomic refcount
diff --git a/gst/gstquery.c b/gst/gstquery.c
index 4883913..8516775 100644
--- a/gst/gstquery.c
+++ b/gst/gstquery.c
@@ -319,7 +319,7 @@ _gst_query_free (GstQuery * query)
gst_structure_free (query->structure);
}
- g_slice_free (GstQuery, query);
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
}
static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
More information about the gstreamer-commits
mailing list