[tcljava-dev] Proposed patch for passing multiple args to JVM
Brought to you by:
mdejong
|
From: Mark T. <mar...@am...> - 2002-05-08 17:02:16
|
Hello,
I hope I'm doing this correctly - I apologize if not.
I have made a change to the JavaInitEnv() method in javaCmd.c that allows
multiple
arguments to be passed to the JVM (via tclblend_init) when initialized (for
example,
-Djava.security.manager -Djava.security.policy=file:c:\\tmp\\java.policy).
Prior to
this, the number of args was limited to 2, with one being the CLASSPATH.
The changes (diff -u) are below.
Best wishes,
Mark Thornton
HMS Software
Phone: (847)854-8961
Fax: (847)854-8986
############################################################################
########
diff -u -w /tcl/src/tclblend1.3.0/src/native/javaCmd.c
/tcl/src/tcljava/tcljava/src/native/javaCmd.c
--- /tcl/src/tclblend1.3.0/src/native/javaCmd.c Wed May 08 11:18:37 2002
+++ /tcl/src/tcljava/tcljava/src/native/javaCmd.c Sun Oct 29 20:22:29 2000
@@ -350,7 +350,7 @@
{
jsize nVMs;
char *path, *newPath;
- int oldSize, size;
+ int oldSize, size, maxOptions = 2;
#ifdef JDK1_2
JavaVMOption *options;
JavaVMInitArgs vm_args;
@@ -359,9 +359,6 @@
#else
JDK1_1InitArgs vm_args;
#endif /* JDK1_2 */
- int i, n_jvm_args = 0;
- char *tclblend_init, *token, *jvm_args;
- char jvm_arg_sep[] = " ";
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
@@ -419,52 +416,9 @@
fprintf(stderr, "TCLBLEND_DEBUG: No JVM, creating one\n");
#endif /* TCLBLEND_DEBUG */
- /* get the classpath */
- path = getenv("CLASSPATH");
-
memset(&vm_args, 0, sizeof(vm_args));
#ifdef JDK1_2
- /*
- * If the global tcl_variable tclblend_init is set, then pass its
- * value to the JVM.
- * If the value of the string is "help", then initialization
- * of the JVM does not occur and a usage string is returned.
- */
-
- if ((tclblend_init = (void *) Tcl_GetVar(interp, "tclblend_init",
- TCL_GLOBAL_ONLY)) != NULL) {
- if ( !strcmp(tclblend_init, "help")) {
- Tcl_AppendResult(interp,
- "The value of the global tcl variable 'tclblend_init' is passed to
the\n "
- "Java virtual machine upon initialization.\n "
- "Example values include:\n"
- " -Djava.compiler=NONE - disable Just In Time Compiler\n"
- " -Djava.library.path=c:\\jdk\\lib\\tools.jar - set native library
path\n"
- " -verbose:jni - print debugging messages\n"
- "\nFor -verbose, the value should be a string with one or\n"
- "more comma separated names (i.e. class,jni). In JDK1.2,\n"
- "the standard names are: class, gc, jni\n"
- "To see what other options are available, run 'java -help'.\n"
- "Tcl Blend only: If the value is 'help', then JVM initialization
stop\n",
- "and this message is returned.",
- NULL);
- goto error;
- }
- jvm_args = ckalloc(strlen(tclblend_init + 1));
- strcpy(jvm_args, tclblend_init);
- token = strtok(jvm_args, jvm_arg_sep);
- while(token != NULL) {
- token = strtok(NULL, jvm_arg_sep);
- n_jvm_args++;
- }
- }
-
- /* if the classpath is set, allow for it */
- if (path) {
- n_jvm_args++;
- }
-
- options = (JavaVMOption *) ckalloc(sizeof(JavaVMOption) *
n_jvm_args);
+ options = (JavaVMOption *) ckalloc(sizeof(JavaVMOption) *
maxOptions);
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.ignoreUnrecognized= 1;
@@ -495,6 +449,8 @@
* 1.1, we need to append to the vm_args.classpath.
*/
+ path = getenv("CLASSPATH");
+
#ifdef JDK1_2
#define JAVA_CLASS_PATH_ARG "-Djava.class.path="
if (path) {
@@ -505,31 +461,6 @@
strcat(options[0].optionString, path);
options[0].extraInfo = (void *)NULL;
}
-
- /* Now add any additional args */
- i=1;
- strcpy(jvm_args, tclblend_init);
- token = strtok(jvm_args, jvm_arg_sep);
- while(token != NULL) {
- options[i].optionString = token;
- options[i].extraInfo = (void *)NULL;
- token = strtok(NULL, jvm_arg_sep);
- i++;
- }
- ckfree(jvm_args);
-#ifdef TCLBLEND_DEBUG
- fprintf(stderr, "TCLBLEND_DEBUG: tclblend_init set\n"
- " vm_args.version: %x\n"
- " vm_args.nOptions: %d\n",
- vm_args.version, vm_args.nOptions);
- for( i = 0; i < n_jvm_args; i++) {
- fprintf(stderr,
- " options[%d].optionString = '%s', "
- " options.[%d].extraInfo = '%s'\n",
- i, options[i].optionString, i,
- options[i].extraInfo ? (char *)options[i].extraInfo : "NULL");
- }
-#endif /* TCLBLEND_DEBUG */
#else
if (path && vm_args.classpath) {
oldSize = strlen(path);
@@ -557,6 +488,58 @@
#endif /* JDK1_2 */
#endif /* TCLBLEND_DEBUG */
+
+#ifdef JDK1_2
+ /*
+ * If the global tcl_variable tclblend_init is set, then pass its
+ * value to the JVM.
+ * If the value of the string is "help", then initialization
+ * of the JVM does not occur and a usage string is returned.
+ */
+
+ if ((options[vm_args.nOptions].optionString =
+ (void *) Tcl_GetVar(interp, "tclblend_init",
+ TCL_GLOBAL_ONLY)) != NULL) {
+ if ( !strcmp((char *)options[vm_args.nOptions].optionString,
"help")) {
+ Tcl_AppendResult(interp,
+ "The value of the global tcl variable 'tclblend_init' is passed to
the\n "
+ "Java virtual machine upon initialization.\n "
+ "Example values include:\n"
+ " -Djava.compiler=NONE - disable Just In Time Compiler\n"
+ " -Djava.library.path=c:\\jdk\\lib\\tools.jar - set native library
path\n"
+ " -verbose:jni - print debugging messages\n"
+ "\nFor -verbose, the value should be a string with one or\n"
+ "more comma separated names (i.e. class,jni). In JDK1.2,\n"
+ "the standard names are: class, gc, jni\n"
+ "To see what other options are available, run 'java -help'.\n"
+ "Tcl Blend only: If the value is 'help', then JVM initialization
stop\n",
+ "and this message is returned.",
+ NULL);
+ goto error;
+ }
+ options[vm_args.nOptions].extraInfo = (void *)NULL;
+ vm_args.nOptions++;
+
+#ifdef TCLBLEND_DEBUG
+ {
+ int i;
+ fprintf(stderr, "TCLBLEND_DEBUG: tclblend_init set\n"
+ " vm_args.version: %x\n"
+ " vm_args.nOptions: %d\n",
+ vm_args.version, vm_args.nOptions);
+ for( i = 0; i < maxOptions; i++) {
+ fprintf(stderr,
+ " options[%d].optionString = '%s', "
+ " options.[%d].extraInfo = '%s'\n",
+ i, options[i].optionString, i,
+ options[i].extraInfo ? (char *)options[i].extraInfo :
"NULL");
+ }
+ }
+#endif /* TCLBLEND_DEBUG */
+
+ }
+#endif /* JDK1_2 */
+
#ifdef TCLBLEND_DEBUG
fprintf(stderr, "TCLBLEND_DEBUG: JNI_CreateJavaVM\n");
#endif /* TCLBLEND_DEBUG */
|