You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by sh...@apache.org on 2018/11/22 22:36:21 UTC
[arrow] branch master updated: ARROW-3854: [GLib] Deprecate
garrow_gio_{input, output}_stream_get_raw()
This is an automated email from the ASF dual-hosted git repository.
shiro 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 1995e88 ARROW-3854: [GLib] Deprecate garrow_gio_{input,output}_stream_get_raw()
1995e88 is described below
commit 1995e8858f7cd365f6df7512823f8062d96386b0
Author: Kouhei Sutou <ko...@clear-code.com>
AuthorDate: Fri Nov 23 07:35:46 2018 +0900
ARROW-3854: [GLib] Deprecate garrow_gio_{input,output}_stream_get_raw()
Because we use `_get_raw()` name for functions that return C++ object.
We can provide getter for raw `GInputStream`/`GOutputStream` via GObject property mechanism. We used the mechanism for `GArrowCompressed{Input,Output}Stream`.
This pull request includes some implementation cleanups (sorry):
* Removed internal `garrow_buffer_input_stream_new_raw_buffer()` API
* Fixed indent.
* Changed to use `auto`.
* Moved `GParamSpec *spec` position.
Author: Kouhei Sutou <ko...@clear-code.com>
Closes #3014 from kou/glib-clean-io-stream and squashes the following commits:
e5dc7fe9 <Kouhei Sutou> Close definition and use place
aed730e9 <Kouhei Sutou> Use auto
c23ed351 <Kouhei Sutou> Deprecate gio_{input,output}_get_raw()
8a1f5556 <Kouhei Sutou> Fix indent
9c695b3f <Kouhei Sutou> Remove needless internal API
---
c_glib/arrow-glib/input-stream.cpp | 140 +++++++++++++++++++++++++-----------
c_glib/arrow-glib/input-stream.h | 6 +-
c_glib/arrow-glib/input-stream.hpp | 6 +-
c_glib/arrow-glib/output-stream.cpp | 116 +++++++++++++++++++++++-------
c_glib/arrow-glib/output-stream.h | 6 +-
5 files changed, 204 insertions(+), 70 deletions(-)
diff --git a/c_glib/arrow-glib/input-stream.cpp b/c_glib/arrow-glib/input-stream.cpp
index b22b3ac..69a20b0 100644
--- a/c_glib/arrow-glib/input-stream.cpp
+++ b/c_glib/arrow-glib/input-stream.cpp
@@ -113,9 +113,7 @@ G_DEFINE_TYPE_WITH_CODE(GArrowInputStream,
static void
garrow_input_stream_finalize(GObject *object)
{
- GArrowInputStreamPrivate *priv;
-
- priv = GARROW_INPUT_STREAM_GET_PRIVATE(object);
+ auto priv = GARROW_INPUT_STREAM_GET_PRIVATE(object);
priv->input_stream = nullptr;
@@ -128,9 +126,7 @@ garrow_input_stream_set_property(GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GArrowInputStreamPrivate *priv;
-
- priv = GARROW_INPUT_STREAM_GET_PRIVATE(object);
+ auto priv = GARROW_INPUT_STREAM_GET_PRIVATE(object);
switch (prop_id) {
case PROP_INPUT_STREAM:
@@ -164,15 +160,13 @@ garrow_input_stream_init(GArrowInputStream *object)
static void
garrow_input_stream_class_init(GArrowInputStreamClass *klass)
{
- GObjectClass *gobject_class;
- GParamSpec *spec;
-
- gobject_class = G_OBJECT_CLASS(klass);
+ auto gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = garrow_input_stream_finalize;
gobject_class->set_property = garrow_input_stream_set_property;
gobject_class->get_property = garrow_input_stream_get_property;
+ GParamSpec *spec;
spec = g_param_spec_pointer("input-stream",
"Input stream",
"The raw std::shared<arrow::io::InputStream> *",
@@ -406,14 +400,13 @@ garrow_buffer_input_stream_init(GArrowBufferInputStream *object)
static void
garrow_buffer_input_stream_class_init(GArrowBufferInputStreamClass *klass)
{
- GParamSpec *spec;
-
auto gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = garrow_buffer_input_stream_dispose;
gobject_class->set_property = garrow_buffer_input_stream_set_property;
gobject_class->get_property = garrow_buffer_input_stream_get_property;
+ GParamSpec *spec;
spec = g_param_spec_object("buffer",
"Buffer",
"The data",
@@ -435,7 +428,7 @@ garrow_buffer_input_stream_new(GArrowBuffer *buffer)
auto arrow_buffer = garrow_buffer_get_raw(buffer);
auto arrow_buffer_reader =
std::make_shared<arrow::io::BufferReader>(arrow_buffer);
- return garrow_buffer_input_stream_new_raw_buffer(&arrow_buffer_reader, buffer);
+ return garrow_buffer_input_stream_new_raw(&arrow_buffer_reader, buffer);
}
/**
@@ -567,14 +560,14 @@ namespace garrow {
}
arrow::Status ReadAt(int64_t position, int64_t n_bytes,
- int64_t *n_read_bytes, void* out) override {
- return arrow::io::RandomAccessFile::ReadAt(
- position, n_bytes, n_read_bytes, out);
+ int64_t *n_read_bytes, void* out) override {
+ return arrow::io::RandomAccessFile::ReadAt(
+ position, n_bytes, n_read_bytes, out);
}
arrow::Status ReadAt(int64_t position, int64_t n_bytes,
- std::shared_ptr<arrow::Buffer>* out) override {
- return arrow::io::RandomAccessFile::ReadAt(position, n_bytes, out);
+ std::shared_ptr<arrow::Buffer>* out) override {
+ return arrow::io::RandomAccessFile::ReadAt(position, n_bytes, out);
}
arrow::Status Read(int64_t n_bytes,
@@ -669,9 +662,72 @@ namespace garrow {
G_BEGIN_DECLS
-G_DEFINE_TYPE(GArrowGIOInputStream,
- garrow_gio_input_stream,
- GARROW_TYPE_SEEKABLE_INPUT_STREAM);
+
+typedef struct GArrowGIOInputStreamPrivate_ {
+ GInputStream *raw;
+} GArrowGIOInputStreamPrivate;
+
+enum {
+ PROP_GIO_RAW = 1
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowGIOInputStream,
+ garrow_gio_input_stream,
+ GARROW_TYPE_SEEKABLE_INPUT_STREAM);
+
+#define GARROW_GIO_INPUT_STREAM_GET_PRIVATE(object) \
+ static_cast<GArrowGIOInputStreamPrivate *>( \
+ garrow_gio_input_stream_get_instance_private( \
+ GARROW_GIO_INPUT_STREAM(object)))
+
+static void
+garrow_gio_input_stream_dispose(GObject *object)
+{
+ auto priv = GARROW_GIO_INPUT_STREAM_GET_PRIVATE(object);
+
+ if (priv->raw) {
+ g_object_unref(priv->raw);
+ priv->raw = nullptr;
+ }
+
+ G_OBJECT_CLASS(garrow_gio_input_stream_parent_class)->dispose(object);
+}
+
+static void
+garrow_gio_input_stream_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ auto priv = GARROW_GIO_INPUT_STREAM_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_GIO_RAW:
+ priv->raw = G_INPUT_STREAM(g_value_dup_object(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_gio_input_stream_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ auto priv = GARROW_GIO_INPUT_STREAM_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_GIO_RAW:
+ g_value_set_object(value, priv->raw);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
static void
garrow_gio_input_stream_init(GArrowGIOInputStream *object)
@@ -681,6 +737,20 @@ garrow_gio_input_stream_init(GArrowGIOInputStream *object)
static void
garrow_gio_input_stream_class_init(GArrowGIOInputStreamClass *klass)
{
+ auto gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = garrow_gio_input_stream_dispose;
+ gobject_class->set_property = garrow_gio_input_stream_set_property;
+ gobject_class->get_property = garrow_gio_input_stream_get_property;
+
+ GParamSpec *spec;
+ spec = g_param_spec_object("raw",
+ "Raw",
+ "The raw GInputStream *",
+ G_TYPE_INPUT_STREAM,
+ static_cast<GParamFlags>(G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(gobject_class, PROP_GIO_RAW, spec);
}
/**
@@ -698,6 +768,7 @@ garrow_gio_input_stream_new(GInputStream *gio_input_stream)
std::make_shared<garrow::GIOInputStream>(gio_input_stream);
auto object = g_object_new(GARROW_TYPE_GIO_INPUT_STREAM,
"input-stream", &arrow_input_stream,
+ "raw", gio_input_stream,
NULL);
auto input_stream = GARROW_GIO_INPUT_STREAM(object);
return input_stream;
@@ -710,16 +781,14 @@ garrow_gio_input_stream_new(GInputStream *gio_input_stream)
* Returns: (transfer none): The wrapped #GInputStream.
*
* Since: 0.5.0
+ *
+ * Deprecated: 0.12.0: Use GArrowGIOInputStream::raw property instead.
*/
GInputStream *
garrow_gio_input_stream_get_raw(GArrowGIOInputStream *input_stream)
{
- auto arrow_input_stream =
- garrow_input_stream_get_raw(GARROW_INPUT_STREAM(input_stream));
- auto arrow_gio_input_stream =
- std::static_pointer_cast<garrow::GIOInputStream>(arrow_input_stream);
- auto gio_input_stream = arrow_gio_input_stream->get_input_stream();
- return gio_input_stream;
+ auto priv = GARROW_GIO_INPUT_STREAM_GET_PRIVATE(input_stream);
+ return priv->raw;
}
typedef struct GArrowCompressedInputStreamPrivate_ {
@@ -809,14 +878,13 @@ garrow_compressed_input_stream_init(GArrowCompressedInputStream *object)
static void
garrow_compressed_input_stream_class_init(GArrowCompressedInputStreamClass *klass)
{
- GParamSpec *spec;
-
auto gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = garrow_compressed_input_stream_dispose;
gobject_class->set_property = garrow_compressed_input_stream_set_property;
gobject_class->get_property = garrow_compressed_input_stream_get_property;
+ GParamSpec *spec;
spec = g_param_spec_object("codec",
"Codec",
"The codec for the stream",
@@ -879,9 +947,7 @@ garrow_input_stream_new_raw(std::shared_ptr<arrow::io::InputStream> *arrow_input
std::shared_ptr<arrow::io::InputStream>
garrow_input_stream_get_raw(GArrowInputStream *input_stream)
{
- GArrowInputStreamPrivate *priv;
-
- priv = GARROW_INPUT_STREAM_GET_PRIVATE(input_stream);
+ auto priv = GARROW_INPUT_STREAM_GET_PRIVATE(input_stream);
return priv->input_stream;
}
@@ -896,14 +962,8 @@ garrow_seekable_input_stream_get_raw(GArrowSeekableInputStream *seekable_input_s
}
GArrowBufferInputStream *
-garrow_buffer_input_stream_new_raw(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader)
-{
- return garrow_buffer_input_stream_new_raw_buffer(arrow_buffer_reader, nullptr);
-}
-
-GArrowBufferInputStream *
-garrow_buffer_input_stream_new_raw_buffer(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader,
- GArrowBuffer *buffer)
+garrow_buffer_input_stream_new_raw(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader,
+ GArrowBuffer *buffer)
{
auto buffer_input_stream =
GARROW_BUFFER_INPUT_STREAM(g_object_new(GARROW_TYPE_BUFFER_INPUT_STREAM,
diff --git a/c_glib/arrow-glib/input-stream.h b/c_glib/arrow-glib/input-stream.h
index 1a4c9cf..9deebd7 100644
--- a/c_glib/arrow-glib/input-stream.h
+++ b/c_glib/arrow-glib/input-stream.h
@@ -182,7 +182,11 @@ struct _GArrowGIOInputStreamClass
GType garrow_gio_input_stream_get_type(void) G_GNUC_CONST;
GArrowGIOInputStream *garrow_gio_input_stream_new(GInputStream *gio_input_stream);
-GInputStream *garrow_gio_input_stream_get_raw(GArrowGIOInputStream *input_stream);
+#ifndef GARROW_DISABLE_DEPRECATED
+G_GNUC_DEPRECATED
+GInputStream *
+garrow_gio_input_stream_get_raw(GArrowGIOInputStream *input_stream);
+#endif
#define GARROW_TYPE_COMPRESSED_INPUT_STREAM \
(garrow_compressed_input_stream_get_type())
diff --git a/c_glib/arrow-glib/input-stream.hpp b/c_glib/arrow-glib/input-stream.hpp
index 34857a1..d06d65b 100644
--- a/c_glib/arrow-glib/input-stream.hpp
+++ b/c_glib/arrow-glib/input-stream.hpp
@@ -31,9 +31,9 @@ std::shared_ptr<arrow::io::InputStream> garrow_input_stream_get_raw(GArrowInputS
std::shared_ptr<arrow::io::RandomAccessFile> garrow_seekable_input_stream_get_raw(GArrowSeekableInputStream *input_stream);
-GArrowBufferInputStream *garrow_buffer_input_stream_new_raw(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader);
-GArrowBufferInputStream *garrow_buffer_input_stream_new_raw_buffer(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader,
- GArrowBuffer *buffer);
+GArrowBufferInputStream *
+garrow_buffer_input_stream_new_raw(std::shared_ptr<arrow::io::BufferReader> *arrow_buffer_reader,
+ GArrowBuffer *buffer);
std::shared_ptr<arrow::io::BufferReader> garrow_buffer_input_stream_get_raw(GArrowBufferInputStream *input_stream);
GArrowMemoryMappedInputStream *garrow_memory_mapped_input_stream_new_raw(std::shared_ptr<arrow::io::MemoryMappedFile> *arrow_memory_mapped_file);
diff --git a/c_glib/arrow-glib/output-stream.cpp b/c_glib/arrow-glib/output-stream.cpp
index 946ee0b..aa0a13c 100644
--- a/c_glib/arrow-glib/output-stream.cpp
+++ b/c_glib/arrow-glib/output-stream.cpp
@@ -111,9 +111,7 @@ G_DEFINE_TYPE_WITH_CODE(GArrowOutputStream,
static void
garrow_output_stream_finalize(GObject *object)
{
- GArrowOutputStreamPrivate *priv;
-
- priv = GARROW_OUTPUT_STREAM_GET_PRIVATE(object);
+ auto priv = GARROW_OUTPUT_STREAM_GET_PRIVATE(object);
priv->output_stream = nullptr;
@@ -126,9 +124,7 @@ garrow_output_stream_set_property(GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GArrowOutputStreamPrivate *priv;
-
- priv = GARROW_OUTPUT_STREAM_GET_PRIVATE(object);
+ auto priv = GARROW_OUTPUT_STREAM_GET_PRIVATE(object);
switch (prop_id) {
case PROP_OUTPUT_STREAM:
@@ -162,15 +158,13 @@ garrow_output_stream_init(GArrowOutputStream *object)
static void
garrow_output_stream_class_init(GArrowOutputStreamClass *klass)
{
- GObjectClass *gobject_class;
- GParamSpec *spec;
-
- gobject_class = G_OBJECT_CLASS(klass);
+ auto gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = garrow_output_stream_finalize;
gobject_class->set_property = garrow_output_stream_set_property;
gobject_class->get_property = garrow_output_stream_get_property;
+ GParamSpec *spec;
spec = g_param_spec_pointer("output-stream",
"io::OutputStream",
"The raw std::shared<arrow::io::OutputStream> *",
@@ -394,18 +388,94 @@ namespace garrow {
G_BEGIN_DECLS
-G_DEFINE_TYPE(GArrowGIOOutputStream,
- garrow_gio_output_stream,
- GARROW_TYPE_OUTPUT_STREAM);
+typedef struct GArrowGIOOutputStreamPrivate_ {
+ GOutputStream *raw;
+} GArrowGIOOutputStreamPrivate;
+
+enum {
+ PROP_GIO_RAW = 1
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowGIOOutputStream,
+ garrow_gio_output_stream,
+ GARROW_TYPE_OUTPUT_STREAM);
+
+#define GARROW_GIO_OUTPUT_STREAM_GET_PRIVATE(object) \
+ static_cast<GArrowGIOOutputStreamPrivate *>( \
+ garrow_gio_output_stream_get_instance_private( \
+ GARROW_GIO_OUTPUT_STREAM(object)))
+
+static void
+garrow_gio_output_stream_dispose(GObject *object)
+{
+ auto priv = GARROW_GIO_OUTPUT_STREAM_GET_PRIVATE(object);
+
+ if (priv->raw) {
+ g_object_unref(priv->raw);
+ priv->raw = nullptr;
+ }
+
+ G_OBJECT_CLASS(garrow_gio_output_stream_parent_class)->dispose(object);
+}
+
+static void
+garrow_gio_output_stream_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ auto priv = GARROW_GIO_OUTPUT_STREAM_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_GIO_RAW:
+ priv->raw = G_OUTPUT_STREAM(g_value_dup_object(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_gio_output_stream_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ auto priv = GARROW_GIO_OUTPUT_STREAM_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_GIO_RAW:
+ g_value_set_object(value, priv->raw);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
static void
-garrow_gio_output_stream_init(GArrowGIOOutputStream *gio_output_stream)
+garrow_gio_output_stream_init(GArrowGIOOutputStream *object)
{
}
static void
garrow_gio_output_stream_class_init(GArrowGIOOutputStreamClass *klass)
{
+ auto gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = garrow_gio_output_stream_dispose;
+ gobject_class->set_property = garrow_gio_output_stream_set_property;
+ gobject_class->get_property = garrow_gio_output_stream_get_property;
+
+ GParamSpec *spec;
+ spec = g_param_spec_object("raw",
+ "Raw",
+ "The raw GOutputStream *",
+ G_TYPE_OUTPUT_STREAM,
+ static_cast<GParamFlags>(G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(gobject_class, PROP_GIO_RAW, spec);
}
/**
@@ -421,6 +491,7 @@ garrow_gio_output_stream_new(GOutputStream *gio_output_stream)
std::make_shared<garrow::GIOOutputStream>(gio_output_stream);
auto object = g_object_new(GARROW_TYPE_GIO_OUTPUT_STREAM,
"output-stream", &arrow_output_stream,
+ "raw", gio_output_stream,
NULL);
auto output_stream = GARROW_GIO_OUTPUT_STREAM(object);
return output_stream;
@@ -433,16 +504,14 @@ garrow_gio_output_stream_new(GOutputStream *gio_output_stream)
* Returns: (transfer none): The wrapped #GOutputStream.
*
* Since: 0.5.0
+ *
+ * Deprecated: 0.12.0: Use GArrowGIOOutputStream::raw property instead.
*/
GOutputStream *
garrow_gio_output_stream_get_raw(GArrowGIOOutputStream *output_stream)
{
- auto arrow_output_stream =
- garrow_output_stream_get_raw(GARROW_OUTPUT_STREAM(output_stream));
- auto arrow_gio_output_stream =
- std::static_pointer_cast<garrow::GIOOutputStream>(arrow_output_stream);
- auto gio_output_stream = arrow_gio_output_stream->get_output_stream();
- return gio_output_stream;
+ auto priv = GARROW_GIO_OUTPUT_STREAM_GET_PRIVATE(output_stream);
+ return priv->raw;
}
typedef struct GArrowCompressedOutputStreamPrivate_ {
@@ -532,14 +601,13 @@ garrow_compressed_output_stream_init(GArrowCompressedOutputStream *object)
static void
garrow_compressed_output_stream_class_init(GArrowCompressedOutputStreamClass *klass)
{
- GParamSpec *spec;
-
auto gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = garrow_compressed_output_stream_dispose;
gobject_class->set_property = garrow_compressed_output_stream_set_property;
gobject_class->get_property = garrow_compressed_output_stream_get_property;
+ GParamSpec *spec;
spec = g_param_spec_object("codec",
"Codec",
"The codec for the stream",
@@ -603,9 +671,7 @@ garrow_output_stream_new_raw(std::shared_ptr<arrow::io::OutputStream> *arrow_out
std::shared_ptr<arrow::io::OutputStream>
garrow_output_stream_get_raw(GArrowOutputStream *output_stream)
{
- GArrowOutputStreamPrivate *priv;
-
- priv = GARROW_OUTPUT_STREAM_GET_PRIVATE(output_stream);
+ auto priv = GARROW_OUTPUT_STREAM_GET_PRIVATE(output_stream);
return priv->output_stream;
}
diff --git a/c_glib/arrow-glib/output-stream.h b/c_glib/arrow-glib/output-stream.h
index 0318652..bcfd818 100644
--- a/c_glib/arrow-glib/output-stream.h
+++ b/c_glib/arrow-glib/output-stream.h
@@ -193,7 +193,11 @@ struct _GArrowGIOOutputStreamClass
GType garrow_gio_output_stream_get_type(void) G_GNUC_CONST;
GArrowGIOOutputStream *garrow_gio_output_stream_new(GOutputStream *gio_output_stream);
-GOutputStream *garrow_gio_output_stream_get_raw(GArrowGIOOutputStream *output_stream);
+#ifndef GARROW_DISABLE_DEPRECATED
+G_GNUC_DEPRECATED
+GOutputStream *
+garrow_gio_output_stream_get_raw(GArrowGIOOutputStream *output_stream);
+#endif
#define GARROW_TYPE_COMPRESSED_OUTPUT_STREAM \
(garrow_compressed_output_stream_get_type())