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>
93 lines
2.1 KiB
C
93 lines
2.1 KiB
C
#include "stack_domain.h"
|
|
#include <string.h>
|
|
#define ATTR_READY UINT64_C(0x534441545452)
|
|
static int attr_live(const struct sd_attr *attr)
|
|
{
|
|
return attr != NULL && attr->ready == ATTR_READY;
|
|
}
|
|
int sd_attr_init(struct sd_attr *out, const struct sd_port *port)
|
|
{
|
|
struct sd_attr next;
|
|
uint64_t bytes;
|
|
int rc;
|
|
if (out == NULL) {
|
|
return SD_EINVAL;
|
|
}
|
|
rc = sd_port_default(port, &bytes);
|
|
if (rc != SD_OK) {
|
|
return rc;
|
|
}
|
|
memset(&next, 0, sizeof(next));
|
|
next.port = *port;
|
|
next.size = bytes;
|
|
next.revision = 1;
|
|
next.explicit_size = 0;
|
|
next.ready = ATTR_READY;
|
|
*out = next;
|
|
return SD_OK;
|
|
}
|
|
int sd_attr_set(struct sd_attr *attr, uint64_t bytes)
|
|
{
|
|
uint64_t rounded;
|
|
int rc;
|
|
if (!attr_live(attr)) {
|
|
return SD_EINVAL;
|
|
}
|
|
rc = sd_port_round(&attr->port, bytes, &rounded);
|
|
if (rc != SD_OK) {
|
|
return rc;
|
|
}
|
|
if (attr->revision == UINT64_MAX) {
|
|
return SD_EINVAL;
|
|
}
|
|
attr->size = rounded;
|
|
attr->revision += 1;
|
|
attr->explicit_size = 1;
|
|
return SD_OK;
|
|
}
|
|
int sd_attr_get(const struct sd_attr *attr, uint64_t *bytes,
|
|
uint64_t *revision, int *explicit_size)
|
|
{
|
|
if (!attr_live(attr) || bytes == NULL || revision == NULL || explicit_size == NULL) {
|
|
return SD_EINVAL;
|
|
}
|
|
*bytes = attr->size;
|
|
*revision = attr->revision;
|
|
*explicit_size = attr->explicit_size;
|
|
return SD_OK;
|
|
}
|
|
int sd_attr_copy(struct sd_attr *out, const struct sd_attr *source)
|
|
{
|
|
if (out == NULL || !attr_live(source)) {
|
|
return SD_EINVAL;
|
|
}
|
|
if (out != source) {
|
|
*out = *source;
|
|
}
|
|
return SD_OK;
|
|
}
|
|
int sd_attr_reset(struct sd_attr *attr)
|
|
{
|
|
uint64_t bytes;
|
|
int rc;
|
|
if (!attr_live(attr)) {
|
|
return SD_EINVAL;
|
|
}
|
|
rc = sd_port_default(&attr->port, &bytes);
|
|
if (rc != SD_OK || attr->revision == UINT64_MAX) {
|
|
return SD_EINVAL;
|
|
}
|
|
attr->size = bytes;
|
|
attr->revision += 1;
|
|
attr->explicit_size = 0;
|
|
return SD_OK;
|
|
}
|
|
int sd_attr_destroy(struct sd_attr *attr)
|
|
{
|
|
if (!attr_live(attr)) {
|
|
return SD_EINVAL;
|
|
}
|
|
memset(attr, 0, sizeof(*attr));
|
|
return SD_OK;
|
|
}
|