mirror of
https://github.com/boostorg/build.git
synced 2026-02-14 12:42:11 +00:00
Prevent already registered type error.
A type can be registered as inheriting from a base type, however, due to lazy loading, it's possible for that base type to not have been registered yet. Originally, calling type.register() with an unregistered base type would have registered the base type. Later, when the base type itself was registered, an error would have been raised saying that the base type was already registered. This change allows for lazy loading to occur such that a base type can be registered after a subtype is has already inherited from it.
This commit is contained in:
@@ -71,14 +71,19 @@ def register (type, suffixes = [], base_type = None):
|
||||
if __re_hyphen.search (type):
|
||||
raise BaseException ('type name "%s" contains a hyphen' % type)
|
||||
|
||||
if type in __types:
|
||||
# it's possible for a type to be registered with a
|
||||
# base type that hasn't been registered yet. in the
|
||||
# check for base_type below and the following calls to setdefault()
|
||||
# the key `type` will be added to __types. When the base type
|
||||
# actually gets registered, it would fail after the simple check
|
||||
# of "type in __types"; thus the check for "'base' in __types[type]"
|
||||
if type in __types and 'base' in __types[type]:
|
||||
raise BaseException ('Type "%s" is already registered.' % type)
|
||||
|
||||
entry = {}
|
||||
entry ['base'] = base_type
|
||||
entry ['derived'] = []
|
||||
entry ['scanner'] = None
|
||||
__types [type] = entry
|
||||
entry = __types.setdefault(type, {})
|
||||
entry['base'] = base_type
|
||||
entry.setdefault('derived', [])
|
||||
entry.setdefault('scanner', None)
|
||||
|
||||
if base_type:
|
||||
__types.setdefault(base_type, {}).setdefault('derived', []).append(type)
|
||||
|
||||
Reference in New Issue
Block a user