From a4a420eedcc5426f67b8ed64bbf88f70fce53963 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 21 Feb 2024 12:53:03 +0100 Subject: [PATCH 1/2] Autotools: Turn libexpatinternal.la into standalone library .. so that we can now have code in say xmlparse.c that does not end up in libexpat.so but still runs when executing the test suite. --- expat/lib/Makefile.am | 15 +++++++-------- expat/tests/Makefile.am | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/expat/lib/Makefile.am b/expat/lib/Makefile.am index 0e0185b5..1ecb8fa2 100644 --- a/expat/lib/Makefile.am +++ b/expat/lib/Makefile.am @@ -36,7 +36,9 @@ include_HEADERS = \ expat_external.h lib_LTLIBRARIES = libexpat.la -noinst_LTLIBRARIES = libexpatinternal.la +if WITH_TESTS +noinst_LTLIBRARIES = libtestpat.la +endif libexpat_la_LDFLAGS = \ @AM_LDFLAGS@ \ @@ -44,17 +46,14 @@ libexpat_la_LDFLAGS = \ -no-undefined \ -version-info @LIBCURRENT@:@LIBREVISION@:@LIBAGE@ -libexpat_la_SOURCES = - -# This layer of indirection allows -# the test suite to access internal symbols -# despite compiling with -fvisibility=hidden -libexpatinternal_la_SOURCES = \ +libexpat_la_SOURCES = \ xmlparse.c \ xmltok.c \ xmlrole.c -libexpat_la_LIBADD = libexpatinternal.la +if WITH_TESTS +libtestpat_la_SOURCES = $(libexpat_la_SOURCES) +endif doc_DATA = \ ../AUTHORS \ diff --git a/expat/tests/Makefile.am b/expat/tests/Makefile.am index f949fe7f..97da3bf6 100644 --- a/expat/tests/Makefile.am +++ b/expat/tests/Makefile.am @@ -72,8 +72,8 @@ runtests_cxx_SOURCES = \ runtests_cxx.cpp \ structdata_cxx.cpp -runtests_LDADD = ../lib/libexpatinternal.la -runtests_cxx_LDADD = ../lib/libexpatinternal.la +runtests_LDADD = ../lib/libtestpat.la +runtests_cxx_LDADD = ../lib/libtestpat.la runtests_LDFLAGS = @AM_LDFLAGS@ @LIBM@ runtests_cxx_LDFLAGS = @AM_LDFLAGS@ @LIBM@ From 7e2a0da9ba6581c073484ff400a98fd4037b5c73 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 21 Feb 2024 12:53:48 +0100 Subject: [PATCH 2/2] lib: Hide some test-only code behind new macro XML_TESTING --- expat/CMakeLists.txt | 2 ++ expat/apply-clang-tidy.sh | 1 + expat/lib/Makefile.am | 2 ++ expat/lib/internal.h | 10 ++++++++-- expat/lib/xmlparse.c | 12 ++++++++++-- expat/tests/Makefile.am | 2 +- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/expat/CMakeLists.txt b/expat/CMakeLists.txt index dd793188..6649d769 100644 --- a/expat/CMakeLists.txt +++ b/expat/CMakeLists.txt @@ -676,6 +676,8 @@ if(EXPAT_BUILD_TESTS) ) foreach(_target ${_EXPAT_TEST_TARGETS}) + target_compile_definitions(${_target} PRIVATE -DXML_TESTING) + set_property(TARGET ${_target} PROPERTY RUNTIME_OUTPUT_DIRECTORY tests) expat_add_test(${_target} $) diff --git a/expat/apply-clang-tidy.sh b/expat/apply-clang-tidy.sh index 2e520bd0..17015f6c 100755 --- a/expat/apply-clang-tidy.sh +++ b/expat/apply-clang-tidy.sh @@ -68,6 +68,7 @@ flags=( -DXML_DTD -DXML_GE -DXML_NS + -DXML_TESTING ) if [[ $# -gt 0 ]]; then diff --git a/expat/lib/Makefile.am b/expat/lib/Makefile.am index 1ecb8fa2..f32430ab 100644 --- a/expat/lib/Makefile.am +++ b/expat/lib/Makefile.am @@ -52,6 +52,8 @@ libexpat_la_SOURCES = \ xmlrole.c if WITH_TESTS +libtestpat_la_CPPFLAGS = -DXML_TESTING + libtestpat_la_SOURCES = $(libexpat_la_SOURCES) endif diff --git a/expat/lib/internal.h b/expat/lib/internal.h index cdbd3609..81db8955 100644 --- a/expat/lib/internal.h +++ b/expat/lib/internal.h @@ -161,8 +161,14 @@ unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser); const char *unsignedCharToPrintable(unsigned char c); #endif -extern XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c -extern unsigned int g_bytesScanned; // used for testing only +extern +#if ! defined(XML_TESTING) + const +#endif + XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c +#if defined(XML_TESTING) +extern unsigned int g_bytesScanned; // used for testing only +#endif #ifdef __cplusplus } diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c index 63fcaa92..0451e693 100644 --- a/expat/lib/xmlparse.c +++ b/expat/lib/xmlparse.c @@ -629,8 +629,14 @@ static unsigned long getDebugLevel(const char *variableName, ? 0 \ : ((*((pool)->ptr)++ = c), 1)) -XML_Bool g_reparseDeferralEnabledDefault = XML_TRUE; // write ONLY in runtests.c -unsigned int g_bytesScanned = 0; // used for testing only +#if ! defined(XML_TESTING) +const +#endif + XML_Bool g_reparseDeferralEnabledDefault + = XML_TRUE; // write ONLY in runtests.c +#if defined(XML_TESTING) +unsigned int g_bytesScanned = 0; // used for testing only +#endif struct XML_ParserStruct { /* The first member must be m_userData so that the XML_GetUserData @@ -1017,7 +1023,9 @@ callProcessor(XML_Parser parser, const char *start, const char *end, return XML_ERROR_NONE; } } +#if defined(XML_TESTING) g_bytesScanned += (unsigned)have_now; +#endif const enum XML_Error ret = parser->m_processor(parser, start, end, endPtr); if (ret == XML_ERROR_NONE) { // if we consumed nothing, remember what we had on this parse attempt. diff --git a/expat/tests/Makefile.am b/expat/tests/Makefile.am index 97da3bf6..e1ab9f8c 100644 --- a/expat/tests/Makefile.am +++ b/expat/tests/Makefile.am @@ -32,7 +32,7 @@ SUBDIRS = . benchmark -AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib +AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib -DXML_TESTING check_PROGRAMS = runtests runtests_cxx TESTS = runtests runtests_cxx