From cb56d5af3880b5c8dbb3903225d3d2413a9dba34 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Tue, 24 Aug 2021 16:27:26 +1000 Subject: [PATCH 1/8] Avoid redefinition of strcasecmp in mingw-w64 --- config.h.cmake.in | 4 ++-- configure.ac | 2 +- libdispatch/ncjson.c | 2 +- libdispatch/nclist.c | 2 +- ncgen/ncgen.h | 2 ++ 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/config.h.cmake.in b/config.h.cmake.in index b7a4c0bfe..622e094ad 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -57,7 +57,7 @@ are set when opening a binary file on Windows. */ #define _OFF_T_DEFINED #endif - #ifdef _WIN32 + #if defined(_WIN32) && !defined(__MINGW32__) #ifndef strcasecmp #define strcasecmp _stricmp #endif @@ -656,7 +656,7 @@ with zip */ #cmakedefine uintptr_t unsigned long /* Define strcasecmp, strncasecmp, snprintf on Win32 systems. */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #ifndef HAVE_STRCASECMP #define strcasecmp _stricmp #endif diff --git a/configure.ac b/configure.ac index 2206b9225..eb91a064a 100644 --- a/configure.ac +++ b/configure.ac @@ -1655,7 +1655,7 @@ AC_SUBST(HAS_LOGGING,[$enable_logging]) #AH_VERBATIM([_WIN32_STRICMP], AH_BOTTOM( [/* Define strcasecmp, strncasecmp, snprintf on Win32 systems. */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define strcasecmp _stricmp #define strncasecmp _strnicmp #define snprintf _snprintf diff --git a/libdispatch/ncjson.c b/libdispatch/ncjson.c index 1cca2132e..0ee47d940 100644 --- a/libdispatch/ncjson.c +++ b/libdispatch/ncjson.c @@ -14,7 +14,7 @@ TODO: make utf8 safe #include #include "ncjson.h" -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define strcasecmp _stricmp #else #include diff --git a/libdispatch/nclist.c b/libdispatch/nclist.c index 3d45d92a9..83153db2e 100644 --- a/libdispatch/nclist.c +++ b/libdispatch/nclist.c @@ -6,7 +6,7 @@ #include "nclist.h" -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define strcasecmp _stricmp #endif diff --git a/ncgen/ncgen.h b/ncgen/ncgen.h index e93f4627b..c2eac3a40 100644 --- a/ncgen/ncgen.h +++ b/ncgen/ncgen.h @@ -9,8 +9,10 @@ #ifdef _WIN32 #include #include "isnan.h" +#ifndef __MINGW32__ #define strcasecmp _stricmp #endif +#endif #ifdef USE_NETCDF4 #define CLASSICONLY 0 From 7b3d71b7189b4f81da812e144d6db9e0ab7cf531 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 5 Sep 2021 17:13:23 +1000 Subject: [PATCH 2/8] Define strcasecmp for Windows in ncconfigure.h --- include/ncconfigure.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/include/ncconfigure.h b/include/ncconfigure.h index 2b4375ea5..a12e4ab50 100644 --- a/include/ncconfigure.h +++ b/include/ncconfigure.h @@ -65,13 +65,28 @@ extern int fileno(FILE*); #endif #endif /*STDC*/ -#endif /*!_WIN32*/ -#ifdef _WIN32 +#else /*_WIN32*/ + #ifndef HAVE_STRLCAT #define strlcat(d,s,n) strcat_s((d),(n),(s)) #endif + +#ifndef __MINGW32__ +#ifndef strcasecmp +#define strcasecmp _stricmp #endif +#ifndef strncasecmp +#define strncasecmp _strnicmp +#endif +#ifndef snprintf +#if _MSC_VER<1900 +#define snprintf _snprintf +#endif +#endif +#endif /*__MINGW32__*/ + +#endif /*_WIN32*/ /* handle null arguments */ #ifndef nulldup From 3cf75bf088c2e367f5af2f3f88bb85bf437f160d Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 5 Sep 2021 17:14:36 +1000 Subject: [PATCH 3/8] Avoid duplicate definition of strcasecmp in config.h --- config.h.cmake.in | 32 -------------------------------- configure.ac | 10 ---------- 2 files changed, 42 deletions(-) diff --git a/config.h.cmake.in b/config.h.cmake.in index 622e094ad..276dfc202 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -57,23 +57,6 @@ are set when opening a binary file on Windows. */ #define _OFF_T_DEFINED #endif - #if defined(_WIN32) && !defined(__MINGW32__) - #ifndef strcasecmp - #define strcasecmp _stricmp - #endif - - #ifndef strincasecmp - #define strncasecmp _strnicmp - #endif - - #ifndef snprintf - #if _MSC_VER<1900 - #define snprintf _snprintf - #endif - #endif - #endif - - #define strdup _strdup #define fdopen _fdopen #define write _write @@ -655,21 +638,6 @@ with zip */ /* Define to `unsigned long if does not define. */ #cmakedefine uintptr_t unsigned long -/* Define strcasecmp, strncasecmp, snprintf on Win32 systems. */ -#if defined(_WIN32) && !defined(__MINGW32__) - #ifndef HAVE_STRCASECMP - #define strcasecmp _stricmp - #endif - - #ifndef HAVE_STRNCASECMP - #define strncasecmp _strnicmp - #endif - - #ifndef HAVE_SNPRINTF - #define snprintf _snprintf - #endif -#endif - #cmakedefine WORDS_BIGENDIAN #include "ncconfigure.h" diff --git a/configure.ac b/configure.ac index eb91a064a..e4cb3a2e4 100644 --- a/configure.ac +++ b/configure.ac @@ -1651,16 +1651,6 @@ AC_SUBST(HAS_MULTIFILTERS,[$has_multifilters]) AC_SUBST(DO_NCZARR_ZIP_TESTS,[$enable_nczarr_zip]) AC_SUBST(HAS_LOGGING,[$enable_logging]) -# Include some specifics for netcdf on windows. -#AH_VERBATIM([_WIN32_STRICMP], -AH_BOTTOM( -[/* Define strcasecmp, strncasecmp, snprintf on Win32 systems. */ -#if defined(_WIN32) && !defined(__MINGW32__) - #define strcasecmp _stricmp - #define strncasecmp _strnicmp - #define snprintf _snprintf -#endif]) - # Access netcdf specific version of config.h AH_BOTTOM([#include "ncconfigure.h"]) From 4fa91d824138b823241e5e6a31baecda30d618cd Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 5 Sep 2021 17:15:36 +1000 Subject: [PATCH 4/8] Use strcasecmp definitions from config.h --- dap4_test/dump.c | 1 - libdispatch/ncjson.c | 7 +------ libdispatch/nclist.c | 6 +----- ncdump/nccopy.c | 1 - ncdump/ncdump.c | 1 - ncdump/ncvalidator.c | 1 - ncgen/ncgen.h | 8 +------- ncgen3/main.c | 1 - 8 files changed, 3 insertions(+), 23 deletions(-) diff --git a/dap4_test/dump.c b/dap4_test/dump.c index 1c242f131..76a49a5d5 100644 --- a/dap4_test/dump.c +++ b/dap4_test/dump.c @@ -17,7 +17,6 @@ #if defined(_WIN32) && !defined(__MINGW32__) #include "XGetopt.h" -#define snprintf _snprintf #endif #include "netcdf.h" diff --git a/libdispatch/ncjson.c b/libdispatch/ncjson.c index 0ee47d940..12b9208ef 100644 --- a/libdispatch/ncjson.c +++ b/libdispatch/ncjson.c @@ -12,14 +12,9 @@ TODO: make utf8 safe #include #include #include +#include "config.h" #include "ncjson.h" -#if defined(_WIN32) && !defined(__MINGW32__) -#define strcasecmp _stricmp -#else -#include -#endif - #undef DEBUG #define NCJ_OK 0 diff --git a/libdispatch/nclist.c b/libdispatch/nclist.c index 83153db2e..a18c158ba 100644 --- a/libdispatch/nclist.c +++ b/libdispatch/nclist.c @@ -3,13 +3,9 @@ #include #include #include - +#include "config.h" #include "nclist.h" -#if defined(_WIN32) && !defined(__MINGW32__) -#define strcasecmp _stricmp -#endif - int nclistnull(void* e) {return e == NULL;} #ifndef TRUE diff --git a/ncdump/nccopy.c b/ncdump/nccopy.c index 12f759234..312f7dcca 100644 --- a/ncdump/nccopy.c +++ b/ncdump/nccopy.c @@ -15,7 +15,6 @@ #if defined(_WIN32) && !defined(__MINGW32__) #include "XGetopt.h" -#define snprintf _snprintf #endif #ifdef HAVE_UNISTD_H diff --git a/ncdump/ncdump.c b/ncdump/ncdump.c index f0cf35169..0321bc7c0 100644 --- a/ncdump/ncdump.c +++ b/ncdump/ncdump.c @@ -11,7 +11,6 @@ Research/Unidata. See \ref copyright file for more info. */ #if defined(_WIN32) && !defined(__MINGW32__) #include "XGetopt.h" -#define snprintf _snprintf #endif #ifdef HAVE_UNISTD_H diff --git a/ncdump/ncvalidator.c b/ncdump/ncvalidator.c index dead0d036..7e77c76fb 100644 --- a/ncdump/ncvalidator.c +++ b/ncdump/ncvalidator.c @@ -76,7 +76,6 @@ THIS SOFTWARE. #if defined(_WIN32) && !defined(__MINGW32__) #include #include "XGetopt.h" -#define snprintf _snprintf #endif #define X_ALIGN 4 diff --git a/ncgen/ncgen.h b/ncgen/ncgen.h index c2eac3a40..45b5bfe13 100644 --- a/ncgen/ncgen.h +++ b/ncgen/ncgen.h @@ -6,13 +6,7 @@ * $Header: /upc/share/CVS/netcdf-3/ncgen/ncgen.h,v 1.18 2010/06/01 15:34:53 ed Exp $ *********************************************************************/ -#ifdef _WIN32 -#include -#include "isnan.h" -#ifndef __MINGW32__ -#define strcasecmp _stricmp -#endif -#endif +#include "config.h" #ifdef USE_NETCDF4 #define CLASSICONLY 0 diff --git a/ncgen3/main.c b/ncgen3/main.c index 6f9c5f5df..aabcae680 100644 --- a/ncgen3/main.c +++ b/ncgen3/main.c @@ -17,7 +17,6 @@ #if defined(_WIN32) && !defined(__MINGW32__) #include "XGetopt.h" -#define snprintf _snprintf #endif #include "netcdf.h" From 1fa3955226ecffcf90a22ec73e788d72ece4e2ae Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Mon, 6 Sep 2021 10:28:18 +1000 Subject: [PATCH 5/8] Remove config.h from ncjson.c and nclist.c --- libdispatch/ncjson.c | 7 ++++++- libdispatch/nclist.c | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libdispatch/ncjson.c b/libdispatch/ncjson.c index 12b9208ef..0ee47d940 100644 --- a/libdispatch/ncjson.c +++ b/libdispatch/ncjson.c @@ -12,9 +12,14 @@ TODO: make utf8 safe #include #include #include -#include "config.h" #include "ncjson.h" +#if defined(_WIN32) && !defined(__MINGW32__) +#define strcasecmp _stricmp +#else +#include +#endif + #undef DEBUG #define NCJ_OK 0 diff --git a/libdispatch/nclist.c b/libdispatch/nclist.c index a18c158ba..83153db2e 100644 --- a/libdispatch/nclist.c +++ b/libdispatch/nclist.c @@ -3,9 +3,13 @@ #include #include #include -#include "config.h" + #include "nclist.h" +#if defined(_WIN32) && !defined(__MINGW32__) +#define strcasecmp _stricmp +#endif + int nclistnull(void* e) {return e == NULL;} #ifndef TRUE From 114185e84bdfb408745a9e25ee4d6b3fdbc19976 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 3 Oct 2021 11:27:42 +1100 Subject: [PATCH 6/8] Fix NCJTHROW definition after merge from main --- libdispatch/ncjson.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libdispatch/ncjson.c b/libdispatch/ncjson.c index 32d459adc..e86217564 100644 --- a/libdispatch/ncjson.c +++ b/libdispatch/ncjson.c @@ -15,8 +15,10 @@ TODO: make utf8 safe #include "ncjson.h" -#if defined(_WIN32) && !defined(__MINGW32__) -#define strcasecmp _stricmp +#undef NCJDEBUG +#ifdef NCJDEBUG +static int ncjbreakpoint(int err) {return err;} +#define NCJTHROW(err) ((err)==NCJ_ERR?ncjbreakpoint(err):(err)) #else #define NCJTHROW(err) (err) #endif @@ -60,7 +62,7 @@ typedef struct NCJbuf { /**************************************************/ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define strdup _strdup #define strcasecmp _stricmp #else From 56c549af0fb028eb84bf229ec71e3a4103693070 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Tue, 11 Jan 2022 19:05:46 -0700 Subject: [PATCH 7/8] Make sure mode flags are properly defined in netcdf.h In a number of places in the netcdf-c library, some of the high order mode flags (the mode argument to nc_open or nc_close) are being used to save state information. This means that the description of the defined and open mode flags in netcdf.h were not accurate. This PR moves all those hack flags so that the list of mode flags in netcdf.h is correct. --- .github/workflows/mingw.yml | 2 +- .github/workflows/run_tests.yml | 2 +- include/nc3internal.h | 39 ++++++++++++++------------ include/nc4internal.h | 16 ++++------- include/netcdf.h | 12 ++++---- libsrc/nc3internal.c | 49 +++++++++++---------------------- libsrc/ncio.c | 38 +++++++++++++++++++++++-- libsrc/ncio.h | 8 ++---- libsrc/s3io.c | 1 + 9 files changed, 90 insertions(+), 77 deletions(-) diff --git a/.github/workflows/mingw.yml b/.github/workflows/mingw.yml index a6fd8ad39..0f9c9a2c5 100644 --- a/.github/workflows/mingw.yml +++ b/.github/workflows/mingw.yml @@ -1,5 +1,5 @@ name: NetCDF-Build MinGW -on: [workflow_dispatch] +on: [workflow_dispatch,push] jobs: build: diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 16ef43432..eb6b6036e 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -4,7 +4,7 @@ name: Run netCDF Tests -on: [pull_request] +on: [pull_request,push] jobs: diff --git a/include/nc3internal.h b/include/nc3internal.h index af4f2ea72..dbd4625ac 100644 --- a/include/nc3internal.h +++ b/include/nc3internal.h @@ -224,15 +224,18 @@ NC_lookupvar(NC3_INFO* ncp, int varid, NC_var **varp); struct NC3_INFO { /* contains the previous NC during redef. */ NC3_INFO *old; - /* flags */ -#define NC_CREAT 2 /* in create phase, cleared by ncendef */ -#define NC_INDEF 8 /* in define mode, cleared by ncendef */ -#define NC_NSYNC 0x10 /* synchronise numrecs on change */ -#define NC_HSYNC 0x20 /* synchronise whole header on change */ -#define NC_NDIRTY 0x40 /* numrecs has changed */ -#define NC_HDIRTY 0x80 /* header info has changed */ -/* NC_NOFILL in netcdf.h, historical interface */ - int flags; + int flags; /* mode flags */ + int state; /* state transitions flags */ +# define NC_CREAT 0x1 /* in create phase, cleared by ncendef */ +# define NC_INDEF 0x2 /* in define mode, cleared by ncendef */ +# define NC_NSYNC 0x4 /* synchronise numrecs on change */ +# define NC_HSYNC 0x8 /* synchronise whole header on change */ +# define NC_NDIRTY 0x10 /* numrecs has changed */ +# define NC_HDIRTY 0x20 /* header info has changed */ +/* NC_NOFILL defined in netcdf.h, historical interface */ +#if 0 +# define NC_NOFILL 0x100 /**< Argument to nc_set_fill() to turn off filling of data. */ +#endif struct ncio* nciop; size_t chunk; /* largest extent this layer will request from ncio->get() */ size_t xsz; /* external size of this header, == var[0].begin */ @@ -258,31 +261,31 @@ struct NC3_INFO { fClr((ncp)->flags, NC_WRITE) #define NC_IsNew(ncp) \ - fIsSet((ncp)->flags, NC_CREAT) + fIsSet((ncp)->state, NC_CREAT) #define NC_indef(ncp) \ - (NC_IsNew(ncp) || fIsSet((ncp)->flags, NC_INDEF)) + (NC_IsNew(ncp) || fIsSet((ncp)->state, NC_INDEF)) #define set_NC_ndirty(ncp) \ - fSet((ncp)->flags, NC_NDIRTY) + fSet((ncp)->state, NC_NDIRTY) #define NC_ndirty(ncp) \ - fIsSet((ncp)->flags, NC_NDIRTY) + fIsSet((ncp)->state, NC_NDIRTY) #define set_NC_hdirty(ncp) \ - fSet((ncp)->flags, NC_HDIRTY) + fSet((ncp)->state, NC_HDIRTY) #define NC_hdirty(ncp) \ - fIsSet((ncp)->flags, NC_HDIRTY) + fIsSet((ncp)->state, NC_HDIRTY) #define NC_dofill(ncp) \ - (!fIsSet((ncp)->flags, NC_NOFILL)) + (!fIsSet((ncp)->state, NC_NOFILL)) #define NC_doHsync(ncp) \ - fIsSet((ncp)->flags, NC_HSYNC) + fIsSet((ncp)->state, NC_HSYNC) #define NC_doNsync(ncp) \ - fIsSet((ncp)->flags, NC_NSYNC) + fIsSet((ncp)->state, NC_NSYNC) # define NC_get_numrecs(nc3i) \ ((nc3i)->numrecs) diff --git a/include/nc4internal.h b/include/nc4internal.h index 9fe0688c6..2eb656fca 100644 --- a/include/nc4internal.h +++ b/include/nc4internal.h @@ -276,20 +276,14 @@ typedef struct NC_GRP_INFO NCindex* vars; /**< NCindex * */ } NC_GRP_INFO_T; -/* These constants apply to the cmode parameter in the +/* These constants apply to the flags field in the * HDF5_FILE_INFO_T defined below. */ -/* Make sure they do not conflict with defined flags in netcdf.h */ -#define NC_CREAT 0x10002 /**< in create phase, cleared by ncendef */ -#define NC_INDEF 0x10008 /**< in define mode, cleared by ncendef */ -#define NC_NSYNC 0x10010 /**< synchronise numrecs on change */ -#define NC_HSYNC 0x10020 /**< synchronise whole header on change */ -#define NC_NDIRTY 0x10040 /**< numrecs has changed */ -#define NC_HDIRTY 0x10080 /**< header info has changed */ +#define NC_INDEF 0x01 /**< in define mode, cleared by ncendef */ /** This is the metadata we need to keep track of for each * netcdf-4/HDF5 file. */ -typedef struct NC_FILE_INFO +typedef struct NC_FILE_INFO { NC_OBJ hdr; NC *controller; /**< Pointer to containing NC. */ @@ -297,8 +291,8 @@ typedef struct NC_FILE_INFO MPI_Comm comm; /**< Copy of MPI Communicator used to open the file. */ MPI_Info info; /**< Copy of MPI Information Object used to open the file. */ #endif - int flags; /**< Flags used to open the file. */ - int cmode; /**< Create mode used to create the file. */ + int cmode; /**< Create/Open mode for the file. */ + int flags; /**< State transition flags . */ nc_bool_t parallel; /**< True if file is open for parallel access */ nc_bool_t redef; /**< True if redefining an existing file */ nc_bool_t no_attr_create_order; /**< True if the creation order tracking of attributes is disabled (netcdf-4 only) */ diff --git a/include/netcdf.h b/include/netcdf.h index 084948af6..657fabc0d 100644 --- a/include/netcdf.h +++ b/include/netcdf.h @@ -115,13 +115,14 @@ extern "C" { #define NC_NOFILL 0x100 /**< Argument to nc_set_fill() to turn off filling of data. */ /* Define the ioflags bits for nc_create and nc_open. - currently unused: + Currently unused in lower 16 bits: 0x0002 - and the whole upper 16 bits - Note: nc4internal also defines flags in this space even tho it should not. - so check there around #define NC_CREAT. + All upper 16 bits are unused except + 0x20000 */ +/* Lower 16 bits */ + #define NC_NOWRITE 0x0000 /**< Set read-only access for nc_open(). */ #define NC_WRITE 0x0001 /**< Set read-write access for nc_open(). */ @@ -161,7 +162,8 @@ Use this in mode flags for both nc_create() and nc_open(). */ #define NC_PERSIST 0x4000 /**< Save diskless contents to disk. Mode flag for nc_open() or nc_create() */ #define NC_INMEMORY 0x8000 /**< Read from memory. Mode flag for nc_open() or nc_create() */ -#define NC_NOATTCREORD 0x20000 /**< Disable the netcdf-4 (hdf5) attribute creation order tracking */ +/* Upper 16 bits */ +#define NC_NOATTCREORD 0x20000 /**< Disable the netcdf-4 (hdf5) attribute creation order tracking */ #define NC_MAX_MAGIC_NUMBER_LEN 8 /**< Max len of user-defined format magic number. */ diff --git a/libsrc/nc3internal.c b/libsrc/nc3internal.c index 51c6d1fbf..2045304e0 100644 --- a/libsrc/nc3internal.c +++ b/libsrc/nc3internal.c @@ -413,7 +413,7 @@ write_numrecs(NC3_INFO *ncp) (void) ncio_rel(ncp->nciop, NC_NUMRECS_OFFSET, RGN_MODIFIED); if(status == NC_NOERR) - fClr(ncp->flags, NC_NDIRTY); + fClr(ncp->state, NC_NDIRTY); return status; } @@ -435,7 +435,7 @@ read_NC(NC3_INFO *ncp) status = nc_get_NC(ncp); if(status == NC_NOERR) - fClr(ncp->flags, NC_NDIRTY | NC_HDIRTY); + fClr(ncp->state, NC_NDIRTY | NC_HDIRTY); return status; } @@ -454,7 +454,7 @@ write_NC(NC3_INFO *ncp) status = ncx_put_NC(ncp, NULL, 0, 0); if(status == NC_NOERR) - fClr(ncp->flags, NC_NDIRTY | NC_HDIRTY); + fClr(ncp->state, NC_NDIRTY | NC_HDIRTY); return status; } @@ -864,7 +864,7 @@ NC_endef(NC3_INFO *ncp, { /* a plain redef, not a create */ assert(!NC_IsNew(ncp)); - assert(fIsSet(ncp->flags, NC_INDEF)); + assert(fIsSet(ncp->state, NC_INDEF)); assert(ncp->begin_rec >= ncp->old->begin_rec); assert(ncp->begin_var >= ncp->old->begin_var); @@ -937,7 +937,7 @@ NC_endef(NC3_INFO *ncp, ncp->old = NULL; } - fClr(ncp->flags, NC_CREAT | NC_INDEF); + fClr(ncp->state, NC_CREAT | NC_INDEF); return ncio_sync(ncp->nciop); } @@ -1071,7 +1071,7 @@ NC3_create(const char *path, int ioflags, size_t initialsz, int basepe, goto unwind_alloc; } - fSet(nc3->flags, NC_CREAT); + fSet(nc3->state, NC_CREAT); if(fIsSet(nc3->nciop->ioflags, NC_SHARE)) { @@ -1082,7 +1082,7 @@ NC3_create(const char *path, int ioflags, size_t initialsz, int basepe, * automatically. Some sort of IPC (external to this package) * would be used to trigger a call to nc_sync(). */ - fSet(nc3->flags, NC_NSYNC); + fSet(nc3->state, NC_NSYNC); } status = ncx_put_NC(nc3, &xp, sizeof_off_t, nc3->xsz); @@ -1173,29 +1173,12 @@ NC3_open(const char *path, int ioflags, int basepe, size_t *chunksizehintp, goto unwind_alloc; } -#ifdef ENABLE_BYTERANGE - { - NCURI* uri = NULL; - ncuriparse(path,&uri); - if(uri) { - /* If the model specified the use of byte-ranges, then signal by - a temporary hack using one of the flags in the ioflags. */ - if(NC_testmode(uri,"bytes")) { -# ifdef ENABLE_S3_SDK - if(NC_iss3(uri)) ioflags |= NC_S3SDK; else -# endif - ioflags |= NC_HTTP; - } - ncurifree(uri); - } - } -#endif /*ENABLE_BYTERANGE*/ status = ncio_open(path, ioflags, 0, 0, &nc3->chunk, parameters, &nc3->nciop, NULL); if(status) goto unwind_alloc; - assert(nc3->flags == 0); + assert(nc3->state == 0); if(fIsSet(nc3->nciop->ioflags, NC_SHARE)) { @@ -1206,7 +1189,7 @@ NC3_open(const char *path, int ioflags, int basepe, size_t *chunksizehintp, * automatically. Some sort of IPC (external to this package) * would be used to trigger a call to nc_sync(). */ - fSet(nc3->flags, NC_NSYNC); + fSet(nc3->state, NC_NSYNC); } status = nc_get_NC(nc3); @@ -1279,10 +1262,10 @@ NC3_abort(int ncid) { /* a plain redef, not a create */ assert(!NC_IsNew(nc3)); - assert(fIsSet(nc3->flags, NC_INDEF)); + assert(fIsSet(nc3->state, NC_INDEF)); free_NC3INFO(nc3->old); nc3->old = NULL; - fClr(nc3->flags, NC_INDEF); + fClr(nc3->state, NC_INDEF); } else if(!NC_readonly(nc3)) { @@ -1397,7 +1380,7 @@ NC3_redef(int ncid) if(nc3->old == NULL) return NC_ENOMEM; - fSet(nc3->flags, NC_INDEF); + fSet(nc3->state, NC_INDEF); return NC_NOERR; } @@ -1509,15 +1492,15 @@ NC3_set_fill(int ncid, if(NC_readonly(nc3)) return NC_EPERM; - oldmode = fIsSet(nc3->flags, NC_NOFILL) ? NC_NOFILL : NC_FILL; + oldmode = fIsSet(nc3->state, NC_NOFILL) ? NC_NOFILL : NC_FILL; if(fillmode == NC_NOFILL) { - fSet(nc3->flags, NC_NOFILL); + fSet(nc3->state, NC_NOFILL); } else if(fillmode == NC_FILL) { - if(fIsSet(nc3->flags, NC_NOFILL)) + if(fIsSet(nc3->state, NC_NOFILL)) { /* * We are changing back to fill mode @@ -1527,7 +1510,7 @@ NC3_set_fill(int ncid, if(status != NC_NOERR) return status; } - fClr(nc3->flags, NC_NOFILL); + fClr(nc3->state, NC_NOFILL); } else { diff --git a/libsrc/ncio.c b/libsrc/ncio.c index 9023d6076..133eddad4 100644 --- a/libsrc/ncio.c +++ b/libsrc/ncio.c @@ -12,6 +12,8 @@ #include "netcdf.h" #include "ncio.h" #include "fbits.h" +#include "ncuri.h" +#include "ncrc.h" /* With the advent of diskless io, we need to provide for multiple ncio packages at the same time, @@ -46,6 +48,9 @@ extern int ffio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** co extern int memio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const); extern int memio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const); +/* Forward */ +static int urlmodetest(const char* path); + int ncio_create(const char *path, int ioflags, size_t initialsz, off_t igeto, size_t igetsz, size_t *sizehintp, @@ -78,6 +83,8 @@ ncio_open(const char *path, int ioflags, void* parameters, ncio** iopp, void** const mempp) { + int modetest = urlmodetest(path); + /* Diskless open has the following constraints: 1. file must be classic version 1 or 2 or 5 */ @@ -93,12 +100,11 @@ ncio_open(const char *path, int ioflags, } # endif /*USE_MMAP*/ # ifdef ENABLE_BYTERANGE - /* The NC_HTTP flag is a big hack until we can reorganize the ncio interface */ - if(fIsSet(ioflags,NC_HTTP)) { + if(modetest == NC_HTTP) { return httpio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp); } # ifdef ENABLE_S3_SDK - if(fIsSet(ioflags,NC_S3SDK)) { + if(modetest == NC_S3SDK) { return s3io_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp); } # endif @@ -162,3 +168,29 @@ ncio_close(ncio* const nciop, int doUnlink) int status = nciop->close(nciop,doUnlink); return status; } + +/* URL utilities */ + +/* +Check mode flags and return: +NC_HTTP => byterange +NC_S3SDK => s3 +0 => Not URL +*/ +static int +urlmodetest(const char* path) +{ + int kind = 0; + NCURI* uri = NULL; + + ncuriparse(path,&uri); + if(uri == NULL) return 0; /* Not URL */ + if(NC_testmode(uri, "bytes")) + kind = NC_HTTP; + else if(NC_testmode(uri, "s3")) + kind = NC_S3SDK; + else + kind = 0; + ncurifree(uri); + return kind; +} diff --git a/libsrc/ncio.h b/libsrc/ncio.h index c43bba95e..e35be60e8 100644 --- a/libsrc/ncio.h +++ b/libsrc/ncio.h @@ -11,11 +11,9 @@ #include /* off_t */ #include "netcdf.h" -/* Define internal use only flags to signal use of byte ranges and S3. - This is temporary until we can re-organize the ncio open/create API. -*/ -#define NC_HTTP 0x80000000 -#define NC_S3SDK 0x40000000 +/* Define internal use only flags to signal use of byte ranges and S3. */ +#define NC_HTTP 1 +#define NC_S3SDK 2 typedef struct ncio ncio; /* forward reference */ diff --git a/libsrc/s3io.c b/libsrc/s3io.c index 7f120e319..6c180e821 100644 --- a/libsrc/s3io.c +++ b/libsrc/s3io.c @@ -36,6 +36,7 @@ #include "fbits.h" #include "rnd.h" #include "ncs3sdk.h" +#include "ncuri.h" #define DEFAULTPAGESIZE 16384 From b5879b19357bf665e84a198a8b797e58057eb37c Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Tue, 11 Jan 2022 20:14:34 -0700 Subject: [PATCH 8/8] Update release notes --- .github/workflows/mingw.yml | 2 +- .github/workflows/run_tests.yml | 2 +- RELEASE_NOTES.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mingw.yml b/.github/workflows/mingw.yml index 0f9c9a2c5..a6fd8ad39 100644 --- a/.github/workflows/mingw.yml +++ b/.github/workflows/mingw.yml @@ -1,5 +1,5 @@ name: NetCDF-Build MinGW -on: [workflow_dispatch,push] +on: [workflow_dispatch] jobs: build: diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index eb6b6036e..16ef43432 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -4,7 +4,7 @@ name: Run netCDF Tests -on: [pull_request,push] +on: [pull_request] jobs: diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 98828d660..b041b22f1 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release ## 4.8.2 - TBD +* [Bug Fix] Make sure that netcdf.h accurately defines the flags in the open/create mode flags. See [Github #2183](https://github.com/Unidata/netcdf-c/pull/2183). * [Enhancement] Improve support for msys2+mingw platform. See [Github #2171](https://github.com/Unidata/netcdf-c/pull/2171). * [Bug Fix] Clean up the various inter-test dependencies in ncdump for CMake. See [Github #2168](https://github.com/Unidata/netcdf-c/pull/2168). * [Enhancement] Added options to suppress the new behavior from [Github #2135](https://github.com/Unidata/netcdf-c/pull/2135). The options for `cmake` and `configure` are, respectively `-DENABLE_LIBXML2` and `--(enable/disable)-libxml2`. Both of these options defaul to 'on/enabled'. When disabled, the bundled `ezxml` XML interpreter is used regardless of whether `libxml2` is present on the system.