From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Fabrice Popineau" Newsgroups: gmane.emacs.devel Subject: patch to fileio.c Date: Sun, 26 Oct 2008 16:15:28 +0100 Organization: =?iso-8859-1?Q?Sup=E9lec?= Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1225034179 19555 80.91.229.12 (26 Oct 2008 15:16:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 26 Oct 2008 15:16:19 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 26 16:17:21 2008 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ku7Ml-0000hG-7n for ged-emacs-devel@m.gmane.org; Sun, 26 Oct 2008 16:17:19 +0100 Original-Received: from localhost ([127.0.0.1]:36556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ku7Le-0002IR-IR for ged-emacs-devel@m.gmane.org; Sun, 26 Oct 2008 11:16:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ku7LZ-0002IC-UN for emacs-devel@gnu.org; Sun, 26 Oct 2008 11:16:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ku7LX-0002Gz-W9 for emacs-devel@gnu.org; Sun, 26 Oct 2008 11:16:05 -0400 Original-Received: from [199.232.76.173] (port=40931 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ku7LX-0002Gw-RB for emacs-devel@gnu.org; Sun, 26 Oct 2008 11:16:03 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:40334 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ku7LX-0005Zc-Aq for emacs-devel@gnu.org; Sun, 26 Oct 2008 11:16:03 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Ku7LQ-0007XT-Om for emacs-devel@gnu.org; Sun, 26 Oct 2008 15:15:56 +0000 Original-Received: from sparky.metz.supelec.fr ([193.48.224.190]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 26 Oct 2008 15:15:56 +0000 Original-Received: from fabrice.popineau by sparky.metz.supelec.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 26 Oct 2008 15:15:56 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 64 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: sparky.metz.supelec.fr X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6001.18000 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18049 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:105015 Archived-At: Hi, You should consider adding the following patch. As I reported earlier, the fd file descriptor may be closed twice in insert-file-contents. It happens every time a file is visited and this same file is modified outside emacs. In this case, you can ask to visit the file again (or emacs will ask you if you try to save it) "File foobar.txt changed on disk. Reread from disk? (yes or no)" The fd file descriptor in this case is closed by emacs_close() at line 3654 and by close_file_unwind() registered at line 3233. When emacs_close(fd) is reached, the unwind_protect registered function should be removed. Unfortunately, in the mean time other stuff has been put in the unwind_protect stack, so you can't just decrement the pointer. It can be done when the handled: label is reached. Hence the flag in my patch. There was a previous patch may be related to the same problem, but not fixing it: 2008-09-14 Kenichi Handa * fileio.c (Finsert_file_contents): Delete incorrect decrement of specpdl_ptr. Best regards, Fabrice --- \Mirror\emacs\src\fileio.c 2008-10-16 21:30:49.000000000 +0200 +++ fileio.c 2008-10-26 10:39:11.000000000 +0100 @@ -3141,6 +3141,7 @@ int read_quit = 0; Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark; int we_locked_file = 0; + int should_remove_unwind_protect = 0; if (current_buffer->base_buffer && ! NILP (visit)) error ("Cannot do file visiting in an indirect buffer"); @@ -3650,8 +3651,10 @@ if (coding.carryover_bytes > 0) bcopy (coding.carryover, read_buf, unprocessed); } + UNGCPRO; emacs_close (fd); + should_remove_unwind_protect = 1; /* At this point, HOW_MUCH should equal TOTAL, or should be <= 0 if we couldn't read the file. */ @@ -4033,6 +4036,9 @@ #endif handled: +#if 1 + if (should_remove_unwind_protect) specpdl_ptr--; +#endif if (!NILP (visit)) {