| 50 | } py_sb_t; |
| 51 | |
| 52 | static void py_put(py_sb_t *sb, const char *s, size_t n) { |
| 53 | if (sb->failed) { |
| 54 | return; |
| 55 | } |
| 56 | if (sb->len + n + 1 > sb->cap) { |
| 57 | size_t ncap = sb->cap ? sb->cap : PY_SB_INIT; |
| 58 | while (ncap < sb->len + n + 1) { |
| 59 | ncap *= 2; |
| 60 | } |
| 61 | char *grown = (char *)cbm_arena_alloc(sb->a, ncap); |
| 62 | if (!grown) { |
| 63 | sb->failed = true; |
| 64 | return; |
| 65 | } |
| 66 | if (sb->len > 0) { |
| 67 | memcpy(grown, sb->buf, sb->len); |
| 68 | } |
| 69 | sb->buf = grown; |
| 70 | sb->cap = ncap; |
| 71 | } |
| 72 | memcpy(sb->buf + sb->len, s, n); |
| 73 | sb->len += n; |
| 74 | sb->buf[sb->len] = '\0'; |
| 75 | } |
| 76 | |
| 77 | /* One record: its kind, then each field after a TAB, then a newline. */ |
| 78 | static void py_rec(py_sb_t *sb, const char *kind, int nfields, const char *const *f, |
no test coverage detected