Bug #5533
closedsegfault when setting xslt parameter in a loop
100%
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
Related issues
Updated by O'Neil Delpratt over 2 years 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?
Updated by Lou Burnard over 2 years ago
- File summarize2.py summarize2.py added
- File summarize.xsl summarize.xsl added
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.
Updated by O'Neil Delpratt over 2 years 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()
Updated by O'Neil Delpratt over 2 years ago
- Related to Bug #4386: setProperty and setParameter does not replace keys already in the map added
Updated by O'Neil Delpratt over 2 years 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()
Updated by O'Neil Delpratt over 2 years ago
- Related to Bug #5542: Python example causes segmentation error added
Updated by O'Neil Delpratt over 2 years 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