Bug #6324


PyXdmValue toString causes SIGSEGV, Segmentation fault

Added by O'Neil Delpratt 5 months ago. Updated 5 months ago.

Python API
Start date:
Due date:
% Done:


Estimated time:
Found in version:
Fixed in version:


Reported by user here:

The following code snipper where we create an XdmValue, add items and print throws a SIGSEGV fault.:

    xdm_value = PyXdmValue()




under gdb shows more details:

Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
0x00007ffff733f36a in XdmValue::toString (this=0x555555baed90) at Saxon.C.API/XdmValue.cpp:40
40	                        (void *)(values[0]->getUnderlyingValue()));

Related issues

Precedes SaxonC - Bug #6327: TypeError: __str__ returned non-string (type NoneType)ResolvedO'Neil Delpratt2024-01-192024-01-19

Actions #1

Updated by O'Neil Delpratt 5 months ago

  • Category changed from C++ API to Python API
  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Bug fixed and committed to repo. Tests added to pytests.

The problem is the reference count is not being incremented when an XdmItem is added to the XdmValue using add_xdm_item. This results in the GC deleting the XdmItem before it is used by the XdmValue in a processor.

Also fixed in the PHP API.

The workaround in Python is to create an XdmAtomicValue with a variable.

For the following code:

xdm_value.add_xdm_item(saxon_proc.make_string_value('foo')) The workaround works for me:

avalue = saxon_proc.make_string_value('foo') xdm_value.add_xdm_item(avalue)

Actions #2

Updated by Martin Honnen 5 months ago

I see you are building SaxonC 12.4.2.

As for this issue, should it be possible to print a newly created, but empty PyXdmValue, now with the fix?


    xdm_value = PyXdmValue()


It appears to still give an error

Traceback (most recent call last):
  File "C:\Users\marti\PycharmProjects\SaxonC12PyXdmValueTest1\", line 6, in <module>
TypeError: __str__ returned non-string (type NoneType)
Actions #3

Updated by O'Neil Delpratt 5 months ago

Hi Martin,

For the newly created PyXdmValue the workaround is to use the size property. E.g:

    xdm_value = PyXdmValue()

which returns zero.

A change to this probably won't make it in SaxonC 12.4.2.

Actions #4

Updated by O'Neil Delpratt 5 months ago

Also what is probably happening is the string representation of the PyXdmValue object (i.e. __str__) is None in that case.

Actions #5

Updated by Martin Honnen 5 months ago

I see.

But a plain

    value = None


does not give any error, nor does e.g. the print of an empty PyXdmMap fail

    xdm_map = saxon_proc.make_map2({}, 'UTF-8')


those two just print None.

The failure to print an empty PyXdmValue is not too important, more a cosmetical problem, but still something that could be improved, I guess. And yes, I understand it might be too late for 12.4.2.

Actions #6

Updated by O'Neil Delpratt 5 months ago

  • Precedes Bug #6327: TypeError: __str__ returned non-string (type NoneType) added
Actions #7

Updated by O'Neil Delpratt 5 months ago

For the empty PyXdmValue object the __str__ is trying to return None, which is not allowed in Python hence the error. I think this is a bug in SaxonC. I have created another bug issue for this #6327.

make_map2 is a method hence can return None if an empty map is given.

Actions #8

Updated by O'Neil Delpratt 5 months ago

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

Fix applied in SaxonC 12.4.2 maintenance release

Please register to edit this issue

Also available in: Atom PDF