@@ -5,6 +5,9 @@ from cpython.mem cimport PyMem_Malloc, PyMem_Free
5
5
from cpython cimport PyObject_GetBuffer, PyBuffer_Release, PyBUF_SIMPLE, \
6
6
Py_buffer, PyBytes_AsString
7
7
8
+ from .python cimport PyMemoryView_Check, PyMemoryView_GET_BUFFER
9
+
10
+
8
11
from .errors import (HttpParserError,
9
12
HttpParserCallbackError,
10
13
HttpParserInvalidStatusError,
@@ -149,17 +152,29 @@ cdef class HttpParser:
149
152
cdef:
150
153
size_t data_len
151
154
size_t nb
155
+ Py_buffer * buf
152
156
153
- PyObject_GetBuffer(data, & self .py_buf, PyBUF_SIMPLE)
154
- data_len = < size_t> self .py_buf.len
157
+ if PyMemoryView_Check(data):
158
+ buf = PyMemoryView_GET_BUFFER(data)
159
+ data_len = < size_t> buf.len
160
+ nb = cparser.http_parser_execute(
161
+ self ._cparser,
162
+ self ._csettings,
163
+ < char * > buf.buf,
164
+ data_len)
165
+
166
+ else :
167
+ buf = & self .py_buf
168
+ PyObject_GetBuffer(data, buf, PyBUF_SIMPLE)
169
+ data_len = < size_t> buf.len
155
170
156
- nb = cparser.http_parser_execute(
157
- self ._cparser,
158
- self ._csettings,
159
- < char * > self .py_buf .buf,
160
- data_len)
171
+ nb = cparser.http_parser_execute(
172
+ self ._cparser,
173
+ self ._csettings,
174
+ < char * > buf .buf,
175
+ data_len)
161
176
162
- PyBuffer_Release(& self .py_buf )
177
+ PyBuffer_Release(buf )
163
178
164
179
if self ._cparser.http_errno != cparser.HPE_OK:
165
180
ex = parser_error_from_errno(
0 commit comments