]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid unwind-protect without unwind forms in cl-letf
authorMattias Engdegård <mattiase@acm.org>
Wed, 29 Mar 2023 15:03:31 +0000 (17:03 +0200)
committerMattias Engdegård <mattiase@acm.org>
Wed, 29 Mar 2023 17:47:03 +0000 (19:47 +0200)
* lisp/emacs-lisp/cl-macs.el (cl--letf): Use unwind-protect only if
necessary, avoiding a warning.

lisp/emacs-lisp/cl-macs.el

index cffe8b09f53cfadcda9e024a942489fc518c9b38..8dc8b475a7fa3814cf16d06a23d42a28e53ee370 100644 (file)
@@ -2758,26 +2758,29 @@ Each PLACE may be a symbol, or any generalized variable allowed by `setf'.
   ;; Common-Lisp's `psetf' does the first, so we'll do the same.
   (if (null bindings)
       (if (and (null binds) (null simplebinds)) (macroexp-progn body)
+        (let ((body-form
+               (macroexp-progn
+                (append
+                 (delq nil
+                       (mapcar (lambda (x)
+                                 (pcase x
+                                   ;; If there's no vnew, do nothing.
+                                   (`(,_vold ,_getter ,setter ,vnew)
+                                    (funcall setter vnew))))
+                               binds))
+                 body))))
         `(let* (,@(mapcar (lambda (x)
                             (pcase-let ((`(,vold ,getter ,_setter ,_vnew) x))
                               (list vold getter)))
                           binds)
                 ,@simplebinds)
-           (unwind-protect
-               ,(macroexp-progn
-                 (append
-                  (delq nil
-                        (mapcar (lambda (x)
-                                  (pcase x
-                                    ;; If there's no vnew, do nothing.
-                                    (`(,_vold ,_getter ,setter ,vnew)
-                                     (funcall setter vnew))))
-                                binds))
-                  body))
-             ,@(mapcar (lambda (x)
-                         (pcase-let ((`(,vold ,_getter ,setter ,_vnew) x))
-                           (funcall setter vold)))
-                       binds))))
+           ,(if binds
+                `(unwind-protect ,body-form
+                   ,@(mapcar (lambda (x)
+                               (pcase-let ((`(,vold ,_getter ,setter ,_vnew) x))
+                                 (funcall setter vold)))
+                             binds))
+              body-form))))
     (let* ((binding (car bindings))
            (place (car binding)))
       (gv-letplace (getter setter) place