| 75 | |
| 76 | |
| 77 | static inline int |
| 78 | add_field(tokenizer_state *ts) |
| 79 | { |
| 80 | /* The previous field is done, advance to keep a NUL byte at the end */ |
| 81 | ts->field_buffer_pos += 1; |
| 82 | |
| 83 | if (NPY_UNLIKELY(ts->num_fields + 1 > ts->fields_size)) { |
| 84 | npy_intp size = ts->num_fields; |
| 85 | |
| 86 | npy_intp alloc_size = grow_size_and_multiply( |
| 87 | &size, 4, sizeof(field_info)); |
| 88 | if (alloc_size < 0) { |
| 89 | /* Check for a size overflow, path should be almost impossible. */ |
| 90 | PyErr_Format(PyExc_ValueError, |
| 91 | "too many columns found; cannot read file."); |
| 92 | return -1; |
| 93 | } |
| 94 | field_info *fields = (field_info *)PyMem_Realloc(ts->fields, alloc_size); |
| 95 | if (fields == nullptr) { |
| 96 | PyErr_NoMemory(); |
| 97 | return -1; |
| 98 | } |
| 99 | ts->fields = fields; |
| 100 | ts->fields_size = size; |
| 101 | } |
| 102 | |
| 103 | ts->fields[ts->num_fields].offset = ts->field_buffer_pos; |
| 104 | ts->fields[ts->num_fields].quoted = false; |
| 105 | ts->num_fields += 1; |
| 106 | /* Ensure this (currently empty) word is NUL terminated. */ |
| 107 | ts->field_buffer[ts->field_buffer_pos] = '\0'; |
| 108 | assert(ts->field_buffer_length > ts->field_buffer_pos); |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | template <typename UCS> |
no test coverage detected