source: branches/streams/abcl/src/org/armedbear/lisp/fdefinition.lisp

Last change on this file was 14451, checked in by Mark Evenson, 12 years ago

Loosen check for issuing redfinition from TRUENAME to PROBE-FILENAME.

Under no condition should we be promoting what should be a warning to
an error if the truename fails. In any event, the function
redefinition check still has corner cases, for example when used with
JAR-PATHNAME, that need to be (eventually) nailed down.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1;;; fdefinition.lisp
2;;;
3;;; Copyright (C) 2005-2006 Peter Graves
4;;; $Id: fdefinition.lisp 14451 2013-03-27 14:35:18Z mevenson $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19;;;
20;;; As a special exception, the copyright holders of this library give you
21;;; permission to link this library with independent modules to produce an
22;;; executable, regardless of the license terms of these independent
23;;; modules, and to copy and distribute the resulting executable under
24;;; terms of your choice, provided that you also meet, for each linked
25;;; independent module, the terms and conditions of the license of that
26;;; module.  An independent module is a module which is not derived from
27;;; or based on this library.  If you modify this library, you may extend
28;;; this exception to your version of the library, but you are not
29;;; obligated to do so.  If you do not wish to do so, delete this
30;;; exception statement from your version.
31
32(in-package #:system)
33
34(export '(record-source-information untraced-function))
35
36(defun check-redefinition (name)
37  (when (and *warn-on-redefinition* (fboundp name) (not (autoloadp name)))
38    (when (and (symbolp name)
39               (source-pathname name))
40      ;; SOURCE-PATHNAME is badly named as it is either a PATHNAMAE
41      ;; or the symbol :TOP-LEVEL
42      (let ((old-source 
43             (if (keywordp (source-pathname name))
44                 (source-pathname name)
45                 (probe-file (source-pathname name))))
46            (current-source 
47             (if (not *source*) 
48                 :top-level
49                 (probe-file *source*))))
50        (cond ((equal old-source 
51                      current-source)) ; OK
52              (t
53               (if (eq current-source :top-level)
54                   (style-warn "redefining ~S at top level" name)
55                   (let ((*package* +cl-package+))
56                     (if (eq old-source :top-level)
57                         (style-warn "redefining ~S in ~S (previously defined at top level)"
58                                     name current-source)
59                         (style-warn "redefining ~S in ~S (previously defined in ~S)"
60                                     name current-source old-source))))))))))
61
62(defun record-source-information (name &optional source-pathname source-position)
63  (unless source-pathname
64    (setf source-pathname (or *source* :top-level)))
65  (unless source-position
66    (setf source-position *source-position*))
67  (let ((source (if source-position
68                    (cons source-pathname source-position)
69                    source-pathname)))
70    (cond ((symbolp name)
71           (put name '%source source)))))
72
73;; Redefined in trace.lisp.
74(defun trace-redefined-update (&rest args)
75  (declare (ignore args))
76  )
77
78;; Redefined in trace.lisp.
79(defun untraced-function (name)
80  (declare (ignore name))
81  nil)
82
83(defun fset (name function &optional source-position arglist documentation)
84  (cond ((symbolp name)
85         (check-redefinition name)
86         (record-source-information name nil source-position)
87         (when arglist
88           (%set-arglist function arglist))
89         (%set-documentation function 'function documentation)
90         (%set-symbol-function name function))
91        ((setf-function-name-p name)
92         (check-redefinition name)
93         (record-source-information name nil source-position)
94         ;; FIXME arglist documentation
95         (setf (get (%cadr name) 'setf-function) function))
96        (t
97         (require-type name '(or symbol (cons (eql setf) (cons symbol null))))))
98  (when (functionp function) ; FIXME Is this test needed?
99    (%set-lambda-name function name))
100  (trace-redefined-update name function)
101  function)
102
103(defun fdefinition (name)
104  (cond ((symbolp name)
105         (symbol-function name))
106        ((setf-function-name-p name)
107         (or (get (%cadr name) 'setf-function)
108             (error 'undefined-function :name name)))
109        (t
110         (require-type name '(or symbol (cons (eql setf) (cons symbol null)))))))
111
112(defun %set-fdefinition (name function)
113  (fset name function))
114
115(defsetf fdefinition %set-fdefinition)
Note: See TracBrowser for help on using the repository browser.