Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
correct a thoughtlessness (access violation)
[simgrid.git] / src / java / jmsg.c
index e74aec4..73b69e9 100644 (file)
@@ -844,7 +844,7 @@ Java_simgrid_msg_Msg_init(JNIEnv* env, jclass cls, jobjectArray jargs) {
 
   argc++;
        
-  argv = xbt_new0(char*,1);
+  argv = xbt_new0(char*, argc);
         
   argv[0] = strdup("java");
        
@@ -988,17 +988,26 @@ Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg) {
 JNIEXPORT void JNICALL 
 Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class,jstring jname)
 {
-       int rv;
+   char *errmsg = NULL;
+   xbt_ex_t e;
        
-       /* get the C string from the java string*/
-       const char* name = (*env)->GetStringUTFChars(env, jname, 0);
-
-       rv = xbt_context_select_factory(name);
-               
-       (*env)->ReleaseStringUTFChars(env, jname, name);
+   /* get the C string from the java string*/
+   const char* name = (*env)->GetStringUTFChars(env, jname, 0);
+
+   TRY {
+      xbt_context_select_factory(name);
+   } CATCH(e) {
+      errmsg = xbt_strdup(e.msg);
+      xbt_ex_free(e);
+   }
+   
+   (*env)->ReleaseStringUTFChars(env, jname, name);
        
-       if(rv)
-               jxbt_throw_native(env, xbt_strdup("xbt_select_context_factory() failed"));       
+   if(errmsg) {
+      char *thrown = bprintf("xbt_select_context_factory() failed: %s",errmsg);
+      free(errmsg);
+      jxbt_throw_native(env, thrown);
+   }   
 }
 
 JNIEXPORT void JNICALL