From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andrew Hyatt Newsgroups: gmane.emacs.bugs Subject: bug#5440: 23.1; buffer-file-format encoding temp buffers not reentrant Date: Thu, 21 Jul 2016 00:33:17 -0400 Message-ID: References: <87sk9z3vt2.fsf@blah.blah> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1469075669 3947 80.91.229.3 (21 Jul 2016 04:34:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Jul 2016 04:34:29 +0000 (UTC) Cc: 5440@debbugs.gnu.org To: Kevin Ryde Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 21 06:34:18 2016 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 1bQ5gg-0003IA-1w for geb-bug-gnu-emacs@m.gmane.org; Thu, 21 Jul 2016 06:34:18 +0200 Original-Received: from localhost ([::1]:38186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ5gc-0001GF-0m for geb-bug-gnu-emacs@m.gmane.org; Thu, 21 Jul 2016 00:34:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ5gT-0001Fx-UN for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 00:34:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQ5gQ-0002NW-N4 for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 00:34:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46851) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ5gQ-0002NS-JK for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 00:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bQ5gQ-0000rq-GD for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 00:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrew Hyatt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 21 Jul 2016 04:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5440 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 5440-submit@debbugs.gnu.org id=B5440.14690756103274 (code B ref 5440); Thu, 21 Jul 2016 04:34:02 +0000 Original-Received: (at 5440) by debbugs.gnu.org; 21 Jul 2016 04:33:30 +0000 Original-Received: from localhost ([127.0.0.1]:59182 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQ5ft-0000qk-KK for submit@debbugs.gnu.org; Thu, 21 Jul 2016 00:33:29 -0400 Original-Received: from mail-qk0-f169.google.com ([209.85.220.169]:35071) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQ5fr-0000qW-St for 5440@debbugs.gnu.org; Thu, 21 Jul 2016 00:33:28 -0400 Original-Received: by mail-qk0-f169.google.com with SMTP id s63so64132346qkb.2 for <5440@debbugs.gnu.org>; Wed, 20 Jul 2016 21:33:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=8189A3ueOjEb30frzswYoJV8bxxSxKiD51OHHCPoxPQ=; b=cvp2atJtB9P12FtLuTt57xoGdlDOVjGyTCaB3zCJjl1bqY9OcDCLAup0gs9yy02f6S E1ihyIf3vmgrfouqh/3mv2aoC4KNg6qrsQd0qrd81QeJH3yhQZ8rh8h6IIPf5evDM8K+ Bs4et+q0JF4p5itYHtJdEDToBIQGpXYWNnMFfuda4o46skgYIiKG2aoRuPSeoI/YATfG ABSe3a7xAXt7keCAxvIa5rxkdJsEVT/bS6W6v8fgHqDt9DZQSwDbaXEj63+NR/8BfSDd Psy8sGrq58gelZsIy5f+JwGaq31A+O1bB81+rtNpaz2Cg2O/4ihbgFIcKfvnndo90E6d eYqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=8189A3ueOjEb30frzswYoJV8bxxSxKiD51OHHCPoxPQ=; b=RMX+nXtDfP4l+1STQYnCImwwcO9zb49hbhKTXX9it/3mmpEmVB0+irxxh6hoKytWzo 8maDosk5L1fFAi6Ua6n+v5K90ebfYyGvzBPN3Wmra+POVofG2WvjZwdyLTnORqlfmmDJ Vf56FO46bnvgeGh3VKqrUMifRqHiy8doQOKs3dAl/Dv1zLUzwt+XcfuDGHBAKIB//0MT ZhpnO6Vbq4vgSSEGZ5JVYwhpasFK/0d5G60MBk0y+SuU3ikm4c6FRP+bZOjmseESggkB TuDHUtxcCaiIMf1uXFSzj0XQL39ly5YfNu+ZlDBJaao4MJrP5ZaV85QejR6hVEye3zdE u2hg== X-Gm-Message-State: ALyK8tJ243E/Pd8UuKW+M3GM5El3RdCd0Pt/IckGchnmKwkDn+GTygWY0ECNKXiMyjAdWQ== X-Received: by 10.55.88.68 with SMTP id m65mr22717011qkb.205.1469075601823; Wed, 20 Jul 2016 21:33:21 -0700 (PDT) Original-Received: from Andrews-MacBook-Pro.local.ahyatt-laptop (cpe-74-73-128-199.nyc.res.rr.com. [74.73.128.199]) by smtp.gmail.com with ESMTPSA id g29sm3354139qtg.12.2016.07.20.21.33.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jul 2016 21:33:18 -0700 (PDT) In-Reply-To: <87sk9z3vt2.fsf@blah.blah> (Kevin Ryde's message of "Fri, 22 Jan 2010 10:03:21 +1100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (darwin) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:121360 Archived-At: This reproduces on Emacs 25. But I wonder if this should be a wishlist instead of a bug. As the original report notes, decoding a buffer while encoding another buffer doesn't seem like a normal use-case. If no one objects in the next few weeks, I can wishlist this. Making it a minor-severity bug also seems reasonable to me. Kevin Ryde writes: > The way build_annotations() makes `format-annotate-function' use the > same temp buffer " *Format Temp 0*" on each call is not reentrant. If > TO-FN from the format-alist does anything that writes another buffer > with a buffer-file-format then the buffer which TO-FN is supposed to be > working on is clobbered. > > foo.el below illustrates the problem. Evaluating it writes a /tmp/x > containing > > THIS IS FORMAT ONE > this is buffer yyy text > > where I expected it to be > > THIS IS FORMAT TWO > hello world > > The `message's emitted by my-one-encode and my-two-encode show they get > the same " *Format Temp 0*" buffer. The latter is what you get in > /tmp/x if taking away the "/tmp/y" blob within `my-two-encode'. > > I expect this wouldn't arise often in practice, but it ought to be > reasonably easy to make build_annotations() (or wherever) do better in > the management of temporary buffers. I expect it's a matter of finding > the right place in the write crunching that temp buffers used can be > killed. > > > (add-to-list 'format-alist '(my-one > "My format." > nil ;; no automatic decode > my-one-decode > my-one-encode > t ;; encode modifies the region > nil)) ;; write removes from buffer-file-formats > > (defun my-one-decode (beg end) > end) > > (defun my-one-encode (beg end buffer) > (message "my-one-encode in %S" (current-buffer)) > > (save-excursion > (save-restriction > (narrow-to-region beg end) > > (insert "THIS IS FORMAT ONE\n") > > (point-max)))) > > > (add-to-list 'format-alist '(my-two > "My format." > nil ;; no automatic decode > my-two-decode > my-two-encode > t ;; encode modifies the region > nil)) ;; write removes from buffer-file-formats > > (defun my-two-decode (beg end) > (save-excursion > (save-restriction > (narrow-to-region beg end) > > (goto-char beg) > (if (looking-at "THIS IS FORMAT TWO\n") > (delete-region (match-beginning 0) (match-end 0))) > > (point-max)))) > > (defun my-two-encode (beg end buffer) > (message "my-two-encode in %S" (current-buffer)) > > (save-excursion > (save-restriction > (narrow-to-region beg end) > > (goto-char (point-min)) > (insert "THIS IS FORMAT TWO\n") > > (save-current-buffer > (find-file "/tmp/y") > (format-decode-buffer 'my-one) > (erase-buffer) > (insert "this is buffer yyy text\n") > (save-buffer) > (kill-buffer nil)) > > (point-max)))) > > > (progn > (find-file "/tmp/x") > (format-decode-buffer 'my-two) > (erase-buffer) > (insert "hello world\n") > (save-buffer) > (kill-buffer nil) > (find-file "/tmp/x")) > > > > In GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.16.5) > of 2009-09-14 on raven, modified by Debian > configured using `configure '--build=i486-linux-gnu' '--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.1/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.1/leim' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS='' > > Important settings: > value of $LC_ALL: nil > value of $LC_COLLATE: nil > value of $LC_CTYPE: nil > value of $LC_MESSAGES: nil > value of $LC_MONETARY: nil > value of $LC_NUMERIC: nil > value of $LC_TIME: nil > value of $LANG: en_AU > value of $XMODIFIERS: nil > locale-coding-system: iso-latin-1-unix > default-enable-multibyte-characters: t