summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2017-07-31 11:19:41 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2017-08-30 16:25:44 +0000
commit47557157d84d2821accf81ff6d72041635ccd050 (patch)
treeba594fd76e342861f5af40d032c16a8ef6a83819 /src/python
parent9f465d0a1b35a37a1c5d3489de0f78f314a662d1 (diff)
downloadgem5-47557157d84d2821accf81ff6d72041635ccd050.tar.xz
python: Make GlobalExitEvent.getCode() return an int
PyBind normally casts integers returned from the C to long in Python. This is normally fine since long in most cases behaves just like an int. However, when passing the return value from getcode() to sys.exit, unexpected behavior ensues. Due to the way the function is defined, any type other than int (with the exception of None) will be treated as an error and be equivalent to sys.exit(1). Since we frequently use the sys.exit(event.getCode()) pattern, we need to ensure that the function returns an integer. This change adds an explicit type conversion to a Python integer in the wrapper code. Change-Id: I73d6b881025064afa2b2e6eb4512fa2a4b0a87da Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Jose Marinho <jose.marinho@arm.com> Reviewed-by: Curtis Dunham <curtis.dunham@arm.com> Reviewed-on: https://gem5-review.googlesource.com/4280 Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Joe Gross <joe.gross@amd.com>
Diffstat (limited to 'src/python')
-rw-r--r--src/python/pybind11/event.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/python/pybind11/event.cc b/src/python/pybind11/event.cc
index f9e65685d..88ee6996a 100644
--- a/src/python/pybind11/event.cc
+++ b/src/python/pybind11/event.cc
@@ -135,7 +135,10 @@ pybind_init_event(py::module &m_native)
std::unique_ptr<GlobalSimLoopExitEvent, py::nodelete>>(
m, "GlobalSimLoopExitEvent")
.def("getCause", &GlobalSimLoopExitEvent::getCause)
- .def("getCode", &GlobalSimLoopExitEvent::getCode)
+ .def("getCode", [](GlobalSimLoopExitEvent *e) {
+ return py::reinterpret_steal<py::object>(
+ PyInt_FromLong(e->getCode()));
+ })
;
// Event base class. These should never be returned directly to