You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/04/25 19:47:58 UTC
arrow git commit: ARROW-894: [GLib] Add GArrowResizableBuffer and
GArrowPoolBuffer
Repository: arrow
Updated Branches:
refs/heads/master 6ae49a1dd -> 015b28492
ARROW-894: [GLib] Add GArrowResizableBuffer and GArrowPoolBuffer
Author: Kouhei Sutou <ko...@clear-code.com>
Closes #600 from kou/glib-pool-buffer and squashes the following commits:
f8845aa [Kouhei Sutou] [GLib] Add GArrowResizableBuffer and GArrowPoolBuffer
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/015b2849
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/015b2849
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/015b2849
Branch: refs/heads/master
Commit: 015b2849299be4bee9b470e3965465e1b0278881
Parents: 6ae49a1
Author: Kouhei Sutou <ko...@clear-code.com>
Authored: Tue Apr 25 15:47:53 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Tue Apr 25 15:47:53 2017 -0400
----------------------------------------------------------------------
c_glib/arrow-glib/buffer.cpp | 114 +++++++++++++++++++++++++++++++++++
c_glib/arrow-glib/buffer.h | 99 ++++++++++++++++++++++++++++++
c_glib/arrow-glib/buffer.hpp | 1 +
c_glib/test/test-pool-buffer.rb | 32 ++++++++++
4 files changed, 246 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/015b2849/c_glib/arrow-glib/buffer.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/buffer.cpp b/c_glib/arrow-glib/buffer.cpp
index 5fc3b07..5c28daf 100644
--- a/c_glib/arrow-glib/buffer.cpp
+++ b/c_glib/arrow-glib/buffer.cpp
@@ -38,6 +38,11 @@ G_BEGIN_DECLS
* #GArrowBuffer is immutable.
*
* #GArrowMutableBuffer is mutable.
+ *
+ * #GArrowResizableBuffer is mutable and
+ * resizable. #GArrowResizableBuffer isn't instantiatable.
+ *
+ * #GArrowPoolBuffer is mutable, resizable and instantiatable.
*/
typedef struct GArrowBufferPrivate_ {
@@ -357,6 +362,106 @@ garrow_mutable_buffer_slice(GArrowMutableBuffer *buffer,
return garrow_mutable_buffer_new_raw(&arrow_buffer);
}
+
+G_DEFINE_TYPE(GArrowResizableBuffer, \
+ garrow_resizable_buffer, \
+ GARROW_TYPE_MUTABLE_BUFFER)
+
+static void
+garrow_resizable_buffer_init(GArrowResizableBuffer *object)
+{
+}
+
+static void
+garrow_resizable_buffer_class_init(GArrowResizableBufferClass *klass)
+{
+}
+
+/**
+ * garrow_resizable_buffer_resize:
+ * @buffer: A #GArrowResizableBuffer.
+ * @new_size: The new buffer size in bytes.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * Since: 0.3.0
+ */
+gboolean
+garrow_resizable_buffer_resize(GArrowResizableBuffer *buffer,
+ gint64 new_size,
+ GError **error)
+{
+ auto arrow_buffer = garrow_buffer_get_raw(GARROW_BUFFER(buffer));
+ auto arrow_resizable_buffer =
+ std::static_pointer_cast<arrow::ResizableBuffer>(arrow_buffer);
+ auto status = arrow_resizable_buffer->Resize(new_size);
+ if (status.ok()) {
+ return TRUE;
+ } else {
+ garrow_error_set(error, status, "[resizable-buffer][resize]");
+ return FALSE;
+ }
+}
+
+/**
+ * garrow_resizable_buffer_reserve:
+ * @buffer: A #GArrowResizableBuffer.
+ * @new_capacity: The new buffer capacity in bytes.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * Since: 0.3.0
+ */
+gboolean
+garrow_resizable_buffer_reserve(GArrowResizableBuffer *buffer,
+ gint64 new_capacity,
+ GError **error)
+{
+ auto arrow_buffer = garrow_buffer_get_raw(GARROW_BUFFER(buffer));
+ auto arrow_resizable_buffer =
+ std::static_pointer_cast<arrow::ResizableBuffer>(arrow_buffer);
+ auto status = arrow_resizable_buffer->Reserve(new_capacity);
+ if (status.ok()) {
+ return TRUE;
+ } else {
+ garrow_error_set(error, status, "[resizable-buffer][capacity]");
+ return FALSE;
+ }
+}
+
+
+G_DEFINE_TYPE(GArrowPoolBuffer, \
+ garrow_pool_buffer, \
+ GARROW_TYPE_RESIZABLE_BUFFER)
+
+static void
+garrow_pool_buffer_init(GArrowPoolBuffer *object)
+{
+}
+
+static void
+garrow_pool_buffer_class_init(GArrowPoolBufferClass *klass)
+{
+}
+
+/**
+ * garrow_pool_buffer_new:
+ *
+ * Returns: A newly created #GArrowPoolBuffer.
+ *
+ * Since: 0.3.0
+ */
+GArrowPoolBuffer *
+garrow_pool_buffer_new(void)
+{
+ auto arrow_memory_pool = arrow::default_memory_pool();
+ auto arrow_buffer = std::make_shared<arrow::PoolBuffer>(arrow_memory_pool);
+ return garrow_pool_buffer_new_raw(&arrow_buffer);
+}
+
+
G_END_DECLS
GArrowBuffer *
@@ -383,3 +488,12 @@ garrow_mutable_buffer_new_raw(std::shared_ptr<arrow::MutableBuffer> *arrow_buffe
NULL));
return buffer;
}
+
+GArrowPoolBuffer *
+garrow_pool_buffer_new_raw(std::shared_ptr<arrow::PoolBuffer> *arrow_buffer)
+{
+ auto buffer = GARROW_POOL_BUFFER(g_object_new(GARROW_TYPE_POOL_BUFFER,
+ "buffer", arrow_buffer,
+ NULL));
+ return buffer;
+}
http://git-wip-us.apache.org/repos/asf/arrow/blob/015b2849/c_glib/arrow-glib/buffer.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/buffer.h b/c_glib/arrow-glib/buffer.h
index 5334614..22a5e9b 100644
--- a/c_glib/arrow-glib/buffer.h
+++ b/c_glib/arrow-glib/buffer.h
@@ -125,4 +125,103 @@ GArrowMutableBuffer *garrow_mutable_buffer_slice(GArrowMutableBuffer *buffer,
gint64 offset,
gint64 size);
+
+#define GARROW_TYPE_RESIZABLE_BUFFER \
+ (garrow_resizable_buffer_get_type())
+#define GARROW_RESIZABLE_BUFFER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_RESIZABLE_BUFFER, \
+ GArrowResizableBuffer))
+#define GARROW_RESIZABLE_BUFFER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_RESIZABLE_BUFFER, \
+ GArrowResizableBufferClass))
+#define GARROW_IS_RESIZABLE_BUFFER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), GARROW_TYPE_RESIZABLE_BUFFER))
+#define GARROW_IS_RESIZABLE_BUFFER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), GARROW_TYPE_RESIZABLE_BUFFER))
+#define GARROW_RESIZABLE_BUFFER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_RESIZABLE_BUFFER, \
+ GArrowResizableBufferClass))
+
+typedef struct _GArrowResizableBuffer GArrowResizableBuffer;
+#ifndef __GTK_DOC_IGNORE__
+typedef struct _GArrowResizableBufferClass GArrowResizableBufferClass;
+#endif
+
+/**
+ * GArrowResizableBuffer:
+ *
+ * It wraps `arrow::ResizableBuffer`.
+ */
+struct _GArrowResizableBuffer
+{
+ /*< private >*/
+ GArrowMutableBuffer parent_instance;
+};
+
+#ifndef __GTK_DOC_IGNORE__
+struct _GArrowResizableBufferClass
+{
+ GArrowMutableBufferClass parent_class;
+};
+#endif
+
+GType garrow_resizable_buffer_get_type(void) G_GNUC_CONST;
+
+gboolean garrow_resizable_buffer_resize(GArrowResizableBuffer *buffer,
+ gint64 new_size,
+ GError **error);
+gboolean garrow_resizable_buffer_reserve(GArrowResizableBuffer *buffer,
+ gint64 new_capacity,
+ GError **error);
+
+
+#define GARROW_TYPE_POOL_BUFFER \
+ (garrow_pool_buffer_get_type())
+#define GARROW_POOL_BUFFER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_POOL_BUFFER, \
+ GArrowPoolBuffer))
+#define GARROW_POOL_BUFFER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_POOL_BUFFER, \
+ GArrowPoolBufferClass))
+#define GARROW_IS_POOL_BUFFER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), GARROW_TYPE_POOL_BUFFER))
+#define GARROW_IS_POOL_BUFFER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), GARROW_TYPE_POOL_BUFFER))
+#define GARROW_POOL_BUFFER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_POOL_BUFFER, \
+ GArrowPoolBufferClass))
+
+typedef struct _GArrowPoolBuffer GArrowPoolBuffer;
+#ifndef __GTK_DOC_IGNORE__
+typedef struct _GArrowPoolBufferClass GArrowPoolBufferClass;
+#endif
+
+/**
+ * GArrowPoolBuffer:
+ *
+ * It wraps `arrow::PoolBuffer`.
+ */
+struct _GArrowPoolBuffer
+{
+ /*< private >*/
+ GArrowResizableBuffer parent_instance;
+};
+
+#ifndef __GTK_DOC_IGNORE__
+struct _GArrowPoolBufferClass
+{
+ GArrowResizableBufferClass parent_class;
+};
+#endif
+
+GType garrow_pool_buffer_get_type(void) G_GNUC_CONST;
+
+GArrowPoolBuffer *garrow_pool_buffer_new(void);
+
G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/015b2849/c_glib/arrow-glib/buffer.hpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/buffer.hpp b/c_glib/arrow-glib/buffer.hpp
index 1337d9e..d1664b1 100644
--- a/c_glib/arrow-glib/buffer.hpp
+++ b/c_glib/arrow-glib/buffer.hpp
@@ -27,3 +27,4 @@ GArrowBuffer *garrow_buffer_new_raw(std::shared_ptr<arrow::Buffer> *arrow_buffer
std::shared_ptr<arrow::Buffer> garrow_buffer_get_raw(GArrowBuffer *buffer);
GArrowMutableBuffer *garrow_mutable_buffer_new_raw(std::shared_ptr<arrow::MutableBuffer> *arrow_buffer);
+GArrowPoolBuffer *garrow_pool_buffer_new_raw(std::shared_ptr<arrow::PoolBuffer> *arrow_buffer);
http://git-wip-us.apache.org/repos/asf/arrow/blob/015b2849/c_glib/test/test-pool-buffer.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-pool-buffer.rb b/c_glib/test/test-pool-buffer.rb
new file mode 100644
index 0000000..57f3458
--- /dev/null
+++ b/c_glib/test/test-pool-buffer.rb
@@ -0,0 +1,32 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestPoolBuffer < Test::Unit::TestCase
+ def setup
+ @buffer = Arrow::PoolBuffer.new
+ end
+
+ def test_resize
+ @buffer.resize(1)
+ assert_equal(1, @buffer.size)
+ end
+
+ def test_reserve
+ @buffer.reserve(1)
+ assert_equal(64, @buffer.capacity)
+ end
+end