Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pointer to NC from open/create in the dispatch table #1450

Merged
merged 21 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/hdf4dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern "C" {

extern int
NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp,
void *parameters, const NC_Dispatch *, NC *);
void *parameters, const NC_Dispatch *, int);

extern int
NC_HDF4_abort(int ncid);
Expand Down
4 changes: 2 additions & 2 deletions include/nc3dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ extern "C" {
extern int
NC3_create(const char *path, int cmode,
size_t initialsz, int basepe, size_t *chunksizehintp,
void* mpidata, const struct NC_Dispatch*, NC* ncp);
void* mpidata, const struct NC_Dispatch*, int ncid);

/* WARNING: this signature differs from external nc_open API*/
extern int
NC3_open(const char *path, int mode,
int basepe, size_t *chunksizehintp,
void* mpidata, const NC_Dispatch*, NC* ncp);
void* mpidata, const NC_Dispatch*, int ncid);

extern int
NC3_new_nc(NC**);
Expand Down
4 changes: 2 additions & 2 deletions include/nc4dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ extern "C" {
EXTERNL int
NC4_create(const char *path, int cmode,
size_t initialsz, int basepe, size_t *chunksizehintp,
void* parameters, const NC_Dispatch*, NC*);
void* parameters, const NC_Dispatch*, int);

EXTERNL int
NC4_open(const char *path, int mode,
int basepe, size_t *chunksizehintp,
void* parameters, const NC_Dispatch*, NC*);
void* parameters, const NC_Dispatch*, int);

EXTERNL int
NC4_redef(int ncid);
Expand Down
2 changes: 2 additions & 0 deletions include/nc4internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ int nc4_get_typeclass(const NC_FILE_INFO_T *h5, nc_type xtype,
int nc4_type_free(NC_TYPE_INFO_T *type);

/* These list functions add and delete vars, atts. */
int nc4_file_list_add(int ncid, const char *path, int mode,
void **dispatchdata);
int nc4_nc4f_list_add(NC *nc, const char *path, int mode);
int nc4_nc4f_list_del(NC_FILE_INFO_T *h5);
int nc4_var_list_add(NC_GRP_INFO_T* grp, const char* name, int ndims,
Expand Down
6 changes: 3 additions & 3 deletions include/netcdf_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ struct NC_Dispatch

int (*create)(const char *path, int cmode, size_t initialsz,
int basepe, size_t *chunksizehintp, void *parameters,
const struct NC_Dispatch *table, NC *ncp);
const struct NC_Dispatch *table, int ncid);
int (*open)(const char *path, int mode, int basepe, size_t *chunksizehintp,
void *parameters, const struct NC_Dispatch *table, NC *ncp);
void *parameters, const struct NC_Dispatch *table, int ncid);

int (*redef)(int);
int (*_enddef)(int,size_t,size_t,size_t,size_t);
Expand Down Expand Up @@ -140,7 +140,7 @@ struct NC_Dispatch

EXTERNL int NC_RO_create(const char *path, int cmode, size_t initialsz, int basepe,
size_t *chunksizehintp, void* parameters,
const NC_Dispatch*, NC*);
const NC_Dispatch*, int);
EXTERNL int NC_RO_redef(int ncid);
EXTERNL int NC_RO__enddef(int ncid, size_t h_minfree, size_t v_align, size_t v_minfree,
size_t r_align);
Expand Down
11 changes: 8 additions & 3 deletions libdap2/ncd2dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static NCerror applyclientparams(NCDAPCOMMON*);
static int
NCD2_create(const char *path, int cmode,
size_t initialsz, int basepe, size_t *chunksizehintp,
void* mpidata, const struct NC_Dispatch*,NC* ncp);
void* mpidata, const struct NC_Dispatch*,int);

