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§
- XPath
Context - XPath 1.0 evaluation context.
Constants§
- XPATH_
CONTEXT_ SIGNATURE - First 8 bytes of every internal
XPathContextallocation. C-interop helpers that receive a_xmlXPathContextwhoseextraslot may hold either the internal Rust context (engine rule) or a transform context (upstream libxslt stores thexsltTransformContextthere — php readsctxt->context->extradirectly) inspect this to tell the two apart.
Functions§
- has_
signature - True when
ptrpoints at an internalXPathContextallocation (the engine stores one in_xmlXPathContext.extra). False when it points at an upstream-layoutxsltTransformContextin the same slot (the XSLT extension-function mirror bridge) or at anything else.
Type Aliases§
- BoxedX
Path Function - A boxed, capture-capable XPath function implementation.
- Func
Lookup Func - C callback for function lookup.
- Function
Lookup Fn - A namespaced function-lookup fallback: consulted by
lookup_functionafter the exact-name registry misses, so engines (XSLT) can resolveprefix:local(...)calls against their own extension registries. - VarLookup
Func - C callback for variable lookup.
- XPath
Function - XPath extension function signature.