CodeSampleX

샘플

modernc.org/libc v1.72.3: Xstrlen

검증된 샘플 — golang modernc.org/libc v1.72.3: Xstrlen. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: libc.Xstrlen(tls, ptr) returns libc.Tsize_t(0)…

sha256:e5af47b3a75042f96695659cde1de350e77106218469e7b6e3ee1db80eb44add

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-29

케이스

HOW
목표
verify modernc.org/libc.Xstrlen in pkg:golang/modernc.org/libc@v1.72.3
패키지
심벌
  • modernc.org/libc.Xstrlen
생성일
2026-11-29T01:42:50Z

컨트랙트

  1. libc.Xstrlen(tls, ptr) returns libc.Tsize_t(0) for an empty C string allocated with libc.CString
  2. libc.Xstrlen(tls, ptr) returns exact byte length as libc.Tsize_t for ASCII strings and is idempotent across repeated calls
  3. libc.Xstrlen(tls, ptr) counts raw UTF-8 bytes rather than Unicode runes for multi-byte strings
  4. libc.Xstrlen(tls, ptr) stops at the first embedded NUL byte and measures interior substrings via uintptr offset arithmetic
  5. libc.Xstrlen(tls, 0) safely returns 0 for a zero uintptr without faulting

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.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 modernc.org/libc.Xstrlen in pkg:golang/modernc.org/libc@v1.72.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/modernc.org/libc@v1.72.3
Demonstrate these symbols/APIs:
  - modernc.org/libc.Xstrlen

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:30b40ce54629d850bde714c81834dd916a635b035e0860468cf15e506f52ab00","contract":["libc.Xstrlen(tls, ptr) returns libc.Tsize_t(0) for an empty C string allocated with libc.CString","libc.Xstrlen(tls, ptr) returns exact byte length as libc.Tsize_t for ASCII strings and is idempotent across repeated calls","libc.Xstrlen(tls, ptr) counts raw UTF-8 bytes rather than Unicode runes for multi-byte strings","libc.Xstrlen(tls, ptr) stops at the first embedded NUL byte and measures interior substrings via uintptr offset arithmetic","libc.Xstrlen(tls, 0) safely returns 0 for a zero uintptr without faulting"],"goal":"verify modernc.org/libc.Xstrlen in pkg:golang/modernc.org/libc@v1.72.3","kind":"HOW","packages":["pkg:golang/modernc.org/libc@v1.72.3"],"schemaVersion":1,"symbols":["modernc.org/libc.Xstrlen"]},"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.3"],"schemaVersion":1,"subject":"pkg:golang/modernc.org/libc@v1.72.3","symbols":["modernc.org/libc.Xstrlen"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require modernc.org/libc v1.72.3

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.0 h1:yRLPFZieg532OT4rp4JFNIVcquwalMX26G95WQDqwCQ=
modernc.org/ccgo/v4 v4.34.0/go.mod h1:AS5WYMyBakQ+fhsHhtP8mWB82KTGPkNNJDGfGQCe0/A=
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.2 h1:ZtDCnhonXSZexk/AYsegNRV1lJGgaNZJuKjJSWKyEqo=
modernc.org/gc/v3 v3.1.2/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.3 h1:ZnDF4tXn4NBXFutMMQC4vtbTFSXhhKzR73fv0beZEAU=
modernc.org/libc v1.72.3/go.mod h1:dn0dZNnnn1clLyvRxLxYExxiKRZIRENOfqQ8XEeg4Qs=
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=
main.go
package main

import (
	"fmt"
	"log"

	"modernc.org/libc"
)

func main() {
	tls := libc.NewTLS()
	defer tls.Close()

	ptr, err := libc.CString("modernc-libc")
	if err != nil {
		log.Fatalf("CString allocation failed: %v", err)
	}
	defer libc.Xfree(tls, ptr)

	n := libc.Xstrlen(tls, ptr)
	fmt.Printf("strlen=%d\n", n)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify modernc.org/libc.Xstrlen in pkg:golang/modernc.org/libc@v1.72.3",
  "kind": "HOW",
  "packages": [
    "pkg:golang/modernc.org/libc@v1.72.3"
  ],
  "symbols": [
    "modernc.org/libc.Xstrlen"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"unicode/utf8"

	"modernc.org/libc"
)

func must(cond bool, msg string) {
	if !cond {
		fmt.Fprintf(os.Stderr, "FAIL: %s\n", msg)
		os.Exit(1)
	}
}

func main() {
	tls := libc.NewTLS()
	defer tls.Close()

	// 1. Empty C string returns length 0.
	emptyPtr, err := libc.CString("")
	must(err == nil && emptyPtr != 0, "CString(\"\") should succeed with non-zero pointer")
	defer libc.Xfree(tls, emptyPtr)
	must(libc.Xstrlen(tls, emptyPtr) == libc.Tsize_t(0), "Xstrlen on empty C string must return 0")

	// 2. Plain ASCII string returns exact byte count as libc.Tsize_t.
	ascii := "modernc-libc"
	asciiPtr, err := libc.CString(ascii)
	must(err == nil && asciiPtr != 0, "CString on ASCII input should succeed")
	defer libc.Xfree(tls, asciiPtr)
	must(libc.Xstrlen(tls, asciiPtr) == libc.Tsize_t(12), "Xstrlen on 12-byte ASCII string must return 12")
	must(libc.Xstrlen(tls, asciiPtr) == libc.Tsize_t(len(ascii)), "repeated Xstrlen call must return identical length")

	// 3. Multi-byte UTF-8 string counts raw bytes before NUL, not Unicode runes.
	utf8Text := "h\u00e9llo \u4e16\u754c"
	must(len(utf8Text) == 13 && utf8.RuneCountInString(utf8Text) == 8, "UTF-8 fixture must have 13 bytes and 8 runes")
	utf8Ptr, err := libc.CString(utf8Text)
	must(err == nil && utf8Ptr != 0, "CString on UTF-8 input should succeed")
	defer libc.Xfree(tls, utf8Ptr)
	must(libc.Xstrlen(tls, utf8Ptr) == libc.Tsize_t(13), "Xstrlen must return UTF-8 byte count (13), not rune count (8)")

	// 4. Embedded NUL byte stops scan early; interior uintptr offset measures trailing segment.
	withNul := "prefix\x00suffix"
	nulPtr, err := libc.CString(withNul)
	must(err == nil && nulPtr != 0, "CString on input with embedded NUL should succeed")
	defer libc.Xfree(tls, nulPtr)
	must(libc.Xstrlen(tls, nulPtr) == libc.Tsize_t(6), "Xstrlen must stop at first embedded NUL byte and return 6")
	must(libc.Xstrlen(tls, nulPtr+7) == libc.Tsize_t(6), "Xstrlen at uintptr offset past embedded NUL must return trailing length 6")

	// 5. Zero uintptr (NULL pointer) returns 0 without faulting.
	must(libc.Xstrlen(tls, 0) == libc.Tsize_t(0), "Xstrlen(tls, 0) must return 0 without panicking or faulting")

	fmt.Println("PASS: modernc.org/libc.Xstrlen contract verified")
}

오리진 시더

익명