From 4e02e7c217a1ee81dc16c378582697dd5a14de47 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Mon, 10 Nov 2008 11:51:18 -0800 Subject: python: Fix the reference counting for python events placed on the eventq. We need to add a reference when an object is put on the C++ queue, and remove a reference when the object is removed from the queue. This was not happening before and caused a memory problem. --- src/python/swig/event.i | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/python/swig/event.i') diff --git a/src/python/swig/event.i b/src/python/swig/event.i index 10d75d2de..b40e59a4b 100644 --- a/src/python/swig/event.i +++ b/src/python/swig/event.i @@ -41,6 +41,35 @@ #pragma SWIG nowarn=350,351 +%extend EventQueue { + void + schedule(Event *event, Tick when) + { + // Any python event that are scheduled must have their + // internal object's refcount incremented so that the object + // sticks around while it is in the event queue. + PythonEvent *pyevent = dynamic_cast(event); + if (pyevent) + pyevent->incref(); + $self->schedule(event, when); + } + + void + deschedule(Event *event) + { + $self->deschedule(event); + + // Now that we're removing the python object from the event + // queue, we need to decrement its reference count. + PythonEvent *pyevent = dynamic_cast(event); + if (pyevent) + pyevent->decref(); + } +} + +%ignore EventQueue::schedule; +%ignore EventQueue::deschedule; + %import "base/fast_alloc.hh" %import "sim/serialize.hh" -- cgit v1.2.3