Skip to content
  • Nat Goodspeed's avatar
    DRTVWR-493: Defend LL[Param]Singleton against ctor/init exceptions. · 54b98cb8
    Nat Goodspeed authored
    An exception in the LLSingleton subclass constructor, or in its
    initSingleton() method, could leave the LLSingleton machinery in a bad state:
    the failing instance would remain in the MasterList, also on the stack of
    initializing LLSingletons. Catch exceptions in either and perform relevant
    cleanup.
    
    This problem is highlighted by test programs, in which LL_ERRS throws an
    exception rather than crashing the whole process.
    
    In the relevant catch clauses, clean up the initializing stack BEFORE logging.
    Otherwise we get tangled up recording bogus dependencies.
    
    Move capture_dependency() out of finishInitializing(): it must be called by
    every valid getInstance() call, both from LLSingleton and LLParamSingleton.
    
    Introduce new CONSTRUCTED EInitState value to distinguish "have called the
    constructor but not yet the initSingleton() method" from "currently within
    initSingleton() method." This is transient, but we execute the 'switch' on
    state within that moment. One could argue that the previous enum used
    INITIALIZING for current CONSTRUCTED, and INITIALIZED meant INITIALIZING too,
    but this is clearer.
    
    Introduce template LLSingletonBase::classname() helper methods to clarify
    verbose demangle(typeid(stuff).name()) calls.
    
    Similarly, introduce LLSingleton::pop_initializing() shorthand method.
    54b98cb8