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]

[PATCH PR/17092]: use more "unlocked" stdio functions


As noted in PR/17092 there are a few more opportunities for using
unlocked stdio functions.  But it's more prevalent that just java.  I
went through and setup all the unused unlocked functions I found in
stdio.h on my gnu/linux system.  Some notes:

1.  If you're wondering why the m4_split/m4_normalize in
    AC_CHECK_DECLS below, seems it's necessary when passing in a macro
    expansion as the function list which I did.  These m4_ sugar
    macros are implicitly called in AC_CHECK_FUNCS and
    gcc_AC_CHECK_DECLS, but strangely not in the official
    AC_CHECK_DECLS.

2.  I added prototype backups in system.h only for unlocked functions
    that weren't part of the posix set.  If some system needs them, we
    can always add them.  (Because the list of unlocked functions is
    macroized, we're doing the extra auto checks anyway... I could be
    convinced to add them defensively as a followup.)

3.  I see that we already check for fprintf_unlocked prior to my
    patch, but I don't see that function on my glibc.  Did I miss
    something or is there some system out there that has it?  Why
    doesn't glibc have it BTW?  (I didn't add plain printf_unlocked
    because I don't see it locally either.)

4.  I noticed that the existing backup prototype for fwrite_unlocked
    had a non-standard return type of int.  I changed it to size_t.

5.  I was a little disappointed to realize that when fixincludes and
    libcpp were moved to the top level, that we now have three
    separate and slightly different copies of system.h.  The code
    duplication, plus the libcpp bool incompatibility, plus not
    getting these three-staged... remind me again why moving these
    plus intl/ to the top level was a good idea? :-)


Anyway, I'm seeing a speed improvement when compiling combine.i or
dwarf2out.i at -O0 averaging around 1%, but it fluctuates slightly
either way.  When I compile dwarf2out.c (therefore using libcpp) it
gets slightly better, ~1.4%.

Bootstrapped on x86_64-unknown-linux-gnu, no regressions.

Okay for mainline?

		Thanks,
		--Kaveh


2005-04-04  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

fixincludes:
	* configure.ac (fixincludes_UNLOCKED_FUNCS): New.
	(AC_CHECK_FUNCS, AC_CHECK_DECLS): Check for fixincludes_UNLOCKED_FUNCS.
	* system.h (putchar, getc, getchar, clearerr, feof, fileno,
	fflush, fgetc, fgets, ferror, fread): Redefine to the associated
	_unlocked function.
	(fwrite_unlocked): Fix prototype.
	
	* configure, config.in: Regenerate.
	
gcc:
	PR/17092
	* configure.ac (gcc_UNLOCKED_FUNCS): New.
	(AC_CHECK_FUNCS, AC_CHECK_DECLS): Check for gcc_UNLOCKED_FUNCS.
	* system.h (putchar, getc, getchar, clearerr, feof, fileno,
	fflush, fgetc, fgets, ferror, fread): Redefine to the associated
	_unlocked function.
	(fwrite_unlocked): Fix prototype.
	
	* configure, config.in: Regenerate.

libcpp:
	* configure.ac (libcpp_UNLOCKED_FUNCS): New.
	(AC_CHECK_FUNCS, AC_CHECK_DECLS): Check for libcpp_UNLOCKED_FUNCS.
	* system.h (putchar, getc, getchar, clearerr, feof, fileno,
	fflush, fgetc, fgets, ferror, fread): Redefine to the associated
	_unlocked function.
	(fwrite_unlocked): Fix prototype.
	
	* configure, config.in: Regenerate.

