[h5py] 45/455: Cleanup

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 854bc2ce8d23a51f16a1d00b06c4f201a506192b
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue Jun 10 04:27:23 2008 +0000

    Cleanup
---
 h5py/h5.pyx    |  2 --
 h5py/h5a.pyx   |  4 ++-
 h5py/h5d.pxd   | 26 +++++++++--------
 h5py/h5d.pyx   | 10 +++----
 h5py/h5e.pxd   | 87 ++++++++++++++++++++++++++++----------------------------
 h5py/h5e.pyx   | 89 +++++++++++++++++++++++++++++++++++++++++++---------------
 h5py/utils.pyx | 13 +++++++++
 7 files changed, 144 insertions(+), 87 deletions(-)

diff --git a/h5py/h5.pyx b/h5py/h5.pyx
index aea1e3c..e71ef8d 100644
--- a/h5py/h5.pyx
+++ b/h5py/h5.pyx
@@ -24,7 +24,6 @@
 """
 
 from h5e cimport _enable_exceptions
-from numpy cimport import_array
 
 # === Library init ============================================================
 
@@ -35,7 +34,6 @@ cdef int import_hdf5() except -1:
     return 0
 
 import_hdf5()
-import_array()
 
 # === API =====================================================================
 
diff --git a/h5py/h5a.pyx b/h5py/h5a.pyx
index 6aba468..a3f21c2 100644
--- a/h5py/h5a.pyx
+++ b/h5py/h5a.pyx
@@ -22,7 +22,7 @@ from h5p cimport H5P_DEFAULT
 from h5t cimport PY_H5Tclose
 from h5s cimport H5Sclose
 
-from numpy cimport ndarray, PyArray_DATA
+from numpy cimport import_array, ndarray, PyArray_DATA
 from utils cimport  check_numpy_read, check_numpy_write, \
                     emalloc, efree
 
@@ -31,6 +31,8 @@ import h5
 import h5t
 import h5s
 
+import_array()
+
 # === General attribute operations ============================================
 
 def create(hid_t loc_id, char* name, hid_t type_id, hid_t space_id):
diff --git a/h5py/h5d.pxd b/h5py/h5d.pxd
index 40fef57..3c77d7f 100644
--- a/h5py/h5d.pxd
+++ b/h5py/h5d.pxd
@@ -15,51 +15,52 @@
 # directory.
 
 from defs_c cimport size_t, time_t
-from h5 cimport hid_t, hbool_t, herr_t, htri_t, hsize_t, hssize_t, hvl_t, haddr_t, HADDR_UNDEF
+from h5 cimport hid_t, herr_t, hsize_t, haddr_t
 
 cdef extern from "hdf5.h":
 
   # HDF5 layouts
-  cdef enum H5D_layout_t:
+  ctypedef enum H5D_layout_t:
     H5D_LAYOUT_ERROR    = -1,
     H5D_COMPACT         = 0,    # raw data is very small
     H5D_CONTIGUOUS      = 1,    # the default
     H5D_CHUNKED         = 2,    # slow and fancy
     H5D_NLAYOUTS        = 3     # this one must be last!
 
-  cdef enum H5D_alloc_time_t:
+  ctypedef enum H5D_alloc_time_t:
     H5D_ALLOC_TIME_ERROR	=-1,
     H5D_ALLOC_TIME_DEFAULT  =0,
     H5D_ALLOC_TIME_EARLY	=1,
     H5D_ALLOC_TIME_LATE	    =2,
     H5D_ALLOC_TIME_INCR	    =3
 
-  cdef enum H5D_space_status_t:
+  ctypedef enum H5D_space_status_t:
     H5D_SPACE_STATUS_ERROR	        =-1,
     H5D_SPACE_STATUS_NOT_ALLOCATED	=0,
     H5D_SPACE_STATUS_PART_ALLOCATED	=1,
     H5D_SPACE_STATUS_ALLOCATED		=2
 
-  cdef enum H5D_fill_time_t:
+  ctypedef enum H5D_fill_time_t:
     H5D_FILL_TIME_ERROR	=-1,
     H5D_FILL_TIME_ALLOC =0,
     H5D_FILL_TIME_NEVER	=1,
     H5D_FILL_TIME_IFSET	=2
 
-  cdef enum H5D_fill_value_t:
+  ctypedef enum H5D_fill_value_t:
     H5D_FILL_VALUE_ERROR        =-1,
     H5D_FILL_VALUE_UNDEFINED    =0,
     H5D_FILL_VALUE_DEFAULT      =1,
     H5D_FILL_VALUE_USER_DEFINED =2
 
 
-  # --- Dataset operations ----------------------------------------------------
-  hid_t     H5Dcreate(hid_t loc, char* name, hid_t type_id, hid_t space_id, hid_t create_plist_id) except *
+  hid_t     H5Dcreate(hid_t loc, char* name, hid_t type_id, hid_t space_id, 
+                        hid_t create_plist_id) except *
   hid_t     H5Dopen(hid_t file_id, char *name) except *
   herr_t    H5Dclose(hid_t dset_id) except *
 
   hid_t     H5Dget_space(hid_t dset_id) except *
-  herr_t    H5Dget_space_status(hid_t dset_id, H5D_space_status_t *status) except *
+  herr_t    H5Dget_space_status(hid_t dset_id, 
+                                H5D_space_status_t *status) except *
   hid_t     H5Dget_type(hid_t dset_id) except *
   hid_t     H5Dget_create_plist(hid_t dataset_id) except *
   
@@ -73,11 +74,12 @@ cdef extern from "hdf5.h":
 
   herr_t    H5Dextend(hid_t dataset_id, hsize_t *size) except *
 
-  # These are not for the external API
   herr_t    H5Dfill(void *fill, hid_t fill_type_id, void *buf, 
                     hid_t buf_type_id, hid_t space_id  ) except *
-  herr_t    H5Dvlen_get_buf_size(hid_t dset_id, hid_t type_id, hid_t space_id, hsize_t *size) except *
-  herr_t    H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist, void *buf) except *
+  herr_t    H5Dvlen_get_buf_size(hid_t dset_id, hid_t type_id, 
+                                    hid_t space_id, hsize_t *size) except *
+  herr_t    H5Dvlen_reclaim(hid_t type_id, hid_t space_id, 
+                            hid_t plist, void *buf) except *
   ctypedef  herr_t (*H5D_operator_t)(void *elem, hid_t type_id, unsigned ndim,
 				    hsize_t *point, void *operator_data)
   herr_t    H5Diterate(void *buf, hid_t type_id, hid_t space_id, 
diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index dfdc988..b592d0e 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -23,11 +23,11 @@
 """
 
 # Pyrex compile-time imports
