changeset a0dab21e422f in /z/repo/gem5 details: http://repo.gem5.org/gem5?cmd=changeset;node=a0dab21e422f description: sim: fix reference counting of PythonEvent
When gem5 is a slave to another simulator and the Python is only used to initialize the configuration (and not perform actual simulation), a "debug start" (--debug-start) event will get freed during or immediately after the initial Python frame's execution rather than remaining in the event queue. This tricky patch fixes the GC issue causing this. diffstat: src/python/swig/event.i | 4 ++++ src/python/swig/pyevent.cc | 8 ++++---- src/python/swig/pyevent.hh | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diffs (56 lines): diff -r 87f7b5a07584 -r a0dab21e422f src/python/swig/event.i --- a/src/python/swig/event.i Thu Jan 22 05:01:31 2015 -0500 +++ b/src/python/swig/event.i Tue Dec 23 11:51:40 2014 -0600 @@ -71,6 +71,10 @@ } } +%typemap(out) PythonEvent* { + result->object = $result = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PythonEvent, SWIG_POINTER_NEW); +} + %ignore EventQueue::schedule; %ignore EventQueue::deschedule; diff -r 87f7b5a07584 -r a0dab21e422f src/python/swig/pyevent.cc --- a/src/python/swig/pyevent.cc Thu Jan 22 05:01:31 2015 -0500 +++ b/src/python/swig/pyevent.cc Tue Dec 23 11:51:40 2014 -0600 @@ -34,10 +34,10 @@ #include "sim/async.hh" #include "sim/eventq.hh" -PythonEvent::PythonEvent(PyObject *obj, Priority priority) - : Event(priority), object(obj) +PythonEvent::PythonEvent(PyObject *code, Priority priority) + : Event(priority), eventCode(code) { - if (object == NULL) + if (code == NULL) panic("Passed in invalid object"); } @@ -49,7 +49,7 @@ PythonEvent::process() { PyObject *args = PyTuple_New(0); - PyObject *result = PyObject_Call(object, args, NULL); + PyObject *result = PyObject_Call(eventCode, args, NULL); Py_DECREF(args); if (result) { diff -r 87f7b5a07584 -r a0dab21e422f src/python/swig/pyevent.hh --- a/src/python/swig/pyevent.hh Thu Jan 22 05:01:31 2015 -0500 +++ b/src/python/swig/pyevent.hh Tue Dec 23 11:51:40 2014 -0600 @@ -37,9 +37,10 @@ class PythonEvent : public Event { private: - PyObject *object; + PyObject *eventCode; // PyObject to call to perform event + public: + PyObject *object; // PyObject wrapping this PythonEvent - public: PythonEvent(PyObject *obj, Event::Priority priority); ~PythonEvent(); _______________________________________________ gem5-dev mailing list gem5-dev@gem5.org http://m5sim.org/mailman/listinfo/gem5-dev