From: Andreas Sandberg Date: Mon, 31 Jul 2017 10:19:41 +0000 (+0100) Subject: python: Make GlobalExitEvent.getCode() return an int X-Git-Tag: v19.0.0.0~2647 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=47557157d84d2821accf81ff6d72041635ccd050;p=gem5.git 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 Reviewed-by: Jose Marinho Reviewed-by: Curtis Dunham Reviewed-on: https://gem5-review.googlesource.com/4280 Reviewed-by: Jason Lowe-Power Reviewed-by: Joe Gross --- 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>( m, "GlobalSimLoopExitEvent") .def("getCause", &GlobalSimLoopExitEvent::getCause) - .def("getCode", &GlobalSimLoopExitEvent::getCode) + .def("getCode", [](GlobalSimLoopExitEvent *e) { + return py::reinterpret_steal( + PyInt_FromLong(e->getCode())); + }) ; // Event base class. These should never be returned directly to