Skip to content

Commit

Permalink
Fix C string handling issues in Cython 3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
scoder committed Dec 30, 2023
1 parent 8259564 commit 1a4362b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/lxml/etree.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cython: binding=True
# cython: auto_pickle=False
# cython: language_level=3str
# cython: language_level=3

"""
The ``lxml.etree`` module implements the extended ElementTree API for XML.
Expand Down
2 changes: 1 addition & 1 deletion src/lxml/objectify.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cython: binding=True
# cython: auto_pickle=False
# cython: language_level=3str
# cython: language_level=3

"""
The ``lxml.objectify`` module implements a Python object API for XML.
Expand Down
12 changes: 6 additions & 6 deletions src/lxml/serializer.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -456,31 +456,31 @@ cdef _write_attr_string(tree.xmlOutputBuffer* buf, const char *string):

base = cur = <const char*>string
while cur[0] != 0:
if cur[0] == '\n':
if cur[0] == b'\n':
if base != cur:
tree.xmlOutputBufferWrite(buf, cur - base, base)

tree.xmlOutputBufferWrite(buf, 5, "&#10;")
cur += 1
base = cur

elif cur[0] == '\r':
elif cur[0] == b'\r':
if base != cur:
tree.xmlOutputBufferWrite(buf, cur - base, base)

tree.xmlOutputBufferWrite(buf, 5, "&#13;")
cur += 1
base = cur

elif cur[0] == '\t':
elif cur[0] == b'\t':
if base != cur:
tree.xmlOutputBufferWrite(buf, cur - base, base)

tree.xmlOutputBufferWrite(buf, 4, "&#9;")
cur += 1
base = cur

elif cur[0] == '"':
elif cur[0] == b'"':
if base != cur:
tree.xmlOutputBufferWrite(buf, cur - base, base)

Expand All @@ -496,14 +496,14 @@ cdef _write_attr_string(tree.xmlOutputBuffer* buf, const char *string):
cur += 1
base = cur

elif cur[0] == '>':
elif cur[0] == b'>':
if base != cur:
tree.xmlOutputBufferWrite(buf, cur - base, base)

tree.xmlOutputBufferWrite(buf, 4, "&gt;")
cur += 1
base = cur
elif cur[0] == '&':
elif cur[0] == b'&':
if base != cur:
tree.xmlOutputBufferWrite(buf, cur - base, base)

Expand Down
16 changes: 8 additions & 8 deletions src/lxml/xmlerror.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -716,32 +716,32 @@ cdef void _receiveGenericError(void* c_log_handler, int c_domain,
c_name_pos = c_pos = msg
format_count = 0
while c_pos[0]:
if c_pos[0] == '%':
if c_pos[0] == b'%':
c_pos += 1
if c_pos[0] == 's': # "%s"
if c_pos[0] == b's': # "%s"
format_count += 1
c_str = cvarargs.va_charptr(args)
if c_pos == msg + 1:
c_text = c_str # msg == "%s..."
elif c_name_pos[0] == 'e':
elif c_name_pos[0] == b'e':
if cstring_h.strncmp(c_name_pos, 'element %s', 10) == 0:
c_element = c_str
elif c_name_pos[0] == 'f':
elif c_name_pos[0] == b'f':
if cstring_h.strncmp(c_name_pos, 'file %s', 7) == 0:
if cstring_h.strncmp('string://__STRING__XSLT',
c_str, 23) == 0:
c_str = '<xslt>'
c_error.file = c_str
elif c_pos[0] == 'd': # "%d"
elif c_pos[0] == b'd': # "%d"
format_count += 1
c_int = cvarargs.va_int(args)
if cstring_h.strncmp(c_name_pos, 'line %d', 7) == 0:
c_error.line = c_int
elif c_pos[0] != '%': # "%%" == "%"
elif c_pos[0] != b'%': # "%%" == "%"
format_count += 1
break # unexpected format or end of string => abort
elif c_pos[0] == ' ':
if c_pos[1] != '%':
elif c_pos[0] == b' ':
if c_pos[1] != b'%':
c_name_pos = c_pos + 1
c_pos += 1

Expand Down

0 comments on commit 1a4362b

Please sign in to comment.