[h5py] 108/455: Fixes: indexes > 2**32, field index regression, more duct tape on threading tests
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:23 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 447f00e3d35a0bd62a763c20c7d7058e8b6d94e0
Author: andrewcollette <andrew.collette at gmail.com>
Date: Tue Aug 26 00:31:45 2008 +0000
Fixes: indexes > 2**32, field index regression, more duct tape on threading tests
---
h5py/highlevel.py | 2 +-
h5py/tests/test_h5s.py | 4 ++--
h5py/tests/test_threads.py | 40 +++++++++++++++++++++++++++++-----------
h5py/utils.pxd | 17 +++++++++++++++--
h5py/utils.pyx | 16 ++++++++++++++--
h5py/utils_hl.py | 7 +++++++
h5py/utils_low.c | 30 ------------------------------
h5py/utils_low.h | 3 ---
8 files changed, 68 insertions(+), 51 deletions(-)
diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index de53763..9e5c813 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -662,7 +662,7 @@ class Dataset(HLObject):
if not name in basetype.names:
raise ValueError("Field %s does not appear in this type." % name)
- new_dtype = numpy.dtype([(name, basetype.fields[name]) for name in names])
+ new_dtype = numpy.dtype([(name, basetype.fields[name][0]) for name in names])
# Create the holder array
arr = numpy.ndarray(mspace.shape, new_dtype)
diff --git a/h5py/tests/test_h5s.py b/h5py/tests/test_h5s.py
index cebca56..30b48b2 100644
--- a/h5py/tests/test_h5s.py
+++ b/h5py/tests/test_h5s.py
@@ -16,8 +16,8 @@ import numpy
from h5py import *
from h5py.h5 import H5Error
-spaces = [(10,10), (1,1), (1,), ()]
-max_spaces = [(10,10), (3,4), (h5s.UNLIMITED,), ()]
+spaces = [(10,10), (1,1), (1,), (), (2**40,)]
+max_spaces = [(10,10), (3,4), (h5s.UNLIMITED,), (), (2**41,)]
class TestH5S(unittest.TestCase):
diff --git a/h5py/tests/test_threads.py b/h5py/tests/test_threads.py
index b8f6587..071f9cd 100644
--- a/h5py/tests/test_threads.py
+++ b/h5py/tests/test_threads.py
@@ -216,33 +216,51 @@ class TestThreads(unittest.TestCase):
class SleeperThread(Thread):
- def __init__(self, sleeptime):
+ def __init__(self, sleeptime, next_thread):
Thread.__init__(self)
self.sleeptime = sleeptime
self.time = 0
+ self.next_thread = next_thread
@h5sync
def run(self):
- time.sleep(self.sleeptime)
+ if self.next_thread is not None:
+ self.next_thread.start() # We should already hold the lock
+ time.sleep(self.sleeptime/2.0)
self.time = time.time()
+ time.sleep(self.sleeptime/2.0)
- thread_a = SleeperThread(2)
- thread_b = SleeperThread(1)
+ def run_dec(real_lock):
+ oldlock = h5py.config.lock
+ try:
+ if not real_lock:
+ h5py.config.lock = dummy_threading.RLock()
- thread_a.start()
- time.sleep(0.2)
- thread_b.start()
+ thread_b = SleeperThread(1, None) # last thread
+ thread_a = SleeperThread(2, thread_b) # first thread
- thread_a.join()
- thread_b.join()
+ thread_a.start()
+
+ thread_a.join()
+ thread_b.join()
+
+ if real_lock:
+ self.assert_(thread_a.time < thread_b.time, "%f !< %f" % (thread_a.time, thread_b.time))
+ else:
+ self.assert_(thread_a.time > thread_b.time, "%f !> %f" % (thread_a.time, thread_b.time))
+ finally:
+ h5py.config.lock = oldlock
+
+ run_dec(True)
+ run_dec(False)
- self.assert_(thread_a.time < thread_b.time, "%f :: %f" % (thread_a.time, thread_b.time))
-
@h5sync
def thisismyname(foo):
+ """ I'm a docstring! """
pass
self.assertEqual(thisismyname.__name__, "thisismyname")
+ self.assertEqual(thisismyname.__doc__, " I'm a docstring! ")
diff --git a/h5py/utils.pxd b/h5py/utils.pxd
index 34d6b65..e74ba97 100644
--- a/h5py/utils.pxd
+++ b/h5py/utils.pxd
@@ -20,8 +20,6 @@ cdef extern from "utils_low.h":
hid_t create_ieee_complex64(char byteorder, char* real_name, char* img_name) except -1
hid_t create_ieee_complex128(char byteorder, char* real_name, char* img_name) except -1
- # Tuple conversion
- object convert_dims(hsize_t* dims, hsize_t rank) # automatic except
# Numpy array validation
int check_numpy_read(ndarray arr, hid_t space_id) except 0
@@ -34,9 +32,24 @@ cdef extern from "utils_low.h":
# === Custom API ==============================================================
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 pybool(long long val)
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 b59f573..f6a490a 100644
--- a/h5py/utils.pyx
+++ b/h5py/utils.pyx
@@ -29,12 +29,24 @@ cdef int convert_tuple(object tpl, hsize_t *dims, hsize_t rank) except -1:
try:
for i from 0<=i<rank:
- dims[i] = long(tpl[i])
+ dims[i] = tpl[i]
except TypeError:
- raise TypeError("Can't convert element %d (%s) to a long" % (i, tpl[i]))
+ raise TypeError("Can't convert element %d (%s) to hsize_t" % (i, tpl[i]))
return 0
+cdef object convert_dims(hsize_t* dims, hsize_t rank):
+ # Convert an hsize_t array to a Python tuple of long ints.
+
+ cdef list dims_list
+ cdef int i
+ dims_list = []
+
+ for i from 0<=i<rank:
+ dims_list.append(dims[i])
+
+ return tuple(dims_list)
+
cdef object create_numpy_hsize(int rank, hsize_t* dims):
# Create an empty Numpy array which can hold HDF5 hsize_t entries
diff --git a/h5py/utils_hl.py b/h5py/utils_hl.py
index 974f174..6fed636 100644
--- a/h5py/utils_hl.py
+++ b/h5py/utils_hl.py
@@ -72,6 +72,9 @@ class FlatIndexer(object):
def __init__(self, shape, args):
""" Shape must be a tuple; args must be iterable.
"""
+ if shape == ():
+ raise TypeError("Can't slice into a scalar array.")
+
try:
args = tuple(iter(args))
except TypeError:
@@ -117,8 +120,12 @@ def slice_select(space, args):
"""
if len(args) == 0 or (len(args) == 1 and args[0] is Ellipsis):
+ # The only safe way to access a scalar dataspace
space.select_all()
return space.copy(), False
+ else:
+ if space.get_simple_extent_type() == h5s.SCALAR:
+ raise TypeError('Can\'t slice a scalar dataset (only fields and "..." allowed)')
if len(args) == 1:
argval = args[0]
diff --git a/h5py/utils_low.c b/h5py/utils_low.c
index 1811b39..500ff19 100644
--- a/h5py/utils_low.c
+++ b/h5py/utils_low.c
@@ -53,36 +53,6 @@ void efree(void* ptr){
free(ptr);
}
-/* Convert an hsize_t array to a Python tuple of long ints.
- Returns NULL on failure, and raises an exception (either propagates
- an exception from the conversion, or raises RuntimeError).
-*/
-PyObject* convert_dims(hsize_t* dims, hsize_t rank) {
-
- PyObject* tpl;
- PyObject* plong;
- int i;
- tpl = NULL;
- plong = NULL;
-
- tpl = PyTuple_New(rank);
- if(tpl == NULL) goto err;
-
- for(i=0; i<rank; i++){
- plong = PyLong_FromLong((long) dims[i]);
- if(plong == NULL) goto err;
- PyTuple_SET_ITEM(tpl, i, plong); /* steals reference */
- }
-
- return tpl;
-
- err:
- Py_XDECREF(tpl);
- if(!PyErr_Occurred()){
- PyErr_SetString(PyExc_RuntimeError, "Failed to convert hsize_t array to tuple.");
- }
- return NULL;
-}
/* The functions
diff --git a/h5py/utils_low.h b/h5py/utils_low.h
index c3b68a2..e8e62e3 100644
--- a/h5py/utils_low.h
+++ b/h5py/utils_low.h
@@ -23,12 +23,9 @@
#include "hdf5.h"
#include "numpy/arrayobject.h"
-
hid_t create_ieee_complex64(const char byteorder, const char* real_name, const char* img_name);
hid_t create_ieee_complex128(const char byteorder, const char* real_name, const char* img_name);
-PyObject* convert_dims(hsize_t* dims, hsize_t rank);
-
int check_numpy_read(PyArrayObject* arr, hid_t space_id);
int check_numpy_write(PyArrayObject* arr, hid_t space_id);
--
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