[hdf-forum] H5Fget_vfd_handle signature

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[hdf-forum] H5Fget_vfd_handle signature

Francesc Alted
Hi,

I'm trying to get the OS file handler out of a HDF5 'hid_t file_id'
identifier.  The signature for the function that should do this in HDF5
is:

H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)

[BTW, the reference manual is wrong about this signature]

Now, I had to convert the 'file_handle' variable into a typed (i.e.
not 'void') variable so as to be able to deal with it in Python and
pass it to its fcntl module (in order to do operations on the handler).  
I've chosen a regular 'int' for keeping the handle information and,
apparently, it works well on Linux and H5P_DEFAULT driver.

My question is: do you think that converting the 'void **file_handle'
into an integer is a good practice in general, or there are cases where
this conversion would not work?

Thanks,

--
Francesc Alted
Freelance developer
Tel +34-964-282-249

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.




Reply | Threaded
Open this post in threaded view
|

[hdf-forum] H5Fget_vfd_handle signature

Ger van Diepen
Hi Francesc,

Converting a pointer to int is very bad practice. On 64-bit machines an int is often 32 bits, so it may well fail as it is too short for the 64-bit pointer.
ptrdiff_t is defined as the integer type with the correct precision.

Cheers,
Ger

>>> Francesc Alted <faltet at pytables.com> 09/08/08 10:11 AM >>>
Hi,

I'm trying to get the OS file handler out of a HDF5 'hid_t file_id'
identifier.  The signature for the function that should do this in HDF5
is:

H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)

[BTW, the reference manual is wrong about this signature]

Now, I had to convert the 'file_handle' variable into a typed (i.e.
not 'void') variable so as to be able to deal with it in Python and
pass it to its fcntl module (in order to do operations on the handler).  
I've chosen a regular 'int' for keeping the handle information and,
apparently, it works well on Linux and H5P_DEFAULT driver.

My question is: do you think that converting the 'void **file_handle'
into an integer is a good practice in general, or there are cases where
this conversion would not work?

Thanks,

--
Francesc Alted
Freelance developer
Tel +34-964-282-249

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.




----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.




Reply | Threaded
Open this post in threaded view
|

[hdf-forum] H5Fget_vfd_handle signature

Dimitris Servis
In reply to this post by Francesc Alted
Hi Francesc,

I did not really ever look into this problem. However from experience, I can
give you a first hint for problems: 64bit. You should take care that you
convert to and from integer data types that provide enough storage for an
address.

HTH

-- dimitris

2008/9/8 Francesc Alted <faltet at pytables.com>

> Hi,
>
> I'm trying to get the OS file handler out of a HDF5 'hid_t file_id'
> identifier.  The signature for the function that should do this in HDF5
> is:
>
> H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)
>
> [BTW, the reference manual is wrong about this signature]
>
> Now, I had to convert the 'file_handle' variable into a typed (i.e.
> not 'void') variable so as to be able to deal with it in Python and
> pass it to its fcntl module (in order to do operations on the handler).
> I've chosen a regular 'int' for keeping the handle information and,
> apparently, it works well on Linux and H5P_DEFAULT driver.
>
> My question is: do you think that converting the 'void **file_handle'
> into an integer is a good practice in general, or there are cases where
> this conversion would not work?
>
> Thanks,
>
> --
> Francesc Alted
> Freelance developer
> Tel +34-964-282-249
>
> ----------------------------------------------------------------------
> This mailing list is for HDF software users discussion.
> To subscribe to this list, send a message to
> hdf-forum-subscribe at hdfgroup.org.
> To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20080908/cb3b2a8a/attachment.html>

Reply | Threaded
Open this post in threaded view
|

[hdf-forum] H5Fget_vfd_handle signature

Francesc Alted
In reply to this post by Ger van Diepen
Hi Ger,

A Monday 08 September 2008, Ger van Diepen escrigu?:
> Hi Francesc,
>
> Converting a pointer to int is very bad practice. On 64-bit machines
> an int is often 32 bits, so it may well fail as it is too short for
> the 64-bit pointer. ptrdiff_t is defined as the integer type with the
> correct precision.

That's a good point.  However, I want to pass it to low-level OS
functions (fcntl, flock, lockf, dup2 style), where they are requiring
the descriptor to be an 'int', so I suppose that the file handler will
never require more that 32-bit -- at least in Linux, but I'm not sure
about other OS, specially Windows; this is why I was asking.

