샘플
modernc.org/memory v1.5.0
검증된 샘플 — golang modernc.org/memory v1.5.0. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: Allocator.Calloc allocates zero-initialized memory…
sha256:9a97c7453795e851b8021d9aea29c31142cdeba19c69cb5f4d0063be3656d173
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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")
}
오리진 시더
익명