From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10639 invoked by alias); 16 Sep 2013 05:49:15 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 10626 invoked by uid 89); 16 Sep 2013 05:49:14 -0000 Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 16 Sep 2013 05:49:14 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_50,KHOP_THREADED,RDNS_NONE,SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: aibo.runbox.com Received: from [10.9.9.209] (helo=mailfront04.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1VLRgK-0008AU-68; Mon, 16 Sep 2013 07:49:08 +0200 Received: from 70-36-239-203.dsl.dynamic.sonic.net ([70.36.239.203] helo=localhost.localdomain) by mailfront04.runbox.com with esmtpsa (uid:757155 ) (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) id 1VLRg0-0001M6-Qc; Mon, 16 Sep 2013 07:48:49 +0200 Message-ID: <52369BBD.4010806@bothner.com> Date: Mon, 16 Sep 2013 05:49:00 -0000 From: Per Bothner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8 MIME-Version: 1.0 To: Matthieu Vachon CC: "kawa@sourceware.org" Subject: Re: Patch for wrong no declaration seen for command-line-arguments References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------000803050703020109050605" X-IsSubscribed: yes X-SW-Source: 2013-q3/txt/msg00064.txt.bz2 This is a multi-part message in MIME format. --------------000803050703020109050605 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1086 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/ --------------000803050703020109050605 Content-Type: text/x-patch; name="command-line-args.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="command-line-args.patch" Content-length: 3513 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 ) (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 '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"); --------------000803050703020109050605--