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>
133 lines
3.0 KiB
C
133 lines
3.0 KiB
C
#include "pathvisit.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
void pv_pool_init(struct pv_pool *pool)
|
|
{
|
|
size_t i;
|
|
memset(pool, 0, sizeof(*pool));
|
|
for (i = 0; i < PV_BLOCKS; ++i) {
|
|
pool->blocks[i].address = NULL;
|
|
pool->blocks[i].length = 0;
|
|
}
|
|
}
|
|
|
|
void pv_pool_begin(struct pv_pool *pool, unsigned fail_at)
|
|
{
|
|
pool->fail_at = fail_at;
|
|
pool->round_attempts = 0;
|
|
}
|
|
|
|
static size_t empty_slot(const struct pv_pool *pool)
|
|
{
|
|
size_t i;
|
|
for (i = 0; i < PV_BLOCKS; ++i) {
|
|
if (pool->blocks[i].address == NULL) {
|
|
return i;
|
|
}
|
|
}
|
|
return PV_BLOCKS;
|
|
}
|
|
|
|
static size_t find_slot(const struct pv_pool *pool, const char *address)
|
|
{
|
|
size_t i;
|
|
for (i = 0; i < PV_BLOCKS; ++i) {
|
|
if (pool->blocks[i].address == address) {
|
|
return i;
|
|
}
|
|
}
|
|
return PV_BLOCKS;
|
|
}
|
|
|
|
char *pv_pool_copy(struct pv_pool *pool, const char *text)
|
|
{
|
|
size_t slot;
|
|
size_t bytes;
|
|
char *copy;
|
|
pool->attempts += 1;
|
|
pool->round_attempts += 1;
|
|
if (pool->fail_at != 0 && pool->round_attempts == pool->fail_at) {
|
|
pool->failures += 1;
|
|
return NULL;
|
|
}
|
|
slot = empty_slot(pool);
|
|
if (slot == PV_BLOCKS) {
|
|
pool->failures += 1;
|
|
return NULL;
|
|
}
|
|
bytes = strlen(text) + 1;
|
|
copy = malloc(bytes);
|
|
if (copy == NULL) {
|
|
pool->failures += 1;
|
|
return NULL;
|
|
}
|
|
memcpy(copy, text, bytes);
|
|
pool->blocks[slot].address = copy;
|
|
pool->blocks[slot].length = bytes;
|
|
pool->allocations += 1;
|
|
pool->live += 1;
|
|
pool->bytes += bytes;
|
|
if (pool->bytes > pool->peak) {
|
|
pool->peak = pool->bytes;
|
|
}
|
|
return copy;
|
|
}
|
|
|
|
void pv_pool_release(struct pv_pool *pool, char *address)
|
|
{
|
|
size_t slot;
|
|
if (address == NULL) {
|
|
return;
|
|
}
|
|
slot = find_slot(pool, address);
|
|
if (slot == PV_BLOCKS) {
|
|
pool->bad_releases += 1;
|
|
return;
|
|
}
|
|
pool->bytes -= pool->blocks[slot].length;
|
|
pool->live -= 1;
|
|
pool->releases += 1;
|
|
pool->blocks[slot].address = NULL;
|
|
pool->blocks[slot].length = 0;
|
|
free(address);
|
|
}
|
|
|
|
int pv_pool_consistent(const struct pv_pool *pool)
|
|
{
|
|
size_t i;
|
|
uint64_t live = 0;
|
|
uint64_t bytes = 0;
|
|
for (i = 0; i < PV_BLOCKS; ++i) {
|
|
if (pool->blocks[i].address != NULL) {
|
|
live += 1;
|
|
bytes += pool->blocks[i].length;
|
|
if (pool->blocks[i].length == 0) {
|
|
return 0;
|
|
}
|
|
} else if (pool->blocks[i].length != 0) {
|
|
return 0;
|
|
}
|
|
}
|
|
if (live != pool->live || bytes != pool->bytes) {
|
|
return 0;
|
|
}
|
|
if (pool->allocations != pool->releases + pool->live) {
|
|
return 0;
|
|
}
|
|
if (pool->attempts != pool->allocations + pool->failures) {
|
|
return 0;
|
|
}
|
|
return pool->peak >= pool->bytes;
|
|
}
|
|
|
|
void pv_pool_dispose(struct pv_pool *pool)
|
|
{
|
|
size_t i;
|
|
for (i = 0; i < PV_BLOCKS; ++i) {
|
|
if (pool->blocks[i].address != NULL) {
|
|
pv_pool_release(pool, pool->blocks[i].address);
|
|
}
|
|
}
|
|
}
|