summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-04-29 19:31:27 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-04-29 19:34:18 +0900
commit0312f051fe78d620a56371c7c07fce40c52a510e (patch)
tree0b48176dad2aa7d0aa4d06c7d63042a9b39ea5e5
parent162c4166ce011f8dfca265549e6a343101a129aa (diff)
downloadbuildstream-0312f051fe78d620a56371c7c07fce40c52a510e.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.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/buildstream/plugin.py b/buildstream/plugin.py
index 2c94c212c..307aefa69 100644
--- a/buildstream/plugin.py
+++ b/buildstream/plugin.py
@@ -149,8 +149,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
@@ -656,6 +660,7 @@ class Plugin():
#
@classmethod
def _lookup(cls, unique_id):
+ assert unique_id != 0, "Looking up invalid plugin ID 0, ID counter starts at 1"
assert unique_id in cls.__TABLE, "Could not find plugin with ID {}".format(unique_id)
return cls.__TABLE[unique_id]