chiark / gitweb /
src/class-{finalize,layout}-impl.lisp: Error checking on layout slots.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 30 Aug 2015 09:58:38 +0000 (10:58 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 14 Sep 2015 09:34:14 +0000 (10:34 +0100)
The layout slots which are autovivifying (`effective-methods',
`%ilayout', and `vtables') shouldn't be accessed prior to class
finalization, so gather their definitions together and check that this
is done properly.

src/class-finalize-impl.lisp
src/class-layout-impl.lisp

index 9e7541275750336d5294b8ff7d9f00f6d078b2b2..9c34bd7c46767d71fc07989e6429198605012dce 100644 (file)
@@ -391,4 +391,18 @@ (defmethod finalize-sod-class ((class sod-class))
       (:finalized
        t))))
 
+(macrolet ((define-layout-slot (slot (class) &body body)
+            `(define-on-demand-slot sod-class ,slot (,class)
+               (check-class-is-finalized ,class)
+               ,@body)))
+  (flet ((check-class-is-finalized (class)
+          (unless (eq (sod-class-state class) :finalized)
+            (error "Class ~S is not finalized" class))))
+    (define-layout-slot %ilayout (class)
+      (compute-ilayout class))
+    (define-layout-slot effective-methods (class)
+      (compute-effective-methods class))
+    (define-layout-slot vtables (class)
+      (compute-vtables class))))
+
 ;;;----- That's all, folks --------------------------------------------------
index 8edfcf6c05625f88e9b29bc6bdb039f03a6c6d84..7a2d9ccb0b07a76aae1a6b8bc3c93d6d4bdd60f3 100644 (file)
@@ -129,9 +129,6 @@ (defmethod compute-effective-methods ((class sod-class))
                    (sod-class-messages super)))
          (sod-class-precedence-list class)))
 
-(define-on-demand-slot sod-class effective-methods (class)
-  (compute-effective-methods class))
-
 ;;;--------------------------------------------------------------------------
 ;;; Instance layout.
 
@@ -204,9 +201,6 @@ (defmethod compute-ilayout ((class sod-class))
                                                    (reverse chain)))
                                  (sod-class-chains class))))
 
-(define-on-demand-slot sod-class %ilayout (class)
-  (compute-ilayout class))
-
 ;;;--------------------------------------------------------------------------
 ;;; Vtable layout.
 
@@ -384,7 +378,4 @@ (defmethod compute-vtables ((class sod-class))
            (compute-vtable class (reverse chain)))
          (sod-class-chains class)))
 
-(define-on-demand-slot sod-class vtables (class)
-  (compute-vtables class))
-
 ;;;----- That's all, folks --------------------------------------------------