[jira] [Commented] (ARROW-2261) [GLib] Can't share the same memory in GArrowBuffer safely

2018-03-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/ARROW-2261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16388395#comment-16388395
 ] 

ASF GitHub Bot commented on ARROW-2261:
---

xhochy closed pull request #1701: ARROW-2261: [GLib] Improve memory management 
for GArrowBuffer data
URL: https://github.com/apache/arrow/pull/1701
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/c_glib/arrow-glib/buffer.cpp b/c_glib/arrow-glib/buffer.cpp
index 4be8fed18..4dd9ce33a 100644
--- a/c_glib/arrow-glib/buffer.cpp
+++ b/c_glib/arrow-glib/buffer.cpp
@@ -47,11 +47,13 @@ G_BEGIN_DECLS
 
 typedef struct GArrowBufferPrivate_ {
   std::shared_ptr buffer;
+  GBytes *data;
 } GArrowBufferPrivate;
 
 enum {
   PROP_0,
-  PROP_BUFFER
+  PROP_BUFFER,
+  PROP_DATA
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE(GArrowBuffer, garrow_buffer, G_TYPE_OBJECT)
@@ -59,6 +61,19 @@ G_DEFINE_TYPE_WITH_PRIVATE(GArrowBuffer, garrow_buffer, 
G_TYPE_OBJECT)
 #define GARROW_BUFFER_GET_PRIVATE(obj) \
   (G_TYPE_INSTANCE_GET_PRIVATE((obj), GARROW_TYPE_BUFFER, GArrowBufferPrivate))
 
+static void
+garrow_buffer_dispose(GObject *object)
+{
+  auto priv = GARROW_BUFFER_GET_PRIVATE(object);
+
+  if (priv->data) {
+g_bytes_unref(priv->data);
+priv->data = nullptr;
+  }
+
+  G_OBJECT_CLASS(garrow_buffer_parent_class)->dispose(object);
+}
+
 static void
 garrow_buffer_finalize(GObject *object)
 {
@@ -71,9 +86,9 @@ garrow_buffer_finalize(GObject *object)
 
 static void
 garrow_buffer_set_property(GObject *object,
-  guint prop_id,
-  const GValue *value,
-  GParamSpec *pspec)
+   guint prop_id,
+   const GValue *value,
+   GParamSpec *pspec)
 {
   auto priv = GARROW_BUFFER_GET_PRIVATE(object);
 
@@ -82,6 +97,9 @@ garrow_buffer_set_property(GObject *object,
 priv->buffer =
   *static_cast(g_value_get_pointer(value));
 break;
+  case PROP_DATA:
+priv->data = static_cast(g_value_dup_boxed(value));
+break;
   default:
 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 break;
@@ -90,11 +108,16 @@ garrow_buffer_set_property(GObject *object,
 
 static void
 garrow_buffer_get_property(GObject *object,
-  guint prop_id,
-  GValue *value,
-  GParamSpec *pspec)
+   guint prop_id,
+   GValue *value,
+   GParamSpec *pspec)
 {
+  auto priv = GARROW_BUFFER_GET_PRIVATE(object);
+
   switch (prop_id) {
+  case PROP_DATA:
+g_value_set_boxed(value, priv->data);
+break;
   default:
 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 break;
@@ -113,6 +136,7 @@ garrow_buffer_class_init(GArrowBufferClass *klass)
 
   auto gobject_class = G_OBJECT_CLASS(klass);
 
+  gobject_class->dispose  = garrow_buffer_dispose;
   gobject_class->finalize = garrow_buffer_finalize;
   gobject_class->set_property = garrow_buffer_set_property;
   gobject_class->get_property = garrow_buffer_get_property;
@@ -123,6 +147,14 @@ garrow_buffer_class_init(GArrowBufferClass *klass)
   static_cast(G_PARAM_WRITABLE |

G_PARAM_CONSTRUCT_ONLY));
   g_object_class_install_property(gobject_class, PROP_BUFFER, spec);
+
+  spec = g_param_spec_boxed("data",
+"Data",
+"The raw data passed as GBytes *",
+G_TYPE_BYTES,
+static_cast(G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property(gobject_class, PROP_DATA, spec);
 }
 
 /**
@@ -141,7 +173,25 @@ garrow_buffer_new(const guint8 *data, gint64 size)
 {
   auto arrow_buffer = std::make_shared(data, size);
   return garrow_buffer_new_raw(_buffer);
+}
 
+/**
+ * garrow_buffer_new_bytes:
+ * @data: Data for the buffer.
+ *
+ * Returns: A newly created #GArrowBuffer.
+ *
+ * Since: 0.9.0
+ */
+GArrowBuffer *
+garrow_buffer_new_bytes(GBytes *data)
+{
+  size_t data_size;
+  auto raw_data = g_bytes_get_data(data, _size);
+  auto arrow_buffer =
+std::make_shared(static_cast(raw_data),
+data_size);
+  return garrow_buffer_new_raw_bytes(_buffer, data);
 }
 
 /**
@@ -226,6 +276,12 @@ garrow_buffer_get_capacity(GArrowBuffer *buffer)
 GBytes *
 garrow_buffer_get_data(GArrowBuffer *buffer)
 {
+  auto priv = GARROW_BUFFER_GET_PRIVATE(buffer);
+  if (priv->data) {
+g_bytes_ref(priv->data);
+return 

[jira] [Commented] (ARROW-2261) [GLib] Can't share the same memory in GArrowBuffer safely

2018-03-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/ARROW-2261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16386304#comment-16386304
 ] 

ASF GitHub Bot commented on ARROW-2261:
---

kou opened a new pull request #1701: ARROW-2261: [GLib] Improve memory 
management for GArrowBuffer data
URL: https://github.com/apache/arrow/pull/1701
 
 
   This change introduces GBytes constructors to GArrowBuffer and
   GArrowMutableBuffer. GBytes has reference count feature. It means that
   we can share the same memory safely.
   
   We can't share the same memory safely with the current raw guint8
   constructor.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [GLib] Can't share the same memory in GArrowBuffer safely
> -
>
> Key: ARROW-2261
> URL: https://issues.apache.org/jira/browse/ARROW-2261
> Project: Apache Arrow
>  Issue Type: Improvement
>  Components: GLib
>Affects Versions: 0.8.0
>Reporter: Kouhei Sutou
>Assignee: Kouhei Sutou
>Priority: Major
>  Labels: pull-request-available
> Fix For: 0.9.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)