| 41 | |
| 42 | template <typename UCS> |
| 43 | static inline int |
| 44 | copy_to_field_buffer(tokenizer_state *ts, |
| 45 | const UCS *chunk_start, const UCS *chunk_end) |
| 46 | { |
| 47 | npy_intp chunk_length = chunk_end - chunk_start; |
| 48 | /* Space for length +1 termination, +2 additional padding for add_field */ |
| 49 | npy_intp size = chunk_length + ts->field_buffer_pos + 3; |
| 50 | |
| 51 | if (NPY_UNLIKELY(ts->field_buffer_length < size)) { |
| 52 | npy_intp alloc_size = grow_size_and_multiply(&size, 32, sizeof(Py_UCS4)); |
| 53 | if (alloc_size < 0) { |
| 54 | PyErr_Format(PyExc_ValueError, |
| 55 | "line too long to handle while reading file."); |
| 56 | return -1; |
| 57 | } |
| 58 | Py_UCS4 *grown = (Py_UCS4 *)PyMem_Realloc(ts->field_buffer, alloc_size); |
| 59 | if (grown == nullptr) { |
| 60 | PyErr_NoMemory(); |
| 61 | return -1; |
| 62 | } |
| 63 | ts->field_buffer_length = size; |
| 64 | ts->field_buffer = grown; |
| 65 | } |
| 66 | |
| 67 | Py_UCS4 *write_pos = ts->field_buffer + ts->field_buffer_pos; |
| 68 | for (; chunk_start < chunk_end; chunk_start++, write_pos++) { |
| 69 | *write_pos = (Py_UCS4)*chunk_start; |
| 70 | } |
| 71 | *write_pos = '\0'; /* always ensure we end with NUL */ |
| 72 | ts->field_buffer_pos += chunk_length; |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | static inline int |
no test coverage detected