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
diff --git a/buildstream/plugin.py b/buildstream/plugin.py
index 2c94c21..307aefa 100644
--- a/buildstream/plugin.py
+++ b/buildstream/plugin.py
@@ -149,8 +149,12 @@
# 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 @@
#
@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]