[h5py] 247/455: Handle non-string objects

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:38 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 f30ddb5fb409ce53d2acd5eb498bfa111a88bae3
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue May 26 22:49:36 2009 +0000

    Handle non-string objects
---
 h5py/typeconv.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/h5py/typeconv.c b/h5py/typeconv.c
index 787ab70..b2c544f 100644
--- a/h5py/typeconv.c
+++ b/h5py/typeconv.c
@@ -159,6 +159,7 @@ herr_t str_to_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
     PyGILState_STATE gil;
 
     PyObject**   obj;
+    PyObject*    inter_string = NULL;
     char**       str;
     char*        str_tmp;
     Py_ssize_t   len;
@@ -203,11 +204,20 @@ herr_t str_to_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
             if(*obj == NULL || *obj == Py_None){
                 len = 1;
                 str_tmp = "";
-            } else if(PyString_CheckExact(*obj)) {
-                len = PyString_Size(*obj)+1;
-                str_tmp = PyString_AsString(*obj);
-            } else {
-                goto conv_failed;
+
+            } else { /* If it's not a string, take the result of str(obj) */
+
+                if(PyString_CheckExact(*obj)) {
+                    len = PyString_Size(*obj)+1;
+                    str_tmp = PyString_AsString(*obj);
+                } else {
+                    inter_string = PyObject_Str(*obj);
+                    if(inter_string == NULL) goto conv_failed;
+                    len = PyString_Size(inter_string)+1;
+                    str_tmp = PyString_AsString(inter_string);
+                    Py_DECREF(inter_string);
+                }
+
             }
 
             *str = (char*)malloc(len);  /* len already includes null term */

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