Don't convert nullptr to std::string in C layer

PiperOrigin-RevId: 569232756
This commit is contained in:
Sebastian Schmidt 2023-09-28 11:02:09 -07:00 committed by Copybara-Service
parent a577dc3043
commit 33d6143a1a
2 changed files with 11 additions and 3 deletions

View File

@ -14,6 +14,7 @@ limitations under the License.
==============================================================================*/
#include <cstdint>
#include <string>
#include <vector>
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
@ -24,7 +25,8 @@ namespace mediapipe::tasks::c::components::processors {
void CppConvertToClassifierOptions(
const ClassifierOptions& in,
mediapipe::tasks::components::processors::ClassifierOptions* out) {
out->display_names_locale = in.display_names_locale;
out->display_names_locale =
in.display_names_locale ? std::string(in.display_names_locale) : "";
out->max_results = in.max_results;
out->score_threshold = in.score_threshold;
out->category_allowlist =

View File

@ -15,6 +15,9 @@ limitations under the License.
#include "mediapipe/tasks/c/core/base_options_converter.h"
#include <memory>
#include <string>
#include "mediapipe/tasks/c/core/base_options.h"
#include "mediapipe/tasks/cc/core/base_options.h"
@ -23,8 +26,11 @@ namespace mediapipe::tasks::c::components::containers {
void CppConvertToBaseOptions(const BaseOptions& in,
mediapipe::tasks::core::BaseOptions* out) {
out->model_asset_buffer =
std::make_unique<std::string>(in.model_asset_buffer);
out->model_asset_path = in.model_asset_path;
in.model_asset_buffer
? std::make_unique<std::string>(in.model_asset_buffer)
: nullptr;
out->model_asset_path =
in.model_asset_path ? std::string(in.model_asset_path) : "";
}
} // namespace mediapipe::tasks::c::components::containers