unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19324: 25.0.50; add-function and nil
@ 2014-12-09  4:55 Leo Liu
  2014-12-10 19:54 ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Leo Liu @ 2014-12-09  4:55 UTC (permalink / raw)
  To: 19324


1. Goto a buffer (e.g. text-mode) with eldoc-documentation-function nil
2. (add-function :after-until (local 'eldoc-documentation-function) #'ignore)
3. Move around to trigger eldoc error: (void-function nil)

Looks like the orig function is unconditionally called without checking
it's a function object.

Leo





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

* bug#19324: 25.0.50; add-function and nil
  2014-12-09  4:55 bug#19324: 25.0.50; add-function and nil Leo Liu
@ 2014-12-10 19:54 ` Stefan Monnier
  2014-12-11  0:57   ` Leo Liu
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2014-12-10 19:54 UTC (permalink / raw)
  To: Leo Liu; +Cc: 19324

> 1. Goto a buffer (e.g. text-mode) with eldoc-documentation-function nil
> 2. (add-function :after-until (local 'eldoc-documentation-function) #'ignore)
> 3. Move around to trigger eldoc error: (void-function nil)
> Looks like the orig function is unconditionally called without checking
> it's a function object.

Indeed.  But I don't think advice.el should handle this case.
IOW the way I see it there are 2 ways to fix this problem:
- Change the default value so it's always a function.
- Make sure all the functions you add use either :override or :around
  and check that the orig is not nil before calling it.

Obviously, the first option is much better, which is why I've been
changing various foo-function variables so that their default value is
not nil.


        Stefan





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

* bug#19324: 25.0.50; add-function and nil
  2014-12-10 19:54 ` Stefan Monnier
@ 2014-12-11  0:57   ` Leo Liu
  2014-12-11  2:48     ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Leo Liu @ 2014-12-11  0:57 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 19324

On 2014-12-10 14:54 -0500, Stefan Monnier wrote:
> - Make sure all the functions you add use either :override or :around
>   and check that the orig is not nil before calling it.

Yes, I had expected this to work and obviously not so filed this bug.
Otherwise it is not a bad workaround.

Go to a buffer in text mode where the default
eldoc-documentation-function is nil and eval

  (add-function :around (local 'eldoc-documentation-function)
                        (lambda (orig) (or (and orig (funcall orig)) (ignore))))

Move around to get the error.

Leo





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

* bug#19324: 25.0.50; add-function and nil
  2014-12-11  0:57   ` Leo Liu
@ 2014-12-11  2:48     ` Stefan Monnier
  2014-12-11  3:54       ` Leo Liu
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2014-12-11  2:48 UTC (permalink / raw)
  To: Leo Liu; +Cc: 19324

> Yes, I had expected this to work and obviously not so filed this bug.
> Otherwise it is not a bad workaround.

> Go to a buffer in text mode where the default
> eldoc-documentation-function is nil and eval

>   (add-function :around (local 'eldoc-documentation-function)
>                         (lambda (orig) (or (and orig (funcall orig)) (ignore))))

> Move around to get the error.

Ah, right, damn: the (local <foo>) causes the insertion of a "proxy
function" which runs the global value, but that doesn't check if
it's nil.
IOW it only works for :override.


        Stefan





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

* bug#19324: 25.0.50; add-function and nil
  2014-12-11  2:48     ` Stefan Monnier
@ 2014-12-11  3:54       ` Leo Liu
  2014-12-11 17:01         ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Leo Liu @ 2014-12-11  3:54 UTC (permalink / raw)
  To: 19324

On 2014-12-10 21:48 -0500, Stefan Monnier wrote:
> Ah, right, damn: the (local <foo>) causes the insertion of a "proxy
> function" which runs the global value, but that doesn't check if it's
> nil. IOW it only works for :override.

Sounds like a bug ;)

Leo






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

* bug#19324: 25.0.50; add-function and nil
  2014-12-11  3:54       ` Leo Liu
@ 2014-12-11 17:01         ` Stefan Monnier
  2014-12-11 17:46           ` Leo Liu
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2014-12-11 17:01 UTC (permalink / raw)
  To: Leo Liu; +Cc: 19324

>> Ah, right, damn: the (local <foo>) causes the insertion of a "proxy
>> function" which runs the global value, but that doesn't check if it's
>> nil. IOW it only works for :override.
> Sounds like a bug ;)

Indeed, I fixed the eldoc-documentation-function not to be nil.


        Stefan






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

* bug#19324: 25.0.50; add-function and nil
  2014-12-11 17:01         ` Stefan Monnier
@ 2014-12-11 17:46           ` Leo Liu
  2014-12-11 19:11             ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Leo Liu @ 2014-12-11 17:46 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 19324

On 2014-12-11 12:01 -0500, Stefan Monnier wrote:
> Indeed, I fixed the eldoc-documentation-function not to be nil.
>
>
>         Stefan

But :around are still broken. It promises to pass on ORIG but instead
passes a proxy. so the advice has no (public) way to tell missing
function. Do you have a fix for this? Otherwise we have to check and set
a dummy value to be safe, for example¹.

Leo

Footnotes: 
¹  https://github.com/leoliu/ggtags/commit/115194cc27dd578b986aaaf0dc390bb57e9838b2





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

* bug#19324: 25.0.50; add-function and nil
  2014-12-11 17:46           ` Leo Liu
@ 2014-12-11 19:11             ` Stefan Monnier
  2014-12-12  0:44               ` Leo Liu
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2014-12-11 19:11 UTC (permalink / raw)
  To: Leo Liu; +Cc: 19324

> But :around are still broken.  It promises to pass on ORIG but instead
> passes a proxy.  So the advice has no (public) way to tell missing
> function.  Do you have a fix for this?

No I don't have a fix for this.
`add-function' is designed to work on places that only hold functions,
so any other value (such as nil) will create problems.

IOW a variable that can hold "either nil or a function" is not something
that add-function supports.

I guess we could treat nil as an alias for `ignore' in the "proxy
function", which would fix this particular issue.  See patch below.
But I don't intend to handle all the cases in which a "nil function" can
show up.  Many/most uses of `foo-function' actually give a special
meaning to nil which is different from `ignore'.
So I'm not sure we should cater to this particular case.

> Otherwise we have to check and set a dummy value to be safe, for
> example¹.

That looks like a good workaround.


        Stefan


diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el
index a81d3e4..7e1c236 100644
--- a/lisp/emacs-lisp/nadvice.el
+++ b/lisp/emacs-lisp/nadvice.el
@@ -234,7 +234,7 @@ different, but `function-equal' will hopefully ignore those differences.")
   (if (local-variable-p var) (symbol-value var)
     (setq advice--buffer-local-function-sample
           ;; This function acts like the t special value in buffer-local hooks.
-          (lambda (&rest args) (apply (default-value var) args)))))
+          (lambda (&rest args) (apply (or (default-value var) #'ignore) args)))))
 
 (eval-and-compile
   (defun advice--normalize-place (place)





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

* bug#19324: 25.0.50; add-function and nil
  2014-12-11 19:11             ` Stefan Monnier
@ 2014-12-12  0:44               ` Leo Liu
  0 siblings, 0 replies; 9+ messages in thread
From: Leo Liu @ 2014-12-12  0:44 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 19324-done

On 2014-12-11 14:11 -0500, Stefan Monnier wrote:
> No I don't have a fix for this.
> `add-function' is designed to work on places that only hold functions,
> so any other value (such as nil) will create problems.
>
> IOW a variable that can hold "either nil or a function" is not something
> that add-function supports.
>
> I guess we could treat nil as an alias for `ignore' in the "proxy
> function", which would fix this particular issue.  See patch below.
> But I don't intend to handle all the cases in which a "nil function" can
> show up.  Many/most uses of `foo-function' actually give a special
> meaning to nil which is different from `ignore'.
> So I'm not sure we should cater to this particular case.

Thanks, Stefan, for the explanation. In that case maybe the workaround
isn't needed because we still cannot tell if ORIG is missing. I consider
the bug closed.

Leo





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

end of thread, other threads:[~2014-12-12  0:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-09  4:55 bug#19324: 25.0.50; add-function and nil Leo Liu
2014-12-10 19:54 ` Stefan Monnier
2014-12-11  0:57   ` Leo Liu
2014-12-11  2:48     ` Stefan Monnier
2014-12-11  3:54       ` Leo Liu
2014-12-11 17:01         ` Stefan Monnier
2014-12-11 17:46           ` Leo Liu
2014-12-11 19:11             ` Stefan Monnier
2014-12-12  0:44               ` Leo Liu

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).