[h5py] 133/455: More 1.8.X work; backwards-incompatible changes to H5A; broken for now

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:25 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 8471c50d5ddcbbe9ea097ab2d98ab4ac2f09d42a
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Wed Oct 1 04:09:17 2008 +0000

    More 1.8.X work; backwards-incompatible changes to H5A; broken for now
---
 h5py/defs.pxd |  18 +++++-
 h5py/h5a.pyx  |  61 ++++++++++++++------
 h5py/h5g.pyx  |  10 ++--
 h5py/h5l.pyx  | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 h5py/h5o.pyx  |  79 ++++++++++----------------
 setup.py      |   5 +-
 6 files changed, 276 insertions(+), 76 deletions(-)

diff --git a/h5py/defs.pxd b/h5py/defs.pxd
index a8fc733..2fdf6ab 100644
--- a/h5py/defs.pxd
+++ b/h5py/defs.pxd
@@ -491,7 +491,7 @@ IF H5PY_18API:
 
     #  Prototype for H5Literate/H5Literate_by_name() operator 
     ctypedef herr_t (*H5L_iterate_t) (hid_t group, char *name, H5L_info_t *info,
-                      void *op_data)
+                      void *op_data) except 2
 
     # Links API
 
@@ -546,6 +546,13 @@ IF H5PY_18API:
       H5_index_t idx_type, H5_iter_order_t order, H5L_iterate_t op,
       void *op_data, hid_t lapl_id) except *
 
+    herr_t H5Lunpack_elink_val(void *ext_linkval, size_t link_size,
+        unsigned *flags, char **filename, char **obj_path) except *
+
+    herr_t H5Lcreate_external(char *file_name, char *obj_name,
+        hid_t link_loc_id, char *link_name, hid_t lcpl_id, hid_t lapl_id) except *
+
+
 # === H5O - General object operations (1.8.X only) ============================
 
 IF H5PY_18API:
@@ -640,13 +647,14 @@ IF H5PY_18API:
               char *comment, size_t bufsize, hid_t lapl_id) except *
 
     ctypedef herr_t (*H5O_iterate_t)(hid_t obj, char *name, H5O_info_t *info,
-                      void *op_data)
+                      void *op_data) except 2
 
     herr_t H5Ovisit(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order,
             H5O_iterate_t op, void *op_data) except *
     herr_t H5Ovisit_by_name(hid_t loc_id, char *obj_name,
             H5_index_t idx_type, H5_iter_order_t order, H5O_iterate_t op,
             void *op_data, hid_t lapl_id) except *
+
     herr_t H5Oclose(hid_t object_id) except *
 
 # === H5P - Property list API =================================================
@@ -1217,5 +1225,11 @@ cdef extern from "hdf5.h":
       H5T_cset_t        cset        # Character set of attribute name
       hsize_t           data_size   # Size of raw data
 
+    herr_t H5Aopen(hid_t obj_id, char *attr_name, hid_t aapl_id) 
+    herr_t H5Aopen_by_name( hid_t loc_id, char *obj_name, char *attr_name,
+        hid_t aapl_id, hid_t lapl_id) 
+    herr_t H5Aopen_by_idx(hid_t loc_id, char *obj_name, H5_index_t idx_type,
+        H5_iter_order_t order, hsize_t n, hid_t aapl_id, hid_t lapl_id) 
+
 
 
diff --git a/h5py/h5a.pyx b/h5py/h5a.pyx
index 6eeeed2..518ac48 100644
--- a/h5py/h5a.pyx
+++ b/h5py/h5a.pyx
@@ -21,6 +21,7 @@ include "sync.pxi"
 from h5 cimport init_hdf5
 from h5t cimport TypeID, typewrap, py_create
 from h5s cimport SpaceID
+from h5p cimport PropID, pdefault
 from numpy cimport import_array, ndarray, PyArray_DATA
 from utils cimport check_numpy_read, check_numpy_write, emalloc, efree
 
