diff options
Diffstat (limited to 'src/python')
-rw-r--r-- | src/python/m5/util/pybind.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/python/m5/util/pybind.py b/src/python/m5/util/pybind.py index 4b5e03d31..4664c1602 100644 --- a/src/python/m5/util/pybind.py +++ b/src/python/m5/util/pybind.py @@ -58,10 +58,12 @@ class PyBindProperty(PyBindExport): code('.${export}("${{self.name}}", &${cname}::${{self.cxx_name}})') class PyBindMethod(PyBindExport): - def __init__(self, name, cxx_name=None, args=None): + def __init__(self, name, cxx_name=None, args=None, + return_value_policy=None): self.name = name self.cxx_name = cxx_name if cxx_name else name self.args = args + self.return_value_policy = return_value_policy def _conv_arg(self, value): if isinstance(value, bool): @@ -72,6 +74,10 @@ class PyBindMethod(PyBindExport): raise TypeError("Unsupported PyBind default value type") def export(self, code, cname): + arguments = [ '"${{self.name}}"', '&${cname}::${{self.cxx_name}}' ] + if self.return_value_policy: + arguments.append('pybind11::return_value_policy::' + '${{self.return_value_policy}}') if self.args: def get_arg_decl(arg): if isinstance(arg, tuple): @@ -81,8 +87,5 @@ class PyBindMethod(PyBindExport): else: return 'py::arg("%s")' % arg - code('.def("${{self.name}}", &${cname}::${{self.name}}, ') - code(' ' + \ - ', '.join([ get_arg_decl(a) for a in self.args ]) + ')') - else: - code('.def("${{self.name}}", &${cname}::${{self.cxx_name}})') + arguments.extend(list([ get_arg_decl(a) for a in self.args ])) + code('.def(' + ', '.join(arguments) + ')') |