zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH v3] Make zpty module work in the cygwin and msys2
@ 2021-01-18  2:28 Peiyuan Song
  2021-01-18  5:43 ` Jun T
  0 siblings, 1 reply; 5+ messages in thread
From: Peiyuan Song @ 2021-01-18  2:28 UTC (permalink / raw)
  To: zsh-workers

cygwin have /dev/ptmx, need defined `_GNU_SOURCE 1` to use it, but
configure check /dev/ptmx is usable only defined it for linux.

Another probleam is cygwin upstream have an issue
https://cygwin.com/pipermail/cygwin-developers/2021-January/012030.html,
because of that issue, movefd will broken the fd opened by
posix_openpt, so that we mast disable movefd in zpty until cygwin
fix that issue.
v3 change: remove duplicate the code for check_fd_table, use
addmodulefd, assume cygwin upstream issue will be fixed in version
3.2.0
---
 Src/Modules/zpty.c | 11 +++++++++++
 configure.ac       |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 45fd15ee0..dfd2a2a7a 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -30,6 +30,13 @@
 #include "zpty.mdh"
 #include "zpty.pro"

+#ifdef __CYGWIN__
+#include <cygwin/version.h>
+#if defined(CYGWIN_VERSION_DLL_MAJOR) && CYGWIN_VERSION_DLL_MAJOR<3002
+#define USE_CYGWIN_FIX 1
+#endif
+#endif
+
 /* The number of bytes we normally read when given no pattern and the
  * upper bound on the number of bytes we read (even if we are give a
  * pattern). */
@@ -428,6 +435,7 @@ newptycmd(char *nam, char *pname, char **args, int
echo, int nblock)
        mypid = 0; /* trick to ensure we _exit() */
        zexit(lastval, ZEXIT_NORMAL);
     }
+#ifndef USE_CYGWIN_FIX
     master = movefd(master);
     if (master == -1) {
        zerrnam(nam, "cannot duplicate fd %d: %e", master, errno);
@@ -435,6 +443,9 @@ newptycmd(char *nam, char *pname, char **args, int
echo, int nblock)
        ineval = oineval;
        return 1;
     }
+#else
+    addmodulefd(master, FDT_INTERNAL);
+#endif

     p = (Ptycmd) zalloc(sizeof(*p));

diff --git a/configure.ac b/configure.ac
index 549cae3d6..16dafac05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2460,7 +2460,7 @@ if test x$ac_cv_have_dev_ptmx = xyes -o
x$ac_cv_func_posix_openpt = xyes && \
    test x$ac_cv_func_ptsname = xyes; then
    AC_CACHE_CHECK([if /dev/ptmx is usable],
    ac_cv_use_dev_ptmx,
-   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef __linux
+   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#if defined(__linux) ||
defined(__CYGWIN__)
 #define _GNU_SOURCE 1
 #endif
 #include <stdlib.h>
--
2.30.0.windows.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] Make zpty module work in the cygwin and msys2
  2021-01-18  2:28 [PATCH v3] Make zpty module work in the cygwin and msys2 Peiyuan Song
@ 2021-01-18  5:43 ` Jun T
  2021-01-18  7:17   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Jun T @ 2021-01-18  5:43 UTC (permalink / raw)
  To: zsh-workers; +Cc: Peiyuan Song

Thank you for the patch. It (v3) works fine on my Cygwin (3.1.7).

> 2021/01/18 11:28, Peiyuan Song <squallatf@gmail.com> wrote:
> 
> assume cygwin upstream issue will be fixed in version
> 3.2.0

Are you sure it will be fixed in 3.2.0 (and also not fixed in 3.1.x) ?


Currently, all or part of the following tests are skipped on Cygwin
due to the broken zpty:

E01, V08, W02, X0{2,3,4} Y0{1,2,3}

If these are modified so that they are no skipped on Cygwin, all of them
pass except Y01, which fails as follows:


