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

VM opcode snippet for parsing XML text into a document handle. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 if (!xml_inited)
 free_value (vtext)
 free (text)
 if (doc)
 push_value (vm, make_int(h))

Variables

case OP_XML_PARSE
Value vtext = pop_value(vm)
char * text = value_to_string_alloc(&vtext)
xmlDocPtr doc = xmlReadMemory(text, (int)strlen(text), NULL, NULL, XML_PARSE_NONET)
int h = 0
 break

Detailed Description

VM opcode snippet for parsing XML text into a document handle.

This snippet is included by vm.c and implements OP_XML_PARSE.

Opcode: OP_XML_PARSE

  • Stack effect: pop (string xml_text) → push (int doc_handle | 0)
  • Behavior: Parses the given XML string into an in-memory xmlDoc. On success, a positive document handle is allocated via the XML handle registry and pushed. On failure (malformed XML, OOM), 0 is pushed.
  • Initialization: Ensures libxml2 is initialized once (xmlInitParser()).
  • Gating: If FUN_WITH_XML2 is disabled, the input is discarded and 0 is pushed.

Notes

  • The handle must later be released via appropriate XML VM opcodes that free documents; leaking handles will leak memory.
  • The parser is invoked with XML_PARSE_NONET to disallow network access.

Example

  • stack: [ "<root/>" ]
  • OP_XML_PARSE → [ 1 ] (example handle)

Definition in file parse.c.

Function Documentation

◆ free()

free ( text )

◆ free_value()

free_value ( vtext )

◆ if() [1/2]

if ( ! xml_inited)

Definition at line 39 of file parse.c.

◆ if() [2/2]

if ( doc )

Definition at line 53 of file parse.c.

◆ push_value()

push_value ( vm ,
make_int(h)  )

Variable Documentation

◆ break

break

Definition at line 65 of file parse.c.

◆ doc

xmlDocPtr doc = xmlReadMemory(text, (int)strlen(text), NULL, NULL, XML_PARSE_NONET)

Definition at line 50 of file parse.c.

◆ h

int h = 0

Definition at line 52 of file parse.c.

◆ OP_XML_PARSE

case OP_XML_PARSE

Definition at line 36 of file parse.c.

◆ text

char* text = value_to_string_alloc(&vtext)

Definition at line 44 of file parse.c.

◆ vtext

Value vtext = pop_value(vm)

Definition at line 43 of file parse.c.