353 lines
11 KiB
Diff
353 lines
11 KiB
Diff
diff -Naur Python-3.7.0-orig/Include/iscygpty.h Python-3.7.0/Include/iscygpty.h
|
|
--- Python-3.7.0-orig/Include/iscygpty.h 1970-01-01 03:00:00.000000000 +0300
|
|
+++ Python-3.7.0/Include/iscygpty.h 2018-07-12 10:22:48.966107500 +0300
|
|
@@ -0,0 +1,41 @@
|
|
+/*
|
|
+ * iscygpty.h -- part of ptycheck
|
|
+ * https://github.com/k-takata/ptycheck
|
|
+ *
|
|
+ * Copyright (c) 2015-2017 K.Takata
|
|
+ *
|
|
+ * You can redistribute it and/or modify it under the terms of either
|
|
+ * the MIT license (as described below) or the Vim license.
|
|
+ *
|
|
+ * Permission is hereby granted, free of charge, to any person obtaining
|
|
+ * a copy of this software and associated documentation files (the
|
|
+ * "Software"), to deal in the Software without restriction, including
|
|
+ * without limitation the rights to use, copy, modify, merge, publish,
|
|
+ * distribute, sublicense, and/or sell copies of the Software, and to
|
|
+ * permit persons to whom the Software is furnished to do so, subject to
|
|
+ * the following conditions:
|
|
+ *
|
|
+ * The above copyright notice and this permission notice shall be
|
|
+ * included in all copies or substantial portions of the Software.
|
|
+ *
|
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
+ */
|
|
+
|
|
+#ifndef _ISCYGPTY_H
|
|
+#define _ISCYGPTY_H
|
|
+
|
|
+#ifdef _WIN32
|
|
+int is_cygpty(int fd);
|
|
+int is_cygpty_used(void);
|
|
+#else
|
|
+#define is_cygpty(fd) 0
|
|
+#define is_cygpty_used() 0
|
|
+#endif
|
|
+
|
|
+#endif /* _ISCYGPTY_H */
|
|
diff -Naur Python-3.7.0-orig/Makefile.pre.in Python-3.7.0/Makefile.pre.in
|
|
--- Python-3.7.0-orig/Makefile.pre.in 2018-07-12 10:22:43.802498400 +0300
|
|
+++ Python-3.7.0/Makefile.pre.in 2018-07-12 10:22:48.966107500 +0300
|
|
@@ -350,6 +350,7 @@
|
|
Python/graminit.o \
|
|
Python/import.o \
|
|
Python/importdl.o \
|
|
+ Python/iscygpty.o \
|
|
Python/marshal.o \
|
|
Python/modsupport.o \
|
|
Python/mysnprintf.o \
|
|
@@ -984,6 +985,7 @@
|
|
$(srcdir)/Include/genobject.h \
|
|
$(srcdir)/Include/import.h \
|
|
$(srcdir)/Include/intrcheck.h \
|
|
+ $(srcdir)/Include/iscygpty.h \
|
|
$(srcdir)/Include/iterobject.h \
|
|
$(srcdir)/Include/listobject.h \
|
|
$(srcdir)/Include/longintrepr.h \
|
|
diff -Naur Python-3.7.0-orig/Modules/_io/fileio.c Python-3.7.0/Modules/_io/fileio.c
|
|
--- Python-3.7.0-orig/Modules/_io/fileio.c 2018-06-27 06:07:35.000000000 +0300
|
|
+++ Python-3.7.0/Modules/_io/fileio.c 2018-07-12 10:22:48.981707500 +0300
|
|
@@ -17,6 +17,7 @@
|
|
#endif
|
|
#include <stddef.h> /* For offsetof */
|
|
#include "_iomodule.h"
|
|
+#include "iscygpty.h"
|
|
|
|
/*
|
|
* Known likely problems:
|
|
@@ -1116,7 +1117,7 @@
|
|
return err_closed();
|
|
Py_BEGIN_ALLOW_THREADS
|
|
_Py_BEGIN_SUPPRESS_IPH
|
|
- res = isatty(self->fd);
|
|
+ res = isatty(self->fd) || is_cygpty(self->fd);
|
|
_Py_END_SUPPRESS_IPH
|
|
Py_END_ALLOW_THREADS
|
|
return PyBool_FromLong(res);
|
|
diff -Naur Python-3.7.0-orig/Modules/main.c Python-3.7.0/Modules/main.c
|
|
--- Python-3.7.0-orig/Modules/main.c 2018-07-12 10:21:48.188400700 +0300
|
|
+++ Python-3.7.0/Modules/main.c 2018-07-12 10:22:49.012907600 +0300
|
|
@@ -5,6 +5,7 @@
|
|
#include "internal/import.h"
|
|
#include "internal/pygetopt.h"
|
|
#include "internal/pystate.h"
|
|
+#include "iscygpty.h"
|
|
|
|
#include <locale.h>
|
|
|
|
@@ -1093,6 +1094,7 @@
|
|
pymain_init_stdio(_PyMain *pymain)
|
|
{
|
|
pymain->stdin_is_interactive = (isatty(fileno(stdin))
|
|
+ || is_cygpty(fileno(stdin))
|
|
|| Py_InteractiveFlag);
|
|
|
|
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
|
|
diff -Naur Python-3.7.0-orig/Modules/posixmodule.c Python-3.7.0/Modules/posixmodule.c
|
|
--- Python-3.7.0-orig/Modules/posixmodule.c 2018-07-12 10:21:50.372404600 +0300
|
|
+++ Python-3.7.0/Modules/posixmodule.c 2018-07-12 10:22:48.997307500 +0300
|
|
@@ -32,6 +32,7 @@
|
|
#else
|
|
#include "winreparse.h"
|
|
#endif
|
|
+#include "iscygpty.h"
|
|
|
|
/* On android API level 21, 'AT_EACCESS' is not declared although
|
|
* HAVE_FACCESSAT is defined. */
|
|
@@ -8547,7 +8548,7 @@
|
|
{
|
|
int return_value;
|
|
_Py_BEGIN_SUPPRESS_IPH
|
|
- return_value = isatty(fd);
|
|
+ return_value = isatty(fd) || is_cygpty(fd);
|
|
_Py_END_SUPPRESS_IPH
|
|
return return_value;
|
|
}
|
|
diff -Naur Python-3.7.0-orig/Python/frozenmain.c Python-3.7.0/Python/frozenmain.c
|
|
--- Python-3.7.0-orig/Python/frozenmain.c 2018-06-27 06:07:35.000000000 +0300
|
|
+++ Python-3.7.0/Python/frozenmain.c 2018-07-12 10:22:49.012907600 +0300
|
|
@@ -4,6 +4,7 @@
|
|
#include "Python.h"
|
|
#include "internal/pystate.h"
|
|
#include <locale.h>
|
|
+#include "iscygpty.h"
|
|
|
|
#ifdef MS_WINDOWS
|
|
extern void PyWinFreeze_ExeInit(void);
|
|
@@ -101,7 +102,7 @@
|
|
else
|
|
sts = 0;
|
|
|
|
- if (inspect && isatty((int)fileno(stdin)))
|
|
+ if (inspect && (isatty((int)fileno(stdin)) || is_cygpty((int)fileno(stdin))))
|
|
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
|
|
|
|
#ifdef MS_WINDOWS
|
|
diff -Naur Python-3.7.0-orig/Python/iscygpty.c Python-3.7.0/Python/iscygpty.c
|
|
--- Python-3.7.0-orig/Python/iscygpty.c 1970-01-01 03:00:00.000000000 +0300
|
|
+++ Python-3.7.0/Python/iscygpty.c 2018-07-12 10:22:49.012907600 +0300
|
|
@@ -0,0 +1,185 @@
|
|
+/*
|
|
+ * iscygpty.c -- part of ptycheck
|
|
+ * https://github.com/k-takata/ptycheck
|
|
+ *
|
|
+ * Copyright (c) 2015-2017 K.Takata
|
|
+ *
|
|
+ * You can redistribute it and/or modify it under the terms of either
|
|
+ * the MIT license (as described below) or the Vim license.
|
|
+ *
|
|
+ * Permission is hereby granted, free of charge, to any person obtaining
|
|
+ * a copy of this software and associated documentation files (the
|
|
+ * "Software"), to deal in the Software without restriction, including
|
|
+ * without limitation the rights to use, copy, modify, merge, publish,
|
|
+ * distribute, sublicense, and/or sell copies of the Software, and to
|
|
+ * permit persons to whom the Software is furnished to do so, subject to
|
|
+ * the following conditions:
|
|
+ *
|
|
+ * The above copyright notice and this permission notice shall be
|
|
+ * included in all copies or substantial portions of the Software.
|
|
+ *
|
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
+ */
|
|
+
|
|
+#ifdef _WIN32
|
|
+
|
|
+#include <ctype.h>
|
|
+#include <io.h>
|
|
+#include <wchar.h>
|
|
+#include <windows.h>
|
|
+
|
|
+#ifdef USE_FILEEXTD
|
|
+/* VC 7.1 or earlier doesn't support SAL. */
|
|
+# if !defined(_MSC_VER) || (_MSC_VER < 1400)
|
|
+# define __out
|
|
+# define __in
|
|
+# define __in_opt
|
|
+# endif
|
|
+/* Win32 FileID API Library:
|
|
+ * http://www.microsoft.com/en-us/download/details.aspx?id=22599
|
|
+ * Needed for WinXP. */
|
|
+# include <fileextd.h>
|
|
+#else /* USE_FILEEXTD */
|
|
+/* VC 8 or earlier. */
|
|
+# if defined(_MSC_VER) && (_MSC_VER < 1500)
|
|
+# ifdef ENABLE_STUB_IMPL
|
|
+# define STUB_IMPL
|
|
+# else
|
|
+# error "Win32 FileID API Library is required for VC2005 or earlier."
|
|
+# endif
|
|
+# endif
|
|
+#endif /* USE_FILEEXTD */
|
|
+
|
|
+
|
|
+#include "iscygpty.h"
|
|
+
|
|
+//#define USE_DYNFILEID
|
|
+#ifdef USE_DYNFILEID
|
|
+typedef BOOL (WINAPI *pfnGetFileInformationByHandleEx)(
|
|
+ HANDLE hFile,
|
|
+ FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
|
|
+ LPVOID lpFileInformation,
|
|
+ DWORD dwBufferSize
|
|
+);
|
|
+static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL;
|
|
+
|
|
+# ifndef USE_FILEEXTD
|
|
+static BOOL WINAPI stub_GetFileInformationByHandleEx(
|
|
+ HANDLE hFile,
|
|
+ FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
|
|
+ LPVOID lpFileInformation,
|
|
+ DWORD dwBufferSize
|
|
+ )
|
|
+{
|
|
+ return FALSE;
|
|
+}
|
|
+# endif
|
|
+
|
|
+static void setup_fileid_api(void)
|
|
+{
|
|
+ if (pGetFileInformationByHandleEx != NULL) {
|
|
+ return;
|
|
+ }
|
|
+ pGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx)
|
|
+ GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
|
|
+ "GetFileInformationByHandleEx");
|
|
+ if (pGetFileInformationByHandleEx == NULL) {
|
|
+# ifdef USE_FILEEXTD
|
|
+ pGetFileInformationByHandleEx = GetFileInformationByHandleEx;
|
|
+# else
|
|
+ pGetFileInformationByHandleEx = stub_GetFileInformationByHandleEx;
|
|
+# endif
|
|
+ }
|
|
+}
|
|
+#else
|
|
+# define pGetFileInformationByHandleEx GetFileInformationByHandleEx
|
|
+# define setup_fileid_api()
|
|
+#endif
|
|
+
|
|
+
|
|
+#define is_wprefix(s, prefix) \
|
|
+ (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0)
|
|
+
|
|
+/* Check if the fd is a cygwin/msys's pty. */
|
|
+int is_cygpty(int fd)
|
|
+{
|
|
+#ifdef STUB_IMPL
|
|
+ return 0;
|
|
+#else
|
|
+ HANDLE h;
|
|
+ int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * (MAX_PATH - 1);
|
|
+ FILE_NAME_INFO *nameinfo;
|
|
+ WCHAR *p = NULL;
|
|
+
|
|
+ setup_fileid_api();
|
|
+
|
|
+ h = (HANDLE) _get_osfhandle(fd);
|
|
+ if (h == INVALID_HANDLE_VALUE) {
|
|
+ return 0;
|
|
+ }
|
|
+ /* Cygwin/msys's pty is a pipe. */
|
|
+ if (GetFileType(h) != FILE_TYPE_PIPE) {
|
|
+ return 0;
|
|
+ }
|
|
+ nameinfo = malloc(size + sizeof(WCHAR));
|
|
+ if (nameinfo == NULL) {
|
|
+ return 0;
|
|
+ }
|
|
+ /* Check the name of the pipe:
|
|
+ * '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master' */
|
|
+ if (pGetFileInformationByHandleEx(h, FileNameInfo, nameinfo, size)) {
|
|
+ nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0';
|
|
+ p = nameinfo->FileName;
|
|
+ if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */
|
|
+ p += 8;
|
|
+ } else if (is_wprefix(p, L"\\msys-")) { /* MSYS and MSYS2 */
|
|
+ p += 6;
|
|
+ } else {
|
|
+ p = NULL;
|
|
+ }
|
|
+ if (p != NULL) {
|
|
+ while (*p && isxdigit(*p)) /* Skip 16-digit hexadecimal. */
|
|
+ ++p;
|
|
+ if (is_wprefix(p, L"-pty")) {
|
|
+ p += 4;
|
|
+ } else {
|
|
+ p = NULL;
|
|
+ }
|
|
+ }
|
|
+ if (p != NULL) {
|
|
+ while (*p && isdigit(*p)) /* Skip pty number. */
|
|
+ ++p;
|
|
+ if (is_wprefix(p, L"-from-master")) {
|
|
+ //p += 12;
|
|
+ } else if (is_wprefix(p, L"-to-master")) {
|
|
+ //p += 10;
|
|
+ } else {
|
|
+ p = NULL;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ free(nameinfo);
|
|
+ return (p != NULL);
|
|
+#endif /* STUB_IMPL */
|
|
+}
|
|
+
|
|
+/* Check if at least one cygwin/msys pty is used. */
|
|
+int is_cygpty_used(void)
|
|
+{
|
|
+ int fd, ret = 0;
|
|
+
|
|
+ for (fd = 0; fd < 3; fd++) {
|
|
+ ret |= is_cygpty(fd);
|
|
+ }
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+#endif /* _WIN32 */
|
|
+
|
|
+/* vim: set ts=4 sw=4: */
|
|
diff -Naur Python-3.7.0-orig/Python/pylifecycle.c Python-3.7.0/Python/pylifecycle.c
|
|
--- Python-3.7.0-orig/Python/pylifecycle.c 2018-06-27 06:07:35.000000000 +0300
|
|
+++ Python-3.7.0/Python/pylifecycle.c 2018-07-12 10:22:49.012907600 +0300
|
|
@@ -17,6 +17,7 @@
|
|
#include "ast.h"
|
|
#include "marshal.h"
|
|
#include "osdefs.h"
|
|
+#include "iscygpty.h"
|
|
#include <locale.h>
|
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
@@ -2187,7 +2188,7 @@
|
|
int
|
|
Py_FdIsInteractive(FILE *fp, const char *filename)
|
|
{
|
|
- if (isatty((int)fileno(fp)))
|
|
+ if (isatty((int)fileno(fp)) || is_cygpty((int)fileno(fp)))
|
|
return 1;
|
|
if (!Py_InteractiveFlag)
|
|
return 0;
|