示例
modernc.org/memory v1.5.0
已验证示例 — golang modernc.org/memory v1.5.0. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: Allocator.Calloc allocates zero-initialized memory slices…
sha256:9a97c7453795e851b8021d9aea29c31142cdeba19c69cb5f4d0063be3656d173
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-20 |
案例
HOW- 目标
- verify pkg:golang/modernc.org/memory@v1.5.0
- 创建时间
- 2026-08-19T23:14:17Z
契约
- Allocator.Calloc allocates zero-initialized memory slices and Allocator.Free releases them
- Allocator.Malloc allocates uninitialized memory slices and Allocator.Realloc resizes slices preserving existing content
- UsableSize reports the actual usable capacity of allocated memory slices
- Allocator.UintptrCalloc and Allocator.UintptrFree manage memory allocations using uintptr addresses
- Allocator.Close releases OS resources allocated by the Allocator instance
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
源代码
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:golang/modernc.org/memory@v1.5.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/modernc.org/memory@v1.5.0
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:1d6fe7c4d5894fd413381e248e6721f4d7cadb4f27f7f32dcb1722b6adfe52e2","contract":["Allocator.Calloc allocates zero-initialized memory slices and Allocator.Free releases them","Allocator.Malloc allocates uninitialized memory slices and Allocator.Realloc resizes slices preserving existing content","UsableSize reports the actual usable capacity of allocated memory slices","Allocator.UintptrCalloc and Allocator.UintptrFree manage memory allocations using uintptr addresses","Allocator.Close releases OS resources allocated by the Allocator instance"],"goal":"verify pkg:golang/modernc.org/memory@v1.5.0","kind":"HOW","packages":["pkg:golang/modernc.org/memory@v1.5.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/modernc.org/memory@v1.5.0"],"schemaVersion":1,"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require modernc.org/memory v1.5.0
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
package main
import (
"fmt"
"modernc.org/memory"
)
// BufferPool manages memory buffers using a modernc.org/memory Allocator.
type BufferPool struct {
allocator memory.Allocator
}
// NewBufferPool creates an initialized BufferPool.
func NewBufferPool() *BufferPool {
return &BufferPool{}
}
// AllocateZeroed allocates a zero-initialized byte slice of the requested size.
func (p *BufferPool) AllocateZeroed(size int) ([]byte, error) {
return p.allocator.Calloc(size)
}
// AllocateRaw allocates an uninitialized byte slice of the requested size.
func (p *BufferPool) AllocateRaw(size int) ([]byte, error) {
return p.allocator.Malloc(size)
}
// Resize resizes an existing byte slice to a new size, preserving original contents.
func (p *BufferPool) Resize(b []byte, newSize int) ([]byte, error) {
return p.allocator.Realloc(b, newSize)
}
// Release deallocates a previously allocated byte slice.
func (p *BufferPool) Release(b []byte) error {
return p.allocator.Free(b)
}
// GetCapacity returns the actual usable capacity of an allocated byte slice.
func (p *BufferPool) GetCapacity(b []byte) int {
if len(b) == 0 {
return 0
}
return memory.UsableSize(&b[0])
}
// Close releases all OS resources backing the buffer pool.
func (p *BufferPool) Close() error {
return p.allocator.Close()
}
func main() {
pool := NewBufferPool()
defer pool.Close()
buf, err := pool.AllocateZeroed(64)
if err != nil {
fmt.Printf("Allocation failed: %v\n", err)
return
}
copy(buf, []byte("CodeSampleX verification"))
fmt.Printf("Allocated buffer with %d bytes, usable capacity %d\n", len(buf), pool.GetCapacity(buf))
resized, err := pool.Resize(buf, 128)
if err != nil {
fmt.Printf("Reallocation failed: %v\n", err)
return
}
fmt.Printf("Resized buffer to %d bytes: %s\n", len(resized), string(resized[:24]))
if err := pool.Release(resized); err != nil {
fmt.Printf("Release failed: %v\n", err)
return
}
fmt.Println("Memory management completed successfully.")
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/modernc.org/memory@v1.5.0",
"kind": "HOW",
"packages": [
"pkg:golang/modernc.org/memory@v1.5.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"fmt"
"os"
"modernc.org/memory"
)
func main() {
// Assertion 1: Allocator.Calloc allocates zero-initialized memory slices and Allocator.Free releases them
{
var alloc memory.Allocator
size := 128
buf, err := alloc.Calloc(size)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Calloc(%d) returned error: %v\n", size, err)
os.Exit(1)
}
if len(buf) != size {
fmt.Fprintf(os.Stderr, "FAIL: Calloc(%d) returned slice of length %d\n", size, len(buf))
os.Exit(1)
}
for i, b := range buf {
if b != 0 {
fmt.Fprintf(os.Stderr, "FAIL: Calloc(%d) byte at index %d is non-zero: %d\n", size, i, b)
os.Exit(1)
}
}
if err := alloc.Free(buf); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Free returned error: %v\n", err)
os.Exit(1)
}
_ = alloc.Close()
}
// Assertion 2: Allocator.Malloc allocates uninitialized memory slices and Allocator.Realloc resizes slices preserving existing content
{
var alloc memory.Allocator
initialSize := 32
buf, err := alloc.Malloc(initialSize)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Malloc(%d) returned error: %v\n", initialSize, err)
os.Exit(1)
}
if len(buf) != initialSize {
fmt.Fprintf(os.Stderr, "FAIL: Malloc(%d) returned slice of length %d\n", initialSize, len(buf))
os.Exit(1)
}
payload := []byte("sample payload data 12345")
copy(buf, payload)
expandedSize := 96
resizedBuf, err := alloc.Realloc(buf, expandedSize)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Realloc to %d returned error: %v\n", expandedSize, err)
os.Exit(1)
}
if len(resizedBuf) != expandedSize {
fmt.Fprintf(os.Stderr, "FAIL: Realloc to %d returned slice of length %d\n", expandedSize, len(resizedBuf))
os.Exit(1)
}
for i, b := range payload {
if resizedBuf[i] != b {
fmt.Fprintf(os.Stderr, "FAIL: Realloc corrupted data at index %d: expected %d, got %d\n", i, b, resizedBuf[i])
os.Exit(1)
}
}
if err := alloc.Free(resizedBuf); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Free after Realloc returned error: %v\n", err)
os.Exit(1)
}
_ = alloc.Close()
}
// Assertion 3: UsableSize reports the actual usable capacity of allocated memory slices
{
var alloc memory.Allocator
reqSize := 48
buf, err := alloc.Calloc(reqSize)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Calloc(%d) error: %v\n", reqSize, err)
os.Exit(1)
}
usable := memory.UsableSize(&buf[0])
if usable < reqSize {
fmt.Fprintf(os.Stderr, "FAIL: UsableSize(%d) returned %d, expected >= %d\n", reqSize, usable, reqSize)
os.Exit(1)
}
if err := alloc.Free(buf); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Free error: %v\n", err)
os.Exit(1)
}
_ = alloc.Close()
}
// Assertion 4: Allocator.UintptrCalloc and Allocator.UintptrFree manage memory allocations using uintptr addresses
{
var alloc memory.Allocator
reqSize := 64
ptr, err := alloc.UintptrCalloc(reqSize)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: UintptrCalloc(%d) error: %v\n", reqSize, err)
os.Exit(1)
}
if ptr == 0 {
fmt.Fprintf(os.Stderr, "FAIL: UintptrCalloc returned nil pointer (0)\n")
os.Exit(1)
}
usable := memory.UintptrUsableSize(ptr)
if usable < reqSize {
fmt.Fprintf(os.Stderr, "FAIL: UintptrUsableSize returned %d, expected >= %d\n", usable, reqSize)
os.Exit(1)
}
if err := alloc.UintptrFree(ptr); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: UintptrFree error: %v\n", err)
os.Exit(1)
}
_ = alloc.Close()
}
// Assertion 5: Allocator.Close releases OS resources allocated by the Allocator instance
{
var alloc memory.Allocator
buf, err := alloc.Calloc(1024)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Calloc before Close returned error: %v\n", err)
os.Exit(1)
}
_ = alloc.Free(buf)
if err := alloc.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Close returned error: %v\n", err)
os.Exit(1)
}
}
fmt.Println("PASS: modernc.org/memory contract verified")
}
原始种子者
匿名