Skip to main content

Module context

Module context 

Source
Expand description

XPath 1.0 Evaluation Context (§25).

The evaluation context holds the state required to evaluate an XPath expression: the current document, context node, context position/size, variable bindings, namespace declarations, registered extension functions, and recursion-depth tracking.

§UPSTREAM-PARITY

Mirrors xmlXPathContext from libxml2 with additional Rust-side state for variable/function resolution and safe recursion guards.

§Courts

XPATH-CONTEXT-*

§Upstream contract

Mirrors xmlXPathContext (xpath.c / xpathInternals.h, SRC-LIBXML2-2.15.0-XPATH-C, parity target libxml2 2.15.3 oracle): context node/document, position/size, variable and function registries, namespace scope, the C var/function lookup hooks, and the opLimit/ opCount fields (R-000128 fixed their widths in the C mirror).

§Conceptual behavior

Holds the state an evaluation needs: current document, context node, context position/size, variable bindings, namespace declarations, registered extension functions and recursion-depth tracking. The C function bridge (R-000162) synthesizes an xmlXPathParserContext around the value stack, pushes evaluated args, invokes the registered C function and converts its result back — including the namespaced function_lookup fallback the XSLT engine uses for prefix:local calls.

§Ownership & safety invariants

Callback user-data pointers (var_lookup_data / func_lookup_data) are stored verbatim and passed back — the caller keeps them alive (OWNERSHIP_ATLAS §6). A VarLookupFunc returning an _xmlXPathObject transfers ownership to the caller. Context state is single-threaded per evaluation; the recursion guard bounds nesting.

§Historical quirks & epochs

R-000162: the C XPath function registry was a stub that always errored (‘C extension function cannot be called’) until the 11.1-L callback audit built the parser-context bridge — registered functions now run with oracle-verified semantics. The recursion guard mirrors upstream depth handling introduced in the hardening epochs (SEC-0001 lineage).

§Deliberate oddities

The synthesized parser context is an internal adapter, not the full upstream xmlXPathParserContext: only the value-stack operations that C extension functions observe are modeled.

§Proving courts

XPATH-CONTEXT-* and CALLBACK-001 (courts/suites/data-abi/callback- family-probe.c) verify registered C function invocation byte-identical against the oracle; cargo test covers variable/function resolution.

§Tempting simplifications that would break parity

Do not drop the C-callback bridge back to a Rust-only registry: XSLT extension functions and C consumers register raw function pointers through xmlXPathRegisterFunc/xmlXPathRegisterFuncNS and observe them firing (R-000162). Do not remove the recursion guard — deep expressions must fail like the oracle, not overflow the stack.

Structs§

XPathContext
XPath 1.0 evaluation context.

Constants§

XPATH_CONTEXT_SIGNATURE
First 8 bytes of every internal XPathContext allocation. C-interop helpers that receive a _xmlXPathContext whose extra slot may hold either the internal Rust context (engine rule) or a transform context (upstream libxslt stores the xsltTransformContext there — php reads ctxt->context->extra directly) inspect this to tell the two apart.

Functions§

has_signature
True when ptr points at an internal XPathContext allocation (the engine stores one in _xmlXPathContext.extra). False when it points at an upstream-layout xsltTransformContext in the same slot (the XSLT extension-function mirror bridge) or at anything else.

Type Aliases§

BoxedXPathFunction
A boxed, capture-capable XPath function implementation.
FuncLookupFunc
C callback for function lookup.
FunctionLookupFn
A namespaced function-lookup fallback: consulted by lookup_function after the exact-name registry misses, so engines (XSLT) can resolve prefix:local(...) calls against their own extension registries.
VarLookupFunc
C callback for variable lookup.
XPathFunction
XPath extension function signature.