This is an automated email from the ASF dual-hosted git repository.

kszucs 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 8f32019  ARROW-4955: [GLib] Add garrow_file_is_closed()
8f32019 is described below

commit 8f320194008b95707282190b0fd75492512cd376
Author: Kouhei Sutou <[email protected]>
AuthorDate: Tue Mar 19 08:50:13 2019 +0100

    ARROW-4955: [GLib] Add garrow_file_is_closed()
    
    Author: Kouhei Sutou <[email protected]>
    
    Closes #3970 from kou/glib-file-is-closed and squashes the following 
commits:
    
    471536a8 <Kouhei Sutou>  Add garrow_file_is_closed()
---
 c_glib/arrow-glib/file.cpp                     | 15 +++++++++
 c_glib/arrow-glib/file.h                       | 30 +++++++----------
 c_glib/test/test-memory-mapped-input-stream.rb | 45 ++++++++++++++------------
 3 files changed, 50 insertions(+), 40 deletions(-)

diff --git a/c_glib/arrow-glib/file.cpp b/c_glib/arrow-glib/file.cpp
index e05743b..2869f1c 100644
--- a/c_glib/arrow-glib/file.cpp
+++ b/c_glib/arrow-glib/file.cpp
@@ -64,6 +64,21 @@ garrow_file_close(GArrowFile *file,
 }
 
 /**
+ * garrow_file_is_closed:
+ * @file: A #GArrowFile.
+ *
+ * Returns: %TRUE if the @file is already closed, %FALSE otherwise.
+ *
+ * Since: 0.13.0
+ */
+gboolean
+garrow_file_is_closed(GArrowFile *file)
+{
+  auto arrow_file = garrow_file_get_raw(file);
+  return arrow_file->closed();
+}
+
+/**
  * garrow_file_tell:
  * @file: A #GArrowFile.
  * @error: (nullable): Return location for a #GError or %NULL.
diff --git a/c_glib/arrow-glib/file.h b/c_glib/arrow-glib/file.h
index 68054aa..45319b8 100644
--- a/c_glib/arrow-glib/file.h
+++ b/c_glib/arrow-glib/file.h
@@ -20,30 +20,22 @@
 #pragma once
 
 #include <arrow-glib/file-mode.h>
+#include <arrow-glib/gobject-type.h>
+#include <arrow-glib/version.h>
 
 G_BEGIN_DECLS
 
-#define GARROW_TYPE_FILE                     \
-  (garrow_file_get_type())
-#define GARROW_FILE(obj)                             \
-  (G_TYPE_CHECK_INSTANCE_CAST((obj),                    \
-                              GARROW_TYPE_FILE,      \
-                              GArrowFile))
-#define GARROW_IS_FILE(obj)                          \
-  (G_TYPE_CHECK_INSTANCE_TYPE((obj),                    \
-                              GARROW_TYPE_FILE))
-#define GARROW_FILE_GET_IFACE(obj)                           \
-  (G_TYPE_INSTANCE_GET_INTERFACE((obj),                         \
-                                 GARROW_TYPE_FILE,           \
-                                 GArrowFileInterface))
-
-typedef struct _GArrowFile          GArrowFile;
-typedef struct _GArrowFileInterface GArrowFileInterface;
-
-GType garrow_file_get_type(void) G_GNUC_CONST;
+#define GARROW_TYPE_FILE (garrow_file_get_type())
+G_DECLARE_INTERFACE(GArrowFile,
+                    garrow_file,
+                    GARROW,
+                    FILE,
+                    GObject)
 
 gboolean garrow_file_close(GArrowFile *file,
-                              GError **error);
+                           GError **error);
+GARROW_AVAILABLE_IN_0_13
+gboolean garrow_file_is_closed(GArrowFile *file);
 gint64 garrow_file_tell(GArrowFile *file,
                            GError **error);
 GArrowFileMode garrow_file_get_mode(GArrowFile *file);
diff --git a/c_glib/test/test-memory-mapped-input-stream.rb 
b/c_glib/test/test-memory-mapped-input-stream.rb
index a02d925..7c5f933 100644
--- a/c_glib/test/test-memory-mapped-input-stream.rb
+++ b/c_glib/test/test-memory-mapped-input-stream.rb
@@ -16,11 +16,15 @@
 # under the License.
 
 class TestMemoryMappedInputStream < Test::Unit::TestCase
+  def setup
+    @data = "Hello World"
+    @tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
+    @tempfile.write(@data)
+    @tempfile.close
+  end
+
   def test_new
-    tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
-    tempfile.write("Hello")
-    tempfile.close
-    input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+    input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
     begin
       buffer = input.read(5)
       assert_equal("Hello", buffer.data.to_s)
@@ -29,23 +33,28 @@ class TestMemoryMappedInputStream < Test::Unit::TestCase
     end
   end
 
+  def test_close
+    input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
+    assert do
+      not input.closed?
+    end
+    input.close
+    assert do
+      input.closed?
+    end
+  end
+
   def test_size
-    tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
-    tempfile.write("Hello")
-    tempfile.close
-    input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+    input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
     begin
-      assert_equal(5, input.size)
+      assert_equal(@data.bytesize, input.size)
     ensure
       input.close
     end
   end
 
   def test_read
-    tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
-    tempfile.write("Hello World")
-    tempfile.close
-    input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+    input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
     begin
       buffer = input.read(5)
       assert_equal("Hello", buffer.data.to_s)
@@ -55,10 +64,7 @@ class TestMemoryMappedInputStream < Test::Unit::TestCase
   end
 
   def test_read_at
-    tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
-    tempfile.write("Hello World")
-    tempfile.close
-    input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+    input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
     begin
       buffer = input.read_at(6, 5)
       assert_equal("World", buffer.data.to_s)
@@ -68,10 +74,7 @@ class TestMemoryMappedInputStream < Test::Unit::TestCase
   end
 
   def test_mode
-    tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
-    tempfile.write("Hello World")
-    tempfile.close
-    input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+    input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
     begin
       assert_equal(Arrow::FileMode::READWRITE, input.mode)
     ensure

Reply via email to