Merge branch 'main' of github.com:WardF/netcdf-c

This commit is contained in:
Ward Fisher 2023-12-11 10:08:22 -07:00
commit b1b29ed839
17 changed files with 128 additions and 76 deletions

View File

@ -14,6 +14,9 @@
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif

View File

@ -6,6 +6,9 @@
#ifndef NCS3SDK_H
#define NCS3SDK_H 1
#define AWSHOST ".amazonaws.com"
#define GOOGLEHOST "storage.googleapis.com"
/* Track the server type, if known */
typedef enum NCS3SVC {NCS3UNK=0, /* unknown */
NCS3=1, /* s3.amazon.aws */

View File

@ -694,7 +694,7 @@ searchgrouptree(int ncid1, int tid1, int grp, int* tid2)
int gid;
uintptr_t id;
id = grp;
id = (uintptr_t)grp;
nclistpush(queue,(void*)id); /* prime the queue */
while(nclistlength(queue) > 0) {
id = (uintptr_t)nclistremove(queue,0);
@ -712,7 +712,7 @@ searchgrouptree(int ncid1, int tid1, int grp, int* tid2)
goto done;
/* push onto the end of the queue */
for(i=0;i<nids;i++) {
id = ids[i];
id = (uintptr_t)ids[i];
nclistpush(queue,(void*)id);
}
free(ids); ids = NULL;

View File

@ -267,9 +267,9 @@ const char *nc_strerror(int ncerr1)
case NC_EMPI: return "NetCDF: MPI operation failed.";
case NC_ERCFILE:
return "NetCDF: RC File Failure.";
case NC_ENULLPAD:
case NC_ENULLPAD:
return "NetCDF: File fails strict Null-Byte Header check.";
case NC_EINMEMORY:
case NC_EINMEMORY:
return "NetCDF: In-memory File operation failed.";
case NC_ENCZARR:
return "NetCDF: NCZarr error";

View File

@ -1152,7 +1152,7 @@ NCH5_s3comms_s3r_open(const char* root, NCS3SVC svc, const char *region, const c
/* Compute the signing key */
if (SUCCEED != NCH5_s3comms_signing_key(&signing_key, access_key, region, iso8601now))
HGOTO_ERROR(H5E_ARGS, NC_EINVAL, NULL, "problem in NCH5_s3comms_s3comms_signing_key.");
if (nulllen(signing_key)==0)
if (signing_key == NULL)
HGOTO_ERROR(H5E_ARGS, NC_EAUTH, NULL, "signing key cannot be null.");
handle->signing_key = signing_key;
signing_key = NULL;
@ -2033,7 +2033,7 @@ NCH5_s3comms_signing_key(unsigned char **mdp, const char *secret, const char *re
if ((size_t)ret != (AWS4_secret_len - 1))
HGOTO_ERRORVA(H5E_ARGS, NC_EINVAL, FAIL, "problem writing AWS4+secret `%s`", secret);
if((md = (unsigned char*)malloc(SHA256_DIGEST_LENGTH))==NULL)
if((md = (unsigned char*)calloc(1,SHA256_DIGEST_LENGTH))==NULL)
HGOTO_ERROR(H5E_ARGS, NC_ENOMEM, NULL, "could not malloc space for signing key .");
/* hash_func, key, len(key), msg, len(msg), digest_dest, digest_len_dest

View File

@ -31,7 +31,7 @@ NClist* nclistnew(void)
ncinitialized = 1;
}
*/
l = (NClist*)malloc(sizeof(NClist));
l = (NClist*)calloc(1,sizeof(NClist));
if(l) {
l->alloc=0;
l->length=0;
@ -286,10 +286,13 @@ done:
void*
nclistextract(NClist* l)
{
void* result = l->content;
void* result = NULL;
if(l) {
result = l->content;
l->alloc = 0;
l->length = 0;
l->content = NULL;
}
return result;
}

View File

@ -46,7 +46,7 @@ static void
ncperr(const char* fcn, NCPSharedLib* lib)
{
const char* msg = dlerror();
lib->err.msg[0] = '\0';
memset(lib->err.msg,0,sizeof(lib->err.msg));
if(msg != NULL) {
strlcat(lib->err.msg,fcn,sizeof(lib->err.msg));
strlcat(lib->err.msg,": ",sizeof(lib->err.msg));

View File

@ -105,10 +105,9 @@ load(NCPSharedLib* lib , const char* path0, int flags)
char* msg = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &msg, 0, NULL);
if(msg) {
memset(lib->err.msg,0,sizeof(lib->err.msg));
if(msg)
strncpy(lib->err.msg,msg,sizeof(lib->err.msg));
} else
lib->err.msg[0] = '\0';
ret = NC_ENOTFOUND;
goto ldone;
}

View File

@ -68,6 +68,7 @@ EXTERNL int
ncpload(NCPSharedLib* lib, const char* path, int flags)
{
if(lib == NULL || path == NULL) return NC_EINVAL;
ncpclearerrmsg(lib);
return lib->api.load(lib,path,flags);
}
@ -75,6 +76,7 @@ EXTERNL int
ncpunload(NCPSharedLib* lib) /* Unloads a shared library. */
{
if(lib == NULL) return NC_EINVAL;
ncpclearerrmsg(lib);
return lib->api.unload(lib);
}
@ -93,6 +95,7 @@ EXTERNL void*
ncpgetsymbol(NCPSharedLib* lib,const char* name)
{
if(lib == NULL) return NULL;
ncpclearerrmsg(lib);
return lib->api.getsymbol(lib,name);
}
@ -113,3 +116,11 @@ ncpgeterrmsg(NCPSharedLib* lib)
if(lib == NULL) return NULL;
return (lib->err.msg[0] == '\0' ? NULL : lib->err.msg);
}
/* Clear the last err msg. */
EXTERNL void
ncpclearerrmsg(NCPSharedLib* lib)
{
if(lib == NULL) return;
memset(lib->err.msg,0,sizeof(lib->err.msg));
}

View File

@ -71,6 +71,9 @@ EXTERNL const char* ncpgetpath(NCPSharedLib*);
/* Return last err msg */
EXTERNL const char* ncpgeterrmsg(NCPSharedLib* lib);
/* Clear the last err msg. */
EXTERNL void ncpclearerrmsg(NCPSharedLib* lib);
EXTERNL const char* intstr(int err1);
#endif /*NCPOCO_H*/

View File

@ -230,15 +230,18 @@ dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref)
ncap->nelems = 0;
{
NC_attr **app = ncap->value;
const NC_attr **drpp = (const NC_attr **)ref->value;
NC_attr *const *const end = &app[ref->nelems];
for( /*NADA*/; app < end; drpp++, app++, ncap->nelems++)
if (app)
{
*app = dup_NC_attr(*drpp);
if(*app == NULL)
const NC_attr **drpp = (const NC_attr **)ref->value;
NC_attr *const *const end = &app[ref->nelems];
for( /*NADA*/; app < end; drpp++, app++, ncap->nelems++)
{
status = NC_ENOMEM;
break;
*app = dup_NC_attr(*drpp);
if(*app == NULL)
{
status = NC_ENOMEM;
break;
}
}
}
}

View File

@ -228,15 +228,18 @@ dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref)
ncap->nelems = 0;
{
NC_dim **dpp = ncap->value;
const NC_dim **drpp = (const NC_dim **)ref->value;
NC_dim *const *const end = &dpp[ref->nelems];
for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->nelems++)
if(dpp != NULL)
{
*dpp = dup_NC_dim(*drpp);
if(*dpp == NULL)
const NC_dim **drpp = (const NC_dim **)ref->value;
NC_dim *const *const end = &dpp[ref->nelems];
for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->nelems++)
{
status = NC_ENOMEM;
break;
*dpp = dup_NC_dim(*drpp);
if(*dpp == NULL)
{
status = NC_ENOMEM;
break;
}
}
}
}

