File Fix-compile-error-with-protobuf-RepeatedIterator-137.patch of Package python-onnxruntime
From b4a4fa5aac9e1fafe348f2c9d7d121ed28a35433 Mon Sep 17 00:00:00 2001
From: Jicheng Tang <tangjch15@gmail.com>
Date: Tue, 29 Nov 2022 01:33:53 +0800
Subject: [PATCH] Fix compile error with protobuf RepeatedIterator (#13731)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
### Description
<!-- Describe your changes. -->
There are some compile errors with
google::protobuf::internal::RepeatedIterator.
replace reinterpret_cast with &(*iter), which iter is RepeatedIterator
type.
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
My protobuf version is:
- libprotoc 3.21.5
- g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
when I use build command:
```
./build.sh --use_cuda --cudnn_home /usr --cuda_home /usr/local/cuda --config Debug --build_shared_lib --parallel
```
There are some compile errors like this:
- error 1
onnxruntime/test/util/test_utils.cc:186:105: error: no matching function
for call to ‘make_span(google::protobuf::RepeatedField<long
int>::const_iterator, google::protobuf::RepeatedField<long
int>::const_iterator)’
186 | ind_span = gsl::make_span(indices_proto.int64_data().cbegin(),
indices_proto.int64_data().cend());
- error 2
onnxruntime/test/onnx/tensorprotoutils.cc:101:56: error: invalid cast
from type ‘google::protobuf::internal::RepeatedIterator<const long
unsigned int>’ to type ‘const uint32_t*’ {aka ‘const unsigned int*’}
101 | *p_data++ = *reinterpret_cast<const T*>(data_iter);
---
onnxruntime/test/onnx/tensorprotoutils.cc | 2 +-
onnxruntime/test/util/test_utils.cc | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Index: onnxruntime-1.3.1/onnxruntime/test/onnx/tensorprotoutils.cc
===================================================================
--- onnxruntime-1.3.1.orig/onnxruntime/test/onnx/tensorprotoutils.cc
+++ onnxruntime-1.3.1/onnxruntime/test/onnx/tensorprotoutils.cc
@@ -124,7 +125,7 @@ static void UnpackTensorWithRawData(cons
OrtErrorCode::ORT_FAIL); \
auto& data = tensor.field_name(); \
for (auto data_iter = data.cbegin(); data_iter != data.cend(); ++data_iter) \
- *p_data++ = *reinterpret_cast<const T*>(data_iter); \
+ *p_data++ = gsl::narrow<T>(*data_iter); \
return; \
}
Index: onnxruntime-1.3.1/onnxruntime/core/framework/tensorprotoutils.cc
===================================================================
--- onnxruntime-1.3.1.orig/onnxruntime/core/framework/tensorprotoutils.cc
+++ onnxruntime-1.3.1/onnxruntime/core/framework/tensorprotoutils.cc
@@ -115,7 +116,7 @@ namespace utils {
expected_size, ") does not match the data size(", tensor.field_size(), ") in proto"); \
auto& data = tensor.field_name(); \
for (auto data_iter = data.cbegin(); data_iter != data.cend(); ++data_iter) \
- *p_data++ = *reinterpret_cast<const T*>(data_iter); \
+ *p_data++ = gsl::narrow<T>(*data_iter); \
return Status::OK(); \
}