Skip to content

Commit

Permalink
Remove the hash_size param from H5Iregister_type() (#5170)
Browse files Browse the repository at this point in the history
The hash_size parameter of H5Iregister_type() hasn't been used since 1.8.
It's been removed and the API call has been versioned.

This PR also updates the make_vers script to handle v2.0.0.

Fixes #4344
  • Loading branch information
derobins authored Dec 10, 2024
1 parent 945fb3c commit 8f2c03b
Show file tree
Hide file tree
Showing 16 changed files with 856 additions and 268 deletions.
308 changes: 146 additions & 162 deletions bin/make_vers

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion c++/src/C2Cppfunction_map.htm
Original file line number Diff line number Diff line change
Expand Up @@ -9992,7 +9992,7 @@
none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
padding:0in 5.4pt 0in 5.4pt'>
<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'>H5Iregister_type</p>
normal'>H5Iregister_type2</p>
</td>
<td width=474 valign=top style='width:355.2pt;border-top:none;border-left:
none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
Expand Down
8 changes: 4 additions & 4 deletions doxygen/examples/H5I_examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fail_dcpl:;
hid_t obj_id;

// register a new ID type
if ((type = H5Iregister_type(128, 1024, &free_func)) < 0) {
if ((type = H5Iregister_type2(1024, &free_func)) < 0) {
ret_val = EXIT_FAILURE;
goto fail_register;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ fail_register:;
hsize_t count;

// register a new ID type
if ((type = H5Iregister_type(128, 1024, NULL)) < 0) {
if ((type = H5Iregister_type2(1024, NULL)) < 0) {
ret_val = EXIT_FAILURE;
goto fail_register;
}
Expand All @@ -194,7 +194,7 @@ fail_register:;
hid_t obj_id;

// register a new ID type
if ((type = H5Iregister_type(128, 1024, NULL)) < 0) {
if ((type = H5Iregister_type2(1024, NULL)) < 0) {
ret_val = EXIT_FAILURE;
goto fail_register;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ fail_register:;
H5I_type_t type;

// register a new ID type
if ((type = H5Iregister_type(128, 1024, NULL)) < 0) {
if ((type = H5Iregister_type2(1024, NULL)) < 0) {
ret_val = EXIT_FAILURE;
goto fail_register;
}
Expand Down
11 changes: 3 additions & 8 deletions hl/src/H5PT.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ typedef struct {
static hsize_t H5PT_ptable_count = 0;
static H5I_type_t H5PT_ptable_id_type = H5I_UNINIT;

#define H5PT_HASH_TABLE_SIZE 64

/* Packet Table private functions */
static herr_t H5PT_free_id(void *id, void **_ctx);
static herr_t H5PT_close(htbl_t *table);
Expand Down Expand Up @@ -73,8 +71,7 @@ H5PTcreate(hid_t loc_id, const char *dset_name, hid_t dtype_id, hsize_t chunk_si

/* Register the packet table ID type if this is the first table created */
if (H5PT_ptable_id_type < 0)
if ((H5PT_ptable_id_type =
H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, (H5I_free_t)H5PT_free_id)) < 0)
if ((H5PT_ptable_id_type = H5Iregister_type2(0, (H5I_free_t)H5PT_free_id)) < 0)
goto error;

/* Get memory for the table identifier */
Expand Down Expand Up @@ -187,8 +184,7 @@ H5PTcreate_fl(hid_t loc_id, const char *dset_name, hid_t dtype_id, hsize_t chunk

/* Register the packet table ID type if this is the first table created */
if (H5PT_ptable_id_type < 0)
if ((H5PT_ptable_id_type =
H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, (H5I_free_t)H5PT_free_id)) < 0)
if ((H5PT_ptable_id_type = H5Iregister_type2(0, (H5I_free_t)H5PT_free_id)) < 0)
goto error;

/* Get memory for the table identifier */
Expand Down Expand Up @@ -287,8 +283,7 @@ H5PTopen(hid_t loc_id, const char *dset_name)

/* Register the packet table ID type if this is the first table created */
if (H5PT_ptable_id_type < 0)
if ((H5PT_ptable_id_type =
H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, (H5I_free_t)H5PT_free_id)) < 0)
if ((H5PT_ptable_id_type = H5Iregister_type2(0, (H5I_free_t)H5PT_free_id)) < 0)
goto error;

table = (htbl_t *)malloc(sizeof(htbl_t));
Expand Down
2 changes: 1 addition & 1 deletion java/src/hdf/hdf5lib/H5.java
Original file line number Diff line number Diff line change
Expand Up @@ -6306,7 +6306,7 @@ public synchronized static native void H5Iclear_type(int type_id, boolean force)
// hid_t H5Iregister(H5I_type_t type, const void *object);

// typedef herr_t (*H5I_free_t)(void *);
// H5I_type_t H5Iregister_type(size_t hash_size, unsigned reserved, H5I_free_t free_func);
// H5I_type_t H5Iregister_type2(unsigned reserved, H5I_free_t free_func);

// void *H5Iremove_verify(hid_t id, H5I_type_t id_type);

Expand Down
18 changes: 18 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ New Features

Library:
--------
- The H5Iregister_type() signature has changed

The hash_size parameter has not been used since early versions of HDF5
1.8, so it has been removed and the API call has been versioned.

The old signature has been renamed to H5Iregister_type1() and is considered
deprecated:

H5I_type_t H5Iregister_type1(size_t hash_size, unsigned reserved, H5I_free_t free_func);

The new signature is H5Iregister_type2(). New code should use this
version:

H5I_type_t H5Iregister_type2(unsigned reserved, H5I_free_t free_func);

H5Iregister_type() will map to the new signature unless the library is
explicitly configured to use an older version of the API.

- H5F_LIBVER_LATEST is now an enum value

This was previously #defined to the latest H5F_libver_t API version, but
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ IDE_GENERATED_PROPERTIES ("H5HL" "${H5HL_HDRS}" "${H5HL_SOURCES}" )
set (H5I_SOURCES
${HDF5_SRC_DIR}/H5I.c
${HDF5_SRC_DIR}/H5Idbg.c
${HDF5_SRC_DIR}/H5Ideprec.c
${HDF5_SRC_DIR}/H5Iint.c
${HDF5_SRC_DIR}/H5Itest.c
)
Expand Down
66 changes: 9 additions & 57 deletions src/H5I.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,82 +73,34 @@ static int H5I__iterate_pub_cb(void *obj, hid_t id, void *udata);
/*******************/

/*-------------------------------------------------------------------------
* Function: H5Iregister_type
* Function: H5Iregister_type2
*
* Purpose: Public interface to H5I_register_type. Creates a new type
* Purpose: Public interface to H5I_register_type2. Creates a new type
* of ID's to give out. A specific number (RESERVED) of type
* entries may be reserved to enable "constant" values to be handed
* out which are valid IDs in the type, but which do not map to any
* data structures and are not allocated dynamically later. HASH_SIZE is
* the minimum hash table size to use for the type. FREE_FUNC is
* called with an object pointer when the object is removed from
* the type.
* data structures and are not allocated dynamically later.
* FREE_FUNC is called with an object pointer when the object is
* removed from the type.
*
* Return: Success: Type ID of the new type
* Failure: H5I_BADID
*
*-------------------------------------------------------------------------
*/
H5I_type_t
H5Iregister_type(size_t H5_ATTR_UNUSED hash_size, unsigned reserved, H5I_free_t free_func)
H5Iregister_type2(unsigned reserved, H5I_free_t free_func)
{
H5I_class_t *cls = NULL; /* New ID class */
H5I_type_t new_type = H5I_BADID; /* New ID type value */
H5I_type_t ret_value = H5I_BADID; /* Return value */
H5I_type_t ret_value = H5I_BADID;

FUNC_ENTER_API(H5I_BADID)

/* Generate a new H5I_type_t value */

/* Increment the number of types */
if (H5I_next_type_g < H5I_MAX_NUM_TYPES) {
new_type = (H5I_type_t)H5I_next_type_g;
H5I_next_type_g++;
}
else {
bool done; /* Indicate that search was successful */
int i;

/* Look for a free type to give out */
done = false;
for (i = H5I_NTYPES; i < H5I_MAX_NUM_TYPES && done == false; i++) {
if (NULL == H5I_type_info_array_g[i]) {
/* Found a free type ID */
new_type = (H5I_type_t)i;
done = true;
}
}

/* Verify that we found a type to give out */
if (done == false)
HGOTO_ERROR(H5E_ID, H5E_NOSPACE, H5I_BADID, "Maximum number of ID types exceeded");
}

/* Allocate new ID class */
if (NULL == (cls = H5MM_calloc(sizeof(H5I_class_t))))
HGOTO_ERROR(H5E_ID, H5E_CANTALLOC, H5I_BADID, "ID class allocation failed");

/* Initialize class fields */
cls->type = new_type;
cls->flags = H5I_CLASS_IS_APPLICATION;
cls->reserved = reserved;
cls->free_func = free_func;

/* Register the new ID class */
if (H5I_register_type(cls) < 0)
if (H5I_BADID == (ret_value = H5I__register_type_common(reserved, free_func)))
HGOTO_ERROR(H5E_ID, H5E_CANTINIT, H5I_BADID, "can't initialize ID class");

/* Set return value */
ret_value = new_type;

done:
/* Clean up on error */
if (ret_value < 0)
if (cls)
cls = H5MM_xfree(cls);

FUNC_LEAVE_API(ret_value)
} /* end H5Iregister_type() */
} /* end H5Iregister_type2() */

/*-------------------------------------------------------------------------
* Function: H5Itype_exists
Expand Down
97 changes: 97 additions & 0 deletions src/H5Ideprec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the LICENSE file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*-------------------------------------------------------------------------
*
* Created: H5Ideprec.c
*
* Purpose: Deprecated functions from the H5I interface. These
* functions are here for compatibility purposes and may be
* removed in the future. Applications should switch to the
* newer APIs.
*
*-------------------------------------------------------------------------
*/

/****************/
/* Module Setup */
/****************/

#include "H5Imodule.h" /* This source code file is part of the H5I module */

/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Ipkg.h" /* File access */

/****************/
/* Local Macros */
/****************/

/******************/
/* Local Typedefs */
/******************/

/********************/
/* Package Typedefs */
/********************/

/********************/
/* Local Prototypes */
/********************/

/*********************/
/* Package Variables */
/*********************/

/*****************************/
/* Library Private Variables */
/*****************************/

/*******************/
/* Local Variables */
/*******************/

#ifndef H5_NO_DEPRECATED_SYMBOLS
/*-------------------------------------------------------------------------
* Function: H5Iregister_type1
*
* Purpose: Public interface to H5I_register_type. Creates a new type
* of ID's to give out. A specific number (RESERVED) of type
* entries may be reserved to enable "constant" values to be handed
* out which are valid IDs in the type, but which do not map to any
* data structures and are not allocated dynamically later. HASH_SIZE is
* the minimum hash table size to use for the type. FREE_FUNC is
* called with an object pointer when the object is removed from
* the type.
*
* Return: Success: Type ID of the new type
* Failure: H5I_BADID
*
*-------------------------------------------------------------------------
*/
H5I_type_t
H5Iregister_type1(size_t H5_ATTR_UNUSED hash_size, unsigned reserved, H5I_free_t free_func)
{
H5I_type_t ret_value = H5I_BADID;

FUNC_ENTER_API(H5I_BADID)

if (H5I_BADID == (ret_value = H5I__register_type_common(reserved, free_func)))
HGOTO_ERROR(H5E_ID, H5E_CANTINIT, H5I_BADID, "can't initialize ID class");

done:
FUNC_LEAVE_API(ret_value)
} /* end H5Iregister_type1() */
#endif /* H5_NO_DEPRECATED_SYMBOLS */
70 changes: 70 additions & 0 deletions src/H5Iint.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,76 @@ H5I_term_package(void)
FUNC_LEAVE_NOAPI(in_use)
} /* end H5I_term_package() */

/*-------------------------------------------------------------------------
* Function: H5I__register_type_common
*
* Purpose: Common functionality for H5Iregister_type(1|2)
*
* Return: Success: Type ID of the new type
* Failure: H5I_BADID
*-------------------------------------------------------------------------
*/
H5I_type_t
H5I__register_type_common(unsigned reserved, H5I_free_t free_func)
{
H5I_class_t *cls = NULL; /* New ID class */
H5I_type_t new_type = H5I_BADID; /* New ID type value */
H5I_type_t ret_value = H5I_BADID; /* Return value */

FUNC_ENTER_PACKAGE

/* Generate a new H5I_type_t value */

/* Increment the number of types */
if (H5I_next_type_g < H5I_MAX_NUM_TYPES) {
new_type = (H5I_type_t)H5I_next_type_g;
H5I_next_type_g++;
}
else {
bool done; /* Indicate that search was successful */
int i;

/* Look for a free type to give out */
done = false;
for (i = H5I_NTYPES; i < H5I_MAX_NUM_TYPES && done == false; i++) {
if (NULL == H5I_type_info_array_g[i]) {
/* Found a free type ID */
new_type = (H5I_type_t)i;
done = true;
}
}

/* Verify that we found a type to give out */
if (done == false)
HGOTO_ERROR(H5E_ID, H5E_NOSPACE, H5I_BADID, "Maximum number of ID types exceeded");
}

/* Allocate new ID class */
if (NULL == (cls = H5MM_calloc(sizeof(H5I_class_t))))
HGOTO_ERROR(H5E_ID, H5E_CANTALLOC, H5I_BADID, "ID class allocation failed");

/* Initialize class fields */
cls->type = new_type;
cls->flags = H5I_CLASS_IS_APPLICATION;
cls->reserved = reserved;
cls->free_func = free_func;

/* Register the new ID class */
if (H5I_register_type(cls) < 0)
HGOTO_ERROR(H5E_ID, H5E_CANTINIT, H5I_BADID, "can't initialize ID class");

/* Set return value */
ret_value = new_type;

done:
/* Clean up on error */
if (ret_value == H5I_BADID)
if (cls)
cls = H5MM_xfree(cls);

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5I__register_type_common() */

/*-------------------------------------------------------------------------
* Function: H5I_register_type
*
Expand Down
Loading

0 comments on commit 8f2c03b

Please sign in to comment.