Bug #6324
closedPyXdmValue toString causes SIGSEGV, Segmentation fault
100%
Description
Reported by user here: https://saxonica.plan.io/boards/4/topics/9589
The following code snipper where we create an XdmValue, add items and print throws a SIGSEGV fault.:
xdm_value = PyXdmValue()
#print(xdm_value)
xdm_value.add_xdm_item(saxon_proc.make_string_value('foo'))
print(xdm_value)
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
Updated by O'Neil Delpratt 11 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)
Updated by Martin Honnen 11 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?
E.g.
xdm_value = PyXdmValue()
print(xdm_value)
It appears to still give an error
Traceback (most recent call last):
File "C:\Users\marti\PycharmProjects\SaxonC12PyXdmValueTest1\main.py", line 6, in <module>
print(xdm_value)
TypeError: __str__ returned non-string (type NoneType)
Updated by O'Neil Delpratt 11 months ago
Hi Martin,
For the newly created PyXdmValue the workaround is to use the size
property.
E.g:
xdm_value = PyXdmValue()
print(xdm_value.size)
which returns zero.
A change to this probably won't make it in SaxonC 12.4.2.
Updated by O'Neil Delpratt 11 months ago
Also what is probably happening is the string representation of the PyXdmValue object (i.e. __str__
) is None
in that case.
Updated by Martin Honnen 11 months ago
I see.
But a plain
value = None
print(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')
print(xdm_map)
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.
Updated by O'Neil Delpratt 11 months ago
- Precedes Bug #6327: TypeError: __str__ returned non-string (type NoneType) added
Updated by O'Neil Delpratt 11 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.
Updated by O'Neil Delpratt 11 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