amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

5 lines
7.6 KiB
JSON

{
"expr.h": "#ifndef EXPR_H\n#define EXPR_H\n#include <stddef.h>\n#include <stdint.h>\n#define EX_MAX_CHILDREN 8\n#define EX_NAME_SIZE 16\n#define EX_TEXT_LIMIT 4096\n#define EX_VALUE_LIMIT INT64_C(1000000000000)\ntypedef enum {\n EX_OK, EX_SYNTAX, EX_LIMIT, EX_MEMORY, EX_ARITH,\n EX_UNBOUND, EX_BUFFER, EX_ARGUMENT\n} ex_status;\ntypedef enum {\n EX_NUMBER, EX_VARIABLE, EX_ADD, EX_SUB, EX_MUL,\n EX_MIN, EX_MAX, EX_NEG, EX_ABS, EX_SUM\n} ex_kind;\ntypedef struct ex_node {\n ex_kind kind;\n int64_t number;\n char name[EX_NAME_SIZE];\n size_t arity;\n struct ex_node *child[EX_MAX_CHILDREN];\n} ex_node;\ntypedef void *(*ex_allocate)(void *, size_t);\ntypedef void (*ex_release)(void *, void *);\ntypedef struct {\n void *context;\n ex_allocate allocate;\n ex_release release;\n} ex_allocator;\ntypedef struct {\n ex_node *root;\n ex_allocator memory;\n size_t max_nodes;\n size_t max_depth;\n} ex_tree;\ntypedef struct {\n const char *name;\n int64_t value;\n} ex_binding;\ntypedef void (*ex_visitor)(void *, const ex_node *);\nex_status ex_init(ex_tree *, ex_allocator, size_t, size_t);\nvoid ex_destroy(ex_tree *);\nex_status ex_parse(ex_tree *, const char *, size_t);\nex_status ex_clone(ex_tree *, const ex_tree *);\nsize_t ex_count(const ex_tree *);\nsize_t ex_height(const ex_tree *);\nvoid ex_visit(const ex_tree *, ex_visitor, void *);\nex_status ex_render(const ex_tree *, char *, size_t, size_t *);\nex_status ex_evaluate(const ex_tree *, const ex_binding *, size_t, int64_t *);\n#endif\n",
"observe.c": "#include \"expr.h\"\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\ntypedef struct {\n void *pointer;\n int live;\n} allocation;\nstatic allocation records[30000];\nstatic size_t used, live_count, bad_free, early_free;\nstatic long allowance = -1;\nstatic int live_pointer(const void *pointer)\n{\n size_t i;\n for (i = 0; i < used; ++i)\n if (records[i].pointer == pointer)\n return records[i].live;\n return 0;\n}\nstatic void *observe_allocate(void *context, size_t size)\n{\n void *pointer;\n (void)context;\n if (allowance == 0)\n return NULL;\n if (allowance > 0)\n --allowance;\n pointer = calloc(1, size);\n if (!pointer || used == 30000)\n exit(3);\n records[used].pointer = pointer;\n records[used++].live = 1;\n ++live_count;\n return pointer;\n}\nstatic void observe_release(void *context, void *pointer)\n{\n size_t i, j;\n ex_node *node = pointer;\n (void)context;\n if (!pointer)\n return;\n for (i = 0; i < used; ++i) {\n if (records[i].pointer == pointer && records[i].live) {\n for (j = 0; j < node->arity && j < EX_MAX_CHILDREN; ++j)\n if (live_pointer(node->child[j]))\n ++early_free;\n records[i].live = 0;\n --live_count;\n return;\n }\n }\n ++bad_free;\n}\nstatic void json_string(const char *text)\n{\n const unsigned char *p = (const unsigned char *)text;\n putchar('\"');\n for (; *p; ++p) {\n if (*p == '\"' || *p == '\\\\') {\n putchar('\\\\');\n putchar(*p);\n } else if (*p >= 32 && *p < 127) {\n putchar(*p);\n } else {\n printf(\"\\\\u%04x\", *p);\n }\n }\n putchar('\"');\n}\nstatic void visit_print(void *context, const ex_node *node)\n{\n int *first = context;\n if (!*first)\n putchar(',');\n *first = 0;\n printf(\"[%d,%lld,\", (int)node->kind, (long long)node->number);\n json_string(node->name);\n putchar(']');\n}\nstatic void tree_print(const ex_tree *tree)\n{\n char buffer[EX_TEXT_LIMIT + 1] = {0};\n size_t needed = 0;\n int first = 1;\n ex_status rc = ex_render(tree, buffer, sizeof(buffer), &needed);\n printf(\"[%zu,%zu,%d,\", ex_count(tree), ex_height(tree), (int)rc);\n json_string(buffer);\n printf(\",[\");\n ex_visit(tree, visit_print, &first);\n printf(\"]]\");\n}\nstatic size_t decode_hex(const char *hex, char *out)\n{\n size_t i, count = strlen(hex) / 2;\n if (!strcmp(hex, \"-\"))\n return 0;\n for (i = 0; i < count; ++i) {\n unsigned int value = 0;\n sscanf(hex + i * 2, \"%2x\", &value);\n out[i] = (char)value;\n }\n return count;\n}\nint main(void)\n{\n ex_tree trees[2];\n ex_allocator memory = {NULL, observe_allocate, observe_release};\n char line[18000];\n ex_init(&trees[0], memory, 256, 32);\n ex_init(&trees[1], memory, 256, 32);\n while (fgets(line, sizeof(line), stdin)) {\n char op;\n int slot = 0, source = 0;\n ex_status rc = EX_OK;\n char extra[20000] = \"[]\";\n if (sscanf(line, \" %c\", &op) != 1)\n return 4;\n if (op == 'P') {\n char hex[9000], text[4500];\n size_t length;\n sscanf(line, \" %c %d %ld %8999s\", &op, &slot, &allowance, hex);\n length = decode_hex(hex, text);\n rc = ex_parse(&trees[slot], text, length);\n } else if (op == 'C') {\n sscanf(line, \" %c %d %d %ld\", &op, &slot, &source, &allowance);\n rc = ex_clone(&trees[slot], &trees[source]);\n } else if (op == 'D') {\n sscanf(line, \" %c %d\", &op, &slot);\n ex_destroy(&trees[slot]);\n } else if (op == 'I') {\n size_t nodes = 0, depth = 0;\n sscanf(line, \" %c %d %zu %zu\", &op, &slot, &nodes, &depth);\n ex_destroy(&trees[slot]);\n rc = ex_init(&trees[slot], memory, nodes, depth);\n } else if (op == 'Q') {\n char buffer[EX_TEXT_LIMIT + 1];\n char *cursor;\n char *token;\n char names[64][EX_NAME_SIZE];\n ex_binding bindings[64];\n size_t capacity, count, i, needed = 777777;\n int64_t value = 888888;\n ex_status eval_rc, render_rc;\n token = strtok(line, \" \\t\\r\\n\");\n token = strtok(NULL, \" \\t\\r\\n\"); slot = atoi(token);\n token = strtok(NULL, \" \\t\\r\\n\"); capacity = (size_t)strtoul(token, NULL, 10);\n token = strtok(NULL, \" \\t\\r\\n\"); count = (size_t)strtoul(token, NULL, 10);\n for (i = 0; i < count; ++i) {\n token = strtok(NULL, \" \\t\\r\\n\");\n snprintf(names[i], sizeof(names[i]), \"%s\", token);\n bindings[i].name = names[i];\n token = strtok(NULL, \" \\t\\r\\n\");\n bindings[i].value = (int64_t)strtoll(token, NULL, 10);\n }\n memset(buffer, 'Z', sizeof(buffer));\n eval_rc = ex_evaluate(&trees[slot], bindings, count, &value);\n render_rc = ex_render(&trees[slot], buffer, capacity, &needed);\n cursor = extra;\n cursor += sprintf(cursor, \"[%d,%lld,%d,%zu,\\\"\", (int)eval_rc, (long long)value, (int)render_rc, needed);\n for (i = 0; i < (render_rc == EX_OK ? needed + 1 : capacity); ++i)\n cursor += sprintf(cursor, \"%02x\", (unsigned char)buffer[i]);\n sprintf(cursor, \"\\\"]\");\n } else {\n return 5;\n }\n allowance = -1;\n printf(\"[%d,%zu,%zu,%zu,\", (int)rc, live_count, bad_free, early_free);\n tree_print(&trees[0]);\n putchar(',');\n tree_print(&trees[1]);\n printf(\",%s]\\n\", extra);\n fflush(stdout);\n }\n ex_destroy(&trees[0]);\n ex_destroy(&trees[1]);\n printf(\"[\\\"END\\\",%zu,%zu,%zu]\\n\", live_count, bad_free, early_free);\n for (size_t i = 0; i < used; ++i)\n free(records[i].pointer);\n return 0;\n}\n"
}