mirror of
https://github.com/Takiiiiiiii/strato.git
synced 2025-07-17 08:46:39 +00:00
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:
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user