Skip to content

Commit

Permalink
update cython so we do not need to patch generated file
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Dec 7, 2024
1 parent d2ab6c1 commit 633d842
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 69 deletions.
2 changes: 0 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ source =
.
source_pkgs =
yarl
omit =
patch_source.py
19 changes: 4 additions & 15 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -51,42 +51,31 @@ if not pure_py
if get_option('cython-trace').enabled()
cython_args += ['-X', 'linetrace=True']
add_global_arguments('-DCYTHON_TRACE=1', language: 'c')
add_global_arguments('-DCYTHON_USE_SYS_MONITORING=0', language: 'c')
endif

cython_gen = generator(
cython,
output: ['@BASENAME@.c_unpatched'],
arguments: ['@INPUT@', '--output-file', '@OUTPUT0@'] + cython_args,
)

rewrite_pyx_path = generator(
py_inter,
output: ['@BASENAME@.c'],
arguments: [
join_paths(meson.project_source_root(), 'patch_source.py'),
'@INPUT@',
'@OUTPUT0@',
],
arguments: ['@INPUT@', '--output-file', '@OUTPUT0@'] + cython_args,
)

quoting_c = cython_gen.process(
'yarl/_quoting_c.pyx',
preserve_path_from: meson.current_source_dir(),
)

quoting_c_patched = rewrite_pyx_path.process(quoting_c)

out = py.extension_module(
'_quoting_c',
quoting_c_patched,
quoting_c,
subdir: 'yarl',
install: true,
dependencies: py.dependency(),
)

copy_c = custom_target(
'copy generated c file back to source tree',
input: quoting_c_patched,
input: quoting_c,
output: 'copy_c',
build_by_default: false,
command: [
Expand Down
42 changes: 0 additions & 42 deletions patch_source.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
'cython ; implementation_name == "cpython"',
'cython==3.1.0a1 ; implementation_name == "cpython"',
"meson[ninja]",
"meson-python",
]
Expand Down
2 changes: 1 addition & 1 deletion requirements/cython.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cython==3.0.11
cython==3.1.0a1
meson
ninja
16 changes: 8 additions & 8 deletions yarl/_quoting_c.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ cdef inline int _is_lower_hex(Py_UCS4 v) noexcept:
return 'a' <= v <= 'f'


cdef inline Py_UCS4 _restore_ch(Py_UCS4 d1, Py_UCS4 d2):
cdef inline (Py_UCS4, uint8_t) _restore_ch(Py_UCS4 d1, Py_UCS4 d2):
cdef int digit1 = _from_hex(d1)
if digit1 < 0:
return <Py_UCS4>-1
return 0, 0
cdef int digit2 = _from_hex(d2)
if digit2 < 0:
return <Py_UCS4>-1
return <Py_UCS4>(digit1 << 4 | digit2)
return <Py_UCS4>0 , 0
return <Py_UCS4>(digit1 << 4 | digit2), 1


cdef uint8_t ALLOWED_TABLE[16]
Expand Down Expand Up @@ -262,11 +262,11 @@ cdef class _Quoter:
ch = PyUnicode_READ(kind, data, idx)
idx += 1
if ch == '%' and self._requote and idx <= length - 2:
ch = _restore_ch(
ch, ok = _restore_ch(
PyUnicode_READ(kind, data, idx),
PyUnicode_READ(kind, data, idx + 1)
)
if ch != <Py_UCS4>-1:
if ok:
idx += 2
if ch < 128:
if bit_at(self._protected_table, ch):
Expand Down Expand Up @@ -352,11 +352,11 @@ cdef class _Unquoter:
idx += 1
if ch == '%' and idx <= length - 2:
changed = 1
ch = _restore_ch(
ch, ok = _restore_ch(
PyUnicode_READ(kind, data, idx),
PyUnicode_READ(kind, data, idx + 1)
)
if ch != <Py_UCS4>-1:
if ok:
idx += 2
assert buflen < 4
buffer[buflen] = ch
Expand Down

0 comments on commit 633d842

Please sign in to comment.