[glib/buffer] Add g_buffer_new_take_data()
- From: Ryan Lortie <ryanl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib/buffer] Add g_buffer_new_take_data()
- Date: Sat, 6 Feb 2010 02:13:45 +0000 (UTC)
commit bc45d202351291e338ba6576ae0862aac32924ce
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Feb 5 21:11:58 2010 -0500
Add g_buffer_new_take_data()
glib/gbuffer.c | 31 +++++++++++++++++++++++++++++++
glib/gbuffer.h | 3 +++
2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/glib/gbuffer.c b/glib/gbuffer.c
index 7eec6e6..4dc5d24 100644
--- a/glib/gbuffer.c
+++ b/glib/gbuffer.c
@@ -68,6 +68,37 @@ g_buffer_new_from_data (gconstpointer data,
return buffer;
}
+/* < private >
+ * g_buffer_new_take_data:
+ * @data: the data to be used for the buffer
+ * @size: the size of @data
+ * returns: a reference to a new #GBuffer
+ *
+ * Creates a new #GBuffer from @data.
+ *
+ * @data must have been created by a call to g_malloc(), g_malloc0() or
+ * g_realloc() or by one of the many functions that wrap these calls
+ * (such as g_new(), g_strdup(), etc).
+ *
+ * After this call, @data belongs to the buffer and may no longer be
+ * accessed by the caller. g_free() will be called on @data at an
+ * unspecified point (perhaps before this call returns).
+ */
+GBuffer *
+g_buffer_new_take_data (gpointer data,
+ gsize size)
+{
+ GBuffer *buffer;
+
+ buffer = g_slice_new (GBuffer);
+ buffer->data = data;
+ buffer->size = size;
+ buffer->free_func = g_buffer_free_gfree;
+ buffer->ref_count = 1;
+
+ return buffer;
+}
+
static void
g_buffer_free (GBuffer *buffer)
{
diff --git a/glib/gbuffer.h b/glib/gbuffer.h
index 9107238..405904b 100644
--- a/glib/gbuffer.h
+++ b/glib/gbuffer.h
@@ -70,6 +70,9 @@ G_GNUC_INTERNAL
GBuffer * g_buffer_new_from_data (gconstpointer data,
gsize size);
G_GNUC_INTERNAL
+GBuffer * g_buffer_new_take_data (gpointer data,
+ gsize size);
+G_GNUC_INTERNAL
GBuffer * g_buffer_new_from_static_data (gconstpointer data,
gsize size);
G_GNUC_INTERNAL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]