Adding JNU_NewObjectByName
@@ -97,6 +97,37 @@ JNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *defaultDetail)
@throw create_JavaIoIOException_initWithNSString_(lastErrorString(defaultDetail));
}
+JNIEXPORT jobject JNICALL
+JNU_NewObjectByName(JNIEnv *env, const char *class_name,
+ const char *constructor_sig, ...)
+{
+ jobject obj = NULL;
+
+ jclass cls = 0;
+ jmethodID cls_initMID;
+ va_list args;
+
+ if ((*env)->EnsureLocalCapacity(env, 2) < 0)
+ goto done;
+
+ cls = (*env)->FindClass(env, class_name);
+ if (cls == 0) {
+ goto done;
+ }
+ cls_initMID = (*env)->GetMethodID(env, cls,
+ "<init>", constructor_sig);
+ if (cls_initMID == NULL) {
+ goto done;
+ }
+ va_start(args, constructor_sig);
+ obj = (*env)->NewObjectV(env, cls, cls_initMID, args);
+ va_end(args);
+
+done:
+ (*env)->DeleteLocalRef(env, cls);
+ return obj;
+}
+
JNIEXPORT jstring
JNU_NewStringPlatform(JNIEnv *env, const char *str) {
return [NSString stringWithUTF8String:str];
