Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Zle goes through select() quickly growin # of times



The forgotten debug prints patch, attached. First file count.txt is
just a proof that I'm not making this up ;)

On 17 June 2018 at 22:23, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> Hello,
> I'm debugging the reason why Ctrl-C can be ignored. U stumbled upon this:
>
> 1. I open shell, enter "ls ", then press Ctrl-C
> 2. Debug logs from before "< master Zle select()" and after "> master
> Zle select()" occur
> 3. At first Ctrl-C, there are 24 select() recurrent code execution
> paths – the logs around select() are triggered ~24 times.
> 4. At second "ls <Ctrl-C>", there are 96 recurrent code paths.
> 5. At third "ls <Ctrl-C>, there are 197 recurrent code paths.
>
> The logs are:
>
> BASIC < select Before: selret: 0, errflag: 0, retflag: 0, breaks: 0,
> exit_pending: 0
> BASIC > select After: selret: 0, errflag: 0, retflag: 0, breaks: 0,
> exit_pending: 0
>
> two lines, installed before master select() (first line) and after the
> master select (second line).
>
> Could it be that Zsh reacts in this way after occurring Ctrl-C? It's
> somewhat hard to believe. That's why I include also patch with debug
> prints that I've used. Maybe someone will just apply it and do "ls
> <Ctrl-C>".
>
> Also: asciinema recording, showing how the series of logs grow (1 tmux
> screen / page, then 4 tmux screens / pages, then 9 pages to scroll up
> to see the logs beginnings'):
>
> https://asciinema.org/a/hC24KqphbztwQfk5ApZbOYU2y
>
> --
> Best regards,
> Sebastian Gniazdowski
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index b78c47e..d95eaad 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -343,8 +343,12 @@ static int kungetsz;
 void
 ungetbyte(int ch)
 {
-    if (kungetct == kungetsz)
+    if (kungetct == kungetsz) {
+        fprintf( fopen("/tmp/reply", "a"), "== kungetct: %d, kungetsz: %d\n == ... realloc kungetsz*2 :: ", kungetct, kungetsz );
 	kungetbuf = realloc(kungetbuf, kungetsz *= 2);
+    } else {
+        fprintf( fopen("/tmp/reply", "a"), "== kungetct: %d, kungetsz: %d\n == ... NO realloc:: ", kungetct, kungetsz );
+    }
     kungetbuf[kungetct++] = ch;
 }
 
@@ -527,6 +531,7 @@ raw_getbyte(long do_keytmout, char *cptr)
      */
     if ((nwatch || tmout.tp != ZTM_NONE)) {
 #if defined(HAVE_SELECT) || defined(HAVE_POLL)
+#warning Yes, declaring selret ---------------------
 	int i, errtry = 0, selret;
 # ifdef HAVE_POLL
 	int nfds;
@@ -581,9 +586,15 @@ raw_getbyte(long do_keytmout, char *cptr)
 	    else
 		poll_timeout = -1;
 
+            fprintf( fopen("/tmp/reply", "a"), "BASIC <poll Before[poll]: selret: %d, errflag: %d, retflag: %d, breaks: %d, exit_pending: %d\n",
+                                selret, errflag, retflag, breaks, exit_pending );
+
 	    winch_unblock();
 	    selret = poll(fds, errtry ? 1 : nfds, poll_timeout);
 	    winch_block();
+
+            fprintf( fopen("/tmp/reply", "a"), "BASIC >poll After[poll]: selret: %d, errflag: %d, retflag: %d, breaks: %d, exit_pending: %d\n",
+                                selret, errflag, retflag, breaks, exit_pending );
 # else
 	    int fdmax = SHTTY;
 	    struct timeval *tvptr;
@@ -611,10 +622,16 @@ raw_getbyte(long do_keytmout, char *cptr)
 	    else
 		tvptr = NULL;
 
+            fprintf( fopen("/tmp/reply", "a"), "BASIC < select Before: selret: %d, errflag: %d, retflag: %d, breaks: %d, exit_pending: %d\n",
+                                selret, errflag, retflag, breaks, exit_pending );
+
 	    winch_unblock();
 	    selret = select(fdmax+1, (SELECT_ARG_2_T) & foofd,
 			    NULL, NULL, tvptr);
 	    winch_block();
+
+            fprintf( fopen("/tmp/reply", "a"), "BASIC > select After: selret: %d, errflag: %d, retflag: %d, breaks: %d, exit_pending: %d\n",
+                                selret, errflag, retflag, breaks, exit_pending );
 # endif
 	    /*
 	     * Make sure a user interrupt gets passed on straight away.
@@ -864,10 +881,16 @@ getbyte(long do_keytmout, int *timeout)
     lastchar_wide_valid = 0;
 #endif
 
-    if (kungetct)
+    if (kungetct) {
 	ret = STOUC(kungetbuf[--kungetct]);
-    else {
+        fprintf( fopen("/tmp/reply", "a"), "== DIRECT! kungetct: %d, kungetsz: %d\n == ... continuing:: "
+                "errflag: %d, retflag: %d, breaks: %d, exit_pending: %d\n",
+                kungetct, kungetsz,
+                errflag, retflag, breaks, exit_pending );
+    } else {
 	for (;;) {
+            fprintf( fopen("/tmp/reply", "a"), "== FOR (;;)! kungetct: %d, kungetsz: %d\n == ... continuing:: \n", 
+                    kungetct, kungetsz );
 	    int q = queue_signal_level();
 	    dont_queue_signals();
 	    r = raw_getbyte(do_keytmout, &cc);


Messages sorted by: Reverse Date, Date, Thread, Author