Skip to content

Commit

Permalink
only __del__ if owned (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs authored Sep 17, 2024
1 parent a57f1f6 commit be32852
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions python/ndelement/ciarlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ndelement._ndelementrs import lib as _lib, ffi as _ffi
from ndelement.reference_cell import ReferenceCellType, entity_counts, dim
from enum import Enum
from _cffi_backend import _CDataBase


class Continuity(Enum):
Expand Down Expand Up @@ -44,13 +45,15 @@ class MapType(Enum):
class CiarletElement(object):
"""Ciarlet element."""

def __init__(self, rs_element):
def __init__(self, rs_element: _CDataBase, owned: bool = True):
"""Initialise."""
self._rs_element = rs_element
self._owned = owned

def __del__(self):
"""Delete object."""
_lib.ciarlet_free_element(self._rs_element)
if self._owned:
_lib.ciarlet_free_element(self._rs_element)

@property
def dtype(self):
Expand Down Expand Up @@ -181,13 +184,15 @@ def tabulate(self, points: npt.NDArray[np.floating], nderivs: int) -> npt.NDArra
class ElementFamily(object):
"""Ciarlet element."""

def __init__(self, rs_family):
def __init__(self, rs_family: _CDataBase, owned: bool = True):
"""Initialise."""
self._rs_family = rs_family
self._owned = owned

def __del__(self):
"""Delete object."""
_lib.ciarlet_free_family(self._rs_family)
if self._owned:
_lib.ciarlet_free_family(self._rs_family)

def element(self, cell: ReferenceCellType) -> CiarletElement:
return CiarletElement(_lib.element_family_element(self._rs_family, cell.value))
Expand Down

0 comments on commit be32852

Please sign in to comment.