Merge branch 'main' into silence-ncgen-warnings

* main:
  Set flags to avoid warning messages if curl isn't found.
  Use modern cmake nomenclature for curl.
  Skip checking for duplicates if only one element in list
  Change format of backwards-loops
This commit is contained in:
Peter Hill 2024-04-05 17:12:45 +01:00
commit 03db612ef1
No known key found for this signature in database
GPG Key ID: 0C6B9742E72848EE
18 changed files with 68 additions and 71 deletions

View File

@ -218,25 +218,27 @@ endif(USE_HDF5)
################################ ################################
# See if we have libcurl # See if we have libcurl
find_package(CURL) find_package(CURL)
target_compile_options(netcdf #target_compile_options(netcdf
PRIVATE # PRIVATE
-DCURL_STATICLIB=1 # -DCURL_STATICLIB=1
) #)
target_include_directories(netcdf #target_include_directories(netcdf
PRIVATE # PRIVATE
${CURL_INCLUDE_DIRS} # ${CURL_INCLUDE_DIRS}
) #)
if(CURL_FOUND)
MESSAGE(STATUS "Found CURL_INCLUDE_DIRS: ${CURL_INCLUDE_DIRS}")
# Define a test flag for have curl library
if(CURL_LIBRARIES OR CURL_LIBRARY)
set(FOUND_CURL TRUE) set(FOUND_CURL TRUE)
target_link_libraries(netcdf
PRIVATE
CURL::libcurl
)
else() else()
set(FOUND_CURL FALSE) set(FOUND_CURL FALSE)
endif() set(NETCDF_ENABLE_DAP2 OFF)
set(FOUND_CURL ${FOUND_CURL} TRUE ) set(NETCDF_ENABLE_DAP4 OFF)
set(NETCDF_ENABLE_BYTERANGE OFF)
set(NETCDF_ENABLE_S3 OFF)
endif(CURL_FOUND)
# Start disabling if curl not found # Start disabling if curl not found
if(NOT FOUND_CURL) if(NOT FOUND_CURL)

View File

@ -27,7 +27,7 @@ set_property(SOURCE ncd2dispatch.c
add_library(dap2 OBJECT ${dap2_SOURCES}) add_library(dap2 OBJECT ${dap2_SOURCES})
target_link_libraries(dap2 PUBLIC ${CURL_LIBRARIES}) target_link_libraries(dap2 PUBLIC CURL::libcurl ${CURL_LIBRARIES})
target_include_directories(dap2 PUBLIC ${CURL_INCLUDE_DIRS}) target_include_directories(dap2 PUBLIC ${CURL_INCLUDE_DIRS})
target_compile_options(dap2 target_compile_options(dap2
PRIVATE PRIVATE

View File

@ -25,7 +25,7 @@ static int iscacheableconstraint(DCEconstraint* con);
int int
iscached(NCDAPCOMMON* nccomm, CDFnode* target, NCcachenode** cachenodep) iscached(NCDAPCOMMON* nccomm, CDFnode* target, NCcachenode** cachenodep)
{ {
int i, found; int found;
size_t j; size_t j;
size_t index; size_t index;
NCcache* cache; NCcache* cache;
@ -39,7 +39,8 @@ iscached(NCDAPCOMMON* nccomm, CDFnode* target, NCcachenode** cachenodep)
cache = nccomm->cdf.cache; cache = nccomm->cdf.cache;
cachenode = cache->prefetch; cachenode = cache->prefetch;
if(cachenode!= NULL) { if(cachenode!= NULL) {
for(found=0,i=0;i<nclistlength(cachenode->vars);i++) { found = 0;
for(size_t i=0;i<nclistlength(cachenode->vars);i++) {
CDFnode* var = (CDFnode*)nclistget(cachenode->vars,i); CDFnode* var = (CDFnode*)nclistget(cachenode->vars,i);
if(var == target) { if(var == target) {
if(cachenodep) *cachenodep = cachenode; if(cachenodep) *cachenodep = cachenode;
@ -51,7 +52,7 @@ iscached(NCDAPCOMMON* nccomm, CDFnode* target, NCcachenode** cachenodep)
/*search other cache nodes starting at latest first */ /*search other cache nodes starting at latest first */
index = 0; index = 0;
for(i=nclistlength(cache->nodes)-1;i>=0;i--) { for(size_t i = nclistlength(cache->nodes); i-->0;) {
cachenode = (NCcachenode*)nclistget(cache->nodes,i); cachenode = (NCcachenode*)nclistget(cache->nodes,i);
/* We currently do not try to match constraints; /* We currently do not try to match constraints;
If the cachenode is constrained by more than If the cachenode is constrained by more than

View File

@ -623,8 +623,7 @@ next: continue;
} /*for(;;)*/ } /*for(;;)*/
/* remove all NULL elements */ /* remove all NULL elements */
int n; for(size_t n = nclistlength(list); n-->0;) {
for(n=nclistlength(list)-1;n>=0;n--) {
DCEprojection* target = (DCEprojection*)nclistget(list,n); DCEprojection* target = (DCEprojection*)nclistget(list,n);
if(target == NULL) if(target == NULL)
nclistremove(list,n); nclistremove(list,n);

View File

@ -114,9 +114,8 @@ dapodom_count(Dapodometer* odom)
int int
dapodom_next(Dapodometer* odom) dapodom_next(Dapodometer* odom)
{ {
int i; /* do not make unsigned */
if(odom->rank == 0) return 0; if(odom->rank == 0) return 0;
for(i=odom->rank-1;i>=0;i--) { for(size_t i = odom->rank; i-->0;) {
odom->index[i] += odom->stride[i]; odom->index[i] += odom->stride[i];
if(odom->index[i] < odom->stop[i]) break; if(odom->index[i] < odom->stop[i]) break;
if(i == 0) return 0; /* leave the 0th entry if it overflows*/ if(i == 0) return 0; /* leave the 0th entry if it overflows*/

View File

@ -268,11 +268,8 @@ nclistminus(NClist* l1, NClist* l2)
int int
nclistdeleteall(NClist* l, void* elem) nclistdeleteall(NClist* l, void* elem)
{ {
int i; /* do not make unsigned */ int found = 0;
unsigned int len,found; for(size_t i = nclistlength(l); i-->0;) {
found = 0;
len = nclistlength(l);
for(i=len-1;i>=0;i--) {
void* test = nclistget(l,i); void* test = nclistget(l,i);
if(test==elem) { if(test==elem) {
nclistremove(l,i); nclistremove(l,i);

View File

@ -2146,14 +2146,14 @@ fail:
static NCerror static NCerror
suppressunusablevars(NCDAPCOMMON* dapcomm) suppressunusablevars(NCDAPCOMMON* dapcomm)
{ {
int i,j; size_t i,j;
int found = 1; int found = 1;
NClist* path = nclistnew(); NClist* path = nclistnew();
while(found) { while(found) {
found = 0; found = 0;
/* Walk backwards to aid removal semantics */ /* Walk backwards to aid removal semantics */
for(i=nclistlength(dapcomm->cdf.ddsroot->tree->varnodes)-1;i>=0;i--) { for(i = nclistlength(dapcomm->cdf.ddsroot->tree->varnodes); i-->0;) {
CDFnode* var = (CDFnode*)nclistget(dapcomm->cdf.ddsroot->tree->varnodes,i); CDFnode* var = (CDFnode*)nclistget(dapcomm->cdf.ddsroot->tree->varnodes,i);
/* See if this var is under an unusable sequence */ /* See if this var is under an unusable sequence */
nclistclear(path); nclistclear(path);

View File

@ -20,7 +20,7 @@ set_property(SOURCE d4meta.c
SKIP_UNITY_BUILD_INCLUSION ON) SKIP_UNITY_BUILD_INCLUSION ON)
add_library(dap4 OBJECT ${dap4_SOURCES}) add_library(dap4 OBJECT ${dap4_SOURCES})
target_link_libraries(dap4 PUBLIC ${CURL_LIBRARIES}) target_link_libraries(dap4 PUBLIC CURL::libcurl ${CURL_LIBRARIES})
target_include_directories(dap4 PUBLIC ${CURL_INCLUDE_DIRS}) target_include_directories(dap4 PUBLIC ${CURL_INCLUDE_DIRS})
target_compile_options(dap4 target_compile_options(dap4
PRIVATE PRIVATE

View File

@ -557,10 +557,9 @@ negateone(const char* mode, NClist* newmodes)
const struct MODEINFER* tests = modenegations; const struct MODEINFER* tests = modenegations;
int changed = 0; int changed = 0;
for(;tests->key;tests++) { for(;tests->key;tests++) {
int i;
if(strcasecmp(tests->key,mode)==0) { if(strcasecmp(tests->key,mode)==0) {
/* Find and remove all instances of the inference value */ /* Find and remove all instances of the inference value */
for(i=nclistlength(newmodes)-1;i>=0;i--) { for(size_t i = nclistlength(newmodes); i-- > 0;) {
char* candidate = nclistget(newmodes,i); char* candidate = nclistget(newmodes,i);
if(strcasecmp(candidate,tests->inference)==0) { if(strcasecmp(candidate,tests->inference)==0) {
nclistremove(newmodes,i); nclistremove(newmodes,i);
@ -1188,17 +1187,17 @@ cleancommalist(const char* commalist, int caseinsensitive)
static void static void
cleanstringlist(NClist* strs, int caseinsensitive) cleanstringlist(NClist* strs, int caseinsensitive)
{ {
int i,j;
if(nclistlength(strs) == 0) return; if(nclistlength(strs) == 0) return;
/* Remove nulls */ /* Remove nulls */
for(i=nclistlength(strs)-1;i>=0;i--) { for(size_t i = nclistlength(strs); i-->0;) {
if(nclistget(strs,i)==NULL) nclistremove(strs,i); if(nclistget(strs,i)==NULL) nclistremove(strs,i);
} }
if(nclistlength(strs) <= 1) return;
/* Remove duplicates*/ /* Remove duplicates*/
for(i=0;i<nclistlength(strs);i++) { for(size_t i=0;i<nclistlength(strs);i++) {
const char* value = nclistget(strs,i); const char* value = nclistget(strs,i);
/* look ahead for duplicates */ /* look ahead for duplicates */
for(j=nclistlength(strs)-1;j>i;j--) { for(size_t j=nclistlength(strs)-1;j>i;j--) {
int match; int match;
const char* candidate = nclistget(strs,j); const char* candidate = nclistget(strs,j);
if(caseinsensitive) if(caseinsensitive)

View File

@ -362,7 +362,6 @@ rctrim(char* text)
char* p; char* p;
char* q; char* q;
size_t len = 0; size_t len = 0;
int i;
if(text == NULL || *text == '\0') return; if(text == NULL || *text == '\0') return;
@ -375,7 +374,7 @@ rctrim(char* text)
len = strlen(p); len = strlen(p);
/* locate last non-trimchar */ /* locate last non-trimchar */
if(len > 0) { if(len > 0) {
for(i=(len-1);i>=0;i--) { for(size_t i = len; i-->0;) {
p = &text[i]; p = &text[i];
if(*p != ' ' && *p != '\t' && *p != '\r') {break;} if(*p != ' ' && *p != '\t' && *p != '\r') {break;}
*p = '\0'; /* elide trailing trimchars */ *p = '\0'; /* elide trailing trimchars */

View File

@ -224,13 +224,13 @@ printfilterlist(NC_VAR_INFO_T* var, const char* tag, int line)
int int
NC4_hdf5_filter_freelist(NC_VAR_INFO_T* var) NC4_hdf5_filter_freelist(NC_VAR_INFO_T* var)
{ {
int i, stat=NC_NOERR; int stat=NC_NOERR;
NClist* filters = (NClist*)var->filters; NClist* filters = (NClist*)var->filters;
if(filters == NULL) goto done; if(filters == NULL) goto done;
PRINTFILTERLIST(var,"free: before"); PRINTFILTERLIST(var,"free: before");
/* Free the filter list backward */ /* Free the filter list backward */
for(i=nclistlength(filters)-1;i>=0;i--) { for(size_t i = nclistlength(filters);i-->0;) {
struct NC_HDF5_Filter* spec = (struct NC_HDF5_Filter*)nclistremove(filters,i); struct NC_HDF5_Filter* spec = (struct NC_HDF5_Filter*)nclistremove(filters,i);
if(spec->nparams > 0) nullfree(spec->params); if(spec->nparams > 0) nullfree(spec->params);
nullfree(spec); nullfree(spec);
@ -312,11 +312,10 @@ done:
int int
NC4_hdf5_filter_remove(NC_VAR_INFO_T* var, unsigned int id) NC4_hdf5_filter_remove(NC_VAR_INFO_T* var, unsigned int id)
{ {
int k;
NClist* flist = (NClist*)var->filters; NClist* flist = (NClist*)var->filters;
/* Walk backwards */ /* Walk backwards */
for(k=nclistlength(flist)-1;k>=0;k--) { for(size_t k = nclistlength(flist); k-->0;) {
struct NC_HDF5_Filter* f = (struct NC_HDF5_Filter*)nclistget(flist,k); struct NC_HDF5_Filter* f = (struct NC_HDF5_Filter*)nclistget(flist,k);
if(f->filterid == id) { if(f->filterid == id) {
/* Remove from variable */ /* Remove from variable */

View File

@ -42,6 +42,10 @@ if(USE_HDF4)
) )
endif() endif()
if(FOUND_CURL)
target_link_libraries(netcdf PRIVATE CURL::libcurl)
endif()
if(NETCDF_ENABLE_DAP2) if(NETCDF_ENABLE_DAP2)
target_sources(netcdf target_sources(netcdf
PRIVATE PRIVATE
@ -144,7 +148,7 @@ if(USE_HDF5)
endif() endif()
if(FOUND_CURL) if(FOUND_CURL)
set(TLL_LIBS ${TLL_LIBS} ${CURL_LIBRARIES}) set(TLL_LIBS ${TLL_LIBS} CURL::libcurl ${CURL_LIBRARIES})
endif() endif()
if(USE_HDF4) if(USE_HDF4)

View File

@ -96,8 +96,7 @@ NCZ_compute_projections(struct Common* common, int r, size64_t chunkindex, cons
projection = &projections[n]; projection = &projections[n];
if(n > 0) { if(n > 0) {
/* Find last non-skipped projection */ /* Find last non-skipped projection */
int i; for(size_t i=n;i-->0;) { /* walk backward */
for(i=n-1;i>=0;i--) { /* walk backward */
if(!projections[i].skip) { if(!projections[i].skip) {
prev = &projections[i]; prev = &projections[i];
break; break;

View File

@ -423,12 +423,12 @@ done:
int int
NCZ_filter_remove(NC_VAR_INFO_T* var, unsigned int id) NCZ_filter_remove(NC_VAR_INFO_T* var, unsigned int id)
{ {
int k, stat = NC_NOERR; int stat = NC_NOERR;
NClist* flist = (NClist*)var->filters; NClist* flist = (NClist*)var->filters;
ZTRACE(6,"var=%s id=%u",var->hdr.name,id); ZTRACE(6,"var=%s id=%u",var->hdr.name,id);
/* Walk backwards */ /* Walk backwards */
for(k=nclistlength(flist)-1;k>=0;k--) { for(size_t k = nclistlength(flist); k-->0;) {
struct NCZ_Filter* f = (struct NCZ_Filter*)nclistget(flist,k); struct NCZ_Filter* f = (struct NCZ_Filter*)nclistget(flist,k);
if(f->hdf5.id == id) { if(f->hdf5.id == id) {
/* Remove from variable */ /* Remove from variable */
@ -896,9 +896,8 @@ fprintf(stderr,">>> next: alloc=%u used=%u buf=%p\n",(unsigned)next_alloc,(unsig
} }
} else { } else {
/* Apply in reverse order */ /* Apply in reverse order */
int k; for(size_t k=nclistlength(chain); k-->0;) {
for(k=(int)nclistlength(chain)-1;k>=0;k--) { f = (struct NCZ_Filter*)nclistget(chain, k);
f = (struct NCZ_Filter*)nclistget(chain,(size_t)k);
if(f->flags & FLAG_SUPPRESS) continue; /* this filter should not be applied */ if(f->flags & FLAG_SUPPRESS) continue; /* this filter should not be applied */
ff = f->plugin->hdf5.filter; ff = f->plugin->hdf5.filter;
/* code can be simplified */ /* code can be simplified */

View File

@ -42,6 +42,7 @@ ENDif (USE_FFIO)
if (NETCDF_ENABLE_BYTERANGE) if (NETCDF_ENABLE_BYTERANGE)
list(APPEND libsrc_SOURCES httpio.c) list(APPEND libsrc_SOURCES httpio.c)
if (NETCDF_ENABLE_S3) if (NETCDF_ENABLE_S3)
list(APPEND libsrc_SOURCES s3io.c) list(APPEND libsrc_SOURCES s3io.c)
endif(NETCDF_ENABLE_S3) endif(NETCDF_ENABLE_S3)
@ -55,6 +56,7 @@ endif()
if (NETCDF_ENABLE_BYTERANGE) if (NETCDF_ENABLE_BYTERANGE)
target_include_directories(netcdf3 PUBLIC ${CURL_INCLUDE_DIRS}) target_include_directories(netcdf3 PUBLIC ${CURL_INCLUDE_DIRS})
target_link_libraries(netcdf3 PUBLIC CURL::libcurl)
target_compile_options(netcdf3 target_compile_options(netcdf3
PRIVATE PRIVATE
-DCURL_STATICLIB=1 -DCURL_STATICLIB=1

View File

@ -1104,8 +1104,7 @@ odom_init(size_t rank, size_t* indices, size_t* dimsizes)
static void static void
odom_next(size_t rank, size_t* indices, size_t* dimsizes) odom_next(size_t rank, size_t* indices, size_t* dimsizes)
{ {
int i; for(size_t i = rank; i-->0;) {
for(i=rank-1;i>=0;i--) {
indices[i]++; indices[i]++;
if(indices[i] < dimsizes[i]) break; if(indices[i] < dimsizes[i]) break;
if(i > 0) indices[i] = 0; if(i > 0) indices[i] = 0;

View File

@ -15,7 +15,7 @@ endif()
if(STATUS_PARALLEL) if(STATUS_PARALLEL)
target_link_libraries(oc2 PUBLIC MPI::MPI_C) target_link_libraries(oc2 PUBLIC MPI::MPI_C)
endif(STATUS_PARALLEL) endif(STATUS_PARALLEL)
target_link_libraries(oc2 PUBLIC ${CURL_LIBRARIES}) target_link_libraries(oc2 PUBLIC CURL::libcurl ${CURL_LIBRARIES})
target_include_directories(oc2 PUBLIC ${CURL_INCLUDE_DIRS}) target_include_directories(oc2 PUBLIC ${CURL_INCLUDE_DIRS})
target_compile_options(oc2 target_compile_options(oc2
PRIVATE PRIVATE

View File

@ -490,8 +490,7 @@ ocarrayoffset(size_t rank, size_t* sizes, const size_t* indices)
void void
ocarrayindices(size_t index, size_t rank, size_t* sizes, size_t* indices) ocarrayindices(size_t index, size_t rank, size_t* sizes, size_t* indices)
{ {
int i; for(size_t i = rank; i-->0;) {
for(i=rank-1;i>=0;i--) {
indices[i] = index % sizes[i]; indices[i] = index % sizes[i];
index = (index - indices[i]) / sizes[i]; index = (index - indices[i]) / sizes[i];
} }