Project

Profile

Help

Bug #6324

closed

PyXdmValue toString causes SIGSEGV, Segmentation fault

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

Status:
Closed
Priority:
Normal
Category:
Python API
Start date:
2024-01-18
Due date:
% Done:

100%

Estimated time:
Found in version:
12.4.1
Fixed in version:
12.4.2
Platforms:

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

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

Actions
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?

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)
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()
    print(xdm_value.size)

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

    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.

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