diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-04-29 19:31:27 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2019-04-30 11:52:59 +0000 |
commit | 60bbe8daa1995b471aa69e234a4d39d61525adbd (patch) | |
tree | d48f6fba8015349021a92fd250c89a730111ab9c | |
parent | 0c064be9a7af972946dc8aa1d9daf63d4527cf4e (diff) | |
download | buildstream-60bbe8daa1995b471aa69e234a4d39d61525adbd.tar.gz |
plugin.py: Start plugin ID counter at ID 1
This was always intended, but was not well commented. The reason
we start plugin ID counters at 1 is that we prefer relying on
a falsy value to determine whether an ID holding variable has
been set or not.
This patch also adds a more informative assertion in Plugin._lookup()
This by itself essentially fixes #1012
-rw-r--r-- | buildstream/plugin.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 5fdcdaeb8..fe4c0c0d0 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -187,8 +187,12 @@ class Plugin(): # Unique id generator for Plugins # # Each plugin gets a unique id at creation. - # Ids are a monotically increasing integer - __id_generator = itertools.count() + # + # Ids are a monotically increasing integer which + # starts as 1 (a falsy plugin ID is considered unset + # in various parts of the codebase). + # + __id_generator = itertools.count(1) # Hold on to a lookup table by counter of all instantiated plugins. # We use this to send the id back from child processes so we can lookup @@ -756,6 +760,7 @@ class Plugin(): # @classmethod def _lookup(cls, unique_id): + assert unique_id != 0, "Looking up invalid plugin ID 0, ID counter starts at 1" try: return cls.__TABLE[unique_id] except KeyError: |