Project

Profile

Help

Bug #5542

closed

Python example causes segmentation error

Added by O'Neil Delpratt almost 2 years ago. Updated over 1 year ago.

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

100%

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

Description

The following python script causes a segmentation error:

from saxonc import *

with PySaxonProcessor(license=False) as proc:

  print(proc.version)
  xdmAtomicval = proc.make_boolean_value(False)
  xsltproc = proc.new_xslt30_processor()
  executable = xsltproc.compile_stylesheet(stylesheet_file="test.xsl")
  executable.set_result_as_raw_value(True)
  executable.set_initial_match_selection(file_name="cat.xml")
  xdm_atomic_value = proc.make_integer_value(5)
  executable.set_parameter("param",proc.make_string_value("text"))
  executable.set_parameter("param2",xdm_atomic_value)
  result = executable.apply_templates_returning_string()
  print(result)

Running under gdb we get some insight as to where the segmentation fault occurs:

SaxonC-HE 11.3 from Saxonica

Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
0x00007ffff7481bdb in SaxonProcessor::createParameterJArray (parameters=std::map with 2 elements = {...}, properties=std::map with 2 elements = {...}, 
    additions=additions@entry=0) at ../SaxonProcessor.cpp:543
543	            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
(gdb) bt
#0  0x00007ffff7481bdb in SaxonProcessor::createParameterJArray (parameters=std::map with 2 elements = {...}, properties=std::map with 2 elements = {...}, 
    additions=additions@entry=0) at ../SaxonProcessor.cpp:543
#1  0x00007ffff749da78 in XsltExecutable::applyTemplatesReturningString (this=0xfd8270) at /usr/include/c++/9/bits/stl_tree.h:129
#2  0x00007ffff7478832 in __pyx_pf_6saxonc_16PyXsltExecutable_50apply_templates_returning_string (__pyx_v_self=0x7ffff7557e50, __pyx_v_kwds=<optimised out>)
    at saxonc.cpp:22186
#3  __pyx_pw_6saxonc_16PyXsltExecutable_51apply_templates_returning_string (__pyx_v_self=0x7ffff7557e50, __pyx_args=<optimised out>, __pyx_kwds=<optimised out>)
    at saxonc.cpp:21831
#4  0x0000000000503b99 in ?? ()
#5  0x000000000056b1da in _PyEval_EvalFrameDefault ()
#6  0x000000000056939a in _PyEval_EvalCodeWithName ()
#7  0x000000000068d047 in PyEval_EvalCode ()
#8  0x000000000067e351 in ?? ()
#9  0x000000000067e3cf in ?? ()
#10 0x000000000067e471 in ?? ()
#11 0x000000000067e817 in PyRun_SimpleFileExFlags ()
#12 0x00000000006b6fe2 in Py_RunMain ()
#13 0x00000000006b736d in Py_BytesMain ()
#14 0x00007ffff7de8083 in __libc_start_main (main=0x4eead0 <main>, argc=2, argv=0x7fffffffe1c8, init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, 
    stack_end=0x7fffffffe1b8) at ../csu/libc-start.c:308
#15 0x00000000005fa5ce in _start ()

Related issues

Related to SaxonC - Bug #5533: segfault when setting xslt parameter in a loopClosedO'Neil Delpratt2022-05-23

Actions
Related to SaxonC - Bug #5452: set_source and set_output_file functions don't exists but are in examplesClosedO'Neil Delpratt2022-04-08

Actions
Actions #1

Updated by O'Neil Delpratt almost 2 years ago

The workaround is to replace the following code:

  executable.set_parameter("param",proc.make_string_value("text"))

With the below code which creates a variable for the XdmAtomicValue:

  value1= proc.make_string_value("text")
  executable.set_parameter("param",value1)
Actions #2

Updated by O'Neil Delpratt almost 2 years ago

This bug issue looks the same as the following: #5533

Actions #3

Updated by O'Neil Delpratt almost 2 years ago

  • Related to Bug #5533: segfault when setting xslt parameter in a loop added
Actions #4

Updated by O'Neil Delpratt almost 2 years ago

  • Related to Bug #5452: set_source and set_output_file functions don't exists but are in examples added
Actions #5

Updated by O'Neil Delpratt almost 2 years ago

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

During the debugging phase the Python sys.getrefcount(object) was useful to check for objects not used anywhere else.

The fix was to add the C++ XdmValue.incrementRefCount() method call in the PyXsltExecutable.set_parameter. This prevents the Python garbage collection mechanism from deleting the PyXdmValue before it is used in the internal processor.

Bug fix committed on the saxon11 and main branches.

Actions #6

Updated by O'Neil Delpratt over 1 year 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