[m-rev.] diff: fix standard library compilation in the Java grade
Julien Fischer
jfischer at opturion.com
Tue Mar 8 23:26:49 AEDT 2022
Fix standard library compilation in the Java grade.
library/io.environment.m:
library/io.file.m:
Fully qualify entities in foreign_procs that may be inlined
across module boundaries.
library/io.m:
Move the definition of the private class StreamPipe from here ...
library/io.call_system.m:
... to here where it is actually used.
Julien.
diff --git a/library/io.call_system.m b/library/io.call_system.m
index bbf5122..c2c34f4 100644
--- a/library/io.call_system.m
+++ b/library/io.call_system.m
@@ -232,12 +232,12 @@ call_system_return_signal(Command, Result, !IO) :-
process = java.lang.Runtime.getRuntime().exec(Command);
}
- StreamPipe stdin = new StreamPipe(mercury_stdin,
+ StreamPipe stdin = new StreamPipe(jmercury.io.mercury_stdin,
process.getOutputStream());
StreamPipe stdout = new StreamPipe(process.getInputStream(),
- mercury_stdout);
+ jmercury.io.mercury_stdout);
StreamPipe stderr = new StreamPipe(process.getErrorStream(),
- mercury_stderr);
+ jmercury.io.mercury_stderr);
stdin.start();
stdout.start();
stderr.start();
@@ -268,6 +268,49 @@ call_system_return_signal(Command, Result, !IO) :-
}
").
+:- pragma foreign_code("Java", "
+
+ // StreamPipe is a mechanism for connecting streams to those of a
+ // Runtime.exec() Process.
+
+ private static class StreamPipe extends java.lang.Thread {
+ jmercury.io.MR_TextInputFile in;
+ jmercury.io.MR_TextOutputFile out;
+ boolean closeOutput = false;
+ java.lang.Exception exception = null;
+
+ StreamPipe(java.io.InputStream in, jmercury.io.MR_TextOutputFile out) {
+ this.in = new jmercury.io.MR_TextInputFile(in);
+ this.out = out;
+ }
+
+ StreamPipe(jmercury.io.MR_TextInputFile in, java.io.OutputStream out) {
+ this.in = in;
+ this.out = new jmercury.io.MR_TextOutputFile(out);
+ closeOutput = true;
+ }
+
+ public void run() {
+ try {
+ while (true) {
+ int c = in.read_char();
+ if (c == -1 || interrupted()) {
+ break;
+ }
+ out.put((char) c);
+ }
+ out.flush();
+ if (closeOutput) {
+ out.close();
+ }
+ }
+ catch (java.lang.Exception e) {
+ exception = e;
+ }
+ }
+ } // class StreamPipe
+").
+
%---------------------------------------------------------------------------%
decode_system_command_exit_code(Code0) = Status :-
diff --git a/library/io.environment.m b/library/io.environment.m
index 2c22a7f..d0e39a1 100644
--- a/library/io.environment.m
+++ b/library/io.environment.m
@@ -174,7 +174,8 @@ get_environment_var_map(EnvVarMap, !IO) :-
for (java.util.Map.Entry<String, String> entry : env.entrySet()) {
String name = entry.getKey();
String value = entry.getValue();
- EnvVarAL = ML_record_env_var_and_value(name, value, EnvVarAL);
+ EnvVarAL = jmercury.io__environment.ML_record_env_var_and_value(name,
+ value, EnvVarAL);
}
").
diff --git a/library/io.file.m b/library/io.file.m
index f0470c9..a722fcc 100644
--- a/library/io.file.m
+++ b/library/io.file.m
@@ -1069,17 +1069,17 @@ file_type(FollowSymLinks, FileName, Result, !IO) :-
// The Java implementation can distinguish between regular files and
// directories, and for everything else it just returns unknown.
- FileType = io.ML_FILE_TYPE_UNKNOWN;
+ FileType = jmercury.io__file.ML_FILE_TYPE_UNKNOWN;
Error = null;
try {
java.io.File file = new java.io.File(FileName);
if (file.isFile()) {
- FileType = io.ML_FILE_TYPE_REGULAR_FILE;
+ FileType = jmercury.io__file.ML_FILE_TYPE_REGULAR_FILE;
} else if (file.isDirectory()) {
- FileType = io.ML_FILE_TYPE_DIRECTORY;
+ FileType = jmercury.io__file.ML_FILE_TYPE_DIRECTORY;
} else if (file.exists()) {
- FileType = io.ML_FILE_TYPE_UNKNOWN;
+ FileType = jmercury.io__file.ML_FILE_TYPE_UNKNOWN;
} else {
Error = new java.io.FileNotFoundException(
""File not found or I/O error"");
diff --git a/library/io.m b/library/io.m
index 1a7ad2e..9fbc6f3 100644
--- a/library/io.m
+++ b/library/io.m
@@ -3376,46 +3376,6 @@ ML_wide_to_utf8(const wchar_t *ws, MR_AllocSiteInfoPtr alloc_id)
binary_output.close();
}
}
-
- // StreamPipe is a mechanism for connecting streams to those of a
- // Runtime.exec() Process.
-
- private static class StreamPipe extends java.lang.Thread {
- MR_TextInputFile in;
- MR_TextOutputFile out;
- boolean closeOutput = false;
- java.lang.Exception exception = null;
-
- StreamPipe(java.io.InputStream in, MR_TextOutputFile out) {
- this.in = new MR_TextInputFile(in);
- this.out = out;
- }
-
- StreamPipe(MR_TextInputFile in, java.io.OutputStream out) {
- this.in = in;
- this.out = new MR_TextOutputFile(out);
- closeOutput = true;
- }
-
- public void run() {
- try {
- while (true) {
- int c = in.read_char();
- if (c == -1 || interrupted()) {
- break;
- }
- out.put((char) c);
- }
- out.flush();
- if (closeOutput) {
- out.close();
- }
- }
- catch (java.lang.Exception e) {
- exception = e;
- }
- }
- } // class StreamPipe
").
:- pragma foreign_code("Java", "
More information about the reviews
mailing list