static int NCD2_redef(int ncid);
static int NCD2__enddef(int ncid, size_t h_minfree, size_t v_align, size_t v_minfree, size_t r_align);
Expand Down Expand Up @@ -227,7 +227,7 @@ NCD2_abort(int ncid)
static int
NCD2_create(const char *path, int cmode,
size_t initialsz, int basepe, size_t *chunksizehintp,
void* mpidata, const NC_Dispatch* dispatch, NC* ncp)
void* mpidata, const NC_Dispatch* dispatch, int ncid)
{
return NC_EPERM;
}
Expand Down Expand Up @@ -271,14 +271,19 @@ NCD2_get_vars(int ncid, int varid,
/* See ncd2dispatch.c for other version */
int
NCD2_open(const char* path, int mode, int basepe, size_t *chunksizehintp,
void* mpidata, const NC_Dispatch* dispatch, NC* drno)
void* mpidata, const NC_Dispatch* dispatch, int ncid)
{
NCerror ncstat = NC_NOERR;
OCerror ocstat = OC_NOERR;
NCDAPCOMMON* dapcomm = NULL;
NC* drno;
const char* value;
int nc3id = -1;

/* Find pointer to NC struct for this file. */
ncstat = NC_check_id(ncid,&drno);
if(ncstat != NC_NOERR) {goto done;}

if(path == NULL)
{ncstat = NC_EDAPURL; goto done;}
if(dispatch == NULL)
Expand Down
2 changes: 1 addition & 1 deletion libdap2/ncd2dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extern "C" {
extern int
NCD2_open(const char *path, int mode,
int basepe, size_t *chunksizehintp,
void* mpidata, const struct NC_Dispatch* dispatch, NC* ncp);
void* mpidata, const struct NC_Dispatch* dispatch, int ncid);

extern int
NCD2_close(int ncid,void*);
Expand Down
7 changes: 6 additions & 1 deletion libdap4/d4file.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,23 @@ static const char* checkseps = "+,:;";
int
NCD4_open(const char * path, int mode,
int basepe, size_t *chunksizehintp,
void *mpidata, const NC_Dispatch *dispatch, NC *nc)
void *mpidata, const NC_Dispatch *dispatch, int ncid)
{
int ret = NC_NOERR;
NCD4INFO* d4info = NULL;
const char* value;
NCD4meta* meta;
NC* nc;

if(path == NULL)
return THROW(NC_EDAPURL);

assert(dispatch != NULL);

/* Find pointer to NC struct for this file. */
ret = NC_check_id(ncid,&nc);
if(ret != NC_NOERR) {goto done;}

/* Setup our NC and NCDAPCOMMON state*/

d4info = (NCD4INFO*)calloc(1,sizeof(NCD4INFO));
Expand Down
2 changes: 1 addition & 1 deletion libdap4/ncd4dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ NCD4_sync(int ncid)
static int
NCD4_create(const char *path, int cmode,
size_t initialsz, int basepe, size_t *chunksizehintp,
void* mpidata, const NC_Dispatch *dispatch, NC *ncp)
void* mpidata, const NC_Dispatch *dispatch, int ncid)
{
return THROW(NC_EPERM);
}
Expand Down
2 changes: 1 addition & 1 deletion libdap4/ncd4dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern "C" {
extern int
NCD4_open(const char *path, int mode,
int basepe, size_t *chunksizehintp,
void *mpidata, const struct NC_Dispatch *dispatch, NC *ncp);
void *mpidata, const struct NC_Dispatch *dispatch, int ncid);

