Hello,
I'm trying to write a conversion callback that can translate between
HDF5 variable-length strings and another format (in this case, Python
strings). I have a good deal of experience with the HDF5 C API but
have never used vlens before, so I'm having some difficulty. I've
read the document at:
http://www.hdfgroup.org/HDF5/doc1.6/Datatypes.html#Datatypes-DataConversion
and have based my conversion code on this example. However, I've not
been able to get it to work. So far I've tried writing a scalar
attibute; the created attribute has the correct type according to
h5dump (H5T_STRING, strsize H5T_VARIABLE), but the string itself is
length zero. I have a feeling I'm not using the right representation
for vlen strings. Are HDF5 variable-length strings still represented
by the hvl_t struct? Or are they just char*'s? The heart of my
conversion process is this:
(*buf is provided as the argument callback)
for reading:
obj_buf = (PyObject**)buf;
vlen_buf = (hvl_t*)buf;
for(i=0;i<nelements-1;i++){
obj_buf[i] = PyString_FromStringAndSize((char*)vlen_buf[i].p,
vlen_buf[i].len);
}
and for writing:
for(i=nelements-1;i>=0; i--){
vlen_buf[i].p = malloc(<string length>)
vlen_buf[i].len = <string length>
memcpy(vlen_buf[i].p, (Python object's char*), <string length>)
}
The full code is here:
http://code.google.com/p/h5py/source/browse/branches/vlen/h5py/newtypes.c?spec=svn310&r=310
I'd appreciate any thoughts or advice people might have on this.
Thanks,
Andrew Collette
···
----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.