[h5py] 297/455: Fix inefficient __contains__ implementation
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:43 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 07af874856ea218db9559999eb0a3b6230f36600
Author: andrewcollette <andrew.collette at gmail.com>
Date: Wed Jul 15 19:19:33 2009 +0000
Fix inefficient __contains__ implementation
---
h5py/h5e.pxd | 7 +++++++
h5py/h5e.pyx | 15 +++++++++++++++
h5py/h5g.pyx | 18 ++++++++++--------
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/h5py/h5e.pxd b/h5py/h5e.pxd
index d5adea0..fa3d1df 100644
--- a/h5py/h5e.pxd
+++ b/h5py/h5e.pxd
@@ -222,3 +222,10 @@ cdef extern from "hdf5.h":
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)
+ctypedef struct err_cookie:
+ H5E_auto_t func
+ void* data
+
+cdef err_cookie disable_errors() except *
+cdef void enable_errors(err_cookie) except *
+
diff --git a/h5py/h5e.pyx b/h5py/h5e.pyx
index e029bc1..4f4d594 100644
--- a/h5py/h5e.pyx
+++ b/h5py/h5e.pyx
@@ -373,4 +373,19 @@ cpdef int register_thread() except -1:
raise RuntimeError("Failed to register HDF5 exception callback")
return 0
+cdef err_cookie disable_errors() except *:
+ # Temporarily disable errors for the current thread
+ cdef err_cookie cookie
+ H5Eget_auto(&cookie.func, &cookie.data)
+ H5Eset_auto(NULL, NULL)
+ return cookie
+
+cdef void enable_errors(err_cookie cookie) except *:
+ # Re-enable errors for the current thread
+ cdef herr_t retval
+ retval = H5Eset_auto(cookie.func, cookie.data)
+ if(retval < 0):
+ raise RuntimeError("Cant' re-enable exception support")
+
+
diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index b7a9111..abeaa91 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -20,6 +20,7 @@ include "config.pxi"
from h5 cimport init_hdf5, SmartStruct
from utils cimport emalloc, efree
from h5p cimport PropID, pdefault
+from h5e cimport err_cookie, disable_errors, enable_errors
IF H5PY_18API:
from h5l cimport LinkProxy
@@ -433,15 +434,16 @@ cdef class GroupID(ObjectID):
Determine if a group member of the given name is present
"""
-
+ cdef herr_t retval
+ cdef err_cookie cookie
+
+ cookie = disable_errors()
try:
- IF H5PY_18API:
- return <bint>H5Lexists(self.id, name, H5P_DEFAULT)
- ELSE:
- H5Gget_objinfo(self.id, name, 1, NULL)
- return True
- except H5Error:
- return False
+ retval = H5Gget_objinfo(self.id, name, 1, NULL)
+ finally:
+ enable_errors(cookie)
+
+ return bool(retval >= 0)
@nosync
def __iter__(self):
--
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