Andreas Sandberg has submitted this change and it was merged. (
https://gem5-review.googlesource.com/4280 )
Change subject: python: Make GlobalExitEvent.getCode() return an int
......................................................................
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 <[email protected]>
Reviewed-by: Jose Marinho <[email protected]>
Reviewed-by: Curtis Dunham <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/4280
Reviewed-by: Jason Lowe-Power <[email protected]>
Reviewed-by: Joe Gross <[email protected]>
---
M src/python/pybind11/event.cc
1 file changed, 4 insertions(+), 1 deletion(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved
Joe Gross: Looks good to me, approved
Andreas Sandberg: Looks good to me, approved
diff --git a/src/python/pybind11/event.cc b/src/python/pybind11/event.cc
index f9e6568..88ee699 100644
--- a/src/python/pybind11/event.cc
+++ b/src/python/pybind11/event.cc
@@ -135,7 +135,10 @@
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
--
To view, visit https://gem5-review.googlesource.com/4280
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I73d6b881025064afa2b2e6eb4512fa2a4b0a87da
Gerrit-Change-Number: 4280
Gerrit-PatchSet: 2
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bradford Beckmann <[email protected]>
Gerrit-Reviewer: Curtis Dunham <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Joe Gross <[email protected]>
Gerrit-Reviewer: Nathan Binkert <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev