|
1 | 1 | import json |
2 | 2 | import threading |
3 | 3 |
|
4 | | -from cpython.bytes cimport PyBytes_AsString |
| 4 | +from cpython.bytes cimport PyBytes_AsStringAndSize |
5 | 5 |
|
6 | 6 |
|
7 | 7 | cdef extern from "jv.h": |
@@ -161,10 +161,11 @@ cdef class _JSONParser(object): |
161 | 161 |
|
162 | 162 | cdef bint _ready_next_bytes(self) except 1: |
163 | 163 | cdef char* cbytes |
| 164 | + cdef ssize_t clen |
164 | 165 | try: |
165 | 166 | self._bytes = next(self._text_iter).encode("utf8") |
166 | | - cbytes = PyBytes_AsString(self._bytes) |
167 | | - jv_parser_set_buf(self._parser, cbytes, len(cbytes), 1) |
| 167 | + PyBytes_AsStringAndSize(self._bytes, &cbytes, &clen) |
| 168 | + jv_parser_set_buf(self._parser, cbytes, clen, 1) |
168 | 169 | except StopIteration: |
169 | 170 | self._bytes = None |
170 | 171 | jv_parser_set_buf(self._parser, "", 0, 0) |
@@ -349,8 +350,10 @@ cdef class _ResultIterator(object): |
349 | 350 | self._bytes_input = bytes_input |
350 | 351 | self._ready = False |
351 | 352 | cdef jv_parser* parser = jv_parser_new(0) |
352 | | - cdef char* cbytes_input = PyBytes_AsString(bytes_input) |
353 | | - jv_parser_set_buf(parser, cbytes_input, len(cbytes_input), 0) |
| 353 | + cdef char* cbytes_input |
| 354 | + cdef ssize_t clen_input |
| 355 | + PyBytes_AsStringAndSize(bytes_input, &cbytes_input, &clen_input) |
| 356 | + jv_parser_set_buf(parser, cbytes_input, clen_input, 0) |
354 | 357 | self._parser = parser |
355 | 358 |
|
356 | 359 | def __iter__(self): |
|
0 commit comments