One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 lines
15 KiB
JSON
6 lines
15 KiB
JSON
{
|
|
"pattern.h": "#ifndef PATTERN_H\n#define PATTERN_H\n#include <stddef.h>\n#include <stdint.h>\n#define PR_MAX_NAMES 64\n#define PR_NAME_BYTES 64\n#define PR_PATTERN_BYTES 128\nstruct pr_catalog { size_t count; const char *names[PR_MAX_NAMES]; };\nstruct pr_allocator { void *ctx; void *(*allocate)(void *, size_t); void (*release)(void *, void *); };\nstruct pr_result { size_t count; char **items; };\nstruct pr_report {\n int status;\n size_t matched;\n size_t bytes;\n uint32_t checksum;\n size_t shown;\n char names[PR_MAX_NAMES][PR_NAME_BYTES + 1];\n};\nint pr_pattern_valid(const char *pattern);\nint pr_matches(const char *pattern, const char *name);\nint pr_expand(const struct pr_catalog *catalog, const char *pattern,\n const struct pr_allocator *allocator, struct pr_result *result);\nvoid pr_release(struct pr_result *result, const struct pr_allocator *allocator);\nint pr_query(const struct pr_catalog *catalog, const char *pattern, size_t limit,\n const struct pr_allocator *allocator, struct pr_report *report);\n#endif\n",
|
|
"expand.c": "#include \"pattern.h\"\n#include <string.h>\n\nstatic int ordinary(unsigned char c)\n{\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||\n (c >= '0' && c <= '9') || c == '_' || c == '-' ||\n c == '.' || c == '/';\n}\n\nstatic int allowed(unsigned char c)\n{\n return ordinary(c) || c == '*' || c == '?' || c == '[' ||\n c == ']' || c == '!' || c == '\\\\';\n}\n\nstatic int set_end(const char *pattern, size_t start, size_t *end)\n{\n size_t i = start + 1;\n size_t members = 0;\n if (pattern[i] == '!')\n ++i;\n while (pattern[i] && pattern[i] != ']') {\n if (pattern[i] == '\\\\') {\n ++i;\n if (!pattern[i])\n return 0;\n }\n ++members;\n ++i;\n }\n if (!pattern[i] || members == 0)\n return 0;\n *end = i;\n return 1;\n}\n\nint pr_pattern_valid(const char *pattern)\n{\n size_t i = 0;\n size_t end = 0;\n if (!pattern || strlen(pattern) > PR_PATTERN_BYTES)\n return 0;\n while (pattern[i]) {\n if (!allowed((unsigned char)pattern[i]))\n return 0;\n if (pattern[i] == '\\\\') {\n ++i;\n if (!pattern[i] || !allowed((unsigned char)pattern[i]))\n return 0;\n } else if (pattern[i] == '[') {\n if (!set_end(pattern, i, &end))\n return 0;\n for (size_t k = i + 1; k < end; ++k)\n if (!allowed((unsigned char)pattern[k]))\n return 0;\n i = end;\n }\n ++i;\n }\n return 1;\n}\n\nstatic int set_match(const char *pattern, size_t start, size_t end,\n unsigned char c)\n{\n size_t i = start + 1;\n int negative = pattern[i] == '!';\n int member = 0;\n if (negative)\n ++i;\n while (i < end) {\n if (pattern[i] == '\\\\')\n ++i;\n if ((unsigned char)pattern[i] == c)\n member = 1;\n ++i;\n }\n return c != '/' && (negative ? !member : member);\n}\n\nint pr_matches(const char *pattern, const char *name)\n{\n unsigned char table[PR_PATTERN_BYTES + 1][PR_NAME_BYTES + 1];\n size_t plen = strlen(pattern);\n size_t nlen = strlen(name);\n if (plen > PR_PATTERN_BYTES || nlen > PR_NAME_BYTES)\n return 0;\n memset(table, 0, sizeof(table));\n table[0][0] = 1;\n for (size_t i = 0; i < plen;) {\n size_t next = i + 1;\n size_t end = 0;\n char kind = pattern[i];\n unsigned char literal = (unsigned char)kind;\n if (kind == '\\\\') {\n literal = (unsigned char)pattern[i + 1];\n next = i + 2;\n } else if (kind == '[') {\n if (!set_end(pattern, i, &end))\n return 0;\n next = end + 1;\n }\n for (size_t j = 0; j <= nlen; ++j) {\n if (!table[i][j])\n continue;\n if (kind == '*') {\n table[next][j] = 1;\n for (size_t k = j; k < nlen && name[k] != '/'; ++k)\n table[next][k + 1] = 1;\n } else if (j < nlen) {\n int matches;\n if (kind == '?')\n matches = name[j] != '/';\n else if (kind == '[')\n matches = set_match(pattern, i, end, (unsigned char)name[j]);\n else\n matches = literal == (unsigned char)name[j];\n if (matches)\n table[next][j + 1] = 1;\n }\n }\n i = next;\n }\n return table[plen][nlen] != 0;\n}\n\nint pr_expand(const struct pr_catalog *catalog, const char *pattern,\n const struct pr_allocator *allocator, struct pr_result *result)\n{\n result->count = 0;\n result->items = NULL;\n if (!pr_pattern_valid(pattern))\n return 2;\n if (!catalog->count)\n return 1;\n result->items = allocator->allocate(allocator->ctx,\n catalog->count * sizeof(char *));\n if (!result->items)\n return 3;\n for (size_t i = 0; i < catalog->count; ++i) {\n const char *name = catalog->names[i];\n size_t length;\n char *copy;\n if (!pr_matches(pattern, name))\n continue;\n length = strlen(name);\n copy = allocator->allocate(allocator->ctx, length + 1);\n if (!copy)\n return 3;\n memcpy(copy, name, length + 1);\n result->items[result->count] = copy;\n ++result->count;\n }\n return result->count ? 0 : 1;\n}\n",
|
|
"observe.c": "#include \"pattern.h\"\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <limits.h>\nstruct block { void *pointer; size_t bytes; };\nstruct ledger {\n long fail_at;\n size_t attempts;\n size_t allocated;\n size_t freed;\n size_t live_blocks;\n size_t live_bytes;\n size_t peak_bytes;\n size_t bad_frees;\n struct block blocks[66];\n};\nstatic void *tracked_allocate(void *context, size_t bytes)\n{\n struct ledger *ledger = context;\n size_t attempt = ledger->attempts++;\n void *pointer;\n if (ledger->fail_at >= 0 && attempt == (size_t)ledger->fail_at)\n return NULL;\n pointer = malloc(bytes);\n if (!pointer)\n exit(4);\n for (size_t i = 0; i < 66; ++i) {\n if (ledger->blocks[i].pointer)\n continue;\n ledger->blocks[i].pointer = pointer;\n ledger->blocks[i].bytes = bytes;\n ++ledger->allocated;\n ++ledger->live_blocks;\n ledger->live_bytes += bytes;\n if (ledger->live_bytes > ledger->peak_bytes)\n ledger->peak_bytes = ledger->live_bytes;\n return pointer;\n }\n free(pointer);\n exit(4);\n}\nstatic void tracked_release(void *context, void *pointer)\n{\n struct ledger *ledger = context;\n if (!pointer)\n return;\n for (size_t i = 0; i < 66; ++i) {\n if (ledger->blocks[i].pointer != pointer)\n continue;\n --ledger->live_blocks;\n ledger->live_bytes -= ledger->blocks[i].bytes;\n ++ledger->freed;\n ledger->blocks[i].pointer = NULL;\n ledger->blocks[i].bytes = 0;\n free(pointer);\n return;\n }\n ++ledger->bad_frees;\n}\nstatic void ledger_finish(struct ledger *ledger)\n{\n for (size_t i = 0; i < 66; ++i) {\n if (ledger->blocks[i].pointer) {\n free(ledger->blocks[i].pointer);\n ledger->blocks[i].pointer = NULL;\n }\n }\n}\nstatic int digit(unsigned char c)\n{\n if (c >= '0' && c <= '9')\n return c - '0';\n if (c >= 'a' && c <= 'f')\n return c - 'a' + 10;\n if (c >= 'A' && c <= 'F')\n return c - 'A' + 10;\n return -1;\n}\nstatic int decode(const char *text, char *output, size_t capacity)\n{\n size_t length = strlen(text);\n if (strcmp(text, \"-\") == 0) {\n output[0] = 0;\n return 1;\n }\n if (length % 2 || length / 2 >= capacity)\n return 0;\n for (size_t i = 0; i < length; i += 2) {\n int hi = digit((unsigned char)text[i]);\n int lo = digit((unsigned char)text[i + 1]);\n if (hi < 0 || lo < 0 || (hi == 0 && lo == 0))\n return 0;\n output[i / 2] = (char)(hi * 16 + lo);\n }\n output[length / 2] = 0;\n return 1;\n}\nstatic int decimal(const char *text, long low, long high, long *out)\n{\n size_t i = 0;\n int negative = 0;\n unsigned long value = 0;\n if (text[i] == '+' || text[i] == '-') {\n negative = text[i] == '-';\n ++i;\n }\n if (!text[i])\n return 0;\n for (; text[i]; ++i) {\n unsigned char c = (unsigned char)text[i];\n if (c < '0' || c > '9')\n return 0;\n if (value > 1000000)\n return 0;\n value = value * 10 + (unsigned long)(c - '0');\n }\n if (value > LONG_MAX)\n return 0;\n *out = negative ? -(long)value : (long)value;\n return *out >= low && *out <= high;\n}\nstatic size_t tokenize(char *line, char **tokens, size_t capacity)\n{\n size_t count = 0;\n char *p = line;\n while (*p) {\n while (*p == ' ' || *p == '\\t' || *p == '\\r')\n ++p;\n if (!*p)\n break;\n if (count == capacity)\n return capacity + 1;\n tokens[count++] = p;\n while (*p && *p != ' ' && *p != '\\t' && *p != '\\r')\n ++p;\n if (*p)\n *p++ = 0;\n }\n return count;\n}\nstatic int read_line(char *line, size_t capacity)\n{\n size_t n;\n if (!fgets(line, (int)capacity, stdin))\n return 0;\n n = strlen(line);\n if (n && line[n - 1] == '\\n') {\n line[n - 1] = 0;\n return 1;\n }\n if (!feof(stdin))\n return -1;\n return 1;\n}\nstatic void print_hex(const char *name)\n{\n static const char hex[] = \"0123456789abcdef\";\n const unsigned char *p = (const unsigned char *)name;\n if (!*p) {\n putchar('-');\n return;\n }\n for (; *p; ++p) {\n putchar(hex[*p >> 4]);\n putchar(hex[*p & 15]);\n }\n}\nstatic int inputs_same(const struct pr_catalog *catalog,\n char saved[64][65], const char *pattern, const char *before,\n const struct pr_allocator *allocator, const struct pr_allocator *old,\n const struct pr_catalog *original)\n{\n if (strcmp(pattern, before) || allocator->ctx != old->ctx ||\n allocator->allocate != old->allocate || allocator->release != old->release)\n return 0;\n if (catalog->count != original->count)\n return 0;\n for (size_t i = 0; i < catalog->count; ++i)\n if (catalog->names[i] != original->names[i] || strcmp(catalog->names[i], saved[i]))\n return 0;\n return 1;\n}\nstatic void observe(const struct pr_catalog *catalog, char names[64][65],\n const char *pattern, long fail_at, size_t limit)\n{\n struct ledger ledger;\n struct pr_allocator allocator;\n struct pr_allocator old;\n struct pr_catalog original;\n struct pr_report report;\n char saved[64][65];\n char before[130];\n int status;\n int same;\n memset(&ledger, 0, sizeof(ledger));\n memset(&report, 0xa5, sizeof(report));\n ledger.fail_at = fail_at;\n allocator.ctx = &ledger;\n allocator.allocate = tracked_allocate;\n allocator.release = tracked_release;\n old = allocator;\n original = *catalog;\n memcpy(saved, names, sizeof(saved));\n strcpy(before, pattern);\n status = pr_query(catalog, pattern, limit, &allocator, &report);\n same = inputs_same(catalog, saved, pattern, before, &allocator, &old, &original);\n printf(\"O %d %d %zu %zu %u %zu %d %zu %zu %zu %zu %zu %zu %zu\",\n status, report.status, report.matched, report.bytes, report.checksum,\n report.shown, same, ledger.attempts, ledger.allocated, ledger.freed,\n ledger.live_blocks, ledger.live_bytes, ledger.peak_bytes, ledger.bad_frees);\n if (report.shown > 64)\n exit(5);\n for (size_t i = 0; i < report.shown; ++i) {\n if (!memchr(report.names[i], 0, 65))\n exit(5);\n putchar(' ');\n print_hex(report.names[i]);\n }\n putchar('\\n');\n ledger_finish(&ledger);\n}\n\nstatic void observe_release(const struct pr_catalog *catalog, const char *pattern,\n long fail_at)\n{\n struct ledger ledger;\n struct pr_allocator allocator;\n struct pr_result result;\n int status;\n memset(&ledger, 0, sizeof(ledger));\n ledger.fail_at = fail_at;\n allocator.ctx = &ledger;\n allocator.allocate = tracked_allocate;\n allocator.release = tracked_release;\n status = pr_expand(catalog, pattern, &allocator, &result);\n pr_release(&result, &allocator);\n pr_release(&result, &allocator);\n printf(\"R %d %zu %d %zu %zu %zu %zu %zu %zu %zu\\n\",\n status, result.count, result.items == NULL,\n ledger.attempts, ledger.allocated, ledger.freed, ledger.live_blocks,\n ledger.live_bytes, ledger.peak_bytes, ledger.bad_frees);\n ledger_finish(&ledger);\n}\nint main(void)\n{\n char line[5002];\n char *tokens[6];\n char names[64][65];\n char pattern[130];\n struct pr_catalog catalog;\n int have_catalog = 0;\n int state;\n memset(&catalog, 0, sizeof(catalog));\n memset(names, 0, sizeof(names));\n while ((state = read_line(line, sizeof(line))) > 0) {\n size_t count = tokenize(line, tokens, 6);\n long n;\n if (count == 2 && strcmp(tokens[0], \"C\") == 0) {\n if (!decimal(tokens[1], 0, 64, &n))\n return 2;\n catalog.count = (size_t)n;\n for (size_t i = 0; i < catalog.count; ++i) {\n if (read_line(line, sizeof(line)) != 1 ||\n tokenize(line, tokens, 6) != 1 ||\n !decode(tokens[0], names[i], sizeof(names[i])))\n return 2;\n catalog.names[i] = names[i];\n }\n have_catalog = 1;\n } else if (count == 5 && strcmp(tokens[0], \"Q\") == 0 && have_catalog) {\n long fail_at, limit, repeat;\n if (!decode(tokens[1], pattern, sizeof(pattern)) ||\n !decimal(tokens[2], -1, 65, &fail_at) ||\n !decimal(tokens[3], 0, 64, &limit) ||\n !decimal(tokens[4], 1, 16, &repeat))\n return 2;\n for (long i = 0; i < repeat; ++i)\n observe(&catalog, names, pattern, fail_at, (size_t)limit);\n } else if (count == 4 && strcmp(tokens[0], \"D\") == 0 && have_catalog) {\n long fail_at, repeat;\n if (!decode(tokens[1], pattern, sizeof(pattern)) ||\n !decimal(tokens[2], -1, 65, &fail_at) ||\n !decimal(tokens[3], 1, 16, &repeat))\n return 2;\n for (long i = 0; i < repeat; ++i)\n observe_release(&catalog, pattern, fail_at);\n } else {\n return 2;\n }\n }\n return state < 0 ? 2 : 0;\n}\n"
|
|
}
|