# HG changeset patch
# User Josef Eisl <zapster@zapster.cc>
# Date 1349250976 -7200
# Node ID 33ae9126d82044d6faf7aa0193c93dde70183a81
# Parent  816e9070d623c003826ba77784406c63678ab84c
PR166: make check-langtools failure: MineField.sh

  PR166: fixed position (regarding -Xbootclasspath\p) and ordering
  of the -endorseddirs commandline option.
  * src/vm/vm.cpp: insert -endorseddirs entries at the correct position
  * src/vm/succ.cpp: corrected the ordering of the -endorseddirs entries

diff -r 816e9070d623 -r 33ae9126d820 src/vm/suck.cpp
--- a/src/vm/suck.cpp	Wed Sep 05 23:46:21 2012 +0200
+++ b/src/vm/suck.cpp	Wed Oct 03 09:56:16 2012 +0200
@@ -1,6 +1,6 @@
 /* src/vm/suck.cpp - functions to read LE ordered types from a buffer
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008
+   Copyright (C) 1996-2012
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
@@ -205,6 +205,7 @@
 	s4              i;
 	s4              namlen;
 	char           *p;
+	char* boot_class_path = NULL;
 
 	// Get the property value.
 	Properties& properties = VM::get_current()->get_properties();
@@ -253,29 +254,36 @@
 					namlen = strlen(namelist[i]->d_name);
 #endif
 
-					/* Allocate memory for bootclasspath. */
+					if (boot_class_path == NULL) {
+						/* Allocate memory for bootclasspath. */
+						p = MNEW(char,
+								 pathlen + strlen("/") + namlen +
+								 strlen("0"));
 
-					// FIXME Make boot_class_path const char*.
-					char* boot_class_path = (char*) properties.get("sun.boot.class.path");
+						strcpy(p, path);
+						strcat(p, "/");
+						strcat(p, namelist[i]->d_name);
 
-					p = MNEW(char,
-							 pathlen + strlen("/") + namlen +
-							 strlen(":") +
-							 strlen(boot_class_path) +
-							 strlen("0"));
+					} else {
+						/* Allocate memory for bootclasspath. */
+						p = MNEW(char,
+								 pathlen + strlen("/") + namlen +
+								 strlen(":") +
+								 strlen(boot_class_path) +
+								 strlen("0"));
 
-					/* Prepend the file found to the bootclasspath. */
+						/* Append the file found to the bootclasspath. */
 
-					strcpy(p, path);
-					strcat(p, "/");
-					strcat(p, namelist[i]->d_name);
-					strcat(p, ":");
-					strcat(p, boot_class_path);
+						strcpy(p, boot_class_path);
+						strcat(p, ":");
+						strcat(p, path);
+						strcat(p, "/");
+						strcat(p, namelist[i]->d_name);
 
-					properties.put("sun.boot.class.path", p);
-					properties.put("java.boot.class.path", p);
+						MFREE(boot_class_path, char, strlen(boot_class_path));
+					}
 
-					MFREE(boot_class_path, char, strlen(boot_class_path));
+					boot_class_path = p;
 
 					/* free the memory allocated by scandir */
 					/* (We use `free` as the memory came from the C library.) */
@@ -302,6 +310,33 @@
 		else
 			start = end;
 	}
+
+	if (boot_class_path != NULL) {
+		// only update if something has changed
+
+		// FIXME Make boot_class_path const char*.
+		char* old_boot_class_path = (char*) properties.get("sun.boot.class.path");
+
+		p = MNEW(char,
+				 strlen(boot_class_path) +
+				 strlen(":") +
+				 strlen(old_boot_class_path) +
+				 strlen("0"));
+
+		/* Prepend the file found to the bootclasspath. */
+
+		strcpy(p, boot_class_path);
+		strcat(p, ":");
+		strcat(p, old_boot_class_path);
+
+		MFREE(boot_class_path, char, strlen(boot_class_path));
+		MFREE(old_boot_class_path, char, strlen(old_boot_class_path));
+
+		/* Prepend the file found to the bootclasspath. */
+		properties.put("sun.boot.class.path", p);
+		properties.put("java.boot.class.path", p);
+	}
+
 }
 
 
diff -r 816e9070d623 -r 33ae9126d820 src/vm/vm.cpp
--- a/src/vm/vm.cpp	Wed Sep 05 23:46:21 2012 +0200
+++ b/src/vm/vm.cpp	Wed Oct 03 09:56:16 2012 +0200
@@ -667,6 +667,7 @@
 	int   len;
 	char *p;
 	char *boot_class_path;
+	char *boot_class_path_p = NULL;
 	char *class_path;
 	int   opt;
 	bool  opt_version;
@@ -794,6 +795,11 @@
 			/* Forget default bootclasspath and set the argument as
 			   new boot classpath. */
 
+			/* Forget stored -Xbootclasspath/p value */
+			if (boot_class_path_p != NULL) {
+				MFREE(boot_class_path_p, char, len);
+				boot_class_path_p = NULL;
+			}
 			// FIXME Make boot_class_path const char*.
 			boot_class_path = (char*) _properties.get("sun.boot.class.path");
 
@@ -831,22 +837,22 @@
 
 		case OPT_BOOTCLASSPATH_P:
 			/* Prepend to bootclasspath. */
-
-			// FIXME Make boot_class_path const char*.
-			boot_class_path = (char*) _properties.get("sun.boot.class.path");
-
-			len = strlen(boot_class_path);
-
-			p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
-
-			strcpy(p, opt_arg);
-			strcat(p, ":");
-			strcat(p, boot_class_path);
-
-			_properties.put("sun.boot.class.path", p);
-			_properties.put("java.boot.class.path", p);
-
-			MFREE(boot_class_path, char, len);
+			/* Note: we can not add this value directly to sun/java.boot.class.path
+			   because we need to take care of the ordering regarding the
+			   endorseddirs property */
+
+			if (boot_class_path_p == NULL) {
+				boot_class_path_p = MNEW(char, strlen(opt_arg) + strlen("0"));
+				strcpy(boot_class_path_p, opt_arg);
+			} else {
+				len = strlen(boot_class_path_p);
+				p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
+				strcpy(p, opt_arg);
+				strcat(p, ":");
+				strcat(p, boot_class_path_p);
+				MFREE(boot_class_path_p, char, len);
+				boot_class_path_p = p;
+			}
 			break;
 
 		case OPT_BOOTCLASSPATH_C:
@@ -1295,6 +1301,10 @@
 
 	/* AFTER: thread_preinit */
 
+	/* Add -Xbootclasspath/p if it exists */
+	if (boot_class_path_p != NULL)
+		_suckclasspath.add(boot_class_path_p);
+
 	_suckclasspath.add_from_property("java.endorsed.dirs");
 
 	/* Now we have all options handled and we can print the version
