Author: jhb Date: Thu Mar 11 17:03:32 2010 New Revision: 205021 URL: http://svn.freebsd.org/changeset/base/205021
Log: - 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. PR: threads/141198 Reported by: Jeremy Huddleston @ Apple MFC after: 2 weeks Modified: head/lib/libc/stdio/findfp.c head/lib/libc/stdio/local.h head/lib/libc/stdio/snprintf.c head/lib/libc/stdio/vasprintf.c head/lib/libc/stdio/vdprintf.c head/lib/libc/stdio/vfprintf.c head/lib/libc/stdio/vsnprintf.c head/lib/libc/stdio/vsprintf.c head/lib/libc/stdio/vsscanf.c head/lib/libc/stdio/vswprintf.c head/lib/libc/stdio/vswscanf.c head/lib/libc/stdio/xprintf.c Modified: head/lib/libc/stdio/findfp.c ============================================================================== --- head/lib/libc/stdio/findfp.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/findfp.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/local.h ============================================================================== --- head/lib/libc/stdio/local.h Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/local.h Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/snprintf.c ============================================================================== --- head/lib/libc/stdio/snprintf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/snprintf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/vasprintf.c ============================================================================== --- head/lib/libc/stdio/vasprintf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/vasprintf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/vdprintf.c ============================================================================== --- head/lib/libc/stdio/vdprintf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/vdprintf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/vfprintf.c ============================================================================== --- head/lib/libc/stdio/vfprintf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/vfprintf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/vsnprintf.c ============================================================================== --- head/lib/libc/stdio/vsnprintf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/vsnprintf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/vsprintf.c ============================================================================== --- head/lib/libc/stdio/vsprintf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/vsprintf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/vsscanf.c ============================================================================== --- head/lib/libc/stdio/vsscanf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/vsscanf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/vswprintf.c ============================================================================== --- head/lib/libc/stdio/vswprintf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/vswprintf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/vswscanf.c ============================================================================== --- head/lib/libc/stdio/vswscanf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/vswscanf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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: head/lib/libc/stdio/xprintf.c ============================================================================== --- head/lib/libc/stdio/xprintf.c Thu Mar 11 16:58:15 2010 (r205020) +++ head/lib/libc/stdio/xprintf.c Thu Mar 11 17:03:32 2010 (r205021) @@ -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 */ _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"