[m-rev.] diff: fix io.progname/4 and io.command_line_arguments/3 in Java grade

Julien Fischer jfischer at opturion.com
Fri Nov 9 16:06:38 AEDT 2018


Fix io.progname/4 and io.command_line_arguments/3 in Java grade.

library/io.m:
      In the Java grade, do not assume that the programe name and argument
      vector have been set in the Mercury runtime.  If Mercury is being used
      as a library in a Java application they may not have been.

Julien.

diff --git a/library/io.m b/library/io.m
index 71c301e..d407c09 100644
--- a/library/io.m
+++ b/library/io.m
@@ -11306,11 +11306,14 @@ decode_system_command_exit_code(Status, yes, Status, no, 0).
  %---------------------%

  :- pragma foreign_proc("Java",
-    progname(_Default::in, PrognameOut::out, _IO0::di, _IO::uo),
+    progname(Default::in, PrognameOut::out, _IO0::di, _IO::uo),
      [will_not_call_mercury, promise_pure, tabled_for_io, thread_safe,
          may_not_duplicate],
  "
      PrognameOut = jmercury.runtime.JavaInternal.progname;
+    if (PrognameOut == null) {
+        PrognameOut = Default;
+    }
  ").

  :- pragma foreign_proc("Java",
@@ -11319,9 +11322,13 @@ decode_system_command_exit_code(Status, yes, Status, no, 0).
  "
      String[] arg_vector = jmercury.runtime.JavaInternal.args;
      Args = list.empty_list();
-    // arg_vector does not include the executable name.
-    for (int i = arg_vector.length - 1; i >= 0; --i) {
-        Args = list.cons(arg_vector[i], Args);
+    // The argument vector may not be set if Mercury is being used
+    // as a library by a native Java application.
+    if (arg_vector != null) {
+        // arg_vector does not include the executable name.
+        for (int i = arg_vector.length - 1; i >= 0; --i) {
+            Args = list.cons(arg_vector[i], Args);
+        }
      }
  ").



More information about the reviews mailing list