You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No safe way to hand a str's bytes to a C (const void *, size_t) parameter: the user read the str header like std/regex.w does #3130
To pass multipart data to curl_mime_data(part, const char *data, size_t datasize), the user found std/regex.w:123's trick of reading a str's first word as its data pointer and copied it into application code (with unsafe). A program should never read a representation.
The facade grammar has buffer param data len param datasize for this shape; it needs to accept &str (and &[u8]/&List[u8]) at that pair and supply pointer and length, so the presented call is part.data(body)?. Separately, std should not need the trick either: a str.as_bytes() view (a &[u8] over the same buffer) is the one spelling for "the bytes of this text", and the regex engine's reader moves to it.
Done when: buffer param takes a &str; str.as_bytes() exists; no file under lib/ or src/ reads a str's header words directly.
use c_import("int put(const char *src, unsigned long n); int putv(const void *src, unsigned long n);")
c contract x:
fn put
buffer param src len param n
fn putv
buffer param src len param n
put(body) with body: str: refused, "argument expression 'body' has type str" (the rendered parameter is []u8). Same for putv.
put(body.as_bytes()): accepted, safe, no unsafe. str.as_bytes() already exists (lib/std/string.w, "The bytes as a view (§16.5): s as []u8").
put(bytes) with bytes: List[u8]: accepted.
So the issue's first cause is gone: a program no longer needs to read a str's header to pass its bytes. What is left is one call, .as_bytes(), at each such argument, and two places in std that still read the header (lib/std/regex.w:123, lib/std/internal/str_abi.w:11).
1. What the others do. Rust: s.as_bytes(), explicit; a &str is never a &[u8]. Go: []byte(s), explicit and a copy. Zig: a string is[]const u8; nothing to convert. Swift: a String argument bridges implicitly to a C const char * parameter, and not to a (pointer, length) pair.
2. What the spec says. §16.3c (D47): "A str may be passed automatically to a *const c_char parameter" of a c_import function: the precedent for lending text to C without a spelling. §16.2b.8: "buffer param P len param L renders P and L as one []u8 parameter". §16.5: s as []u8 is the view of a str's bytes. Nothing lets a str stand where a []u8 is expected.
3. Mission fit. The program has already determined everything: the facade says "these bytes and their count", the argument is a str, and a str's bytes are its UTF-8, one meaning. .as_bytes() there is a spelling the compiler already knows. D47 made the same call for const char *.
B. A str converts to []u8 at any []u8 parameter. A language rule, not a facade rule: every With function taking []u8 accepts text. Wider than the issue; it makes "text or bytes" invisible at every call, including ones where passing text was a mistake.
(Leaving it as .as_bytes() is not offered: it is the ceremony the issue is about.)
4. Prediction: A, 80%. It is the issue's own "done when" ("buffer param takes a &str"), it mirrors D47's scope, and it adds a capability only where a contract already states the bytes-and-length meaning.
Spec sentence A would add (derived, not landed), after "the compiler supplies the pointer and the byte length from that one value." in §16.2b.8:
A str is accepted where an input buffer is rendered: its bytes and their length are supplied, as s as []u8 supplies them.
Mine without a ruling: the two std sites stop reading a str's header (they take the bytes through the view), which closes the issue's third item.
Landed in #3410 (ruling of 2026-11-17, option A). A str is accepted where a contract renders an input buffer (buffer param P len param L): part.data(body) is the presented call. An output buffer (capacity … inout) and a program's own []u8 parameter still take bytes. A slice has as_ptr() / as_mut_ptr(), named as List's are, and the two reads of a str's header in std (regex.w, internal/str_abi.w) go through them. §16.2b.8 carries the blessed sentence.
Activity
ehartford commentedon Nov 17, 2026
Brief (2026-11-17): a
strat a facade's input bufferThe facts (installed compiler, main fe2e430):
put(body)withbody: str: refused, "argument expression 'body' has type str" (the rendered parameter is[]u8). Same forputv.put(body.as_bytes()): accepted, safe, nounsafe.str.as_bytes()already exists (lib/std/string.w, "The bytes as a view (§16.5):s as []u8").put(bytes)withbytes: List[u8]: accepted.So the issue's first cause is gone: a program no longer needs to read a
str's header to pass its bytes. What is left is one call,.as_bytes(), at each such argument, and two places in std that still read the header (lib/std/regex.w:123,lib/std/internal/str_abi.w:11).1. What the others do. Rust:
s.as_bytes(), explicit; a&stris never a&[u8]. Go:[]byte(s), explicit and a copy. Zig: a string is[]const u8; nothing to convert. Swift: aStringargument bridges implicitly to a Cconst char *parameter, and not to a (pointer, length) pair.2. What the spec says. §16.3c (D47): "A
strmay be passed automatically to a*const c_charparameter" of a c_import function: the precedent for lending text to C without a spelling. §16.2b.8: "buffer param P len param LrendersPandLas one[]u8parameter". §16.5:s as []u8is the view of astr's bytes. Nothing lets astrstand where a[]u8is expected.3. Mission fit. The program has already determined everything: the facade says "these bytes and their count", the argument is a
str, and astr's bytes are its UTF-8, one meaning..as_bytes()there is a spelling the compiler already knows. D47 made the same call forconst char *.Options.
stris accepted at a facade's input buffer. Where abuffer … lenclause renders an input[]u8(notcapacity … inout, which C writes), astrargument is its bytes and their length. Scope: facade-rendered parameters only, as D47 is c_import-only.part.data(body)?is then the presented call, which is what No safe way to hand astr's bytes to a C(const void *, size_t)parameter: the user read the str header like std/regex.w does #3130 asks for.strconverts to[]u8at any[]u8parameter. A language rule, not a facade rule: every With function taking[]u8accepts text. Wider than the issue; it makes "text or bytes" invisible at every call, including ones where passing text was a mistake..as_bytes()is not offered: it is the ceremony the issue is about.)4. Prediction: A, 80%. It is the issue's own "done when" ("
buffer paramtakes a&str"), it mirrors D47's scope, and it adds a capability only where a contract already states the bytes-and-length meaning.Spec sentence A would add (derived, not landed), after "the compiler supplies the pointer and the byte length from that one value." in §16.2b.8:
Mine without a ruling: the two std sites stop reading a
str's header (they take the bytes through the view), which closes the issue's third item.Contracts: a str is accepted where an input buffer is rendered. Its b…
ehartford commentedon Nov 17, 2026
Landed in #3410 (ruling of 2026-11-17, option A). A
stris accepted where a contract renders an input buffer (buffer param P len param L):part.data(body)is the presented call. An output buffer (capacity … inout) and a program's own[]u8parameter still take bytes. A slice hasas_ptr()/as_mut_ptr(), named as List's are, and the two reads of a str's header in std (regex.w,internal/str_abi.w) go through them. §16.2b.8 carries the blessed sentence.