GNU bug report logs - #13438
24.2.92; Infinite loop in python imenu support

Previous Next

Package: emacs;

Reported by: Ivan Andrus <darthandrus <at> gmail.com>

Date: Mon, 14 Jan 2013 21:00:02 UTC

Severity: important

Found in version 24.2.92

Done: Fabián Ezequiel Gallina <fabian <at> anue.biz>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 13438 in the body.
You can then email your comments to 13438 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#13438; Package emacs. (Mon, 14 Jan 2013 21:00:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ivan Andrus <darthandrus <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 14 Jan 2013 21:00:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ivan Andrus <darthandrus <at> gmail.com>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: 24.2.92; Infinite loop in python imenu support
Date: Mon, 14 Jan 2013 21:59:01 +0100
The following happens on the Emacs 24 branch as well as trunk.

From `emacs -Q`

In a new python buffer, insert 

def bob():
    return 3


and position the cursor before def.  Then run M-x imenu, and you get the
message 

imenu-default-create-index-function: Infinite loop at *scratch*:1:imenu-prev-index-position-function does not move point

-Ivan


In GNU Emacs 24.2.92.1 (i386-apple-darwin12.2.0, NS apple-appkit-1187.34)
 of 2013-01-14 on oroszlan.local
Bzr revision: 111176 jan.h.d <at> swipnet.se-20130113193605-626pw01y497yubsc
Windowing system distributor `Apple', version 10.3.1187
Configured using:
 `configure '--with-ns''

Important settings:
  value of $LC_CTYPE: UTF-8
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Python

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
d e f SPC b o b , , <backspace> <backspace> ( ) : <return> 
<tab> s-x C-g M-x p y t h <tab> <return> <tab> <tab> 
SPC SPC SPC <tab> d <backspace> r e t u r n SPC 5 <tab> 
<up> <up> <up> <up> <up> <up> C-a C-k C-k C-k C-k C-k 
C-k C-k <down> <tab> <tab> C-h k <tab> <tab> <up> <tab> 
M-x i m e <tab> <return> M-x r e p o r <tab> <retu
rn>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
kill-region: The mark is not set now, so there is no region
Quit
python-indent-line: Arithmetic error [4 times]
byte-code: Beginning of buffer
python-indent-line: Arithmetic error [2 times]
Type C-x 1 to delete the help window, C-M-v to scroll help.
python-indent-line: Arithmetic error [2 times]
imenu-default-create-index-function: Infinite loop at *scratch*:1: imenu-prev-index-position-function does not move point

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils imenu help-fns help-mode python rx easymenu comint
ring ansi-color time-date tooltip ediff-hook vc-hooks lisp-float-type
mwheel ns-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment lisp-mode register page menu-bar rfn-eshadow
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
make-network-process ns multi-tty emacs)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13438; Package emacs. (Mon, 21 Jan 2013 03:03:02 GMT) Full text and rfc822 format available.

Message #8 received at 13438 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Fabian Ezequiel Gallina <galli.87 <at> gmail.com>
Cc: Ivan Andrus <darthandrus <at> gmail.com>, 13438 <at> debbugs.gnu.org
Subject: Re: bug#13438: 24.2.92; Infinite loop in python imenu support
Date: Sun, 20 Jan 2013 22:01:34 -0500
Hi, could you look at this report please?

http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13438

Ivan Andrus wrote:

