Hello Curtis Dunham,

I'd like you to do a code review. Please visit

    https://gem5-review.googlesource.com/4280

to review the following change.


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]>
---
M src/python/pybind11/event.cc
1 file changed, 4 insertions(+), 1 deletion(-)



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: newchange
Gerrit-Change-Id: I73d6b881025064afa2b2e6eb4512fa2a4b0a87da
Gerrit-Change-Number: 4280
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Curtis Dunham <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to