Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct conflict in #2170 #2266

Merged
merged 12 commits into from
Mar 30, 2022
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1251,8 +1251,9 @@ IF(NOT FOUND_CURL)
ENDIF(NOT FOUND_CURL)


OPTION(ENABLE_LIBXML2 "Link against libxml2 if it is available, use the packaged ezxml parser otherwise." ON)
SET(XMLPARSER "ezxml (bundled)")
OPTION(ENABLE_LIBXML2 "Link against libxml2 if it is available, use the packaged tinyxml2 parser otherwise." ON)
SET(XMLPARSER "tinyxml2 (bundled)")

# see if we have libxml2

IF(ENABLE_LIBXML2)
Expand Down Expand Up @@ -1794,6 +1795,7 @@ CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)
CHECK_FUNCTION_EXISTS(strndup HAVE_STRNDUP)
CHECK_FUNCTION_EXISTS(strtoll HAVE_STRTOLL)
CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
CHECK_FUNCTION_EXISTS(strtoull HAVE_STRTOULL)
CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
CHECK_FUNCTION_EXISTS(mktemp HAVE_MKTEMP)
Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This file contains a high-level description of this package's evolution. Release
## 4.8.2 - TBD

* [Enhancement] Improve filter support. More specifically (1) add nc_inq_filter_avail to check if a filter is available, (2) add the notion of standard filters, (3) cleanup szip support to fix interaction with NCZarr. See [Github #2245](https://github.com/Unidata/netcdf-c/pull/2245).
* [Enhancement] Switch to tinyxml2 as the default xml parser implementation. See [Github #2170](https://github.com/Unidata/netcdf-c/pull/2170).
* [Bug Fix] Require that the type of the variable in nc_def_var_filter is not variable length. See [Github #/2231](https://github.com/Unidata/netcdf-c/pull/2231).
* [File Change] Apply HDF5 v1.8 format compatibility when writing to previous files, as well as when creating new files. The superblock version remains at 2 for newly created files. Full backward read/write compatibility for netCDF-4 is maintained in all cases. See [Github #2176](https://github.com/Unidata/netcdf-c/issues/2176).
* [Enhancement] Add ability to set dataset alignment for netcdf-4/HDF5 files. See [Github #2206](https://github.com/Unidata/netcdf-c/pull/2206).
Expand Down
17 changes: 10 additions & 7 deletions config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ are set when opening a binary file on Windows. */
#cmakedefine HAVE_LIBPNETCDF 1

/* Define to 1 if you have the libxml2 library. */
#cmakedefine HAVE_LIBXML2 1
#cmakedefine ENABLE_LIBXML2 1

/* Define to 1 if you have the <locale.h> header file. */
#cmakedefine HAVE_LOCALE_H 1
Expand Down Expand Up @@ -358,12 +358,6 @@ are set when opening a binary file on Windows. */
/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H 1

/* Define to 1 if you have the `strdup' function. */
#cmakedefine HAVE_STRDUP 1

/* Define to 1 if you have the `strndup` function. */
#cmakedefine HAVE_STRNDUP

/* Define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H 1

Expand All @@ -379,6 +373,15 @@ are set when opening a binary file on Windows. */
/* Define to 1 if you have the <libgen.h> header file. */
#cmakedefine HAVE_LIBGEN_H 1

/* Define to 1 if you have the `strdup' function. */
#cmakedefine HAVE_STRDUP 1

/* Define to 1 if you have the `strndup` function. */
#cmakedefine HAVE_STRNDUP

/* Define to 1 if you have the `strcasecmp` function. */
#cmakedefine HAVE_STRCASECMP

/* Define to 1 if you have the `strlcat' function. */
#cmakedefine HAVE_STRLCAT 1

Expand Down
83 changes: 46 additions & 37 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,45 @@ fi

CFLAGS="$SAVECFLAGS"

###
# Libxml2 control block.
###

AC_MSG_CHECKING([whether to search for and use external libxml2])
AC_ARG_ENABLE([libxml2],
[AS_HELP_STRING([--disable-libxml2],
[disable detection and use of libxml2 in favor of the bundled ezxml interpreter])])
test "x$enable_libxml2" = xno || enable_libxml2=yes
AC_MSG_RESULT([$enable_libxml2])

have_libxml2=no
if test "x$enable_libxml2" = xyes; then
# We can optionally use libxml2 for DAP4, if available
AC_CHECK_LIB([xml2],[xmlReadMemory],[have_libxml2=yes],[have_libxml2=no])
if test "x$have_libxml2" = "xyes" ; then
AC_SEARCH_LIBS([xmlReadMemory],[xml2 xml2.dll cygxml2.dll], [],[])
fi
if test "x$have_libxml2" = xyes; then
XML2FLAGS=`xml2-config --cflags`
AC_SUBST([XML2FLAGS],${XML2FLAGS})
AC_DEFINE([HAVE_LIBXML2], [1], [if true, use libxml2])
fi
fi

if test "x$enable_libxml2" = xyes; then
XMLPARSER="libxml2"
else
XMLPARSER="tinyxml2 (bundled)"
fi

# Need a condition and subst for this
AM_CONDITIONAL(ENABLE_LIBXML2, [test "x$enable_libxml2" = xyes])
AC_SUBST([XMLPARSER],[${XMLPARSER}])

###
# End Libxml2 block
###

# --enable-dap => enable-dap4
enable_dap4=$enable_dap
AC_MSG_CHECKING([whether dap remote testing should be enabled])
Expand Down Expand Up @@ -1094,51 +1133,21 @@ AC_CHECK_FUNCS([strlcat snprintf strcasecmp fileno \
AC_CHECK_FUNCS([clock_gettime])
AC_CHECK_TYPES([struct timespec])

# disable dap4 if netcdf-4 is disabled
#if test "x$enable_netcdf_4" = "xno" ; then
# disable dap4 if hdf5 is disabled
if test "x$enable_hdf5" = "xno" ; then
AC_MSG_WARN([netcdf-4 not enabled; disabling DAP4])
enable_dap4=no
fi

if test "x$enable_dap4" = xyes; then
AC_DEFINE([ENABLE_DAP4], [1], [if true, build DAP4 Client])
if test "x$ISOSX" = xyes && "x$have_libxml2" = xno ; then
AC_MSG_ERROR([Error: OSX requires libxml2 => --disable-dap4.])
enable_dap4=no
fi

###
# Libxml2 control block.
###

AC_MSG_CHECKING([whether to search for and use external libxml2])
AC_ARG_ENABLE([libxml2],
[AS_HELP_STRING([--disable-libxml2],
[disable detection and use of libxml2 in favor of the bundled ezxml interpreter])])
test "x$disable_libxml2" = xyes && enable_libxml2=no
AC_MSG_RESULT($enable_libxml2)

AC_SUBST([XMLPARSER],"ezxml")
if test "x$enable_libxml2" = xyes; then
# We can optionally use libxml2 for DAP4, if available
AC_CHECK_LIB([xml2],[xmlReadMemory],[have_libxml2=yes],[have_libxml2=no])
if test "x$have_libxml2" = "xyes" ; then
AC_SEARCH_LIBS([xmlReadMemory],[xml2 xml2.dll cygxml2.dll], [],[])
AC_SUBST([XMLPARSER],"libxml2")
fi
if test "x$have_libxml2" = xyes; then
XML2FLAGS=`xml2-config --cflags`
AC_SUBST([XML2FLAGS],${XML2FLAGS})
AC_DEFINE([HAVE_LIBXML2], [1], [if true, use libxml2])
fi

if test "x$enable_dap4" = xyes; then
AC_DEFINE([ENABLE_DAP4], [1], [if true, build DAP4 Client])
fi

# Need a condition for this
AM_CONDITIONAL(HAVE_LIBXML2, [test "x$have_libxml2" = xyes])

###
# End Libxml2 block
###

# check for useful, but not essential, memio support
AC_CHECK_FUNCS([memmove getpagesize sysconf])

Expand Down Expand Up @@ -1257,7 +1266,7 @@ AC_FUNC_ALLOCA
AC_CHECK_DECLS([isnan, isinf, isfinite],,,[#include <math.h>])
AC_STRUCT_ST_BLKSIZE
UD_CHECK_IEEE
AC_CHECK_TYPES([size_t, ssize_t, schar, uchar, longlong, ushort, uint, int64, uint64, size64_t, ssize64_t, _off64_t, uint64_t])
AC_CHECK_TYPES([size_t, ssize_t, schar, uchar, longlong, ushort, uint, int64, uint64, size64_t, ssize64_t, _off64_t, uint64_t, ptrdiff_t])
AC_TYPE_OFF_T
AC_TYPE_UINTPTR_T
AC_C_CHAR_UNSIGNED
Expand Down
1 change: 1 addition & 0 deletions dap4_test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include $(top_srcdir)/lib_flags.am
#SH_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
#LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
#TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
#TESTS_ENVIRONMENT = export SETX=1;

# Note which tests depend on other tests. Necessary for make -j check.
TEST_EXTENSIONS = .sh
Expand Down
14 changes: 8 additions & 6 deletions dap4_test/test_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ main(int argc, char** argv)
}

/* build the url */
snprintf(url,sizeof(url),"file://%s#dap4&debug=copy",argv[0]);
if(argc >= 3) {
strlcat(url,"&substratename=",sizeof(url));
strlcat(url,argv[1],sizeof(url));
}
snprintf(url,sizeof(url),"file://%s#dap4&debug=copy%s%s%s",
argv[0],
(argc >= 3 ? "&substratename=" : ""),
(argc >= 3 ? argv[1] : ""),
#ifdef DEBUG
strlcat(url,"&log",sizeof(url));
"&log"
#else
""
#endif
);

#ifdef DEBUG
fprintf(stderr,"test_data url=%s\n",url);
Expand Down
43 changes: 38 additions & 5 deletions include/ncconfigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#ifndef NCCONFIGURE_H
#define NCCONFIGURE_H 1

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
Expand Down Expand Up @@ -41,24 +45,49 @@ typedef SSIZE_T ssize_t;
#ifndef _WIN32
#if __STDC__ == 1 /*supposed to be same as -ansi flag */

#if defined(__cplusplus)
extern "C" {
#endif

/* WARNING: in some systems, these functions may be defined as macros, so check */
#ifndef HAVE_STRDUP
#ifndef strdup
extern char* strdup(const char*);
char* strdup(const char*);
#endif
#endif

#ifndef HAVE_STRLCAT
#ifndef strlcat
extern size_t strlcat(char*,const char*,size_t);
size_t strlcat(char*,const char*,size_t);
#endif
#endif

#ifndef HAVE_SNPRINTF
#ifndef snprintf
extern int snprintf(char*, size_t, const char*, ...);
int snprintf(char*, size_t, const char*, ...);
#endif
#endif

#ifndef HAVE_STRCASECMP
#ifndef strcasecmp
extern int strcasecmp(const char*, const char*);
#endif
#endif

#ifndef HAVE_STRTOLL
#ifndef strtoll
extern long long int strtoll(const char*, char**, int);
long long int strtoll(const char*, char**, int);
#endif
#endif

#ifndef HAVE_STRTOULL
#ifndef strtoull
extern unsigned long long int strtoull(const char*, char**, int);
unsigned long long int strtoull(const char*, char**, int);
#endif
#endif

#if defined(__cplusplus)
}
#endif

#endif /*STDC*/
Expand Down Expand Up @@ -145,6 +174,10 @@ typedef unsigned long long uint64_t;
typedef unsigned long long size64_t;
#endif

#ifndef HAVE_PTRDIFF_T
typedef long ptrdiff_t;
#endif

/* Provide a fixed size alternative to off_t or off64_t */
typedef long long fileoffset_t;

Expand Down
9 changes: 8 additions & 1 deletion lib_flags.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ if USE_DAP
AM_CPPFLAGS += -I${top_srcdir}/oc2
endif


if ENABLE_NCZARR
AM_CPPFLAGS += -I${top_srcdir}/libnczarr
endif

if ENABLE_S3_SDK

if ENABLE_S3_SDK
AM_LDFLAGS += -lstdc++
endif

if ! ENABLE_LIBXML2
# => tinyxml2
AM_LDFLAGS += -lstdc++
endif

Expand Down
1 change: 1 addition & 0 deletions libdap4/d4parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ NCD4_parse(NCD4meta* metadata)
done:
if(doc != NULL)
ncxml_free(doc);
doc = NULL;
reclaimParser(parser);
return THROW(ret);
}
Expand Down
2 changes: 1 addition & 1 deletion libncxml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
IF(HAVE_LIBXML2)
SET(libncxml_SOURCES ncxml_xml2.c)
ELSE()
SET(libncxml_SOURCES ncxml_ezxml.c ezxml.c ezxml.h)
SET(libncxml_SOURCES ncxml_tinyxml2.cpp tinyxml2.cpp tinyxml2.h)
ENDIF()

add_library(ncxml OBJECT ${libncxml_SOURCES})
Expand Down
42 changes: 11 additions & 31 deletions libncxml/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

include $(top_srcdir)/lib_flags.am

if HAVE_LIBXML2
if ENABLE_LIBXML2
AM_CPPFLAGS += ${XML2FLAGS}
endif

Expand All @@ -20,42 +20,22 @@ noinst_LTLIBRARIES = libncxml.la
libncxml_la_LIBADD =
libncxml_la_LDFLAGS =

if HAVE_LIBXML2
if ENABLE_LIBXML2
libncxml_la_SOURCES = ncxml_xml2.c
else
libncxml_la_SOURCES = ncxml_ezxml.c ezxml.c ezxml.h
AM_CXXFLAGS = -std=c++11
libncxml_la_SOURCES = ncxml_tinyxml2.cpp tinyxml2.cpp tinyxml2.h
endif

EXTRA_DIST = CMakeLists.txt license.txt

# Construct ezxml from latest sources
REPO = https://downloads.sourceforge.net/project/ezxml/
EZXML = ezxml-0.8.6.tar.gz
makelib::
echo "WARNING DO NOT RUN THIS since the patches are not in the tar file"
exit 1
rm -fr ./ezxml.[ch] ./license.txt ./ezxml ./ezxml.c.? ./ezxml.h.?
tar -zxf ${EZXML}
cat ezxml/ezxml.h > ./ezxml.h
sed -i.1 -e '/ezxml_parse_fd/d' ezxml.h
sed -i.2 -e '/ezxml_parse_file/d' ezxml.h
sed -i.3 -e '/ezxml_parse_fp/d' ezxml.h
echo "#define EZXML_NOMMAP 1" > ./ezxml.c
cat ezxml/ezxml.c >> ./ezxml.c
sed -i.1 -e '/<unistd.h>/d' ezxml.c
sed -i.2 -e '/ezxml_parse_fp(FILE/i#if 0' ./ezxml.c
sed -i.3 -e '/ezxml_ampencode(const/i#endif //0' ./ezxml.c
sed -i.4 -e 's|//\(.*\)|/*\1*/|' ezxml.h
sed -i.5 -e 's|//\(.*\)|/*\1*/|' ezxml.c
cp ezxml/license.txt .
rm -fr ezxml

# Define path to the xml github dir; this value assumes it is in a parallel directory to netcdf-c (YMMV)
TINYREPO = https://github.com/leethomason/tinyxml2.git
# Download and massage the tinyxml2 source
REPO = https://github.com/leethomason/tinyxml2.git
tinyxml2::
rm -fr ./tinyxml2 ./license.txt
git clone --depth=1 ${TINYREPO}
cat tinyxml2/tinyxml2.h > ./tinyxml2.h
cat tinyxml2/tinyxml2.cpp > ./tinyxml2.cpp
git clone --depth=1 ${REPO}
cat tinyxml2/LICENSE.txt > ./license.txt

cat tinyxml2/tinyxml2.h > ./tinyxml2.h
sed -e 's/__BORLANDC__/__APPLE__/' < tinyxml2/tinyxml2.cpp \
| sed -e 's/ptrdiff_t/long/g' > ./tinyxml2.cpp
rm -fr tinyxml2
Loading