From b25fdab6b3ee35a75e737b953b807add2d1835ef Mon Sep 17 00:00:00 2001 From: Korobeinikov Evgeny Date: Tue, 4 Feb 2025 20:05:45 +0300 Subject: [PATCH 1/2] Remove throw --- interop/src/cpp/DeserializerBase.h | 4 ---- interop/src/cpp/SerializerBase.h | 1 - interop/src/cpp/ets/convertors-ets.cc | 3 --- interop/src/cpp/types/signatures.cc | 2 -- 4 files changed, 10 deletions(-) diff --git a/interop/src/cpp/DeserializerBase.h b/interop/src/cpp/DeserializerBase.h index eb87c4109..40af182c9 100644 --- a/interop/src/cpp/DeserializerBase.h +++ b/interop/src/cpp/DeserializerBase.h @@ -53,7 +53,6 @@ inline const char *tagName(InteropTag tag) return "OBJECT"; } fprintf(stderr, "tag name %d is wrong\n", tag); - throw "Error"; } inline const char *tagNameExact(InteropTag tag) @@ -76,7 +75,6 @@ inline const char *tagNameExact(InteropTag tag) return "INTEROP_TAG_OBJECT"; } fprintf(stderr, "tag name %d is wrong\n", tag); - throw "Error"; } inline InteropFunction makeArkFunctionFromId(InteropInt32 id) { @@ -465,7 +463,6 @@ public: else { fprintf(stderr, "Bad number tag %d\n", result.tag); - throw "Unknown number tag"; } return result; } @@ -504,7 +501,6 @@ public: default: { fprintf(stderr, "Bad length tag %d\n", result.type); - throw "Error"; } } return result; diff --git a/interop/src/cpp/SerializerBase.h b/interop/src/cpp/SerializerBase.h index 951ccac94..56da4bb65 100644 --- a/interop/src/cpp/SerializerBase.h +++ b/interop/src/cpp/SerializerBase.h @@ -173,7 +173,6 @@ public: writeFloat32(value.f32); } else { fprintf(stderr, "Bad number tag %d\n", value.tag); - throw "Unknown number tag"; } } diff --git a/interop/src/cpp/ets/convertors-ets.cc b/interop/src/cpp/ets/convertors-ets.cc index 455548eeb..d6f66171c 100644 --- a/interop/src/cpp/ets/convertors-ets.cc +++ b/interop/src/cpp/ets/convertors-ets.cc @@ -111,7 +111,6 @@ const std::vector>& EtsExports: auto it = implementations.find(module); if (it == implementations.end()) { LOGE("Module %s is not registered", module.c_str()); - throw "Fatal error"; } return it->second; } @@ -130,7 +129,6 @@ void EtsExports::setClasspath(const char* module, const char *classpath) { classpaths.insert(std::make_pair(module, classpath)); } else { LOGE("Classpath for module %s was redefined", module); - throw "Fatal error"; } } @@ -151,5 +149,4 @@ const std::string& EtsExports::getClasspath(const std::string& module) { return defaultClasspath->second; } LOGE("Classpath for module %s was not registered", module.c_str()); - throw "Fatal error"; } diff --git a/interop/src/cpp/types/signatures.cc b/interop/src/cpp/types/signatures.cc index 3d035719f..9e16aa586 100644 --- a/interop/src/cpp/types/signatures.cc +++ b/interop/src/cpp/types/signatures.cc @@ -78,7 +78,6 @@ std::string sigType(const std::string &type) { KOALA_INTEROP_TYPEDEFS("sigType", "jni") #endif fprintf(stderr, "Unhandled type: %s\n", type.c_str()); - throw "Error"; } std::string codeType(const std::string &type) { @@ -88,7 +87,6 @@ std::string codeType(const std::string &type) { KOALA_INTEROP_TYPEDEFS("codeType", "jni") #endif fprintf(stderr, "Unhandled type: %s\n", type.c_str()); - throw "Error"; } std::string convertType(const char* name, const char* koalaType) { -- Gitee From 6fa7fba2c39beedb8b2cf3d8114d54d5d0092ed5 Mon Sep 17 00:00:00 2001 From: Korobeinikov Evgeny Date: Tue, 4 Feb 2025 21:26:26 +0300 Subject: [PATCH 2/2] add INTEROP_FATAL macro --- interop/src/cpp/DeserializerBase.h | 8 ++++---- interop/src/cpp/SerializerBase.h | 2 +- interop/src/cpp/interop-types.h | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/interop/src/cpp/DeserializerBase.h b/interop/src/cpp/DeserializerBase.h index 40af182c9..7f62a8768 100644 --- a/interop/src/cpp/DeserializerBase.h +++ b/interop/src/cpp/DeserializerBase.h @@ -52,7 +52,7 @@ inline const char *tagName(InteropTag tag) case InteropTag::INTEROP_TAG_OBJECT: return "OBJECT"; } - fprintf(stderr, "tag name %d is wrong\n", tag); + INTEROP_FATAL("Fatal error"); } inline const char *tagNameExact(InteropTag tag) @@ -74,7 +74,7 @@ inline const char *tagNameExact(InteropTag tag) case InteropTag::INTEROP_TAG_OBJECT: return "INTEROP_TAG_OBJECT"; } - fprintf(stderr, "tag name %d is wrong\n", tag); + INTEROP_FATAL("Fatal error"); } inline InteropFunction makeArkFunctionFromId(InteropInt32 id) { @@ -462,7 +462,7 @@ public: } else { - fprintf(stderr, "Bad number tag %d\n", result.tag); + INTEROP_FATAL("Fatal error"); } return result; } @@ -500,7 +500,7 @@ public: } default: { - fprintf(stderr, "Bad length tag %d\n", result.type); + INTEROP_FATAL("Fatal error"); } } return result; diff --git a/interop/src/cpp/SerializerBase.h b/interop/src/cpp/SerializerBase.h index 56da4bb65..8d6381466 100644 --- a/interop/src/cpp/SerializerBase.h +++ b/interop/src/cpp/SerializerBase.h @@ -172,7 +172,7 @@ public: } else if (value.tag == InteropTag::INTEROP_TAG_FLOAT32) { writeFloat32(value.f32); } else { - fprintf(stderr, "Bad number tag %d\n", value.tag); + INTEROP_FATAL("Unknown tag number"); } } diff --git a/interop/src/cpp/interop-types.h b/interop/src/cpp/interop-types.h index b8aeefb34..ff0f53b4f 100644 --- a/interop/src/cpp/interop-types.h +++ b/interop/src/cpp/interop-types.h @@ -3,6 +3,8 @@ #include +#define INTEROP_FATAL(msg, ...) fprintf(stderr, msg "\n", ##__VA_ARGS__); assert(false); + typedef enum InteropTag { INTEROP_TAG_UNDEFINED = 101, -- Gitee