Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Python, only __del__ if owned #36

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading