Skip to content

Commit 9b9c170

Browse files
authored
Merge pull request #3182 from DennisHeimbigner/manyurls.dmh
Fix the problems around ncdap_test/test_manyurls.c.
2 parents a18605f + 6037385 commit 9b9c170

File tree

8 files changed

+53
-31
lines changed

8 files changed

+53
-31
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release
77

88
## 4.10.0 - TBD
99

10+
* Fix the problems around ncdap_test/test_manyurls.c. See [Github ????](https://github.com/Unidata/netcdf-c/issues/????) for more information.
1011
* Fix bug in ncdump when printing FQNs ([Issue 3184](https://github.com/Unidata/netcdf-c/issues/3184)). See [Github ????](https://github.com/Unidata/netcdf-c/issues/????) for more information.
1112
* Update `macOS` github runners from macos-13 to macos-14, due to deprecation.
1213
* Fix an error compiling netCDF with AWS-S3-SDK support using cmake. See [Github 3155](https://github.com/Unidata/netcdf-c/issues/3155) for more information.

config.h.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ are set when opening a binary file on Windows. */
148148
/* if true, build DAP4 Client */
149149
#cmakedefine NETCDF_ENABLE_DAP4 1
150150

151+
/* if true, do long dap tests */
152+
#cmakedefine NETCDF_ENABLE_DAP_LONG_TESTS 1
153+
151154
/* if true, do remote tests */
152155
#cmakedefine NETCDF_ENABLE_DAP_REMOTE_TESTS 1
153156

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,10 @@ AC_ARG_ENABLE([dap-long-tests],
734734
[enable dap long tests])])
735735
test "x$enable_dap_long_tests" = xyes || enable_dap_long_tests=no
736736
AC_MSG_RESULT([$enable_dap_long_tests])
737+
if test "x$enable_dap_long_tests" = xyes; then
738+
AC_DEFINE([NETCDF_ENABLE_DAP_LONG_TESTS], [1], [if true, execute long dap tests])
739+
fi
740+
737741
if test "x$enable_dap_remote_tests" = "xno" || test "x$enable_external_server_tests" = "xno" ; then
738742
AC_MSG_NOTICE([--disable-dap-remote|external-server-tests => --disable_dap_long_tests])
739743
enable_dap_long_tests=no

libdispatch/nclist.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,30 @@ nclistclearall(NClist* l)
9393
return TRUE;
9494
}
9595

96+
/*
97+
Set allocated memory to newalloc elements.
98+
If newalloc is zero, then just guarantee that l->content has memory allocated.
99+
*/
96100
int
97-
nclistsetalloc(NClist* l, size_t sz)
101+
nclistsetalloc(NClist* l, size_t newalloc)
98102
{
99103
void** newcontent = NULL;
104+
size_t alloc;
100105
if(l == NULL) return nclistfail();
101-
if(sz <= 0) {sz = (l->length?2*l->length:DEFAULTALLOC);}
102-
if(l->alloc >= sz) {return TRUE;}
103-
newcontent=(void**)calloc(sz,sizeof(void*));
104-
if(newcontent != NULL && l->alloc > 0 && l->length > 0 && l->content != NULL) {
106+
if(newalloc == 0) newalloc = DEFAULTALLOC; /* force newalloc to be greater than 0 */
107+
if(l->alloc >= newalloc) {return TRUE;} /* already enough space */
108+
/* Iterate to find an allocation greater or equal to newalloc */
109+
alloc = l->alloc;
110+
while(alloc < newalloc)
111+
alloc = (2*alloc + 1); /* Double until we have a suitable allocation; +1 in case alloc is zero*/
112+
newcontent=(void**)calloc(alloc,sizeof(void*));
113+
if(newcontent == NULL) return nclistfail(); /* out of memory */
114+
/* Copy data, if any, to new contents */
115+
if(l->alloc > 0 && l->length > 0 && l->content != NULL)
105116
memcpy((void*)newcontent,(void*)l->content,sizeof(void*)*l->length);
106-
}
107-
if(l->content != NULL) free(l->content);
108-
l->content=newcontent;
109-
l->alloc=sz;
117+
if(l->content != NULL) free(l->content); /* reclaim old contents */
118+
l->content = newcontent;
119+
l->alloc = alloc;
110120
return TRUE;
111121
}
112122

@@ -167,9 +177,9 @@ int
167177
nclistpush(NClist* l, const void* elem)
168178
{
169179
if(l == NULL) return nclistfail();
170-
if(l->length >= l->alloc) nclistsetalloc(l,0);
171180
if(l->content == NULL)
172181
nclistsetalloc(l,0);
182+
if(l->length >= l->alloc) nclistsetalloc(l,l->length+1);
173183
l->content[l->length] = (void*)elem;
174184
l->length++;
175185
return TRUE;
@@ -313,10 +323,10 @@ nclistextract(NClist* l)
313323
{
314324
void* result = NULL;
315325
if(l) {
316-
result = l->content;
317-
l->alloc = 0;
318-
l->length = 0;
319-
l->content = NULL;
326+
result = l->content;
327+
l->alloc = 0;
328+
l->length = 0;
329+
l->content = NULL;
320330
}
321331
return result;
322332
}

libsrc/httpio.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ typedef struct NCHTTP {
4747
NC_HTTP_STATE* state;
4848
long long size; /* of the object */
4949
NCbytes* interval;
50+
int verbose;
5051
} NCHTTP;
5152

5253
/* Forward */
@@ -92,6 +93,8 @@ httpio_new(const char* path, int ioflags, ncio** nciopp, NCHTTP** hpp)
9293
if(http == NULL) {status = NC_ENOMEM; goto fail;}
9394
*((void* *)&nciop->pvt) = http;
9495

96+
http->verbose = (getenv("CURLOPT_VERBOSE") == NULL ? 0 : 1);
97+
9598
if(nciopp) *nciopp = nciop;
9699
if(hpp) *hpp = http;
97100

@@ -172,7 +175,7 @@ httpio_open(const char* path,
172175
/* Create private data */
173176
if((status = httpio_new(path, ioflags, &nciop, &http))) goto done;
174177
/* Open the path and get curl handle and object size */
175-
if((status = nc_http_open(path,&http->state))) goto done;
178+
if((status = nc_http_open_verbose(path,http->verbose,&http->state))) goto done;
176179
if((status = nc_http_size(http->state,&http->size))) goto done;
177180

178181
sizehint = pagesize;

nc_test4/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ endif
4444
NC4_TESTS += tst_h_strbug tst_h_refs
4545

4646
# Build test programs plus programs used in test scripts.
47-
check_PROGRAMS = $(NC4_TESTS) tst_empty_vlen_unlim tst_charvlenbug \
47+
check_PROGRAMS = $(NC4_TESTS) tst_empty_vlen_unlim tst_charvlenbug \
4848
tst_vlenstr tst_zero_len_att
4949
TESTS = $(NC4_TESTS) run_empty_vlen_test.sh run_zero_len_att_test.sh
5050
XFAIL_TESTS =

ncdap_test/Makefile.am

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ TESTS += tst_longremote3.sh
6464
tst_longremote3.log: tst_remote3.log
6565
endif
6666

67-
if NETCDF_ENABLE_DAP_LONG_TESTS
68-
test_manyurls_SOURCES = test_manyurls.c manyurls.h
69-
test_manyurls.log: tst_longremote3.log
70-
TESTS += test_manyurls
71-
endif
67+
# This test how many urls we can have open at one time, but it is basically useless, so disable it */
68+
#if NETCDF_ENABLE_DAP_LONG_TESTS
69+
#check_PROGRAMS += test_manyurls
70+
#TESTS += test_manyurls
71+
#test_manyurls_SOURCES = test_manyurls.c manyurls.h
72+
#test_manyurls.log: tst_longremote3.log
73+
#endif
7274

7375
test_partvar_SOURCES = test_partvar.c
7476

ncdap_test/test_manyurls.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
#include "manyurls.h"
77

8-
#undef VERBOSE
8+
/* Turn on to verify that all the URLS in manyurls.h are valid */
9+
#undef VERIFY
910

1011
int main()
1112
{
@@ -16,24 +17,22 @@ int main()
1617
char* tp = *p;
1718
int mode = 0;
1819
int status = -1;
19-
#ifdef VERBOSE
20-
printf("Opening: %s\n",tp);
21-
#endif
20+
printf("Testing: %s\n",tp);
2221
status = nc_open(tp, mode, &ncid);
2322
switch(status) {
2423
case NC_NOERR:
2524
break;
2625
case NC_ENOTFOUND:
27-
#ifdef VERBOSE
28-
printf("{%d} %s\n",i,tp);
29-
#endif
26+
printf("Warning: notfound: {%d} %s\n",i,tp);
3027
status = NC_NOERR;
3128
break;
3229
default:
33-
fprintf(stderr,"*** %s\n",nc_strerror(status));
34-
return 1;
30+
printf("Failure: %s\n",nc_strerror(status));
31+
break;
3532
}
36-
// nc_close(ncid);
33+
#ifdef VERIFY
34+
nc_close(ncid); /* Do not close to see how many urls we can keep open */
35+
#endif
3736
}
3837
return 0;
3938
}

0 commit comments

Comments
 (0)