unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8496: some file locking code in insert-file-contents cannot be right
@ 2011-04-14  0:40 Paul Eggert
  2011-04-14  6:48 ` Eli Zaretskii
  2011-04-14  8:00 ` Andreas Schwab
  0 siblings, 2 replies; 6+ messages in thread
From: Paul Eggert @ 2011-04-14  0:40 UTC (permalink / raw)
  To: 8496

As a result of the "mark unexported symbols 'static'" patch that I'm
working on, in the Emacs trunk I found some file-locking code inside
insert-file-contents that cannot be right:

     if (NILP (visit) && inserted > 0)
       {
   #ifdef CLASH_DETECTION
	 if (!NILP (BVAR (current_buffer, file_truename))
	     /* Make binding buffer-file-name to nil effective.  */
	     && !NILP (BVAR (current_buffer, filename))
	     && SAVE_MODIFF >= MODIFF)
	   we_locked_file = 1;
   #endif /* CLASH_DETECTION */
	 prepare_to_modify_buffer (GPT, GPT, NULL);
       }

The above code is equivalent to a no-op, since 'inserted' must
be zero here.  There's later code:

   #ifdef CLASH_DETECTION
	 if (we_locked_file)
	   unlock_file (BVAR (current_buffer, file_truename));
   #endif

that is also a no-op, because 'we_locked_file' must be zero.

GCC merrily optimizes all this code away, but I don't think
that was intended.  What *is* intended here?





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

* bug#8496: some file locking code in insert-file-contents cannot be right
  2011-04-14  0:40 bug#8496: some file locking code in insert-file-contents cannot be right Paul Eggert
@ 2011-04-14  6:48 ` Eli Zaretskii
  2011-04-14  7:53   ` Paul Eggert
  2011-04-14  8:55   ` Eli Zaretskii
  2011-04-14  8:00 ` Andreas Schwab
  1 sibling, 2 replies; 6+ messages in thread
From: Eli Zaretskii @ 2011-04-14  6:48 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8496

> Date: Wed, 13 Apr 2011 17:40:49 -0700
> From: Paul Eggert <eggert@cs.ucla.edu>
> 
> As a result of the "mark unexported symbols 'static'" patch that I'm
> working on, in the Emacs trunk I found some file-locking code inside
> insert-file-contents that cannot be right:
> 
>      if (NILP (visit) && inserted > 0)
>        {
>    #ifdef CLASH_DETECTION
> 	 if (!NILP (BVAR (current_buffer, file_truename))
> 	     /* Make binding buffer-file-name to nil effective.  */
> 	     && !NILP (BVAR (current_buffer, filename))
> 	     && SAVE_MODIFF >= MODIFF)
> 	   we_locked_file = 1;
>    #endif /* CLASH_DETECTION */
> 	 prepare_to_modify_buffer (GPT, GPT, NULL);
>        }
> 
> The above code is equivalent to a no-op, since 'inserted' must
> be zero here.

