Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Oct 2010 13:13:20 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r213720 - stable/8/lib/libc/stdio
Message-ID:  <201010121313.o9CDDKVw048587@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Tue Oct 12 13:13:20 2010
New Revision: 213720
URL: http://svn.freebsd.org/changeset/base/213720

Log:
  MFC 205021:
  - Use an initializer macro to initialize fields in 'fake' FILE objects used
    by *sprintf(), etc.
  - Explicitly initialize _fl_mutex to PTHREAD_MUTEX_INITIALIZER for all FILE
    objects.  This is currently a nop on FreeBSD, but is import for other
    platforms (or in the future) where PTHREAD_MUTEX_INITIALIZER is not simply
    zero.

Modified:
  stable/8/lib/libc/stdio/findfp.c
  stable/8/lib/libc/stdio/local.h
  stable/8/lib/libc/stdio/snprintf.c
  stable/8/lib/libc/stdio/vasprintf.c
  stable/8/lib/libc/stdio/vdprintf.c
  stable/8/lib/libc/stdio/vfprintf.c
  stable/8/lib/libc/stdio/vsnprintf.c
  stable/8/lib/libc/stdio/vsprintf.c
  stable/8/lib/libc/stdio/vsscanf.c
  stable/8/lib/libc/stdio/vswprintf.c
  stable/8/lib/libc/stdio/vswscanf.c
  stable/8/lib/libc/stdio/xprintf.c
Directory Properties:
  stable/8/lib/libc/   (props changed)
  stable/8/lib/libc/locale/   (props changed)
  stable/8/lib/libc/stdtime/   (props changed)
  stable/8/lib/libc/sys/   (props changed)

Modified: stable/8/lib/libc/stdio/findfp.c
==============================================================================
--- stable/8/lib/libc/stdio/findfp.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/findfp.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -61,6 +61,7 @@ int	__sdidinit;
 	._read = __sread,		\
 	._seek = __sseek,		\
 	._write = __swrite,		\
+	._fl_mutex = PTHREAD_MUTEX_INITIALIZER, \
 }
 				/* the usual - (stdin + stdout + stderr) */
 static FILE usual[FOPEN_MAX - 3];
@@ -96,7 +97,7 @@ moreglue(n)
 	int n;
 {
 	struct glue *g;
-	static FILE empty;
+	static FILE empty = { ._fl_mutex = PTHREAD_MUTEX_INITIALIZER };
 	FILE *p;
 
 	g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE));
@@ -154,7 +155,7 @@ found:
 	fp->_ub._size = 0;
 	fp->_lb._base = NULL;	/* no line buffer */
 	fp->_lb._size = 0;
-/*	fp->_lock = NULL; */	/* once set always set (reused) */
+/*	fp->_fl_mutex = NULL; */ /* once set always set (reused) */
 	fp->_orientation = 0;
 	memset(&fp->_mbstate, 0, sizeof(mbstate_t));
 	return (fp);

Modified: stable/8/lib/libc/stdio/local.h
==============================================================================
--- stable/8/lib/libc/stdio/local.h	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/local.h	Tue Oct 12 13:13:20 2010	(r213720)
@@ -110,6 +110,14 @@ extern int	__sdidinit;
 }
 
 /*
+ * Structure initializations for 'fake' FILE objects.
+ */
+#define	FAKE_FILE {				\
+	._file = -1,				\
+	._fl_mutex = PTHREAD_MUTEX_INITIALIZER, \
+}
+
+/*
  * Set the orientation for a stream. If o > 0, the stream has wide-
  * orientation. If o < 0, the stream has byte-orientation.
  */

