all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Anders Lindgren <andlind@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 16576@debbugs.gnu.org
Subject: bug#16576: Binding `standard-output' to a function doesn't work -- function sometimes called with garbage
Date: Tue, 28 Jan 2014 20:39:57 +0100	[thread overview]
Message-ID: <CABr8ebYLZ5r=K=RN-UTGEb0nBiZNfRFVezCK4j3wu6_DnOS_dA@mail.gmail.com> (raw)
In-Reply-To: <83ob2w85d3.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 4704 bytes --]

Hi!

I got the same result with your version. After running it 24 times, I got
the following output (on Emacs 22) -- please note the extra text and
control characters towards the end of the string (which I have changed to
the \xNN syntax, in order not to confuse the mail program).

"\"(\\\\(co\\\\(?:mbine-after-change-calls\\\\|nd\\\\(?:ition-case\\\\(?:-unless-debug\\\\)?\\\\)?\\\\)\\\\|eval-\\\\(?:a\\\\(?:fter-load\\\\|nd-compile\\\\)\\\\|next-after-load\\\\|when\\\\(?:-compile\\\\)?\\\\)\\\\\\\\|p\\\\(?:case\\\\(?:-let\\\\*?\\\\)?\\\\|rog[*12nv]?\\\\)\\\\|save-\\\\(?:current-buffer\\\\|excursion\\\\|match-data\\\\|restriction\\\\|selected-window\\\\|window-excursion\\\\)\\\\|track-mouse\\\\|unwind-protect\\\\|w\\\\(?:hile\\\\(?:-no-input\\\\)?\\\\|ith-\\\\(?:c\\\\(?:a\\\\(?:\\\\(?:se\\\\|tegory\\\\)-table\\\\)\\\\|urrent-buffer\\\\)\\\\|demoted-errors\\\\|electric-help\\\\|local-quit\\\\|no-warnings\\\\|output-to-\\\\(?:string\\\\|temp-buffer\\\\)\\\\|s\\\\(?:elected-\\\\(?:frame\\\\|window\\\\)\\\\|ilent-modifications\\\\|yntax-table\\\\)\\\\|t\\\\(?:emp-\\\\(?:buffer\\\\|\\\\(?:fil\\\\|messag\\\\)e\\\\)\\\\|imeout\\\\(?:-handler\\\\)?\\\\)\\\\|wrapper-hook\\\\)\\\\)\\\\)\\\\>\x00cs/
\xdc\xac\x06\\\"(\\\\\\\\(co\\\\\\\\(?:mbine-after-change-calls\\\\\\\\|n\""