@@ -42,26 +43,50 @@ def create(ObjectID loc not None, char* name, TypeID tid not None,
     """
     return AttrID(H5Acreate(loc.id, name, tid.id, space.id, H5P_DEFAULT))
 
- at sync
-def open_idx(ObjectID loc not None, int idx):
-    """ (ObjectID loc_id, UINT idx) => AttrID
-
-        Open an exisiting attribute on an object, by zero-based index.
-    """
-    # If the argument is declared UINT and someone passes in -1, the Pyrex
-    # layer happily converts it to something like 2**32 -1, which crashes the
-    # 1.6.5 version HDF5 library.
-    if idx < 0:
-        raise ValueError("Index must be a non-negative integer.")
-    return AttrID(H5Aopen_idx(loc.id, idx))
+IF H5PY_18API:
+    @sync
+    def open(ObjectID loc not None, char* name=NULL, int idx=-1, *,
+            char* obj_name='.', int idx_type=H5_INDEX_NAME, int order=H5_ITER_NATIVE,
+            PropID lapl=None):
+        """
+            (ObjectID loc, STRING name=NULL, INT order=-1, **kwds)
+            => AttrID
+       
+            Open an attribute attached to an existing object.  You must specify
+            exactly one of either name or idx.
+
+            Keyword-only arguments:
+            * STRING obj_name (NULL):       Attribute is attached to this group member
+            * PropID lapl (None):           Controls how "obj_name" is interpreted
+            * INT idx_type (h5.INDEX_NAME)  Controls how idx is interpreted
+            * INT order (h5.ITER_NATIVE)    Controls how idx is interpreted
+        """
+        if (name == NULL and idx < 0) or (name != NULL and idx >= 0):
+            raise ValueError("Exactly one of name or idx must be specified")
+
+        if name != NULL:
+            return AttrID(H5Aopen_by_name(loc.id, obj_name, name,
+                            H5P_DEFAULT, pdefault(lapl)))
+        else:
+            return AttrID(H5Aopen_by_idx(loc.id, obj_name,
+                <H5_index_t>idx_type, <H5_iter_order_t>order, idx,
+                H5P_DEFAULT, pdefault(lapl)))
+
+ELSE:
+    @sync
+    def open(ObjectID loc not None, char* name=NULL, int idx=-1):
+        """ (ObjectID loc, STRING name=NULL, INT idx=-1) => AttrID
 
- at sync
-def open_name(ObjectID loc not None, char* name):
-    """ (ObjectID loc, STRING name) => AttrID
+            Open an attribute attached to an existing object.  You must specify
+            exactly one of either name or idx.
+        """
+        if (name == NULL and idx < 0) or (name != NULL and idx >= 0):
+            raise ValueError("Exactly one of name or idx must be specified")
 
-        Open an existing attribute on an object, by name.
-    """
-    return AttrID(H5Aopen_name(loc.id, name))
+        if name != NULL:
+            return AttrID(H5Aopen_name(loc.id, name))
+        else:
+            return AttrID(H5Aopen_idx(loc.id, idx))
 
 @sync
 def delete(ObjectID loc not None, char* name):
diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index 5fcf333..8d41d98 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -155,14 +155,12 @@ IF H5PY_18API:
                                                 pdefault(gapl)))
 ELSE:
     @sync
-    def create(ObjectID loc not None, char* name, int size_hint=-1):
-        """ (ObjectID loc, STRING name, INT size_hint=-1) => GroupID
+    def create(ObjectID loc not None, char* name):
+        """ (ObjectID loc, STRING name) => GroupID
 
-            Create a new group, under a given parent group.  If given, size_hint
-            is an estimate of the space to reserve (in bytes) for group member
-            names.
+            Create a new group, under a given parent group.
         """
-        return GroupID(H5Gcreate(loc.id, name, size_hint))
+        return GroupID(H5Gcreate(loc.id, name, -1))
 
 cdef herr_t iter_cb_helper(hid_t gid, char *name, object int_tpl) except -1:
     # Callback function for H5Giterate
diff --git a/h5py/h5l.pyx b/h5py/h5l.pyx
index 8932364..08f3517 100644
--- a/h5py/h5l.pyx
+++ b/h5py/h5l.pyx
@@ -18,8 +18,81 @@ include "config.pxi"
 include "sync.pxi"
 
 from h5 cimport init_hdf5
+from h5p cimport PropID, pdefault
+from h5g cimport GroupID
+from utils cimport emalloc, efree
+from python_exc cimport PyErr_SetString
+
 init_hdf5()
 
+# === Public constants ========================================================
+
+TYPE_HARD = H5L_TYPE_HARD         
+TYPE_SOFT = H5L_TYPE_SOFT      
+TYPE_EXTERNAL = H5L_TYPE_EXTERNAL     
+
+cdef class LinkInfo:
+
+    cdef H5L_info_t infostruct
+    cdef object __weakref__
+
+    property type:
+        """ Integer type code for link (h5l.TYPE_*) """
+        def __get__(self):
+            return <int>self.infostruct.type
+    property corder_valid:
+        """ Indicates if the creation order is valid """
+        def __get__(self):
+            return <bint>self.infostruct.corder_valid
+    property corder:
+        """ Creation order """
+        def __get__(self):
+            return self.infostruct.corder
+    property cset:
+        """ Integer type code for character set (h5t.CSET_*) """
+        def __get__(self):
+            return self.infostruct.cset
+    property u:
+        """ Either the address of a hard link or the size of a soft/UD link """
+        def __get__(self):
+            if self.infostruct.type == H5L_TYPE_HARD:
+                return self.infostruct.u.address
+            else:
+                return self.infostruct.u.val_size
+
+    def __repr__(self):
+        typenames = {H5L_TYPE_HARD: "HARD", H5L_TYPE_SOFT: "SOFT",
+                     H5L_TYPE_EXTERNAL: "EXTERNAL"}
+        cset_names = {H5T_CSET_ASCII: "ASCII", H5T_CSET_UTF8: "UTF8"}
+        return "LinkInfo (%s, element %d, cset %s)" % \
+            (typenames.get(self.type, "UNKNOWN"), self.corder,
+            cset_names.get(self.cset, "UNKNOWN"))
+
+cdef class _LinkVisitor:
+
+    """ Helper class for iteration callback """
+
+    cdef object func
+    cdef object retval
+    cdef LinkInfo info
+
+    def __init__(self, func):
+        self.func = func
+        self.retval = None
+        self.info = LinkInfo()
+
+cdef herr_t cb_link_iterate(hid_t grp, char* name, H5L_info_t *istruct, void* data) except 2:
+    # Standard iteration callback for iterate/visit routines
+
+    cdef _LinkVisitor it = <_LinkVisitor?>data
+    it.info.infostruct = istruct[0]
+
+    it.retval = it.func(name, it.info)
+
+    if (it.retval is None) or (not it.retval):
+        return 0
+    return 1
+
 cdef class LinkProxy(ObjectID):
 
     """
@@ -54,6 +127,74 @@ cdef class LinkProxy(ObjectID):
         raise TypeError("Link proxies are unhashable; use the parent group instead.")
 
     @sync
+    def create_hard(self, char* new_name, GroupID cur_loc not None,
+        char* cur_name, PropID lcpl=None, PropID lapl=None):
+        """ (STRING new_name, GroupID cur_loc, STRING cur_name,
+             PropLCID lcpl=None, PropLAID lapl=None)
+
+            Create a new hard link in this group pointing to an existing link
+            in another group.
+        """
+        H5Lcreate_hard(cur_loc.id, cur_name, self.id, new_name,
+            pdefault(lcpl), pdefault(lapl))
+
+    @sync
+    def create_soft(self, char* new_name, char* target,
+        PropID lcpl=None, PropID lapl=None):
+        """ (STRING new_name, STRING target, PropLCID lcpl=None,
+             PropLAID lapl=None)
+
+            Create a new soft link in this group, with the given string value.
+            The link target does not need to exist.
+        """
+        H5Lcreate_soft(target, self.id, new_name,
+            pdefault(lcpl), pdefault(lapl))
+
+    @sync
+    def get_val(self, char* name, PropID lapl=None):
+        """ (STRING name, PropLAID lapl=None) => STRING or TUPLE(file, obj)
+
+            Get the string value of a soft link, or a 2-tuple representing
+            the contents of an external link.
+        """
+        cdef hid_t plist = pdefault(lapl)
+        cdef H5L_info_t info
+        cdef size_t buf_size
+        cdef char* buf = NULL
+        cdef char* ext_file_name = NULL
+        cdef char* ext_obj_name = NULL
+        cdef unsigned int wtf = 0
+
+        H5Lget_info(self.id, name, &info, plist)
+        if info.type != H5L_TYPE_SOFT and info.type != H5L_TYPE_EXTERNAL:
+            raise TypeError("Link must be either a soft or external link")
+
+        buf_size = info.u.val_size
+        buf = <char*>emalloc(buf_size)
+        try:
+            H5Lget_val(self.id, name, buf, buf_size, plist)
+            if info.type == H5L_TYPE_SOFT:
+                py_retval = buf
+            else:
+                H5Lunpack_elink_val(buf, buf_size, &wtf, &ext_file_name, &ext_obj_name)
+                py_retval = (str(ext_file_name), str(ext_obj_name))
+        finally:
+            efree(buf)
+        
+        return py_retval
+
+    @sync
+    def create_external(self, char* link_name, char* file_name, char* obj_name,
+        PropID lcpl=None, PropID lapl=None):
+        """ (STRING link_name, STRING file_name, STRING obj_name,
+             PropLCID lcpl=None, PropLAID lapl=None)
+
+            Create a new external link, pointing to an object in another file.
+        """
+        H5Lcreate_external(file_name, obj_name, self.id, link_name,
+            pdefault(lcpl), pdefault(lapl))
+
+    @sync
     def exists(self, char* name):
         """ (STRING name) => BOOL
 
@@ -61,6 +202,44 @@ cdef class LinkProxy(ObjectID):
         """
         return <bint>(H5Lexists(self.id, name, H5P_DEFAULT))
 
+    @sync
+    def get_info(self, char* name, PropID lapl=None):
+        """ (STRING name, PropLAID lapl=None) => LinkInfo instance
+
+            Get information about a link in this group.
+        """
+        cdef LinkInfo info = LinkInfo()
+        H5Lget_info(self.id, name, &info.infostruct, pdefault(lapl))
+        return info
+
+    @sync
+    def visit(self, object func, *,
+              int idx_type=H5_INDEX_NAME, int order=H5_ITER_NATIVE,
+              char* name='.', PropID lapl=None):
+        """ (CALLABLE func, **kwds) => <Return value from func>
+
+            Iterate a function or callable object over all groups below this
+            one.  Your callable should conform to the signature:
+
+                func(STRING name, LinkInfo info) => Result
+
+            Returning None or a logical False continues iteration; returning
+            anything else aborts iteration and returns that value.
+
+            Keyword-only arguments:
+            * STRING name ("."):             Visit a subgroup instead
+            * PropLAID lapl (None):          Controls how "name" is interpreted
+            * INT idx_type (h5.INDEX_NAME):  What indexing strategy to use
+            * INT order (h5.ITER_NATIVE):    Order in which iteration occurs
+        """
+        cdef _LinkVisitor it = _LinkVisitor(func)
+
+        H5Lvisit_by_name(self.id, name, <H5_index_t>idx_type,
+            <H5_iter_order_t>order, cb_link_iterate, <void*>it, pdefault(lapl))
+
+        return it.retval
+
+
 
 
 
diff --git a/h5py/h5o.pyx b/h5py/h5o.pyx
index 9728190..2c6c1b9 100644
--- a/h5py/h5o.pyx
+++ b/h5py/h5o.pyx
@@ -19,6 +19,7 @@ include "sync.pxi"
 # Pyrex compile-time imports
 from h5 cimport init_hdf5, ObjectID
 from h5i cimport wrap_identifier
+from h5p cimport PropID, pdefault
 
 # Initialization
 init_hdf5()
@@ -58,77 +59,59 @@ def get_info(ObjectID obj not None):
     H5Oget_info(obj.id, &info.infostruct)
     return info
 
-cdef class _Visit_Data:
+
+# === Visit routines ==========================================================
+
+cdef class _ObjectVisitor:
 
     cdef object func
-    cdef object exc
     cdef object retval
     cdef ObjInfo objinfo
 
     def __init__(self, func):
         self.func = func
-        self.exc = None
         self.retval = None
         self.objinfo = ObjInfo()
 
-cdef herr_t visit_cb(hid_t obj, char* name, H5O_info_t *info, void* data):
+cdef herr_t cb_obj_iterate(hid_t obj, char* name, H5O_info_t *info, void* data) except 2:
 
-    cdef _Visit_Data wrapper
-    wrapper = <_Visit_Data>data
+    cdef _ObjectVisitor visit
+    visit = <_ObjectVisitor>data
 
-    wrapper.objinfo.infostruct = info[0]
+    visit.objinfo.infostruct = info[0]
 
-    try:
-        retval = wrapper.func(name, wrapper.objinfo)
-    except StopIteration:
-        return 1
-    except BaseException, e:   # The exception MUST be trapped, including SystemExit
-        wrapper.exc = e
-        return 1
+    visit.retval = visit.func(name, visit.objinfo)
 
-    if retval is not None:
-        wrapper.retval = retval
-        return 1
-
-    return 0
+    if (visit.retval is None) or (not visit.retval):
+        return 0
+    return 1
  
 @sync
-def visit(ObjectID obj not None, object func, int idx_type=H5_INDEX_NAME,
-          int order=H5_ITER_NATIVE):
-    """ (ObjectID obj, CALLABLE func, INT idx_type=, INT order=)
-
-        Recursively iterate a function or callable object over this group's
-        contents.  Your callable should match the signature:
+def visit(ObjectID loc not None, object func, *,
+          int idx_type=H5_INDEX_NAME, int order=H5_ITER_NATIVE,
+          char* name=".", PropID lapl=None):
+    """ (ObjectID loc, CALLABLE func, **kwds) => <Return value from func>
 
-            func(name, info)
+        Iterate a function or callable object over all objects below the
+        specified one.  Your callable should conform to the signature:
 
-        where "name" is (a) name relative to the starting group, and "info" is
-        an ObjInfo instance describing each object.  Please note the same
-        ObjInfo instance is provided call to call, with its values mutated.
-        Don't store references to it; use the copy module instead.
+            func(STRING name, ObjInfo info) => Result
 
-        Your callable should also conform to the following behavior:
+        Returning None or a logical False continues iteration; returning
+        anything else aborts iteration and returns that value.
 
-        1. Return None for normal iteration; raise StopIteration to cancel
-           and return None from h5o.visit.
-
-        2. Returning a value other than None cancels iteration and immediately
-           returns that value from h5o.visit.
-
-        3. Raising any other exception aborts iteration; the exception will
-           be correctly propagated.
+        Keyword-only arguments:
+        * STRING name ("."):            Visit a subgroup of "loc" instead
+        * PropLAID lapl (None):          Control how "name" is interpreted
+        * INT idx_type (h5.INDEX_NAME):  What indexing strategy to use
+        * INT order (h5.ITER_NATIVE):    Order in which iteration occurs
     """
-    cdef _Visit_Data wrapper
-    wrapper = _Visit_Data(func)
-
-    H5Ovisit(obj.id, <H5_index_t>idx_type, <H5_iter_order_t>order, visit_cb, <void*>wrapper)
-
-    if wrapper.exc is not None:
-        raise wrapper.exc
+    cdef _ObjectVisitor visit = _ObjectVisitor()
 
-    return wrapper.retval  # None or custom value
-    
+    H5Ovisit_by_name(loc.id, name, <H5_index_t>idx_type,
+        <H5_iter_order_t>order, cb_obj_iterate, <void*>visit, pdefault(lapl))
 
+    return visit.retval
 
 
 
diff --git a/setup.py b/setup.py
index 9c31407..b78fd36 100644
--- a/setup.py
+++ b/setup.py
@@ -189,7 +189,8 @@ class cybuild(build):
 
         build.finalize_options(self)
 
-        if self.cython_only or self.diag or self.threads or self.api or self.hdf5:
+        if any((self.cython, self.cython_only, self.diag, self.threads,
+                self.api, self.hdf5)):
             self._default = False
             self.cython = True
 
@@ -235,7 +236,7 @@ class cybuild(build):
 
         # Rebuild the C source files if necessary
         if self.cython:
-            self.compile_cython(modules)
+            self.compile_cython(sorted(modules))
             if self.cython_only:
                 exit(0)
 

-- 
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