netcdf-c/ncdump/nciter.h
Dennis Heimbigner 245961de00 re: github issues
https://github.com/Unidata/netcdf-c/issues/1168
    https://github.com/Unidata/netcdf-c/issues/1163
    https://github.com/Unidata/netcdf-c/issues/1162

This PR partially fixes memory leaks in the netcdf-c library,
in the ncdump utility, and in some test cases.

The netcdf-c library now runs memory clean with the assumption
that the --disable-utilities option is used. The primary remaining
problem is ncgen. Once that is fixed, I believe the netcdf-c library
will run memory clean with no limitations.

Notes
-----------
1. Memory checking was performed using gcc -fsanitize=address.
   Valgrind-based testing has yet to be performed.
2. The pnetcdf, hdf4, and examples code has not been tested.

Misc. Non-leak changes
1. Make tst_diskless2 only run when netcdf4 is enabled (issue 1162)
2. Fix CmakeLists.txt to turn off logging if ENABLE_NETCDF_4 is OFF
3. Isolated all my debug scripts into a single top-level directory
   called debug
4. Fix some USE_NETCDF4 dependencies in nc_test and nc_test4 Makefile.am
2018-10-30 20:48:12 -06:00

61 lines
2.0 KiB
C

/*********************************************************************
* Copyright 2009, University Corporation for Atmospheric Research
* See netcdf/README file for copying and redistribution conditions.
* "$Id: nciter.h 400 2010-08-27 21:02:52Z russ $"
*********************************************************************/
#ifndef _NCITER_
#define _NCITER_
#include "netcdf.h"
#if defined(__cplusplus)
extern "C" {
#endif
/*
* The opaque structure to hold per-variable state of data iteration
*/
typedef struct {
int first; /* false after first invocation of nc_next_iter() */
int right_dim; /* rightmost dimension for start of variable pieces */
size_t rows; /* how many subpiece rows in bufsiz */
size_t numrows; /* how many row pieces in right_dim dimension */
size_t cur; /* current "row" in loop over row pieces */
size_t leftover; /* how many rows left over after partitioning
* bufsiz into subpiece blocks */
int more; /* whether there is more data still to get */
size_t to_get; /* number of values to get on this access */
int rank; /* number of dimensions */
size_t inc; /* increment for right_dim element of start vector */
int chunked; /* 1 if chunked, 0 if contiguous */
size_t *dimsizes;
size_t *chunksizes; /* ignored if not chunked */
} nciter_t;
/*
* The Interfaces
*/
/* Get iterator for variable data. Returns pointer to malloc'd
* nciter_t, which caller must later release using nc_free_iter(), not
* free(). */
extern int
nc_get_iter(int ncid, int varid, size_t bufsize, nciter_t **iterpp);
/* Iterate over blocks of variable values, using start and count
* vectors. Returns number of values to access (product of counts),
* or 0 if done. */
extern size_t
nc_next_iter(nciter_t *iterp, size_t *start, size_t *count);
/* Release memory allocated for iterator */
extern int
nc_free_iter(nciter_t *iterp);
#if defined(__cplusplus)
}
#endif
#endif /* _NCITER_ */