Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
xml2.c File Reference

Lightweight libxml2 handle registry for Fun VM extension helpers. More...

#include <libxml/parser.h>
#include <libxml/tree.h>
Include dependency graph for xml2.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  XmlDocSlot
 Slot describing a registered XML document. More...
struct  XmlNodeSlot
 Slot describing a registered XML node. More...

Functions

static int xml_doc_alloc (xmlDocPtr d)
 Allocate a document handle for the given xmlDoc pointer.
static xmlDocPtr xml_doc_get (int h)
 Retrieve a registered xmlDoc by handle.
static int xml_doc_free_handle (int h)
 Free a document handle and the underlying xmlDoc.
static int xml_node_alloc (xmlNodePtr n)
 Allocate a node handle for the given xmlNode pointer.
static xmlNodePtr xml_node_get (int h)
 Retrieve a registered xmlNode by handle.
static int xml_node_free_handle (int h)
 Free a node handle without freeing the underlying node.

Variables

static XmlDocSlot g_xml_docs [64]
static XmlNodeSlot g_xml_nodes [256]

Detailed Description

Lightweight libxml2 handle registry for Fun VM extension helpers.

This module provides small fixed-size registries for libxml2 objects when compiled with FUN_WITH_XML2. Documents and nodes can be associated with small integer handles to make them easier to pass around inside the interpreter and its C API boundaries. The document registry owns the underlying xmlDoc, while the node registry does not own the xmlNode — nodes are freed when their owning document is freed.

Limits: The registries are fixed-size (docs: 64, nodes: 256). Handle value 0 is reserved and indicates failure/invalid.

Thread-safety: Not thread-safe. Coordinate access externally if needed.

Definition in file xml2.c.

Function Documentation

◆ xml_doc_alloc()

int xml_doc_alloc ( xmlDocPtr d)
static

Allocate a document handle for the given xmlDoc pointer.

Parameters
dValid xmlDocPtr to register. Ownership is transferred to the registry, which will xmlFreeDoc() it when the handle is freed.
Returns
Positive handle in the range [1, 63] on success; 0 if no slot is available.

Definition at line 62 of file xml2.c.

◆ xml_doc_free_handle()

int xml_doc_free_handle ( int h)
static

Free a document handle and the underlying xmlDoc.

Parameters
hHandle to release.
Returns
1 if the handle was valid and has been released; 0 otherwise.

Definition at line 88 of file xml2.c.

◆ xml_doc_get()

xmlDocPtr xml_doc_get ( int h)
static

Retrieve a registered xmlDoc by handle.

Parameters
hHandle previously returned by xml_doc_alloc().
Returns
xmlDocPtr if the handle is valid and in use; NULL otherwise.

Definition at line 78 of file xml2.c.

◆ xml_node_alloc()

int xml_node_alloc ( xmlNodePtr n)
static

Allocate a node handle for the given xmlNode pointer.

Parameters
nValid xmlNodePtr to register. Ownership is NOT transferred; nodes are managed by their owning document.
Returns
Positive handle in the range [1, 255] on success; 0 if no slot is available.

Definition at line 104 of file xml2.c.

◆ xml_node_free_handle()

int xml_node_free_handle ( int h)
static

Free a node handle without freeing the underlying node.

Nodes are owned by their document; releasing the document invalidates any associated node handles.

Parameters
hHandle to release.
Returns
1 if the handle was valid and has been released; 0 otherwise.

Definition at line 133 of file xml2.c.

◆ xml_node_get()

xmlNodePtr xml_node_get ( int h)
static

Retrieve a registered xmlNode by handle.

Parameters
hHandle previously returned by xml_node_alloc().
Returns
xmlNodePtr if the handle is valid and in use; NULL otherwise.

Definition at line 120 of file xml2.c.

Variable Documentation

◆ g_xml_docs

XmlDocSlot g_xml_docs[64]
static

Definition at line 51 of file xml2.c.

◆ g_xml_nodes

XmlNodeSlot g_xml_nodes[256]
static

Definition at line 52 of file xml2.c.