Skip to content

Commit

Permalink
Fix for pystring_to_buffer creation/deallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gem Dot Artigas authored and GemDot committed Sep 20, 2023
1 parent 3f32c00 commit bb34d67
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cpp/arcticdb/pipeline/frame_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void aggregator_set_data(
auto wrapper= convert::py_unicode_to_buffer(*ptr_data, scoped_gil_lock);
agg.set_string_at(col, s, wrapper.buffer_, wrapper.length_);
} else {
auto wrapper = convert::pystring_to_buffer(*ptr_data);
auto wrapper = convert::pystring_to_buffer(*ptr_data, false);
agg.set_string_at(col, s, wrapper.buffer_, wrapper.length_);
}
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/arcticdb/python/python_to_tensor_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ bool is_unicode(PyObject *obj) {
return PyUnicode_Check(obj);
}

PyStringWrapper pystring_to_buffer(PyObject *obj) {
PyStringWrapper pystring_to_buffer(PyObject *obj, bool is_owned) {
char *buffer;
ssize_t length;
util::check(!is_unicode(obj), "Unexpected unicode object");
if (PYBIND11_BYTES_AS_STRING_AND_SIZE(obj, &buffer, &length))
util::raise_rte("Unable to extract string contents! (invalid type)");

return {buffer, length, obj};
return {buffer, length, is_owned ? obj : nullptr};
}

PyStringWrapper py_unicode_to_buffer(PyObject *obj, std::optional<ScopedGILLock>& scoped_gil_lock) {
Expand All @@ -50,7 +50,7 @@ PyStringWrapper py_unicode_to_buffer(PyObject *obj, std::optional<ScopedGILLock>
PyObject* utf8_obj = PyUnicode_AsUTF8String(obj);
if (!utf8_obj)
util::raise_rte("Unable to extract string contents! (encoding issue)");
return pystring_to_buffer(utf8_obj);
return pystring_to_buffer(utf8_obj, true);
}
} else {
util::raise_rte("Expected unicode");
Expand Down
2 changes: 1 addition & 1 deletion cpp/arcticdb/python/python_to_tensor_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct ARCTICDB_VISIBILITY_HIDDEN PyStringWrapper {
};

PyStringWrapper pystring_to_buffer(
PyObject *obj);
PyObject *obj, bool is_owned);

PyStringWrapper py_unicode_to_buffer(
PyObject *obj,
Expand Down

0 comments on commit bb34d67

Please sign in to comment.