[h5py] 51/455: First ideas for a new identifier interface, rather than using ints.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:16 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit d3ae78bf961c9493816990197502171ae2b41127
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Sat Jun 14 07:35:25 2008 +0000

    First ideas for a new identifier interface, rather than using ints.
---
 h5py/h5.pxd | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++
 h5py/h5.pyx | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+)

diff --git a/h5py/h5.pxd b/h5py/h5.pxd
index e11655f..da6fd40 100644
--- a/h5py/h5.pxd
+++ b/h5py/h5.pxd
@@ -42,6 +42,62 @@ cdef extern from "hdf5.h":
   herr_t H5get_libversion(unsigned *majnum, unsigned *minnum,
                           unsigned *relnum ) except *
 
+# === Custom identifier wrappers ==============================================
+
+cdef class ObjectID:
+    """ Base wrapper class for HDF5 object identifiers """
+    cdef readonly hid_t id
+
+cdef class FileID(ObjectID):
+    """ File identifier """
+
+cdef class GroupID(ObjectID):
+    """ Group identifier """
+    pass
+
+cdef class SpaceID(ObjectID):
+    """ Dataspace identifier """
+    pass
+
+cdef class DatasetID(ObjectID):
+    """ Dataset identifier """
+    pass
+
+cdef class TypeID(ObjectID):
+    """ Datatype identifier """
+    pass
+
+cdef class AttrID(ObjectID):
+    """ Attribute identifier """
+    pass
+
+cdef class PropID(ObjectID):
+    """ Property list (class or instance) identifier """
+    pass
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
 
 
diff --git a/h5py/h5.pyx b/h5py/h5.pyx
index ea1b263..8d20081 100644
--- a/h5py/h5.pyx
+++ b/h5py/h5.pyx
@@ -20,6 +20,7 @@
 """
 
 from h5e cimport _enable_exceptions
+from h5i cimport H5Iinc_ref, H5Idec_ref, H5Iget_ref, H5Iget_type, H5I_BADID
 
 # === Library init ============================================================
 
@@ -66,3 +67,68 @@ class DDict(dict):
     def __missing__(self, key):
         return '*INVALID* (%s)' % str(key)
 
+# === Identifier wrappers =====================================================
+
+cdef class ObjectID:
+        
+    def __cinit__(self, hid_t id):
+        """ Object init; simply records the given ID. """
+        self.id = id
+
+    def __dealloc__(self):
+        """ Automatically decrefs the ID, if it's valid. """
+        if H5Iget_type(self.id) != H5I_BADID:
+            H5Idec_ref(self.id)
+
+    def __copy__(self):
+        """ Create a new instance and incref the ID. """
+        copy = type(self)(self.id)
+        H5Iinc_ref(self.id)
+        return copy
+
+    def __str__(self):
+        if H5Iget_type(self.id) != H5I_BADID:
+            ref = str(H5Iget_ref(self.id))
+        else:
+            ref = "INVALID"
+
+        return "%d [%s] %s" % (self.id, ref, self.__class__.__name__)
+
+cdef class FileID(ObjectID):
+
+    def close(self):
+        # todo: recursive close of all open ids
+        if H5Iget_type(self.id) != H5I_BADID:
+            H5Fclose(self.id)
+
+cdef class TypeID(ObjectID):
+
+    def __dealloc__(self):
+        """ For type objects, we have to intercept the damn "can't close
+            an immutable type" BS.  Conveniently, there's no way to check
+            if a type is immutable.
+        """
+        if H5Iget_type(self.id) != H5I_BADID:
+            try:
+                H5Idec_ref(self.id)
+            except EnvironmentError:
+                pass
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git



More information about the debian-science-commits mailing list