When it comes to the original program, I believe that it's correct. The
function bound to `standard-output' is called from within `prin1', which is
called from inside the scope of `let'. Hence, it will work on the local
version of the variable. (If it wouldn't have been correct -- why would it
return the correct value *most* of the time?)

    -- Anders


On Tue, Jan 28, 2014 at 4:59 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Tue, 28 Jan 2014 10:09:08 +0100
> > From: Anders Lindgren <andlind@gmail.com>
> >
> >     emacs -Q
> >     Eval the following:
> >
> > (defvar bug-bind-output-str nil)
> >
> > (defun bug-bind-output-function (char)
> >   (setq bug-bind-output-str
> >         (concat bug-bind-output-str (list char))))
> >
> > (defun bug-bind-output-test ()
> >   (interactive)
> >   (let ((bug-bind-output-str "")
> >         (standard-output 'bug-bind-output-function)
> >         (s
> >
> "(\\(co\\(?:mbine-after-change-calls\\|nd\\(?:ition-case\\(?:-unless-debug\\)?\\)?\\)\\|eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|next-after-load\\|when\\(?:-compile\\)?\\)\\|i\\(?:f\\|nline\\)\\|l\\(?:ambda\\|et\\(?:\\*\\|rec\\)?\\)\\|p\\(?:case\\(?:-let\\*?\\)?\\|rog[*12nv]?\\)\\|save-\\(?:current-buffer\\|excursion\\|match-data\\|restriction\\|selected-window\\|window-excursion\\)\\|track-mouse\\|unwind-protect\\|w\\(?:hile\\(?:-no-input\\)?\\|ith-\\(?:c\\(?:a\\(?:\\(?:se\\|tegory\\)-table\\)\\|urrent-buffer\\)\\|demoted-errors\\|electric-help\\|local-quit\\|no-warnings\\|output-to-\\(?:string\\|temp-buffer\\)\\|s\\(?:elected-\\(?:frame\\|window\\)\\|ilent-modifications\\|yntax-table\\)\\|t\\(?:emp-\\(?:buffer\\|\\(?:fil\\|messag\\)e\\)\\|imeout\\(?:-handler\\)?\\)\\|wrapper-hook\\)\\)\\)\\>")
> >         s0)
> >     (prin1 s)
> >     bug-bind-output-str))
> >
> > Type this a number of times:
> >
> >     M-x (bug-bind-output-test) RET
>
> I think there's a bug in your test program.  You let-bind
> bug-bind-output-str, and print that local binding after you call
> prin1.  But your print function concatenates each character onto the
> _global_ binding of bug-bind-output-str, so the result is not in your
> local binding, it's in the global one.
>
> If you change your program like this:
>
>   (defun bug-bind-output-test ()
>     (interactive)
>     (setq bug-bind-output-str "")
>     (let ((standard-output 'bug-bind-output-function)
>           (s
>
> "(\\(co\\(?:mbine-after-change-calls\\|nd\\(?:ition-case\\(?:-unless-debug\\)?\\)?\\)\\|eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|next-after-load\\|when\\(?:-compile\\)?\\)\\|i\\(?:f\\|nline\\)\\|l\\(?:ambda\\|et\\(?:\\*\\|rec\\)?\\)\\|p\\(?:case\\(?:-let\\*?\\)?\\|rog[*12nv]?\\)\\|save-\\(?:current-buffer\\|excursion\\|match-data\\|restriction\\|selected-window\\|window-excursion\\)\\|track-mouse\\|unwind-protect\\|w\\(?:hile\\(?:-no-input\\)?\\|ith-\\(?:c\\(?:a\\(?:\\(?:se\\|tegory\\)-table\\)\\|urrent-buffer\\)\\|demoted-errors\\|electric-help\\|local-quit\\|no-warnings\\|output-to-\\(?:string\\|temp-buffer\\)\\|s\\(?:elected-\\(?:frame\\|window\\)\\|ilent-modifications\\|yntax-table\\)\\|t\\(?:emp-\\(?:buffer\\|\\(?:fil\\|messag\\)e\\)\\|imeout\\(?:-handler\\)?\\)\\|wrapper-hook\\)\\)\\)\\>")
>           s0)
>       (prin1 s)
>       bug-bind-output-str))
>
> i.e., work with the global binding, then the program works as
> expected, AFAICS.
>

[-- Attachment #2: Type: text/html, Size: 5404 bytes --]

  reply	other threads:[~2014-01-28 19:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-28  9:09 bug#16576: Binding `standard-output' to a function doesn't work -- function sometimes called with garbage Anders Lindgren
2014-01-28 15:59 ` Eli Zaretskii
2014-01-28 19:39   ` Anders Lindgren [this message]
2014-01-28 20:25     ` Eli Zaretskii
2014-01-28 22:00       ` Anders Lindgren
2014-01-29 18:01         ` Eli Zaretskii
2014-01-29 21:12           ` Anders Lindgren
2014-01-30  0:38             ` Stefan Monnier
2014-01-31 16:20               ` Anders Lindgren
2014-01-31 21:04                 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABr8ebYLZ5r=K=RN-UTGEb0nBiZNfRFVezCK4j3wu6_DnOS_dA@mail.gmail.com' \
    --to=andlind@gmail.com \
    --cc=16576@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.