CodeSampleX

Пример

modernc.org/libc v1.72.5

Проверенный пример — golang modernc.org/libc v1.72.5. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден: libc.NewTLS returns a non-nil…

sha256:22fe9e5967a0a27cb15b12f1578c4a2140eec536145296caae45b1b751688609

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go

Среды запусков проверки

Окружение Контракт Этапы Запуск
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-11-08

Кейс

HOW
Цель
verify pkg:golang/modernc.org/libc@v1.72.5
Пакеты
Создан
2026-11-08T02:56:07Z

Контракт

  1. libc.NewTLS returns a non-nil *libc.TLS initialized with a positive ID and 0 active stack slots, and Close zeroes the TLS ID
  2. TLS.Alloc and TLS.Free allocate and release stack memory while updating StackSlots count
  3. libc.CString and libc.GoString round-trip UTF-8 strings and libc.Xstrcmp returns 0 for equal strings and a negative value when the first string is lexicographically smaller
  4. libc.Xmalloc, libc.Xmemset, libc.Xstrlen and libc.Xfree allocate, initialize, measure and release C heap memory

Файлы

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • libc_sample.go
  • spec.json
  • test/contract.go

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

PROMPT.md
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/libc@v1.72.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/modernc.org/libc@v1.72.5

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.
csx.json
{"case":{"caseId":"case:sha256:7616696f753680496ab5a013bfa84603bf82c06ff8e86b7e832babf6b9b00947","contract":["libc.NewTLS returns a non-nil *libc.TLS initialized with a positive ID and 0 active stack slots, and Close zeroes the TLS ID","TLS.Alloc and TLS.Free allocate and release stack memory while updating StackSlots count","libc.CString and libc.GoString round-trip UTF-8 strings and libc.Xstrcmp returns 0 for equal strings and a negative value when the first string is lexicographically smaller","libc.Xmalloc, libc.Xmemset, libc.Xstrlen and libc.Xfree allocate, initialize, measure and release C heap memory"],"goal":"verify pkg:golang/modernc.org/libc@v1.72.5","kind":"HOW","packages":["pkg:golang/modernc.org/libc@v1.72.5"],"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/libc@v1.72.5"],"schemaVersion":1,"subject":"pkg:golang/modernc.org/libc@v1.72.5","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require modernc.org/libc v1.72.5

require (
	github.com/dustin/go-humanize v1.0.1 // indirect
	github.com/google/uuid v1.6.0 // indirect
	github.com/mattn/go-isatty v0.0.20 // indirect
	github.com/ncruces/go-strftime v1.0.0 // indirect
	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
	golang.org/x/sys v0.41.0 // indirect
	modernc.org/mathutil v1.7.1 // indirect
	modernc.org/memory v1.11.0 // indirect
)
go.sum
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
modernc.org/cc/v4 v4.28.2 h1:3tQ0lf2ADtoby2EtSP+J7IE2SHwEJdP8ioR59wx7XpY=
modernc.org/cc/v4 v4.28.2/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
modernc.org/ccgo/v4 v4.34.2 h1:mxsy2FdrB6+qG3NfXefz1AmWv0ehOSDO4jxgxd7h9yo=
modernc.org/ccgo/v4 v4.34.2/go.mod h1:1L7us56+kAKu04p25EATpmBBvhbcqqZ85ibqWVwVgog=
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
modernc.org/gc/v3 v3.1.3 h1:6QAplYyVO+KdPW3pGnqmJDUxtkec8ooEWvks/hhU3lc=
modernc.org/gc/v3 v3.1.3/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
modernc.org/libc v1.72.5 h1:m2OGx9Ser1VvTS4Z9ZJlWs+CBMxutLaTiAWkNz+NB9U=
modernc.org/libc v1.72.5/go.mod h1:np0N7KDJ7eUtMZmOqVZNldrZyG+DHLl2B5pg8Hbar3U=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
libc_sample.go
package sample

import (
	"modernc.org/libc"
)

type ProbeResult struct {
	ThreadID     int32
	InitialSlots int
	ActiveSlots  int
	FreedSlots   int
	RoundTrip    string
	EqualCmp     int32
	OrderedCmp   int32
	FilledString string
	FilledLength int
}

func RunLibcProbe(input string) (ProbeResult, error) {
	tls := libc.NewTLS()
	defer tls.Close()

	res := ProbeResult{
		ThreadID:     tls.ID,
		InitialSlots: tls.StackSlots(),
	}

	slotPtr := tls.Alloc(16)
	res.ActiveSlots = tls.StackSlots()
	if slotPtr != 0 {
		tls.Free(16)
	}
	res.FreedSlots = tls.StackSlots()

	cstr, err := libc.CString(input)
	if err != nil {
		return res, err
	}
	defer libc.Xfree(tls, cstr)
	res.RoundTrip = libc.GoString(cstr)

	s1, err := libc.CString("alpha")
	if err != nil {
		return res, err
	}
	defer libc.Xfree(tls, s1)

	s2, err := libc.CString("alpha")
	if err != nil {
		return res, err
	}
	defer libc.Xfree(tls, s2)

	s3, err := libc.CString("beta")
	if err != nil {
		return res, err
	}
	defer libc.Xfree(tls, s3)

	res.EqualCmp = libc.Xstrcmp(tls, s1, s2)
	res.OrderedCmp = libc.Xstrcmp(tls, s1, s3)

	buf := libc.Xmalloc(tls, 16)
	if buf != 0 {
		defer libc.Xfree(tls, buf)
		libc.Xmemset(tls, buf, 'Z', 5)
		libc.Xmemset(tls, buf+5, 0, 1)
		res.FilledString = libc.GoString(buf)
		res.FilledLength = int(libc.Xstrlen(tls, buf))
	}

	return res, nil
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/modernc.org/libc@v1.72.5",
  "kind": "HOW",
  "packages": [
    "pkg:golang/modernc.org/libc@v1.72.5"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"modernc.org/libc"
	"sample"
)

func require(cond bool, msg string) {
	if !cond {
		fmt.Fprintln(os.Stderr, "contract assertion failed:", msg)
		os.Exit(1)
	}
}

func main() {
	res, err := sample.RunLibcProbe("modernc-libc-v1.72.5")
	require(err == nil, "RunLibcProbe must not return an error")
	require(res.ThreadID > 0, "libc.NewTLS must assign a positive thread ID")
	require(res.InitialSlots == 0, "new TLS must initialize with 0 stack slots")
	require(res.ActiveSlots == 1, "TLS.Alloc must increment StackSlots to 1")
	require(res.FreedSlots == 0, "TLS.Free must restore StackSlots to 0")
	require(res.RoundTrip == "modernc-libc-v1.72.5", "CString and GoString must round-trip UTF-8 text")
	require(res.EqualCmp == 0, "Xstrcmp must return 0 for equal C strings")
	require(res.OrderedCmp < 0, "Xstrcmp must return negative value when first C string is lexicographically smaller")
	require(res.FilledString == "ZZZZZ", "Xmalloc, Xmemset and GoString must produce expected 5-byte string")
	require(res.FilledLength == 5, "Xstrlen must return 5 for a 5-byte NUL-terminated buffer")

	tls := libc.NewTLS()
	require(tls != nil && tls.ID > 0, "direct NewTLS call must return initialized TLS")
	tls.Close()
	require(tls.ID == 0, "TLS.Close must zero the TLS ID")
}

Исходный сидер

аноним