Skip to content

Commit

Permalink
ARROW-863: [GLib] Use GBytes to implement zero-copy
Browse files Browse the repository at this point in the history
Author: Kouhei Sutou <[email protected]>

Closes apache#572 from kou/glib-buffer-use-gbytes and squashes the following commits:

dc37de3 [Kouhei Sutou] [GLib] Use GBytes to implement zero-copy
  • Loading branch information
kou authored and wesm committed Apr 20, 2017
1 parent a68f31b commit 3f9b26c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
13 changes: 7 additions & 6 deletions c_glib/arrow-glib/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,19 @@ garrow_buffer_get_capacity(GArrowBuffer *buffer)
/**
* garrow_buffer_get_data:
* @buffer: A #GArrowBuffer.
* @size: (out): The number of bytes of the data.
*
* Returns: (array length=size): The data of the buffer.
* Returns: (transfer full): The data of the buffer. The data is owned by
* the buffer. You should not free or modify the data.
*
* Since: 0.3.0
*/
const guint8 *
garrow_buffer_get_data(GArrowBuffer *buffer, gint64 *size)
GBytes *
garrow_buffer_get_data(GArrowBuffer *buffer)
{
auto arrow_buffer = garrow_buffer_get_raw(buffer);
*size = arrow_buffer->size();
return arrow_buffer->data();
auto data = g_bytes_new_static(arrow_buffer->data(),
arrow_buffer->size());
return data;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions c_glib/arrow-glib/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ GArrowBuffer *garrow_buffer_new (const guint8 *data,
gint64 size);
gboolean garrow_buffer_is_mutable (GArrowBuffer *buffer);
gint64 garrow_buffer_get_capacity (GArrowBuffer *buffer);
const guint8 *garrow_buffer_get_data (GArrowBuffer *buffer,
gint64 *size);
GBytes *garrow_buffer_get_data (GArrowBuffer *buffer);
gint64 garrow_buffer_get_size (GArrowBuffer *buffer);
GArrowBuffer *garrow_buffer_get_parent (GArrowBuffer *buffer);

Expand Down
6 changes: 3 additions & 3 deletions c_glib/test/test-buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_capacity
end

def test_data
assert_equal(@data, @buffer.data.pack("C*"))
assert_equal(@data, @buffer.data.to_s)
end

def test_size
Expand All @@ -45,11 +45,11 @@ def test_parent

def test_copy
copied_buffer = @buffer.copy(1, 3)
assert_equal(@data[1, 3], copied_buffer.data.pack("C*"))
assert_equal(@data[1, 3], copied_buffer.data.to_s)
end

def test_slice
sliced_buffer = @buffer.slice(1, 3)
assert_equal(@data[1, 3], sliced_buffer.data.pack("C*"))
assert_equal(@data[1, 3], sliced_buffer.data.to_s)
end
end
2 changes: 1 addition & 1 deletion c_glib/test/test-tensor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_value_type
end

def test_buffer
assert_equal(@raw_data, @tensor.buffer.data)
assert_equal(@raw_data, @tensor.buffer.data.to_s.unpack("c*"))
end

def test_shape
Expand Down

0 comments on commit 3f9b26c

Please sign in to comment.