Further progress on [NCF-340], capturing previously-lost error code NC_EGLOBAL

This commit is contained in:
Ward Fisher 2015-09-10 15:55:06 -06:00
parent 7aa22d275b
commit dffaff8406
4 changed files with 299 additions and 4252 deletions

View File

@ -217,8 +217,8 @@ NC_findvar(const NC_vararray *ncap, const char *name, NC_var **varpp);
extern int
NC_check_vlen(NC_var *varp, size_t vlen_max);
extern NC_var *
NC_lookupvar(NC3_INFO* ncp, int varid);
extern int
NC_lookupvar(NC3_INFO* ncp, int varid, NC_var **varp);
/* End defined in var.c */
@ -286,7 +286,7 @@ struct NC3_INFO {
fIsSet((ncp)->flags, NC_CREAT)
#define NC_indef(ncp) \
(NC_IsNew(ncp) || fIsSet((ncp)->flags, NC_INDEF))
(NC_IsNew(ncp) || fIsSet((ncp)->flags, NC_INDEF))
#define set_NC_ndirty(ncp) \
fSet((ncp)->flags, NC_NDIRTY)

File diff suppressed because it is too large Load Diff

View File

@ -1332,9 +1332,9 @@ NC3_get_vara(int ncid, int varid,
if(NC_indef(nc3))
return NC_EINDEFINE;
varp = NC_lookupvar(nc3, varid);
if(varp == NULL)
return NC_ENOTVAR;
status = NC_lookupvar(nc3, varid, &varp);
if(status != NC_NOERR)
return status;
if(memtype == NC_NAT) memtype=varp->type;
@ -1463,7 +1463,7 @@ NC3_put_vara(int ncid, int varid,
return NC_EINDEFINE;
status = NC_lookupvar(nc3, varid, &varp);
if(status != NC_NOERROR)
if(status != NC_NOERR)
return status; /*invalid varid */

View File

@ -509,32 +509,37 @@ NC_check_vlen(NC_var *varp, size_t vlen_max) {
}
/*
* Given valid ncp and varid, return var
* else NULL on error
* Formerly
NC_hlookupvar()
/*! Look up a variable by varid.
*
* Given a valid ncp structure and varid, return the var.
*
* Formerly NC_hlookupvar()
*
* @param[in] ncp NC3_INFO data structure.
* @param[in] varid The varid key for the var we are looking up.
* @param[out] varp Data structure to contain the varp pointer.
* @return Error code, if one exists, 0 otherwise.
*/
NC_var *
NC_lookupvar(NC3_INFO* ncp, int varid)
{
NC_var *varp;
int NC_lookupvar(NC3_INFO* ncp, int varid, NC_var **varp)
{
if(varid == NC_GLOBAL)
{
/* Global is error in this context */
return(NULL);
return NC_EGLOBAL;
}
varp = elem_NC_vararray(&ncp->vars, (size_t)varid);
*varp = elem_NC_vararray(&ncp->vars, (size_t)varid);
if(varp == NULL)
{
return NULL;
return NC_ENOTVAR;
}
assert(varp != NULL);
return NC_NOERR;
return(varp);
}
@ -717,11 +722,11 @@ NC3_rename_var(int ncid, int varid, const char *unewname)
return NC_ENAMEINUSE;
}
varp = NC_lookupvar(ncp, varid);
if(varp == NULL)
status = NC_lookupvar(ncp, varid, &varp);
if(status != NC_NOERR)
{
/* invalid varid */
return NC_ENOTVAR; /* TODO: is this the right error code? */
return status;
}
old = varp->name;