diff options
| author | Philip Kaludercic <philipk@posteo.net> | 2025-02-28 08:31:56 +0100 |
|---|---|---|
| committer | Philip Kaludercic <philipk@posteo.net> | 2025-02-28 08:32:17 +0100 |
| commit | 4d7b5c9a7234f68f2b3a6eff4ef338a104df0384 (patch) | |
| tree | 2088e0d73dfd7788f6041597af44abf9177f8625 | |
| parent | 598b98d25e963252beea12dd7f0b9cf5e68c4f26 (diff) | |
compat-31: Copy {incf,decf} definitions from emacs.git
As the new tests show, the previous implementations were not robust if
PLACE causes side effects.
| -rw-r--r-- | compat-31.el | 6 | ||||
| -rw-r--r-- | compat-tests.el | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/compat-31.el b/compat-31.el index bb87724..84ff7bf 100644 --- a/compat-31.el +++ b/compat-31.el @@ -52,7 +52,8 @@ The DELTA is first added to PLACE, and then stored in PLACE. Return the incremented value of PLACE. See also `decf'." - `(setf ,place (+ ,place (or ,delta 1)))) + (gv-letplace (getter setter) place + (funcall setter `(+ ,getter ,(or delta 1))))) (compat-defmacro decf (place &optional delta) ;; <compat-tests:decf> "Decrement PLACE by DELTA (default to 1). @@ -61,7 +62,8 @@ The DELTA is first subtracted from PLACE, and then stored in PLACE. Return the decremented value of PLACE. See also `incf'." - `(setf ,place (- ,place (or ,delta 1)))) + (gv-letplace (getter setter) place + (funcall setter `(- ,getter ,(or delta 1))))) ;;;; Defined in color.el diff --git a/compat-tests.el b/compat-tests.el index 802b2c8..7c67dc0 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -3357,7 +3357,10 @@ (let ((x 0)) (should-error (eval '(incf x 'symb) t)) (should-error (eval '(incf x [a b c]) t)) - (ignore x))) + (ignore x)) + (let ((vec (vector 1 2 3)) (i 0)) + (incf (aref vec (incf i))) + (should (equal [1 3 3] vec)))) (ert-deftest compat-decf () (let ((x 3)) @@ -3385,7 +3388,10 @@ (let ((x 0)) (should-error (eval '(decf x 'symb) t)) (should-error (eval '(decf x [a b c]) t)) - (ignore x))) + (ignore x)) + (let ((vec (vector 1 2 3)) (i 2)) + (decf (aref vec (decf i))) + (should (equal [1 1 3] vec)))) (ert-deftest compat-color-blend () ;; example from the docstring |
