xsltsaxon-c

Why is my xslt code causing saxonc to bomb?


I keep getting this error. I'm doing a loop and calling my xslt.transform() method (see listing) about 3 times in a row. It bombs about 50% of the time trying to make it to the end of the loop.

My question is, what is wrong with my code? Am I not calling a method needed to reset the new_xslt30_processor or reset the PySaxonProcessor between each loop? It tends to work the first time through, so that's my hunch. I'm not cleaning up something.

JET RUNTIME HAS DETECTED UNRECOVERABLE ERROR: runtime error Thread C8B63 ["Thread-0"] is terminated without notifying the JVM. Probably, "DetachCurrentThread" function was not called Please, contact the vendor of the application. Core dump will be piped to "/lib/systemd/systemd-coredump %P %u %g %s %t 9223372036854775808 %h" Extra information about error is saved in the "jet_err_822032.txt" file.

xslt.py

import os
import saxonc

from typing import Dict, List

class Xslt():

  @classmethod
  def transform(cls, xsl_file: str, xml_file: str, output_file: str, parameters: Dict[str,str]) -> bool:
    try:
      out = cls.transform_to_string(xsl_file, xml_file, parameters)
      with open(output_file, "w") as f:
        f.write(out)
      return True
    except Exception as e:
      print(str(e))
      return False

  @classmethod
  def transform_to_string(cls, xsl_file: str, xml_file: str, parameters: Dict[str,str]) -> str:
    with saxonc.PySaxonProcessor(license=True) as saxonproc:
      xsltproc = saxonproc.new_xslt30_processor()
      for parameter in parameters:
        xsltproc.set_parameter(parameter, saxonproc.make_string_value(parameters[parameter]))
      saxonproc.set_cwd(os.getcwd())
      return xsltproc.transform_to_string(source_file=xml_file, stylesheet_file=xsl_file)

Output

Error: failed to allocate an object - please check if an exception was thrown proc is nullptr in SaxonProcessor constructor Error: failed to allocate an object - please check if an exception was thrown Error: failed to allocate an object - please check if an exception was thrown Error: failed to allocate an object - please check if an exception was thrown Error: Xslt30Processor not in a clean state. - Exception found

╭─ bash   SaxonHE11-4J  羽393ms⠀                                                   11.0.16     toddmo  104.5.65.251
╰─ff java -cp saxon-he-11.4.jar net.sf.saxon.Version
SAXON-J-HE 11.4 from Saxonica (build 72811)

Solution

  • OK calling clear_parameters in the last part of transform_to_string appears to fix it:

    result = xsltproc.transform_to_string(source_file=xml_file, stylesheet_file=xsl_file)
    xsltproc.clear_parameters()
    return result
    

    Python is de-allocating the parameters at the end of the function call but saxonc is relying on re-using those if the routine is called multiple times. Clearing the parameters tells saxonc to make them from scratch during each iteration, or each call (my loop is higher up in the call chain).

    There still might be a bug, so I'll try to post this in the Saxonica forum as an issue soon.