Thanks,

Francesc

> >>> Francesc Alted <faltet at pytables.com> 09/08/08 10:11 AM >>>
>
> Hi,
>
> I'm trying to get the OS file handler out of a HDF5 'hid_t file_id'
> identifier.  The signature for the function that should do this in
> HDF5 is:
>
> H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)
>
> [BTW, the reference manual is wrong about this signature]
>
> Now, I had to convert the 'file_handle' variable into a typed (i.e.
> not 'void') variable so as to be able to deal with it in Python and
> pass it to its fcntl module (in order to do operations on the
> handler). I've chosen a regular 'int' for keeping the handle
> information and, apparently, it works well on Linux and H5P_DEFAULT
> driver.
>
> My question is: do you think that converting the 'void **file_handle'
> into an integer is a good practice in general, or there are cases
> where this conversion would not work?
>
> Thanks,



--
Francesc Alted
Freelance developer
Tel +34-964-282-249

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.




Reply | Threaded
Open this post in threaded view
|

[hdf-forum] H5Fget_vfd_handle signature

Ger van Diepen
Hi Francesc,

I don't know about Windows.

I didn't look at H5Fget_vfd_handle, but from the signature I expected
it to give you a FILE*. Now I see it gives you a pointer to the file
handle, so it depends on the underlying file driver what you'll get.

Ger
 
>>> Francesc Alted <faltet at pytables.com> 09/08/08 2:27 PM >>>
Hi Ger,

A Monday 08 September 2008, Ger van Diepen escrigu?:
> Hi Francesc,
>
> Converting a pointer to int is very bad practice. On 64-bit machines
> an int is often 32 bits, so it may well fail as it is too short for
> the 64-bit pointer. ptrdiff_t is defined as the integer type with
the
> correct precision.

That's a good point.  However, I want to pass it to low-level OS
functions (fcntl, flock, lockf, dup2 style), where they are requiring
the descriptor to be an 'int', so I suppose that the file handler will

never require more that 32-bit -- at least in Linux, but I'm not sure
about other OS, specially Windows; this is why I was asking.

Thanks,

Francesc

> >>> Francesc Alted <faltet at pytables.com> 09/08/08 10:11 AM >>>
>
> Hi,
>
> I'm trying to get the OS file handler out of a HDF5 'hid_t file_id'
> identifier.  The signature for the function that should do this in
> HDF5 is:
>
> H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)
>
> [BTW, the reference manual is wrong about this signature]
>
> Now, I had to convert the 'file_handle' variable into a typed (i.e.
> not 'void') variable so as to be able to deal with it in Python and
> pass it to its fcntl module (in order to do operations on the
> handler). I've chosen a regular 'int' for keeping the handle
> information and, apparently, it works well on Linux and H5P_DEFAULT
> driver.
>
> My question is: do you think that converting the 'void
**file_handle'
> into an integer is a good practice in general, or there are cases
> where this conversion would not work?
>
> Thanks,



--
Francesc Alted
Freelance developer
Tel +34-964-282-249

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to
hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.



----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.




Reply | Threaded
Open this post in threaded view
|

[hdf-forum] H5Fget_vfd_handle signature

Dimitris Servis
Hi Francesc,

copy-paste from VS2005 watch window while debugging x64 on WXPx64:

        sizeof(FILE*)    8    unsigned int
the same with 32bit

        sizeof(FILE*)    4    unsigned int

HTH

-- dimitris

2008/9/8 Ger van Diepen <diepen at astron.nl>

