Skip to content

Commit

Permalink
Merge pull request #135 from xhochy/steal-arrow-reference
Browse files Browse the repository at this point in the history
Interpret Arrow results as stolen references
  • Loading branch information
MathMagique authored Oct 10, 2017
2 parents 89262b4 + 5508fbf commit cb28ee2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Version history / changelog

From version 2.0.0, turbodbc adapts semantic versioning.

Version 2.4.1
-------------

* Fixed a memory leak on ``fetchallarrow()`` that increased the reference
count of the returned table by one too much.

Version 2.4.0
-------------

Expand Down
2 changes: 1 addition & 1 deletion cpp/turbodbc_arrow/Library/src/arrow_result_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pybind11::object arrow_result_set::fetch_all()
}

arrow::py::import_pyarrow();
return pybind11::reinterpret_borrow<pybind11::object>(pybind11::handle(arrow::py::wrap_table(table)));
return pybind11::reinterpret_steal<pybind11::object>(pybind11::handle(arrow::py::wrap_table(table)));
}


Expand Down
13 changes: 13 additions & 0 deletions python/turbodbc_test/test_select_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from mock import patch

import datetime
import gc
import pytest
import sys
import turbodbc

from query_fixture import query_fixture
Expand Down Expand Up @@ -56,6 +58,17 @@ def test_arrow_empty_column(dsn, configuration):
assert result.num_rows == 0


@for_each_database
@pyarrow
def test_arrow_reference_count(dsn, configuration):
with open_cursor(configuration) as cursor:
with query_fixture(cursor, configuration, 'INSERT INTEGER') as table_name:
cursor.execute("SELECT a FROM {}".format(table_name))
result = cursor.fetchallarrow()
gc.collect()
assert sys.getrefcount(result) == 2


@for_each_database
@pyarrow
def test_arrow_int_column(dsn, configuration):
Expand Down

0 comments on commit cb28ee2

Please sign in to comment.