Skip to contentSkip to conversation

providers: use local variable for packages_dynamic pattern

PATCH In review Matt Madison 2 participants 3 messages Apr 18, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 providers: use local variable for packages_dynamic pattern

During parsing, Python raises

RuntimeError: dictionary changed size during iteration

in getRuntimeProviders, if you happen to have a recipe with an explicit RDEPENDS on a dynamic package containing a '+' character, such as 'gtk+3-locale-en'.

This is because we're using the modified pattern as the key into the packages_dynamic dict to append to rproviders, and since that key doesn't exist, the dict is getting modified to add a new, empty, entry for it. So even without the runtime error, we'd be generating an incorrect result.

Fix this by using a local variable for modifying the pattern and using the original key to retrieve the value on a match.

---
 lib/bb/providers.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/bb/providers.py +3 -3
index 8c1c31a5..e11a4637 100644
@@ -396,8 +396,8 @@ def getRuntimeProviders(dataCache, rdepend):
         return rproviders
 
     # Only search dynamic packages if we can't find anything in other variables
-    for pattern in dataCache.packages_dynamic:
-        pattern = pattern.replace(r'+', r"\+")
+    for pat_key in dataCache.packages_dynamic:
+        pattern = pat_key.replace(r'+', r"\+")
         if pattern in regexp_cache:
             regexp = regexp_cache[pattern]
         else:
@@ -408,7 +408,7 @@ def getRuntimeProviders(dataCache, rdepend):
                 raise
             regexp_cache[pattern] = regexp
         if regexp.match(rdepend):
-            rproviders += dataCache.packages_dynamic[pattern]
+            rproviders += dataCache.packages_dynamic[pat_key]
             logger.debug("Assuming %s is a dynamic package, but it may not exist" % rdepend)
 
     return rproviders
Signature · 1 line
2.32.0
#1 lore raw
Quoted 8 lines · Matt Madison

During parsing, Python raises

RuntimeError: dictionary changed size during iteration

in getRuntimeProviders, if you happen to have a recipe with an explicit RDEPENDS on a dynamic package containing a '+' character, such as 'gtk+3-locale-en'.

Quoted 8 lines

This is because we're using the modified pattern as the key into the packages_dynamic dict to append to rproviders, and since that key doesn't exist, the dict is getting modified to add a new, empty, entry for it. So even without the runtime error, we'd be generating an incorrect result.

Fix this by using a local variable for modifying the pattern and using the original key to retrieve the value on a match.

Good fine I wonder if a test case would be good to have Added as well

Quoted 48 lines
---
 lib/bb/providers.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/bb/providers.py +0 -0
index 8c1c31a5..e11a4637 100644
@@ -396,8 +396,8 @@ def getRuntimeProviders(dataCache, rdepend):
         return rproviders
 
     # Only search dynamic packages if we can't find anything in other

variables

lib/bb/providers.py +3 -3
-    for pattern in dataCache.packages_dynamic:
-        pattern = pattern.replace(r'+', r"\+")
+    for pat_key in dataCache.packages_dynamic:
+        pattern = pat_key.replace(r'+', r"\+")
         if pattern in regexp_cache:
             regexp = regexp_cache[pattern]
         else:
@@ -408,7 +408,7 @@ def getRuntimeProviders(dataCache, rdepend):
                 raise
             regexp_cache[pattern] = regexp
         if regexp.match(rdepend):
-            rproviders += dataCache.packages_dynamic[pattern]
+            rproviders += dataCache.packages_dynamic[pat_key]
             logger.debug("Assuming %s is a dynamic package, but it may
 not exist" % rdepend)
 

return rproviders
--
2.32.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#13633):
https://lists.openembedded.org/g/bitbake-devel/message/13633
Mute This Topic: https://lists.openembedded.org/mt/90486450/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw
Quoted 19 lines · Khem Raj
Quoted 15 lines · Matt Madison

During parsing, Python raises

RuntimeError: dictionary changed size during iteration

in getRuntimeProviders, if you happen to have a recipe with an explicit RDEPENDS on a dynamic package containing a '+' character, such as 'gtk+3-locale-en'.

This is because we're using the modified pattern as the key into the packages_dynamic dict to append to rproviders, and since that key doesn't exist, the dict is getting modified to add a new, empty, entry for it. So even without the runtime error, we'd be generating an incorrect result.

Quoted 5 lines
Quoted 2 lines

Fix this by using a local variable for modifying the pattern and using the original key to retrieve the value on a match.

Good fine I wonder if a test case would be good to have Added as well

I was wondering that, too. Are there test cases for exercising the PACKAGES_DYNAMIC feature already? If someone can provide a pointer, I can see about adding one for this.

Thanks,
-Matt

Quoted 44 lines
Quoted 44 lines
---
 lib/bb/providers.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/bb/providers.py +3 -4
index 8c1c31a5..e11a4637 100644
@@ -396,8 +396,8 @@ def getRuntimeProviders(dataCache, rdepend):
         return rproviders
 
     # Only search dynamic packages if we can't find anything in other variables
-    for pattern in dataCache.packages_dynamic:
-        pattern = pattern.replace(r'+', r"\+")
+    for pat_key in dataCache.packages_dynamic:
+        pattern = pat_key.replace(r'+', r"\+")
         if pattern in regexp_cache:
             regexp = regexp_cache[pattern]
         else:
@@ -408,7 +408,7 @@ def getRuntimeProviders(dataCache, rdepend):
                 raise
             regexp_cache[pattern] = regexp
         if regexp.match(rdepend):
-            rproviders += dataCache.packages_dynamic[pattern]
+            rproviders += dataCache.packages_dynamic[pat_key]
             logger.debug("Assuming %s is a dynamic package, but it may not exist" % rdepend)
 
     return rproviders
--

2.32.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#13633): https://lists.openembedded.org/g/bitbake-devel/message/13633
Mute This Topic: https://lists.openembedded.org/mt/90486450/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-