diff -rup orig/egcc-CVS20050403/fixincludes/configure.ac egcc-CVS20050403/fixincludes/configure.ac
--- orig/egcc-CVS20050403/fixincludes/configure.ac	2005-03-21 21:09:53.000000000 -0500
+++ egcc-CVS20050403/fixincludes/configure.ac	2005-04-04 15:05:55.772021920 -0400
@@ -66,10 +66,9 @@ AC_DEFINE_UNQUOTED([EXE_EXT], "$ac_exeex
 AC_HEADER_STDC
 AC_CHECK_HEADERS([stddef.h stdlib.h strings.h unistd.h fcntl.h sys/file.h \
 	sys/stat.h])
-AC_CHECK_FUNCS(putc_unlocked fputc_unlocked fputs_unlocked \
-        fwrite_unlocked fprintf_unlocked)
-AC_CHECK_DECLS([abort, errno, putc_unlocked, fputc_unlocked,
-        fputs_unlocked, fwrite_unlocked, fprintf_unlocked])
+define(fixincludes_UNLOCKED_FUNCS, clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked)
+AC_CHECK_FUNCS(fixincludes_UNLOCKED_FUNCS)
+AC_CHECK_DECLS(m4_split(m4_normalize(abort errno fixincludes_UNLOCKED_FUNCS)))
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
diff -rup orig/egcc-CVS20050403/fixincludes/system.h egcc-CVS20050403/fixincludes/system.h
--- orig/egcc-CVS20050403/fixincludes/system.h	2004-08-31 05:26:05.000000000 -0400
+++ egcc-CVS20050403/fixincludes/system.h	2005-04-04 15:01:54.573689640 -0400
@@ -57,11 +57,65 @@ Software Foundation, 59 Temple Place - S
 #  undef putc
 #  define putc(C, Stream) putc_unlocked (C, Stream)
 # endif
+# ifdef HAVE_PUTCHAR_UNLOCKED
+#  undef putchar
+#  define putchar(C) putchar_unlocked (C)
+# endif
+# ifdef HAVE_GETC_UNLOCKED
+#  undef getc
+#  define getc(Stream) getc_unlocked (Stream)
+# endif
+# ifdef HAVE_GETCHAR_UNLOCKED
+#  undef getchar
+#  define getchar() getchar_unlocked ()
+# endif
 # ifdef HAVE_FPUTC_UNLOCKED
 #  undef fputc
 #  define fputc(C, Stream) fputc_unlocked (C, Stream)
 # endif
 
+# ifdef HAVE_CLEARERR_UNLOCKED
+#  undef clearerr
+#  define clearerr(Stream) clearerr_unlocked (Stream)
+#  if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
+extern void clearerr_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FEOF_UNLOCKED
+#  undef feof
+#  define feof(Stream) feof_unlocked (Stream)
+#  if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
+extern int feof_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FILENO_UNLOCKED
+#  undef fileno
+#  define fileno(Stream) fileno_unlocked (Stream)
+#  if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
+extern int fileno_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FFLUSH_UNLOCKED
+#  undef fflush
+#  define fflush(Stream) fflush_unlocked (Stream)
+#  if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
+extern int fflush_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FGETC_UNLOCKED
+#  undef fgetc
+#  define fgetc(Stream) fgetc_unlocked (Stream)
+#  if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
+extern int fgetc_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FGETS_UNLOCKED
+#  undef fgets
+#  define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
+#  if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
+extern char *fgets_unlocked (char *, int, FILE *);
+#  endif
+# endif
 # ifdef HAVE_FPUTS_UNLOCKED
 #  undef fputs
 #  define fputs(String, Stream) fputs_unlocked (String, Stream)
@@ -69,11 +123,25 @@ Software Foundation, 59 Temple Place - S
 extern int fputs_unlocked (const char *, FILE *);
 #  endif
 # endif
+# ifdef HAVE_FERROR_UNLOCKED
+#  undef ferror
+#  define ferror(Stream) ferror_unlocked (Stream)
+#  if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
+extern int ferror_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FREAD_UNLOCKED
+#  undef fread
+#  define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
+#  if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
+extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
+#  endif
+# endif
 # ifdef HAVE_FWRITE_UNLOCKED
 #  undef fwrite
 #  define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
 #  if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
-extern int fwrite_unlocked (const void *, size_t, size_t, FILE *);
+extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
 #  endif
 # endif
 # ifdef HAVE_FPRINTF_UNLOCKED
diff -rup orig/egcc-CVS20050403/gcc/configure.ac egcc-CVS20050403/gcc/configure.ac
--- orig/egcc-CVS20050403/gcc/configure.ac	2005-04-01 09:44:02.000000000 -0500
+++ egcc-CVS20050403/gcc/configure.ac	2005-04-04 14:31:58.254771624 -0400
@@ -977,11 +977,11 @@ fi
 dnl Disabled until we have a complete test for buggy enum bitfields.
 dnl gcc_AC_C_ENUM_BF_UNSIGNED
 
+define(gcc_UNLOCKED_FUNCS, clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked)
 AC_CHECK_FUNCS(times clock dup2 kill getrlimit setrlimit atoll atoq \
-	sysconf strsignal putc_unlocked fputc_unlocked fputs_unlocked \
-	fwrite_unlocked fprintf_unlocked getrusage nl_langinfo \
-        scandir alphasort gettimeofday mbstowcs wcswidth mmap mincore \
-        setlocale)
+	sysconf strsignal getrusage nl_langinfo scandir alphasort \
+	gettimeofday mbstowcs wcswidth mmap mincore setlocale \
+	gcc_UNLOCKED_FUNCS)
 
 if test x$ac_cv_func_mbstowcs = xyes; then
   AC_CACHE_CHECK(whether mbstowcs works, gcc_cv_func_mbstowcs_works,
@@ -1048,10 +1048,9 @@ AM_LANGINFO_CODESET
 # We will need to find libiberty.h and ansidecl.h
 saved_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -I${srcdir} -I${srcdir}/../include"
-gcc_AC_CHECK_DECLS(getenv atol sbrk abort atof getcwd getwd \
-	strsignal putc_unlocked fputs_unlocked fwrite_unlocked \
-        fprintf_unlocked strstr errno snprintf vasprintf \
-	malloc realloc calloc free basename getopt clock getpagesize, , ,[
+gcc_AC_CHECK_DECLS(getenv atol sbrk abort atof getcwd getwd strsignal \
+	strstr errno snprintf vasprintf malloc realloc calloc free \
+	basename getopt clock getpagesize gcc_UNLOCKED_FUNCS, , ,[
 #include "ansidecl.h"
 #include "system.h"])
 
diff -rup orig/egcc-CVS20050403/gcc/system.h egcc-CVS20050403/gcc/system.h
--- orig/egcc-CVS20050403/gcc/system.h	2005-03-23 20:42:48.000000000 -0500
+++ egcc-CVS20050403/gcc/system.h	2005-04-04 14:04:42.388461104 -0400
@@ -65,11 +65,65 @@ Software Foundation, 59 Temple Place - S
 #  undef putc
 #  define putc(C, Stream) putc_unlocked (C, Stream)
 # endif
+# ifdef HAVE_PUTCHAR_UNLOCKED
+#  undef putchar
+#  define putchar(C) putchar_unlocked (C)
+# endif
+# ifdef HAVE_GETC_UNLOCKED
+#  undef getc
+#  define getc(Stream) getc_unlocked (Stream)
+# endif
+# ifdef HAVE_GETCHAR_UNLOCKED
+#  undef getchar
+#  define getchar() getchar_unlocked ()
+# endif
 # ifdef HAVE_FPUTC_UNLOCKED
 #  undef fputc
 #  define fputc(C, Stream) fputc_unlocked (C, Stream)
 # endif
 
+# ifdef HAVE_CLEARERR_UNLOCKED
+#  undef clearerr
+#  define clearerr(Stream) clearerr_unlocked (Stream)
+#  if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
+extern void clearerr_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FEOF_UNLOCKED
+#  undef feof
+#  define feof(Stream) feof_unlocked (Stream)
+#  if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
+extern int feof_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FILENO_UNLOCKED
+#  undef fileno
+#  define fileno(Stream) fileno_unlocked (Stream)
+#  if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
+extern int fileno_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FFLUSH_UNLOCKED
+#  undef fflush
+#  define fflush(Stream) fflush_unlocked (Stream)
+#  if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
+extern int fflush_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FGETC_UNLOCKED
+#  undef fgetc
+#  define fgetc(Stream) fgetc_unlocked (Stream)
+#  if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
+extern int fgetc_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FGETS_UNLOCKED
+#  undef fgets
+#  define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
+#  if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
+extern char *fgets_unlocked (char *, int, FILE *);
+#  endif
+# endif
 # ifdef HAVE_FPUTS_UNLOCKED
 #  undef fputs
 #  define fputs(String, Stream) fputs_unlocked (String, Stream)
@@ -77,11 +131,25 @@ Software Foundation, 59 Temple Place - S
 extern int fputs_unlocked (const char *, FILE *);
 #  endif
 # endif
+# ifdef HAVE_FERROR_UNLOCKED
+#  undef ferror
+#  define ferror(Stream) ferror_unlocked (Stream)
+#  if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
+extern int ferror_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FREAD_UNLOCKED
+#  undef fread
+#  define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
+#  if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
+extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
+#  endif
+# endif
 # ifdef HAVE_FWRITE_UNLOCKED
 #  undef fwrite
 #  define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
 #  if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
-extern int fwrite_unlocked (const void *, size_t, size_t, FILE *);
+extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
 #  endif
 # endif
 # ifdef HAVE_FPRINTF_UNLOCKED
diff -rup orig/egcc-CVS20050403/libcpp/configure.ac egcc-CVS20050403/libcpp/configure.ac
--- orig/egcc-CVS20050403/libcpp/configure.ac	2005-03-19 20:49:39.000000000 -0500
+++ egcc-CVS20050403/libcpp/configure.ac	2005-04-04 14:53:44.182240472 -0400
@@ -44,10 +44,9 @@ AC_TYPE_SIZE_T
 AC_STRUCT_TM
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
-AC_CHECK_FUNCS(putc_unlocked fputc_unlocked fputs_unlocked \
-        fwrite_unlocked fprintf_unlocked)
-AC_CHECK_DECLS([abort, basename, errno, getopt, putc_unlocked, fputc_unlocked,
-        fputs_unlocked, fwrite_unlocked, fprintf_unlocked])
+define(libcpp_UNLOCKED_FUNCS, clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked)
+AC_CHECK_FUNCS(libcpp_UNLOCKED_FUNCS)
+AC_CHECK_DECLS(m4_split(m4_normalize(abort basename errno getopt libcpp_UNLOCKED_FUNCS)))
 
 # Checks for library functions.
 AC_FUNC_ALLOCA
diff -rup orig/egcc-CVS20050403/libcpp/system.h egcc-CVS20050403/libcpp/system.h
--- orig/egcc-CVS20050403/libcpp/system.h	2004-06-12 01:53:54.000000000 -0400
+++ egcc-CVS20050403/libcpp/system.h	2005-04-04 14:04:53.683743960 -0400
@@ -57,11 +57,65 @@ Software Foundation, 59 Temple Place - S
 #  undef putc
 #  define putc(C, Stream) putc_unlocked (C, Stream)
 # endif
+# ifdef HAVE_PUTCHAR_UNLOCKED
+#  undef putchar
+#  define putchar(C) putchar_unlocked (C)
+# endif
+# ifdef HAVE_GETC_UNLOCKED
+#  undef getc
+#  define getc(Stream) getc_unlocked (Stream)
+# endif
+# ifdef HAVE_GETCHAR_UNLOCKED
+#  undef getchar
+#  define getchar() getchar_unlocked ()
+# endif
 # ifdef HAVE_FPUTC_UNLOCKED
 #  undef fputc
 #  define fputc(C, Stream) fputc_unlocked (C, Stream)
 # endif
 
+# ifdef HAVE_CLEARERR_UNLOCKED
+#  undef clearerr
+#  define clearerr(Stream) clearerr_unlocked (Stream)
+#  if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
+extern void clearerr_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FEOF_UNLOCKED
+#  undef feof
+#  define feof(Stream) feof_unlocked (Stream)
+#  if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
+extern int feof_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FILENO_UNLOCKED
+#  undef fileno
+#  define fileno(Stream) fileno_unlocked (Stream)
+#  if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
+extern int fileno_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FFLUSH_UNLOCKED
+#  undef fflush
+#  define fflush(Stream) fflush_unlocked (Stream)
+#  if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
+extern int fflush_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FGETC_UNLOCKED
+#  undef fgetc
+#  define fgetc(Stream) fgetc_unlocked (Stream)
+#  if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
+extern int fgetc_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FGETS_UNLOCKED
+#  undef fgets
+#  define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
+#  if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
+extern char *fgets_unlocked (char *, int, FILE *);
+#  endif
+# endif
 # ifdef HAVE_FPUTS_UNLOCKED
 #  undef fputs
 #  define fputs(String, Stream) fputs_unlocked (String, Stream)
@@ -69,11 +123,25 @@ Software Foundation, 59 Temple Place - S
 extern int fputs_unlocked (const char *, FILE *);
 #  endif
 # endif
+# ifdef HAVE_FERROR_UNLOCKED
+#  undef ferror
+#  define ferror(Stream) ferror_unlocked (Stream)
+#  if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
+extern int ferror_unlocked (FILE *);
+#  endif
+# endif
+# ifdef HAVE_FREAD_UNLOCKED
+#  undef fread
+#  define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
+#  if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
+extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
+#  endif
+# endif
 # ifdef HAVE_FWRITE_UNLOCKED
 #  undef fwrite
 #  define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
 #  if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
-extern int fwrite_unlocked (const void *, size_t, size_t, FILE *);
+extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
 #  endif
 # endif
 # ifdef HAVE_FPRINTF_UNLOCKED


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