./Y01completion.ztst: starting.
--- /tmp/zsh.ztst.60503/ztst.out        2021-01-18 10:07:03.427737000 +0900
+++ /tmp/zsh.ztst.60503/ztst.tout       2021-01-18 10:07:03.662082600 +0900
@@ -3,7 +3,7 @@
 FI:{\!foo}
 FI:{\#foo}
 FI:{Afoo}
-FI:{\\foo}
 FI:{bfoo}
+EX:{foo}
 FI:{\|foo}
 FI:{\~foo}
Test ./Y01completion.ztst failed: output differs from expected as shown above for:
  {
    mkdir sortnobslash
    touch sortnobslash/{'!foo','#foo','\foo','|foo','~foo',Afoo,bfoo}
    comptesteval 'old_LC_ALL=$LC_ALL; LC_ALL=C'
    comptest $': sortnobslash/\t'
  } always {
    comptesteval 'LC_ALL=$old_LC_ALL'
    rm -rf sortnobslash
  }
Was testing: ignore backslashes when sorting completion matches
./Y01completion.ztst: test failed.


As you can see, 'sortnobslash/foo' (instead of 'sortnobslash/\foo') is created
by the touch command.
I guess '\' is not allowed in a filename on Cygwin.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] Make zpty module work in the cygwin and msys2
  2021-01-18  5:43 ` Jun T
@ 2021-01-18  7:17   ` Bart Schaefer
  2021-01-18 10:56     ` Jun T
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2021-01-18  7:17 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers, Peiyuan Song

On Sun, Jan 17, 2021 at 9:43 PM Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>
> As you can see, 'sortnobslash/foo' (instead of 'sortnobslash/\foo') is created
> by the touch command.
> I guess '\' is not allowed in a filename on Cygwin.

Forward slash and backslash are equivalent as directory separators in
Cygwin, I believe.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] Make zpty module work in the cygwin and msys2
  2021-01-18  7:17   ` Bart Schaefer
@ 2021-01-18 10:56     ` Jun T
  2021-01-19  8:44       ` Jun T
  0 siblings, 1 reply; 5+ messages in thread
From: Jun T @ 2021-01-18 10:56 UTC (permalink / raw)
  To: zsh-workers; +Cc: Peiyuan Song


> 2021/01/18 16:17, Bart Schaefer <schaefer@brasslantern.com> wrote:
> 
> On Sun, Jan 17, 2021 at 9:43 PM Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>> 
>> As you can see, 'sortnobslash/foo' (instead of 'sortnobslash/\foo') is created
>> by the touch command.
>> I guess '\' is not allowed in a filename on Cygwin.
> 
> Forward slash and backslash are equivalent as directory separators in
> Cygwin, I believe.

Yep, thanks.
So we can just skip the test on cygwin.

BTW, the title '[PATCH v3] Make zpty module work in the cygwin and msys2'
suggests that the patch will also work on msys2. Is this true?

I guess __CYGWIN__ is also #defined in gcc on msys2, but CYGWIN_VERSION_DLL_MAJOR
may not be defined (I haven't yet tested on msys2).
Is movefd() on msys2 broken or not?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] Make zpty module work in the cygwin and msys2
  2021-01-18 10:56     ` Jun T
@ 2021-01-19  8:44       ` Jun T
  0 siblings, 0 replies; 5+ messages in thread
From: Jun T @ 2021-01-19  8:44 UTC (permalink / raw)
  To: zsh-workers; +Cc: Peiyuan Song


> 2021/01/18 14:43、I wrote:
> 
> Are you sure it will be fixed in 3.2.0 (and also not fixed in 3.1.x) ?

I got a reply from Peiyuan Song and it seems OK to assume this.
I will push the patch v3 unless someone finds any problem.

I will also push the patches below for the tests.


 Test/E01options.ztst      | 4 +---
 Test/V08zpty.ztst         | 2 --
 Test/W02jobs.ztst         | 4 +---
 Test/X02zlevi.ztst        | 4 +---
 Test/X03zlebindkey.ztst   | 4 +---
 Test/X04zlehighlight.ztst | 2 --
 Test/Y01completion.ztst   | 8 +++++---
 Test/Y02compmatch.ztst    | 4 +---
 Test/Y03arguments.ztst    | 4 +---
 9 files changed, 11 insertions(+), 25 deletions(-)

diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index 22751a5a2..415f46cd7 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -1426,9 +1426,7 @@ F:If this test fails at the first unsetopt, refer to P01privileged.ztst.
   fi
 0:PRIVILEGED sanity check: default value is correct
 
-  if [[ $OSTYPE == cygwin ]]; then
-    ZTST_skip='the zsh/zpty module does not work on Cygwin'
-  elif zmodload -e zsh/zpty 2>/dev/null; then
+  if zmodload -e zsh/zpty 2>/dev/null; then
     for target_dir target_pattern in \
       '.' '*' \
       '/' '/*'
diff --git a/Test/V08zpty.ztst b/Test/V08zpty.ztst
index b0cbfa050..057db2e18 100644
--- a/Test/V08zpty.ztst
+++ b/Test/V08zpty.ztst
@@ -6,8 +6,6 @@
   if ! zmodload zsh/zpty 2>/dev/null
   then
     ZTST_unimplemented="the zsh/zpty module is not available"
-  elif [[ $OSTYPE = cygwin ]]; then
-    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
   fi
 
 %test
diff --git a/Test/W02jobs.ztst b/Test/W02jobs.ztst
index fe12f979d..b09f2ac62 100644
--- a/Test/W02jobs.ztst
+++ b/Test/W02jobs.ztst
@@ -2,9 +2,7 @@
 
 %prep
 
-  if [[ $OSTYPE == cygwin ]]; then
-    ZTST_unimplemented='the zsh/zpty module does not work on Cygwin'
-  elif zmodload zsh/zpty 2> /dev/null; then
+  if zmodload zsh/zpty 2> /dev/null; then
     zpty_start() {
       export PS1= PS2=
       zpty -d
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 4e7966e12..8146d6752 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -11,9 +11,7 @@
       break;
     fi
   done
-  if [[ $OSTYPE = cygwin ]]; then
-    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
-  elif ( zmodload zsh/zpty 2>/dev/null ); then
+  if ( zmodload zsh/zpty 2>/dev/null ); then
     . $ZTST_srcdir/comptest
     comptestinit -v -z $ZTST_testdir/../Src/zsh
   else
diff --git a/Test/X03zlebindkey.ztst b/Test/X03zlebindkey.ztst
index 298d7df5d..d643b1ec9 100644
--- a/Test/X03zlebindkey.ztst
+++ b/Test/X03zlebindkey.ztst
@@ -12,9 +12,7 @@
       break;
     fi
   done
-  if [[ $OSTYPE = cygwin ]]; then
-    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
-  elif ( zmodload zsh/zpty 2>/dev/null ); then
+  if ( zmodload zsh/zpty 2>/dev/null ); then
     . $ZTST_srcdir/comptest
     comptestinit -z $ZTST_testdir/../Src/zsh
   else
diff --git a/Test/X04zlehighlight.ztst b/Test/X04zlehighlight.ztst
index ea1d64fe1..f84c02505 100644
--- a/Test/X04zlehighlight.ztst
+++ b/Test/X04zlehighlight.ztst
@@ -5,8 +5,6 @@
   export TERM=xterm-256color
   if [[ ${+termcap} != 1 || ${termcap[Co]} != <-> || ${termcap[Co]} -lt 256 ]]; then
     ZTST_unimplemented="no termcap module OR termcap doesn't support 256 or more colors"
-  elif [[ $OSTYPE == cygwin ]]; then
-    ZTST_unimplemented='the zsh/zpty module does not work on Cygwin'
   elif zmodload zsh/zpty 2> /dev/null; then
     zpty_start() {
       export PS1= PS2=
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index a00103946..65f341d49 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -11,9 +11,7 @@
       break;
     fi
   done
-  if [[ $OSTYPE = cygwin ]]; then
-    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
-  elif ( zmodload zsh/zpty 2>/dev/null ); then
+  if ( zmodload zsh/zpty 2>/dev/null ); then
     . $ZTST_srcdir/comptest
     mkdir comp.tmp
     cd comp.tmp
@@ -156,6 +154,9 @@ F:regression test workers/31611
 >line: {tst word:/}{}
 
 # Test for regression introduced by workers/41242, raised in workers/43842
+  if [[ $OSTYPE = cygwin ]]; then
+    ZTST_skip="\\ is equivalent to / in pathname on cygwin"
+  else
   {
     mkdir sortnobslash
     touch sortnobslash/{'!foo','#foo','\foo','|foo','~foo',Afoo,bfoo}
@@ -165,6 +166,7 @@ F:regression test workers/31611
     comptesteval 'LC_ALL=$old_LC_ALL'
     rm -rf sortnobslash
   }
+  fi
 0:ignore backslashes when sorting completion matches
 >line: {: sortnobslash/}{}
 >DESCRIPTION:{file}
diff --git a/Test/Y02compmatch.ztst b/Test/Y02compmatch.ztst
index e2f8e1a61..621707482 100644
--- a/Test/Y02compmatch.ztst
+++ b/Test/Y02compmatch.ztst
@@ -11,9 +11,7 @@
 # contains the compadd output.
 
 %prep
-  if [[ $OSTYPE = cygwin ]]; then
-    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
-  elif ( zmodload zsh/zpty 2>/dev/null ); then
+  if ( zmodload zsh/zpty 2>/dev/null ); then
     . $ZTST_srcdir/comptest
     mkdir match.tmp
     cd match.tmp
diff --git a/Test/Y03arguments.ztst b/Test/Y03arguments.ztst
index a815799b3..bf41aead5 100644
--- a/Test/Y03arguments.ztst
+++ b/Test/Y03arguments.ztst
@@ -1,9 +1,7 @@
 # Tests for _arguments.
 
 %prep
-  if [[ $OSTYPE = cygwin ]]; then
-    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
-  elif ( zmodload zsh/zpty 2>/dev/null ); then
+  if ( zmodload zsh/zpty 2>/dev/null ); then
     . $ZTST_srcdir/comptest
     mkdir comp.tmp
     cd comp.tmp




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-19  8:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18  2:28 [PATCH v3] Make zpty module work in the cygwin and msys2 Peiyuan Song
2021-01-18  5:43 ` Jun T
2021-01-18  7:17   ` Bart Schaefer
2021-01-18 10:56     ` Jun T
2021-01-19  8:44       ` Jun T

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).