Skip to content

Commit

Permalink
Split H5Tconv.c into modules by type
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendersonHDF committed Apr 11, 2024
1 parent d284457 commit 2dd3fb4
Show file tree
Hide file tree
Showing 27 changed files with 7,567 additions and 6,892 deletions.
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,15 @@ set (H5T_SOURCES
${HDF5_SRC_DIR}/H5Tcommit.c
${HDF5_SRC_DIR}/H5Tcompound.c
${HDF5_SRC_DIR}/H5Tconv.c
${HDF5_SRC_DIR}/H5Tconv_char.c
${HDF5_SRC_DIR}/H5Tconv_short.c
${HDF5_SRC_DIR}/H5Tconv_int.c
${HDF5_SRC_DIR}/H5Tconv_long.c
${HDF5_SRC_DIR}/H5Tconv_llong.c
${HDF5_SRC_DIR}/H5Tconv_float16.c
${HDF5_SRC_DIR}/H5Tconv_float.c
${HDF5_SRC_DIR}/H5Tconv_double.c
${HDF5_SRC_DIR}/H5Tconv_ldouble.c
${HDF5_SRC_DIR}/H5Tcset.c
${HDF5_SRC_DIR}/H5Tdbg.c
${HDF5_SRC_DIR}/H5Tdeprec.c
Expand Down
36 changes: 11 additions & 25 deletions src/H5T.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
#include "H5VLprivate.h" /* Virtual Object Layer */
#include "H5VMprivate.h" /* Vectors and arrays */

/* Datatype conversion functions */
#include "H5Tconv_char.h"
#include "H5Tconv_short.h"
#include "H5Tconv_int.h"
#include "H5Tconv_long.h"
#include "H5Tconv_llong.h"
#include "H5Tconv_float.h"
#include "H5Tconv_double.h"
#include "H5Tconv_ldouble.h"

/****************/
/* Local Macros */
/****************/
Expand Down Expand Up @@ -4491,30 +4501,6 @@ H5T_get_size(const H5T_t *dt)
FUNC_LEAVE_NOAPI(dt->shared->size)
} /* end H5T_get_size() */

/*-------------------------------------------------------------------------
* Function: H5T_get_force_conv
*
* Purpose: Determines if the type has forced conversion. This will be
* true if and only if the type keeps a pointer to a file VOL
* object internally.
*
* Return: true/false (never fails)
*
*-------------------------------------------------------------------------
*/
bool
H5T_get_force_conv(const H5T_t *dt)
{
/* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
FUNC_ENTER_NOAPI_NOINIT_NOERR

/* check args */
assert(dt);
assert(dt->shared);

FUNC_LEAVE_NOAPI(dt->shared->force_conv)
} /* end H5T_get_force_conv() */

/*-------------------------------------------------------------------------
* Function: H5T_cmp
*
Expand Down Expand Up @@ -5536,7 +5522,7 @@ H5T__path_free(H5T_path_t *path, H5T_conv_ctx_t *conv_ctx)
assert(conv_ctx);

if (path->conv.u.app_func) {
H5T__print_stats(path, &nprint);
H5T__print_path_stats(path, &nprint);

path->cdata.command = H5T_CONV_FREE;

Expand Down
7,892 changes: 1,793 additions & 6,099 deletions src/H5Tconv.c

Large diffs are not rendered by default.

232 changes: 232 additions & 0 deletions src/H5Tconv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 COPYING 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]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef H5Tconv_H
#define H5Tconv_H

/* Private headers needed by this file */
#include "H5private.h"
#include "H5Sprivate.h"
#include "H5Tprivate.h"

/**************************/
/* Library Private Macros */
/**************************/

/* Length of debugging name buffer */
#define H5T_NAMELEN 32

/****************************/
/* Library Private Typedefs */
/****************************/

/* Forward reference of H5S_t */
struct H5S_t;

/* Structure for conversion callback property */
typedef struct H5T_conv_cb_t {
H5T_conv_except_func_t func;
void *user_data;
} H5T_conv_cb_t;

/* Context struct for information used during datatype conversions.
* Which union member is valid to read from is dictated by the
* accompanying H5T_cdata_t structure's H5T_cmd_t member value.
*/
typedef struct H5T_conv_ctx_t {
union {
/*
* Fields only valid during conversion function initialization
* (H5T_cmd_t H5T_CONV_INIT)
*/
struct H5T_conv_ctx_init_fields {
H5T_conv_cb_t cb_struct;
} init;

/*
* Fields only valid during conversion function conversion
* process (H5T_cmd_t H5T_CONV_CONV)
*/
struct H5T_conv_ctx_conv_fields {
H5T_conv_cb_t cb_struct;
hid_t dxpl_id;
hid_t src_type_id;
hid_t dst_type_id;

/* Is conversion currently being done on a member of
* a container type, like a compound datatype? If so,
* cached information can be reused rather than creating
* and tearing it down for every compound element.
*/
bool recursive;
} conv;

/*
* Fields only valid during conversion function free process
* (H5T_cmd_t H5T_CONV_FREE)
*/
struct H5T_conv_ctx_free_fields {
hid_t src_type_id;
hid_t dst_type_id;
} free;
} u;
} H5T_conv_ctx_t;

