From 85d7c4a8eea9f8a78d8c070a66d3f665c1cc05f5 Mon Sep 17 00:00:00 2001 From: Vindaar Date: Fri, 8 Nov 2024 12:48:49 +0100 Subject: [PATCH] [attributes] close attribute after `withAttr` --- src/nimhdf5/datatypes.nim | 3 ++- src/nimhdf5/hdf5_json.nim | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/nimhdf5/datatypes.nim b/src/nimhdf5/datatypes.nim index ead32ba..b79a0dc 100644 --- a/src/nimhdf5/datatypes.nim +++ b/src/nimhdf5/datatypes.nim @@ -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() diff --git a/src/nimhdf5/hdf5_json.nim b/src/nimhdf5/hdf5_json.nim index 0b77bde..9fd9ddb 100644 --- a/src/nimhdf5/hdf5_json.nim +++ b/src/nimhdf5/hdf5_json.nim @@ -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: @@ -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.