[h5py] 355/455: Implement region reference conversion, fix typemapping glitch

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:50 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 c842ea7403281463ee53f76a90b9d9600742f7f8
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Thu Jan 7 08:31:47 2010 +0000

    Implement region reference conversion, fix typemapping glitch
---
 h5py/_conv.pxd |  2 +-
 h5py/_conv.pyx | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 h5py/defs.pxd  |  3 ---
 h5py/h5r.pxd   |  5 +++++
 h5py/h5t.pyx   |  2 +-
 5 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/h5py/_conv.pxd b/h5py/_conv.pxd
index 9dca753..6127919 100644
--- a/h5py/_conv.pxd
+++ b/h5py/_conv.pxd
@@ -12,7 +12,7 @@
 
 include "defs.pxd"
 
-from h5r cimport Reference
+from h5r cimport Reference, RegionReference, hobj_ref_t, hdset_reg_ref_t
 
 # Minimal interface for Python objects immune to Cython refcounting
 cdef extern from "Python.h":
diff --git a/h5py/_conv.pyx b/h5py/_conv.pyx
index e669fcd..148acf8 100644
--- a/h5py/_conv.pyx
+++ b/h5py/_conv.pyx
@@ -288,6 +288,47 @@ cdef int conv_pyref2objref(void* ipt, void* opt, void* bkg, void* priv) except -
 
     return 0
 
+cdef int conv_regref2pyref(void* ipt, void* opt, void* bkg, void* priv) except -1:
+
+    cdef PyObject** buf_obj = <PyObject**>opt
+    cdef PyObject** bkg_obj = <PyObject**>bkg
+    cdef hdset_reg_ref_t* buf_ref = <hdset_reg_ref_t*>ipt
+
+    cdef RegionReference ref = RegionReference()
+    cdef PyObject* ref_ptr = NULL
+
+    memcpy(ref.ref.reg_ref, buf_ref, sizeof(hdset_reg_ref_t))
+
+    ref.typecode = H5R_DATASET_REGION
+
+    ref_ptr = <PyObject*>ref
+    Py_INCREF(ref_ptr)  # because Cython discards its reference when the
+                        # function exits
+
+    Py_XDECREF(bkg_obj[0])
+    buf_obj[0] = ref_ptr
+
+    return 0
+
+cdef int conv_pyref2regref(void* ipt, void* opt, void* bkg, void* priv) except -1:
+
+    cdef PyObject** buf_obj = <PyObject**>ipt
+    cdef hdset_reg_ref_t* buf_ref = <hdset_reg_ref_t*>opt
+
+    cdef object obj
+    cdef RegionReference ref
+
+    if buf_obj[0] != NULL and buf_obj[0] != Py_None:
+        obj = <object>(buf_obj[0])
+        if not isinstance(obj, RegionReference):
+            raise TypeError("Can't convert incompatible object to HDF5 region reference")
+        ref = <RegionReference>(buf_obj[0])
+        memcpy(buf_ref, ref.ref.reg_ref, sizeof(hdset_reg_ref_t))
+    else:
+        memset(buf_ref, c'\0', sizeof(hdset_reg_ref_t))
+
+    return 0
+
 # =============================================================================
 # Conversion functions
 
