From 66b1e966370d6aba1fdd678be85ffe5cbda6cbe7 Mon Sep 17 00:00:00 2001 From: LeechyLiang Date: Sun, 6 Apr 2025 21:51:20 +0800 Subject: [PATCH] Modify signature rawString2Builder Signed-off-by: LeechyLiang Change-Id: I476c5585cb5985015622a34b81915800fbaac420 --- interfaces/ets/ani/hilog/BUILD.gn | 1 + interfaces/ets/ani/hilog/src/hilog_ani.cpp | 31 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/interfaces/ets/ani/hilog/BUILD.gn b/interfaces/ets/ani/hilog/BUILD.gn index f9d188c..ac767db 100644 --- a/interfaces/ets/ani/hilog/BUILD.gn +++ b/interfaces/ets/ani/hilog/BUILD.gn @@ -30,6 +30,7 @@ ohos_shared_library("hilog_ani") { external_deps = [ "bounds_checking_function:libsec_shared", "runtime_core:ani", + "runtime_core:ani_helpers", "runtime_core:libarkruntime", ] diff --git a/interfaces/ets/ani/hilog/src/hilog_ani.cpp b/interfaces/ets/ani/hilog/src/hilog_ani.cpp index 9f2d0b9..1d26149 100644 --- a/interfaces/ets/ani/hilog/src/hilog_ani.cpp +++ b/interfaces/ets/ani/hilog/src/hilog_ani.cpp @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -74,6 +75,7 @@ static std::string AniStringToStdString(ani_env *env, ani_string aniStr) static bool isIntParam(ani_env *env, ani_object elementObj) { ani_class intClass; + // Pls replace manually if (ANI_OK != env->FindClass(CLASS_NAME_INT.c_str(), &intClass)) { HiLog::Info(LABEL, "FindClass failed %{public}s", CLASS_NAME_INT.c_str()); return false; @@ -88,6 +90,7 @@ static bool isIntParam(ani_env *env, ani_object elementObj) static bool isBooleanParam(ani_env *env, ani_object elementObj) { ani_class booleanClass; + // Pls replace manually if (ANI_OK != env->FindClass(CLASS_NAME_BOOLEAN.c_str(), &booleanClass)) { HiLog::Info(LABEL, "FindClass failed %{public}s", CLASS_NAME_BOOLEAN.c_str()); return false; @@ -102,6 +105,7 @@ static bool isBooleanParam(ani_env *env, ani_object elementObj) static bool isDoubleParam(ani_env *env, ani_object elementObj) { ani_class doubleClass; + // Pls replace manually if (ANI_OK != env->FindClass(CLASS_NAME_DOUBLE.c_str(), &doubleClass)) { HiLog::Info(LABEL, "FindClass failed %{public}s", CLASS_NAME_DOUBLE.c_str()); return false; @@ -117,6 +121,7 @@ static bool isStringParam(ani_env *env, ani_object elementObj) { ani_class stringClass; const char *className = "Lstd/core/String;"; + // Pls replace manually if (ANI_OK != env->FindClass(className, &stringClass)) { HiLog::Info(LABEL, "FindClass failed %{public}s", className); return false; @@ -131,6 +136,7 @@ static bool isStringParam(ani_env *env, ani_object elementObj) static bool isBigIntParam(ani_env *env, ani_object elementObj) { ani_class bigIntClass; + // Pls replace manually if (ANI_OK != env->FindClass(CLASS_NAME_BIGINT.c_str(), &bigIntClass)) { HiLog::Info(LABEL, "FindClass failed %{public}s", CLASS_NAME_BIGINT.c_str()); return false; @@ -145,12 +151,16 @@ static bool isBigIntParam(ani_env *env, ani_object elementObj) static void parseIntParam(ani_env *env, ani_object elementObj, std::vector& params) { ani_class intClass; + // Pls replace manually if (ANI_OK != env->FindClass(CLASS_NAME_INT.c_str(), &intClass)) { HiLog::Info(LABEL, "FindClass failed %{public}s", CLASS_NAME_INT.c_str()); return; } ani_method unboxedMethod; - if (ANI_OK != env->Class_FindMethod(intClass, FUNC_NAME_UNBOXED.c_str(), ":I", &unboxedMethod)) { + arkts::ani_signature::SignatureBuilder FUNC_NAME_UNBOXED.c_str()SigBuilder; + FUNC_NAME_UNBOXED.c_str()SigBuilder.SetReturnInt(); + auto FUNC_NAME_UNBOXED.c_str()Signature = FUNC_NAME_UNBOXED.c_str()SigBuilder.BuildSignatureDescriptor(); + if (ANI_OK != env->Class_FindMethod(intClass, FUNC_NAME_UNBOXED.c_str(), FUNC_NAME_UNBOXED.c_str()Signature.c_str(), &unboxedMethod)) { HiLog::Info(LABEL, "Class_FindMethod failed %{public}s", FUNC_NAME_UNBOXED.c_str()); return; } @@ -169,12 +179,16 @@ static void parseIntParam(ani_env *env, ani_object elementObj, std::vector& params) { ani_class booleanClass; + // Pls replace manually if (ANI_OK != env->FindClass(CLASS_NAME_BOOLEAN.c_str(), &booleanClass)) { HiLog::Info(LABEL, "FindClass failed %{public}s", CLASS_NAME_BOOLEAN.c_str()); return; } ani_method unboxedMethod; - if (ANI_OK != env->Class_FindMethod(booleanClass, FUNC_NAME_UNBOXED.c_str(), ":Z", &unboxedMethod)) { + arkts::ani_signature::SignatureBuilder FUNC_NAME_UNBOXED.c_str()SigBuilder; + FUNC_NAME_UNBOXED.c_str()SigBuilder.SetReturnBoolean(); + auto FUNC_NAME_UNBOXED.c_str()Signature = FUNC_NAME_UNBOXED.c_str()SigBuilder.BuildSignatureDescriptor(); + if (ANI_OK != env->Class_FindMethod(booleanClass, FUNC_NAME_UNBOXED.c_str(), FUNC_NAME_UNBOXED.c_str()Signature.c_str(), &unboxedMethod)) { HiLog::Info(LABEL, "Class_FindMethod failed %{public}s", FUNC_NAME_UNBOXED.c_str()); return; } @@ -193,12 +207,16 @@ static void parseBooleanParam(ani_env *env, ani_object elementObj, std::vector& params) { ani_class doubleClass; + // Pls replace manually if (ANI_OK != env->FindClass(CLASS_NAME_DOUBLE.c_str(), &doubleClass)) { HiLog::Info(LABEL, "FindClass failed %{public}s", CLASS_NAME_DOUBLE.c_str()); return; } ani_method unboxedMethod; - if (ANI_OK != env->Class_FindMethod(doubleClass, FUNC_NAME_UNBOXED.c_str(), ":D", &unboxedMethod)) { + arkts::ani_signature::SignatureBuilder FUNC_NAME_UNBOXED.c_str()SigBuilder; + FUNC_NAME_UNBOXED.c_str()SigBuilder.SetReturnDouble(); + auto FUNC_NAME_UNBOXED.c_str()Signature = FUNC_NAME_UNBOXED.c_str()SigBuilder.BuildSignatureDescriptor(); + if (ANI_OK != env->Class_FindMethod(doubleClass, FUNC_NAME_UNBOXED.c_str(), FUNC_NAME_UNBOXED.c_str()Signature.c_str(), &unboxedMethod)) { HiLog::Info(LABEL, "Class_FindMethod failed %{public}s", FUNC_NAME_UNBOXED.c_str()); return; } @@ -226,9 +244,13 @@ static void parseStringParam(ani_env *env, ani_object elementObj, std::vector& params) { ani_class bigIntClass; + // Pls replace manually env->FindClass(CLASS_NAME_BIGINT.c_str(), &bigIntClass); ani_method getLongMethod; - if (ANI_OK != env->Class_FindMethod(bigIntClass, FUNC_NAME_GETLONG.c_str(), ":J", &getLongMethod)) { + arkts::ani_signature::SignatureBuilder FUNC_NAME_GETLONG.c_str()SigBuilder; + FUNC_NAME_GETLONG.c_str()SigBuilder.SetReturnLong(); + auto FUNC_NAME_GETLONG.c_str()Signature = FUNC_NAME_GETLONG.c_str()SigBuilder.BuildSignatureDescriptor(); + if (ANI_OK != env->Class_FindMethod(bigIntClass, FUNC_NAME_GETLONG.c_str(), FUNC_NAME_GETLONG.c_str()Signature.c_str(), &getLongMethod)) { HiLog::Info(LABEL, "Class_FindMethod failed %{public}s", FUNC_NAME_GETLONG.c_str()); return; } @@ -457,6 +479,7 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) } ani_class cls {}; + // Pls replace manually if (ANI_OK != env->FindClass(CLASS_NAME_HILOGANI.c_str(), &cls)) { return ANI_INVALID_ARGS; } -- Gitee