Forums » Saxon/C Help and Discussions »
Clarification on make_string_value needed
Added by Martin Honnen about 5 years ago
I have tried another simple example with the Python saxonc module built on Windows 10 64bit using Cython against/with Python 3.7; this time I have tried to use a Python string and create a PyXdmAtomicValue using the make_string_value
method of PySaxonProcessor
:
import saxonc
s1 = 'This is a test.'
with saxonc.PySaxonProcessor(license=False) as proc:
print(proc.version)
xdm_string_value = proc.make_string_value(s1)
print(xdm_string_value)
xquery_processor = proc.new_xquery_processor()
xquery_processor.set_parameter('s1', xdm_string_value)
result = xquery_processor.run_query_to_value(query_text = 'declare variable $s1 external; $s1')
print(result)
print(result.get_atomic_value().string_value)
This doesn't work at all, erroring with
Saxon/C 1.2.0 running with Saxon-HE 9.9.1.5J from Saxonica
Traceback (most recent call last):
File ".\string-param-for-xquery1.py", line 8, in <module>
xdm_string_value = proc.make_string_value(s1)
File "saxonc.pyx", line 247, in saxonc.PySaxonProcessor.make_string_value
val.derivedaptr = val.derivedptr = val.thisvptr = self.thisptr.makeStringValue(str_)
TypeError: expected bytes, str found
Is that an intended design of the API?
It seems most functions exposed elsewhere in the API to Python and expecting a Python str do then internally use .encode('UTF-8')
before passing the value on to the C/C++ char * side expecting API.
Is that missing in the saxonc.PySaxonProcessor.make_string_value
implementation?
Or do really have to pass bytes in?
Replies (2)
RE: Clarification on make_string_value needed - Added by O'Neil Delpratt about 5 years ago
Created bug issue to track this bug: #4349
As mentioned the The .encode('UTF-8')
and C/C++ conversion was missing. I have committed the fix you should now be able to apply the patch by replacing the saxonc.pyx with the one on subversion:
https://dev.saxonica.com/repos/archive/opensource/latest9.9/hec/Saxon.C.API/python-saxon/saxonc.pyx
RE: Clarification on make_string_value needed - Added by O'Neil Delpratt about 5 years ago
This issue has been resolved in the Saxon/C 1.2.1 maintenance release.
Please register to reply