From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23970 invoked from network); 17 Dec 2001 21:15:49 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 17 Dec 2001 21:15:49 -0000 Received: (qmail 24074 invoked by alias); 17 Dec 2001 21:15:43 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16360 Received: (qmail 24063 invoked from network); 17 Dec 2001 21:15:42 -0000 Message-ID: From: JohnW@bops.com To: zsh-workers@sunsite.dk Subject: PATCH: fix for autoloading and compiling under Cygwin Date: Mon, 17 Dec 2001 15:15:05 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C1873F.E607E110" This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C1873F.E607E110 Content-Type: text/plain; charset="iso-8859-1" I was actually overlooking writing of zwc files in my first fix. Here's a new patch that really fixes the problem, with a test case, too. I've done two things here: * I added the O_BINARY flag to all calls to 'open' on zwc files. * For text files, I changed the code to treat the result of 'seek' as an upper bound on the length of the file. For the actual length, the return value of 'read' is used. Checks that 'seek' and 'read' return the same thing have been changed to check that 'seek' and 'read' both return nonnegative values. -----Original Message----- From: Borsenkow Andrej [mailto:Andrej.Borsenkow@mow.siemens.ru] Sent: Monday, December 17, 2001 8:43 AM To: 'Zsh hackers list' Cc: JohnW@bops.com Subject: RE: forward: fix for problem under cygwin > > I found a Unixism in zsh that prevents autoloading and function compilation > from working under cygwin. There are several bits of code that assume > character offsets are the same as byte offsets in files. I've fixed this by > either opening files in binary mode or relaxing the error checking. No. We must never assume files are DOS text files because it makes them non-portable not only between Cygwin/Unix but even between two different Cygwin instances (just think about remounting the same directory in binary mode after creating file in text mode). We must ensure that read/write of zwc files always happens in binary mode. This will make it possible to share files between Cygwin/Unix as well. Your patch has several O_BINARY for reading but I do not see O_BINARY for writing. Of course, after doing it one probably has to recreate zwc files to be sure. -andrej ------_=_NextPart_000_01C1873F.E607E110 Content-Type: application/octet-stream; name="zsh-patch.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="zsh-patch.diff" Only in zsh-4.0.4-patched/Config: defs.mk Only in zsh-4.0.4-patched/Doc: Makefile Only in zsh-4.0.4/Etc: .zsh-development-guide.swp Only in zsh-4.0.4-patched/Etc: Makefile Only in zsh-4.0.4-patched: Makefile Only in zsh-4.0.4-patched/Src: .parse.c.swp Only in zsh-4.0.4-patched/Src/Builtins: Makefile Only in zsh-4.0.4-patched/Src/Builtins: Makefile.in Only in zsh-4.0.4-patched/Src: Makefile Only in zsh-4.0.4-patched/Src: Makemod Only in zsh-4.0.4-patched/Src: Makemod.in Only in zsh-4.0.4-patched/Src/Modules: Makefile Only in zsh-4.0.4-patched/Src/Modules: Makefile.in Only in zsh-4.0.4-patched/Src/Modules: cap.exp Only in zsh-4.0.4-patched/Src/Zle: Makefile Only in zsh-4.0.4-patched/Src/Zle: Makefile.in diff -ur zsh-4.0.4/Src/exec.c zsh-4.0.4-patched/Src/exec.c --- zsh-4.0.4/Src/exec.c Wed Oct 24 06:16:32 2001 +++ zsh-4.0.4-patched/Src/exec.c Mon Dec 10 13:33:48 2001 @@ -3470,7 +3470,7 @@ getfpfunc(char *s, int *ksh) { char **pp, buf[PATH_MAX]; - off_t len; + off_t len, textlen; char *d; Eprog r; int fd; @@ -3490,12 +3490,12 @@ if ((len =3D lseek(fd, 0, 2)) !=3D -1) { d =3D (char *) zalloc(len + 1); lseek(fd, 0, 0); - if (read(fd, d, len) =3D=3D len) { + if ((textlen =3D read(fd, d, len)) >=3D 0) { char *oldscriptname =3D scriptname; =20 close(fd); - d[len] =3D '\0'; - d =3D metafy(d, len, META_REALLOC); + d[textlen] =3D '\0'; + d =3D metafy(d, textlen, META_REALLOC); =20 scriptname =3D dupstring(s); r =3D parse_string(d, 1); diff -ur zsh-4.0.4/Src/parse.c zsh-4.0.4-patched/Src/parse.c --- zsh-4.0.4/Src/parse.c Wed Oct 24 06:16:32 2001 +++ zsh-4.0.4-patched/Src/parse.c Mon Dec 17 12:30:00 2001 @@ -2405,7 +2405,7 @@ int fd, v =3D 0; wordcode buf[FD_PRELEN + 1]; =20 - if ((fd =3D open(name, O_RDONLY)) < 0) { + if ((fd =3D open(name, O_RDONLY | O_BINARY)) < 0) { if (err) zwarnnam(nam, "can't open zwc file: %s", name, 0); return NULL; @@ -2542,7 +2542,7 @@ static int build_dump(char *nam, char *dump, char **files, int ali, int map, int = flags) { - int dfd, fd, hlen, tlen, flen, ona =3D noaliases; + int dfd, fd, hlen, tlen, flen, ona =3D noaliases, textlen; LinkList progs; char *file; Eprog prog; @@ -2551,7 +2551,7 @@ if (!strsfx(FD_EXT, dump)) dump =3D dyncat(dump, FD_EXT); =20 - if ((dfd =3D open(dump, O_WRONLY|O_CREAT, 0600)) < 0) { + if ((dfd =3D open(dump, O_WRONLY|O_CREAT|O_BINARY, 0600)) < 0) { zwarnnam(nam, "can't write zwc file: %s", dump, 0); return 1; } @@ -2577,9 +2577,8 @@ return 1; } file =3D (char *) zalloc(flen + 1); - file[flen] =3D '\0'; lseek(fd, 0, 0); - if (read(fd, file, flen) !=3D flen) { + if ((textlen =3D read(fd, file, flen)) < 0) { close(fd); close(dfd); zfree(file, flen); @@ -2589,7 +2588,8 @@ return 1; } close(fd); - file =3D metafy(file, flen, META_REALLOC); + file[textlen] =3D '\0'; + file =3D metafy(file, textlen, META_REALLOC); =20 if (!(prog =3D parse_string(file, 1)) || errflag) { errflag =3D 0; @@ -2682,7 +2682,7 @@ if (!strsfx(FD_EXT, dump)) dump =3D dyncat(dump, FD_EXT); =20 - if ((dfd =3D open(dump, O_WRONLY|O_CREAT, 0600)) < 0) { + if ((dfd =3D open(dump, O_WRONLY|O_CREAT|O_BINARY, 0600)) < 0) { zwarnnam(nam, "can't write zwc file: %s", dump, 0); return 1; } @@ -2814,7 +2814,7 @@ off =3D 0; mlen =3D len; } - if ((fd =3D open(dump, O_RDONLY)) < 0) + if ((fd =3D open(dump, O_RDONLY | O_BINARY)) < 0) return; =20 fd =3D movefd(fd); @@ -3014,7 +3014,7 @@ Patprog *pp; int np, fd, po =3D h->npats * sizeof(Patprog); =20 - if ((fd =3D open(file, O_RDONLY)) < 0 || + if ((fd =3D open(file, O_RDONLY | O_BINARY)) < 0 || lseek(fd, ((h->start * sizeof(wordcode)) + ((fdflags(d) & FDF_OTHER) ? fdother(d) : 0)), 0) < 0) { if (fd >=3D 0) Only in zsh-4.0.4-patched/Test: Makefile Only in zsh-4.0.4-patched: config.cache Only in zsh-4.0.4-patched: config.h Only in zsh-4.0.4-patched: config.log Only in zsh-4.0.4-patched: config.modules Only in zsh-4.0.4-patched: config.status Only in zsh-4.0.4-patched: conftest1.c Only in zsh-4.0.4-patched: conftest1.o Only in zsh-4.0.4-patched: conftest2.c Only in zsh-4.0.4-patched: stamp-h Only in zsh-4.0.4-patched: tags ------_=_NextPart_000_01C1873F.E607E110 Content-Type: application/octet-stream; name="A06autoload.ztst" Content-Disposition: attachment; filename="A06autoload.ztst" %prep mkdir func.tmp echo 'echo zinit; function zfunc() { echo zeval }' >func.tmp/zfunc echo 'echo kinit; function kfunc() { echo keval }' >func.tmp/kfunc echo 'echo eval' >func.tmp/script echo 'echo cinit; compiled() { echo ceval };' >func.tmp/compiled fpath=(func.tmp) %test autoload +X -z zfunc script 0q:zsh-style autoloading autoload +X -k kfunc 0q:ksh-style autoloading zfunc 0q:Only initialization code is executed. >zinit zfunc 0q:Only the function definition is executed. >zeval kfunc 0q:The function is initialized and called. >kinit >keval kfunc 0q:Only the function definition is executed. >keval script 0q:The whole file is executed. >eval zcompile func.tmp/compiled 0q:A file can be compiled. autoload -w func.tmp/compiled 0q:A compiled file can be autoloaded. compiled 0q:A function from a compiled file can be called. >cinit compiled 0q:A compiled function is not re-initialized. >ceval %clean ------_=_NextPart_000_01C1873F.E607E110--