From 80b723cfe705a25db0d1d43b5f106f69b108d7b7 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sun, 25 Mar 2012 23:25:45 +0000 Subject: [PATCH] Python: Fixed reference counting issues with Func objects used by Reactors The C++ Reactor class doesn't own a reference to the Func object. To make borrowing the reference safe, the Python Reactor class now owns a reference, which is guaranteed to be valid for the lifetime of the C++ Reactor object. --- interfaces/python/Cantera/Reactor.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/interfaces/python/Cantera/Reactor.py b/interfaces/python/Cantera/Reactor.py index f29d7863c..c2b29c090 100644 --- a/interfaces/python/Cantera/Reactor.py +++ b/interfaces/python/Cantera/Reactor.py @@ -569,6 +569,7 @@ class FlowDevice: return _cantera.flowdev_setParameters(self.__fdev_id, n, params) def setFunction(self, f): + self._f = f # Hold on to a reference so it doesn't get deleted _cantera.flowdev_setFunction(self.__fdev_id, f.func_id()) def flowdev_id(self): @@ -969,8 +970,11 @@ class Wall: Specify the time-dependent heat flux function [W/m2]. *qfunc* must be a functor (an instance of :class:`.Func1`). """ - n = 0 - if qfunc: n = qfunc.func_id() + if qfunc: + self._qfunc = qfunc # hold on to a reference so it doesn't get deleted + n = self.qfunc.func_id() + else: + n = 0 return _cantera.wall_setHeatFlux(self.__wall_id, n) def setExpansionRateCoeff(self, k): @@ -983,8 +987,11 @@ class Wall: Specify the velocity function [m/s]. *vfunc* must be a functor (an instance of :class:`.Func1`) """ - n = 0 - if vfunc: n = vfunc.func_id() + if vfunc: + self._vfunc = vfunc # hold on to a reference so it doesn't get deleted + n = vfunc.func_id() + else: + n = 0 _cantera.wall_setVelocity(self.__wall_id, n) def vdot(self):