From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Brown Newsgroups: gmane.emacs.bugs Subject: bug#19909: [PATCH] Error out if with-file-notification=w32 is specified on cygwin Date: Fri, 27 Feb 2015 17:25:54 -0500 Message-ID: <54F0EEF2.1030908@cornell.edu> References: <821tlkhq2v.fsf@gmail.com> <83mw48lwvx.fsf@gnu.org> <82wq3cga1n.fsf@gmail.com> <83ioewlv1v.fsf@gnu.org> <82sie0fz1q.fsf@gmail.com> <838ufslitm.fsf@gnu.org> <54E75D96.70601@cornell.edu> <83twygcxif.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030000060002070602010600" X-Trace: ger.gmane.org 1425076052 26167 80.91.229.3 (27 Feb 2015 22:27:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 27 Feb 2015 22:27:32 +0000 (UTC) Cc: 19909@debbugs.gnu.org, rpluim@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 27 23:27:20 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YRTNK-0006oe-Ld for geb-bug-gnu-emacs@m.gmane.org; Fri, 27 Feb 2015 23:27:14 +0100 Original-Received: from localhost ([::1]:39239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRTNJ-0001Sa-V0 for geb-bug-gnu-emacs@m.gmane.org; Fri, 27 Feb 2015 17:27:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRTNC-0001J8-F3 for bug-gnu-emacs@gnu.org; Fri, 27 Feb 2015 17:27:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YRTN9-0007mV-5k for bug-gnu-emacs@gnu.org; Fri, 27 Feb 2015 17:27:06 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56668) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRTN9-0007mK-30 for bug-gnu-emacs@gnu.org; Fri, 27 Feb 2015 17:27:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YRTN8-0006uN-JG for bug-gnu-emacs@gnu.org; Fri, 27 Feb 2015 17:27:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ken Brown Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Feb 2015 22:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19909 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-Cc: bug-gnu-emacs@gnu.org, rpluim@gmail.com Original-Received: via spool by submit@debbugs.gnu.org id=B.142507596126445 (code B ref -1); Fri, 27 Feb 2015 22:27:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Feb 2015 22:26:01 +0000 Original-Received: from localhost ([127.0.0.1]:60266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YRTM8-0006sN-Ar for submit@debbugs.gnu.org; Fri, 27 Feb 2015 17:26:01 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:55730) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YRTM6-0006s9-CB for submit@debbugs.gnu.org; Fri, 27 Feb 2015 17:25:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YRTLz-0006ud-Qj for submit@debbugs.gnu.org; Fri, 27 Feb 2015 17:25:53 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:36227) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRTLz-0006uZ-NV for submit@debbugs.gnu.org; Fri, 27 Feb 2015 17:25:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRTLy-0008DJ-AB for bug-gnu-emacs@gnu.org; Fri, 27 Feb 2015 17:25:51 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YRTLv-0006sx-39 for bug-gnu-emacs@gnu.org; Fri, 27 Feb 2015 17:25:50 -0500 Original-Received: from limerock03.mail.cornell.edu ([128.84.13.243]:34305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRTLu-0006sq-U4; Fri, 27 Feb 2015 17:25:46 -0500 X-CornellRouted: This message has been Routed already. Original-Received: from authusersmtp.mail.cornell.edu (granite3.serverfarm.cornell.edu [10.16.197.8]) by limerock03.mail.cornell.edu (8.14.4/8.14.4_cu) with ESMTP id t1RMPi6F020128; Fri, 27 Feb 2015 17:25:44 -0500 Original-Received: from [192.168.1.3] (cpe-67-249-176-138.twcny.res.rr.com [67.249.176.138]) (authenticated bits=0) by authusersmtp.mail.cornell.edu (8.14.4/8.12.10) with ESMTP id t1RMPhID009054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Fri, 27 Feb 2015 17:25:43 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 In-Reply-To: <83twygcxif.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:99887 Archived-At: This is a multi-part message in MIME format. --------------030000060002070602010600 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 2/20/2015 12:18 PM, Eli Zaretskii wrote: >> Date: Fri, 20 Feb 2015 11:15:18 -0500 >> From: Ken Brown >> CC: bug-gnu-emacs@gnu.org, Robert Pluim >> >> I'm busy with other things at the moment and can't get to it right away. >> If it's easy for you to suggest a patch, why don't you go ahead, and >> Robert can test it. Or you can wait a couple weeks until I can look at it. > > OK, I will try to find time. > >> BTW, file-notification=gfile works fine in the Cygwin-w32 build, so I'm >> not sure there's any need to put a lot of effort into this. > > If it turns out to need a lot of effort, I'll agree with you. It looks like it might not take much effort. What I did for now, just for testing purposes, is to copy into w32notify.c whatever was necessary to make the Cygwin-w32 build compile with w32 file notification. I tested it briefly and it seems to work. Obviously it needs much more testing to make sure this doesn't break anything else, and then we can worry about how to do this right. Robert, please test when you get a chance (patch attached). Ken --------------030000060002070602010600 Content-Type: text/plain; charset=windows-1252; name="cygw32_notify.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cygw32_notify.patch" diff --git a/src/w32notify.c b/src/w32notify.c index ab6cd12..71ee1a3 100644 --- a/src/w32notify.c +++ b/src/w32notify.c @@ -92,12 +92,216 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" #include "w32term.h" /* for enter_crit/leave_crit and WM_EMACS_FILENOTIFY */ #include "w32common.h" /* for OS version data */ -#include "w32.h" /* for w32_strerror */ #include "coding.h" #include "keyboard.h" #include "frame.h" /* needed by termhooks.h */ #include "termhooks.h" /* for FILE_NOTIFY_EVENT */ +/* Experimental code for Cygwin-w32 build */ + +extern char * w32_strerror (int error_no); + +int (WINAPI *pMultiByteToWideChar)(UINT,DWORD,LPCSTR,int,LPWSTR,int); +int (WINAPI *pWideCharToMultiByte)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL); + +#define MAXPATHLEN MAX_PATH +#define MAX_UTF8_PATH (MAXPATHLEN * 4) + +static int file_name_codepage; + +static int +codepage_for_filenames (CPINFO *cp_info) +{ + /* A simple cache to avoid calling GetCPInfo every time we need to + encode/decode a file name. The file-name encoding is not + supposed to be changed too frequently, if ever. */ + static Lisp_Object last_file_name_encoding; + static CPINFO cp; + Lisp_Object current_encoding; + + current_encoding = Vfile_name_coding_system; + if (NILP (current_encoding)) + current_encoding = Vdefault_file_name_coding_system; + + if (!EQ (last_file_name_encoding, current_encoding)) + { + /* Default to the current ANSI codepage. */ + file_name_codepage = w32_ansi_code_page; + + if (NILP (current_encoding)) + { + char *cpname = SDATA (SYMBOL_NAME (current_encoding)); + char *cp = NULL, *end; + int cpnum; + + if (strncmp (cpname, "cp", 2) == 0) + cp = cpname + 2; + else if (strncmp (cpname, "windows-", 8) == 0) + cp = cpname + 8; + + if (cp) + { + end = cp; + cpnum = strtol (cp, &end, 10); + if (cpnum && *end == '\0' && end - cp >= 2) + file_name_codepage = cpnum; + } + } + + if (!file_name_codepage) + file_name_codepage = CP_ACP; /* CP_ACP = 0, but let's not assume that */ + + if (!GetCPInfo (file_name_codepage, &cp)) + { + file_name_codepage = CP_ACP; + if (!GetCPInfo (file_name_codepage, &cp)) + emacs_abort (); + } + } + if (cp_info) + *cp_info = cp; + + return file_name_codepage; +} + +int +filename_to_utf16 (const char *fn_in, wchar_t *fn_out) +{ + int result = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, fn_in, -1, + fn_out, MAX_PATH); + + if (!result) + { + DWORD err = GetLastError (); + + switch (err) + { + case ERROR_INVALID_FLAGS: + case ERROR_INVALID_PARAMETER: + errno = EINVAL; + break; + case ERROR_INSUFFICIENT_BUFFER: + case ERROR_NO_UNICODE_TRANSLATION: + default: + errno = ENOENT; + break; + } + return -1; + } + return 0; +} + +int +filename_from_utf16 (const wchar_t *fn_in, char *fn_out) +{ + int result = pWideCharToMultiByte (CP_UTF8, 0, fn_in, -1, + fn_out, MAX_UTF8_PATH, NULL, NULL); + + if (!result) + { + DWORD err = GetLastError (); + + switch (err) + { + case ERROR_INVALID_FLAGS: + case ERROR_INVALID_PARAMETER: + errno = EINVAL; + break; + case ERROR_INSUFFICIENT_BUFFER: + case ERROR_NO_UNICODE_TRANSLATION: + default: + errno = ENOENT; + break; + } + return -1; + } + return 0; +} + +int +filename_to_ansi (const char *fn_in, char *fn_out) +{ + wchar_t fn_utf16[MAX_PATH]; + + if (filename_to_utf16 (fn_in, fn_utf16) == 0) + { + int result; + int codepage = codepage_for_filenames (NULL); + + result = pWideCharToMultiByte (codepage, 0, fn_utf16, -1, + fn_out, MAX_PATH, NULL, NULL); + if (!result) + { + DWORD err = GetLastError (); + + switch (err) + { + case ERROR_INVALID_FLAGS: + case ERROR_INVALID_PARAMETER: + errno = EINVAL; + break; + case ERROR_INSUFFICIENT_BUFFER: + case ERROR_NO_UNICODE_TRANSLATION: + default: + errno = ENOENT; + break; + } + return -1; + } + return 0; + } + return -1; +} + +int +filename_from_ansi (const char *fn_in, char *fn_out) +{ + wchar_t fn_utf16[MAX_PATH]; + int codepage = codepage_for_filenames (NULL); + int result = pMultiByteToWideChar (codepage, MB_ERR_INVALID_CHARS, fn_in, -1, + fn_utf16, MAX_PATH); + + if (!result) + { + DWORD err = GetLastError (); + + switch (err) + { + case ERROR_INVALID_FLAGS: + case ERROR_INVALID_PARAMETER: + errno = EINVAL; + break; + case ERROR_INSUFFICIENT_BUFFER: + case ERROR_NO_UNICODE_TRANSLATION: + default: + errno = ENOENT; + break; + } + return -1; + } + return filename_from_utf16 (fn_utf16, fn_out); +} + +int +w32_valid_pointer_p (void *p, int size) +{ + SIZE_T done; + HANDLE h = OpenProcess (PROCESS_VM_READ, FALSE, GetCurrentProcessId ()); + + if (h) + { + unsigned char *buf = alloca (size); + int retval = ReadProcessMemory (h, p, buf, size, &done); + + CloseHandle (h); + return retval; + } + else + return -1; +} + +/* End experimental code for Cygwin-w32 build */ + #define DIRWATCH_SIGNATURE 0x01233210 struct notification { diff --git a/src/w32term.c b/src/w32term.c index d415b13..061c9c3 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -3195,7 +3195,6 @@ lispy_file_action (DWORD action) return retval; } -#ifdef WINDOWSNT /* Put file notifications into the Emacs input event queue. This function runs when the WM_EMACS_FILENOTIFY message arrives from a watcher thread. */ @@ -3271,7 +3270,6 @@ queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f, /* We've stuffed all the events ourselves, so w32_read_socket shouldn't. */ event->kind = NO_EVENT; } -#endif /* WINDOWSNT */ #endif /* HAVE_W32NOTIFY */ --------------030000060002070602010600--