* [PATCH] unsafep: Add support for (funcall)
@ 2017-02-27 18:53 Vibhav Pant
2017-02-27 20:56 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Vibhav Pant @ 2017-02-27 18:53 UTC (permalink / raw)
To: emacs-devel@gnu.org
The following patch makes (unsafep) check funcall forms. Right now,
it only works while calling side-effect-free functions like car and cdr.
In the future, I'd like to extend this to add support for looking up and
checking (symbol-function) for other functions too.
Would appreciate some feedback before I push this.
Thanks,
Vibhav
--
Vibhav Pant
vibhavp@gmail.com
diff --git a/lisp/emacs-lisp/unsafep.el b/lisp/emacs-lisp/unsafep.el
index 1ab65a044e..beba6895b8 100644
--- a/lisp/emacs-lisp/unsafep.el
+++ b/lisp/emacs-lisp/unsafep.el
@@ -205,6 +205,12 @@ unsafep
((eq fun '\`)
;; Backquoted form - safe if its expansion is.
(unsafep (cdr (backquote-process (cadr form)))))
+ ((eq fun 'funcall)
+ (let ((func (nth 1 form))
+ (args (nthcdr 2 form)))
+ (if (eq (car-safe func) 'quote)
+ (unsafep (cons (eval func) args) unsafep-vars)
+ (setq reason `(function ,func)))))
(t
;;First unsafep-function call above wasn't nil, no special case applies
reason)))))
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] unsafep: Add support for (funcall)
2017-02-27 18:53 [PATCH] unsafep: Add support for (funcall) Vibhav Pant
@ 2017-02-27 20:56 ` Stefan Monnier
2017-02-28 15:40 ` Vibhav Pant
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2017-02-27 20:56 UTC (permalink / raw)
To: emacs-devel
> The following patch makes (unsafep) check funcall forms. Right now,
> it only works while calling side-effect-free functions like car and cdr.
> In the future, I'd like to extend this to add support for looking up and
> checking (symbol-function) for other functions too.
Hmm... I don't quite get it:
(funcall '<sym> ...)
is better written as
(<sym> ...)
so why/when do you see such code? Could we rewrite it before unsafep
gets to look at it.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] unsafep: Add support for (funcall)
2017-02-27 20:56 ` Stefan Monnier
@ 2017-02-28 15:40 ` Vibhav Pant
2017-02-28 16:18 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Vibhav Pant @ 2017-02-28 15:40 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel@gnu.org
On Tue, Feb 28, 2017 at 2:26 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> Hmm... I don't quite get it:
>
> (funcall '<sym> ...)
>
> is better written as
>
> (<sym> ...)
>
> so why/when do you see such code? Could we rewrite it before unsafep
> gets to look at it.
Indeed, byte-compile-funcall rewrites such forms. I've just added this to remove
a potential false positive from unsafep, as it's not only the byte compiler and
optimizer that use it (for instance, ses.el uses it to warn the user
about "unsafe"
formulae).
--
Vibhav Pant
vibhavp@gmail.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] unsafep: Add support for (funcall)
2017-02-28 15:40 ` Vibhav Pant
@ 2017-02-28 16:18 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2017-02-28 16:18 UTC (permalink / raw)
To: emacs-devel
>> Hmm... I don't quite get it:
>>
>> (funcall '<sym> ...)
>>
>> is better written as
>>
>> (<sym> ...)
>>
>> so why/when do you see such code? Could we rewrite it before unsafep
>> gets to look at it.
> Indeed, byte-compile-funcall rewrites such forms. I've just added this
> to remove a potential false positive from unsafep, as it's not only
> the byte compiler and optimizer that use it (for instance, ses.el uses
> it to warn the user about "unsafe" formulae).
But unsafep must call something like macroexpand-all or something like
that, so we could (should?) arrange for that to do the rewrite.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-02-28 16:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-27 18:53 [PATCH] unsafep: Add support for (funcall) Vibhav Pant
2017-02-27 20:56 ` Stefan Monnier
2017-02-28 15:40 ` Vibhav Pant
2017-02-28 16:18 ` Stefan Monnier
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).