Matthias Rinck wrote on Wed, Dec 04, 2002 at 03:44:29PM +0100: 
> Hello,
> 
> is it possible to redefine a structure without getting an error-message?
> 
> 1) (defstruct x a b)
> 2) (defstruct x a b c) -> error ... [CLOBBER-IT] Smash current layout,
> preserving old code

I once sent a patch which introduces a variable which will make it
default to the redefition without user interaction.

I still think it is a good idea to commit it.

Martin


-- Attached file included as plaintext by Listar --

Index: defstruct.lisp
===================================================================
RCS file: /fares/projects/cmucl/src/code/defstruct.lisp,v
retrieving revision 1.1.1.4
retrieving revision 1.2
diff -u -r1.1.1.4 -r1.2
--- defstruct.lisp      2002/08/26 14:30:19     1.1.1.4
+++ defstruct.lisp      2002/10/09 23:11:41     1.2
@@ -31,12 +31,18 @@
          dd-predicate dd-slots dd-length dd-type dd-raw-index dd-raw-length
          defstruct-slot-description dsd-name dsd-%name dsd-accessor dsd-type
          dsd-index dsd-raw-type dsd-read-only undefine-structure
+         *struct-redefinition-shutup-p*
          *ansi-defstruct-options-p*))
 
 
 (defparameter *ANSI-defstruct-options-p* nil
   "Controls compiling DEFSTRUCT :print-function and :print-method
    options according to ANSI spec. MUST be NIL to compile CMUCL & PCL")
+
+(defparameter *struct-redefinition-shutup-p* nil
+  "Should CMUCL ask interactively when redefiniting a struct in an
+   incompatible way? ITA only variable, CMUCL default is nil")
+
 
 ;;;; Structure frobbing primitives.
 
@@ -1539,6 +1545,14 @@
 (defun %redefine-defstruct (class old-layout new-layout)
   (declare (type class class) (type layout old-layout new-layout))
   (let ((name (class-proper-name class)))
+    (when *struct-redefinition-shutup-p*
+      (warn "Redefinition of struct ~s in incompatible way.  Be sure to do a
+             complete recompile" name)
+      ;; NOTE: line below says destruct-layout, not defstruct-layout.
+      ;; Nice trap...
+      (register-layout new-layout :invalidate nil :destruct-layout old-layout)
+      ;; be CVS merge friendly so we don't reindent code below
+      (return-from %redefine-defstruct (undefined-value)))
     (restart-case
        (error "Redefining class ~S incompatibly with the current ~
                definition."



Reply via email to