diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-08-27 07:28:36 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-08-27 07:28:36 -0700 |
commit | b46add7c71d8c0399901926ac014fd9338e0f371 (patch) | |
tree | d0162f3492f083534fc75c17edb00b845ce27d01 /struct.c | |
parent | 5e59559f324c25581984f47bb341f3ebbafa9329 (diff) | |
download | txr-b46add7c71d8c0399901926ac014fd9338e0f371.tar.gz txr-b46add7c71d8c0399901926ac014fd9338e0f371.tar.bz2 txr-b46add7c71d8c0399901926ac014fd9338e0f371.zip |
OOP: use chk_calloc for objects.
* struct.c (make_struct_impl, make_lazy_struct): Use
chk_calloc instead of chk_malloc for allocating objects.
Remove the loops that initialize slots to nil.
Remove the initialization of the lazy flag to zero.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -753,9 +753,9 @@ static val make_struct_impl(val self, val type, struct args *plist, struct args *args) { struct struct_type *st = stype_handle(&type, self); - cnum nslots = st->nslots, sl; + cnum nslots = st->nslots; size_t size = offsetof(struct struct_inst, slot) + sizeof (val) * nslots; - struct struct_inst *si = coerce(struct struct_inst *, chk_malloc(size)); + struct struct_inst *si = coerce(struct struct_inst *, chk_calloc(1, size)); val sinst; volatile val inited = nil; alloc_seen (seen, seensz); @@ -767,11 +767,8 @@ static val make_struct_impl(val self, val type, self, type, nao); } - for (sl = 0; sl < nslots; sl++) - si->slot[sl] = nil; si->type = st; si->id = st->id; - si->lazy = 0; si->dirty = 1; sinst = cobj(coerce(mem_t *, si), st->name, &struct_inst_ops); @@ -887,14 +884,12 @@ val make_lazy_struct(val type, val argfun) { val self = lit("make-lazy-struct"); struct struct_type *st = stype_handle(&type, self); - cnum nslots = st->nslots, sl; + cnum nslots = st->nslots; cnum nalloc = nslots ? nslots : 1; size_t size = offsetof(struct struct_inst, slot) + sizeof (val) * nalloc; - struct struct_inst *si = coerce(struct struct_inst *, chk_malloc(size)); + struct struct_inst *si = coerce(struct struct_inst *, chk_calloc(1, size)); val sinst; - for (sl = 0; sl < nslots; sl++) - si->slot[sl] = nil; si->type = st; si->id = st->id; si->lazy = 1; |