CONVERSION REFERENCE
The active converter includes one closed, synchronous profile for bounded whole-file UTF-8 reads and exact UTF-8 writes.
with open(path, 'r', encoding='utf-8', newline='') as handle:
...
Each session is one direct, one-item with statement inside a
top-level function. open is the unshadowed built-in and the handle
is a fresh direct name. Mode is literal 'r' or 'w',
encoding is exactly literal 'utf-8', and newline is exactly
literal ''. Multiple sessions may occur sequentially when each has
a closed one-operation lifecycle and request limits permit them.
def load(path: str) -> str:
with open(path, 'r', encoding='utf-8', newline='') as handle:
return handle.read()
Alternatively, assign zero-argument read() to one fresh direct
local, leave the context, and immediately return that value:
def load_named(path: str) -> str:
with open(path, 'r', encoding='utf-8', newline='') as handle:
content = handle.read()
return content
def save(path: str, text: str) -> int:
with open(path, 'w', encoding='utf-8', newline='') as handle:
handle.write(text)
return 0
The operand is one already-proved direct string name or a NUL-free string literal. The Python character-count result is deliberately discarded. Generated C writes the exact UTF-8 byte count, borrows the text, closes exactly once, and reports write or close failure.
def save_two(first: str, second: str, text: str) -> int:
with open(first, 'w', encoding='utf-8', newline='') as left:
left.write(text)
with open(second, 'w', encoding='utf-8', newline='') as right:
right.write(text)
return 0
Closed file sessions compose with ordinary supported control flow before or
after them. A file with statement itself remains a direct
function-body statement; it is not nested under a conditional or loop.
readline, seeking, handle iteration, or general file-object
behavior.close(), return,
post-region use, or a nested-control-flow session.Every generated file-effect entry point receives one additional final
int64_t *pycf_status parameter. It is hidden from Python,
required, non-null, writable, and points to storage owned by the external C
caller. The entry null-guards it, initializes it to 0 before
source-controlled work, and helpers overwrite it on failure.
The registered helper identities are
pycf.file.read_all_utf8_bounded@1.0.0 and
pycf.file.write_utf8_exact@1.0.0. Generated symbols are
pycf_file_read_all_utf8_bounded_v1 and
pycf_file_write_utf8_exact_v1.
| Status | Meaning | Ownership outcome |
|---|---|---|
| 0 | Success | Read buffer transfers to caller; write owns no result. |
| 1 | Open failure | No open handle or owned result remains. |
| 2 | Allocation failure | Any partial allocation is released. |
| 3 | Read failure | Close is still attempted exactly once. |
| 4 | Configured read limit exceeded | No oversized result is published. |
| 5 | Embedded NUL in read content | Read allocation is released. |
| 6 | Invalid RFC 3629 UTF-8 in read content | Read allocation is released. |
| 7 | Close failure | No second close is emitted; no read result transfers. |
| 8 | Exact write failure | Borrowed inputs remain caller-owned. |
char * is a unique
malloc-owned buffer. The caller releases it exactly once with
free.PYC3903; write literals containing NUL reject with
PYC3905.