Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/11464.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implemented support for free-threading builds of CPython -- by :user:`kumaraditya303`.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ aiohttp/_find_header.c: $(call to-hash,aiohttp/hdrs.py ./tools/gen.py)
# Special case for reader since we want to be able to disable
# the extension with AIOHTTP_NO_EXTENSIONS
aiohttp/_websocket/reader_c.c: aiohttp/_websocket/reader_c.py
cython -3 -o $@ $< -I aiohttp -Werror
cython -3 -X freethreading_compatible=True -o $@ $< -I aiohttp -Werror

# _find_headers generator creates _headers.pyi as well
aiohttp/%.c: aiohttp/%.pyx $(call to-hash,$(CYS)) aiohttp/_find_header.c
cython -3 -o $@ $< -I aiohttp -Werror
cython -3 -X freethreading_compatible=True -o $@ $< -I aiohttp -Werror

aiohttp/_websocket/%.c: aiohttp/_websocket/%.pyx $(call to-hash,$(CYS))
cython -3 -o $@ $< -I aiohttp -Werror
cython -3 -X freethreading_compatible=True -o $@ $< -I aiohttp -Werror

vendor/llhttp/node_modules: vendor/llhttp/package.json
cd vendor/llhttp; npm ci
Expand Down
2 changes: 0 additions & 2 deletions aiohttp/_http_parser.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#cython: language_level=3
#
# Based on https://github.com/MagicStack/httptools
#

Expand Down
16 changes: 9 additions & 7 deletions aiohttp/_http_writer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ from libc.string cimport memcpy
from multidict import istr

DEF BUF_SIZE = 16 * 1024 # 16KiB
cdef char BUFFER[BUF_SIZE]

cdef object _istr = istr

Expand All @@ -19,16 +18,17 @@ cdef struct Writer:
char *buf
Py_ssize_t size
Py_ssize_t pos
bint heap_allocated


cdef inline void _init_writer(Writer* writer):
writer.buf = &BUFFER[0]
cdef inline void _init_writer(Writer* writer, char *buf):
writer.buf = buf
writer.size = BUF_SIZE
writer.pos = 0
writer.heap_allocated = 0


cdef inline void _release_writer(Writer* writer):
if writer.buf != BUFFER:
if writer.heap_allocated:
PyMem_Free(writer.buf)


Expand All @@ -39,7 +39,7 @@ cdef inline int _write_byte(Writer* writer, uint8_t ch):
if writer.pos == writer.size:
# reallocate
size = writer.size + BUF_SIZE
if writer.buf == BUFFER:
if not writer.heap_allocated:
buf = <char*>PyMem_Malloc(size)
if buf == NULL:
PyErr_NoMemory()
Expand All @@ -52,6 +52,7 @@ cdef inline int _write_byte(Writer* writer, uint8_t ch):
return -1
writer.buf = buf
writer.size = size
writer.heap_allocated = 1
writer.buf[writer.pos] = <char>ch
writer.pos += 1
return 0
Expand Down Expand Up @@ -125,8 +126,9 @@ def _serialize_headers(str status_line, headers):
cdef Writer writer
cdef object key
cdef object val
cdef char buf[BUF_SIZE]

_init_writer(&writer)
_init_writer(&writer, buf)

try:
if _write_str(&writer, status_line) < 0:
Expand Down
Loading