@@ -328,6 +369,18 @@ cdef herr_t pyref2objref(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
     return generic_converter(src_id, dst_id, cdata, nl, buf_stride, bkg_stride,
              buf_i, bkg_i, dxpl, conv_pyref2objref, init_generic, H5T_BKG_NO)
 
+cdef herr_t regref2pyref(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
+                    size_t nl, size_t buf_stride, size_t bkg_stride, void *buf_i,
+                    void *bkg_i, hid_t dxpl) except -1:
+    return generic_converter(src_id, dst_id, cdata, nl, buf_stride, bkg_stride,
+             buf_i, bkg_i, dxpl, conv_regref2pyref, init_generic, H5T_BKG_YES)
+
+cdef herr_t pyref2regref(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
+                    size_t nl, size_t buf_stride, size_t bkg_stride, void *buf_i,
+                    void *bkg_i, hid_t dxpl) except -1:
+    return generic_converter(src_id, dst_id, cdata, nl, buf_stride, bkg_stride,
+             buf_i, bkg_i, dxpl, conv_pyref2regref, init_generic, H5T_BKG_NO)
+
 # =============================================================================
 # Enum to integer converter
 
@@ -441,10 +494,16 @@ cpdef int register_converters() except -1:
 
     H5Tregister(H5T_PERS_HARD, "vlen2str", vlstring, pyobj, vlen2str)
     H5Tregister(H5T_PERS_HARD, "str2vlen", pyobj, vlstring, str2vlen)
+
     H5Tregister(H5T_PERS_SOFT, "vlen2fixed", vlstring, H5T_C_S1, vlen2fixed)
     H5Tregister(H5T_PERS_SOFT, "fixed2vlen", H5T_C_S1, vlstring, fixed2vlen)
+
     H5Tregister(H5T_PERS_HARD, "objref2pyref", H5T_STD_REF_OBJ, pyobj, objref2pyref)
     H5Tregister(H5T_PERS_HARD, "pyref2objref", pyobj, H5T_STD_REF_OBJ, pyref2objref)
+
+    H5Tregister(H5T_PERS_HARD, "regref2pyref", H5T_STD_REF_DSETREG, pyobj, regref2pyref)
+    H5Tregister(H5T_PERS_HARD, "pyref2regref", pyobj, H5T_STD_REF_DSETREG, pyref2regref)
+
     H5Tregister(H5T_PERS_SOFT, "enum2int", enum, H5T_STD_I32LE, enum2int)
     H5Tregister(H5T_PERS_SOFT, "int2enum", H5T_STD_I32LE, enum, int2enum)
 
@@ -457,10 +516,16 @@ cpdef int unregister_converters() except -1:
 
     H5Tunregister(H5T_PERS_HARD, "vlen2str", -1, -1, vlen2str)
     H5Tunregister(H5T_PERS_HARD, "str2vlen", -1, -1, str2vlen)
+
     H5Tunregister(H5T_PERS_SOFT, "vlen2fixed", -1, -1, vlen2fixed)
     H5Tunregister(H5T_PERS_SOFT, "fixed2vlen", -1, -1, fixed2vlen)
+
     H5Tunregister(H5T_PERS_HARD, "objref2pyref", -1, -1, objref2pyref)
     H5Tunregister(H5T_PERS_HARD, "pyref2objref", -1, -1, pyref2objref)
+
+    H5Tunregister(H5T_PERS_HARD, "regref2pyref", -1, -1, regref2pyref)
+    H5Tunregister(H5T_PERS_HARD, "pyref2regref", -1, -1, pyref2regref)
+
     H5Tunregister(H5T_PERS_SOFT, "enum2int", -1, -1, enum2int)
     H5Tunregister(H5T_PERS_SOFT, "int2enum", -1, -1, int2enum)
 
diff --git a/h5py/defs.pxd b/h5py/defs.pxd
index fd49251..42b8c27 100644
--- a/h5py/defs.pxd
+++ b/h5py/defs.pxd
@@ -806,9 +806,6 @@ cdef extern from "hdf5.h":
     H5R_INTERNAL,
     H5R_MAXTYPE
 
-  ctypedef haddr_t hobj_ref_t
-  ctypedef unsigned char hdset_reg_ref_t[12]
-
   herr_t    H5Rcreate(void *ref, hid_t loc_id, char *name, H5R_type_t ref_type, 
                       hid_t space_id) except *
   hid_t     H5Rdereference(hid_t obj_id, H5R_type_t ref_type, void *ref) except *
diff --git a/h5py/h5r.pxd b/h5py/h5r.pxd
index 40c5ac1..90a978c 100644
--- a/h5py/h5r.pxd
+++ b/h5py/h5r.pxd
@@ -12,6 +12,11 @@
 
 include "defs.pxd"
 
+cdef extern from "hdf5.h":
+
+  ctypedef haddr_t hobj_ref_t
+  ctypedef unsigned char hdset_reg_ref_t[12]
+
 cdef union ref_u:
     hobj_ref_t         obj_ref
     hdset_reg_ref_t    reg_ref
diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index ddef792..9174317 100644
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -1452,7 +1452,7 @@ def special_dtype(**kwds):
         if val not in (Reference, RegionReference):
             raise ValueError("Ref class must be Reference or RegionReference")
 
-        return dtype(('O', [( ({'type': val},'hdf5ref'), 'O' )] ))
+        return dtype(('O', [( ({'type': val},'ref'), 'O' )] ))
 
     raise TypeError('Unknown special type "%s"' % name)
    

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