Subject: Re: bug#16671: 24.3; cl-lib from ELPA defadvices cl-position into infinite loop

From: Stefan Monnier <[email-masked]>
Date: Wed, 19 Feb 2014 14:37:53 -0500

> emacs -Q --eval "(progn (package-initialize t) (package-install
> 'cl-lib) (require 'cl) (position 1 '(1)))"
> *Messages* buffer contains
>   apply: Variable binding depth exceeds max-specpdl-size

Indeed.  Could you try the patch below and confirm if it fixes the
problem for you?

        Stefan

diff --git a/packages/cl-lib/cl-lib.el b/packages/cl-lib/cl-lib.el
index 1ea22e0..cf13c56 100644
--- a/packages/cl-lib/cl-lib.el
+++ b/packages/cl-lib/cl-lib.el
@@ -318,25 +327,27 @@
           (message "%S already defined, not rebinding" new))
       (defalias new fun))))
 
-(autoload 'cl-position "cl-seq")
-(defadvice cl-position (around cl-lib (cl-item cl-seq &rest cl-keys) activate)
+(unless (symbolp (symbol-function 'position))
+  (autoload 'cl-position "cl-seq")
+  (defadvice cl-position (around cl-lib (cl-item cl-seq &rest cl-keys) activate)
   (let ((argk (ad-get-args 2)))
     (if (or (null argk) (keywordp (car argk)))
         ;; This is a call to cl-lib's `cl-position'.
         (setq ad-return-value
               (apply #'position (ad-get-arg 0) (ad-get-arg 1) argk))
       ;; Must be a call to cl's old `cl-position'.
-      ad-do-it)))
+      ad-do-it))))
 
-(autoload 'cl-delete-duplicates "cl-seq")
-(defadvice cl-delete-duplicates (around cl-lib (cl-seq &rest cl-keys) activate)
+(unless (symbolp (symbol-function 'delete-duplicates))
+  (autoload 'cl-delete-duplicates "cl-seq")
+  (defadvice cl-delete-duplicates (around cl-lib (cl-seq &rest cl-keys) activate)
   (let ((argk (ad-get-args 1)))
     (if (or (null argk) (keywordp (car argk)))
         ;; This is a call to cl-lib's `cl-delete-duplicates'.
         (setq ad-return-value
               (apply #'delete-duplicates (ad-get-arg 0) argk))
       ;; Must be a call to cl's old `cl-delete-duplicates'.
-      ad-do-it)))
+      ad-do-it))))
 
 (when (or (not (fboundp 'cl-member))
           (eq (symbol-function 'cl-member) #'memq))