Introduce JniString as C++ wrapper over jstring

We used to manually call JNI UTF-8 string allocation and deallocation functions when utilizing a `jstring` but this could be erroneous and is just inconvenient. All of this has now been consolidated into an class `JniString` which is a wrapper around `std::string` and creates a copy of the contents of the `jstring` in its constructor and passes them into the `std::string` constructor.
This commit is contained in:
PixelyIon
2021-11-09 21:18:47 +05:30
parent 79ceb2cf23
commit fb476567ff
4 changed files with 23 additions and 11 deletions

View File

@ -4,6 +4,13 @@
#include "jvm.h"
namespace skyline {
std::string JniString::GetJString(JNIEnv *env, jstring jString) {
auto utf{env->GetStringUTFChars(jString, nullptr)};
std::string string{utf};
env->ReleaseStringUTFChars(jString, utf);
return string;
}
/*
* @brief A thread-local wrapper over JNIEnv and JavaVM which automatically handles attaching and detaching threads
*/