Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/src/arrow/python/builtin_convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class BytesConverter : public TypedConverter<BinaryBuilder> {
// No error checking
length = PyBytes_GET_SIZE(bytes_obj);
bytes = PyBytes_AS_STRING(bytes_obj);
RETURN_NOT_OK(typed_builder_->Append(bytes, length));
RETURN_NOT_OK(typed_builder_->Append(bytes, static_cast<int32_t>(length)));
}
return Status::OK();
}
Expand Down Expand Up @@ -422,7 +422,7 @@ class UTF8Converter : public TypedConverter<StringBuilder> {
// No error checking
length = PyBytes_GET_SIZE(bytes_obj);
bytes = PyBytes_AS_STRING(bytes_obj);
RETURN_NOT_OK(typed_builder_->Append(bytes, length));
RETURN_NOT_OK(typed_builder_->Append(bytes, static_cast<int32_t>(length)));
}
return Status::OK();
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/python/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ MemoryPool* get_memory_pool() {
// ----------------------------------------------------------------------
// PyBuffer

PyBuffer::PyBuffer(PyObject* obj) : Buffer(nullptr, 0) {
PyBuffer::PyBuffer(PyObject* obj) : Buffer(nullptr, 0), obj_(nullptr) {
if (PyObject_CheckBuffer(obj)) {
obj_ = PyMemoryView_FromObject(obj);
Py_buffer* buffer = PyMemoryView_GET_BUFFER(obj_);
Expand All @@ -61,7 +61,7 @@ PyBuffer::PyBuffer(PyObject* obj) : Buffer(nullptr, 0) {

PyBuffer::~PyBuffer() {
PyAcquireGIL lock;
Py_DECREF(obj_);
Py_XDECREF(obj_);
}

} // namespace py
Expand Down
10 changes: 8 additions & 2 deletions cpp/src/arrow/python/pandas-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,26 @@

#include "arrow/array.h"
#include "arrow/builder.h"
#include "arrow/python/pandas_convert.h"
#include "arrow/table.h"
#include "arrow/test-util.h"
#include "arrow/type.h"

#include "arrow/python/common.h"
#include "arrow/python/pandas_convert.h"

namespace arrow {
namespace py {

TEST(PyBuffer, InvalidInputObject) {
PyBuffer buffer(Py_None);
}

TEST(PandasConversionTest, TestObjectBlockWriteFails) {
StringBuilder builder(default_memory_pool());
const char value[] = {'\xf1', '\0'};

for (int i = 0; i < 1000; ++i) {
builder.Append(value, strlen(value));
builder.Append(value, static_cast<int32_t>(strlen(value)));
}

std::shared_ptr<Array> arr;
Expand Down
10 changes: 5 additions & 5 deletions cpp/src/arrow/python/pandas_convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ Status AppendObjectStrings(StringBuilder& string_builder, PyObject** objects,
PyErr_Clear();
return Status::TypeError("failed converting unicode to UTF8");
}
const int64_t length = PyBytes_GET_SIZE(obj);
const int32_t length = static_cast<int32_t>(PyBytes_GET_SIZE(obj));
Status s = string_builder.Append(PyBytes_AS_STRING(obj), length);
Py_DECREF(obj);
if (!s.ok()) { return s; }
} else if (PyBytes_Check(obj)) {
*have_bytes = true;
const int64_t length = PyBytes_GET_SIZE(obj);
const int32_t length = static_cast<int32_t>(PyBytes_GET_SIZE(obj));
RETURN_NOT_OK(string_builder.Append(PyBytes_AS_STRING(obj), length));
} else {
string_builder.AppendNull();
Expand Down Expand Up @@ -235,7 +235,7 @@ class PandasConverter : public TypeVisitor {
}

Status InitNullBitmap() {
int null_bytes = BitUtil::BytesForBits(length_);
int64_t null_bytes = BitUtil::BytesForBits(length_);

null_bitmap_ = std::make_shared<PoolBuffer>(pool_);
RETURN_NOT_OK(null_bitmap_->Resize(null_bytes));
Expand Down Expand Up @@ -357,7 +357,7 @@ inline Status PandasConverter::ConvertData(std::shared_ptr<Buffer>* data) {

template <>
inline Status PandasConverter::ConvertData<BooleanType>(std::shared_ptr<Buffer>* data) {
int nbytes = BitUtil::BytesForBits(length_);
int64_t nbytes = BitUtil::BytesForBits(length_);
auto buffer = std::make_shared<PoolBuffer>(pool_);
RETURN_NOT_OK(buffer->Resize(nbytes));

Expand Down Expand Up @@ -423,7 +423,7 @@ Status PandasConverter::ConvertBooleans(std::shared_ptr<Array>* out) {

PyObject** objects = reinterpret_cast<PyObject**>(PyArray_DATA(arr_));

int nbytes = BitUtil::BytesForBits(length_);
int64_t nbytes = BitUtil::BytesForBits(length_);
auto data = std::make_shared<PoolBuffer>(pool_);
RETURN_NOT_OK(data->Resize(nbytes));
uint8_t* bitmap = data->mutable_data();
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/python/pandas_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace arrow {

class Array;
class Column;
class DataType;
struct DataType;
class MemoryPool;
class Status;
class Table;
Expand Down