This is the mail archive of the 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]

Re: A patch to constify gcc.c (Really, summarizing remaining warnings)

On Sat, 13 Mar 1999 11:28:51 -0500 (EST), "Kaveh R. Ghazi" wrote:
> > From: Zack Weinberg <>
> > 
> > For the *_unlocked functions, what do you think of this patch (which I
> > am testing as we speak)?
> > 
> > 1999-03-11 12:23 -0500  Zack Weinberg  <>
> > 
> > 	* system.h: Use putc_unlocked, fputc_unlocked, and
> > 	fputs_unlocked only if putc_unlocked has a prototype already.
> > 	Prototype fputs_unlocked if necessary.
> > 	* Check for prototypes of putc_unlocked and
> > 	fputs_unlocked. 
> > 	* acconfig.h: Updated.
>	I have a couple of questions...
>	I'm not sure why you checked for PUTC_UNLOCKED prototypes on
>the above lines.  Shouldn't they be checks for FPUTC and FPUTS to
>match the function tested for?
>	Why did you decide here to prototype fputs_unlocked but none of
>the others?

The check for a prototype for putc_unlocked is really a check for
stdio being threadsafe by default.  If putc_unlocked exists in the
library but isn't prototyped, then stdio isn't threadsafe unless
_REENTRANT is defined, and we don't need to bother using
putc_unlocked.  E.g. Solaris 2.6 stdio.h:

extern int putc(int, FILE *);

#ifndef _REENTRANT
#define putc(x, p)		(--(p)->_cnt < 0 \
					? __flsbuf((x), (p)) \
					: (int)(*(p)->_ptr++ = \
					(unsigned char) (x)))
extern int putc_unlocked(int, FILE *);
#define putc_unlocked(x, p)     (--(p)->_cnt < 0 \
                                        ? __flsbuf((x), (p)) \
                                        : (int)(*(p)->_ptr++ = \
                                        (unsigned char) (x)))

fputc_unlocked is unnecessary if and only if putc_unlocked is
unnecessary, so there's no point checking for both.

fputs_unlocked is different.  It too is unnecessary iff putc_unlocked
is unnecessary.  However, it's not in POSIX, so some people don't have
it, and those who do (at least HPUX, GNU) don't prototype it unless
you define some magic symbol which is different on different systems.
Rather than hunt for this magic symbol and accept all the other cruft
it will enable, we just prototype fputs_unlocked by hand if necessary.
That requires a separate check.

Does it make more sense if you pretend that HAVE_PUTC_UNLOCKED is


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