In Emacs 21.4a, the corresponding code was this:

    if (!NILP (visit))
      {
	...
  #ifdef CLASH_DETECTION
	if (NILP (handler))
	  {
	    if (!NILP (current_buffer->file_truename))
	      unlock_file (current_buffer->file_truename);
	    unlock_file (filename);
	  }
  #endif /* CLASH_DETECTION */

The change to the present form was between 21.4a and 22.1.  It appears
in the trunk history as part of a huge merge from a branch, probably
the Emacs 22.1 release branch.  I need more forensic work to find out
why the change was made, but at this point it certainly looks like
someone goofed with the condition.

What platforms use CLASH_DETECTION?





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

* bug#8496: some file locking code in insert-file-contents cannot be right
  2011-04-14  6:48 ` Eli Zaretskii
@ 2011-04-14  7:53   ` Paul Eggert
  2011-04-14  8:07     ` Eli Zaretskii
  2011-04-14  8:55   ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Eggert @ 2011-04-14  7:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 8496

On 04/13/2011 11:48 PM, Eli Zaretskii wrote:
> What platforms use CLASH_DETECTION?

According to the .h files,
pretty much all the POSIXish platforms do it
(GNU/Linux, BSD, MacOS, AIX, etc.)
and it's also done on Cygwin.





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

* bug#8496: some file locking code in insert-file-contents cannot be right
  2011-04-14  0:40 bug#8496: some file locking code in insert-file-contents cannot be right Paul Eggert
  2011-04-14  6:48 ` Eli Zaretskii
@ 2011-04-14  8:00 ` Andreas Schwab
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2011-04-14  8:00 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8496-done

Paul Eggert <eggert@cs.ucla.edu> writes:

> What *is* intended here?

If you look at 9a95c4d it is obvious.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#8496: some file locking code in insert-file-contents cannot be right
  2011-04-14  7:53   ` Paul Eggert
@ 2011-04-14  8:07     ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2011-04-14  8:07 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8496

> Date: Thu, 14 Apr 2011 00:53:17 -0700
> From: Paul Eggert <eggert@cs.ucla.edu>
> CC: 8496@debbugs.gnu.org
> 
> On 04/13/2011 11:48 PM, Eli Zaretskii wrote:
> > What platforms use CLASH_DETECTION?
> 
> According to the .h files,
> pretty much all the POSIXish platforms do it
> (GNU/Linux, BSD, MacOS, AIX, etc.)
> and it's also done on Cygwin.

That's what I thought.  I guess that pretty much excludes the
possibility that this went undetected because no one uses it.





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

* bug#8496: some file locking code in insert-file-contents cannot be right
  2011-04-14  6:48 ` Eli Zaretskii
  2011-04-14  7:53   ` Paul Eggert
@ 2011-04-14  8:55   ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2011-04-14  8:55 UTC (permalink / raw)
  To: eggert, 8496

> Date: Thu, 14 Apr 2011 02:48:28 -0400
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: 8496@debbugs.gnu.org
> Reply-To: Eli Zaretskii <eliz@gnu.org>
> 
> >      if (NILP (visit) && inserted > 0)
> >        {
> >    #ifdef CLASH_DETECTION
> > 	 if (!NILP (BVAR (current_buffer, file_truename))
> > 	     /* Make binding buffer-file-name to nil effective.  */
> > 	     && !NILP (BVAR (current_buffer, filename))
> > 	     && SAVE_MODIFF >= MODIFF)
> > 	   we_locked_file = 1;
> >    #endif /* CLASH_DETECTION */
> > 	 prepare_to_modify_buffer (GPT, GPT, NULL);
> >        }
> > 
> > The above code is equivalent to a no-op, since 'inserted' must
> > be zero here.
> 
> In Emacs 21.4a, the corresponding code was this:
> 
>     if (!NILP (visit))
>       {
> 	...
>   #ifdef CLASH_DETECTION
> 	if (NILP (handler))
> 	  {
> 	    if (!NILP (current_buffer->file_truename))
> 	      unlock_file (current_buffer->file_truename);
> 	    unlock_file (filename);
> 	  }
>   #endif /* CLASH_DETECTION */

Sorry, that was wrong.  The previous version was this:

   if (NILP (visit) && total > 0)
     prepare_to_modify_buffer (PT, PT, NULL);

The ChangeLog entry for the change (in revision 62259) is this:

     (Finsert_file_contents): If we read 0 bytes from a special file,
     unlock the visited file if we locked it.





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

end of thread, other threads:[~2011-04-14  8:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-14  0:40 bug#8496: some file locking code in insert-file-contents cannot be right Paul Eggert
2011-04-14  6:48 ` Eli Zaretskii
2011-04-14  7:53   ` Paul Eggert
2011-04-14  8:07     ` Eli Zaretskii
2011-04-14  8:55   ` Eli Zaretskii
2011-04-14  8:00 ` Andreas Schwab

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).