From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
1.7 KiB
C
64 lines
1.7 KiB
C
#include "vector.h"
|
|
|
|
#include <errno.h>
|
|
|
|
static size_t window_bytes(const struct vt_span *spans, size_t count)
|
|
{
|
|
size_t total = 0;
|
|
size_t index;
|
|
for (index = 0; index < count; index++) {
|
|
total += spans[index].length;
|
|
}
|
|
return total;
|
|
}
|
|
|
|
ssize_t vt_submit(struct vt_job *job, struct vt_book *book, size_t quota,
|
|
size_t width, vt_sender sender, void *context)
|
|
{
|
|
size_t accepted = 0;
|
|
size_t remaining;
|
|
int error = 0;
|
|
int paused = 0;
|
|
int completed = 0;
|
|
if (job == NULL || book == NULL || sender == NULL || !job->ready ||
|
|
quota == 0 || quota > VT_TOTAL_BYTES || width == 0 || width > VT_WINDOW) {
|
|
return -EINVAL;
|
|
}
|
|
job->last_error = 0;
|
|
remaining = job->cursor.total - job->cursor.done;
|
|
if (remaining > quota) {
|
|
remaining = quota;
|
|
}
|
|
while (remaining != 0) {
|
|
struct vt_span window[VT_WINDOW];
|
|
size_t count = vt_cursor_window(job, remaining, width, window);
|
|
size_t offered = window_bytes(window, count);
|
|
ssize_t result;
|
|
job->calls++;
|
|
result = sender(context, window, count);
|
|
if (result == -EINTR) {
|
|
continue;
|
|
}
|
|
if (result < 0) {
|
|
error = (int)-result;
|
|
break;
|
|
}
|
|
if ((size_t)result > offered) {
|
|
error = EPROTO;
|
|
break;
|
|
}
|
|
if (result == 0) {
|
|
paused = 1;
|
|
break;
|
|
}
|
|
vt_cursor_advance(job, (size_t)result);
|
|
accepted += (size_t)result;
|
|
remaining -= (size_t)result;
|
|
if (job->cursor.done == job->cursor.total) {
|
|
completed = 1;
|
|
}
|
|
}
|
|
job->last_error = error;
|
|
return vt_book_finish(book, accepted, error, paused, completed);
|
|
}
|