From: Per Bothner <per@bothner.com>
To: Matthieu Vachon <matthieu.o.vachon@gmail.com>
Cc: "kawa@sourceware.org" <kawa@sourceware.org>
Subject: Re: Patch for wrong no declaration seen for command-line-arguments
Date: Mon, 16 Sep 2013 05:49:00 -0000 [thread overview]
Message-ID: <52369BBD.4010806@bothner.com> (raw)
In-Reply-To: <CAOTvmo=VWjMv2Etk9gagPTAa2OgnM-3XG9USdLWrARbJ22dTcg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]
On 09/11/2013 08:42 PM, Matthieu Vachon wrote:
> Hi Per,
>
> Here my try at fixing the incorrect warning that occurs when
> generating a main method and using the `command-line-arguments`. It's
> probably not the optimal way to fix the issue but I hope it is good
> enough to be included in the trunk.
Thanks for prodding me into action. Your patch makes me think
that having a special case for command-line-arguments is the wrong approach.
Please try the attached patch instead. That is a simpler/cleaner
solution.
You might also consider using the (command-line) procedure.
It is specified by R6RS and R7RS so is more portable.
It also gives you the "command" used to invoke the application
(roughly argv[0]). The attached patch provides a more informative
result for (car (command-line)) - rather than plain "kawa".
I'd be interested in feedback in how portable it is: Windows,
MacOS, non-Sun/Oracle VMs (including ones that don't set the
sun.java.command property). (I also working on updating the
documentation.)
--
--Per Bothner
per@bothner.com http://per.bothner.com/
[-- Attachment #2: command-line-args.patch --]
[-- Type: text/x-patch, Size: 3513 bytes --]
Index: gnu/expr/ApplicationMainSupport.java
===================================================================
--- gnu/expr/ApplicationMainSupport.java (revision 7583)
+++ gnu/expr/ApplicationMainSupport.java (working copy)
@@ -43,7 +43,6 @@
public static void setArgs (String[] args, int arg_start)
{
int nargs = args.length - arg_start;
- Object[] array = new Object[nargs];
if (arg_start == 0)
commandLineArgArray = args;
else
@@ -53,12 +52,10 @@
strings[i] = args[i+arg_start];
commandLineArgArray = strings;
}
- for (int i = nargs; --i >= 0; )
- array[i] = new FString (args[i + arg_start]);
- commandLineArguments = new FVector (array); // FIXME scsh has list
- // FIXME scsh also has command-line proc
- Environment.getCurrent().put("command-line-arguments",
- commandLineArguments);
+
+ Object[] array = new Object[nargs];
+ System.arraycopy(args, arg_start, array, 0, nargs);
+ commandLineArguments = new ConstVector(array); // FIXME scsh has list
}
public static boolean processSetProperty (String arg)
Index: kawa/lib/rnrs/programs.scm
===================================================================
--- kawa/lib/rnrs/programs.scm (revision 7583)
+++ kawa/lib/rnrs/programs.scm (working copy)
@@ -3,8 +3,32 @@
(require <kawa.lib.prim_syntax>)
(define (command-line) :: list
- (let ((arg0 "kawa")) ;; FIXME
- (cons arg0 (gnu.lists.LList:makeList gnu.expr.ApplicationMainSupport:commandLineArgArray 0))))
+ (let* ((rest
+ (gnu.lists.LList:makeList
+ gnu.expr.ApplicationMainSupport:commandLineArgArray 0))
+ (command ::java.lang.String
+ (try-catch
+ (let ((raw (java.lang.System:getProperty
+ "sun.java.command")))
+ (if (eq? raw #!null) #!null
+ ;; Strip off the tail of the property value that
+ ;; duplicates the rest value.
+ (let* ((frest (format #f "~{ ~a~}" rest))
+ (rlen (raw:length))
+ (flen (frest:length))
+ (alen (- rlen flen)))
+ (cond ((= flen 0)
+ raw)
+ ;; Sanity check
+ ((and (>= alen 0)
+ ((raw:substring alen):equals frest))
+ (raw:substring 0 alen))
+ (else
+ #!null)))))
+ (exp java.lang.Throwable #!null)))
+ (arg0 (if (eq? command #!null) "kawa"
+ ("java ":concat command))))
+ (cons arg0 rest)))
(define (exit #!optional (code 0)) :: #!void
(invoke-static <output-port> 'runCleanups)
Index: kawa/standard/Scheme.java
===================================================================
--- kawa/standard/Scheme.java (revision 7583)
+++ kawa/standard/Scheme.java (working copy)
@@ -565,6 +565,8 @@
defProcStFld("exit", "kawa.lib.rnrs.programs");
defProcStFld("command-line", "kawa.lib.rnrs.programs");
+ defAliasStFld("command-line-arguments",
+ "gnu.expr.ApplicationMainSupport", "commandLineArguments");
defProcStFld("bitwise-arithmetic-shift",
"gnu.kawa.functions.BitwiseOp", "ashift");
next prev parent reply other threads:[~2013-09-16 5:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-12 3:42 Matthieu Vachon
2013-09-12 20:09 ` Charles Turner
2013-09-12 20:20 ` Matthieu Vachon
2013-09-16 5:49 ` Per Bothner [this message]
2013-09-16 17:16 ` Jamison Hope
2013-09-18 13:19 ` Matthieu Vachon
2013-09-18 18:21 ` Per Bothner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52369BBD.4010806@bothner.com \
--to=per@bothner.com \
--cc=kawa@sourceware.org \
--cc=matthieu.o.vachon@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).