This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR bootstrap/10169: Prototype getopt in mips-tfile.c


 > From: Roger Sayle <roger@www.eyesopen.com>
 > 
 > > When I find myself in these situations, I ask: how is this working in
 > > the rest of the source base?  Answer: elsewhere we use getopt_long.
 > > E.g. look at gcov.c.  I believe accepting "long" options is also more
 > > in line with GNU standards.
 > 
 > Now who's being "hackish"?  :>  The reason we define a getopt in
 > libiberty is so we can call it portably from GNU code.  I must
 > admit that I never considered the solution "just don't use getopt!".

Yes absolutely! :-)

Said the Patient:  "Doctor, it hurts when I do this."
Said the Doctor:   "Well don't do that."


 > We could also get equally effective results just renaming the
 > function to xgetopt in libiberty :>

I think the fundamental problem is that we're duplicating a system
header filename (getopt.h) in libiberty.  In other cases where we
replaced a system header we renamed it, e.g. safe-ctype.h, xregex.h or
gcc/fixinc/gnu-regex.h.

So the real solution would be to rename libiberty's getopt.h to
something else like xgetopt.h (but probably leave the functions
defined with their original names.

We probably can't do that since the API for libiberty is set in
stone.  That leave us with the option of not using it. :-)


 > However, I do prefer your hack to the otherwise needless duplication
 > of headers by fixincludes.  I'm working on a patch.

Great, thanks.


 > Perhaps we should
 > poison "getopt" in the gcc source code.

<shrug>


 > But I do have one question.  I've never used getopt_long before so
 > I've been reading both gcov.c (as you suggested) and the man page.
 > Shouldn't gcov.c's and gcov-dump.c's "option" global variables have
 > a zero terminator?  i.e. { 0, 0, 0, 0 }?
 > If so I'll include fixes to both gcov.c and gcov-dump.c in the same
 > patch that changes mips-tfile.c and mips-tdump.c to use getopt_long.

Yes, good catch!  If you don't zero terminate it, then when you supply
an invalid option it'll SEGV.  E.g. try "gcov --qwerty".  Please do
submit a fix for gcov* when you patch the mips-t* programs.

		Thanks,
		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]