> Hi Francesc,
>
> I don't know about Windows.
>
> I didn't look at H5Fget_vfd_handle, but from the signature I expected
> it to give you a FILE*. Now I see it gives you a pointer to the file
> handle, so it depends on the underlying file driver what you'll get.
>
> Ger
>
> >>> Francesc Alted <faltet at pytables.com> 09/08/08 2:27 PM >>>
> Hi Ger,
>
> A Monday 08 September 2008, Ger van Diepen escrigu?:
> > Hi Francesc,
> >
> > Converting a pointer to int is very bad practice. On 64-bit machines
> > an int is often 32 bits, so it may well fail as it is too short for
> > the 64-bit pointer. ptrdiff_t is defined as the integer type with
> the
> > correct precision.
>
> That's a good point.  However, I want to pass it to low-level OS
> functions (fcntl, flock, lockf, dup2 style), where they are requiring
> the descriptor to be an 'int', so I suppose that the file handler will
>
> never require more that 32-bit -- at least in Linux, but I'm not sure
> about other OS, specially Windows; this is why I was asking.
>
> Thanks,
>
> Francesc
>
> > >>> Francesc Alted <faltet at pytables.com> 09/08/08 10:11 AM >>>
> >
> > Hi,
> >
> > I'm trying to get the OS file handler out of a HDF5 'hid_t file_id'
> > identifier.  The signature for the function that should do this in
> > HDF5 is:
> >
> > H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)
> >
> > [BTW, the reference manual is wrong about this signature]
> >
> > Now, I had to convert the 'file_handle' variable into a typed (i.e.
> > not 'void') variable so as to be able to deal with it in Python and
> > pass it to its fcntl module (in order to do operations on the
> > handler). I've chosen a regular 'int' for keeping the handle
> > information and, apparently, it works well on Linux and H5P_DEFAULT
> > driver.
> >
> > My question is: do you think that converting the 'void
> **file_handle'
> > into an integer is a good practice in general, or there are cases
> > where this conversion would not work?
> >
> > Thanks,
>
>
>
> --
> Francesc Alted
> Freelance developer
> Tel +34-964-282-249
>
> ----------------------------------------------------------------------
> This mailing list is for HDF software users discussion.
> To subscribe to this list, send a message to
> hdf-forum-subscribe at hdfgroup.org.
> To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.
>
>
>
> ----------------------------------------------------------------------
> This mailing list is for HDF software users discussion.
> To subscribe to this list, send a message to
> hdf-forum-subscribe at hdfgroup.org.
> To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20080908/66304e1a/attachment.html>

Reply | Threaded
Open this post in threaded view
|

[hdf-forum] H5Fget_vfd_handle signature

Francesc Alted
Hi Dimitris & Ger,

Indeed it helps.  Linux in fact also has the same behaviour than Windows
in this regard.  That forced me to scroogle a bit the net and find that
the C99 standard says about ptrdiff_t:

"""
When two pointers are subtracted, both shall point to
elements of the same array object, or one past the
last element of the array object; the result is the
difference of the subscripts of the two array elements.
The size of the result is implementation-defined, and
its type (a signed integer type) is ptrdiff_t
defined in the <stddef.h> header.
"""

While it says about uintptr_t:

"""
uintptr_t is an unsigned integer type with the property that
any valid pointer to void can be converted to this type, then
converted back to pointer to void, and the result will compare
equal to the original pointer.
"""