-from h5  cimport herr_t, hid_t, size_t, hsize_t, htri_t, haddr_t, HADDR_UNDEF
+from h5  cimport hid_t, size_t, hsize_t, hssize_t
 from h5s cimport H5Sclose, H5S_ALL, H5S_UNLIMITED, H5S_SCALAR, H5S_SIMPLE
 from h5t cimport PY_H5Tclose
 from h5p cimport H5P_DEFAULT, H5Pclose
-from numpy cimport ndarray, PyArray_DATA
+from numpy cimport import_array, ndarray, PyArray_DATA
 from utils cimport  check_numpy_read, check_numpy_write, \
                     convert_tuple, \
                     emalloc, efree
@@ -38,6 +38,8 @@ from h5 import DDict
 import h5t
 import h5s
 
+import_array()
+
 # === Public constants and data structures ====================================
 
 COMPACT     = H5D_COMPACT
@@ -110,7 +112,6 @@ def read(hid_t dset_id, hid_t mspace_id, hid_t fspace_id, ndarray arr_obj, hid_t
         For a friendlier version of this function, try py_read_slab().
     """
     cdef hid_t mtype_id
-    cdef herr_t retval
     cdef int array_ok
     mtype_id = 0
 
@@ -139,7 +140,6 @@ def write(hid_t dset_id, hid_t mspace_id, hid_t fspace_id, ndarray arr_obj, hid_
         For a friendlier version of this function, try py_write_slab()
     """
     cdef hid_t mtype_id
-    cdef herr_t retval
     cdef int array_ok
     mtype_id = 0
 
@@ -166,7 +166,6 @@ def extend(hid_t dset_id, object shape):
     cdef hsize_t* dims
     cdef int rank
     cdef hid_t space_id
-    cdef herr_t retval
     space_id = 0
     dims = NULL
 
@@ -529,7 +528,6 @@ def py_patch(hid_t ds_source, hid_t ds_sink, hid_t transfer_space):
 
     cdef hssize_t npoints
     cdef size_t type_size
-    cdef herr_t retval
 
     source_space = 0    
     sink_space = 0
diff --git a/h5py/h5e.pxd b/h5py/h5e.pxd
index 1c538cb..fb58493 100644
--- a/h5py/h5e.pxd
+++ b/h5py/h5e.pxd
@@ -14,42 +14,43 @@
 # license is available in the file licenses/hdf5.txt in the distribution
 # root directory.
 
-from defs_c cimport size_t, time_t
-from h5 cimport hid_t, hbool_t, herr_t, htri_t, hsize_t, hssize_t, hvl_t
+from h5 cimport herr_t
 from python cimport BaseException, PyErr_SetNone
 
 cdef extern from "hdf5.h":
 
+  # Major error numbers
   ctypedef enum H5E_major_t:
-    H5E_NONE_MAJOR       = 0,
-    H5E_ARGS,
-    H5E_RESOURCE,
-    H5E_INTERNAL,
-    H5E_FILE,
-    H5E_IO,
-    H5E_FUNC,
-    H5E_ATOM,
-    H5E_CACHE,
-    H5E_BTREE,
-    H5E_SYM,
-    H5E_HEAP,
-    H5E_OHDR,
-    H5E_DATATYPE,
-    H5E_DATASPACE,
-    H5E_DATASET,
-    H5E_STORAGE,
-    H5E_PLIST,
-    H5E_ATTR,
-    H5E_PLINE,
-    H5E_EFL,
-    H5E_REFERENCE,
-    H5E_VFL,
-    H5E_TBBT,
-    H5E_TST,
-    H5E_RS,
-    H5E_ERROR,
-    H5E_SLIST
-
+    H5E_NONE_MAJOR       = 0,   # special zero, no error                     
+    H5E_ARGS,                   # invalid arguments to routine               
+    H5E_RESOURCE,               # resource unavailable                       
+    H5E_INTERNAL,               #  Internal error (too specific to document)
+    H5E_FILE,                   # file Accessability                         
+    H5E_IO,                     # Low-level I/O                              
+    H5E_FUNC,                   # function Entry/Exit                        
+    H5E_ATOM,                   # object Atom                                
+    H5E_CACHE,                  # object Cache                               
+    H5E_BTREE,                  # B-Tree Node                                
+    H5E_SYM,                    # symbol Table                               
+    H5E_HEAP,                   # Heap                                       
+    H5E_OHDR,                   # object Header                              
+    H5E_DATATYPE,               # Datatype                                   
+    H5E_DATASPACE,              # Dataspace                                  
+    H5E_DATASET,                # Dataset                                    
+    H5E_STORAGE,                # data storage                               
+    H5E_PLIST,                  # Property lists                             
+    H5E_ATTR,                   # Attribute                                  
+    H5E_PLINE,                  # Data filters                               
+    H5E_EFL,                    # External file list                         
+    H5E_REFERENCE,              # References                                 
+    H5E_VFL,                    # Virtual File Layer                 
+    H5E_TBBT,                   # Threaded, Balanced, Binary Trees           
+    H5E_TST,                    # Ternary Search Trees                       
+    H5E_RS,                     # Reference Counted Strings                  
+    H5E_ERROR,                  # Error API                                  
+    H5E_SLIST                   # Skip Lists                                 
+
+  # Minor error numbers
   ctypedef enum H5E_minor_t:
     H5E_NONE_MINOR       = 0
 
@@ -75,18 +76,18 @@ cdef extern from "hdf5.h":
     H5E_FILEOPEN,               # file already open                          
     H5E_CANTCREATE,             # Can't create file                          
     H5E_CANTOPENFILE,           # Can't open file                            
-    H5E_CANTCLOSEFILE,          # Can't close file			     
+    H5E_CANTCLOSEFILE,          # Can't close file                 
     H5E_NOTHDF5,                # not an HDF5 format file                    
     H5E_BADFILE,                # bad file ID accessed                       
     H5E_TRUNCATED,              # file has been truncated                    
-    H5E_MOUNT,			        # file mount error			     
+    H5E_MOUNT,                    # file mount error                 
 
     #  Generic low-level file I/O errors
     H5E_SEEKERROR,              # seek failed                                
     H5E_READERROR,              # read failed                                
     H5E_WRITEERROR,             # write failed                               
     H5E_CLOSEERROR,             # close failed                               
-    H5E_OVERFLOW,		        # address overflowed			     
+    H5E_OVERFLOW,                # address overflowed                 
     H5E_FCNTL,                  # file fcntl failed                          
 
     #  Function entry/exit interface errors 
@@ -136,8 +137,8 @@ cdef extern from "hdf5.h":
     H5E_CANTCLOSEOBJ,           # Can't close object                         
     H5E_COMPLEN,                # name component is too long                 
     H5E_LINK,                   # link count failure                         
-    H5E_SLINK,			        # symbolic link error			     
-    H5E_PATH,			        # Problem with path to object		     
+    H5E_SLINK,                    # symbolic link error                 
+    H5E_PATH,                    # Problem with path to object             
 
     #  Datatype conversion errors 
     H5E_CANTCONVERT,            # Can't convert datatypes  TypeError?
@@ -157,14 +158,14 @@ cdef extern from "hdf5.h":
     H5E_DUPCLASS,               # Duplicate class name in parent class       
 
     #  Parallel errors 
-    H5E_MPI,			        # some MPI function failed		     
-    H5E_MPIERRSTR,		        # MPI Error String 			     
+    H5E_MPI,                    # some MPI function failed             
+    H5E_MPIERRSTR,                # MPI Error String                  
 
     #  Heap errors 
-    H5E_CANTRESTORE,		    # Can't restore condition                    
+    H5E_CANTRESTORE,            # Can't restore condition                    
 
     #  TBBT errors 
-    H5E_CANTMAKETREE,		    # Can't create TBBT tree                     
+    H5E_CANTMAKETREE,            # Can't create TBBT tree                     
 
     #  I/O pipeline errors 
     H5E_NOFILTER,               # requested filter is not available          
@@ -174,7 +175,7 @@ cdef extern from "hdf5.h":
     H5E_NOENCODER,              #  Filter present, but encoding disabled     
 
     #  System level errors 
-    H5E_SYSERRSTR               #  System error message			     
+    H5E_SYSERRSTR               #  System error message                 
 
   cdef enum H5E_direction_t:
     H5E_WALK_UPWARD    = 0  # begin deep, end at API function    
@@ -193,9 +194,9 @@ cdef extern from "hdf5.h":
 
   char      *H5Eget_major(H5E_major_t n)
   char      *H5Eget_minor(H5E_minor_t n)
-  herr_t    H5Eclear()
+  herr_t    H5Eclear() except *
   ctypedef herr_t (*H5E_auto_t)(void *client_data)
-  herr_t    H5Eset_auto(H5E_auto_t func, void *client_data )
+  herr_t    H5Eset_auto(H5E_auto_t func, void *client_data)
   herr_t    H5Eget_auto(H5E_auto_t *func, void** client_data)
   ctypedef herr_t (*H5E_walk_t)(int n, H5E_error_t *err_desc, void* client_data)  
   herr_t    H5Ewalk(H5E_direction_t direction, H5E_walk_t func, void* client_data  )
diff --git a/h5py/h5e.pyx b/h5py/h5e.pyx
index d315f82..a2c959f 100644
--- a/h5py/h5e.pyx
+++ b/h5py/h5e.pyx
@@ -28,16 +28,12 @@ class ConversionError(StandardError):
     """
     pass
 
-class FileError(H5Error):
-    """ HDF5 logical file error (H5E_FILE)
-    """
-    pass
+# --- New classes -------------------------------------------------------------
 
-class GroupError(H5Error):
-    pass
+# H5E_ARGS => ValueError
 
-class DataspaceError(H5Error):
-    """ H5E_DATASPACE
+class ResourceError(H5Error):
+    """ H5E_RESOURCE
     """
     pass
 
@@ -46,6 +42,11 @@ class DatatypeError(H5Error):
     """
     pass
 
+class DataspaceError(H5Error):
+    """ H5E_DATASPACE
+    """
+    pass
+
 class DatasetError(H5Error):
     """ H5E_DATASET
     """
@@ -56,6 +57,7 @@ class PropertyError(H5Error):
     """
     pass
 
+
 class H5AttributeError(H5Error):
     """ H5E_ATTR
     """
@@ -66,10 +68,9 @@ class FilterError(H5Error):
     """
     pass
 
-class IdentifierError(H5Error):
-    pass
-
 class H5ReferenceError(H5Error):
+    """ H5E_REFERENCE
+    """
     pass
 
 
@@ -79,6 +80,14 @@ cdef class H5ErrorStackElement:
     """
         Represents an entry in the HDF5 error stack.
         Loosely modeled on the H5E_error_t struct.
+
+        Atributes
+        maj_num:    INT major error number
+        min_num:    INT minor error number
+        func_name:  STRING name of failing function
+        file_name:  STRING name of file in which error occurreed
+        line:       UINT line number at which error occured
+        desc:       STRING description of error
     """
     cdef readonly int maj_num
     cdef readonly int min_num
@@ -110,13 +119,25 @@ cdef herr_t walk_cb(int n, H5E_error_t *err_desc, void* stack_in):
     return 0
 
 def get_error_stack():
+    """ () => LIST error_stack
 
+        Retrieve the HDF5 error stack as a list of ErrorStackElement objects,
+        with the most recent call (the deepest one) listed last.
+    """
     stack = []
     H5Ewalk(H5E_WALK_DOWNWARD, walk_cb, <void*>stack)
     return stack
 
 def get_error_string():
-    """ Return the HDF5 error stack as a single string.
+    """ () => STRING error_stack
+
+        Return a string representation of the current error condition.
+        Format is one line of the format 
+            '<Description> (<Function name>: <error type>)'
+
+        If the stack is more than one level deep, this is followed by n lines
+        of the format:
+            '    n: "<Description>" at <function name>'
     """
     cdef int stacklen
     cdef H5ErrorStackElement el
@@ -140,18 +161,31 @@ def get_error_string():
 
     return msg
 
+def clear():
+    """ ()
+
+        Clear the error stack.
+    """
+    H5Eclear()
+
 def get_major(int error):
     """ (INT error) => STRING description
+
+        Get a description associated with an HDF5 minor error code.
     """
     return H5E_get_major(<H5E_major_t>error)
 
 def get_minor(int error):
     """ (INT error) => STRING description
+
+        Get a description associated with an HDF5 minor error code.
     """
     return H5E_get_minor(<H5E_minor_t>error)
 
 def get_error(int error):
     """ (INT errno) => STRING description
+
+        Get a full description for an "errno"-style HDF5 error code.
     """
     cdef int mj
     cdef int mn
@@ -159,6 +193,18 @@ def get_error(int error):
     mj = (error-mn)/1000
     return "%s: %s" % (H5E_get_major(<H5E_major_t>mj), H5E_get_minor(<H5E_minor_t>mn))
 
+def split_error(int error):
+    """ (INT errno) => (INT major, INT minor)
+
+        Convenience function to split an "errno"-style HDF5 error code into
+        its major and minor components.  It's recommended you use this
+        function instead of doing it yourself, as the "encoding" may change
+        in the future.
+    """
+    cdef int mn
+    mn = error % 1000
+    return ((error-mn)/1000, mn)
+
 # === Automatic exception API =================================================
 
 cdef herr_t extract_cb(int n, H5E_error_t *err_desc, void* data_in):
@@ -184,21 +230,18 @@ cdef herr_t err_callback(void* client_data):
     mj = err_struct.maj_num
     mn = err_struct.min_num
 
-    # Highest priority: really bad errors
-    if mn == H5E_UNSUPPORTED:
-        exc = NotImplementedError
-    elif mj == H5E_IO:
+    # File-related errors traditionally raise IOError.
+    # Also raise IOError for low-level disk I/O errors
+    if mj == H5E_FILE or mj == H5E_IO:
         exc = IOError
 
-    # Map function argument exceptions to native Python exceptions.
-    # H5E_BADTYPE does not raise TypeError as this is too easily confused
-    # with the results of Pyrex auto-validation.
+    # All errors which result from illegal function arguments
     elif mj == H5E_ARGS:
         exc = ValueError
 
     # Major errors which map to new h5e exception classes
-    elif mj == H5E_FILE:
-        exc = FileError
+    elif mj == H5E_RESOURCE:
+        exc = ResourceError
     elif mj == H5E_DATATYPE:
         exc = DatatypeError
     elif mj == H5E_DATASPACE:
@@ -206,7 +249,7 @@ cdef herr_t err_callback(void* client_data):
     elif mj == H5E_DATASET:
         exc = DatasetError
     elif mj == H5E_PLIST:
-        exc = PropertyListError
+        exc = PropertyError
     elif mj == H5E_ATTR:
         exc = H5AttributeError
     elif mj == H5E_PLINE:
@@ -214,7 +257,7 @@ cdef herr_t err_callback(void* client_data):
     elif mj == H5E_REFERENCE:
         exc = H5ReferenceError
 
-    # Catchall: base H5Error
+    # Catchall: base H5Error.  
     else:
         exc = H5Error
 
diff --git a/h5py/utils.pyx b/h5py/utils.pyx
index 70b468d..b8e3618 100644
--- a/h5py/utils.pyx
+++ b/h5py/utils.pyx
@@ -1,8 +1,21 @@
+#+
+# 
+# This file is part of h5py, a low-level Python interface to the HDF5 library.
+# 
+# Copyright (C) 2008 Andrew Collette
+# http://h5py.alfven.org
+# License: BSD  (See LICENSE.txt for full license)
+# 
+# $Date$
+# 
+#-
+
 from python cimport PyTuple_Check
 
 cdef int require_tuple(object tpl, int none_allowed, int size, char* name) except -1:
     # Ensure that tpl is in fact a tuple, or None if none_allowed is nonzero.
     # If size >= 0, also ensure that the length matches.
+    # Otherwise raises ValueError
 
     if (tpl is None and none_allowed) or \
       ( PyTuple_Check(tpl) and (size < 0 or len(tpl) == size)):

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