Hello Nikos Nikoleris,
I'd like you to do a code review. Please visit
https://gem5-review.googlesource.com/c/public/gem5/+/15897
to review the following change.
Change subject: python: Value prefix and units conversion fix
......................................................................
python: Value prefix and units conversion fix
Fixes some corner cases when converting the strings to values to units
with prefixes, namely when the value is unitless i.e. 20M.
Change-Id: Iceba8a7dd960afc88cf59dc071324da8a0ac98f7
Reviewed-by: Nikos Nikoleris <[email protected]>
---
M src/python/m5/util/convert.py
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/python/m5/util/convert.py b/src/python/m5/util/convert.py
index 5ae3121..da8ba93 100644
--- a/src/python/m5/util/convert.py
+++ b/src/python/m5/util/convert.py
@@ -93,25 +93,21 @@
# memory size configuration stuff
-def toFloat(value, target_type='float', units=None, prefixes=[]):
+def toFloat(value, target_type='float', units=None, prefixes={}):
assertStr(value)
-
if units and not value.endswith(units):
- units = None
- if not units:
try:
return float(value)
except ValueError:
- raise ValueError, "cannot convert '%s' to %s" % \
+ raise ValueError, "cannot convert '%s' to %s: Invalid unit" % \
(value, target_type)
-
- value = value[:-len(units)]
+ elif units:
+ value = value[:-len(units)]
prefix = next((p for p in prefixes.keys() if value.endswith(p)), None)
if not prefix:
return float(value)
value = value[:-len(prefix)]
-
return float(value) * prefixes[prefix]
def toMetricFloat(value, target_type='float', units=None):
@@ -120,7 +116,7 @@
def toBinaryFloat(value, target_type='float', units=None):
return toFloat(value, target_type, units, binary_prefixes)
-def toInteger(value, target_type='integer', units=None, prefixes=[]):
+def toInteger(value, target_type='integer', units=None, prefixes={}):
value = toFloat(value, target_type, units, prefixes)
result = long(value)
if value != result:
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15897
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Iceba8a7dd960afc88cf59dc071324da8a0ac98f7
Gerrit-Change-Number: 15897
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev