summaryrefslogtreecommitdiffstats
path: root/itypes.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-08-27 06:51:09 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-08-27 06:51:09 -0700
commitd990b667b33d853fcce6294364ae4232545742b0 (patch)
tree0042810b7fa853bc8eb88d84215ab56d6220ccd1 /itypes.h
parent1cf4652639d22e0e3ed7385e20cdcad6c5a6df2f (diff)
downloadtxr-d990b667b33d853fcce6294364ae4232545742b0.tar.gz
txr-d990b667b33d853fcce6294364ae4232545742b0.tar.bz2
txr-d990b667b33d853fcce6294364ae4232545742b0.zip
structs: deal with initialization diamond problem.
Until now it has been documented that if a struct type inherits a supertype two or more times, then the supertype initialization occurs that many times. This change fixes the behavior: bases are initialized once. * struct.c (struct struct_type): New members, ndsupers, dsus providing a flat array for tracking duplicate supertypes. (get_all_supers, get_duplicate_supers): New static functions. (make_struct_type): Calculate the duplicate supers, and store them in the dsus array. Under 242 or lower compat mode, pretend there are duplicates, which defeats the duplicate detecting mechanism (struct_type_destroy): Free the dsus array. (call_inittfun_chain, call_postinitfun_chain): Take new arguments: the root type from which the recursion started, and a stack-allocated bit vector indicating which duplicate bases have already been initialized. If the given type appears in the duplicate bases list of the root type, and its bit is already set, then skip all initialization for it. Otherwise set its bit and proceed. (alloc_seen, clear_seen): New macros to help with allocating the bitvector of duplicate bases. (make_struct_impl, lazy_struct_init, reset_struct): Use alloc_seen and clear_seen macros to manage the bitvector of duplicate bases for calling call_initfun_chain and call_postinitfun_chain. * txr.1: Updated doc with new paragraph about duplicated supertypes, and compat note added.
Diffstat (limited to 'itypes.h')
0 files changed, 0 insertions, 0 deletions