ART: Rewrite JvmtiUniquePtr
Templatize it over the stored type. Add convenience function for
allocation.
Bug: 31455788
Test: m test-art-host
Change-Id: Idaf0a9170e95141e7a9878923aa93a0dbc80819c
diff --git a/runtime/openjdkjvmti/ti_class.cc b/runtime/openjdkjvmti/ti_class.cc
index a8a0ded..4282e38 100644
--- a/runtime/openjdkjvmti/ti_class.cc
+++ b/runtime/openjdkjvmti/ti_class.cc
@@ -673,18 +673,17 @@
return ERR(INVALID_CLASS);
}
- JvmtiUniquePtr sig_copy;
+ JvmtiUniquePtr<char[]> sig_copy;
if (signature_ptr != nullptr) {
std::string storage;
const char* descriptor = klass->GetDescriptor(&storage);
- unsigned char* tmp;
- jvmtiError ret = CopyString(env, descriptor, &tmp);
- if (ret != ERR(NONE)) {
+ jvmtiError ret;
+ sig_copy = CopyString(env, descriptor, &ret);
+ if (sig_copy == nullptr) {
return ret;
}
- sig_copy = MakeJvmtiUniquePtr(env, tmp);
- *signature_ptr = reinterpret_cast<char*>(tmp);
+ *signature_ptr = sig_copy.get();
}
if (generic_ptr != nullptr) {
@@ -700,12 +699,12 @@
oss << str_array->Get(i)->ToModifiedUtf8();
}
std::string output_string = oss.str();
- unsigned char* tmp;
- jvmtiError ret = CopyString(env, output_string.c_str(), &tmp);
- if (ret != ERR(NONE)) {
+ jvmtiError ret;
+ JvmtiUniquePtr<char[]> copy = CopyString(env, output_string.c_str(), &ret);
+ if (copy == nullptr) {
return ret;
}
- *generic_ptr = reinterpret_cast<char*>(tmp);
+ *generic_ptr = copy.release();
} else if (soa.Self()->IsExceptionPending()) {
// TODO: Should we report an error here?
soa.Self()->ClearException();