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>
105 lines
2.7 KiB
C
105 lines
2.7 KiB
C
#include "stream.h"
|
|
static void remember(struct report *r, int error, int role)
|
|
{
|
|
if (r->error == 0) {
|
|
r->error = error;
|
|
r->role = role;
|
|
}
|
|
}
|
|
static int ports_valid(const struct ports *p)
|
|
{
|
|
if (p == NULL) {
|
|
return 0;
|
|
}
|
|
if (p->open == NULL) {
|
|
return 0;
|
|
}
|
|
if (p->write == NULL) {
|
|
return 0;
|
|
}
|
|
if (p->flush == NULL) {
|
|
return 0;
|
|
}
|
|
if (p->close == NULL) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
static int acquire(const struct job *j, const struct ports *p, FILE **handles, struct report *r)
|
|
{
|
|
int count = (j->flags & 1) ? 3 : 2;
|
|
for (int role = 0; role < count; ++role) {
|
|
FILE *f = p->open(p->context, role, j->serial);
|
|
if (f == NULL) {
|
|
remember(r, 10, role);
|
|
return role;
|
|
}
|
|
handles[role] = f;
|
|
}
|
|
return count;
|
|
}
|
|
static int deliver(const struct plan *plan, const struct ports *p, FILE **handles, struct report *r)
|
|
{
|
|
for (int i = 0; i < plan->count; ++i) {
|
|
const struct line *line = &plan->lines[i];
|
|
int role = line->role;
|
|
const char *bytes = line->text.bytes;
|
|
size_t length = line->text.length;
|
|
int result = p->write(p->context, handles[role], bytes, length);
|
|
if (result != 0) {
|
|
remember(r, 20, role);
|
|
return -1;
|
|
}
|
|
r->delivered[role] += length;
|
|
}
|
|
return 0;
|
|
}
|
|
static int flush_handles(int count, const struct ports *p, FILE **handles, struct report *r)
|
|
{
|
|
for (int role = 0; role < count; ++role) {
|
|
int result = p->flush(p->context, handles[role]);
|
|
if (result != 0) {
|
|
remember(r, 30, role);
|
|
return -1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
static void release_handles(int count, const struct ports *p, FILE **handles, struct report *r)
|
|
{
|
|
for (int n = 0; n < count; ++n) {
|
|
int role = n;
|
|
FILE *owned = handles[role];
|
|
handles[role] = NULL;
|
|
if (owned != NULL) {
|
|
int result = p->close(p->context, owned);
|
|
if (result != 0) {
|
|
remember(r, 40, role);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int export_job(const struct job *j, const struct ports *ports, struct report *r)
|
|
{
|
|
struct plan plan;
|
|
FILE *handles[3] = {NULL, NULL, NULL};
|
|
if (build_plan(j, &plan, r) != 0) {
|
|
return -1;
|
|
}
|
|
if (!ports_valid(ports)) {
|
|
remember(r, 3, -1);
|
|
return -1;
|
|
}
|
|
int count = acquire(j, ports, handles, r);
|
|
if (r->error == 0) {
|
|
if (deliver(&plan, ports, handles, r) == 0) {
|
|
flush_handles(count, ports, handles, r);
|
|
}
|
|
}
|
|
release_handles(count, ports, handles, r);
|
|
if (r->error != 0) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|