chiark / gitweb /
Compatibility: the `init' function no longer calls `imprint' for you.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 7 May 2016 13:45:18 +0000 (14:45 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 14:09:03 +0000 (15:09 +0100)
It will make much less sense later.

doc/concepts.tex
doc/structures.tex
lib/sod-structs.3
lib/sod.h
src/builtin.lisp

index 74e5902669dab0a07d1be151d2831b0af8b4a072..166393904aba37669bd288894507789e8cf5289a 100644 (file)
@@ -727,7 +727,7 @@ linking it into some larger data structure to keep track of it.
 Classes can declare initial values for their slots.  A class object's @|init|
 slot points to a function which will establish the appropriate initial values
 for a new instance's slots.  Slots are not initialized in any particularly
-useful order.  The @|init| function also imprints the instance storage.
+useful order.
 
 The provided initialization protocol is extremely simplistic; most notably,
 it's not possible to pass parameters into the initialization process.
@@ -743,6 +743,7 @@ returns a pointer to the new instance.
   \{ \\ \ind
     void *p = malloc(c@->cls.initsz); \\
     if (!p) return (0); \\
+    c@->cls.imprint(p); \\
     c@->cls.init(p); \\
     return (p); \- \\
   \}
index 0b6be0a7bd250b82d3345ed5ce4ebf73fb411702..c8d9dafdfd457e83f3b5a2a1f8c755b8a8596ba3 100644 (file)
@@ -173,11 +173,9 @@ recommended.
     the vtable and class pointers are properly initialized, but the slots are
     left untouched.  The function returns its argument @<p>.
 
-  \item[init] A pointer to a function: given a pointer @<p> to at least
-    @<initsz> bytes of appropriately aligned memory, initialize an instance
-    of the class in it: all of the vtable and class pointers are initialized,
-    as are slots for which initializers are defined.  Other slots are left
-    untouched.  The function returns its argument @<p>.
+  \item[init] A pointer to a function: given a pointer @<p> to an imprinted
+    instance, initialize all of its slots for which initializers are defined.
+    Other slots are left untouched.  The function returns its argument @<p>.
 
   \item[n_supers] The number of direct superclasses.  (This is zero exactly
     in the case of @|SodObject|.)
index 0ef69ca01bdc3dd412aa80599b5c89e4c8f70bff..2d4ecd184a3c913c33e24644dd075efcf5df74db 100644 (file)
@@ -271,12 +271,8 @@ The function returns its argument
 A pointer to a function:
 given a pointer
 .I p
-to at least
-.I initsz
-bytes of appropriately aligned memory,
-initialize an instance of the class in it:
-all of the vtable and class pointers are initialized,
-as are slots for which initializers are defined.
+to an imprinted instance,
+initialize all of its slots for which initializers are defined.
 Other slots are left untouched.
 The function returns its argument
 .IR p .
index 2705dcc71c0c27a976b2145945e289aa348890a1..e0e9193997d907611fdd6c8bf1822cf74044c46c 100644 (file)
--- a/lib/sod.h
+++ b/lib/sod.h
@@ -238,7 +238,8 @@ struct sod_chain {
 
 #define SOD_DECL(cls_, var_)                                           \
   struct cls_##__ilayout var_##__layout;                               \
-  cls_ *var_ = cls_##__class->cls.init(&var_##__layout)
+  cls_ *var_ =                                                         \
+    cls_##__class->cls.init(cls_##__class->cls.imprint(&var_##__layout))
 
 /*----- Functions provided ------------------------------------------------*/
 
index e4b42de7665ce27bf9d64e637af15b0699b4470c..1073cae0a47e77e4f58d4af212051cbd21ddda2a 100644 (file)
@@ -114,8 +114,7 @@ (define-class-slot "init" (class stream)
   (format nil "~A__init" class)
 
   ;; FIXME this needs a metaobject protocol
-  (let ((ilayout (sod-class-ilayout class))
-       (used nil))
+  (let ((ilayout (sod-class-ilayout class)))
     (format stream "~&~:
 /* Provide initial values for an instance's slots. */
 static void *~A__init(void *p)~%{~%" class)
@@ -135,11 +134,6 @@ (define-class-slot "init" (class stream)
                 (let ((dslot (effective-slot-direct-slot slot))
                       (init (effective-slot-initializer slot)))
                   (when init
-                    (unless used
-                      (format stream
-                              "  struct ~A *sod__obj = ~A__imprint(p);~2%"
-                              (ilayout-struct-tag class) class)
-                      (setf used t))
                     (format stream "  {~%    ")
                     (pprint-c-type (sod-slot-type dslot) stream
                                    *sod-tmp-val*)
@@ -149,8 +143,6 @@ (define-class-slot "init" (class stream)
                             (sod-initializer-value init)
                             isl (sod-slot-name dslot)
                             *sod-tmp-val*))))))))))
-    (unless used
-      (format stream "  ~A__imprint(p);~%" class))
     (format stream "~&~:
   return (p);
 }~2%")))