Modified: stable/8/lib/libc/stdio/snprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/snprintf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/snprintf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -48,7 +48,7 @@ snprintf(char * __restrict str, size_t n
 	size_t on;
 	int ret;
 	va_list ap;
-	FILE f;
+	FILE f = FAKE_FILE;
 
 	on = n;
 	if (n != 0)
@@ -56,12 +56,9 @@ snprintf(char * __restrict str, size_t n
 	if (n > INT_MAX)
 		n = INT_MAX;
 	va_start(ap, fmt);
-	f._file = -1;
 	f._flags = __SWR | __SSTR;
 	f._bf._base = f._p = (unsigned char *)str;
 	f._bf._size = f._w = n;
-	f._orientation = 0;
-	memset(&f._mbstate, 0, sizeof(mbstate_t));
 	ret = __vfprintf(&f, fmt, ap);
 	if (on > 0)
 		*f._p = '\0';

Modified: stable/8/lib/libc/stdio/vasprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/vasprintf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/vasprintf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -42,9 +42,8 @@ vasprintf(str, fmt, ap)
 	__va_list ap;
 {
 	int ret;
-	FILE f;
+	FILE f = FAKE_FILE;
 
-	f._file = -1;
 	f._flags = __SWR | __SSTR | __SALC;
 	f._bf._base = f._p = (unsigned char *)malloc(128);
 	if (f._bf._base == NULL) {
@@ -53,8 +52,6 @@ vasprintf(str, fmt, ap)
 		return (-1);
 	}
 	f._bf._size = f._w = 127;		/* Leave room for the NUL */
-	f._orientation = 0;
-	memset(&f._mbstate, 0, sizeof(mbstate_t));
 	ret = __vfprintf(&f, fmt, ap);
 	if (ret < 0) {
 		free(f._bf._base);

Modified: stable/8/lib/libc/stdio/vdprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/vdprintf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/vdprintf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -39,7 +39,7 @@ __FBSDID("$FreeBSD$");
 int
 vdprintf(int fd, const char * __restrict fmt, va_list ap)
 {
-	FILE f;
+	FILE f = FAKE_FILE;
 	unsigned char buf[BUFSIZ];
 	int ret;
 
@@ -56,8 +56,6 @@ vdprintf(int fd, const char * __restrict
 	f._write = __swrite;
 	f._bf._base = buf;
 	f._bf._size = sizeof(buf);
-	f._orientation = 0;
-	bzero(&f._mbstate, sizeof(f._mbstate));
 
 	if ((ret = __vfprintf(&f, fmt, ap)) < 0)
 		return (ret);

Modified: stable/8/lib/libc/stdio/vfprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/vfprintf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/vfprintf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -169,7 +169,7 @@ static int
 __sbprintf(FILE *fp, const char *fmt, va_list ap)
 {
 	int ret;
-	FILE fake;
+	FILE fake = FAKE_FILE;
 	unsigned char buf[BUFSIZ];
 
 	/* XXX This is probably not needed. */

Modified: stable/8/lib/libc/stdio/vsnprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/vsnprintf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/vsnprintf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -47,7 +47,7 @@ vsnprintf(char * __restrict str, size_t 
 	size_t on;
 	int ret;
 	char dummy[2];
-	FILE f;
+	FILE f = FAKE_FILE;
 
 	on = n;
 	if (n != 0)
@@ -61,12 +61,9 @@ vsnprintf(char * __restrict str, size_t 
 		str = dummy;
 		n = 1;
 	}
-	f._file = -1;
 	f._flags = __SWR | __SSTR;
 	f._bf._base = f._p = (unsigned char *)str;
 	f._bf._size = f._w = n;
-	f._orientation = 0;
-	memset(&f._mbstate, 0, sizeof(mbstate_t));
 	ret = __vfprintf(&f, fmt, ap);
 	if (on > 0)
 		*f._p = '\0';

Modified: stable/8/lib/libc/stdio/vsprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/vsprintf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/vsprintf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -44,14 +44,11 @@ int
 vsprintf(char * __restrict str, const char * __restrict fmt, __va_list ap)
 {
 	int ret;
-	FILE f;
+	FILE f = FAKE_FILE;
 
-	f._file = -1;
 	f._flags = __SWR | __SSTR;
 	f._bf._base = f._p = (unsigned char *)str;
 	f._bf._size = f._w = INT_MAX;
-	f._orientation = 0;
-	memset(&f._mbstate, 0, sizeof(mbstate_t));
 	ret = __vfprintf(&f, fmt, ap);
 	*f._p = 0;
 	return (ret);

Modified: stable/8/lib/libc/stdio/vsscanf.c
==============================================================================
--- stable/8/lib/libc/stdio/vsscanf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/vsscanf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -55,16 +55,11 @@ int
 vsscanf(const char * __restrict str, const char * __restrict fmt,
 	__va_list ap)
 {
-	FILE f;
+	FILE f = FAKE_FILE;
 
-	f._file = -1;
 	f._flags = __SRD;
 	f._bf._base = f._p = (unsigned char *)str;
 	f._bf._size = f._r = strlen(str);
 	f._read = eofread;
-	f._ub._base = NULL;
-	f._lb._base = NULL;
-	f._orientation = 0;
-	memset(&f._mbstate, 0, sizeof(mbstate_t));
 	return (__svfscanf(&f, fmt, ap));
 }

Modified: stable/8/lib/libc/stdio/vswprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/vswprintf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/vswprintf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -45,7 +45,7 @@ vswprintf(wchar_t * __restrict s, size_t
 {
 	static const mbstate_t initial;
 	mbstate_t mbs;
-	FILE f;
+	FILE f = FAKE_FILE;
 	char *mbp;
 	int ret, sverrno;
 	size_t nwc;
@@ -55,7 +55,6 @@ vswprintf(wchar_t * __restrict s, size_t
 		return (-1);
 	}
 
-	f._file = -1;
 	f._flags = __SWR | __SSTR | __SALC;
 	f._bf._base = f._p = (unsigned char *)malloc(128);
 	if (f._bf._base == NULL) {
@@ -63,8 +62,6 @@ vswprintf(wchar_t * __restrict s, size_t
 		return (-1);
 	}
 	f._bf._size = f._w = 127;		/* Leave room for the NUL */
-	f._orientation = 0;
-	memset(&f._mbstate, 0, sizeof(mbstate_t));
 	ret = __vfwprintf(&f, fmt, ap);
 	if (ret < 0) {
 		sverrno = errno;

Modified: stable/8/lib/libc/stdio/vswscanf.c
==============================================================================
--- stable/8/lib/libc/stdio/vswscanf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/vswscanf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -62,7 +62,7 @@ vswscanf(const wchar_t * __restrict str,
 {
 	static const mbstate_t initial;
 	mbstate_t mbs;
-	FILE f;
+	FILE f = FAKE_FILE;
 	char *mbstr;
 	size_t mlen;
 	int r;
@@ -80,15 +80,10 @@ vswscanf(const wchar_t * __restrict str,
 		free(mbstr);
 		return (EOF);
 	}
-	f._file = -1;
 	f._flags = __SRD;
 	f._bf._base = f._p = (unsigned char *)mbstr;
 	f._bf._size = f._r = mlen;
 	f._read = eofread;
-	f._ub._base = NULL;
-	f._lb._base = NULL;
-	f._orientation = 0;
-	memset(&f._mbstate, 0, sizeof(mbstate_t));
 	r = __vfwscanf(&f, fmt, ap);
 	free(mbstr);
 

Modified: stable/8/lib/libc/stdio/xprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/xprintf.c	Tue Oct 12 11:05:32 2010	(r213719)
+++ stable/8/lib/libc/stdio/xprintf.c	Tue Oct 12 13:13:20 2010	(r213720)
@@ -48,6 +48,7 @@
 #include <wchar.h>
 #include "un-namespace.h"
 
+#include "local.h"
 #include "printf.h"
 #include "fvwrite.h"
 
@@ -575,7 +576,7 @@ static int
 __v3printf(FILE *fp, const char *fmt, int pct, va_list ap)
 {
 	int ret;
-	FILE fake;
+	FILE fake = FAKE_FILE;
 	unsigned char buf[BUFSIZ];
 
 	/* copy the important variables */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201010121313.o9CDDKVw048587>