From 845bbfc9c55a6e7e62a13af04a305b5b2ebdb8b8 Mon Sep 17 00:00:00 2001 From: Xuejun Zhai Date: Tue, 26 Sep 2023 22:21:50 +0800 Subject: [PATCH] [C API] Fix the BOOLEAN in ov_element_type conflict with the typedefine in Windows.h (#19380) * [C API] Fix BOOLEAN confict between Windows.h & ov_element_type_e in OV Signed-off-by: Zhai, Xuejun * [C API] fix clang format Signed-off-by: Zhai, Xuejun * [C API] Add test for BOOLEAN conflict Signed-off-by: Zhai, Xuejun * [C API] fix clang format Signed-off-by: Zhai, Xuejun * [C API] Fix warning & comments Signed-off-by: Zhai, Xuejun * [C API] enable OV_BOOLEAN for windows & linux Signed-off-by: Zhai, Xuejun * [C API] fix build error Signed-off-by: Zhai, Xuejun * [C API] Remove WIN_BOOLEAN Signed-off-by: Zhai, Xuejun * Update ov_windows_conflict_test.cpp --------- Signed-off-by: Zhai, Xuejun --- src/bindings/c/include/openvino/c/openvino.h | 6 +++++ .../c/tests/ov_windows_conflict_test.cpp | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/bindings/c/tests/ov_windows_conflict_test.cpp diff --git a/src/bindings/c/include/openvino/c/openvino.h b/src/bindings/c/include/openvino/c/openvino.h index f49a5049f7e..c534fc688d1 100644 --- a/src/bindings/c/include/openvino/c/openvino.h +++ b/src/bindings/c/include/openvino/c/openvino.h @@ -15,6 +15,12 @@ **/ #pragma once +#ifdef _WINDOWS_ +# pragma message( \ + "The BOOLEAN define in ov_element_type_e conflict with Windows.h BOOLEAN define. The BOOLEAN of ov_element_type_e redefine to OV_BOOLEAN here. If you want to use BOOLEAN of Windows.h, pls redefine befor include openvino/c/openvino.h, such as typedef BOOLEAN WIN_BOOLEAN") +#endif +#define BOOLEAN OV_BOOLEAN + #include "openvino/c/auto/properties.h" #include "openvino/c/ov_common.h" #include "openvino/c/ov_compiled_model.h" diff --git a/src/bindings/c/tests/ov_windows_conflict_test.cpp b/src/bindings/c/tests/ov_windows_conflict_test.cpp new file mode 100644 index 00000000000..07262bddeeb --- /dev/null +++ b/src/bindings/c/tests/ov_windows_conflict_test.cpp @@ -0,0 +1,26 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/* + * This test only for Windows, which caused by the BOOLEAN define conflict between Windows.h and openvino.h + * (ov_element_type_e). Sollution: 1) check Windows.h was used or not in openvino.h for windows OS 2) if YES, will + * redefine the "BOOLEAN" from Windows.h to "WIN_BOOLEAN" and also redefine the "BOOLEAN" from openvino.h to + * "OV_BOOLEAN" + */ + +#if defined(_WIN32) +# include +# include + +# include "openvino/c/openvino.h" + +# ifndef UNUSED +# define UNUSED(x) ((void)(x)) +# endif + +TEST(ov_windows_conflict_test, ov_windows_boolean_conflict) { + ov_element_type_e element_type = OV_BOOLEAN; // The BOOLEAN from ov_element_type_e will be replaced by OV_BOOLEAN + UNUSED(element_type); +} +#endif