Skip to content

fix: clear attribute PSVI and use xmlBuffer API in dom.c - #290

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-domclearpsvi-and-buffer-api
Draft

toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-domclearpsvi-and-buffer-api

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

What

Fix dead code in domClearPSVI that prevented attribute PSVI clearing, and modernize xmlBuffer access in domGetNodeValue.

Why

domClearPSVI at line 33 checked tree->type == XML_ATTRIBUTE_NODE inside a block guarded by tree->type == XML_ELEMENT_NODE — the condition was always false. Attribute psvi pointers were never cleared between schema revalidations, leaving stale/dangling pointers.

The buffer->content direct field access in domGetNodeValue works on current libxml2 but will fail if the struct is made opaque (as upstream has been moving toward since 2.12). The rest of the codebase already uses xmlBufferContent()/xmlBufferLength().

How

  • Removed the dead type check; attributes in the properties list always have XML_ATTRIBUTE_NODE type, so clear psvi unconditionally.
  • Replaced buffer->content with xmlBufferContent(buffer) and the NULL check with xmlBufferLength(buffer) > 0.
  • Added a revalidation test with typed attributes to exercise the PSVI clearing path.

Testing

Full test suite passes. New test in t/26schema.t validates a document with typed attributes twice in succession.


Quality Report

Changes: 2 files changed, 40 insertions(+), 6 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan

domClearPSVI checked tree->type == XML_ATTRIBUTE_NODE inside a block
where tree->type was already known to be XML_ELEMENT_NODE, making the
condition always false. Attribute psvi pointers were never cleared,
leaving stale/dangling pointers after schema revalidation.

Also replace direct buffer->content field access in domGetNodeValue
with xmlBufferContent()/xmlBufferLength() API calls, matching the
style used throughout LibXML.xs and perl-libxml-mm.c. The direct
field access would fail if libxml2 makes xmlBuffer opaque.
@nwellnhof

Copy link
Copy Markdown
Contributor

Note that #273 addresses the buffer API issue more comprehensively.

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