From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22714 invoked by alias); 1 Apr 2008 21:36:22 -0000 Received: (qmail 22707 invoked by uid 22791); 1 Apr 2008 21:36:21 -0000 X-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_36,J_CHICKENPOX_64,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 01 Apr 2008 21:36:04 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m31La2xd016574 for ; Tue, 1 Apr 2008 17:36:02 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m31La1p9016438; Tue, 1 Apr 2008 17:36:01 -0400 Received: from localhost.localdomain (sebastian-int.corp.redhat.com [172.16.52.221]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m31La0m0014831; Tue, 1 Apr 2008 17:36:01 -0400 Message-ID: <47F2AABC.9070609@redhat.com> Date: Tue, 01 Apr 2008 21:36:00 -0000 From: Andrew Cagney User-Agent: Thunderbird 2.0.0.12 (X11/20080226) MIME-Version: 1.0 To: Tom Tromey CC: Phil Muldoon , Frysk Hackers Subject: Re: Patch: Add Option Groups References: <47DFFE9D.80906@redhat.com> <47E021DF.40407@redhat.com> <47E0C4DC.2080609@redhat.com> <47E24FB8.7090507@redhat.com> <47E28BF9.5020400@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2008-q2/txt/msg00003.txt.bz2 Thanks! I've also applied it locally. Andrew Tom Tromey wrote: >>>>>> "Andrew" == Andrew Cagney writes: >>>>>> > > [ Parser and OptionGroup ] > Andrew> I'm not sure if its an interface restriction, or a bug; either way it > Andrew> leads to a confusing client problem. > > I checked in a fix to the Classpath repository. > I've appended it as well. > > Tom > > ChangeLog: > 2008-03-20 Tom Tromey > > * tools/gnu/classpath/tools/getopt/Parser.java (options): Don't > initialize. > (add, addFinal): Don't update options. > (requireOptions): New method. > (printHelp): Synchronize. Call requireOptions. > (parse): Call requireOptions. > > Index: tools/gnu/classpath/tools/getopt/Parser.java > =================================================================== > RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/getopt/Parser.java,v > retrieving revision 1.9 > diff -u -r1.9 Parser.java > --- tools/gnu/classpath/tools/getopt/Parser.java 22 Sep 2006 01:01:26 -0000 1.9 > +++ tools/gnu/classpath/tools/getopt/Parser.java 20 Mar 2008 18:02:58 -0000 > @@ -1,5 +1,5 @@ > /* Parser.java - parse command line options > - Copyright (C) 2006 Free Software Foundation, Inc. > + Copyright (C) 2006, 2008 Free Software Foundation, Inc. > > This file is part of GNU Classpath. > > @@ -66,7 +66,9 @@ > > private boolean longOnly; > > - private ArrayList options = new ArrayList(); > + // All of the options. This is null initially; users must call > + // requireOptions before access. > + private ArrayList options; > > private ArrayList optionGroups = new ArrayList(); > > @@ -218,7 +220,6 @@ > */ > public synchronized void add(Option opt) > { > - options.add(opt); > defaultGroup.add(opt); > } > > @@ -230,7 +231,6 @@ > */ > protected synchronized void addFinal(Option opt) > { > - options.add(opt); > finalGroup.add(opt); > } > > @@ -242,7 +242,6 @@ > */ > public synchronized void add(OptionGroup group) > { > - options.addAll(group.options); > // This ensures that the final group always appears at the end > // of the options. > if (optionGroups.isEmpty()) > @@ -251,13 +250,29 @@ > optionGroups.add(optionGroups.size() - 1, group); > } > > + // Make sure the 'options' field is properly initialized. > + private void requireOptions() > + { > + if (options != null) > + return; > + options = new ArrayList(); > + Iterator it = optionGroups.iterator(); > + while (it.hasNext()) > + { > + OptionGroup group = (OptionGroup) it.next(); > + options.addAll(group.options); > + } > + } > + > public void printHelp() > { > this.printHelp(System.out); > } > > - void printHelp(PrintStream out) > + synchronized void printHelp(PrintStream out) > { > + requireOptions(); > + > if (headerText != null) > { > formatText(out, headerText); > @@ -417,6 +432,7 @@ > */ > public synchronized void parse(String[] inArgs, FileArgumentCallback files) > { > + requireOptions(); > try > { > args = inArgs; >