This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

JNI issues


Hi!

Is this the right thing to do?

(otherwise java::lang::System::init_properties segfaults, because
_Jv_Compiler_Properties is NULL)

I used this patch to avoid a segfault in java::lang::System::init_properties:

diff -Nrc3p gcc-20010129.orig/libjava/jni.cc gcc-20010129/libjava/jni.cc
*** gcc-20010129.orig/libjava/jni.cc	Sat Jan 27 20:30:31 2001
--- gcc-20010129/libjava/jni.cc	Tue Jan 30 14:12:28 2001
*************** details.  */
*** 20,25 ****
--- 20,26 ----
  #include <jvm.h>
  #include <java-assert.h>
  #include <jni.h>
+ #include <java-props.h>
  #ifdef ENABLE_JVMPI
  #include <jvmpi.h>
  #endif
*************** JNI_CreateJavaVM (JavaVM **vm, void **pe
*** 1976,1981 ****
--- 1977,1984 ----
      return JNI_ERR;
    nvm->functions = &_Jv_JNI_InvokeFunctions;
  
+   JvAssert (! _Jv_Compiler_Properties);
+ 
    // Parse the arguments.
    if (args != NULL)
      {
*************** JNI_CreateJavaVM (JavaVM **vm, void **pe
*** 1984,1989 ****
--- 1987,2007 ----
        if (version != JNI_VERSION_1_2)
  	return JNI_EVERSION;
        JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
+ 
+       // count the options starting with -D
+       int nprops = 0;
+       for (int i = 0; i < ia->nOptions; ++i)
+          if (ia->options[i].optionString[0] == '-' && 
+                  ia->options[i].optionString[1] == 'D')
+              nprops++;
+      
+       _Jv_Compiler_Properties = 
+           (const char **)_Jv_MallocUnchecked ((nprops+1) * sizeof (const char*));
+       if (_Jv_Compiler_Properties == NULL)
+           return JNI_ERR;
+       _Jv_Compiler_Properties[nprops] = NULL;
+ 
+       nprops = 0;
        for (int i = 0; i < ia->nOptions; ++i)
  	{
  	  if (! strcmp (ia->options[i].optionString, "vfprintf")
*************** JNI_CreateJavaVM (JavaVM **vm, void **pe
*** 2004,2010 ****
  	    }
  	  else if (! strncmp (ia->options[i].optionString, "-D", 2))
  	    {
! 	      // FIXME.
  	      continue;
  	    }
  	  else if (ia->ignoreUnrecognized)
--- 2022,2033 ----
  	    }
  	  else if (! strncmp (ia->options[i].optionString, "-D", 2))
  	    {
!               int proplen = strlen(& ia->options[i].optionString[2]);
!               _Jv_Compiler_Properties[nprops] = (const char*) _Jv_MallocUnchecked (proplen+1);
!               if (_Jv_Compiler_Properties[nprops] == NULL)
!                   return JNI_ERR;
!               memcpy((void*)_Jv_Compiler_Properties[nprops++], 
!                       &ia->options[i].optionString[2], proplen+1);
  	      continue;
  	    }
  	  else if (ia->ignoreUnrecognized)
*************** JNI_CreateJavaVM (JavaVM **vm, void **pe
*** 2016,2021 ****
--- 2039,2053 ----
  
  	  return JNI_ERR;
  	}
+     }
+  
+   if ( ! _Jv_Compiler_Properties )
+     {
+      _Jv_Compiler_Properties = 
+          (const char**)_Jv_MallocUnchecked (sizeof (const char*));
+      if (_Jv_Compiler_Properties == NULL)
+          return JNI_ERR;
+      _Jv_Compiler_Properties[0] = NULL;
      }
  
    jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);


-- 
The early bird gets the worm. If you want something else for       
breakfast, get up later.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]