home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-13 | 46.4 KB | 1,894 lines |
- Newsgroups: comp.sources.misc
- From: lwall@netlabs.com (Larry Wall)
- Subject: v25i063: perl - The perl programming language, Patch14
- Message-ID: <1991Nov13.214352.3713@sparky.imd.sterling.com>
- X-Md4-Signature: f49d5027096cbbf2407192e85e45826c
- Date: Wed, 13 Nov 1991 21:43:52 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: lwall@netlabs.com (Larry Wall)
- Posting-number: Volume 25, Issue 63
- Archive-name: perl/patch14
- Environment: UNIX, MS-DOS, OS2
- Patch-To: perl: Volume 18, Issue 19-54
-
- System: perl version 4.0
- Patch #: 14
- Priority: MED-HIGH
- Subject: patch #11, continued
-
- Description:
- See patch #11.
-
- Fix: From rn, say "| patch -p -N -d DIR", where DIR is your perl source
- directory. Outside of rn, say "cd DIR; patch -p -N <thisarticle".
- If you don't have the patch program, apply the following by hand,
- or get patch (version 2.0, latest patchlevel).
-
- After patching:
- *** DO NOTHING--INSTALL ALL PATCHES UP THROUGH #18 FIRST ***
-
- If patch indicates that patchlevel is the wrong version, you may need
- to apply one or more previous patches, or the patch may already
- have been applied. See the patchlevel.h file to find out what has or
- has not been applied. In any event, don't continue with the patch.
-
- If you are missing previous patches they can be obtained from me:
-
- Larry Wall
- lwall@netlabs.com
-
- If you send a mail message of the following form it will greatly speed
- processing:
-
- Subject: Command
- @SH mailpatch PATH perl 4.0 LIST
- ^ note the c
-
- where PATH is a return path FROM ME TO YOU either in Internet notation,
- or in bang notation from some well-known host, and LIST is the number
- of one or more patches you need, separated by spaces, commas, and/or
- hyphens. Saying 35- says everything from 35 to the end.
-
-
- Index: patchlevel.h
- Prereq: 13
- 1c1
- < #define PATCHLEVEL 13
- ---
- > #define PATCHLEVEL 14
-
- Index: doio.c
- *** doio.c.old Tue Nov 5 19:26:02 1991
- --- doio.c Tue Nov 5 19:26:03 1991
- ***************
- *** 1,4 ****
- ! /* $RCSfile: doio.c,v $$Revision: 4.0.1.3 $$Date: 91/06/10 01:21:19 $
- *
- * Copyright (c) 1991, Larry Wall
- *
- --- 1,4 ----
- ! /* $RCSfile: doio.c,v $$Revision: 4.0.1.4 $$Date: 91/11/05 16:51:43 $
- *
- * Copyright (c) 1991, Larry Wall
- *
- ***************
- *** 6,11 ****
- --- 6,20 ----
- * License or the Artistic License, as specified in the README file.
- *
- * $Log: doio.c,v $
- + * Revision 4.0.1.4 91/11/05 16:51:43 lwall
- + * patch11: prepared for ctype implementations that don't define isascii()
- + * patch11: perl mistook some streams for sockets because they return mode 0 too
- + * patch11: reopening STDIN, STDOUT and STDERR failed on some machines
- + * patch11: certain perl errors should set EBADF so that $! looks better
- + * patch11: truncate on a closed filehandle could dump
- + * patch11: stats of _ forgot whether prior stat was actually lstat
- + * patch11: -T returned true on NFS directory
- + *
- * Revision 4.0.1.3 91/06/10 01:21:19 lwall
- * patch10: read didn't work from character special files open for writing
- * patch10: close-on-exec wrongly set on system file descriptors
- ***************
- *** 93,99 ****
-
- name = myname;
- forkprocess = 1; /* assume true if no fork */
- ! while (len && isspace(name[len-1]))
- name[--len] = '\0';
- if (!stio)
- stio = stab_io(stab) = stio_new();
- --- 102,108 ----
-
- name = myname;
- forkprocess = 1; /* assume true if no fork */
- ! while (len && isSPACE(name[len-1]))
- name[--len] = '\0';
- if (!stio)
- stio = stab_io(stab) = stio_new();
- ***************
- *** 135,141 ****
- }
- stio->type = *name;
- if (*name == '|') {
- ! for (name++; isspace(*name); name++) ;
- #ifdef TAINT
- taintenv();
- taintproper("Insecure dependency in piped open");
- --- 144,151 ----
- }
- stio->type = *name;
- if (*name == '|') {
- ! /*SUPPRESS 530*/
- ! for (name++; isSPACE(*name); name++) ;
- #ifdef TAINT
- taintenv();
- taintproper("Insecure dependency in piped open");
- ***************
- *** 158,166 ****
- if (*name == '&') {
- duplicity:
- name++;
- ! while (isspace(*name))
- name++;
- ! if (isdigit(*name))
- fd = atoi(name);
- else {
- stab = stabent(name,FALSE);
- --- 168,176 ----
- if (*name == '&') {
- duplicity:
- name++;
- ! while (isSPACE(*name))
- name++;
- ! if (isDIGIT(*name))
- fd = atoi(name);
- else {
- stab = stabent(name,FALSE);
- ***************
- *** 183,189 ****
- }
- }
- else {
- ! while (isspace(*name))
- name++;
- if (strEQ(name,"-")) {
- fp = stdout;
- --- 193,199 ----
- }
- }
- else {
- ! while (isSPACE(*name))
- name++;
- if (strEQ(name,"-")) {
- fp = stdout;
- ***************
- *** 198,204 ****
- if (*name == '<') {
- mode[0] = 'r';
- name++;
- ! while (isspace(*name))
- name++;
- if (*name == '&')
- goto duplicity;
- --- 208,214 ----
- if (*name == '<') {
- mode[0] = 'r';
- name++;
- ! while (isSPACE(*name))
- name++;
- if (*name == '&')
- goto duplicity;
- ***************
- *** 215,229 ****
- taintproper("Insecure dependency in piped open");
- #endif
- name[--len] = '\0';
- ! while (len && isspace(name[len-1]))
- name[--len] = '\0';
- ! for (; isspace(*name); name++) ;
- fp = mypopen(name,"r");
- stio->type = '|';
- }
- else {
- stio->type = '<';
- ! for (; isspace(*name); name++) ;
- if (strEQ(name,"-")) {
- fp = stdin;
- stio->type = '-';
- --- 225,241 ----
- taintproper("Insecure dependency in piped open");
- #endif
- name[--len] = '\0';
- ! while (len && isSPACE(name[len-1]))
- name[--len] = '\0';
- ! /*SUPPRESS 530*/
- ! for (; isSPACE(*name); name++) ;
- fp = mypopen(name,"r");
- stio->type = '|';
- }
- else {
- stio->type = '<';
- ! /*SUPPRESS 530*/
- ! for (; isSPACE(*name); name++) ;
- if (strEQ(name,"-")) {
- fp = stdin;
- stio->type = '-';
- ***************
- *** 243,252 ****
- }
- if (S_ISSOCK(statbuf.st_mode))
- stio->type = 's'; /* in case a socket was passed in to us */
- #ifdef S_IFMT
- ! else if (!(statbuf.st_mode & S_IFMT))
- ! stio->type = 's'; /* some OS's return 0 on fstat()ed socket */
- #endif
- }
- if (saveifp) { /* must use old fp? */
- fd = fileno(saveifp);
- --- 255,273 ----
- }
- if (S_ISSOCK(statbuf.st_mode))
- stio->type = 's'; /* in case a socket was passed in to us */
- + #ifdef HAS_SOCKET
- + else if (
- #ifdef S_IFMT
- ! !(statbuf.st_mode & S_IFMT)
- ! #else
- ! !statbuf.st_mode
- #endif
- + ) {
- + if (getsockname(fileno(fp), tokenbuf, 0) >= 0 || errno != ENOTSOCK)
- + stio->type = 's'; /* some OS's return 0 on fstat()ed socket */
- + /* but some return 0 for streams too, sigh */
- + }
- + #endif
- }
- if (saveifp) { /* must use old fp? */
- fd = fileno(saveifp);
- ***************
- *** 254,260 ****
- fflush(saveofp); /* emulate fclose() */
- if (saveofp != saveifp) { /* was a socket? */
- fclose(saveofp);
- ! Safefree(saveofp);
- }
- }
- if (fd != fileno(fp)) {
- --- 275,282 ----
- fflush(saveofp); /* emulate fclose() */
- if (saveofp != saveifp) { /* was a socket? */
- fclose(saveofp);
- ! if (fd > 2)
- ! Safefree(saveofp);
- }
- }
- if (fd != fileno(fp)) {
- ***************
- *** 294,301 ****
- --- 316,325 ----
- register STAB *stab;
- {
- register STR *str;
- + #ifndef FLEXFILENAMES
- int filedev;
- int fileino;
- + #endif
- int fileuid;
- int filegid;
- static int filemode = 0;
- ***************
- *** 328,335 ****
- --- 352,361 ----
- defoutstab = stabent("STDOUT",TRUE);
- return stab_io(stab)->ifp;
- }
- + #ifndef FLEXFILENAMES
- filedev = statbuf.st_dev;
- fileino = statbuf.st_ino;
- + #endif
- filemode = statbuf.st_mode;
- fileuid = statbuf.st_uid;
- filegid = statbuf.st_gid;
- ***************
- *** 503,510 ****
-
- if (!stab)
- stab = argvstab;
- ! if (!stab)
- return FALSE;
- stio = stab_io(stab);
- if (!stio) { /* never opened */
- if (dowarn && explicit)
- --- 529,538 ----
-
- if (!stab)
- stab = argvstab;
- ! if (!stab) {
- ! errno = EBADF;
- return FALSE;
- + }
- stio = stab_io(stab);
- if (!stio) { /* never opened */
- if (dowarn && explicit)
- ***************
- *** 601,606 ****
- --- 629,635 ----
- phooey:
- if (dowarn)
- warn("tell() on unopened file");
- + errno = EBADF;
- return -1L;
- }
-
- ***************
- *** 627,632 ****
- --- 656,662 ----
- nuts:
- if (dowarn)
- warn("seek() on unopened file");
- + errno = EBADF;
- return FALSE;
- }
-
- ***************
- *** 641,651 ****
- register char *s;
- int retval;
-
- ! if (!stab || !argstr)
- return -1;
- ! stio = stab_io(stab);
- ! if (!stio)
- ! return -1;
-
- if (argstr->str_pok || !argstr->str_nok) {
- if (!argstr->str_pok)
- --- 671,680 ----
- register char *s;
- int retval;
-
- ! if (!stab || !argstr || !(stio = stab_io(stab)) || !stio->ifp) {
- ! errno = EBADF; /* well, sort of... */
- return -1;
- ! }
-
- if (argstr->str_pok || !argstr->str_nok) {
- if (!argstr->str_pok)
- ***************
- *** 847,853 ****
- }
- #endif /* F_FREESP */
-
- ! int
- do_truncate(str,arg,gimme,arglast)
- STR *str;
- register ARG *arg;
- --- 876,882 ----
- }
- #endif /* F_FREESP */
-
- ! int /*SUPPRESS 590*/
- do_truncate(str,arg,gimme,arglast)
- STR *str;
- register ARG *arg;
- ***************
- *** 864,870 ****
- #ifdef HAS_TRUNCATE
- if ((arg[1].arg_type & A_MASK) == A_WORD) {
- tmpstab = arg[1].arg_ptr.arg_stab;
- ! if (!stab_io(tmpstab) ||
- ftruncate(fileno(stab_io(tmpstab)->ifp), len) < 0)
- result = 0;
- }
- --- 893,899 ----
- #ifdef HAS_TRUNCATE
- if ((arg[1].arg_type & A_MASK) == A_WORD) {
- tmpstab = arg[1].arg_ptr.arg_stab;
- ! if (!stab_io(tmpstab) || !stab_io(tmpstab)->ifp ||
- ftruncate(fileno(stab_io(tmpstab)->ifp), len) < 0)
- result = 0;
- }
- ***************
- *** 873,879 ****
- #else
- if ((arg[1].arg_type & A_MASK) == A_WORD) {
- tmpstab = arg[1].arg_ptr.arg_stab;
- ! if (!stab_io(tmpstab) ||
- chsize(fileno(stab_io(tmpstab)->ifp), len) < 0)
- result = 0;
- }
- --- 902,908 ----
- #else
- if ((arg[1].arg_type & A_MASK) == A_WORD) {
- tmpstab = arg[1].arg_ptr.arg_stab;
- ! if (!stab_io(tmpstab) || !stab_io(tmpstab)->ifp ||
- chsize(fileno(stab_io(tmpstab)->ifp), len) < 0)
- result = 0;
- }
- ***************
- *** 913,925 ****
- return TRUE;
- s = str->str_ptr;
- send = s + str->str_cur;
- ! while (isspace(*s))
- s++;
- if (s >= send)
- return FALSE;
- if (*s == '+' || *s == '-')
- s++;
- ! while (isdigit(*s))
- s++;
- if (s == send)
- return TRUE;
- --- 942,954 ----
- return TRUE;
- s = str->str_ptr;
- send = s + str->str_cur;
- ! while (isSPACE(*s))
- s++;
- if (s >= send)
- return FALSE;
- if (*s == '+' || *s == '-')
- s++;
- ! while (isDIGIT(*s))
- s++;
- if (s == send)
- return TRUE;
- ***************
- *** 927,933 ****
- s++;
- else if (s == str->str_ptr)
- return FALSE;
- ! while (isdigit(*s))
- s++;
- if (s == send)
- return TRUE;
- --- 956,962 ----
- s++;
- else if (s == str->str_ptr)
- return FALSE;
- ! while (isDIGIT(*s))
- s++;
- if (s == send)
- return TRUE;
- ***************
- *** 935,944 ****
- s++;
- if (*s == '+' || *s == '-')
- s++;
- ! while (isdigit(*s))
- s++;
- }
- ! while (isspace(*s))
- s++;
- if (s >= send)
- return TRUE;
- --- 964,973 ----
- s++;
- if (*s == '+' || *s == '-')
- s++;
- ! while (isDIGIT(*s))
- s++;
- }
- ! while (isSPACE(*s))
- s++;
- if (s >= send)
- return TRUE;
- ***************
- *** 955,960 ****
- --- 984,990 ----
- if (!fp) {
- if (dowarn)
- warn("print to unopened file");
- + errno = EBADF;
- return FALSE;
- }
- if (!str)
- ***************
- *** 995,1000 ****
- --- 1025,1031 ----
- if (!fp) {
- if (dowarn)
- warn("print to unopened file");
- + errno = EBADF;
- return FALSE;
- }
- st += ++sp;
- ***************
- *** 1028,1039 ****
- {
- STIO *stio;
-
- - laststype = O_STAT;
- if (arg[1].arg_type & A_DONT) {
- stio = stab_io(arg[1].arg_ptr.arg_stab);
- if (stio && stio->ifp) {
- statstab = arg[1].arg_ptr.arg_stab;
- str_set(statname,"");
- return (laststatval = fstat(fileno(stio->ifp), &statcache));
- }
- else {
- --- 1059,1070 ----
- {
- STIO *stio;
-
- if (arg[1].arg_type & A_DONT) {
- stio = stab_io(arg[1].arg_ptr.arg_stab);
- if (stio && stio->ifp) {
- statstab = arg[1].arg_ptr.arg_stab;
- str_set(statname,"");
- + laststype = O_STAT;
- return (laststatval = fstat(fileno(stio->ifp), &statcache));
- }
- else {
- ***************
- *** 1050,1055 ****
- --- 1081,1087 ----
- else {
- statstab = Nullstab;
- str_set(statname,str_get(str));
- + laststype = O_STAT;
- return (laststatval = stat(str_get(str),&statcache));
- }
- }
- ***************
- *** 1107,1112 ****
- --- 1139,1146 ----
- if (stio && stio->ifp) {
- #ifdef STDSTDIO
- fstat(fileno(stio->ifp),&statcache);
- + if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */
- + return arg->arg_type == O_FTTEXT ? &str_no : &str_yes;
- if (stio->ifp->_cnt <= 0) {
- i = getc(stio->ifp);
- if (i != EOF)
- ***************
- *** 1117,1123 ****
- len = stio->ifp->_cnt + (stio->ifp->_ptr - stio->ifp->_base);
- s = stio->ifp->_base;
- #else
- ! fatal("-T and -B not implemented on filehandles\n");
- #endif
- }
- else {
- --- 1151,1157 ----
- len = stio->ifp->_cnt + (stio->ifp->_ptr - stio->ifp->_base);
- s = stio->ifp->_base;
- #else
- ! fatal("-T and -B not implemented on filehandles");
- #endif
- }
- else {
- ***************
- *** 1124,1129 ****
- --- 1158,1164 ----
- if (dowarn)
- warn("Test on unopened file <%s>",
- stab_name(arg[1].arg_ptr.arg_stab));
- + errno = EBADF;
- return &str_undef;
- }
- }
- ***************
- *** 1137,1144 ****
- fstat(i,&statcache);
- len = read(i,tbuf,512);
- (void)close(i);
- ! if (len <= 0) /* null file is anything */
- ! return &str_yes;
- s = tbuf;
- }
-
- --- 1172,1182 ----
- fstat(i,&statcache);
- len = read(i,tbuf,512);
- (void)close(i);
- ! if (len <= 0) {
- ! if (S_ISDIR(statcache.st_mode) && arg->arg_type == O_FTTEXT)
- ! return &str_no; /* special case NFS directories */
- ! return &str_yes; /* null file is anything */
- ! }
- s = tbuf;
- }
-
- ***************
- *** 1253,1263 ****
-
- /* see if there are shell metacharacters in it */
-
- ! for (s = cmd; *s && isalpha(*s); s++) ; /* catch VAR=val gizmo */
- if (*s == '=')
- goto doshell;
- for (s = cmd; *s; s++) {
- ! if (*s != ' ' && !isalpha(*s) && index("$&*(){}[]'\";\\|?<>~`\n",*s)) {
- if (*s == '\n' && !s[1]) {
- *s = '\0';
- break;
- --- 1291,1302 ----
-
- /* see if there are shell metacharacters in it */
-
- ! /*SUPPRESS 530*/
- ! for (s = cmd; *s && isALPHA(*s); s++) ; /* catch VAR=val gizmo */
- if (*s == '=')
- goto doshell;
- for (s = cmd; *s; s++) {
- ! if (*s != ' ' && !isALPHA(*s) && index("$&*(){}[]'\";\\|?<>~`\n",*s)) {
- if (*s == '\n' && !s[1]) {
- *s = '\0';
- break;
- ***************
- *** 1271,1280 ****
- Cmd = nsavestr(cmd, s-cmd);
- a = Argv;
- for (s = Cmd; *s;) {
- ! while (*s && isspace(*s)) s++;
- if (*s)
- *(a++) = s;
- ! while (*s && !isspace(*s)) s++;
- if (*s)
- *s++ = '\0';
- }
- --- 1310,1319 ----
- Cmd = nsavestr(cmd, s-cmd);
- a = Argv;
- for (s = Cmd; *s;) {
- ! while (*s && isSPACE(*s)) s++;
- if (*s)
- *(a++) = s;
- ! while (*s && !isSPACE(*s)) s++;
- if (*s)
- *s++ = '\0';
- }
- ***************
- *** 1301,1308 ****
- register STIO *stio;
- int domain, type, protocol, fd;
-
- ! if (!stab)
- return FALSE;
-
- stio = stab_io(stab);
- if (!stio)
- --- 1340,1349 ----
- register STIO *stio;
- int domain, type, protocol, fd;
-
- ! if (!stab) {
- ! errno = EBADF;
- return FALSE;
- + }
-
- stio = stab_io(stab);
- if (!stio)
- ***************
- *** 1358,1363 ****
- --- 1399,1405 ----
- nuts:
- if (dowarn)
- warn("bind() on closed fd");
- + errno = EBADF;
- return FALSE;
-
- }
- ***************
- *** 1388,1393 ****
- --- 1430,1436 ----
- nuts:
- if (dowarn)
- warn("connect() on closed fd");
- + errno = EBADF;
- return FALSE;
-
- }
- ***************
- *** 1415,1420 ****
- --- 1458,1464 ----
- nuts:
- if (dowarn)
- warn("listen() on closed fd");
- + errno = EBADF;
- return FALSE;
- }
-
- ***************
- *** 1463,1468 ****
- --- 1507,1513 ----
- nuts:
- if (dowarn)
- warn("accept() on closed fd");
- + errno = EBADF;
- badexit:
- str_sset(str,&str_undef);
- return;
- ***************
- *** 1491,1496 ****
- --- 1536,1542 ----
- nuts:
- if (dowarn)
- warn("shutdown() on closed fd");
- + errno = EBADF;
- return FALSE;
-
- }
- ***************
- *** 1520,1526 ****
- optname = (int)str_gnum(st[sp+2]);
- switch (optype) {
- case O_GSOCKOPT:
- ! st[sp] = str_2mortal(str_new(257));
- st[sp]->str_cur = 256;
- st[sp]->str_pok = 1;
- if (getsockopt(fd, lvl, optname, st[sp]->str_ptr, &st[sp]->str_cur) < 0)
- --- 1566,1572 ----
- optname = (int)str_gnum(st[sp+2]);
- switch (optype) {
- case O_GSOCKOPT:
- ! st[sp] = str_2mortal(Str_new(22,257));
- st[sp]->str_cur = 256;
- st[sp]->str_pok = 1;
- if (getsockopt(fd, lvl, optname, st[sp]->str_ptr, &st[sp]->str_cur) < 0)
- ***************
- *** 1540,1545 ****
- --- 1586,1592 ----
- if (dowarn)
- warn("[gs]etsockopt() on closed fd");
- st[sp] = &str_undef;
- + errno = EBADF;
- return sp;
-
- }
- ***************
- *** 1562,1568 ****
- if (!stio || !stio->ifp)
- goto nuts;
-
- ! st[sp] = str_2mortal(str_new(257));
- st[sp]->str_cur = 256;
- st[sp]->str_pok = 1;
- fd = fileno(stio->ifp);
- --- 1609,1615 ----
- if (!stio || !stio->ifp)
- goto nuts;
-
- ! st[sp] = str_2mortal(Str_new(22,257));
- st[sp]->str_cur = 256;
- st[sp]->str_pok = 1;
- fd = fileno(stio->ifp);
- ***************
- *** 1582,1587 ****
- --- 1629,1635 ----
- nuts:
- if (dowarn)
- warn("get{sock,peer}name() on closed fd");
- + errno = EBADF;
- nuts2:
- st[sp] = &str_undef;
- return sp;
- ***************
- *** 2208,2213 ****
- --- 2256,2262 ----
- case O_READDIR:
- if (gimme == G_ARRAY) {
- --sp;
- + /*SUPPRESS 560*/
- while (dp = readdir(stio->dirp)) {
- #ifdef DIRNAMLEN
- (void)astore(ary,++sp,
- ***************
- *** 2258,2263 ****
- --- 2307,2314 ----
-
- nope:
- st[sp] = &str_undef;
- + if (!errno)
- + errno = EBADF;
- return sp;
-
- #else
- ***************
- *** 2323,2329 ****
- if (--items > 0) {
- tot = items;
- s = str_get(st[++sp]);
- ! if (isupper(*s)) {
- if (*s == 'S' && s[1] == 'I' && s[2] == 'G')
- s += 3;
- if (!(val = whichsig(s)))
- --- 2374,2380 ----
- if (--items > 0) {
- tot = items;
- s = str_get(st[++sp]);
- ! if (isUPPER(*s)) {
- if (*s == 'S' && s[1] == 'I' && s[2] == 'G')
- s += 3;
- if (!(val = whichsig(s)))
-
- Index: dolist.c
- *** dolist.c.old Tue Nov 5 19:26:07 1991
- --- dolist.c Tue Nov 5 19:26:08 1991
- ***************
- *** 1,4 ****
- ! /* $RCSfile: dolist.c,v $$Revision: 4.0.1.2 $$Date: 91/06/10 01:22:15 $
- *
- * Copyright (c) 1991, Larry Wall
- *
- --- 1,4 ----
- ! /* $RCSfile: dolist.c,v $$Revision: 4.0.1.3 $$Date: 91/11/05 17:07:02 $
- *
- * Copyright (c) 1991, Larry Wall
- *
- ***************
- *** 6,11 ****
- --- 6,22 ----
- * License or the Artistic License, as specified in the README file.
- *
- * $Log: dolist.c,v $
- + * Revision 4.0.1.3 91/11/05 17:07:02 lwall
- + * patch11: prepared for ctype implementations that don't define isascii()
- + * patch11: /$foo/o optimizer could access deallocated data
- + * patch11: certain optimizations of //g in array context returned too many values
- + * patch11: regexp with no parens in array context returned wacky $`, $& and $'
- + * patch11: $' not set right on some //g
- + * patch11: added some support for 64-bit integers
- + * patch11: grep of a split lost its values
- + * patch11: added sort {} LIST
- + * patch11: multiple reallocations now avoided in 1 .. 100000
- + *
- * Revision 4.0.1.2 91/06/10 01:22:15 lwall
- * patch10: //g only worked first time through
- *
- ***************
- *** 94,103 ****
- if (!spat->spat_regexp->prelen && lastspat)
- spat = lastspat;
- if (spat->spat_flags & SPAT_KEEP) {
- if (spat->spat_runtime)
- arg_free(spat->spat_runtime); /* it won't change, so */
- spat->spat_runtime = Nullarg; /* no point compiling again */
- - scanconst(spat, t, tmpstr->str_cur);
- hoistmust(spat);
- if (curcmd->c_expr && (curcmd->c_flags & CF_OPTIMIZE) == CFT_EVAL) {
- curcmd->c_flags &= ~CF_OPTIMIZE;
- --- 105,114 ----
- if (!spat->spat_regexp->prelen && lastspat)
- spat = lastspat;
- if (spat->spat_flags & SPAT_KEEP) {
- + scanconst(spat,spat->spat_regexp->precomp, spat->spat_regexp->prelen);
- if (spat->spat_runtime)
- arg_free(spat->spat_runtime); /* it won't change, so */
- spat->spat_runtime = Nullarg; /* no point compiling again */
- hoistmust(spat);
- if (curcmd->c_expr && (curcmd->c_flags & CF_OPTIMIZE) == CFT_EVAL) {
- curcmd->c_flags &= ~CF_OPTIMIZE;
- ***************
- *** 145,151 ****
- t = s;
- play_it_again:
- if (global && spat->spat_regexp->startp[0])
- ! s = spat->spat_regexp->endp[0];
- if (myhint) {
- if (myhint < s || myhint > strend)
- fatal("panic: hint in do_match");
- --- 156,162 ----
- t = s;
- play_it_again:
- if (global && spat->spat_regexp->startp[0])
- ! t = s = spat->spat_regexp->endp[0];
- if (myhint) {
- if (myhint < s || myhint > strend)
- fatal("panic: hint in do_match");
- ***************
- *** 192,199 ****
- spat->spat_short = Nullstr; /* opt is being useless */
- }
- }
- ! if (!spat->spat_regexp->nparens && !global)
- gimme = G_SCALAR; /* accidental array context? */
- if (regexec(spat->spat_regexp, s, strend, t, 0,
- srchstr->str_pok & SP_STUDIED ? srchstr : Nullstr,
- safebase)) {
- --- 203,212 ----
- spat->spat_short = Nullstr; /* opt is being useless */
- }
- }
- ! if (!spat->spat_regexp->nparens && !global) {
- gimme = G_SCALAR; /* accidental array context? */
- + safebase = FALSE;
- + }
- if (regexec(spat->spat_regexp, s, strend, t, 0,
- srchstr->str_pok & SP_STUDIED ? srchstr : Nullstr,
- safebase)) {
- ***************
- *** 233,238 ****
- --- 246,252 ----
-
- for (i = !i; i <= iters; i++) {
- st[++sp] = str_mortal(&str_no);
- + /*SUPPRESS 560*/
- if (s = spat->spat_regexp->startp[i]) {
- len = spat->spat_regexp->endp[i] - s;
- if (len > 0)
- ***************
- *** 256,261 ****
- --- 270,277 ----
- if (spat->spat_flags & SPAT_ONCE)
- spat->spat_flags |= SPAT_USED;
- if (global) {
- + spat->spat_regexp->subbeg = t;
- + spat->spat_regexp->subend = strend;
- spat->spat_regexp->startp[0] = s;
- spat->spat_regexp->endp[0] = s + spat->spat_short->str_cur;
- curspat = spat;
- ***************
- *** 363,369 ****
- ary = stack;
- orig = s;
- if (spat->spat_flags & SPAT_SKIPWHITE) {
- ! while (isascii(*s) && isspace(*s))
- s++;
- }
- if (!limit)
- --- 379,385 ----
- ary = stack;
- orig = s;
- if (spat->spat_flags & SPAT_SKIPWHITE) {
- ! while (isSPACE(*s))
- s++;
- }
- if (!limit)
- ***************
- *** 370,376 ****
- limit = maxiters + 2;
- if (strEQ("\\s+",spat->spat_regexp->precomp)) {
- while (--limit) {
- ! for (m = s; m < strend && !(isascii(*m)&&isspace(*m)); m++) ;
- if (m >= strend)
- break;
- dstr = Str_new(30,m-s);
- --- 386,393 ----
- limit = maxiters + 2;
- if (strEQ("\\s+",spat->spat_regexp->precomp)) {
- while (--limit) {
- ! /*SUPPRESS 530*/
- ! for (m = s; m < strend && !isSPACE(*m); m++) ;
- if (m >= strend)
- break;
- dstr = Str_new(30,m-s);
- ***************
- *** 378,388 ****
- if (!realarray)
- str_2mortal(dstr);
- (void)astore(ary, ++sp, dstr);
- ! for (s = m + 1; s < strend && isascii(*s) && isspace(*s); s++) ;
- }
- }
- else if (strEQ("^",spat->spat_regexp->precomp)) {
- while (--limit) {
- for (m = s; m < strend && *m != '\n'; m++) ;
- m++;
- if (m >= strend)
- --- 395,407 ----
- if (!realarray)
- str_2mortal(dstr);
- (void)astore(ary, ++sp, dstr);
- ! /*SUPPRESS 530*/
- ! for (s = m + 1; s < strend && isSPACE(*s); s++) ;
- }
- }
- else if (strEQ("^",spat->spat_regexp->precomp)) {
- while (--limit) {
- + /*SUPPRESS 530*/
- for (m = s; m < strend && *m != '\n'; m++) ;
- m++;
- if (m >= strend)
- ***************
- *** 401,417 ****
- int fold = (spat->spat_flags & SPAT_FOLD);
-
- i = *spat->spat_short->str_ptr;
- ! if (fold && isupper(i))
- i = tolower(i);
- while (--limit) {
- if (fold) {
- for ( m = s;
- m < strend && *m != i &&
- ! (!isupper(*m) || tolower(*m) != i);
- ! m++)
- ;
- }
- ! else
- for (m = s; m < strend && *m != i; m++) ;
- if (m >= strend)
- break;
- --- 420,436 ----
- int fold = (spat->spat_flags & SPAT_FOLD);
-
- i = *spat->spat_short->str_ptr;
- ! if (fold && isUPPER(i))
- i = tolower(i);
- while (--limit) {
- if (fold) {
- for ( m = s;
- m < strend && *m != i &&
- ! (!isUPPER(*m) || tolower(*m) != i);
- ! m++) /*SUPPRESS 530*/
- ;
- }
- ! else /*SUPPRESS 530*/
- for (m = s; m < strend && *m != i; m++) ;
- if (m >= strend)
- break;
- ***************
- *** 548,556 ****
- --- 567,581 ----
- short ashort;
- int aint;
- long along;
- + #ifdef QUAD
- + quad aquad;
- + #endif
- unsigned short aushort;
- unsigned int auint;
- unsigned long aulong;
- + #ifdef QUAD
- + unsigned quad auquad;
- + #endif
- char *aptr;
- float afloat;
- double adouble;
- ***************
- *** 559,568 ****
- double cdouble;
-
- if (gimme != G_ARRAY) { /* arrange to do first one only */
- ! for (patend = pat; !isalpha(*patend); patend++);
- if (index("aAbBhH", *patend) || *pat == '%') {
- patend++;
- ! while (isdigit(*patend) || *patend == '*')
- patend++;
- }
- else
- --- 584,594 ----
- double cdouble;
-
- if (gimme != G_ARRAY) { /* arrange to do first one only */
- ! /*SUPPRESS 530*/
- ! for (patend = pat; !isALPHA(*patend) || *patend == 'x'; patend++) ;
- if (index("aAbBhH", *patend) || *pat == '%') {
- patend++;
- ! while (isDIGIT(*patend) || *patend == '*')
- patend++;
- }
- else
- ***************
- *** 578,586 ****
- len = strend - strbeg; /* long enough */
- pat++;
- }
- ! else if (isdigit(*pat)) {
- len = *pat++ - '0';
- ! while (isdigit(*pat))
- len = (len * 10) + (*pat++ - '0');
- }
- else
- --- 604,612 ----
- len = strend - strbeg; /* long enough */
- pat++;
- }
- ! else if (isDIGIT(*pat)) {
- len = *pat++ - '0';
- ! while (isDIGIT(*pat))
- len = (len * 10) + (*pat++ - '0');
- }
- else
- ***************
- *** 624,630 ****
- if (datumtype == 'A') {
- aptr = s; /* borrow register */
- s = str->str_ptr + len - 1;
- ! while (s >= str->str_ptr && (!*s || (isascii(*s)&&isspace(*s))))
- s--;
- *++s = '\0';
- str->str_cur = s - str->str_ptr;
- --- 650,656 ----
- if (datumtype == 'A') {
- aptr = s; /* borrow register */
- s = str->str_ptr + len - 1;
- ! while (s >= str->str_ptr && (!*s || isSPACE(*s)))
- s--;
- *++s = '\0';
- str->str_cur = s - str->str_ptr;
- ***************
- *** 644,650 ****
- if (datumtype == 'b') {
- aint = len;
- for (len = 0; len < aint; len++) {
- ! if (len & 7)
- bits >>= 1;
- else
- bits = *s++;
- --- 670,676 ----
- if (datumtype == 'b') {
- aint = len;
- for (len = 0; len < aint; len++) {
- ! if (len & 7) /*SUPPRESS 595*/
- bits >>= 1;
- else
- bits = *s++;
- ***************
- *** 912,917 ****
- --- 938,971 ----
- (void)astore(stack, ++sp, str_2mortal(str));
- }
- break;
- + #ifdef QUAD
- + case 'q':
- + while (len-- > 0) {
- + if (s + sizeof(quad) > strend)
- + aquad = 0;
- + else {
- + bcopy(s,(char*)&aquad,sizeof(quad));
- + s += sizeof(quad);
- + }
- + str = Str_new(42,0);
- + str_numset(str,(double)aquad);
- + (void)astore(stack, ++sp, str_2mortal(str));
- + }
- + break;
- + case 'Q':
- + while (len-- > 0) {
- + if (s + sizeof(unsigned quad) > strend)
- + auquad = 0;
- + else {
- + bcopy(s,(char*)&auquad,sizeof(unsigned quad));
- + s += sizeof(unsigned quad);
- + }
- + str = Str_new(43,0);
- + str_numset(str,(double)auquad);
- + (void)astore(stack, ++sp, str_2mortal(str));
- + }
- + break;
- + #endif
- /* float and double added gnb@melba.bby.oz.au 22/11/89 */
- case 'f':
- case 'F':
- ***************
- *** 1158,1168 ****
- length = 0;
- }
- else
- ! length = ary->ary_max; /* close enough to infinity */
- }
- else {
- offset = 0;
- ! length = ary->ary_max;
- }
- if (offset < 0) {
- length += offset;
- --- 1212,1222 ----
- length = 0;
- }
- else
- ! length = ary->ary_max + 1; /* close enough to infinity */
- }
- else {
- offset = 0;
- ! length = ary->ary_max + 1;
- }
- if (offset < 0) {
- length += offset;
- ***************
- *** 1335,1342 ****
- }
- arg = arg[1].arg_ptr.arg_arg;
- while (i-- > 0) {
- ! if (st[src])
- stab_val(defstab) = st[src];
- else
- stab_val(defstab) = str_mortal(&str_undef);
- (void)eval(arg,G_SCALAR,sp);
- --- 1389,1398 ----
- }
- arg = arg[1].arg_ptr.arg_arg;
- while (i-- > 0) {
- ! if (st[src]) {
- ! st[src]->str_pok &= ~SP_TEMP;
- stab_val(defstab) = st[src];
- + }
- else
- stab_val(defstab) = str_mortal(&str_undef);
- (void)eval(arg,G_SCALAR,sp);
- ***************
- *** 1407,1415 ****
- static STAB *secondstab = Nullstab;
-
- int
- ! do_sort(str,stab,gimme,arglast)
- STR *str;
- ! STAB *stab;
- int gimme;
- int *arglast;
- {
- --- 1463,1471 ----
- static STAB *secondstab = Nullstab;
-
- int
- ! do_sort(str,arg,gimme,arglast)
- STR *str;
- ! ARG *arg;
- int gimme;
- int *arglast;
- {
- ***************
- *** 1423,1428 ****
- --- 1479,1485 ----
- STR *oldfirst;
- STR *oldsecond;
- ARRAY *oldstack;
- + HASH *stash;
- static ARRAY *sortstack = Null(ARRAY*);
-
- if (gimme != G_ARRAY) {
- ***************
- *** 1434,1439 ****
- --- 1491,1497 ----
- up = &st[sp];
- st += sp; /* temporarily make st point to args */
- for (i = 1; i <= max; i++) {
- + /*SUPPRESS 560*/
- if (*up = st[i]) {
- if (!(*up)->str_pok)
- (void)str_2ptr(*up);
- ***************
- *** 1446,1456 ****
- max = up - &st[sp];
- sp--;
- if (max > 1) {
- ! if (stab) {
- int oldtmps_base = tmps_base;
-
- - if (!stab_sub(stab) || !(sortcmd = stab_sub(stab)->cmd))
- - fatal("Undefined subroutine \"%s\" in sort", stab_name(stab));
- if (!sortstack) {
- sortstack = anew(Nullstab);
- astore(sortstack, 0, Nullstr);
- --- 1504,1534 ----
- max = up - &st[sp];
- sp--;
- if (max > 1) {
- ! STAB *stab;
- !
- ! if (arg[1].arg_type == (A_CMD|A_DONT)) {
- ! sortcmd = arg[1].arg_ptr.arg_cmd;
- ! stash = curcmd->c_stash;
- ! }
- ! else {
- ! if ((arg[1].arg_type & A_MASK) == A_WORD)
- ! stab = arg[1].arg_ptr.arg_stab;
- ! else
- ! stab = stabent(str_get(st[sp+1]),TRUE);
- !
- ! if (stab) {
- ! if (!stab_sub(stab) || !(sortcmd = stab_sub(stab)->cmd))
- ! fatal("Undefined subroutine \"%s\" in sort",
- ! stab_name(stab));
- ! stash = stab_stash(stab);
- ! }
- ! else
- ! sortcmd = Nullcmd;
- ! }
- !
- ! if (sortcmd) {
- int oldtmps_base = tmps_base;
-
- if (!sortstack) {
- sortstack = anew(Nullstab);
- astore(sortstack, 0, Nullstr);
- ***************
- *** 1460,1469 ****
- oldstack = stack;
- stack = sortstack;
- tmps_base = tmps_max;
- ! if (sortstash != stab_stash(stab)) {
- firststab = stabent("a",TRUE);
- secondstab = stabent("b",TRUE);
- ! sortstash = stab_stash(stab);
- }
- oldfirst = stab_val(firststab);
- oldsecond = stab_val(secondstab);
- --- 1538,1547 ----
- oldstack = stack;
- stack = sortstack;
- tmps_base = tmps_max;
- ! if (sortstash != stash) {
- firststab = stabent("a",TRUE);
- secondstab = stabent("b",TRUE);
- ! sortstash = stash;
- }
- oldfirst = stab_val(firststab);
- oldsecond = stab_val(secondstab);
- ***************
- *** 1505,1515 ****
- --- 1583,1595 ----
- int retval;
-
- if (str1->str_cur < str2->str_cur) {
- + /*SUPPRESS 560*/
- if (retval = memcmp(str1->str_ptr, str2->str_ptr, str1->str_cur))
- return retval;
- else
- return -1;
- }
- + /*SUPPRESS 560*/
- else if (retval = memcmp(str1->str_ptr, str2->str_ptr, str2->str_cur))
- return retval;
- else if (str1->str_cur == str2->str_cur)
- ***************
- *** 1537,1542 ****
- --- 1617,1624 ----
- (looks_like_number(st[sp+1]) && *st[sp+1]->str_ptr != '0') ) {
- i = (int)str_gnum(st[sp+1]);
- max = (int)str_gnum(st[sp+2]);
- + if (max > i)
- + (void)astore(ary, sp + max - i + 1, Nullstr);
- while (i <= max) {
- (void)astore(ary, ++sp, str = str_mortal(&str_no));
- str_numset(str,(double)i++);
- ***************
- *** 1567,1573 ****
- register int sp = arglast[0];
- register int items = arglast[1] - sp;
- register int count = (int) str_gnum(st[arglast[2]]);
- - register ARRAY *ary = stack;
- register int i;
- int max;
-
- --- 1649,1654 ----
- ***************
- *** 1639,1645 ****
- str_2mortal(str_nmake((double)csv->wantarray)) );
- if (csv->hasargs) {
- ARRAY *ary = csv->argarray;
- - STAB *tmpstab;
-
- if (!dbargs)
- dbargs = stab_xarray(aadd(stabent("DB'args", TRUE)));
- --- 1720,1725 ----
- ***************
- *** 1750,1755 ****
- --- 1830,1836 ----
- return sp;
- }
- (void)hiterinit(hash);
- + /*SUPPRESS 560*/
- while (entry = hiternext(hash)) {
- if (dokeys) {
- tmps = hiterkey(entry,&i);
-
- Index: eval.c
- *** eval.c.old Tue Nov 5 19:26:12 1991
- --- eval.c Tue Nov 5 19:26:13 1991
- ***************
- *** 1,4 ****
- ! /* $RCSfile: eval.c,v $$Revision: 4.0.1.2 $$Date: 91/06/07 11:07:23 $
- *
- * Copyright (c) 1991, Larry Wall
- *
- --- 1,4 ----
- ! /* $RCSfile: eval.c,v $$Revision: 4.0.1.3 $$Date: 91/11/05 17:15:21 $
- *
- * Copyright (c) 1991, Larry Wall
- *
- ***************
- *** 6,11 ****
- --- 6,21 ----
- * License or the Artistic License, as specified in the README file.
- *
- * $Log: eval.c,v $
- + * Revision 4.0.1.3 91/11/05 17:15:21 lwall
- + * patch11: prepared for ctype implementations that don't define isascii()
- + * patch11: various portability fixes
- + * patch11: added sort {} LIST
- + * patch11: added eval {}
- + * patch11: sysread() in socket was substituting recv()
- + * patch11: a last statement outside any block caused occasional core dumps
- + * patch11: missing arguments caused core dump in -D8 code
- + * patch11: eval 'stuff' now optimized to eval {stuff}
- + *
- * Revision 4.0.1.2 91/06/07 11:07:23 lwall
- * patch4: new copyright notice
- * patch4: length($`), length($&), length($') now optimized to avoid string copy
- ***************
- *** 326,331 ****
- --- 336,342 ----
- if (fp) {
- if (gimme == G_SCALAR) {
- while (str_gets(str,fp,str->str_cur) != Nullch)
- + /*SUPPRESS 530*/
- ;
- }
- else {
- ***************
- *** 490,496 ****
- else
- str->str_cur++;
- for (tmps = str->str_ptr; *tmps; tmps++)
- ! if (!isalpha(*tmps) && !isdigit(*tmps) &&
- index("$&*(){}[]'\";\\|?<>~`",*tmps))
- break;
- if (*tmps && stat(str->str_ptr,&statbuf) < 0)
- --- 501,507 ----
- else
- str->str_cur++;
- for (tmps = str->str_ptr; *tmps; tmps++)
- ! if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
- index("$&*(){}[]'\";\\|?<>~`",*tmps))
- break;
- if (*tmps && stat(str->str_ptr,&statbuf) < 0)
- ***************
- *** 694,700 ****
- case O_DIVIDE:
- if ((value = str_gnum(st[2])) == 0.0)
- fatal("Illegal division by zero");
- ! #ifdef cray
- /* insure that 20./5. == 4. */
- {
- double x;
- --- 705,711 ----
- case O_DIVIDE:
- if ((value = str_gnum(st[2])) == 0.0)
- fatal("Illegal division by zero");
- ! #ifdef SLOPPYDIVIDE
- /* insure that 20./5. == 4. */
- {
- double x;
- ***************
- *** 884,890 ****
- --- 895,905 ----
- value = -str_gnum(st[1]);
- goto donumset;
- case O_NOT:
- + #ifdef NOTNOT
- + { char xxx = str_true(st[1]); value = (double) !xxx; }
- + #else
- value = (double) !str_true(st[1]);
- + #endif
- goto donumset;
- case O_COMPLEMENT:
- if (!sawvec || st[1]->str_nok) {
- ***************
- *** 1179,1184 ****
- --- 1194,1200 ----
- case O_SUBSTR:
- anum = ((int)str_gnum(st[2])) - arybase; /* anum=where to start*/
- tmps = str_get(st[1]); /* force conversion to string */
- + /*SUPPRESS 560*/
- if (argtype = (str == st[1]))
- str = arg->arg_ptr.arg_str;
- if (anum < 0)
- ***************
- *** 1204,1209 ****
- --- 1220,1226 ----
- }
- break;
- case O_PACK:
- + /*SUPPRESS 701*/
- (void)do_pack(str,arglast);
- break;
- case O_GREP:
- ***************
- *** 1253,1263 ****
- st = stack->ary_array + arglast[0]; /* maybe realloced */
- goto array_return;
- case O_SORT:
- ! if ((arg[1].arg_type & A_MASK) == A_WORD)
- ! stab = arg[1].arg_ptr.arg_stab;
- ! else
- ! stab = stabent(str_get(st[1]),TRUE);
- ! sp = do_sort(str,stab,
- gimme,arglast);
- goto array_return;
- case O_REVERSE:
- --- 1270,1276 ----
- st = stack->ary_array + arglast[0]; /* maybe realloced */
- goto array_return;
- case O_SORT:
- ! sp = do_sort(str,arg,
- gimme,arglast);
- goto array_return;
- case O_REVERSE:
- ***************
- *** 1451,1456 ****
- --- 1464,1473 ----
- goto badsock;
- #endif
- STR_GROW(st[2], anum+maxarg+1), (tmps = str_get(st[2])); /* sneaky */
- + if (optype == O_SYSREAD) {
- + anum = read(fileno(stab_io(stab)->ifp), tmps+maxarg, anum);
- + }
- + else
- #ifdef HAS_SOCKET
- if (stab_io(stab)->type == 's') {
- argtype = sizeof buf;
- ***************
- *** 1459,1468 ****
- }
- else
- #endif
- - if (optype == O_SYSREAD) {
- - anum = read(fileno(stab_io(stab)->ifp), tmps+maxarg, anum);
- - }
- - else
- anum = fread(tmps+maxarg, 1, anum, stab_io(stab)->ifp);
- if (anum < 0)
- goto say_undef;
- --- 1476,1481 ----
- ***************
- *** 1541,1546 ****
- --- 1554,1560 ----
- case O_REDO:
- case O_NEXT:
- case O_LAST:
- + tmps = Nullch;
- if (maxarg > 0) {
- tmps = str_get(arg[1].arg_ptr.arg_str);
- dopop:
- ***************
- *** 1887,1895 ****
- if (anum < 0)
- goto say_undef;
- if (!anum) {
- if (tmpstab = stabent("$",allstabs))
- str_numset(STAB_STR(tmpstab),(double)getpid());
- ! hclear(pidstatus); /* no kids, so don't wait for 'em */
- }
- value = (double)anum;
- goto donumset;
- --- 1901,1910 ----
- if (anum < 0)
- goto say_undef;
- if (!anum) {
- + /*SUPPRESS 560*/
- if (tmpstab = stabent("$",allstabs))
- str_numset(STAB_STR(tmpstab),(double)getpid());
- ! hclear(pidstatus, FALSE); /* no kids, so don't wait for 'em */
- }
- value = (double)anum;
- goto donumset;
- ***************
- *** 2005,2011 ****
- tmps = str_get(stab_val(defstab));
- else
- tmps = str_get(st[1]);
- ! while (*tmps && isascii(*tmps) && (isspace(*tmps) || *tmps == '0'))
- tmps++;
- if (*tmps == 'x')
- value = (double)scanhex(++tmps, 99, &argtype);
- --- 2020,2026 ----
- tmps = str_get(stab_val(defstab));
- else
- tmps = str_get(st[1]);
- ! while (*tmps && (isSPACE(*tmps) || *tmps == '0'))
- tmps++;
- if (*tmps == 'x')
- value = (double)scanhex(++tmps, 99, &argtype);
- ***************
- *** 2014,2020 ****
- goto donumset;
-
- /* These common exits are hidden here in the middle of the switches for the
- ! /* benefit of those machines with limited branch addressing. Sigh. */
-
- array_return:
- #ifdef DEBUGGING
- --- 2029,2035 ----
- goto donumset;
-
- /* These common exits are hidden here in the middle of the switches for the
- ! benefit of those machines with limited branch addressing. Sigh. */
-
- array_return:
- #ifdef DEBUGGING
- ***************
- *** 2027,2038 ****
- deb("%s RETURNS ()\n",opname[optype]);
- break;
- case 1:
- ! deb("%s RETURNS (\"%s\")\n",opname[optype],str_get(st[1]));
- break;
- default:
- ! tmps = str_get(st[1]);
- deb("%s RETURNS %d ARGS (\"%s\",%s\"%s\")\n",opname[optype],
- ! anum,tmps,anum==2?"":"...,",str_get(st[anum]));
- break;
- }
- }
- --- 2042,2055 ----
- deb("%s RETURNS ()\n",opname[optype]);
- break;
- case 1:
- ! deb("%s RETURNS (\"%s\")\n",opname[optype],
- ! st[1] ? str_get(st[1]) : "");
- break;
- default:
- ! tmps = st[1] ? str_get(st[1]) : "";
- deb("%s RETURNS %d ARGS (\"%s\",%s\"%s\")\n",opname[optype],
- ! anum,tmps,anum==2?"":"...,",
- ! st[anum] ? str_get(st[anum]) : "");
- break;
- }
- }
- ***************
- *** 2410,2415 ****
- --- 2427,2448 ----
- value = (double)(ary->ary_fill + 1);
- goto donumset;
-
- + case O_TRY:
- + sp = do_try(arg[1].arg_ptr.arg_cmd,
- + gimme,arglast);
- + goto array_return;
- +
- + case O_EVALONCE:
- + sp = do_eval(st[1], O_EVAL, curcmd->c_stash, TRUE,
- + gimme,arglast);
- + if (eval_root) {
- + str_free(arg[1].arg_ptr.arg_str);
- + arg[1].arg_ptr.arg_cmd = eval_root;
- + arg[1].arg_type = (A_CMD|A_DONT);
- + arg[0].arg_type = O_TRY;
- + }
- + goto array_return;
- +
- case O_REQUIRE:
- case O_DOFILE:
- case O_EVAL:
- ***************
- *** 2422,2428 ****
- tainted |= tmpstr->str_tainted;
- taintproper("Insecure dependency in eval");
- #endif
- ! sp = do_eval(tmpstr, optype, curcmd->c_stash,
- gimme,arglast);
- goto array_return;
-
- --- 2455,2461 ----
- tainted |= tmpstr->str_tainted;
- taintproper("Insecure dependency in eval");
- #endif
- ! sp = do_eval(tmpstr, optype, curcmd->c_stash, FALSE,
- gimme,arglast);
- goto array_return;
-
- ***************
- *** 2598,2604 ****
- stab = stabent(tmps = str_get(st[1]),FALSE);
- if (stab && stab_io(stab) && stab_io(stab)->ifp)
- anum = fileno(stab_io(stab)->ifp);
- ! else if (isdigit(*tmps))
- anum = atoi(tmps);
- else
- goto say_undef;
- --- 2631,2637 ----
- stab = stabent(tmps = str_get(st[1]),FALSE);
- if (stab && stab_io(stab) && stab_io(stab)->ifp)
- anum = fileno(stab_io(stab)->ifp);
- ! else if (isDIGIT(*tmps))
- anum = atoi(tmps);
- else
- goto say_undef;
-
- Index: t/op/eval.t
- Prereq: 4.0
- *** t/op/eval.t.old Tue Nov 5 19:28:02 1991
- --- t/op/eval.t Tue Nov 5 19:28:02 1991
- ***************
- *** 1,8 ****
- #!./perl
-
- ! # $Header: eval.t,v 4.0 91/03/20 01:52:20 lwall Locked $
-
- ! print "1..10\n";
-
- eval 'print "ok 1\n";';
-
- --- 1,8 ----
- #!./perl
-
- ! # $RCSfile: eval.t,v $$Revision: 4.0.1.1 $$Date: 91/11/05 18:43:19 $
-
- ! print "1..16\n";
-
- eval 'print "ok 1\n";';
-
- ***************
- *** 40,42 ****
- --- 40,57 ----
- close try;
-
- do 'Op.eval'; print $@;
- +
- + # Test the singlequoted eval optimizer
- +
- + $i = 11;
- + for (1..3) {
- + eval 'print "ok ", $i++, "\n"';
- + }
- +
- + eval {
- + print "ok 14\n";
- + die "ok 16\n";
- + 1;
- + } || print "ok 15\n$@";
- +
- +
-
- Index: lib/exceptions.pl
- *** lib/exceptions.pl.old Tue Nov 5 19:26:56 1991
- --- lib/exceptions.pl Tue Nov 5 19:26:56 1991
- ***************
- *** 0 ****
- --- 1,54 ----
- + # exceptions.pl
- + # tchrist@convex.com
- + #
- + # Here's a little code I use for exception handling. It's really just
- + # glorfied eval/die. The way to use use it is when you might otherwise
- + # exit, use &throw to raise an exception. The first enclosing &catch
- + # handler looks at the exception and decides whether it can catch this kind
- + # (catch takes a list of regexps to catch), and if so, it returns the one it
- + # caught. If it *can't* catch it, then it will reraise the exception
- + # for someone else to possibly see, or to die otherwise.
- + #
- + # I use oddly named variables in order to make darn sure I don't conflict
- + # with my caller. I also hide in my own package, and eval the code in his.
- + #
- + # The EXCEPTION: prefix is so you can tell whether it's a user-raised
- + # exception or a perl-raised one (eval error).
- + #
- + # --tom
- + #
- + # examples:
- + # if (&catch('/$user_input/', 'regexp', 'syntax error') {
- + # warn "oops try again";
- + # redo;
- + # }
- + #
- + # if ($error = &catch('&subroutine()')) { # catches anything
- + #
- + # &throw('bad input') if /^$/;
- +
- + sub catch {
- + package exception;
- + local($__code__, @__exceptions__) = @_;
- + local($__package__) = caller;
- + local($__exception__);
- +
- + eval "package $__package__; $__code__";
- + if ($__exception__ = &'thrown) {
- + for (@__exceptions__) {
- + return $__exception__ if /$__exception__/;
- + }
- + &'throw($__exception__);
- + }
- + }
- +
- + sub throw {
- + local($exception) = @_;
- + die "EXCEPTION: $exception\n";
- + }
- +
- + sub thrown {
- + $@ =~ /^(EXCEPTION: )+(.+)/ && $2;
- + }
- +
- + 1;
-
- Index: lib/fastcwd.pl
- *** lib/fastcwd.pl.old Tue Nov 5 19:26:57 1991
- --- lib/fastcwd.pl Tue Nov 5 19:26:58 1991
- ***************
- *** 0 ****
- --- 1,35 ----
- + # By John Bazik
- + #
- + # Usage: $cwd = &fastcwd;
- + #
- + # This is a faster version of getcwd. It's also more dangerous because
- + # you might chdir out of a directory that you can't chdir back into.
- +
- + sub fastcwd {
- + local($odev, $oino, $cdev, $cino, $tdev, $tino);
- + local(@path, $path);
- + local(*DIR);
- +
- + ($cdev, $cino) = stat('.');
- + for (;;) {
- + ($odev, $oino) = ($cdev, $cino);
- + chdir('..');
- + ($cdev, $cino) = stat('.');
- + last if $odev == $cdev && $oino == $cino;
- + opendir(DIR, '.');
- + for (;;) {
- + $_ = readdir(DIR);
- + next if $_ eq '.';
- + next if $_ eq '..';
- +
- + last unless $_;
- + ($tdev, $tino) = lstat($_);
- + last unless $tdev != $odev || $tino != $oino;
- + }
- + closedir(DIR);
- + unshift(@path, $_);
- + }
- + chdir($path = '/' . join('/', @path));
- + $path;
- + }
- + 1;
-
- Index: x2p/find2perl.SH
- *** x2p/find2perl.SH.old Tue Nov 5 19:28:35 1991
- --- x2p/find2perl.SH Tue Nov 5 19:28:36 1991
- ***************
- *** 96,102 ****
- }
- elsif ($_ eq 'group') {
- $gname = shift;
- ! $out .= &tab . "\$gid == \$gid('$gname')";
- $initgroup++;
- }
- elsif ($_ eq 'nouser') {
- --- 96,102 ----
- }
- elsif ($_ eq 'group') {
- $gname = shift;
- ! $out .= &tab . "\$gid == \$gid{'$gname'}";
- $initgroup++;
- }
- elsif ($_ eq 'nouser') {
- ***************
- *** 381,387 ****
- ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
- $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
- if (-f _) {
- ! open(IN, $_) || do {
- warn "Couldn't open $name: $!\n";
- return;
- };
- --- 381,387 ----
- ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
- $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
- if (-f _) {
- ! open(IN, "./$_\0") || do {
- warn "Couldn't open $name: $!\n";
- return;
- };
- ***************
- *** 471,477 ****
- }
- }
- if (-f _) {
- ! open(IN, $_) || do {
- warn "Couldn't open $name: $!\n";
- return;
- };
- --- 471,477 ----
- }
- }
- if (-f _) {
- ! open(IN, "./$_\0") || do {
- warn "Couldn't open $name: $!\n";
- return;
- };
-
- *** End of Patch 14 ***
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-