diff --git a/cf.cmake b/cf.cmake index 680bd2dbd..dcb842ba1 100644 --- a/cf.cmake +++ b/cf.cmake @@ -1,11 +1,13 @@ +# Visual Studio +#VS=1 + # Is netcdf-4 and/or DAP enabled? NC4=1 DAP=1 -#export CC=mpicc -export CC=gcc - +if test "x$VS" != x ; then FLAGS="-DCMAKE_PREFIX_PATH=c:/tools/nccmake" +fi FLAGS="$FLAGS -DCMAKE_INSTALL_PREFIX=d:/ignore" if test "x$DAP" = x ; then @@ -28,14 +30,22 @@ mkdir build cd build NCLIB=`pwd` -NCLIB="${NCLIB}/build/liblib" +if test "x$VS" != x ; then +# Visual Studio +#CFG="RelWithDebInfo" +CFG="Release" +NCLIB="${NCLIB}/build/liblib/$CFG" +export PATH="${NCLIB}:${PATH}" +cmake $FLAGS .. +cmake --build . --config ${CFG} +cmake --build . --config ${CFG} --target RUN_TESTS +else +# GCC +NCLIB="${NCLIB}/build/liblib" G="-GUnix Makefiles" cmake "${G}" $FLAGS .. -#cmake "${G}" --build . - -#cmake "${G}" --build . --target test make all -export PATH="${NCLIB}:${PATH}" make test +fi exit diff --git a/include/Makefile.am b/include/Makefile.am index f66103940..b51d7e5eb 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -19,7 +19,7 @@ nclist.h ncuri.h ncutf8.h ncdispatch.h ncdimscale.h \ netcdf_f.h err_macros.h ncbytes.h nchashmap.h ceconstraints.h rnd.h \ nclog.h ncconfigure.h nc4internal.h nctime.h nc3internal.h \ onstack.h nc_hashmap.h ncrc.h ncoffsets.h nctestserver.h \ -nc4dispatch.h nc3dispatch.h ncexternl.h +nc4dispatch.h nc3dispatch.h ncexternl.h ncwinpath.h if USE_DAP noinst_HEADERS += ncdap.h diff --git a/include/ncuri.h b/include/ncuri.h index b75d2da40..62e27392b 100644 --- a/include/ncuri.h +++ b/include/ncuri.h @@ -85,9 +85,6 @@ extern char* ncuriencode(char* s, char* allowable); extern char* ncuridecode(char* s); extern char* ncuridecodeonly(char* s, char*); -/* path converter; caller frees result */ -extern char* NCpathcvt(const char* path); - #if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__) || defined(__CPLUSPLUS) } #endif diff --git a/include/ncwinpath.h b/include/ncwinpath.h new file mode 100644 index 000000000..09600111b --- /dev/null +++ b/include/ncwinpath.h @@ -0,0 +1,35 @@ +/* + * Copyright 1996, University Corporation for Atmospheric Research + * See netcdf/COPYRIGHT file for copying and redistribution conditions. + */ +#ifndef _NCWINIO_H_ +#define _NCWINIO_H_ + +#include "config.h" +#include +#include +#include "ncexternl.h" + +#ifdef _MSC_VER +#define WINPATH 1 +#endif +#ifdef __MINGW32__ +#define WINPATH 1 +#endif + + +/* path converter */ +EXTERNL char* NCpathcvt(const char* path); + +#ifdef WINPATH +/* path converter wrappers*/ +EXTERNL FILE* NCfopen(const char* path, const char* flags); +EXTERNL int NCopen3(const char* path, int flags, int mode); +EXTERNL int NCopen2(const char* path, int flags); +#else /*!WINPATH*/ +#define NCfopen(path,flags) fopen((path),(flags)) +#define NCopen3(path,flags,mode) open((path),(flags),(mode)) +#define NCopen2(path,flags) open((path),(flags)) +#endif /*WINPATH*/ + +#endif /* _NCWINIO_H_ */ diff --git a/libdap4/d4read.c b/libdap4/d4read.c index 91609965b..e3b02c599 100644 --- a/libdap4/d4read.c +++ b/libdap4/d4read.c @@ -3,6 +3,9 @@ #ifdef HAVE_FCNTL_H #include #endif +#include "ncwinpath.h" + +/* Do conversion if this code was compiled via Vis. Studio or Mingw */ /*Forward*/ static int readpacket(NCD4INFO* state, NCURI*, NCbytes*, NCD4mode, long*); @@ -164,20 +167,12 @@ readfile(const NCURI* uri, const char* suffix, NCbytes* packet) #ifdef O_BINARY flags |= O_BINARY; #endif - fprintf(stderr,"XXXX: d4read.c(line %d) open: path=|%s|\n",__LINE__,filename); fflush(stderr); - { -#ifdef _WIN32 - char* cvtname = NCpathcvt(filename); - if(cvtname == NULL) {stat = NC_ENOMEM; goto done;} - fd = open(cvtname,flags); - free(cvtname); -#else - fd = open(filename,flags); -#endif - } +fprintf(stderr,"XXX: flags=0x%x file=%s\n",flags,filename); + fd = NCopen2(filename,flags); if(fd < 0) { nclog(NCLOGERR,"open failed:%s",filename); - fprintf(stderr,"XXX: open failed: flags=0x%x file=%s\n",flags,filename); fflush(stderr); + fprintf(stderr,"XXX: open failed: flags=0x%x file=%s\n",flags,filename); + fflush(stderr); stat = NC_ENOTFOUND; goto done; } diff --git a/libdispatch/CMakeLists.txt b/libdispatch/CMakeLists.txt index a086d7fc5..4a2536e8b 100644 --- a/libdispatch/CMakeLists.txt +++ b/libdispatch/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(libdispatch_SOURCES dparallel.c dcopy.c dfile.c ddim.c datt.c dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c dvarinq.c ddispatch.c nclog.c dstring.c dutf8.c dinternal.c doffsets.c ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c nc.c nclistmgr.c utf8proc.h utf8proc.c) +SET(libdispatch_SOURCES dparallel.c dcopy.c dfile.c ddim.c datt.c dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c dvarinq.c ddispatch.c nclog.c dstring.c dutf8.c dinternal.c doffsets.c ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c nc.c nclistmgr.c utf8proc.h utf8proc.c dwinpath.c) IF(USE_NETCDF4) SET(libdispatch_SOURCES ${libdispatch_SOURCES} dgroup.c dvlen.c dcompound.c dtype.c denum.c dopaque.c ncaux.c) diff --git a/libdispatch/Makefile.am b/libdispatch/Makefile.am index faf05fd83..42d868c52 100644 --- a/libdispatch/Makefile.am +++ b/libdispatch/Makefile.am @@ -20,7 +20,7 @@ dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c \ dvarinq.c dinternal.c ddispatch.c dutf8.c \ nclog.c dstring.c \ ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c \ -nc.c nclistmgr.c drc.c doffsets.c +nc.c nclistmgr.c drc.c doffsets.c dwinpath.c # Add the utf8 codebase libdispatch_la_SOURCES += utf8proc.c utf8proc.h @@ -65,7 +65,9 @@ ncsettings.c: $(top_srcdir)/libnetcdf.settings ncsettings.hdr cat >> ncsettings.c echo ';' >> ncsettings.c -# Unit test for ncuri +# Unit tests test_ncuri_SOURCES = test_ncuri.c ncuri.c ncbytes.c nclist.c -check_PROGRAMS = test_ncuri -TESTS = test_ncuri +test_pathcvt_SOURCES = test_pathcvt.c dwinpath.c +check_PROGRAMS = test_ncuri test_pathcvt +TESTS = test_ncuri test_pathcvt + diff --git a/libdispatch/dfile.c b/libdispatch/dfile.c index 822d54b3a..bb15dbb0c 100644 --- a/libdispatch/dfile.c +++ b/libdispatch/dfile.c @@ -22,11 +22,11 @@ Research/Unidata. See COPYRIGHT file for more info. #endif #include "ncdispatch.h" #include "netcdf_mem.h" +#include "ncwinpath.h" extern int NC_initialized; extern int NC_finalized; - /** \defgroup datasets NetCDF File and Data I/O NetCDF opens datasets as files or remote access URLs. @@ -1632,7 +1632,7 @@ stored. \returns ::NC_NOERR No error. */ int -NC_create(const char *path, int cmode, size_t initialsz, +NC_create(const char *path0, int cmode, size_t initialsz, int basepe, size_t *chunksizehintp, int useparallel, void* parameters, int *ncidp) { @@ -1643,10 +1643,10 @@ NC_create(const char *path, int cmode, size_t initialsz, int model = NC_FORMATX_UNDEFINED; /* one of the NC_FORMATX values */ int isurl = 0; /* dap or cdmremote or neither */ int xcmode = 0; /* for implied cmode flags */ - char* newpath = NULL; + char* path = NULL; TRACE(nc_create); - if(path == NULL) + if(path0 == NULL) return NC_EINVAL; /* Initialize the dispatch table. The function pointers in the * dispatch table will depend on how netCDF was built @@ -1657,17 +1657,32 @@ NC_create(const char *path, int cmode, size_t initialsz, return stat; } +#ifdef WINPATH + /* Need to do path conversion */ + path = NCpathcvt(path0); +fprintf(stderr,"XXX: path0=%s path=%s\n",path0,path); fflush(stderr); +#else + path = nulldup(path0); +#endif + #ifdef USE_REFCOUNT /* If this path is already open, then fail */ ncp = find_in_NCList_by_name(path); - if(ncp != NULL) + if(ncp != NULL) { + nullfree(path); return NC_ENFILE; + } #endif - model = NC_urlmodel(path,cmode,&newpath); - isurl = (model != 0); - if(!isurl) - newpath = strdup(path); + { + char* newpath = NULL; + model = NC_urlmodel(path,cmode,&newpath); + isurl = (model != 0); + if(isurl) { + nullfree(path); + path = newpath; + } + } /* Look to the incoming cmode for hints */ if(model == NC_FORMATX_UNDEFINED) { @@ -1746,8 +1761,8 @@ NC_create(const char *path, int cmode, size_t initialsz, } /* Create the NC* instance and insert its dispatcher */ - stat = new_NC(dispatcher,newpath,cmode,&ncp); - nullfree(newpath); newpath = NULL; /* no longer needed */ + stat = new_NC(dispatcher,path,cmode,&ncp); + nullfree(path); path = NULL; /* no longer needed */ if(stat) return stat; @@ -1800,7 +1815,7 @@ NC_open(const char *path0, int cmode, int isurl = 0; int version = 0; int flags = 0; - char* path = nulldup(path0); + char* path = NULL; TRACE(nc_open); if(!NC_initialized) { @@ -1808,10 +1823,19 @@ NC_open(const char *path0, int cmode, if(stat) return stat; } +#ifdef WINPATH + /* Need to do path conversion */ + path = NCpathcvt(path0); +fprintf(stderr,"XXX: path0=%s path=%s\n",path0,path); fflush(stderr); +#else + path = nulldup(path0); +#endif + #ifdef USE_REFCOUNT /* If this path is already open, then bump the refcount and return it */ ncp = find_in_NCList_by_name(path); if(ncp != NULL) { + nullfree(path); ncp->refcount++; if(ncidp) *ncidp = ncp->ext_ncid; return NC_NOERR; @@ -1825,7 +1849,8 @@ NC_open(const char *path0, int cmode, if(isurl) { nullfree(path); path = newpath; - } + } else + nullfree(newpath); } if(model == 0) { version = 0; diff --git a/libdispatch/dwinpath.c b/libdispatch/dwinpath.c new file mode 100644 index 000000000..659533620 --- /dev/null +++ b/libdispatch/dwinpath.c @@ -0,0 +1,154 @@ +/* + * Copyright 1996, University Corporation for Atmospheric Research + * See netcdf/COPYRIGHT file for copying and redistribution conditions. + */ + +#include "config.h" +#include +#include +#include +#include +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef _MSC_VER +#include +#endif + +#include "ncexternl.h" +#include "ncwinpath.h" + +/* +Code to provide some path conversion code so that +cygwin and (some) mingw paths can be passed to open/fopen +for Windows. Other cases will be added as needed. +Rules: +1. a leading single alpha-character path element (e.g. /D/...) + will be interpreted as a windows drive letter. +2. a leading '/cygdrive/X' will be converted to + a drive letter X if X is alpha-char. +3. a leading D:/... is treated as a windows drive letter +4. If #1, #2, or #3 is encounterd, then forward slashes + will be converted to backslashes. +5. All other cases are passed thru unchanged +*/ + +/* Define legal windows drive letters */ +static char* windrive = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +static size_t cdlen = 10; /* strlen("/cygdrive/") */ + +EXTERNL +char* /* caller frees */ +NCpathcvt(const char* path) +{ + char* outpath = NULL; + char* p; + char* q; + size_t pathlen; + + if(path == NULL) return NULL; /* defensive driving */ + pathlen = strlen(path); + + /* 1. look for MSYS path /D/... */ + if(pathlen >= 2 + && (path[0] == '/' || path[0] == '\\') + && strchr(windrive,path[1]) != NULL + && (path[2] == '/' || path[2] == '\\' || path[2] == '\0')) { + /* Assume this is a mingw path */ + outpath = (char*)malloc(pathlen+3); /* conservative */ + if(outpath == NULL) return NULL; + q = outpath; + *q++ = path[1]; + *q++ = ':'; + strncpy(q,&path[2],pathlen); + if(strlen(outpath) == 2) + strcat(outpath,"/"); + goto slashtrans; + } + + /* 2. Look for leading /cygdrive/D where D is a single-char drive letter */ + if(pathlen >= (cdlen+1) + && memcmp(path,"/cygdrive/",cdlen)==0 + && strchr(windrive,path[cdlen]) != NULL + && (path[cdlen+1] == '/' + || path[cdlen+1] == '\\' + || path[cdlen+1] == '\0')) { + /* Assume this is a cygwin path */ + outpath = (char*)malloc(pathlen+1); /* conservative */ + if(outpath == NULL) return NULL; + outpath[0] = path[cdlen]; + outpath[1] = ':'; + strcpy(&outpath[2],&path[cdlen+1]); + if(strlen(outpath) == 2) + strcat(outpath,"/"); + goto slashtrans; + } + + /* 3. Look for leading D: where D is a single-char drive letter */ + if(pathlen >= 2 + && strchr(windrive,path[0]) != NULL + && path[1] == ':' + && (path[2] == '\0' || path[2] == '/' || path[2] == '\\')) { + outpath = strdup(path); + goto slashtrans; + } + + /* 4. Other: just pass thru */ + outpath = strdup(path); + goto done; + +slashtrans: + /* In all #1 or #2 cases, translate '/' -> '\\' */ + p = outpath; + for(;*p;p++) { + if(*p == '/') {*p = '\\';} + } +done: + return outpath; +} + +#ifdef WINPATH + +/* +Provide wrappers for open and fopen. +*/ + +EXTERNL +FILE* +NCfopen(const char* path, const char* flags) +{ + FILE* f = NULL; + char* cvtname = NCpathcvt(path); +fprintf(stderr,"XXXX: path=|%s| cvtpath=|%s|\n",path,cvtname?cvtname:"null"); +fflush(stderr); + if(cvtname == NULL) return NULL; + f = fopen(cvtname,flags); + free(cvtname); + return f; +} + +EXTERNL +int +NCopen3(const char* path, int flags, int mode) +{ + int fd = -1; + fprintf(stderr,"XXXX: path=|%s|\n",path); + fflush(stderr); + char* cvtname = NCpathcvt(path); + fprintf(stderr,"XXXX: path=|%s| cvtpath=|%s|\n",path,cvtname?cvtname:"null"); + fflush(stderr); + if(cvtname == NULL) return -1; + fd = open(cvtname,flags,mode); + free(cvtname); + return fd; +} + +EXTERNL +int +NCopen2(const char *path, int flags) +{ + return NCopen3(path,flags,0); +} + +#endif /*WINPATH*/ diff --git a/libdispatch/ncuri.c b/libdispatch/ncuri.c index 32efdceb0..2d922cef3 100644 --- a/libdispatch/ncuri.c +++ b/libdispatch/ncuri.c @@ -912,81 +912,3 @@ parselist(char* ptext, NClist* list) } return ret; } - -/**************************************************/ -/**************************************************/ -/* -Code to provide some path conversion code so that -paths extracted from URLs can be passed to open/fopen -for Windows. Other cases will be added as needed. -Assumptions: -1. a leading single alpha-character path element - will be interpreted as a windows drive letter. -2. a leading '/cygdrive/X' will be converted to - a drive letter X if X is alpha-char. -3. Forward slashes will be converted to backslashes. -*/ - -/* Define legal windows drive letters */ -static char* windrive = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - -static size_t cdlen = 10; /* strlen("/cygdrive/") */ - -char* /* caller frees */ -NCpathcvt(const char* path) -{ - char* outpath = NULL; - char* p; - char* q; - size_t pathlen; - - if(path == NULL) return NULL; /* defensive driving */ - pathlen = strlen(path); - - /* 1. look for MSYS path /D/... */ - if(pathlen >= 2 - && (path[0] == '/' || path[0] == '\\') - && strchr(windrive,path[1]) != NULL - && (path[2] == '/' || path[2] == '\\' || path[2] == '\0')) { - /* Assume this is a mingw path */ - outpath = (char*)malloc(pathlen+3); /* conservative */ - if(outpath == NULL) return NULL; - q = outpath; - *q++ = path[1]; - *q++ = ':'; - strncpy(q,&path[2],pathlen); - if(strlen(outpath) == 2) - strcat(outpath,"/"); - goto slashtrans; - } - - /* 2. Look for leading /cygdrive/D where D is a single-char drive letter */ - if(pathlen >= (cdlen+1) - && memcmp(path,"/cygdrive/",cdlen)==0 - && strchr(windrive,path[cdlen]) != NULL - && (path[cdlen+1] == '/' - || path[cdlen+1] == '\\' - || path[cdlen+1] == '\0')) { - /* Assume this is a cygwin path */ - outpath = (char*)malloc(pathlen+1); /* conservative */ - if(outpath == NULL) return NULL; - outpath[0] = path[cdlen]; - outpath[1] = ':'; - strcpy(&outpath[2],&path[cdlen+1]); - if(strlen(outpath) == 2) - strcat(outpath,"/"); - goto slashtrans; - } - - /* 3. Other: just pass thru */ - outpath = strdup(path); - if(outpath == NULL) return NULL; - -slashtrans: - /* In all cases, translate '/' -> '\\' */ - p = outpath; - for(;*p;p++) { - if(*p == '/') {*p = '\\';} - } - return outpath; -} diff --git a/libdispatch/test_ncuri.c b/libdispatch/test_ncuri.c index 3eac1b3c9..dcf9ad340 100644 --- a/libdispatch/test_ncuri.c +++ b/libdispatch/test_ncuri.c @@ -12,8 +12,6 @@ Test the ncuri parsing #include #include "ncuri.h" -#define WINDEBUG 1 - typedef struct Test { char* url; char* expected; @@ -52,17 +50,6 @@ static char* XTESTS[] = { NULL }; -/* Path conversion tests */ -static Test PATHTESTS[] = { -{"/xxx/a/b","\\xxx\\a\\b"}, -{"d:/x/y","d:\\x\\y"}, -{"/cygdrive/d/x/y","d:\\x\\y"}, -{"/d/x/y","d:\\x\\y"}, -{"/cygdrive/d","d:\\"}, -{"/d","d:\\"}, -{NULL,NULL} -}; - int main(int argc, char** argv) { @@ -103,22 +90,6 @@ main(int argc, char** argv) } } -#if defined(_WIN32) || defined(WINDEBUG) - for(test=PATHTESTS;test->url;test++) { - int ret = 0; - char* cvt = NCpathcvt(test->url); - if(cvt == NULL) { - fprintf(stderr,"TEST returned NULL: %s\n",test->url); - exit(1); - } - if(strcmp(cvt,test->expected) != 0) { - fprintf(stderr,"NCpathcvt failed:: input: |%s| expected=|%s| actual=|%s|\n",test->url,test->expected,cvt); - failcount++; - } - free(cvt); - } -#endif /* _WIN32 */ - fprintf(stderr,"%s test_ncuri\n",failcount > 0 ? "***FAIL":"***PASS"); return (failcount > 0 ? 1 : 0); } diff --git a/libdispatch/test_pathcvt.c b/libdispatch/test_pathcvt.c new file mode 100644 index 000000000..14959d6ce --- /dev/null +++ b/libdispatch/test_pathcvt.c @@ -0,0 +1,61 @@ +/********************************************************************* + * Copyright 2016, UCAR/Unidata + * See netcdf/COPYRIGHT file for copying and redistribution conditions. + *********************************************************************/ + +/** +Test the NCpathcvt +*/ + +#include +#include +#include +#include "ncwinpath.h" + +#undef WINDEBUG +#undef VERBOSE + +typedef struct Test { + char* path; + char* expected; +} Test; + +/* Path conversion tests */ +static Test PATHTESTS[] = { +{"/xxx/a/b","/xxx/a/b"}, +{"d:/x/y","d:\\x\\y"}, +{"/cygdrive/d/x/y","d:\\x\\y"}, +{"/d/x/y","d:\\x\\y"}, +{"/cygdrive/d","d:\\"}, +{"/d","d:\\"}, +{"/cygdrive/d/git/netcdf-c/dap4_test/daptestfiles/test_anon_dim.2.syn","d:\\git\\netcdf-c\\dap4_test\\daptestfiles\\test_anon_dim.2.syn"}, +{"[dap4]file:///cygdrive/d/git/netcdf-c/dap4_test/daptestfiles/test_anon_dim.2.syn","[dap4]file:///cygdrive/d/git/netcdf-c/dap4_test/daptestfiles/test_anon_dim.2.syn"}, +{NULL,NULL} +}; + +int +main(int argc, char** argv) +{ + Test* test; + int failcount = 0; + + for(test=PATHTESTS;test->path;test++) { + int ret = 0; + char* cvt = NCpathcvt(test->path); + if(cvt == NULL) { + fprintf(stderr,"TEST returned NULL: %s\n",test->path); + exit(1); + } + if(strcmp(cvt,test->expected) != 0) { + fprintf(stderr,"NCpathcvt failed:: input: |%s| expected=|%s| actual=|%s|\n",test->path,test->expected,cvt); + failcount++; + } +#ifdef VERBOSE + fprintf(stderr,"NCpathcvt:: input: |%s| actual=|%s|\n",test->path,cvt); +#endif + free(cvt); + } + + fprintf(stderr,"%s test_ncuri\n",failcount > 0 ? "***FAIL":"***PASS"); + return (failcount > 0 ? 1 : 0); +} diff --git a/libsrc4/nc4file.c b/libsrc4/nc4file.c index 6d1a6e6c8..c00809712 100644 --- a/libsrc4/nc4file.c +++ b/libsrc4/nc4file.c @@ -45,8 +45,9 @@ extern int num_spaces; #define MIN_DEFLATE_LEVEL 0 #define MAX_DEFLATE_LEVEL 9 -static int -read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att); +/*Forward*/ +static int read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att); +static void hdf5free(void* memory); /* Custom iteration callback data */ typedef struct { @@ -1399,27 +1400,11 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name) break; } -#ifndef JNA - - /* Free the member name (which HDF5 allocated for us). */ - /* On Windows using the microsoft runtime, it is an error - for one library to free memory allocated by a different library. - IF it is available, we should use H5free_memory*/ - -#ifdef HDF5_HAS_H5FREE - if(member_name != NULL) H5free_memory(member_name); -#else -#ifndef _MSC_VER - if(member_name != NULL) free(member_name); -#endif -#endif -#endif + hdf5free(member_name); member_name = NULL; } -#ifndef JNA - if(member_name != NULL) - free(member_name); -#endif + hdf5free(member_name); + member_name = NULL; if(retval) /* error exit from loop */ return retval; } @@ -1543,17 +1528,11 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name) break; } -#ifndef JNA - /* Free the member name (which HDF5 allocated for us). */ - if(member_name != NULL) free(member_name); -#endif + hdf5free(member_name); member_name = NULL; } - -#ifndef JNA - if(member_name != NULL) - free(member_name); -#endif + hdf5free(member_name); + member_name = NULL; if(value) free(value); if(retval) /* error exit from loop */ return retval; @@ -3342,3 +3321,24 @@ nc_use_parallel_enabled() return 0; } #endif /* USE_PARALLEL4 */ + + +/* +Wrap HDF5 allocated memory free operations +*/ + +static void +hdf5free(void* memory) +{ +#ifndef JNA + /* On Windows using the microsoft runtime, it is an error + for one library to free memory allocated by a different library.*/ +#ifdef HDF5_HAS_H5FREE + if(memory != NULL) H5free_memory(memory); +#else +#ifndef _MSC_VER + if(memory != NULL) free(memory); +#endif +#endif +#endif +} diff --git a/ncdump/ncdump.c b/ncdump/ncdump.c index 2cf1da264..bbaba37e1 100644 --- a/ncdump/ncdump.c +++ b/ncdump/ncdump.c @@ -46,6 +46,7 @@ int optind; #include "isnan.h" #include "cdl.h" #include "nclog.h" +#include "ncwinpath.h" #ifdef USE_NETCDF4 #include "nc4internal.h" /* to get name of the special properties file */ @@ -339,7 +340,7 @@ fileopen(const char* path, void** memp, size_t* sizep) #ifdef vms fd = open(path, oflags, 0, "ctx=stm"); #else - fd = open(path, oflags); + fd = NCopen2(path, oflags); #endif if(fd < 0) { status = errno; diff --git a/ncgen/main.c b/ncgen/main.c index e26b5c5ba..50cb65e4d 100644 --- a/ncgen/main.c +++ b/ncgen/main.c @@ -7,6 +7,7 @@ #include "includes.h" #include "ncoffsets.h" +#include "ncwinpath.h" #ifdef HAVE_GETOPT_H #include #endif @@ -453,7 +454,7 @@ main( if (argc > 0 && strcmp(argv[0], "-") != 0) { char bom[4]; size_t count; - if ((fp = fopen(argv[0], "r")) == NULL) { + if ((fp = NCfopen(argv[0], "r")) == NULL) { derror ("can't open file %s for reading: ", argv[0]); perror(""); return(7); diff --git a/ncgen3/main.c b/ncgen3/main.c index da8bb91d4..2e035fe15 100644 --- a/ncgen3/main.c +++ b/ncgen3/main.c @@ -26,7 +26,8 @@ int optind; #include #endif -#include +#include "netcdf.h" +#include "ncwinpath.h" #include "generic.h" #include "ncgen.h" @@ -229,7 +230,7 @@ main( fp = stdin; if (argc > 0 && strcmp(argv[0], "-") != 0) { - if ((fp = fopen(argv[0], "r")) == NULL) { + if ((fp = NCfopen(argv[0], "r")) == NULL) { derror ("can't open file %s for reading: ", argv[0]); perror(""); return(7); diff --git a/nctest/atttests.c b/nctest/atttests.c index f9fe7f264..6cd41bcea 100644 --- a/nctest/atttests.c +++ b/nctest/atttests.c @@ -698,9 +698,6 @@ test_ncattcopy(path1, path2) error("%s: ncendef failed", pname); ncclose(cdfid); return ++nerrs; } -if(strcmp(path1, "nctest_netcdf4.nc")==0) { -int x=0; -} /* first (source) netcdf is in data mode */ /* create second netCDF to copy attributes to */ if ((cdfid2 = nccreate(path2, NC_CLOBBER)) == -1) {