[h5py] 129/455: Consolidate internal C api, more cleanup
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 0e5f57b84dc032063d678ea597470d206eca3a6b
Author: andrewcollette <andrew.collette at gmail.com>
Date: Fri Sep 26 07:04:04 2008 +0000
Consolidate internal C api, more cleanup
---
h5py/h5.pyx | 15 +++++++--------
h5py/h5a.pyx | 4 ++--
h5py/h5d.pyx | 19 ++++++++++++-------
h5py/h5f.pxd | 4 ----
h5py/h5f.pyx | 44 ++++++++++----------------------------------
h5py/h5g.pyx | 2 +-
h5py/h5i.pxd | 3 +++
h5py/h5i.pyx | 29 +++++++++++++++++++++++++++++
h5py/h5o.pyx | 2 +-
h5py/h5p.pyx | 2 +-
h5py/h5r.pyx | 2 +-
h5py/h5s.pyx | 51 +++++++++++++++++----------------------------------
h5py/h5t.pyx | 2 +-
h5py/utils.pxd | 4 ----
h5py/utils.pyx | 20 ++------------------
15 files changed, 87 insertions(+), 116 deletions(-)
diff --git a/h5py/h5.pyx b/h5py/h5.pyx
index ea8b2fa..c2d60c2 100644
--- a/h5py/h5.pyx
+++ b/h5py/h5.pyx
@@ -41,7 +41,7 @@ import threading
cdef class H5PYConfig:
"""
- Provides runtime access to the library compilation options.
+ Provides runtime access to global library settings.
"""
def __init__(self):
@@ -557,7 +557,7 @@ cpdef object error_string():
stacklen = len(stack)
if stacklen == 0:
- msg = "Unspecified HDF5 error"
+ msg = "No HDF5 error recorded"
else:
el = stack[0]
msg = "%s (%s)" % (el.desc.capitalize(), el.func_name)
@@ -592,10 +592,9 @@ cdef herr_t extract_cb(int n, H5E_error_t *err_desc, void* data_in):
cdef herr_t err_callback(void* client_data) with gil:
# Callback which sets Python exception based on the current error stack.
- # Can't use the standard Pyrex raise because then the traceback
- # points here. MUST be "with gil" as it can be called by nogil HDF5
- # routines. By definition any function for which this can be called
- # already holds the PHIL.
+ # MUST be "with gil" as it can be called by nogil HDF5 routines.
+ # By definition any function for which this can be called already
+ # holds the PHIL.
cdef H5E_error_t err_struct
cdef H5E_major_t mj
@@ -606,11 +605,11 @@ cdef herr_t err_callback(void* client_data) with gil:
try:
exc = _exceptions[mj]
- except:
+ except KeyError:
exc = H5Error
msg = error_string()
- PyErr_SetString(exc, msg)
+ PyErr_SetString(exc, msg) # Can't use "raise" or the traceback points here
return 1
diff --git a/h5py/h5a.pyx b/h5py/h5a.pyx
index 319e259..6eeeed2 100644
--- a/h5py/h5a.pyx
+++ b/h5py/h5a.pyx
@@ -50,7 +50,7 @@ def open_idx(ObjectID loc not None, int idx):
"""
# 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
- # HDF5 library.
+ # 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))
@@ -177,7 +177,7 @@ cdef class AttrID(ObjectID):
shape: A Numpy-style shape tuple representing the dataspace
Hashable: No
- Equality: Python default
+ Equality: Identifier comparison
"""
property name:
""" The attribute's name
diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index a5b8022..8b3f97c 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -54,7 +54,7 @@ FILL_VALUE_DEFAULT = H5D_FILL_VALUE_DEFAULT
FILL_VALUE_USER_DEFINED = H5D_FILL_VALUE_USER_DEFINED
-# === Basic dataset operations ================================================
+# === Dataset operations ======================================================
@sync
def create(ObjectID loc not None, char* name, TypeID tid not None,
@@ -80,7 +80,7 @@ def open(ObjectID loc not None, char* name):
# It's not legal to call PyErr_Occurred() with nogil, so we can't use
# the standard except * syntax. Trap negative return numbers and convert them
-# to something Pyrex can recognize.
+# to something Cython can recognize.
cdef int H5PY_H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t plist_id, void *buf) nogil except -1:
@@ -101,7 +101,6 @@ cdef int H5PY_H5Dwrite(hid_t dset_id, hid_t mem_type, hid_t mem_space, hid_t
return -1
return retval
-# === Dataset I/O =============================================================
cdef class DatasetID(ObjectID):
@@ -118,8 +117,8 @@ cdef class DatasetID(ObjectID):
shape: Numpy-style shape tuple representing the dataspace
rank: Integer giving dataset rank
- Hashable: Yes, if not anonymous
- Equality: HDF5 identity if not anonymous, otherwise Python default
+ Hashable: Yes, unless anonymous
+ Equality: True HDF5 identity if unless anonymous
"""
property dtype:
@@ -199,7 +198,10 @@ cdef class DatasetID(ObjectID):
arr_obj.flags &= (~NPY_WRITEABLE) # Wish-it-was-a-mutex approach
try:
- with nogil:
+ IF H5PY_THREADS:
+ with nogil:
+ H5PY_H5Dread(self_id, mtype_id, mspace_id, fspace_id, plist_id, data)
+ ELSE:
H5PY_H5Dread(self_id, mtype_id, mspace_id, fspace_id, plist_id, data)
finally:
arr_obj.flags |= NPY_WRITEABLE
@@ -239,7 +241,10 @@ cdef class DatasetID(ObjectID):
arr_obj.flags &= (~NPY_WRITEABLE) # Wish-it-was-a-mutex approach
try:
- with nogil:
+ IF H5PY_THREADS:
+ with nogil:
+ H5PY_H5Dwrite(self_id, mtype_id, mspace_id, fspace_id, plist_id, data)
+ ELSE:
H5PY_H5Dwrite(self_id, mtype_id, mspace_id, fspace_id, plist_id, data)
finally:
arr_obj.flags |= NPY_WRITEABLE
diff --git a/h5py/h5f.pxd b/h5py/h5f.pxd
index 7ff9425..e4b1c66 100644
--- a/h5py/h5f.pxd
+++ b/h5py/h5f.pxd
@@ -17,8 +17,4 @@ from h5 cimport class ObjectID
cdef class FileID(ObjectID):
pass
-# Internal h5py function to wrap file-resident identifiers
-# TODO: move this to h5i
-cdef object wrap_identifier(hid_t ident)
-
diff --git a/h5py/h5f.pyx b/h5py/h5f.pyx
index c4dfb10..577b356 100644
--- a/h5py/h5f.pyx
+++ b/h5py/h5f.pyx
@@ -21,9 +21,7 @@ include "sync.pxi"
from h5 cimport init_hdf5
from h5p cimport propwrap, pdefault, PropFAID, PropFCID
from h5t cimport typewrap
-from h5a cimport AttrID
-from h5d cimport DatasetID
-from h5g cimport GroupID
+from h5i cimport wrap_identifier
from utils cimport emalloc, efree
# Initialization
@@ -163,28 +161,6 @@ def get_obj_count(object where=OBJ_ALL, int types=H5F_OBJ_ALL):
return H5Fget_obj_count(where_id, types)
-cdef object wrap_identifier(hid_t ident):
- # Support function for get_obj_ids
- # TODO: move this to H5I
-
- cdef H5I_type_t typecode
- cdef ObjectID obj
- typecode = H5Iget_type(ident)
- if typecode == H5I_FILE:
- obj = FileID(ident)
- elif typecode == H5I_DATASET:
- obj = DatasetID(ident)
- elif typecode == H5I_GROUP:
- obj = GroupID(ident)
- elif typecode == H5I_ATTR:
- obj = AttrID(ident)
- elif typecode == H5I_DATATYPE:
- obj = typewrap(ident)
- else:
- raise ValueError("Unrecognized type code %d" % typecode)
-
- return obj
-
@sync
def get_obj_ids(object where=OBJ_ALL, int types=H5F_OBJ_ALL):
""" (OBJECT where=OBJ_ALL, types=OBJ_ALL) => LIST open_ids
@@ -204,17 +180,16 @@ def get_obj_ids(object where=OBJ_ALL, int types=H5F_OBJ_ALL):
cdef int count
cdef int i
cdef hid_t where_id
- cdef hid_t *obj_list
- cdef list py_obj_list
- obj_list = NULL
- py_obj_list = []
+ cdef hid_t *obj_list = NULL
+ cdef list py_obj_list = []
if isinstance(where, FileID):
where_id = where.id
- elif isinstance(where, int) or isinstance(where, long):
- where_id = where
else:
- raise TypeError("Location must be a FileID or OBJ_ALL.")
+ try:
+ where_id = int(where)
+ except TypeError:
+ raise TypeError("Location must be a FileID or OBJ_ALL.")
try:
count = H5Fget_obj_count(where_id, types)
@@ -230,6 +205,7 @@ def get_obj_ids(object where=OBJ_ALL, int types=H5F_OBJ_ALL):
finally:
efree(obj_list)
+
# === FileID implementation ===================================================
cdef class FileID(ObjectID):
@@ -244,8 +220,8 @@ cdef class FileID(ObjectID):
Properties:
name: File name on disk
- Hashable: Yes, always
- Equality: HDF5 object identity
+ Hashable: Yes, unique to the file (but not the access mode)
+ Equality: Hash comparison
"""
property name:
diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index d8ec0d3..b505af4 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -261,7 +261,7 @@ cdef class GroupID(ObjectID):
for h5py.h5l.LinkProxy for more information.
Hashable: Yes, unless anonymous
- Equality: HDF5 object identity if not anonymous, or NotImplemented
+ Equality: True HDF5 identity unless anonymous
"""
IF H5PY_18API:
diff --git a/h5py/h5i.pxd b/h5py/h5i.pxd
index 2116324..9dd24f2 100644
--- a/h5py/h5i.pxd
+++ b/h5py/h5i.pxd
@@ -12,3 +12,6 @@
include "defs.pxd"
+from h5 cimport ObjectID
+
+cdef ObjectID wrap_identifier(hid_t ident)
diff --git a/h5py/h5i.pyx b/h5py/h5i.pyx
index 7b78fc8..fcc96fe 100644
--- a/h5py/h5i.pyx
+++ b/h5py/h5i.pyx
@@ -20,6 +20,12 @@ include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5, ObjectID
from h5f cimport FileID
+from h5d cimport DatasetID
+from h5g cimport GroupID
+from h5a cimport AttrID
+from h5t cimport typewrap
+from h5p cimport propwrap
+
from utils cimport emalloc, efree
init_hdf5()
@@ -40,6 +46,29 @@ GENPROP_CLS = H5I_GENPROP_CLS
GENPROP_LST = H5I_GENPROP_LST
DATATYPE = H5I_DATATYPE
+cdef ObjectID wrap_identifier(hid_t ident):
+
+ cdef H5I_type_t typecode
+ cdef ObjectID obj
+
+ typecode = H5Iget_type(ident)
+ if typecode == H5I_FILE:
+ obj = FileID(ident)
+ elif typecode == H5I_DATASET:
+ obj = DatasetID(ident)
+ elif typecode == H5I_GROUP:
+ obj = GroupID(ident)
+ elif typecode == H5I_ATTR:
+ obj = AttrID(ident)
+ elif typecode == H5I_DATATYPE:
+ obj = typewrap(ident)
+ elif typecode == H5I_GENPROP_LST:
+ obj = propwrap(ident)
+ else:
+ raise ValueError("Unrecognized type code %d" % typecode)
+
+ return obj
+
# === Identifier API ==========================================================
@sync
diff --git a/h5py/h5o.pyx b/h5py/h5o.pyx
index c97c894..9728190 100644
--- a/h5py/h5o.pyx
+++ b/h5py/h5o.pyx
@@ -18,7 +18,7 @@ include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5, ObjectID
-from h5f cimport wrap_identifier
+from h5i cimport wrap_identifier
# Initialization
init_hdf5()
diff --git a/h5py/h5p.pyx b/h5py/h5p.pyx
index 41b22bf..772c2e3 100644
--- a/h5py/h5p.pyx
+++ b/h5py/h5p.pyx
@@ -21,7 +21,7 @@ include "sync.pxi"
# Compile-time imports
from h5 cimport init_hdf5
from utils cimport require_tuple, convert_dims, convert_tuple, \
- emalloc, efree, require_list, \
+ emalloc, efree, \
check_numpy_write, check_numpy_read
from numpy cimport ndarray, import_array
from h5t cimport TypeID, py_create
diff --git a/h5py/h5r.pyx b/h5py/h5r.pyx
index c8077fe..763c983 100644
--- a/h5py/h5r.pyx
+++ b/h5py/h5r.pyx
@@ -21,7 +21,7 @@ include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5, ObjectID
-from h5f cimport wrap_identifier
+from h5i cimport wrap_identifier
from h5s cimport SpaceID
# Initialization
diff --git a/h5py/h5s.pyx b/h5py/h5s.pyx
index 920ec92..c32d413 100644
--- a/h5py/h5s.pyx
+++ b/h5py/h5s.pyx
@@ -19,7 +19,7 @@ include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5
-from utils cimport require_tuple, require_list, convert_dims, convert_tuple, \
+from utils cimport require_tuple, convert_dims, convert_tuple, \
emalloc, efree, create_numpy_hsize, create_hsize_array
from numpy cimport ndarray
from python_string cimport PyString_FromStringAndSize
@@ -86,10 +86,8 @@ def create_simple(object dims_tpl, object max_dims_tpl=None):
an unlimited dimension.
"""
cdef int rank
- cdef hsize_t* dims
- cdef hsize_t* max_dims
- dims = NULL
- max_dims = NULL
+ cdef hsize_t* dims = NULL
+ cdef hsize_t* max_dims = NULL
require_tuple(dims_tpl, 0, -1, "dims_tpl")
rank = len(dims_tpl)
@@ -117,8 +115,7 @@ IF H5PY_18API:
Unserialize a dataspace. Bear in mind you can also use the native
Python pickling machinery to do this.
"""
- cdef char* buf_
- buf_ = buf
+ cdef char* buf_ = buf
return SpaceID(H5Sdecode(buf_))
# === H5S class API ===========================================================
@@ -167,10 +164,8 @@ cdef class SpaceID(ObjectID):
Serialize a dataspace, including its selection. Bear in mind you
can also use the native Python pickling machinery to do this.
"""
- cdef void* buf
- cdef size_t nalloc
- buf = NULL
- nalloc = 0
+ cdef void* buf = NULL
+ cdef size_t nalloc = 0
H5Sencode(self.id, NULL, &nalloc)
buf = emalloc(nalloc)
@@ -191,8 +186,7 @@ cdef class SpaceID(ObjectID):
@sync
def __setstate__(self, state):
- cdef char* buf
- buf = state
+ cdef char* buf = state
self.id = H5Sdecode(buf)
# === Simple dataspaces ===================================================
@@ -216,8 +210,7 @@ cdef class SpaceID(ObjectID):
"""
cdef int rank
cdef int i
- cdef hssize_t *dims
- dims = NULL
+ cdef hssize_t *dims = NULL
try:
if not H5Sis_simple(self.id):
@@ -257,8 +250,7 @@ cdef class SpaceID(ObjectID):
is True, retrieve the maximum dataspace size instead.
"""
cdef int rank
- cdef hsize_t* dims
- dims = NULL
+ cdef hsize_t* dims = NULL
rank = H5Sget_simple_extent_dims(self.id, NULL, NULL)
@@ -313,10 +305,8 @@ cdef class SpaceID(ObjectID):
an unlimited dimension.
"""
cdef int rank
- cdef hsize_t* dims
- cdef hsize_t* max_dims
- dims = NULL
- max_dims = NULL
+ cdef hsize_t* dims = NULL
+ cdef hsize_t* max_dims = NULL
require_tuple(dims_tpl, 0, -1, "dims_tpl")
rank = len(dims_tpl)
@@ -375,10 +365,8 @@ cdef class SpaceID(ObjectID):
the current selection.
"""
cdef int rank
- cdef hsize_t *start
- cdef hsize_t *end
- start = NULL
- end = NULL
+ cdef hsize_t *start = NULL
+ cdef hsize_t *end = NULL
rank = H5Sget_simple_extent_ndims(self.id)
@@ -532,15 +520,10 @@ cdef class SpaceID(ObjectID):
documentation for the meaning of the "block" and "op" keywords.
"""
cdef int rank
- cdef hsize_t* start_array
- cdef hsize_t* count_array
- cdef hsize_t* stride_array
- cdef hsize_t* block_array
-
- start_array = NULL
- count_array = NULL
- stride_array = NULL
- block_array = NULL
+ cdef hsize_t* start_array = NULL
+ cdef hsize_t* count_array = NULL
+ cdef hsize_t* stride_array = NULL
+ cdef hsize_t* block_array = NULL
# Dataspace rank. All provided tuples must match this.
rank = H5Sget_simple_extent_ndims(self.id)
diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index c235059..2a0dc5a 100644
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -314,7 +314,7 @@ cdef class TypeID(ObjectID):
"""
Base class for type identifiers (implements common operations)
- Hashable: If locked and committed; in HDF5 1.8.X, also if only locked
+ Hashable: If committed; in HDF5 1.8.X, also if locked
Equality: Logical H5T comparison
"""
diff --git a/h5py/utils.pxd b/h5py/utils.pxd
index 2361ae2..4e0dbc0 100644
--- a/h5py/utils.pxd
+++ b/h5py/utils.pxd
@@ -14,9 +14,6 @@ include "defs.pxd"
from numpy cimport ndarray
-# === Custom API ==============================================================
-
-# Memory handling
cdef void* emalloc(size_t size) except? NULL
cdef void efree(void* ptr)
@@ -27,7 +24,6 @@ cdef int convert_tuple(object tuple, hsize_t *dims, hsize_t rank) except -1
cdef object convert_dims(hsize_t* dims, hsize_t rank)
cdef int require_tuple(object tpl, int none_allowed, int size, char* name) except -1
-cdef int require_list(object lst, int none_allowed, int size, char* name) except -1
cdef object create_numpy_hsize(int rank, hsize_t* dims)
cdef object create_hsize_array(object arr)
diff --git a/h5py/utils.pyx b/h5py/utils.pyx
index 5d7b5ed..1643e76 100644
--- a/h5py/utils.pyx
+++ b/h5py/utils.pyx
@@ -140,14 +140,14 @@ cdef int convert_tuple(object tpl, hsize_t *dims, hsize_t rank) except -1:
return 0
cdef object convert_dims(hsize_t* dims, hsize_t rank):
- # Convert an hsize_t array to a Python tuple of long ints.
+ # Convert an hsize_t array to a Python tuple of ints.
cdef list dims_list
cdef int i
dims_list = []
for i from 0<=i<rank:
- dims_list.append(dims[i])
+ dims_list.append(int(dims[i]))
return tuple(dims_list)
@@ -216,20 +216,4 @@ cdef int require_tuple(object tpl, int none_allowed, int size, char* name) excep
PyErr_SetString(ValueError, msg)
return -1
-cdef int require_list(object lst, int none_allowed, int size, char* name) except -1:
- # Counterpart of require_tuple, for lists
-
- if (lst is None and none_allowed) or \
- (isinstance(lst, list) and (size < 0 or len(lst) == size)):
- return 1
-
- nmsg = "" if size < 0 else " of size %d" % size
- smsg = "" if not none_allowed else " or None"
-
- msg = "%s must be a list%s%s." % (name, smsg, nmsg)
- PyErr_SetString(ValueError, msg)
- return -1
-
-
-
--
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