Date: Thu, 15 Feb 2001 15:42:54 -0700 From: Warner Losh <imp@harmony.village.org> To: arch@freebsd.org Subject: Step 1 and 2 patch Message-ID: <200102152242.f1FMgsW11899@harmony.village.org>
next in thread | raw e-mail | index | archive | help
OK. This appears to work for me. I can run ports and other things with these changes. I'm submitting them for review. Please note, that this does *NOT* help us with the sizeof FILE being encoded into the binaries, yet. That's stage 3 and further. This just gets the tree working again with enough "headroom" for us to develop and review a change that will get us out from under this issue. We do need to fix this problem, but not right now and not by breaking the tree for days at a time. And not by requiring all libraries to have their major numbers bumped. Sorry to be blunt here, but I'm feeling nibbled to death by the "what about donig this or that" folks that aren't producing code that works. My frustration is showing through. Since the patch is only 200 lines, I've included it here. It is a slightly fixed up version of the patch that Brian posted here earlier and tries to minimize the grossness. I plan on committing this tomorrow morning. I'll be on IRC later today. Pass the word to interested parties. Warner Index: include/stdio.h =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/include/stdio.h,v retrieving revision 1.29 diff -u -r1.29 stdio.h --- include/stdio.h 2001/02/14 05:00:19 1.29 +++ include/stdio.h 2001/02/15 17:50:52 @@ -70,6 +70,12 @@ struct __file_lock; +/* hold a buncha junk that would grow the ABI */ +struct __sFILEX { + struct __file_lock *_mtlock; /* used for MT-safety */ + unsigned char *_up; /* saved _p when _p is doing ungetc data */ +}; + /* * stdio state variables. * @@ -114,7 +120,7 @@ /* separate buffer for long sequences of ungetc() */ struct __sbuf _ub; /* ungetc buffer */ - unsigned char *_up; /* saved _p when _p is doing ungetc data */ + struct __sFILEX *_extra; /* additions to FILE to not break ABI */ int _ur; /* saved _r when _r is counting ungetc data */ /* tricks to meet minimum requirements even when malloc() fails */ @@ -127,13 +133,10 @@ /* Unix stdio files get aligned to block boundaries on fseek() */ int _blksize; /* stat.st_blksize (may be != _bf._size) */ fpos_t _offset; /* current lseek offset (see WARNING) */ - struct __file_lock *_lock; /* used for MT-safety */ } FILE; __BEGIN_DECLS -extern FILE __stdin; -extern FILE __stdout; -extern FILE __stderr; +extern FILE __sF[]; __END_DECLS #define __SLBF 0x0001 /* line buffered */ @@ -196,9 +199,9 @@ #define SEEK_END 2 /* set file offset to EOF plus offset */ #endif -#define stdin (&__stdin) -#define stdout (&__stdout) -#define stderr (&__stderr) +#define stdin (&__sF[0]) +#define stdout (&__sF[1]) +#define stderr (&__sF[2]) /* * Functions defined in ANSI C standard. Index: lib/libc/Makefile =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/Makefile,v retrieving revision 1.29 diff -u -r1.29 Makefile --- lib/libc/Makefile 2001/02/14 05:00:20 1.29 +++ lib/libc/Makefile 2001/02/15 07:23:29 @@ -7,7 +7,7 @@ # from CFLAGS below. To remove these strings from just the system call # stubs, remove just -DSYSLIBC_RCS from CFLAGS. LIB=c -SHLIB_MAJOR= 5.20010213 +SHLIB_MAJOR= 5 SHLIB_MINOR= 0 CFLAGS+=-DLIBC_RCS -DSYSLIBC_RCS -I${.CURDIR}/include AINC= -I${.CURDIR}/${MACHINE_ARCH} Index: lib/libc/stdio/_flock_stub.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/stdio/_flock_stub.c,v retrieving revision 1.5 diff -u -r1.5 _flock_stub.c --- lib/libc/stdio/_flock_stub.c 2001/02/11 22:06:39 1.5 +++ lib/libc/stdio/_flock_stub.c 2001/02/15 20:31:21 @@ -68,6 +68,16 @@ }; /* + * We need to retain binary compatibility for a while. So pretend + * that _lock is part of FILE * even though it is dereferenced off + * _extra now. When we stop encoding the size of FILE into binaries + * this can be changed in stdio.h. This will reduce the amount of + * code that has to change in the future (just remove this comment + * and #define). + */ +#define _lock _extra->_mtlock + +/* * Allocate and initialize a file lock. */ static int Index: lib/libc/stdio/findfp.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/stdio/findfp.c,v retrieving revision 1.13 diff -u -r1.13 findfp.c --- lib/libc/stdio/findfp.c 2001/02/14 05:00:20 1.13 +++ lib/libc/stdio/findfp.c 2001/02/15 16:29:55 @@ -59,21 +59,22 @@ #define NDYNAMIC 10 /* add ten more whenever necessary */ -#define std(handle, flags, file) \ -FILE handle = {0,0,0,flags,file,{0},0,&handle,__sclose,__sread,__sseek,__swrite} -/* p r w flags file _bf z cookie close read seek write */ - +#define std(flags, file) \ + {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite, __sFX + file} +/* p r w flags file _bf z cookie close read seek write extra*/ /* the usual - (stdin + stdout + stderr) */ static FILE usual[FOPEN_MAX - 3]; static struct glue uglue = { NULL, FOPEN_MAX - 3, usual }; + +static struct __sFILEX __sFX[3]; + +FILE __sF[3] = { + std(__SRD, STDIN_FILENO), + std(__SWR, STDOUT_FILENO), + std(__SWR|__SNBF, STDERR_FILENO) +}; -std(__stdin, __SRD, STDIN_FILENO); -std(__stdout, __SWR, STDOUT_FILENO); -std(__stderr, __SWR|__SNBF, STDERR_FILENO); - -static struct glue sglue2 = { &uglue, 1, &__stderr }; -static struct glue sglue1 = { &sglue2, 1, &__stdout }; -struct glue __sglue = { &sglue1, 1, &__stdin }; +struct glue __sglue = { &uglue, 3, __sF }; static struct glue *lastglue = &uglue; static struct glue * moreglue __P((int)); @@ -93,18 +94,26 @@ int n; { struct glue *g; - FILE *p; static FILE empty; + static struct __sFILEX emptyx; + FILE *p; + struct __sFILEX *fx; - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); + g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE) + + n * sizeof(struct __sFILEX)); if (g == NULL) return (NULL); p = (FILE *)ALIGN(g + 1); + fx = (struct __sFILEX *)&p[n]; g->next = NULL; g->niobs = n; g->iobs = p; - while (--n >= 0) - *p++ = empty; + while (--n >= 0) { + *p = empty; + p->_extra = fx; + *p->_extra = emptyx; + p++, fx++; + } return (g); } Index: lib/libc/stdio/fseek.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/stdio/fseek.c,v retrieving revision 1.10 diff -u -r1.10 fseek.c --- lib/libc/stdio/fseek.c 2001/01/24 13:00:45 1.10 +++ lib/libc/stdio/fseek.c 2001/02/15 07:16:26 @@ -204,7 +204,7 @@ */ if (HASUB(fp)) { curoff += fp->_r; /* kill off ungetc */ - n = fp->_up - fp->_bf._base; + n = fp->_extra->_up - fp->_bf._base; curoff -= n; n += fp->_ur; } else { Index: lib/libc/stdio/refill.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/stdio/refill.c,v retrieving revision 1.10 diff -u -r1.10 refill.c --- lib/libc/stdio/refill.c 2001/02/11 22:06:42 1.10 +++ lib/libc/stdio/refill.c 2001/02/15 07:16:26 @@ -109,7 +109,7 @@ if (HASUB(fp)) { FREEUB(fp); if ((fp->_r = fp->_ur) != 0) { - fp->_p = fp->_up; + fp->_p = fp->_extra->_up; return (0); } } Index: lib/libc/stdio/ungetc.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/stdio/ungetc.c,v retrieving revision 1.8 diff -u -r1.8 ungetc.c --- lib/libc/stdio/ungetc.c 2001/01/24 13:00:47 1.8 +++ lib/libc/stdio/ungetc.c 2001/02/15 07:16:26 @@ -164,7 +164,7 @@ * Initially, we will use the `reserve' buffer. */ fp->_ur = fp->_r; - fp->_up = fp->_p; + fp->_extra->_up = fp->_p; fp->_ub._base = fp->_ubuf; fp->_ub._size = sizeof(fp->_ubuf); fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102152242.f1FMgsW11899>