[cig-commits] r13828 - cs/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Mon Jan 12 14:09:51 PST 2009


Author: luis
Date: 2009-01-12 14:09:51 -0800 (Mon, 12 Jan 2009)
New Revision: 13828

Modified:
   cs/cigma/trunk/src/h5attr.cpp
Log:
Fix definition of listOps in h5attr.cpp

Definition of operator_t function pointers differs across
HDF5 versions, so this might have been the root cause of
the segfault in obj->iterateAttrs()

Modified: cs/cigma/trunk/src/h5attr.cpp
===================================================================
--- cs/cigma/trunk/src/h5attr.cpp	2009-01-12 22:09:50 UTC (rev 13827)
+++ cs/cigma/trunk/src/h5attr.cpp	2009-01-12 22:09:51 UTC (rev 13828)
@@ -260,15 +260,35 @@
     return 0;
 }
 
-void listAttrOp0(H5::H5Object& loc, const string name, void *data)
+void print_attr(const string& name, const string& dtype, const string& value)
 {
-    TRI_LOG_STR("listAttrOp()");
-    string dtype, value;
-    getattr(&loc, name, dtype, value);
-    cout << "\t" << name << " = " << value << endl;
+    cout << "\t" << name << " = ";
+
+    if (dtype != "string")
+    {
+        cout << value;
+    }
+    else
+    {
+        string val(value);
+        boost::algorithm::replace_all(val, "\\", "\\\\");
+        boost::algorithm::replace_all(val, "\r", "\\r");
+        boost::algorithm::replace_all(val, "\n", "\\n");
+        boost::algorithm::replace_all(val, "\t", "\\t");
+        boost::algorithm::replace_all(val, "'", "\\'");
+        cout << "'" << val << "'";
+    }
+    cout << endl;
 }
 
+herr_t listGroupOp(hid_t group, const char *name, void *data)
+{
+    //TRI_LOG_STR("listOp()");
+    cout << "\t" << name << endl;
+}
+
 #ifdef HAVE_HDF5_1_8_2
+
 herr_t listAttrOp(hid_t loc_id, const char *attr_name, const H5A_info_t *ainfo, void *op_data)
 {
     //TRI_LOG_STR("listAttrOp()");
@@ -279,29 +299,32 @@
     {
         H5::H5Object *obj = (H5::H5Object *)op_data;
         getattr(obj, name, dtype, value);
-        cout << "\t" << name << " = ";
-        if (dtype != "string")
-        {
-            cout << value;
-        }
-        else
-        {
-            boost::algorithm::replace_all(value, "\\", "\\\\");
-            boost::algorithm::replace_all(value, "\r", "\\r");
-            boost::algorithm::replace_all(value, "\n", "\\n");
-            boost::algorithm::replace_all(value, "\t", "\\t");
-            boost::algorithm::replace_all(value, "'", "\\'");
-            cout << "'" << value << "'";
-        }
-        cout << endl;
+        print_attr(name, dtype, value);
     }
 }
 
-herr_t listGroupOp(hid_t group, const char *name, void *data)
+#else
+
+herr_t listAttrOp00(hid_t loc_id, const char *attr_name, void *op_data)
 {
-    //TRI_LOG_STR("listOp()");
-    cout << "\t" << name << endl;
+    string name(attr_name);
+    string dtype, value;
+    if (op_data != 0)
+    {
+        H5::H5Object *obj = (H5::H5Object *)op_data;
+        getattr(obj, name, dtype, value);
+        print_attr(name, dtype, value);
+    }
 }
+
+void listAttrOp01(H5::H5Object& loc, const string name, void *data)
+{
+    string dtype, value;
+    getattr(&loc, name, dtype, value);
+    print_attr(name, dtype, value);
+}
+
+
 #endif
 
 
@@ -449,11 +472,9 @@
         }
         else
         {
-            int idx;
+            int num_attrs;
             int status;
 
-            // require hdf5-1.8.2
-            #ifdef HAVE_HDF5_1_8_2
             H5I_type_t objtype = H5::IdComponent::getHDFObjType(obj->getId());
             TRI_LOG(obj->getId());
             TRI_LOG(objtype);
@@ -463,7 +484,7 @@
                 cout << indent << "Groups" << endl;
                 try
                 {
-                    idx = 0;
+                    int idx = 0;
                     while ((status = file->iterateElems(location.c_str(), &idx, listGroupOp, (void *)prefix)) > 0)
                     {
                         //TRI_LOG(status);
@@ -477,6 +498,8 @@
                 // XXX: report dimensions and datatype?
             }
 
+
+            #ifdef HAVE_HDF5_1_8_2
             H5O_info_t oinfo;
             hid_t oid = obj->getId();
             status = H5Oget_info(oid, &oinfo);
@@ -484,32 +507,35 @@
             {
                 throw H5::Exception("main", "H5Oget_info failed");
             }
+            num_attrs = oinfo.num_attrs;
+            #else
+            num_attrs = obj->getNumAttrs();
+            #endif
 
-            int num_attrs = oinfo.num_attrs;
             TRI_LOG(num_attrs);
+
             cout << indent << "Attributes" << endl;
             if (num_attrs > 0)
             {
+                #ifdef HAVE_HDF5_1_8_2
                 hsize_t _idx = 0;
                 while ((status = H5Aiterate2(oid, H5_INDEX_NAME, H5_ITER_INC, &_idx, listAttrOp, obj)) > 0)
                 {
                     //TRI_LOG(status);
                 }
+                #else
+                hid_t oid = obj->getId();
+                unsigned int _idx = 0;
+                while ((status = H5Aiterate(oid, &_idx, listAttrOp00, obj)) > 0)
+                {
+                    //TRI_LOG(status);
+                }
+                #endif
             }
             else
             {
                 cout << "\t" << "No attributes found" << endl;
             }
-            #else
-            if (obj->getNumAttrs() > 0)
-            {
-                obj->iterateAttrs(listAttrOp0);
-            }
-            else
-            {
-                cout << "\t" << "No attributes found" << endl;
-            }
-            #endif
         }
     }
     catch (H5::Exception error)



More information about the CIG-COMMITS mailing list