/* Library internal datatype conversion functions are... */
typedef herr_t (*H5T_lib_conv_t)(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *buf, void *bkg);

/* Conversion callbacks */
typedef struct H5T_conv_func_t {
bool is_app; /* Whether conversion function is registered from application */
union {
H5T_conv_t app_func; /* Application data conversion function */
H5T_lib_conv_t lib_func; /* Library internal data conversion function */
} u;
} H5T_conv_func_t;

#ifdef H5T_DEBUG
/* Statistics about a conversion function */
typedef struct H5T_stats_t {
unsigned ncalls; /*num calls to conversion function */
hsize_t nelmts; /*total data points converted */
H5_timevals_t times; /*total time for conversion */
} H5T_stats_t;
#endif

/* The datatype conversion database */
typedef struct H5T_path_t {
char name[H5T_NAMELEN]; /*name for debugging only */
H5T_t *src; /*source datatype */
H5T_t *dst; /*destination datatype */
H5T_conv_func_t conv; /* Conversion function */
bool is_hard; /*is it a hard function? */
bool is_noop; /*is it the noop conversion? */
H5T_cdata_t cdata; /*data for this function */

#ifdef H5T_DEBUG
H5T_stats_t stats; /*statistics for the conversion */
#endif
} H5T_path_t;

/* The master list of soft conversion functions */
typedef struct H5T_soft_t {
char name[H5T_NAMELEN]; /*name for debugging only */
H5T_class_t src; /*source datatype class */
H5T_class_t dst; /*destination datatype class */
H5T_conv_func_t conv; /*the conversion function */
} H5T_soft_t;

/* Values for the optimization of compound data reading and writing. They indicate
* whether the fields of the source and destination are subset of each other and
* there is no conversion needed.
*/
typedef enum {
H5T_SUBSET_BADVALUE = -1, /* Invalid value */
H5T_SUBSET_FALSE = 0, /* Source and destination aren't subset of each other */
H5T_SUBSET_SRC, /* Source is the subset of dest and no conversion is needed */
H5T_SUBSET_DST, /* Dest is the subset of source and no conversion is needed */
H5T_SUBSET_CAP /* Must be the last value */
} H5T_subset_t;

typedef struct H5T_subset_info_t {
H5T_subset_t subset; /* See above */
size_t copy_size; /* Size in bytes, to copy for each element */
} H5T_subset_info_t;

/*****************************/
/* Library-private Variables */
/*****************************/

/***************************************/
/* Library-private Function Prototypes */
/***************************************/

H5_DLL herr_t H5T_convert(H5T_path_t *tpath, const H5T_t *src_type, const H5T_t *dst_type, size_t nelmts,
size_t buf_stride, size_t bkg_stride, void *buf, void *bkg);

/* Helper function for H5T_convert that accepts a pointer to a H5T_conv_ctx_t structure */
H5_DLL herr_t H5T_convert_with_ctx(H5T_path_t *tpath, const H5T_t *src_type, const H5T_t *dst_type,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *buf, void *bkg);

/* Conversion path and path table routines */
H5_DLL H5T_path_t *H5T_path_find(const H5T_t *src, const H5T_t *dst);
H5_DLL bool H5T_path_noop(const H5T_path_t *p);
H5_DLL bool H5T_noop_conv(const H5T_t *src, const H5T_t *dst);
H5_DLL H5T_bkg_t H5T_path_bkg(const H5T_path_t *p);
H5_DLL H5T_subset_info_t *H5T_path_compound_subset(const H5T_path_t *p);

/* Generic routines */
H5_DLL herr_t H5T_reclaim(const H5T_t *type, struct H5S_t *space, void *buf);
H5_DLL herr_t H5T_reclaim_cb(void *elem, const H5T_t *dt, unsigned ndim, const hsize_t *point, void *op_data);
H5_DLL bool H5T_get_force_conv(const H5T_t *dt);
H5_DLL H5T_subset_info_t *H5T__conv_struct_subset(const H5T_cdata_t *cdata);

/* Conversion functions */
H5_DLL herr_t H5T__conv_noop(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_order(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_order_opt(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_struct(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_struct_opt(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_enum(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *buf, void *bkg);
H5_DLL herr_t H5T__conv_enum_numeric(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *buf, void *bkg);
H5_DLL herr_t H5T__conv_vlen(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *buf, void *bkg);
H5_DLL herr_t H5T__conv_array(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *buf, void *bkg);
H5_DLL herr_t H5T__conv_ref(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *buf, void *bkg);
H5_DLL herr_t H5T__conv_i_i(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_f_f(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_f_i(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_i_f(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_s_s(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);
H5_DLL herr_t H5T__conv_b_b(const H5T_t *src, const H5T_t *dst, H5T_cdata_t *cdata,
const H5T_conv_ctx_t *conv_ctx, size_t nelmts, size_t buf_stride,
size_t bkg_stride, void *_buf, void *bkg);

/* Debugging functions */
H5_DLL herr_t H5T__print_path_stats(H5T_path_t *path, int *nprint /*in,out*/);

/* Testing functions */
H5_DLL int H5T__get_path_table_npaths(void);

#endif /* H5Tconv_H */
Loading

0 comments on commit 2dd3fb4

Please sign in to comment.