Skip to content

Extract XML::Document from XML::Node #15920

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Jun 23, 2025

Introduces the XML::Document type to wrap a LibXML::Doc*, while XML::Node is meant to wrap the subtree LibXML::Node*.

The XML::Document inherits from XML::Node and acts exactly like a XML::Node, so it should hopefully be a transparent change (no breaking changes).

The main advantage is that we now register a single finalizer instead of one for every node (only the document needed a finalizer).

Sadly, it doesn't allow to have a dual strong reference from a document to its nodes, and from the nodes to their document. Boehm GC still complains about cyclic finalization, despite only the document having a finalizer.

Follow up to #15906
Related to #15915

Introduces the XML::Document type to wrap a Pointer(LibXML::Doc), while
XLM::Node is meant to wrap the subtree Pointer(LibXML::Node). The
XML::Document inherits from XML::Node and acts exactly like a XML::Node,
so it should hopefully be a transparent change.

The main advantage is that we now register a single finalizer instead of
one for every node (only the document needed a finalizer). Sadly, it
doesn't allow to have a dual strong reference from a document to its
nodes, and from the nodes to their document. Boehm GC still complains
about cyclic finalization, despite only the document having a
finalizer.
@ysbaddaden ysbaddaden force-pushed the feature/add-xml-document-type branch from c5791a6 to 210a1c8 Compare June 26, 2025 16:43
@ysbaddaden ysbaddaden marked this pull request as ready for review June 26, 2025 16:45
@document
# Gets the document for this node.
def document : Document
@document.as(Document)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why is @document even nilable in the first place?
If it must be, perhaps we could have better error messages in case something breaks down with .not_nil! or perhaps getter! document?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Document < Node, doesn't set @document and simply overrides the method to return self. Yes, getter! would be better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not @document = self?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants