This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 03db8a3 ARROW-2251: [GLib] Keep GArrowBuffer alive while GArrowTensor
for the buffer is live
03db8a3 is described below
commit 03db8a30bc68658733eb0ed26638136792f15639
Author: Kouhei Sutou <[email protected]>
AuthorDate: Sun Mar 4 23:36:40 2018 -0500
ARROW-2251: [GLib] Keep GArrowBuffer alive while GArrowTensor for the
buffer is live
It prevents GC-related crash.
Author: Kouhei Sutou <[email protected]>
Closes #1691 from kou/glib-tensor-refer-buffer and squashes the following
commits:
33ab8576 <Kouhei Sutou> Keep GArrowBuffer alive while GArrowTensor for the
buffer is live
---
c_glib/arrow-glib/input-stream.cpp | 2 +-
c_glib/arrow-glib/tensor.cpp | 58 ++++++++++++++++++++++++++++++++------
c_glib/arrow-glib/tensor.hpp | 3 +-
3 files changed, 52 insertions(+), 11 deletions(-)
diff --git a/c_glib/arrow-glib/input-stream.cpp
b/c_glib/arrow-glib/input-stream.cpp
index 9442224..f602e5f 100644
--- a/c_glib/arrow-glib/input-stream.cpp
+++ b/c_glib/arrow-glib/input-stream.cpp
@@ -282,7 +282,7 @@
garrow_seekable_input_stream_read_tensor(GArrowSeekableInputStream *input_stream
arrow_random_access_file.get(),
&arrow_tensor);
if (garrow_error_check(error, status,
"[seekable-input-stream][read-tensor]")) {
- return garrow_tensor_new_raw(&arrow_tensor);
+ return garrow_tensor_new_raw(&arrow_tensor, nullptr);
} else {
return NULL;
}
diff --git a/c_glib/arrow-glib/tensor.cpp b/c_glib/arrow-glib/tensor.cpp
index 3325f85..359831f 100644
--- a/c_glib/arrow-glib/tensor.cpp
+++ b/c_glib/arrow-glib/tensor.cpp
@@ -40,11 +40,13 @@ G_BEGIN_DECLS
typedef struct GArrowTensorPrivate_ {
std::shared_ptr<arrow::Tensor> tensor;
+ GArrowBuffer *buffer;
} GArrowTensorPrivate;
enum {
PROP_0,
- PROP_TENSOR
+ PROP_TENSOR,
+ PROP_BUFFER
};
G_DEFINE_TYPE_WITH_PRIVATE(GArrowTensor, garrow_tensor, G_TYPE_OBJECT)
@@ -53,6 +55,19 @@ G_DEFINE_TYPE_WITH_PRIVATE(GArrowTensor, garrow_tensor,
G_TYPE_OBJECT)
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GARROW_TYPE_TENSOR, GArrowTensorPrivate))
static void
+garrow_tensor_dispose(GObject *object)
+{
+ auto priv = GARROW_TENSOR_GET_PRIVATE(object);
+
+ if (priv->buffer) {
+ g_object_unref(priv->buffer);
+ priv->buffer = nullptr;
+ }
+
+ G_OBJECT_CLASS(garrow_tensor_parent_class)->dispose(object);
+}
+
+static void
garrow_tensor_finalize(GObject *object)
{
auto priv = GARROW_TENSOR_GET_PRIVATE(object);
@@ -64,9 +79,9 @@ garrow_tensor_finalize(GObject *object)
static void
garrow_tensor_set_property(GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
auto priv = GARROW_TENSOR_GET_PRIVATE(object);
@@ -75,6 +90,9 @@ garrow_tensor_set_property(GObject *object,
priv->tensor =
*static_cast<std::shared_ptr<arrow::Tensor>
*>(g_value_get_pointer(value));
break;
+ case PROP_BUFFER:
+ priv->buffer = GARROW_BUFFER(g_value_dup_object(value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -83,11 +101,16 @@ garrow_tensor_set_property(GObject *object,
static void
garrow_tensor_get_property(GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
+ auto priv = GARROW_TENSOR_GET_PRIVATE(object);
+
switch (prop_id) {
+ case PROP_BUFFER:
+ g_value_set_object(value, priv->buffer);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -106,6 +129,7 @@ garrow_tensor_class_init(GArrowTensorClass *klass)
auto gobject_class = G_OBJECT_CLASS(klass);
+ gobject_class->dispose = garrow_tensor_dispose;
gobject_class->finalize = garrow_tensor_finalize;
gobject_class->set_property = garrow_tensor_set_property;
gobject_class->get_property = garrow_tensor_get_property;
@@ -116,6 +140,14 @@ garrow_tensor_class_init(GArrowTensorClass *klass)
static_cast<GParamFlags>(G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(gobject_class, PROP_TENSOR, spec);
+
+ spec = g_param_spec_object("buffer",
+ "Buffer",
+ "The data",
+ GARROW_TYPE_BUFFER,
+ static_cast<GParamFlags>(G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(gobject_class, PROP_BUFFER, spec);
}
/**
@@ -166,7 +198,7 @@ garrow_tensor_new(GArrowDataType *data_type,
arrow_shape,
arrow_strides,
arrow_dimension_names);
- auto tensor = garrow_tensor_new_raw(&arrow_tensor);
+ auto tensor = garrow_tensor_new_raw(&arrow_tensor, data);
return tensor;
}
@@ -231,6 +263,12 @@ garrow_tensor_get_value_type(GArrowTensor *tensor)
GArrowBuffer *
garrow_tensor_get_buffer(GArrowTensor *tensor)
{
+ auto priv = GARROW_TENSOR_GET_PRIVATE(tensor);
+ if (priv->buffer) {
+ g_object_ref(priv->buffer);
+ return priv->buffer;
+ }
+
auto arrow_tensor = garrow_tensor_get_raw(tensor);
auto arrow_buffer = arrow_tensor->data();
return garrow_buffer_new_raw(&arrow_buffer);
@@ -398,10 +436,12 @@ garrow_tensor_is_column_major(GArrowTensor *tensor)
G_END_DECLS
GArrowTensor *
-garrow_tensor_new_raw(std::shared_ptr<arrow::Tensor> *arrow_tensor)
+garrow_tensor_new_raw(std::shared_ptr<arrow::Tensor> *arrow_tensor,
+ GArrowBuffer *buffer)
{
auto tensor = GARROW_TENSOR(g_object_new(GARROW_TYPE_TENSOR,
"tensor", arrow_tensor,
+ "buffer", buffer,
NULL));
return tensor;
}
diff --git a/c_glib/arrow-glib/tensor.hpp b/c_glib/arrow-glib/tensor.hpp
index 392aeee..8e54e49 100644
--- a/c_glib/arrow-glib/tensor.hpp
+++ b/c_glib/arrow-glib/tensor.hpp
@@ -23,5 +23,6 @@
#include <arrow-glib/tensor.h>
-GArrowTensor *garrow_tensor_new_raw(std::shared_ptr<arrow::Tensor>
*arrow_tensor);
+GArrowTensor *garrow_tensor_new_raw(std::shared_ptr<arrow::Tensor>
*arrow_tensor,
+ GArrowBuffer *buffer);
std::shared_ptr<arrow::Tensor> garrow_tensor_get_raw(GArrowTensor *tensor);
--
To stop receiving notification emails like this one, please contact
[email protected].