Skip to content

Update regression tests to handle Apple's local patching of libxml2#94

Open
nwc10 wants to merge 5 commits intoshlomif:masterfrom
nwc10:nicholas/RT165193
Open

Update regression tests to handle Apple's local patching of libxml2#94
nwc10 wants to merge 5 commits intoshlomif:masterfrom
nwc10:nicholas/RT165193

Conversation

@nwc10
Copy link
Copy Markdown
Contributor

@nwc10 nwc10 commented Feb 20, 2026

This MR builds on the commits in #87

Probably that MR should be merged, then this branch rebased on the merge commit

t/13dtd.t and t/50devel.t both fail on macOS because Apple have made local patches to their version of libxml2, which I believe to be v2.9.13. Apple have published their changes at https://github.com/apple-oss-distributions/libxml2

Apple's libxml2 throws an error in xmlSAX2ResolveEntity if URI is NULL. t/13dtd.t tests this case, but assumes the upstream behaviour of that C code returning NULL and hence XML::LibXML::Dtd->new("",""); returning undef

Handle the Apple variant behaviour, rather than having the test script die. I'm fine with this Perl-space behaviour for the corner case being "implementation defined", rather than trying to work around the OS patching, given that the original bug report from 2004 was closed as

NOT A BUG but a misunderstanding of the package.

https://rt.cpan.org/Public/Bug/Display.html?id=2021

well before t/13dtd.t was written.

The failure of t/50devel.t is messier. The tests that fail are the three instances of cmp_ok(mem_used(), '>', mem_before);

This turns out to be because mem_used() is now always reporting 0 - 0 bytes allocated. Upstream libxml2 vectors all allocation through functions in xmlmemory.c, and uses a static variable to record total allocation. Hence in xmlMallocLoc and similar functions about 20 lines in we have

    debugMemSize += size;
    debugMemBlocks++;

and then there is this function to read it

int
Xmlmemused(void) {
    int res;

    xmlMutexLock(xmlMemMutex);
    res = debugMemSize;
    xmlMutexUnlock(xmlMemMutex);
    return(res);
}

exposed to Perl space as mem_used

In their patched xmlmemory.h they have this:

+#if defined(LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS)
+#define xmlMemMalloc(size) malloc(size)
+#define xmlMemRealloc(ptr, size) realloc(ptr, size)
+#define xmlMemFree(ptr) free(ptr)
+#define xmlMemoryStrdup(str) strdup(str)
+
+#define xmlMallocLoc(size, file, line) malloc(size)
+#define xmlReallocLoc(ptr, size, file, line) realloc((ptr), (size))
+#define xmlMallocAtomicLoc(size, file, line) malloc(size)
+#define xmlMemStrdupLoc(str, file, line) strdup(str)
+#endif
+

and in xmlmemory.c changes such as this:

@@ -161,6 +177,11 @@ xmlMallocBreakpoint(void) {
 void *
 xmlMallocLoc(size_t size, const char * file, int line)
 {
+#ifdef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS
+    if (linkedOnOrAfter2024EReleases())
+        return malloc(size);
+#endif
+
     MEMHDR *p;
     void *ret;

see apple-oss-distributions/libxml2@5d4e3a3#diff-51ff3727803a305d66aca10db9fa81b1bdb2d5e3d201e99661df23df80f14af8 and apple-oss-distributions/libxml2@5d4e3a3#diff-66a9bd352f0152960995cc8bfe359e35d7d03c0023705b26f84e919590d7a518

suggesting that there are both compile time and run time tests to determine whether to shortcut the wrapper.

The upshot is that

  1. the wrapper is now ignored
  2. debugMemSize is never updated
  3. mem_used always returns 0

Hence I propose that we just skip the test if xmlMemUsed returns 0, as it's clearly inaccurate that there is no memory allocated, and it seems to be the easiest way to code a skip.

nwellnhof and others added 5 commits June 25, 2024 19:02
Line numbers are always enabled since libxml2 2.15.0.
Apple have patched their libxml2 to call the system malloc etc directly,
bypassing libxml2's wrappers that track memory usage. The reporting
function xmlMemUsed remains, but it always returns 0.

This regression test is validating that memory is allocated at the expected
time, and is correctly released at the expected time. It was added back in
2014 and is untouched since then,

As it's not possible to run it without memory stats, simply skip it.
t/13dtd.t tests this case, but assumes the upstream behaviour of that C code
returning NULL and hence XML::LibXML::Dtd->new("",""); returning undef

Handle the Apple variant behaviour, rather than having the test script die.
I'm fine with this Perl-space behaviour for the corner case being
"implementation defined", rather than trying to work around the OS patching,
given that the original bug report from 2004 was closed as

    NOT A BUG but a misunderstanding of the package.

https://rt.cpan.org/Public/Bug/Display.html?id=2021

before the test was written.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants