Skip to content

Commit

Permalink
Make Delegator ownership optional for ExtensibleRate
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Sep 11, 2022
1 parent 6e23308 commit 9875cb4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions interfaces/cython/cantera/ctcxx.pxd
Expand Up @@ -33,3 +33,4 @@ cdef extern from "<memory>":
cppclass shared_ptr "std::shared_ptr" [T]:
T* get()
void reset(T*)
void reset()
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/reaction.pxd
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions interfaces/cython/cantera/reaction.pyx
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 9875cb4

Please sign in to comment.