Skip to content

Commit

Permalink
Update tinyxml and allow its use under OS/X.
Browse files Browse the repository at this point in the history
re: PR Unidata#2710

Apparently (see above PR) tinyxml2 now works under OS/X.
So this PR is a follow on to the above PR. It modifies
our OS/X github action to test tinyxml2 under OS/X.
  • Loading branch information
DennisHeimbigner committed Jun 13, 2023
1 parent cfe6231 commit 8887b5b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run_tests_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ jobs:

- name: Configure
shell: bash -l {0}
run: CFLAGS=${CFLAGS} LDFLAGS=${LDFLAGS} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ./configure --enable-hdf5 --enable-dap --disable-dap-remote-tests
run: CFLAGS=${CFLAGS} LDFLAGS=${LDFLAGS} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ./configure --enable-hdf5 --enable-dap --disable-dap-remote-tests --disable-xml2
if: ${{ success() }}

- name: Look at config.log if error
Expand Down Expand Up @@ -374,7 +374,7 @@ jobs:
run: |
mkdir build
cd build
LD_LIBRARY_PATH=${LD_LIBRARY_PATH} cmake .. -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DENABLE_DAP=TRUE -DENABLE_HDF5=TRUE -DENABLE_NCZARR=TRUE -D ENABLE_DAP_LONG_TESTS=TRUE
LD_LIBRARY_PATH=${LD_LIBRARY_PATH} cmake .. -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DENABLE_DAP=TRUE -DENABLE_HDF5=TRUE -DENABLE_NCZARR=TRUE -D ENABLE_DAP_LONG_TESTS=TRUE -DENABLE_XML2=FALSE
- name: Print Summary
shell: bash -l {0}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run_tests_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:

- name: Configure
shell: bash -l {0}
run: CFLAGS=${CFLAGS} LDFLAGS=${LDFLAGS} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ./configure --enable-hdf5 --enable-dap --disable-dap-remote-tests --enable-doxygen --enable-external-server-tests
run: CFLAGS=${CFLAGS} LDFLAGS=${LDFLAGS} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ./configure --enable-hdf5 --enable-dap --disable-dap-remote-tests --enable-doxygen --enable-external-server-tests --disable-xml2
if: ${{ success() }}

- name: Look at config.log if error
Expand Down Expand Up @@ -327,7 +327,7 @@ jobs:
run: |
mkdir build
cd build
LD_LIBRARY_PATH=${LD_LIBRARY_PATH} cmake .. -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DENABLE_DAP=TRUE -DENABLE_HDF5=TRUE -DENABLE_NCZARR=TRUE -D ENABLE_DAP_LONG_TESTS=TRUE
LD_LIBRARY_PATH=${LD_LIBRARY_PATH} cmake .. -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DENABLE_DAP=TRUE -DENABLE_HDF5=TRUE -DENABLE_NCZARR=TRUE -DENABLE_DAP_LONG_TESTS=TRUE -DENABLE_XML2=FALSE
- name: Print Summary
shell: bash -l {0}
Expand Down
10 changes: 2 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,17 @@ CFLAGS="$SAVECFLAGS"
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])])
[disable detection and use of libxml2 in favor of the bundled xml parser])])
test "x$enable_libxml2" = xno || enable_libxml2=yes
AC_MSG_RESULT([$enable_libxml2])


# We can optionally use libxml2 for DAP4 and nch5comms, if enabled
have_libxml2=no
if test "x$enable_libxml2" = xyes; then
AC_CHECK_PROGS([NC_XML2_CONFIG], [xml2-config])
if test -z "$NC_XML2_CONFIG"; then
AC_MSG_ERROR([Cannot find xml2-config utility. Either install the libxml2 development package, or re-run configure with --disable-libxml2 to use the bundled xml2 parser])
fi
# We can optionally use libxml2 for DAP4 and nch5comms, if enabled
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], [],[])
Expand Down Expand Up @@ -1256,11 +1255,6 @@ if test "x$enable_hdf5" = "xno" ; then
enable_dap4=no
fi

if test "x$ISOSX" = xyes && test "x$have_libxml2" = xno && test "x$enable_dap4" = xyes ; then
AC_MSG_WARN([OSX requires libxml2 for DAP4 support; disabling DAP4])
enable_dap4=no
fi