extern int
NCD4_close(int ncid,void*);
Expand Down
6 changes: 3 additions & 3 deletions libdispatch/dfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ NC_create(const char *path0, int cmode, size_t initialsz,

/* Assume create will fill in remaining ncp fields */
if ((stat = dispatcher->create(ncp->path, cmode, initialsz, basepe, chunksizehintp,
parameters, dispatcher, ncp))) {
parameters, dispatcher, ncp->ext_ncid))) {
del_from_NCList(ncp); /* oh well */
free_NC(ncp);
} else {
Expand Down Expand Up @@ -2090,12 +2090,12 @@ NC_open(const char *path0, int omode, int basepe, size_t *chunksizehintp,
/* Create the NC* instance and insert its dispatcher */
if((stat = new_NC(dispatcher,path,omode,&model,&ncp))) goto done;

/* Add to list of known open files */
/* Add to list of known open files. This assignes an ext_ncid. */
add_to_NCList(ncp);

/* Assume open will fill in remaining ncp fields */
stat = dispatcher->open(ncp->path, omode, basepe, chunksizehintp,
parameters, dispatcher, ncp);
parameters, dispatcher, ncp->ext_ncid);
if(stat == NC_NOERR) {
if(ncidp) *ncidp = ncp->ext_ncid;
} else {
Expand Down
4 changes: 2 additions & 2 deletions libdispatch/dreadonly.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ NC_RO_sync(int ncid)
* @param use_parallel Ignored.
* @param parameters Ignored.
* @param dispatch Ignored.
* @param nc_file Ignored.
* @param ncid Ignored.
*
* @return ::NC_EPERM Cannot create files.
* @author Ed Hartnett
*/
int
NC_RO_create(const char* path, int cmode, size_t initialsz, int basepe,
size_t *chunksizehintp, void *parameters,
const NC_Dispatch *dispatch, NC *nc_file)
const NC_Dispatch *dispatch, int ncid)
{
return NC_EPERM;
}
Expand Down
12 changes: 8 additions & 4 deletions libhdf4/hdf4file.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,20 +597,25 @@ hdf4_read_var(NC_FILE_INFO_T *h5, int v)
*/
int
NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp,
void *parameters, const NC_Dispatch *dispatch, NC *nc_file)
void *parameters, const NC_Dispatch *dispatch, int ncid)
{
NC_FILE_INFO_T *h5;
NC_HDF4_FILE_INFO_T *hdf4_file;
NC *nc;
int32 num_datasets, num_gatts;
int32 sdid;
int v, a;
int retval;

/* Check inputs. */
assert(nc_file && path);
assert(path);

LOG((1, "%s: path %s mode %d params %x", __func__, path, mode, parameters));

/* Find pointer to NC. */
if ((retval = NC_check_id(ncid, &nc)))
return retval;

/* Check the mode for validity */
if (mode & ILLEGAL_OPEN_FLAGS)
return NC_EINVAL;
Expand All @@ -624,9 +629,8 @@ NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp,
return NC_EHDFERR;

/* Add necessary structs to hold netcdf-4 file data. */
if ((retval = nc4_nc4f_list_add(nc_file, path, mode)))
if ((retval = nc4_file_list_add(ncid, path, mode, (void **)&h5)))
return retval;
h5 = (NC_FILE_INFO_T *)nc_file->dispatchdata;
assert(h5 && h5->root_grp);
h5->no_write = NC_TRUE;
h5->root_grp->atts_read = 1;
Expand Down
39 changes: 19 additions & 20 deletions libhdf5/hdf5create.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ extern int NC4_create_image_file(NC_FILE_INFO_T* h5, size_t);
*
* @param path The file name of the new file.
* @param cmode The creation mode flag.
* @param initialsz The proposed initial file size (advisory)
* @param parameters extra parameter info (like MPI communicator)
* @param nc Pointer to an instance of NC.
* @param initialsz The proposed initial file size (advisory, for
* in-memory netCDF-4/HDF5 files only).
* @param parameters extra parameter info (like MPI communicator).
* @param ncid The already-assigned ncid for this file (aka ext_ncid).
*
* @return ::NC_NOERR No error.
* @return ::NC_EINVAL Invalid input (check cmode).
Expand All @@ -40,13 +41,13 @@ extern int NC4_create_image_file(NC_FILE_INFO_T* h5, size_t);
*/
static int
nc4_create_file(const char *path, int cmode, size_t initialsz,
void* parameters, NC *nc)
void* parameters, int ncid)
{
hid_t fcpl_id, fapl_id = -1;
unsigned flags;
FILE *fp;
int retval = NC_NOERR;
NC_FILE_INFO_T* nc4_info = NULL;
NC_FILE_INFO_T *nc4_info;
NC_HDF5_FILE_INFO_T *hdf5_info;
NC_HDF5_GRP_INFO_T *hdf5_grp;

Expand All @@ -58,13 +59,13 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
int info_duped = 0; /* Whether the MPI Info object was duplicated */
#endif /* !USE_PARALLEL4 */

assert(nc && path);
assert(path);
LOG((3, "%s: path %s mode 0x%x", __func__, path, cmode));

/* Add necessary structs to hold netcdf-4 file data. */
if ((retval = nc4_nc4f_list_add(nc, path, (NC_WRITE | cmode))))
if ((retval = nc4_file_list_add(ncid, path, NC_WRITE | cmode,
(void **)&nc4_info)))
BAIL(retval);
nc4_info = NC4_DATA(nc);
assert(nc4_info && nc4_info->root_grp);
nc4_info->root_grp->atts_read = 1;

Expand Down Expand Up @@ -261,7 +262,8 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
* @param parameters pointer to struct holding extra data (e.g. for
* parallel I/O) layer. Ignored if NULL.
* @param dispatch Pointer to the dispatch table for this file.
* @param nc_file Pointer to an instance of NC.
* @param ncid The ncid that has been assigned by the dispatch layer
* (aka ext_ncid).
*
* @return ::NC_NOERR No error.
* @return ::NC_EINVAL Invalid input (check cmode).
Expand All @@ -271,11 +273,11 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
int
NC4_create(const char* path, int cmode, size_t initialsz, int basepe,
size_t *chunksizehintp, void *parameters,
const NC_Dispatch *dispatch, NC *nc_file)
const NC_Dispatch *dispatch, int ncid)
{
int res;

assert(nc_file && path);
assert(path);

LOG((1, "%s: path %s cmode 0x%x parameters %p",
__func__, path, cmode, parameters));
Expand All @@ -290,16 +292,13 @@ NC4_create(const char* path, int cmode, size_t initialsz, int basepe,
hdf5_set_log_level();
#endif /* LOGGING */

/* Check the cmode for validity. */
if((cmode & ILLEGAL_CREATE_FLAGS) != 0)
{res = NC_EINVAL; goto done;}
/* Check the cmode for validity. Checking parallel against
* NC_DISKLESS already done in NC_create(). */
if (cmode & ILLEGAL_CREATE_FLAGS)
return NC_EINVAL;

/* check parallel against NC_DISKLESS already done in NC_create() */
/* Create the netCDF-4/HDF5 file. */
res = nc4_create_file(path, cmode, initialsz, parameters, ncid);

nc_file->int_ncid = nc_file->ext_ncid;

res = nc4_create_file(path, cmode, initialsz, parameters, nc_file);

done:
return res;
}
Loading