diff --git a/interfaces/cython/cantera/ctcxx.pxd b/interfaces/cython/cantera/ctcxx.pxd index 4ab4103ecf..28b77d7ff8 100644 --- a/interfaces/cython/cantera/ctcxx.pxd +++ b/interfaces/cython/cantera/ctcxx.pxd @@ -33,3 +33,4 @@ cdef extern from "": cppclass shared_ptr "std::shared_ptr" [T]: T* get() void reset(T*) + void reset() diff --git a/interfaces/cython/cantera/reaction.pxd b/interfaces/cython/cantera/reaction.pxd index 9770198b8e..fde60b5e39 100644 --- a/interfaces/cython/cantera/reaction.pxd +++ b/interfaces/cython/cantera/reaction.pxd @@ -253,7 +253,7 @@ cdef class CustomRate(ReactionRate): cdef Func1 _rate_func # prevent premature garbage collection cdef class ExtensibleRate(ReactionRate): - pass + cdef set_cxx_object(self, CxxReactionRate* rate=*) cdef class InterfaceRateBase(ArrheniusRateBase): cdef CxxInterfaceRateBase* interface diff --git a/interfaces/cython/cantera/reaction.pyx b/interfaces/cython/cantera/reaction.pyx index 3151187977..04492ec073 100644 --- a/interfaces/cython/cantera/reaction.pyx +++ b/interfaces/cython/cantera/reaction.pyx @@ -722,8 +722,17 @@ cdef class ExtensibleRate(ReactionRate): self.set_cxx_object() def __init__(self, *args, **kwargs): - assign_delegates(self, dynamic_cast[CxxDelegatorPtr](self.rate)) - super().__init__(*args, **kwargs) + if self._rate.get() is not NULL: + assign_delegates(self, dynamic_cast[CxxDelegatorPtr](self.rate)) + # ReactionRate does not define __init__, so it does not need to be called + + cdef set_cxx_object(self, CxxReactionRate* rate=NULL): + if rate is NULL: + self.rate = self._rate.get() + else: + self._rate.reset() + self.rate = rate + assign_delegates(self, dynamic_cast[CxxDelegatorPtr](self.rate)) cdef class InterfaceRateBase(ArrheniusRateBase): """