summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-12-01 06:22:10 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-12-01 06:22:10 -0800
commit4e92c2d19382340d8e6c8fe71013d02bbc6065f4 (patch)
treee146a1e44d81a8b1b4bb3ea070d72a16c7527680
parent121a9209a20d5789f693c77e4fbe74522506f74d (diff)
downloadtxr-4e92c2d19382340d8e6c8fe71013d02bbc6065f4.tar.gz
txr-4e92c2d19382340d8e6c8fe71013d02bbc6065f4.tar.bz2
txr-4e92c2d19382340d8e6c8fe71013d02bbc6065f4.zip
Bugfix: structs not inheriting late static slot values.
This bug doesn't affect static slots that are defined in defstruct, because those get initialized in the new type by the static init function. The bug is that the values of static slots added later with static_slot_ensure are not inherited by subtypes that are created later still. (Since static_slot_ensure propagates a slot to subtypes which already exist, those types get the slot value.) * struct.c (make_struct_type): Copy the contents of the static slot array of the supertype into the new type, so that static slot values are inherited. We can just use memcpy because the ordering of static slots is the same in the new type, and the inherited ones precede the new ones, due to the way the all_slots list is combined. * txr.1: Clarify inheritance of static slots.
-rw-r--r--struct.c4
-rw-r--r--txr.129
2 files changed, 27 insertions, 6 deletions
diff --git a/struct.c b/struct.c
index bbe8584f..9ac312aa 100644
--- a/struct.c
+++ b/struct.c
@@ -276,8 +276,10 @@ val make_struct_type(val name, val super,
sethash(struct_type_hash, name, stype);
- if (super)
+ if (super) {
mpush(stype, mkloc(su->dvtypes, super));
+ memcpy(st->stslot, su->stslot, sizeof (val) * su->nstslots);
+ }
call_stinitfun_chain(st, stype);
diff --git a/txr.1 b/txr.1
index 9ff4b35f..9d6faf8b 100644
--- a/txr.1
+++ b/txr.1
@@ -18249,8 +18249,17 @@ but are of a different kind: an instance slot in the supertype
can be replaced by a static slot in the derived type or vice versa.
A structure type is associated with a static initialization function
-which may be used to store initial values into static slots. It is
-invoked when the type is created.
+which may be used to store initial values into static slots. This function
+is invoked once in a type's life time, when the type is created.
+The function is also inherited by derived struct types and invoked when
+they are created.
+
+If a newly introduced (that is to say, non-inherited) static slot isn't
+initialized by the static initialization function, its value defaults to
+.codn nil .
+If an inherited slot isn't initialized by its supertype's initialization
+function, then its initial value in the new type is a copy of the current
+value of the supertype's corresponding slot.
.NP* Functors
@@ -19103,8 +19112,8 @@ de-duplicating the resulting list as if by the
function. Thus, any slots which are already present in the supertype are
removed. If the structure has no supertype, then the list of supertype
slots is taken to be empty. When a structure is instantiated, it shall have all
-the slots specified in the effective list of slots, each slot initialized to
-the value
+the slots specified in the effective list of slots. Each instance slot
+shall be initialized to the value
.codn nil ,
prior to the invocation of
.meta initfun
@@ -19117,7 +19126,17 @@ argument either specifies an initialization function, or is
.codn nil ,
which is equivalent to specifying a function which does nothing.
-If specified, this function must
+Prior to the invocation of
+.metn static-initfun ,
+each new static slot shall be initialized to the value
+.code nil
+and each inherited static slot shall be initialized to
+the current value which the corresponding static slot
+holds in the supertype.
+
+If specified,
+.meta static-initfun
+function must
accept one argument. When the structure type is created (before
the
.code make-struct-type