Skip to content

Commit e7e2f40

Browse files
authored
Merge pull request #2179 from DennisHeimbigner/vlenfix.dmh
Fix various problem around VLEN's
2 parents 20187ce + 978a99b commit e7e2f40

69 files changed

Lines changed: 5459 additions & 4433 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,10 +1270,6 @@ IF(ENABLE_TESTS)
12701270

12711271
OPTION(ENABLE_FAILING_TESTS "Run tests which are known to fail, check to see if any have been fixed." OFF)
12721272

1273-
# There is a special class of tests that currently fail because of memory leaks.
1274-
# As with failing tests, they can be enabled to work on them
1275-
OPTION(ENABLE_UNFIXED_MEMORY_LEAKS "Run tests with unfixed memory leaks" OFF)
1276-
12771273
###
12781274
# Option to turn on unit testing. See
12791275
# https://github.com/Unidata/netcdf-c/pull/1472 for more information.

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release
77

88
## 4.8.2 - TBD
99

10+
* [Bug Fix] Clean up the handling of deeply nested VLEN types. Marks nc_free_vlen() and nc_free_string as deprecated in favor of ncaux_reclaim_data(). See [Github #2179(https://github.com/Unidata/netcdf-c/pull/2179).
1011
* [Bug Fix] Make sure that netcdf.h accurately defines the flags in the open/create mode flags. See [Github #2183](https://github.com/Unidata/netcdf-c/pull/2183).
1112
* [Enhancement] Improve support for msys2+mingw platform. See [Github #2171](https://github.com/Unidata/netcdf-c/pull/2171).
1213
* [Bug Fix] Clean up the various inter-test dependencies in ncdump for CMake. See [Github #2168](https://github.com/Unidata/netcdf-c/pull/2168).

configure.ac

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,6 @@ if test "x$enable_jna" = xyes ; then
299299
AC_DEFINE([JNA], [1], [if true, include jna bug workaround code])
300300
fi
301301

302-
# Should tests with unfixed memory leaks be run?
303-
AC_MSG_CHECKING([if unfixed tests with memory leaks should be enabled])
304-
AC_ARG_ENABLE([unfixed-memory-leaks],
305-
[AS_HELP_STRING([--enable-unfixed-memory-leaks],
306-
[Enable tests in the ncdump directory that have unfixed memory leaks])])
307-
test "x$enable_unfixed_memory_leaks" = xyes || enable_unfixed_memory_leaks=no
308-
AC_MSG_RESULT($enable_unfixed_memory_leaks)
309-
AM_CONDITIONAL([ENABLE_UNFIXED_MEMORY_LEAKS], [test "x$enable_unfixed_memory_leaks" = xyes])
310-
311302
# Does the user want to turn off unit tests (useful for test coverage
312303
# analysis).
313304
AC_MSG_CHECKING([if unit tests should be disabled])

docs/Doxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ INPUT = \
782782
@abs_top_srcdir@/libdispatch/derror.c \
783783
@abs_top_srcdir@/libdispatch/dv2i.c \
784784
@abs_top_srcdir@/libdispatch/dcopy.c \
785+
@abs_top_srcdir@/libdispatch/daux.c \
785786
@abs_top_srcdir@/libsrc4/nc4var.c \
786787
@abs_top_srcdir@/libhdf5/nc4hdf.c \
787788
@abs_top_srcdir@/libsrc4/nc4internal.c \

include/nc4internal.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ typedef struct NC_ATT_INFO
170170
nc_type nc_typeid; /**< NetCDF type of attribute's data. */
171171
void *format_att_info; /**< Pointer to format-specific att info. */
172172
void *data; /**< The attribute data. */
173+
#ifdef SEPDATA
173174
nc_vlen_t *vldata; /**< VLEN data (only used for vlen types). */
174175
char **stdata; /**< String data (only for string type). */
176+
#endif
175177
} NC_ATT_INFO_T;
176178

177179
/** This is a struct to handle the var metadata. */
@@ -252,6 +254,7 @@ typedef struct NC_TYPE_INFO
252254
} e; /**< Enum */
253255
struct Fields {
254256
NClist* field; /**< <! NClist<NC_FIELD_INFO_T*> */
257+
int varsized; /**< <! 1 if this compound is variable sized; 0 if fixed size */
255258
} c; /**< Compound */
256259
struct {
257260
nc_type base_nc_typeid; /**< Typeid of the base type. */
@@ -281,7 +284,7 @@ typedef struct NC_GRP_INFO
281284
#define NC_INDEF 0x01 /**< in define mode, cleared by ncendef */
282285

283286
/** This is the metadata we need to keep track of for each
284-
* netcdf-4/HDF5 file. */
287+
* netcdf-4/ file; used by libhdf5, libnczarr, and libdap4 */
285288

286289
typedef struct NC_FILE_INFO
287290
{
@@ -296,7 +299,7 @@ typedef struct NC_FILE_INFO
296299
nc_bool_t parallel; /**< True if file is open for parallel access */
297300
nc_bool_t redef; /**< True if redefining an existing file */
298301
nc_bool_t no_attr_create_order; /**< True if the creation order tracking of attributes is disabled (netcdf-4 only) */
299-
int fill_mode; /**< Fill mode for vars - Unused internally currently */
302+
int fill_mode; /**< Fill mode for vars */
300303
nc_bool_t no_write; /**< true if nc_open has mode NC_NOWRITE. */
301304
NC_GRP_INFO_T *root_grp; /**< Pointer to root group. */
302305
short next_nc_grpid; /**< Next available group ID. */
@@ -419,14 +422,20 @@ extern int nc4_check_dup_name(NC_GRP_INFO_T *grp, char *norm_name);
419422
/* Get the fill value for a var. */
420423
extern int nc4_get_fill_value(NC_FILE_INFO_T *h5, NC_VAR_INFO_T *var, void **fillp);
421424

422-
/* Find default fill value. */
423-
extern int nc4_get_default_fill_value(nc_type typecode, void *fill_value);
425+
/* Find default fill value for atomic type. */
426+
extern int nc4_get_default_atomic_fill_value(nc_type, void *fill_value);
427+
428+
/* Find default fill value for any type */
429+
extern int nc4_get_default_fill_value(NC_TYPE_INFO_T*, void *fill_value);
424430

425431
/* Get an att given pointers to file, group, and perhaps ver info. */
426432
extern int nc4_get_att_ptrs(NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var,
427433
const char *name, nc_type *xtype, nc_type mem_type,
428434
size_t *lenp, int *attnum, void *data);
429435

436+
/* Get variable/fixed size flag for type */
437+
extern int NC4_inq_type_fixed_size(int ncid, nc_type xtype, int* isfixedsizep);
438+
430439
/* Close the file. */
431440
extern int nc4_close_netcdf4_file(NC_FILE_INFO_T *h5, int abort, NC_memio *memio);
432441

include/nclog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include <stdarg.h>
1111
#include "ncexternl.h"
1212

13+
#ifndef NCCATCH
1314
#undef NCCATCH
15+
#endif
1416

1517
#define NCENVLOGGING "NCLOGGING"
1618
#define NCENVTRACING "NCTRACING"

include/ncoffsets.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ typedef struct NCtypealignset {
5151
NCalignment ncvlenalign; /* nc_vlen_t*/
5252
} NCtypealignset;
5353

54-
EXTERNL size_t NC_class_alignment(int ncclass);
54+
EXTERNL int NC_class_alignment(int ncclass, size_t*);
5555
EXTERNL void NC_compute_alignments(void);
5656

57+
/* From libdispatch/dinstance.c */
58+
EXTERNL int NC_type_alignment(int ncid, nc_type xtype, size_t*);
59+
5760
#endif /*NCOFFSETS_H*/

include/netcdf.h

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,10 @@ nc_inq_vlen(int ncid, nc_type xtype, char *name, size_t *datum_sizep,
742742
/* When you read VLEN type the library will actually allocate the
743743
* storage space for the data. This storage space must be freed, so
744744
* pass the pointer back to this function, when you're done with the
745-
* data, and it will free the vlen memory. */
745+
* data, and it will free the vlen memory.
746+
* These two functions are deprecated in favor of the nc_reclaim_data function.
747+
*/
748+
746749
EXTERNL int
747750
nc_free_vlen(nc_vlen_t *vl);
748751

@@ -761,7 +764,9 @@ nc_get_vlen_element(int ncid, int typeid1, const void *vlen_element,
761764
/* When you read the string type the library will allocate the storage
762765
* space for the data. This storage space must be freed, so pass the
763766
* pointer back to this function, when you're done with the data, and
764-
* it will free the string memory. */
767+
* it will free the string memory.
768+
* This function is deprecated in favor of the nc_reclaim_data function.
769+
*/
765770
EXTERNL int
766771
nc_free_string(size_t len, char **data);
767772

@@ -1753,6 +1758,53 @@ nc_put_var_string(int ncid, int varid, const char **op);
17531758
EXTERNL int
17541759
nc_get_var_string(int ncid, int varid, char **ip);
17551760

1761+
/* Begin recursive instance walking functions */
1762+
1763+
/**
1764+
Reclaim a vector of instances of arbitrary type. Intended for
1765+
use with e.g. nc_get_vara or the input to e.g. nc_put_vara.
1766+
This recursively walks the top-level instances to reclaim any
1767+
nested data such as vlen or strings or such.
1768+
1769+
Assumes it is passed a pointer to count instances of xtype.
1770+
Reclaims any nested data.
1771+
1772+
WARNING: nc_reclaim_data does not reclaim the top-level
1773+
memory because we do not know how it was allocated. However
1774+
nc_reclaim_data_all does reclaim top-level memory.
1775+
1776+
WARNING: all data blocks below the top-level (e.g. string
1777+
instances) will be reclaimed, so do not call if there is any
1778+
static data in the instance.
1779+
1780+
Should work for any netcdf format.
1781+
*/
1782+
1783+
EXTERNL int nc_reclaim_data(int ncid, nc_type xtypeid, void* memory, size_t count);
1784+
EXTERNL int nc_reclaim_data_all(int ncid, nc_type xtypeid, void* memory, size_t count);
1785+
1786+
/**
1787+
1788+
Copy vector of arbitrary type instances. This recursively walks
1789+
the top-level instances to copy any nested data such as vlen or
1790+
strings or such.
1791+
1792+
Assumes it is passed a pointer to count instances of xtype.
1793+
WARNING: nc_copy_data does not copy the top-level memory, but
1794+
assumes a block of proper size was passed in. However
1795+
nc_copy_data_all does allocate top-level memory copy.
1796+
1797+
Should work for any netcdf format.
1798+
*/
1799+
1800+
EXTERNL int nc_copy_data(int ncid, nc_type xtypeid, const void* memory, size_t count, void* copy);
1801+
EXTERNL int nc_copy_data_all(int ncid, nc_type xtypeid, const void* memory, size_t count, void** copyp);
1802+
1803+
/* Instance dumper for debugging */
1804+
EXTERNL int nc_dump_data(int ncid, nc_type xtypeid, void* memory, size_t count, char** buf);
1805+
1806+
/* end recursive instance walking functions */
1807+
17561808
/* Begin Deprecated, same as functions with "_ubyte" replaced by "_uchar" */
17571809
EXTERNL int
17581810
nc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype,
@@ -1790,8 +1842,10 @@ nc_get_varm_ubyte(int ncid, int varid, const size_t *startp,
17901842
const ptrdiff_t * imapp, unsigned char *ip);
17911843
EXTERNL int
17921844
nc_put_var_ubyte(int ncid, int varid, const unsigned char *op);
1845+
17931846
EXTERNL int
17941847
nc_get_var_ubyte(int ncid, int varid, unsigned char *ip);
1848+
17951849
/* End Deprecated */
17961850

17971851
/* Set the log level. 0 shows only errors, 1 only major messages,

include/netcdf_aux.h

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,30 @@ extern "C" {
2424

2525

2626
/**
27-
Reclaim the output tree of data from a call
28-
to e.g. nc_get_vara or the input to e.g. nc_put_vara.
27+
Reclaim a vector of instances of arbitrary type.
28+
Intended for use with e.g. nc_get_vara or the input to e.g. nc_put_vara.
2929
This recursively walks the top-level instances to
3030
reclaim any nested data such as vlen or strings or such.
3131
3232
Assumes it is passed a pointer to count instances of xtype.
3333
Reclaims any nested data.
34-
WARNING: does not reclaim the top-level memory because
35-
we do not know how it was allocated.
36-
Should work for any netcdf format.
37-
*/
38-
39-
EXTERNL int ncaux_reclaim_data(int ncid, int xtype, void* memory, size_t count);
34+
WARNING: ncaux_reclaim_data does not reclaim the top-level memory
35+
because we do not know how it was allocated.
36+
However ncaux_reclaim_data_all does reclaim top-level memory.
4037
38+
WARNING: all data blocks below the top-level (e.g. string instances)
39+
will be reclaimed, so do not call if there is any static data in the instance.
4140
42-
EXTERNL int ncaux_begin_compound(int ncid, const char *name, int alignmode, void** tag);
43-
44-
EXTERNL int ncaux_end_compound(void* tag, nc_type* typeid);
45-
46-
EXTERNL int ncaux_abort_compound(void* tag);
47-
48-
EXTERNL int ncaux_add_field(void* tag, const char *name, nc_type field_type,
49-
int ndims, const int* dimsizes);
41+
Should work for any netcdf format.
5042
51-
/* Takes any type */
52-
EXTERNL size_t ncaux_type_alignment(int xtype, int ncid);
43+
WARNING: deprecated in favor the corresponding function in netcdf.h.
44+
These are just wrappers for nc_reclaim_data and
45+
nc_reclaim_data_all and nc_copy_data and nc_copy_data_all and
46+
are here for back compatibilty.
47+
*/
5348

54-
/* Takes type classes only */
55-
EXTERNL size_t ncaux_class_alignment(int ncclass);
49+
EXTERNL int ncaux_reclaim_data(int ncid, int xtype, void* memory, size_t count);
50+
EXTERNL int ncaux_reclaim_data_all(int ncid, int xtype, void* memory, size_t count);
5651

5752
/**************************************************/
5853
/* Capture the id and parameters for a filter
@@ -70,11 +65,30 @@ EXTERNL int ncaux_h5filterspec_parse_parameter(const char* txt, size_t* nuiparam
7065
EXTERNL void ncaux_h5filterspec_free(struct NC_H5_Filterspec* f);
7166
EXTERNL void ncaux_h5filterspec_fix8(unsigned char* mem, int decode);
7267

68+
/**************************************************/
7369
/* Wrappers to export selected functions from libnetcdf */
7470

7571
EXTERNL int ncaux_readfile(const char* filename, size_t* sizep, void** content);
7672
EXTERNL int ncaux_writefile(const char* filename, size_t size, void* content);
7773

74+
/**************************************************/
75+
76+
/* Takes any type */
77+
EXTERNL int ncaux_type_alignment(int xtype, int ncid, size_t* alignp);
78+
EXTERNL int ncaux_class_alignment(int ncclass, size_t* alignp);
79+
80+
/**************************************************/
81+
/* Takes type classes only */
82+
83+
/* Build compound types and properly handle offset and alignment */
84+
85+
EXTERNL int ncaux_class_alignment(int ncclass, size_t* alignp);
86+
EXTERNL int ncaux_begin_compound(int ncid, const char *name, int alignmode, void** tag);
87+
EXTERNL int ncaux_end_compound(void* tag, nc_type* xtypeid);
88+
EXTERNL int ncaux_abort_compound(void* tag);
89+
EXTERNL int ncaux_add_field(void* tag, const char *name, nc_type field_type,
90+
int ndims, const int* dimsizes);
91+
7892
#if defined(__cplusplus)
7993
}
8094
#endif

0 commit comments

Comments
 (0)