python: Make meta class declarations Python 3 safe
authorAndreas Sandberg <andreas.sandberg@arm.com>
Fri, 25 Jan 2019 11:40:53 +0000 (11:40 +0000)
committerGiacomo Travaglini <giacomo.travaglini@arm.com>
Tue, 10 Mar 2020 09:35:56 +0000 (09:35 +0000)
commit5d70afd3a928e1185bcaf4b8fdbd32f42de5c745
tree435fe372e00d0943f0761fdc948599d782bd4ee8
parentee9a360c601011d9694352b0f87a2bbcd48764bf
python: Make meta class declarations Python 3 safe

Python 2.x and Python 3 use different meta class syntax. Fix this by
implementing meta classes using the add_metaclass decorator in the six
Python library.

Due to the way meta classes are implemented in six,
MetaParamValue.__new__ seems to be called twice for some classes. This
triggers an assertion which when param that checks that Param types
have only been registered once. I have turned this assertion into a
warning.

The assertion was triggered in params.CheckedInt and params.Enum. It
seems like the cause of the issue is that these classes have their own
meta classes (CheckedIntType and MetaEnum) that inherit from
MetaParamValue and a base class (ParamValue) that also inherits from
MetaParamValue.

Change-Id: I5dea08bf0558cfca57897a124cb131c78114e59e
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26083
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
src/python/m5/SimObject.py
src/python/m5/params.py
src/python/m5/util/code_formatter.py
src/python/m5/util/pybind.py