Skip to content

Commit

Permalink
Warn about undefined behavior in Flight source
Browse files Browse the repository at this point in the history
  • Loading branch information
David Li authored and David Li committed Feb 5, 2019
1 parent 1f816e8 commit cd56782
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cpp/src/arrow/flight/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FlightStreamReader : public RecordBatchReader {
}

// For customizing read path for better memory/serialization efficiency
// XXX this cast is undefined behavior
auto custom_reader = reinterpret_cast<grpc::ClientReader<FlightData>*>(stream_.get());

// Explicitly specify the override to invoke - otherwise compiler
Expand Down Expand Up @@ -126,6 +127,7 @@ class FlightPutWriter::FlightPutWriterImpl : public ipc::RecordBatchWriter {
Status WriteRecordBatch(const RecordBatch& batch, bool allow_64bit = false) override {
IpcPayload payload;
RETURN_NOT_OK(ipc::internal::GetRecordBatchPayload(batch, pool_, &payload));
// XXX this cast is undefined behavior
auto custom_writer = reinterpret_cast<grpc::ClientWriter<IpcPayload>*>(writer_.get());
// Explicitly specify the override to invoke - otherwise compiler
// may invoke through vtable (not updated by reinterpret_cast)
Expand Down
7 changes: 6 additions & 1 deletion cpp/src/arrow/flight/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class FlightMessageReaderImpl : public FlightMessageReader {
return Status::OK();
}

// XXX this cast is undefined behavior
auto custom_reader = reinterpret_cast<grpc::ServerReader<FlightData>*>(reader_);

FlightData data;
Expand Down Expand Up @@ -184,6 +185,7 @@ class FlightServiceImpl : public FlightService::Service {
GRPC_RETURN_NOT_OK(server_->DoGet(ticket, &data_stream));

// Requires ServerWriter customization in grpc_customizations.h
// XXX this cast is undefined behavior
auto custom_writer = reinterpret_cast<ServerWriter<IpcPayload>*>(writer);

// Write the schema as the first message in the stream
Expand All @@ -192,7 +194,10 @@ class FlightServiceImpl : public FlightService::Service {
ipc::DictionaryMemo dictionary_memo;
GRPC_RETURN_NOT_OK(ipc::internal::GetSchemaPayload(
*data_stream->schema(), pool, &dictionary_memo, &schema_payload));
custom_writer->Write(schema_payload, grpc::WriteOptions());
// Explicitly specify the override to invoke - otherwise compiler
// may invoke through vtable (not updated by reinterpret_cast)
custom_writer->grpc::ServerWriter<IpcPayload>::Write(schema_payload,
grpc::WriteOptions());

while (true) {
IpcPayload payload;
Expand Down

0 comments on commit cd56782

Please sign in to comment.