Project

Profile

Help

Bug #5533

closed

segfault when setting xslt parameter in a loop

Added by Lou Burnard 3 months ago. Updated 22 days ago.

Status:
Closed
Priority:
Normal
Category:
Python
Start date:
2022-05-23
Due date:
% Done:

100%

Estimated time:
Found in version:
11.3
Fixed in version:
11.4
Platforms:

Description

my python code looks like this:

`import saxonc
with saxonc.PySaxonProcessor(license=False) as proc:
    print(proc.version)
    proc.set_configuration_property("xi", "on")
    xdmAtomicval = proc.make_boolean_value(False)
    xsltproc = proc.new_xslt30_processor()
    for LANG in LANGS:
      repoName=repoRoot+LANG
      print("Summarizing repo "+repoName+ " on "+lastUpdate)
      params=' corpus='+LANG + ' lastUpdate='+ lastUpdate
      xsltproc.set_parameter("corpus",proc.make_string_value(LANG)) 
      xsltproc.set_parameter("lastUpdate",proc.make_string_value(lastUpdate))
      src=repoName + "/driver.tei" 
      result = xsltproc.transform_to_string(source_file=src, stylesheet_file=scriptRoot+"summarize.xsl")
      print(result) `

The first time round the loop everything works correctly. But the second iteration (no matter what the input data) always leads to a core dump and the message

`JET RUNTIME HAS DETECTED UNRECOVERABLE ERROR: system exception at 0x00007ff0557820f4
Please, contact the vendor of the application.
Core dump will be written to "/home/lou/Public/Scripts/core"
Extra information about error is saved in the "jet_err_31824.txt" file.`

If I comment out the two invocations of xsltproc.set_parameter everything works fine (or as well as it can without the parameter values)

The jet_err file is attached in the hope that you can spot what is going wrong, or advise me how to pin it down!


Files

jet_err_31748.txt (93.4 KB) jet_err_31748.txt diagnostics from jet Lou Burnard, 2022-05-23 15:21
summarize2.py (1.59 KB) summarize2.py Lou Burnard, 2022-05-23 17:55
summarize.xsl (16.5 KB) summarize.xsl Lou Burnard, 2022-05-23 17:55

Related issues

Related to SaxonC - Bug #4386: setProperty and setParameter does not replace keys already in the mapClosedO'Neil Delpratt2019-11-15

Actions
Related to SaxonC - Bug #5542: Python example causes segmentation errorClosedO'Neil Delpratt2022-05-26

Actions
Actions #1

Updated by O'Neil Delpratt 3 months ago

  • Category set to Python
  • Assignee set to O'Neil Delpratt
  • Priority changed from Low to Normal
  • Found in version set to 11.3

This looks like a bug. Thanks for reporting it.

For the make_string_value it looks like python is deleting the object created at the end of the loop thinking that the object is not used again.

As a workaround, for the following code:

      xsltproc.set_parameter("corpus",proc.make_string_value(LANG)) 
      xsltproc.set_parameter("lastUpdate",proc.make_string_value(lastUpdate))

Is it possible to replace it as follows:

      XDM_LANG= proc.make_string_value(LANG)
      xdm_lastUpdate = proc.make_string_value(lastUpdate)
      xsltproc.set_parameter("corpus", XDM_LANG) 
      xsltproc.set_parameter("lastUpdate",xdm_lastUpdate)

I will try to create a repo, but is it possible you can supply the stylesheet please so that I can investigate it further?

Actions #2

Updated by Lou Burnard 3 months ago

Excellent! That work around seems to have been successful. Many thanks for the quick turnround, and good luck hunting down the bug. I am attaching my current version of the python code and the style sheet it invokes, since you asked for it, though they won't make much sense without all the other bits and pieces.

Actions #3

Updated by O'Neil Delpratt 3 months ago

Alternatively, you can call clear_parameters on the PyXslt30Processor at the end of the for loop. This is the recommended practice.

See the example below:

    for LANG in LANGS:
      repoName=repoRoot+LANG
      print("Summarizing repo "+repoName+ " on "+lastUpdate)
      params=' corpus='+LANG + ' lastUpdate='+ lastUpdate
      xsltproc.set_parameter("corpus",proc.make_string_value(LANG)) 
      xsltproc.set_parameter("lastUpdate",proc.make_string_value(lastUpdate))
      src=repoName + "/driver.tei" 
      result = xsltproc.transform_to_string(source_file=src, stylesheet_file=scriptRoot+"summarize.xsl")
      print(result) 
      xsltproc.clear_parameter()
Actions #4

Updated by O'Neil Delpratt 3 months ago

  • Related to Bug #4386: setProperty and setParameter does not replace keys already in the map added
Actions #5

Updated by O'Neil Delpratt 3 months ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Bug fixed in the Xslt30Processor and across other Processors too. There is a regression from bug issue #4386. The check for existing keys in the map failed. This has now been patched and available for the next maintenance release.

The workaround in comment #3 avoids the crash. Also as a speed improvement, I recommend compiling the stylesheet to a PyXsltExecutable object before the for loop, which can then be reused. See below:

    executable = xsltproc.compile_stylesheet(stylesheet_file=scriptRoot+"summarize.xsl")
    for LANG in LANGS:
      repoName=repoRoot+LANG
      print("Summarizing repo "+repoName+ " on "+lastUpdate)
      params=' corpus='+LANG + ' lastUpdate='+ lastUpdate
      executable.set_parameter("corpus",proc.make_string_value(LANG)) 
      executable.set_parameter("lastUpdate",proc.make_string_value(lastUpdate))
      src=repoName + "/driver.tei" 
      result = executable.transform_to_string(source_file=src)
      print(result) 
      executable.clear_parameter()
Actions #6

Updated by O'Neil Delpratt 3 months ago

  • Related to Bug #5542: Python example causes segmentation error added
Actions #7

Updated by O'Neil Delpratt 22 days ago

  • Status changed from Resolved to Closed
  • Fixed in version set to 11.4

Bug fix applied in the SaxonC 11.4 maintenance release.

Please register to edit this issue

Also available in: Atom PDF