Check if two identifiers refer to the same object

Is there a way to check if two location identifiers (hid_ts) refer to the same underlying object?

Simon, you might wanna take a look at H5Iobject_verify (https://portal.hdfgroup.org/display/HDF5/H5I_OBJECT_VERIFY). You have to know the kind of object though. You can check a handle’s object type via H5Iget_type (https://portal.hdfgroup.org/display/HDF5/H5I_GET_TYPE). There are, of course, corner cases. For example, several functions accept a file handle or a group handle as arguments for the same parameter. It really depends on your definition of “sameness.” As the saying goes: All handles are equal, but some handles are more equal than others. :sunglasses:

Can I just compare fileno and addr (or fileno and token in 1.12) from H5O_GET_INFO?

Yes, that should be fine. (modulo the potential issues w/ fileno) G.

To follow up on this: when i tried using H5Iobject_verify on a group object, I get the error

 [1] H5Iobject_verify: Object atom/Unable to find ID group information
     cannot call public function on library type

A subset of functions of the H5I API is available for user-defined ID types (as opposed to pre-defined library ID types) only, and H5Iobject_verify is among them. See User-defined ID Types. For pre-defined ID types, there is H5Iis_valid. You can combine that with H5Iget_type, and then try to establish the identity depending on the ID type. OK?

The error message is admittedly somewhat cryptic. :slightly_frowning_face:

G.

Please take a look at the H5Oget_info1 function.

addr field in the H5O_info1_t structure should be the same for both objects. Please make sure that this is a persistent object (i.e., dataset, group, or committed datatype).

In the latest H5Oobj_info function (H5Oobj_info3) output this is information is hidden in a token (?). @nfortne2 or @jhenderson could you please confirm and suggest?

Thank you!

Elena

1 Like

The H5O_info2_t struct used in H5Oget_info3() et al. uses an H5O_token_t token in place of an haddr_t address. A token is 128 bits of arbitrary, VOL-connector-specific data. The robust way of comparing them is via H5Otoken_cmp(). In theory, you could just memcmp(3) them, but you might get in trouble if the connector’s idea of ‘same’ is more complicated than that.