View File

@ -950,7 +950,6 @@ int
NC_calcsize(const NC3_INFO *ncp, off_t *calcsizep)
{
NC_var **vpp = (NC_var **)ncp->vars.value;
NC_var *const *const end = &vpp[ncp->vars.nelems];
NC_var *last_fix = NULL; /* last "non-record" var */
int numrecvars = 0; /* number of record variables */
@ -960,12 +959,16 @@ NC_calcsize(const NC3_INFO *ncp, off_t *calcsizep)
return NC_NOERR;
}
for( /*NADA*/; vpp < end; vpp++) {
if(IS_RECVAR(*vpp)) {
numrecvars++;
} else {
last_fix = *vpp;
}
if (vpp)
{
NC_var *const *const end = &vpp[ncp->vars.nelems];
for( /*NADA*/; vpp < end; vpp++) {
if(IS_RECVAR(*vpp)) {
numrecvars++;
} else {
last_fix = *vpp;
}
}
}
if(numrecvars == 0) {

View File

@ -551,7 +551,7 @@ static int
NCedgeck(const NC3_INFO* ncp, const NC_var *varp,
const size_t *start, const size_t *edges)
{
const size_t *const end = start + varp->ndims;
const size_t *const end = start ? (start + varp->ndims) : NULL;
const size_t *shp = varp->shape;
if(varp->ndims == 0)

View File

@ -448,10 +448,13 @@ ncx_len_NC_dimarray(const NC_dimarray *ncap, int version)
/* else */
{
const NC_dim **dpp = (const NC_dim **)ncap->value;
const NC_dim *const *const end = &dpp[ncap->nelems];
for( /*NADA*/; dpp < end; dpp++)
if (dpp)
{
xlen += ncx_len_NC_dim(*dpp,version);
const NC_dim *const *const end = &dpp[ncap->nelems];
for( /*NADA*/; dpp < end; dpp++)
{
xlen += ncx_len_NC_dim(*dpp,version);
}
}
}
return xlen;
@ -641,11 +644,13 @@ v1h_put_NC_attrV(v1hs *psp, const NC_attr *attrp)
if(status != NC_NOERR)
return status;
(void) memcpy(psp->pos, value, nbytes);
if (value) {
(void) memcpy(psp->pos, value, nbytes);
value = (void *)((char *)value + nbytes);
}
psp->pos = (void *)((char *)psp->pos + nbytes);
value = (void *)((char *)value + nbytes);
remaining -= nbytes;
remaining -= nbytes;
} while(remaining != 0);
@ -709,11 +714,13 @@ v1h_get_NC_attrV(v1hs *gsp, NC_attr *attrp)
if(status != NC_NOERR)
return status;
(void) memcpy(value, gsp->pos, nget);
if (value) {
(void) memcpy(value, gsp->pos, nget);
value = (void *)((signed char *)value + nget);
}
gsp->pos = (void*)((unsigned char *)gsp->pos + nget);
value = (void *)((signed char *)value + nget);
remaining -= nget;
} while(remaining != 0);
@ -790,10 +797,13 @@ ncx_len_NC_attrarray(const NC_attrarray *ncap, int version)
/* else */
{
const NC_attr **app = (const NC_attr **)ncap->value;
const NC_attr *const *const end = &app[ncap->nelems];
for( /*NADA*/; app < end; app++)
if (app)
{
xlen += ncx_len_NC_attr(*app,version);
const NC_attr *const *const end = &app[ncap->nelems];
for( /*NADA*/; app < end; app++)
{
xlen += ncx_len_NC_attr(*app,version);
}
}
}
return xlen;
@ -1090,10 +1100,13 @@ ncx_len_NC_vararray(const NC_vararray *ncap, size_t sizeof_off_t, int version)
/* else */
{
const NC_var **vpp = (const NC_var **)ncap->value;
const NC_var *const *const end = &vpp[ncap->nelems];
for( /*NADA*/; vpp < end; vpp++)
if (vpp)
{
xlen += ncx_len_NC_var(*vpp, sizeof_off_t, version);
const NC_var *const *const end = &vpp[ncap->nelems];
for( /*NADA*/; vpp < end; vpp++)
{
xlen += ncx_len_NC_var(*vpp, sizeof_off_t, version);
}
}
}
return xlen;
@ -1224,7 +1237,6 @@ static int
NC_computeshapes(NC3_INFO* ncp)
{
NC_var **vpp = (NC_var **)ncp->vars.value;
NC_var *const *const end = &vpp[ncp->vars.nelems];
NC_var *first_var = NULL; /* first "non-record" var */
NC_var *first_rec = NULL; /* first "record" var */
int status;
@ -1236,27 +1248,31 @@ NC_computeshapes(NC3_INFO* ncp)
if(ncp->vars.nelems == 0)
return(0);
for( /*NADA*/; vpp < end; vpp++)
if (vpp)
{
status = NC_var_shape(*vpp, &ncp->dims);
if(status != NC_NOERR)
return(status);
NC_var *const *const end = &vpp[ncp->vars.nelems];
for( /*NADA*/; vpp < end; vpp++)
{
status = NC_var_shape(*vpp, &ncp->dims);
if(status != NC_NOERR)
return(status);
if(IS_RECVAR(*vpp))
{
if(first_rec == NULL)
first_rec = *vpp;
ncp->recsize += (*vpp)->len;
}
else
{
if(first_var == NULL)
if(IS_RECVAR(*vpp))
{
if(first_rec == NULL)
first_rec = *vpp;
ncp->recsize += (*vpp)->len;
}
else
{
if(first_var == NULL)
first_var = *vpp;
/*
* Overwritten each time thru.
* Usually overwritten in first_rec != NULL clause below.
*/
ncp->begin_rec = (*vpp)->begin + (off_t)(*vpp)->len;
/*
* Overwritten each time thru.
* Usually overwritten in first_rec != NULL clause below.
*/
ncp->begin_rec = (*vpp)->begin + (off_t)(*vpp)->len;
}
}
}

View File

@ -267,14 +267,17 @@ dup_NC_vararrayV(NC_vararray *ncap, const NC_vararray *ref)
{
NC_var **vpp = ncap->value;
const NC_var **drpp = (const NC_var **)ref->value;
NC_var *const *const end = &vpp[ref->nelems];
for( /*NADA*/; vpp < end; drpp++, vpp++, ncap->nelems++)
if (vpp)
{
*vpp = dup_NC_var(*drpp);
if(*vpp == NULL)
NC_var *const *const end = &vpp[ref->nelems];
for( /*NADA*/; vpp < end; drpp++, vpp++, ncap->nelems++)
{
status = NC_ENOMEM;
break;
*vpp = dup_NC_var(*drpp);
if(*vpp == NULL)
{
status = NC_ENOMEM;
break;
}
}
}
}

View File

@ -61,7 +61,9 @@ if ! aws s3api list-objects-v2 --bucket ${S3TESTBUCKET} --prefix "${S3TESTSUBTRE
fi
aws s3api list-objects-v2 --bucket ${S3TESTBUCKET} --prefix "${S3TESTSUBTREE}" | grep -F '"Key":' >s3gc.keys
while read -r line; do
KEY=`echo "$line" | sed -e 's|[^"]*"Key":[^"]*"\([^"]*\)".*|\1|'`
KEY0=`echo "$line" | sed -e 's|[^"]*"Key":[^"]*"\([^"]*\)".*|\1|'`
# Strip off any leading '/'
KEY=`echo "$KEY0" | sed -e 's|^[/]*\(.*\)|\1|'`
# Ignore keys that do not start with ${S3TESTSUBTREE}
PREFIX=`echo "$KEY" | sed -e 's|\([^/]*\)/.*|\1|'`
if test "x$PREFIX" = "x$S3TESTSUBTREE" ; then