annotate lisp/find-gc.el @ 33980:3aa61201a0ab

(comment-indent): Save excursion around call to comment-indent-function.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 29 Nov 2000 05:11:01 +0000
parents 11218164bc54
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
1 ;;; find-gc.el --- detect functions that call the garbage collector
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
2
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
5 ;; Maintainer: FSF
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
6
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
7 ;; This file is part of GNU Emacs.
123
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
12 ;; any later version.
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
13
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
17 ;; GNU General Public License for more details.
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
18
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
19 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2230
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2230
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2230
diff changeset
22 ;; Boston, MA 02111-1307, USA.
123
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23
2230
6314334d7c2b Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
24 ;;; Commentary:
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
25
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2230
diff changeset
26 ;; Produce in unsafe-list the set of all functions that may invoke GC.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2230
diff changeset
27 ;; This expects the Emacs sources to live in emacs-source-directory.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2230
diff changeset
28 ;; It creates a temporary working directory /tmp/esrc.
123
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29
2230
6314334d7c2b Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
30 ;;; Code:
6314334d7c2b Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
31
123
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 (defun find-gc-unsafe ()
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 (trace-call-tree nil)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 (trace-use-tree)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 (find-unsafe-funcs 'Fgarbage_collect)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 (setq unsafe-list (sort unsafe-list
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 (function (lambda (x y)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 (string-lessp (car x) (car y))))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 (setq emacs-source-directory "/usr/gnu/src/dist/src")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ;;; This does a depth-first search to find all functions that can
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;;; ultimately call the function "target". The result is an a-list
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;;; in unsafe-list; the cars are the unsafe functions, and the cdrs
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 ;;; are (one of) the unsafe functions that these functions directly
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 ;;; call.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 (defun find-unsafe-funcs (target)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 (setq unsafe-list (list (list target)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 (trace-unsafe target)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (defun trace-unsafe (func)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (let ((used (assq func subrs-used)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 (or used
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (error "No subrs-used for %s" (car unsafe-list)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (while (setq used (cdr used))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 (or (assq (car used) unsafe-list)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 (memq (car used) noreturn-list)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 (progn
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 (setq unsafe-list (cons (cons (car used) func) unsafe-list))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 (trace-unsafe (car used))))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 ;;; Functions on this list are safe, even if they appear to be able
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 ;;; to call the target.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 (setq noreturn-list '( Fsignal Fthrow wrong_type_argument ))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 ;;; This produces an a-list of functions in subrs-called. The cdr of
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 ;;; each entry is a list of functions which the function in car calls.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 (defun trace-call-tree (&optional already-setup)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 (message "Setting up directories...")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 (or already-setup
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 (progn
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 ;; Gee, wouldn't a built-in "system" function be handy here.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 (call-process "csh" nil nil nil "-c" "rm -rf /tmp/esrc")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 (call-process "csh" nil nil nil "-c" "mkdir /tmp/esrc")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 (call-process "csh" nil nil nil "-c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 (format "ln -s %s/*.[ch] /tmp/esrc"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 emacs-source-directory))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 (save-excursion
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 (set-buffer (get-buffer-create "*Trace Call Tree*"))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (setq subrs-called nil)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (let ((case-fold-search nil)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 (files source-files)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 name entry)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 (while files
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 (message "Compiling %s..." (car files))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (call-process "csh" nil nil nil "-c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 (format "gcc -dr -c /tmp/esrc/%s -o /dev/null"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 (car files)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 (erase-buffer)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 (insert-file-contents (concat "/tmp/esrc/" (car files) ".rtl"))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 (while (re-search-forward ";; Function \\|(call_insn " nil t)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (if (= (char-after (- (point) 3)) ?o)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 (progn
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 (looking-at "[a-zA-Z0-9_]+")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (setq name (intern (buffer-substring (match-beginning 0)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 (match-end 0))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 (message "%s : %s" (car files) name)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 (setq entry (list name)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 subrs-called (cons entry subrs-called)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (if (looking-at ".*\n?.*\"\\([A-Za-z0-9_]+\\)\"")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 (progn
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 (setq name (intern (buffer-substring (match-beginning 1)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (match-end 1))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (or (memq name (cdr entry))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (setcdr entry (cons name (cdr entry))))))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (delete-file (concat "/tmp/esrc/" (car files) ".rtl"))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (setq files (cdr files)))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 ;;; This was originally generated directory-files, but there were
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 ;;; too many files there that were not actually compiled. The
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 ;;; list below was created for a HP-UX 7.0 system.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (setq source-files '("dispnew.c" "scroll.c" "xdisp.c" "window.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 "term.c" "cm.c" "emacs.c" "keyboard.c" "macros.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 "keymap.c" "sysdep.c" "buffer.c" "filelock.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 "insdel.c" "marker.c" "minibuf.c" "fileio.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 "dired.c" "filemode.c" "cmds.c" "casefiddle.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 "indent.c" "search.c" "regex.c" "undo.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 "alloc.c" "data.c" "doc.c" "editfns.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 "callint.c" "eval.c" "fns.c" "print.c" "lread.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 "abbrev.c" "syntax.c" "unexec.c" "mocklisp.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 "bytecode.c" "process.c" "callproc.c" "doprnt.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 "x11term.c" "x11fns.c"))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 ;;; This produces an inverted a-list in subrs-used. The cdr of each
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 ;;; entry is a list of functions that call the function in car.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 (defun trace-use-tree ()
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 (setq subrs-used (mapcar 'list (mapcar 'car subrs-called)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 (let ((ptr subrs-called)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 p2 found)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (while ptr
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 (setq p2 (car ptr))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 (while (setq p2 (cdr p2))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 (if (setq found (assq (car p2) subrs-used))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (setcdr found (cons (car (car ptr)) (cdr found)))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 (setq ptr (cdr ptr))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
152 (provide 'find-gc)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
153
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 123
diff changeset
154 ;;; find-gc.el ends here