Skip to content

Commit

Permalink
[attributes] close attribute after withAttr
Browse files Browse the repository at this point in the history
  • Loading branch information
Vindaar committed Nov 8, 2024
1 parent a8c35e0 commit 85d7c4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/nimhdf5/datatypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ proc close*(attr: var H5AttrObj) =
$(attr.attr_id.id) & "!")
withDebug:
echo "Closed attribute with status ", err
attr.opened = false
# close state regardless of object, to make sure we don't leave it open accidentally
attr.opened = false

proc close*(attr: H5Attr) = attr[].close()

Expand Down
4 changes: 3 additions & 1 deletion src/nimhdf5/hdf5_json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ template withAttr*(h5attr: H5Attributes, name: string, actions: untyped) =
## copying data type and space and writing the same buffer to a new location.

# read attribute info so that `attr_tab` knows it
h5attr.readAttributeInfo(name, closeAttribute = true) # raises KeyError if it does not exist
h5attr.readAttributeInfo(name) # raises KeyError if it does not exist
let attrObj {.inject.} = h5attr.attr_tab[name]
case attrObj.dtypeAnyKind
of dkBool:
Expand Down Expand Up @@ -290,6 +290,8 @@ template withAttr*(h5attr: H5Attributes, name: string, actions: untyped) =
else:
let attr {.inject.} = readJson(attrObj)
actions
# close the attribute again
h5attr.attr_tab[name].close()

## The following JSON related procs are placeholders. We might implement them fully to be
## able to write compound data at runtime baesd on JSON data.
Expand Down

0 comments on commit 85d7c4a

Please sign in to comment.