So, as I'm not subtracting, I think uintptr_t is the correct value that
I should use (in fact, I've tested in and it seems to work just fine).

Thanks!

A Monday 08 September 2008, Dimitris Servis escrigu?:

> Hi Francesc,
>
> copy-paste from VS2005 watch window while debugging x64 on WXPx64:
>
>         sizeof(FILE*)    8    unsigned int
> the same with 32bit
>
>         sizeof(FILE*)    4    unsigned int
>
> HTH
>
> -- dimitris
>
> 2008/9/8 Ger van Diepen <diepen at astron.nl>
>
> > Hi Francesc,
> >
> > I don't know about Windows.
> >
> > I didn't look at H5Fget_vfd_handle, but from the signature I
> > expected it to give you a FILE*. Now I see it gives you a pointer
> > to the file handle, so it depends on the underlying file driver
> > what you'll get.
> >
> > Ger
> >
> > >>> Francesc Alted <faltet at pytables.com> 09/08/08 2:27 PM >>>
> >
> > Hi Ger,
> >
> > A Monday 08 September 2008, Ger van Diepen escrigu?:
> > > Hi Francesc,
> > >
> > > Converting a pointer to int is very bad practice. On 64-bit
> > > machines an int is often 32 bits, so it may well fail as it is
> > > too short for the 64-bit pointer. ptrdiff_t is defined as the
> > > integer type with
> >
> > the
> >
> > > correct precision.
> >
> > That's a good point.  However, I want to pass it to low-level OS
> > functions (fcntl, flock, lockf, dup2 style), where they are
> > requiring the descriptor to be an 'int', so I suppose that the file
> > handler will
> >
> > never require more that 32-bit -- at least in Linux, but I'm not
> > sure about other OS, specially Windows; this is why I was asking.
> >
> > Thanks,
> >
> > Francesc
> >
> > > >>> Francesc Alted <faltet at pytables.com> 09/08/08 10:11 AM >>>
> > >
> > > Hi,
> > >
> > > I'm trying to get the OS file handler out of a HDF5 'hid_t
> > > file_id' identifier.  The signature for the function that should
> > > do this in HDF5 is:
> > >
> > > H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)
> > >
> > > [BTW, the reference manual is wrong about this signature]
> > >
> > > Now, I had to convert the 'file_handle' variable into a typed
> > > (i.e. not 'void') variable so as to be able to deal with it in
> > > Python and pass it to its fcntl module (in order to do operations
> > > on the handler). I've chosen a regular 'int' for keeping the
> > > handle information and, apparently, it works well on Linux and
> > > H5P_DEFAULT driver.
> > >
> > > My question is: do you think that converting the 'void
> >
> > **file_handle'
> >
> > > into an integer is a good practice in general, or there are cases
> > > where this conversion would not work?
> > >
> > > Thanks,
> >
> > --
> > Francesc Alted
> > Freelance developer
> > Tel +34-964-282-249
> >
> > -------------------------------------------------------------------
> >--- This mailing list is for HDF software users discussion.
> > To subscribe to this list, send a message to
> > hdf-forum-subscribe at hdfgroup.org.
> > To unsubscribe, send a message to
> > hdf-forum-unsubscribe at hdfgroup.org.
> >
> >
> >
> > -------------------------------------------------------------------
> >--- This mailing list is for HDF software users discussion.
> > To subscribe to this list, send a message to
> > hdf-forum-subscribe at hdfgroup.org.
> > To unsubscribe, send a message to
> > hdf-forum-unsubscribe at hdfgroup.org.



--
Francesc Alted
Freelance developer
Tel +34-964-282-249

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.




Reply | Threaded
Open this post in threaded view
|

[hdf-forum] H5Fget_vfd_handle signature

Francesc Alted
In reply to this post by Francesc Alted
Hi Ruth,

A Monday 08 September 2008, escrigu?reu:
> Hi Francesc,
>
> It would help us greatly if you report documentation errors to
> help at hdfgroup.org .  It still takes awhile to get them fixed, but at
> least then they get into bugzilla.

Ah, that's good to know.  I thought that reporting here was enough.

> Maybe you've already reported this one.   I'm cc:ing in the help desk
> just in case you haven't.

No, I had not.

Thanks!

Francesc

>
> -Ruth
>
> On Sep 8, 2008, at 3:11 AM, Francesc Alted wrote:
> > Hi,
> >
> > I'm trying to get the OS file handler out of a HDF5 'hid_t file_id'
> > identifier.  The signature for the function that should do this in
> > HDF5
> > is:
> >
> > H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)
> >
> > [BTW, the reference manual is wrong about this signature]
> >
> > Now, I had to convert the 'file_handle' variable into a typed (i.e.
> > not 'void') variable so as to be able to deal with it in Python and
> > pass it to its fcntl module (in order to do operations on the
> > handler).
> > I've chosen a regular 'int' for keeping the handle information and,
> > apparently, it works well on Linux and H5P_DEFAULT driver.
> >
> > My question is: do you think that converting the 'void
> > **file_handle' into an integer is a good practice in general, or
> > there are cases where
> > this conversion would not work?
> >
> > Thanks,
> >
> > --
> > Francesc Alted
> > Freelance developer
> > Tel +34-964-282-249
> >
> > -------------------------------------------------------------------
> >--- This mailing list is for HDF software users discussion.
> > To subscribe to this list, send a message to
> > hdf-forum-subscribe at hdfgroup.org .
> > To unsubscribe, send a message to
> > hdf-forum-unsubscribe at hdfgroup.org.
>
> ------------------------------------------------------------
> Ruth Aydt
> The HDF Group
> 1901 South First Street,  Suite C-2
> Champaign, IL 61820
>
> aydt at hdfgroup.org
> (217)265-7837 (office)    (217)333-9049 (fax)
> ------------------------------------------------------------



--
Francesc Alted
Freelance developer
Tel +34-964-282-249

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.