if test "x$enable_dap4" = xyes; then
AC_DEFINE([ENABLE_DAP4], [1], [if true, build DAP4 Client])
fi
Expand Down
35 changes: 21 additions & 14 deletions libncxml/tinyxml2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,17 @@ distribution.
#if defined(_WIN64)
#define TIXML_FSEEK _fseeki64
#define TIXML_FTELL _ftelli64
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
|| defined(__NetBSD__) || defined(__DragonFly__) || defined(__ANDROID__)
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || (__CYGWIN__)
#define TIXML_FSEEK fseeko
#define TIXML_FTELL ftello
#elif defined(__ANDROID__)
#if __ANDROID_API__ > 24
#define TIXML_FSEEK fseeko64
#define TIXML_FTELL ftello64
#else
#define TIXML_FSEEK fseeko
#define TIXML_FTELL ftello
#endif
#elif defined(__unix__) && defined(__x86_64__)
#define TIXML_FSEEK fseeko64
#define TIXML_FTELL ftello64
Expand Down Expand Up @@ -1077,7 +1084,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
StrPair endTag;
p = node->ParseDeep( p, &endTag, curLineNumPtr );
if ( !p ) {
DeleteNode( node );
_document->DeleteNode( node );
if ( !_document->Error() ) {
_document->SetError( XML_ERROR_PARSING, initialLineNum, 0);
}
Expand Down Expand Up @@ -1110,7 +1117,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
}
if ( !wellLocated ) {
_document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value());
DeleteNode( node );
_document->DeleteNode( node );
break;
}
}
Expand Down Expand Up @@ -1145,7 +1152,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
}
if ( mismatch ) {
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name());
DeleteNode( node );
_document->DeleteNode( node );
break;
}
}
Expand Down Expand Up @@ -1777,11 +1784,11 @@ XMLError XMLElement::QueryInt64Text(int64_t* ival) const
}


XMLError XMLElement::QueryUnsigned64Text(uint64_t* ival) const
XMLError XMLElement::QueryUnsigned64Text(uint64_t* uval) const
{
if(FirstChild() && FirstChild()->ToText()) {
const char* t = FirstChild()->Value();
if(XMLUtil::ToUnsigned64(t, ival)) {
if(XMLUtil::ToUnsigned64(t, uval)) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
Expand Down Expand Up @@ -2413,21 +2420,21 @@ XMLError XMLDocument::SaveFile( FILE* fp, bool compact )
}


XMLError XMLDocument::Parse( const char* p, size_t len )
XMLError XMLDocument::Parse( const char* xml, size_t nBytes )
{
Clear();

if ( len == 0 || !p || !*p ) {
if ( nBytes == 0 || !xml || !*xml ) {
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
return _errorID;
}
if ( len == static_cast<size_t>(-1) ) {
len = strlen( p );
if ( nBytes == static_cast<size_t>(-1) ) {
nBytes = strlen( xml );
}
TIXMLASSERT( _charBuffer == 0 );
_charBuffer = new char[ len+1 ];
memcpy( _charBuffer, p, len );
_charBuffer[len] = 0;
_charBuffer = new char[ nBytes+1 ];
memcpy( _charBuffer, xml, nBytes );
_charBuffer[nBytes] = 0;

Parse();
if ( Error() ) {
Expand Down
10 changes: 5 additions & 5 deletions libncxml/tinyxml2.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ distribution.
#if defined(TINYXML2_DEBUG)
# if defined(_MSC_VER)
# // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
# define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
# define TIXMLASSERT( x ) do { if ( !((void)0,(x))) { __debugbreak(); } } while(false)
# elif defined (ANDROID_NDK)
# include <android/log.h>
# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
# define TIXMLASSERT( x ) do { if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } } while(false)
# else
# include <assert.h>
# define TIXMLASSERT assert
# endif
#else
# define TIXMLASSERT( x ) {}
# define TIXMLASSERT( x ) do {} while(false)
#endif
#endif

Expand All @@ -112,7 +112,7 @@ static const int TIXML2_PATCH_VERSION = 0;
// system, and the capacity of the stack. On the other hand, it's a trivial
// attack that can result from ill, malicious, or even correctly formed XML,
// so there needs to be a limit in place.
static const int TINYXML2_MAX_ELEMENT_DEPTH = 100;
static const int TINYXML2_MAX_ELEMENT_DEPTH = 500;

namespace tinyxml2
{
Expand Down Expand Up @@ -375,7 +375,7 @@ class MemPoolT : public MemPool
virtual void* Alloc() {
if ( !_root ) {
// Need a new block.
Block* block = new Block();
Block* block = new Block;
_blockPtrs.Push( block );

Item* blockItems = block->items;
Expand Down

0 comments on commit 8887b5b

Please sign in to comment.