> The following happens on the Emacs 24 branch as well as trunk.
>
> From `emacs -Q`
>
> In a new python buffer, insert 
>
> def bob():
>     return 3
>
>
> and position the cursor before def.  Then run M-x imenu, and you get the
> message 
>
> imenu-default-create-index-function: Infinite loop at *scratch*:1:imenu-prev-index-position-function does not move point
>
> -Ivan
>
>
> In GNU Emacs 24.2.92.1 (i386-apple-darwin12.2.0, NS apple-appkit-1187.34)
>  of 2013-01-14 on oroszlan.local
> Bzr revision: 111176 jan.h.d <at> swipnet.se-20130113193605-626pw01y497yubsc
> Windowing system distributor `Apple', version 10.3.1187
> Configured using:
>  `configure '--with-ns''
>
> Important settings:
>   value of $LC_CTYPE: UTF-8
>   locale-coding-system: utf-8-unix
>   default enable-multibyte-characters: t
>
> Major mode: Python
>
> Minor modes in effect:
>   tooltip-mode: t
>   mouse-wheel-mode: t
>   tool-bar-mode: t
>   menu-bar-mode: t
>   file-name-shadow-mode: t
>   global-font-lock-mode: t
>   font-lock-mode: t
>   blink-cursor-mode: t
>   auto-composition-mode: t
>   auto-encryption-mode: t
>   auto-compression-mode: t
>   line-number-mode: t
>   transient-mark-mode: t
>
> Recent input:
> d e f SPC b o b , , <backspace> <backspace> ( ) : <return> 
> <tab> s-x C-g M-x p y t h <tab> <return> <tab> <tab> 
> SPC SPC SPC <tab> d <backspace> r e t u r n SPC 5 <tab> 
> <up> <up> <up> <up> <up> <up> C-a C-k C-k C-k C-k C-k 
> C-k C-k <down> <tab> <tab> C-h k <tab> <tab> <up> <tab> 
> M-x i m e <tab> <return> M-x r e p o r <tab> <retu
> rn>
>
> Recent messages:
> For information about GNU Emacs and the GNU system, type C-h C-a.
> kill-region: The mark is not set now, so there is no region
> Quit
> python-indent-line: Arithmetic error [4 times]
> byte-code: Beginning of buffer
> python-indent-line: Arithmetic error [2 times]
> Type C-x 1 to delete the help window, C-M-v to scroll help.
> python-indent-line: Arithmetic error [2 times]
> imenu-default-create-index-function: Infinite loop at *scratch*:1: imenu-prev-index-position-function does not move point
>
> Load-path shadows:
> None found.
>
> Features:
> (shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
> mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
> gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
> mail-prsvr mail-utils imenu help-fns help-mode python rx easymenu comint
> ring ansi-color time-date tooltip ediff-hook vc-hooks lisp-float-type
> mwheel ns-win tool-bar dnd fontset image regexp-opt fringe
> tabulated-list newcomment lisp-mode register page menu-bar rfn-eshadow
> timer select scroll-bar mouse jit-lock font-lock syntax facemenu
> font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan
> thai tai-viet lao korean japanese hebrew greek romanian slovak czech
> european ethiopic indian cyrillic chinese case-table epa-hook
> jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces
> cus-face macroexp files text-properties overlay sha1 md5 base64 format
> env code-pages mule custom widget hashtable-print-readable backquote
> make-network-process ns multi-tty emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13438; Package emacs. (Wed, 23 Jan 2013 21:59:02 GMT) Full text and rfc822 format available.

Message #11 received at 13438 <at> debbugs.gnu.org (full text, mbox):

From: Fabián Ezequiel Gallina <fabian <at> anue.biz>
To: 13438 <at> debbugs.gnu.org
Subject: 24.2.92; Infinite loop in python imenu support
Date: Wed, 23 Jan 2013 18:58:54 -0300
Fixed in revno 111196




bug closed, send any further explanations to 13438 <at> debbugs.gnu.org and Ivan Andrus <darthandrus <at> gmail.com> Request was from Fabián Ezequiel Gallina <fabian <at> anue.biz> to control <at> debbugs.gnu.org. (Wed, 23 Jan 2013 22:01:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13438; Package emacs. (Thu, 24 Jan 2013 18:02:01 GMT) Full text and rfc822 format available.

Message #16 received at 13438 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Fabián Ezequiel Gallina <fabian <at> anue.biz>
Cc: 13438 <at> debbugs.gnu.org
Subject: Re: /srv/bzr/emacs/emacs-24 r111196: * imenu.el
	(imenu-default-create-index-function): Remove useless
Date: Thu, 24 Jan 2013 13:01:17 -0500
>   * imenu.el (imenu-default-create-index-function): Remove useless
>   infinite loop check.
[...]
> --- a/lisp/imenu.el	2013-01-01 09:11:05 +0000
> +++ b/lisp/imenu.el	2013-01-23 21:55:46 +0000
> @@ -683,8 +683,6 @@
>  	   (goto-char (point-max))
>  	   ;; Search for the function
>  	   (while (funcall imenu-prev-index-position-function)
> -             (when (= pos (point))
> -               (error "Infinite loop at %s:%d: imenu-prev-index-position-function does not move point" (buffer-name) pos))
>               (setq pos (point))
>  	     (save-excursion
>  	       (setq name (funcall imenu-extract-index-name-function)))


I'm not keen on removing an infinite loop check from emacs-24 at this
stage. Why is this issue (apparently) only seen in Python mode, and why
isn't there a Python-specific solution (which seems like it would be
just making imenu-prev-index-position-function return nil when
appropriate)?

Related discussion:
http://lists.gnu.org/archive/html/emacs-devel/2013-01/msg00536.html




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13438; Package emacs. (Thu, 24 Jan 2013 18:31:02 GMT) Full text and rfc822 format available.

Message #19 received at 13438 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Fabián Ezequiel Gallina <fabian <at> anue.biz>,
	13438 <at> debbugs.gnu.org
Subject: Re: bug#13438: /srv/bzr/emacs/emacs-24 r111196: * imenu.el
	(imenu-default-create-index-function): Remove useless
Date: Thu, 24 Jan 2013 13:30:16 -0500
> I'm not keen on removing an infinite loop check from emacs-24 at this
> stage.

The patch is "safe" in the sense that it will only introduce
an inf-loop in those cases where the user used to get an error.
[ Unless of course, the calling context catches those errors.  ]

> Why is this issue (apparently) only seen in Python mode, and why
> isn't there a Python-specific solution (which seems like it would be
> just making imenu-prev-index-position-function return nil when
> appropriate)?

If we can change python.el to work around the problem, we could install
that workaround in emacs-24 and keep the "remove the inf-loop check" for
the trunk, indeed.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13438; Package emacs. (Fri, 25 Jan 2013 08:36:01 GMT) Full text and rfc822 format available.

Message #22 received at 13438 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Fabián Ezequiel Gallina <fabian <at> anue.biz>,
	13438 <at> debbugs.gnu.org
Subject: Re: bug#13438: /srv/bzr/emacs/emacs-24 r111196: * imenu.el
	(imenu-default-create-index-function): Remove useless
Date: Fri, 25 Jan 2013 03:34:53 -0500
>> Why is this issue (apparently) only seen in Python mode

Answering my own question, it happens in any mode that sets
imenu-prev-index-position-function and
imenu-extract-index-name-function, but there are very few of those.

Eg prolog mode. With buffer contents:

------
fac(0,1).
fac(N,F) :- N > 0, M is N - 1,
       fac(M,Fm), F is N * Fm.
------

and point at point-min, switching to prolog-mode causes the same issue.

How about taking the more cautious approach with:

(when (and (= pos (point))
           (not (bobp)))
   (error "Infinite loop... ))

(IIUC, this was actually the suggestion in
http://lists.gnu.org/archive/html/emacs-devel/2013-01/msg00510.html ?)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13438; Package emacs. (Fri, 25 Jan 2013 13:55:02 GMT) Full text and rfc822 format available.

Message #25 received at 13438 <at> debbugs.gnu.org (full text, mbox):

From: Fabián Ezequiel Gallina <fabian <at> anue.biz>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 13438 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#13438: /srv/bzr/emacs/emacs-24 r111196: * imenu.el
	(imenu-default-create-index-function): Remove useless
Date: Fri, 25 Jan 2013 10:55:57 -0300
[Message part 1 (text/plain, inline)]
On 01/25/2013 05:34 AM, Glenn Morris wrote:
>>> Why is this issue (apparently) only seen in Python mode
> Answering my own question, it happens in any mode that sets
> imenu-prev-index-position-function and
> imenu-extract-index-name-function, but there are very few of those.
>
> Eg prolog mode. With buffer contents:
>
> ------
> fac(0,1).
> fac(N,F) :- N > 0, M is N - 1,
>         fac(M,Fm), F is N * Fm.
> ------
>
> and point at point-min, switching to prolog-mode causes the same issue.
>
> How about taking the more cautious approach with:
>
> (when (and (= pos (point))
>             (not (bobp)))
>     (error "Infinite loop... ))
>
> (IIUC, this was actually the suggestion in
> http://lists.gnu.org/archive/html/emacs-devel/2013-01/msg00510.html ?)
I ran into the same thing, and checking bobp is not enough, try adding a 
newline at the beginning of file to the recipe and call imenu with point 
at beginning of defun and you'll see the infinite error check will trigger.

I proposed the following patch that works:

=== modified file 'lisp/imenu.el'
--- lisp/imenu.el       2013-01-01 09:11:05 +0000
+++ lisp/imenu.el       2013-01-22 18:24:45 +0000
@@ -683,7 +683,14 @@
           (goto-char (point-max))
           ;; Search for the function
           (while (funcall imenu-prev-index-position-function)
-             (when (= pos (point))
+             (when (and (= pos (point))
+                        (= pos
+                           (save-excursion
+                             ;; The infinite loop is true if there's
+                             ;; another index position but point keeps
+                             ;; itself in the same place. bug#13438
+                             (if (funcall imenu-prev-index-position-
function)
+                                 (point) 0))))

But finally after some mails with Stefan we decided the best thing will 
be to remove this check altogether.

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13438; Package emacs. (Sun, 27 Jan 2013 02:14:01 GMT) Full text and rfc822 format available.

Message #28 received at 13438 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Fabián Ezequiel Gallina <fabian <at> anue.biz>
Cc: 13438 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#13438: /srv/bzr/emacs/emacs-24 r111196: * imenu.el
	(imenu-default-create-index-function): Remove useless
Date: Sat, 26 Jan 2013 21:12:50 -0500
Oh, so the actual issue is: if you call
imenu-default-create-index-function with point at the start of the last
defun in the buffer. It goes to point-max, then back to the start of the
defun, and mistakenly thinks it is inflooping.

How about the following, which only signals an error if
imenu-prev-index-position-function returns non-nil twice in a row
without moving point.

BTW, neither python-nav-beginning-of-defun or
python-imenu-prev-index-position will move past the start of the first
defun in a buffer, if the defun begins past point-min (ie, if there are
blank lines before the first defun, it does not move over them to
point-min). I don't know if this matters, but it is inconsistent with eg
Prolog and Emacs Lisp modes.


*** lisp/imenu.el	2013-01-23 21:55:46 +0000
--- lisp/imenu.el	2013-01-27 02:02:39 +0000
***************
*** 678,688 ****
    ;; in these major modes.  But save that change for later.
    (cond ((and imenu-prev-index-position-function
  	      imenu-extract-index-name-function)
! 	 (let ((index-alist '()) (pos (point))
  	       name)
  	   (goto-char (point-max))
  	   ;; Search for the function
  	   (while (funcall imenu-prev-index-position-function)
               (setq pos (point))
  	     (save-excursion
  	       (setq name (funcall imenu-extract-index-name-function)))
--- 678,690 ----
    ;; in these major modes.  But save that change for later.
    (cond ((and imenu-prev-index-position-function
  	      imenu-extract-index-name-function)
! 	 (let ((index-alist '()) (pos -1)
  	       name)
  	   (goto-char (point-max))
  	   ;; Search for the function
  	   (while (funcall imenu-prev-index-position-function)
+              (when (= pos (point))
+                (error "Infinite loop at %s:%d: imenu-prev-index-position-function does not move point" (buffer-name) pos))
               (setq pos (point))
  	     (save-excursion
  	       (setq name (funcall imenu-extract-index-name-function)))





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 24 Feb 2013 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 72 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.