From: "Jun. T" <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: ZSH performance regression in 5.8.1.2-test
Date: Fri, 29 Apr 2022 03:51:28 +0900 [thread overview]
Message-ID: <E6EFC8B2-D153-40C5-948C-066BFE4CAC1A@kba.biglobe.ne.jp> (raw)
In-Reply-To: <CAHDOzW5iJ2UJ7yKOs08knymPFkT-cursD2_y79KRYkWVepbHLw@mail.gmail.com>
> 2022/04/28 4:54, Jordan Patterson <jordanp@gmail.com> wrote:
>
> I needed to add a mode argument to the open in your lseek
> configure check.
Added S_IRUSR to open(), and include <sys/stat.h> for it.
I reproduce the whole patch here for convenience.
Tested on Fedora-35, macOS, FreeBSD and Cygwin.
diff --git a/Src/input.c b/Src/input.c
index c59232681..9898a7177 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -217,12 +217,34 @@ shinbufrestore(void)
static int
shingetchar(void)
{
- int nread;
+ int nread, rsize = isset(SHINSTDIN) ? 1 : SHINBUFSIZE;
if (shinbufptr < shinbufendptr)
return STOUC(*shinbufptr++);
shinbufreset();
+#ifdef USE_LSEEK
+ if (rsize == 1 && lseek(SHIN, 0, SEEK_CUR) != (off_t)-1)
+ rsize = SHINBUFSIZE;
+ if (rsize > 1) {
+ do {
+ errno = 0;
+ nread = read(SHIN, shinbuffer, rsize);
+ } while (nread < 0 && errno == EINTR);
+ if (nread <= 0)
+ return -1;
+ if (isset(SHINSTDIN) &&
+ (shinbufendptr = memchr(shinbuffer, '\n', nread))) {
+ shinbufendptr++;
+ rsize = (shinbufendptr - shinbuffer);
+ if (nread > rsize &&
+ lseek(SHIN, -(nread - rsize), SEEK_CUR) < 0)
+ zerr("lseek(%d, %d): %e", SHIN, -(nread - rsize), errno);
+ } else
+ shinbufendptr = shinbuffer + nread;
+ return STOUC(*shinbufptr++);
+ }
+#endif
for (;;) {
errno = 0;
nread = read(SHIN, shinbufendptr, 1);
diff --git a/configure.ac b/configure.ac
index 8bba78c56..c72148d06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2209,6 +2209,65 @@ if test x$zsh_cv_sys_fifo = xyes; then
AC_DEFINE(HAVE_FIFOS)
fi
+dnl -----------
+dnl check that lseek() correctly reports seekability.
+dnl -----------
+AC_CACHE_CHECK(if lseek() correctly reports seekability,
+zsh_cv_sys_lseek,
+[AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+int main() {
+ int pipefd[2], fd;
+ off_t ret;
+ char* tmpfile = "seekfiletest.tmp";
+ if ((fd = open(tmpfile, O_CREAT, S_IRUSR)) < 0) {
+ fprintf(stderr, "creating file failed\n");
+ return 1;
+ }
+ ret = lseek(fd, 0, SEEK_CUR);
+ close(fd);
+ unlink(tmpfile);
+ if (ret == (off_t)-1) {
+ fprintf(stderr, "lseek on regular file failed\n");
+ return 1;
+ }
+ if (pipe(pipefd) < 0) {
+ fprintf(stderr, "creating pipe failed\n");
+ return 1;
+ }
+ write(pipefd[1], "abcdefgh", 8);
+ ret = lseek(pipefd[0], 0, SEEK_CUR);
+ close(pipefd[0]);
+ close(pipefd[1]);
+ if (ret != (off_t)-1) {
+ fprintf(stderr, "lseek on pipe succeeded\n");
+ return 1;
+ }
+ if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ fprintf(stderr, "creating UNIX domain socket failed\n");
+ return 1;
+ }
+ ret = lseek(fd, 0, SEEK_CUR);
+ close(fd);
+ if (ret != (off_t)-1) {
+ fprintf(stderr, "lseek on UNIX domain socket succeeded\n");
+ return 1;
+ }
+ return 0;
+}
+]])],[zsh_cv_sys_lseek=yes],[zsh_cv_sys_lseek=no],[zsh_cv_sys_lseek=yes])
+])
+AH_TEMPLATE([USE_LSEEK],
+[Define to 1 if lseek() can be used for SHIN.])
+if test x$zsh_cv_sys_lseek = xyes; then
+ AC_DEFINE(USE_LSEEK)
+fi
+
dnl -----------
dnl test for whether link() works
dnl for instance, BeOS R4.51 doesn't support hard links yet
next prev parent reply other threads:[~2022-04-28 18:52 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-25 18:16 Jordan Patterson
2022-04-25 18:56 ` Bart Schaefer
2022-04-25 19:20 ` Stephane Chazelas
2022-04-25 21:27 ` Bart Schaefer
2022-04-26 7:01 ` Bart Schaefer
2022-04-26 8:31 ` Peter Stephenson
2022-04-27 0:33 ` Bart Schaefer
2022-04-27 14:11 ` Stephane Chazelas
2022-04-27 15:02 ` Bart Schaefer
2022-04-27 15:07 ` Peter Stephenson
2022-04-27 15:17 ` Bart Schaefer
2022-04-26 14:31 ` Jun. T
2022-04-26 15:15 ` Peter Stephenson
2022-04-27 0:55 ` Bart Schaefer
2022-04-27 9:16 ` Jun T
2022-04-27 0:38 ` Bart Schaefer
2022-04-27 9:34 ` Peter Stephenson
2022-04-27 10:28 ` Jun T
2022-04-27 12:42 ` Jun T
2022-04-27 13:58 ` Jun T
2022-04-27 15:25 ` Bart Schaefer
2022-04-27 16:18 ` Jun. T
2022-04-27 19:54 ` Jordan Patterson
2022-04-28 9:53 ` Jun T
2022-04-28 14:56 ` Bart Schaefer
2022-04-28 18:51 ` Jun. T [this message]
2022-04-29 0:28 ` Bart Schaefer
2022-04-29 2:25 ` Jun. T
2022-04-26 1:08 ` Bart Schaefer
2022-04-26 3:03 ` Jordan Patterson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E6EFC8B2-D153-40C5-948C-066BFE4CAC1A@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).