diff options
| author | Mattias EngdegÄrd | 2023-02-20 15:23:12 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2023-02-21 10:42:00 +0100 |
| commit | db3fea2e5ce46229ae40aa9ca6a89964261a7a5a (patch) | |
| tree | 43264b77f2bc165a310090c40065ee6dfc750169 /test/src | |
| parent | c4c4af022d6091537fb0d748342eba5e7d3ddd23 (diff) | |
| download | emacs-db3fea2e5ce46229ae40aa9ca6a89964261a7a5a.tar.gz emacs-db3fea2e5ce46229ae40aa9ca6a89964261a7a5a.zip | |
Detect and prevent function alias loops in `fset` and `defalias`
Make `fset` and `defalias` signal an error on attempts to create
circular alias chains. This is more effective, efficient and
convenient than permitting alias loops to be created and trying to
detect them at run time each time a function is called, which is what
we have been doing until now, badly.
* lisp/help-fns.el (help-fns--analyze-function):
Don't pass obsolete argument.
* lisp/subr.el (function-alias-p):
* src/data.c (indirect_function, Findirect_function): Simplify.
Now error-free, second argument obsolete.
(Ffset): Detect loops.
* test/lisp/help-fns-tests.el (help-fns--analyze-function-recursive):
* test/lisp/subr-tests.el (test-alias-p):
Adapt tests.
* test/src/data-tests.el (data-tests-fset, data-tests-defalias): New.
* doc/lispref/eval.texi (Function Indirection):
* doc/lispref/functions.texi (Defining Functions, Function Cells):
Update manual.
* etc/NEWS: Announce.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/data-tests.el | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/src/data-tests.el b/test/src/data-tests.el index 28cee9d2c5b..680fdd57d71 100644 --- a/test/src/data-tests.el +++ b/test/src/data-tests.el | |||
| @@ -772,4 +772,40 @@ comparing the subr with a much slower Lisp implementation." | |||
| 772 | "Can't set variable marked with 'make_symbol_constant'." | 772 | "Can't set variable marked with 'make_symbol_constant'." |
| 773 | (should-error (setq most-positive-fixnum 1) :type 'setting-constant)) | 773 | (should-error (setq most-positive-fixnum 1) :type 'setting-constant)) |
| 774 | 774 | ||
| 775 | (ert-deftest data-tests-fset () | ||
| 776 | (fset 'data-tests--fs-fun (lambda () 'moo)) | ||
| 777 | (declare-function data-tests--fs-fun nil) | ||
| 778 | (should (equal (data-tests--fs-fun) 'moo)) | ||
| 779 | |||
| 780 | (fset 'data-tests--fs-fun1 'data-tests--fs-fun) | ||
| 781 | (declare-function data-tests--fs-fun1 nil) | ||
| 782 | (should (equal (data-tests--fs-fun1) 'moo)) | ||
| 783 | |||
| 784 | (fset 'data-tests--fs-a 'data-tests--fs-b) | ||
| 785 | (fset 'data-tests--fs-b 'data-tests--fs-c) | ||
| 786 | |||
| 787 | (should-error (fset 'data-tests--fs-c 'data-tests--fs-c) | ||
| 788 | :type 'cyclic-function-indirection) | ||
| 789 | (fset 'data-tests--fs-d 'data-tests--fs-a) | ||
| 790 | (should-error (fset 'data-tests--fs-c 'data-tests--fs-d) | ||
| 791 | :type 'cyclic-function-indirection)) | ||
| 792 | |||
| 793 | (ert-deftest data-tests-defalias () | ||
| 794 | (defalias 'data-tests--da-fun (lambda () 'baa)) | ||
| 795 | (declare-function data-tests--da-fun nil) | ||
| 796 | (should (equal (data-tests--da-fun) 'baa)) | ||
| 797 | |||
| 798 | (defalias 'data-tests--da-fun1 'data-tests--da-fun) | ||
| 799 | (declare-function data-tests--da-fun1 nil) | ||
| 800 | (should (equal (data-tests--da-fun1) 'baa)) | ||
| 801 | |||
| 802 | (defalias 'data-tests--da-a 'data-tests--da-b) | ||
| 803 | (defalias 'data-tests--da-b 'data-tests--da-c) | ||
| 804 | |||
| 805 | (should-error (defalias 'data-tests--da-c 'data-tests--da-c) | ||
| 806 | :type 'cyclic-function-indirection) | ||
| 807 | (defalias 'data-tests--da-d 'data-tests--da-a) | ||
| 808 | (should-error (defalias 'data-tests--da-c 'data-tests--da-d) | ||
| 809 | :type 'cyclic-function-indirection)) | ||
| 810 | |||
| 775 | ;;; data-tests.el ends here | 811 | ;;; data-tests.el ends here |