Byte-stream adapters
|
Type
|
Level
|
MID
|
UID
|
REFS
|
Title
|
Statement
|
Rationale
|
Comment
|
BIBLIOGRAPHY
|
STATUS
|
COMPONENT
|
APPLICABILITY
|
VERIFICATION_METHODS
|
VERIFICATION_CRITERIA
|
SOURCE
|
LANGUAGE
|
VISIBILITY
|
INTERFACE
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
SW_SPEC
|
1 |
|
|
|
A c_streambuf shall begin without cached input or unget history and shall release its own buffer state on destruction without owning the derived transport. A read callback shall borrow its output array for that call only, return a count in the requested range, write exactly that prefix and consume the corresponding source prefix. Positive partial results shall have the same remaining logical input and future availability as successive one-byte reads. Zero for a positive request shall be the same failure as a one-byte request in that entry state, without making later transfer availability depend on the requested size. A later client operation may succeed after such refusal. Peeking shall retain the next byte without logically consuming it; repeated peeks shall return that byte. Single and bulk reads shall consume cached input first and then callbacks until the request is met or the callback returns zero. They shall distinguish every unsigned-byte value from EOF and return the actual count. Counts shall be nonnegative, and positive requests shall have sufficient output storage; a zero request shall access no storage or callback and preserve cached input and unget history. A successful single or nonempty bulk read shall make its final byte available for one unget. Explicit putback shall instead supply its requested byte. Putback shall fail without changing an already pending byte; no-history unget shall fail without inventing input. Read failure may discard old history. The default callback shall provide no input. Direct streambuf operations shall propagate callback exceptions; partial effects before an exception shall not be rolled back, and a cached byte already transferred need not be restored. |
Numeric parsers must see a coherent byte sequence despite lookahead, partial transfers, putback and transport failures. |
|
|
|
|
|
Check literal binary sequences containing all byte values, repeated peeks, mixed chunk boundaries, empty and zero requests, unget and replacement before/after reads, pending-byte refusal, temporary callback refusal and exceptions. Compare bulk results with successive single-byte reads and verify stream-state/exception-mask integration. |
src/c_streambuf_defs.hh; src/c_streambuf_inlines.hh; src/c_streambuf.cc; src/stdiobuf_defs.hh; src/stdiobuf_inlines.hh; src/stdiobuf.cc; tests/cstreambuf1.cc. |
|
|
Defining header: c_streambuf_defs.hh. Namespace: Parma_Polyhedra_Library. Standard streambuf operations dispatch to the following overrides; callbacks are private virtual functions that a derived transport may override. c_streambuf(); virtual ~c_streambuf(); int_type underflow() override; int_type uflow() override; std::streamsize xsgetn(char_type*, std::streamsize) override; int_type pbackfail(int_type = traits_type::eof()) override; virtual size_t cb_read(char*, size_t); |
||
|
SW_SPEC
|
2 |
|
|
|
A c_streambuf write callback shall borrow its input array only for the call, return a count in the requested range and transfer exactly that prefix. Successive positive partial transfers shall be accepted until the request is complete or zero reports refusal. A callback result of zero for a positive request shall have the same failure and subsequent transfer availability as a one-byte request in that entry state; positive results shall preserve the same subsequent accepted byte sequences as successive one-byte writes. Positive requests shall have sufficient readable storage; counts shall be nonnegative. A zero request shall transfer nothing and call no write callback, admitting a null pointer. Single-character output shall report the supplied byte on success and EOF on refusal. An overflow request containing EOF shall synchronize, returning non-EOF exactly when synchronization succeeds. sync() shall return the synchronization callback's result. Defaults shall refuse output and report successful synchronization. Output and synchronization shall preserve cached input and unget history. Direct operations shall propagate callback exceptions without promising rollback of previously transferred output. Standard istream/ostream state and exception masks shall govern use through those streams. |
Transport refusal must preserve the actual transferred prefix and remain visible through standard stream error handling. |
|
|
|
|
|
Exercise partial/zero writes, all byte values, ordinary/EOF overflow, synchronization success/failure, default callbacks, thrown callbacks, standard stream states and exception masks; interleave input/output and confirm pending input and unget history survive output failures. |
src/c_streambuf_defs.hh; src/c_streambuf_inlines.hh; src/c_streambuf.cc; src/stdiobuf_defs.hh; src/stdiobuf_inlines.hh; src/stdiobuf.cc; tests/cstreambuf1.cc. |
|
|
Defining header: c_streambuf_defs.hh. Namespace: Parma_Polyhedra_Library. std::streamsize xsputn(const char_type*, std::streamsize) override; int_type overflow(int_type) override; int sync() override; virtual size_t cb_write(const char*, size_t); virtual int cb_sync(); |
||
|
SW_SPEC
|
3 |
|
|
Incoming link from:
4. Borrowed stdio output and synchronization
1 |
stdiobuf(file) shall borrow a nonnull open FILE* without closing it on destruction. The caller shall keep it open, provide permissions for requested operations, and observe stdio update-stream sequencing rules. Input shall use the file's byte sequence, distinguish every unsigned byte from EOF, and return the actual number read into the supplied prefix. Bulk counts shall be nonnegative and the supplied output array shall cover the requested count. Peeking shall leave its byte pending in the file through stdio putback. A successful read shall retain its last byte for one unget; a failed read may discard that history. Explicit putback shall request the specified byte even without prior history, using stdio's ungetc result. No-history unget shall fail without inventing a byte. Additional putback capacity beyond stdio's guarantee shall not be required. Input failures shall remain visible through EOF/short counts and the file's stdio state. |
The C++ buffer must preserve the caller-owned file and the C byte-stream failure model. |
|
|
|
|
|
Use temporary binary files containing literal byte sequences, all byte values, mixed peeks/reads, actual EOF and short reads, unget and explicit replacement before/after reads. Check literal suffixes and the continued usability of the file after buffer destruction. |
src/c_streambuf_defs.hh; src/c_streambuf_inlines.hh; src/c_streambuf.cc; src/stdiobuf_defs.hh; src/stdiobuf_inlines.hh; src/stdiobuf.cc; tests/cstreambuf1.cc. |
|
|
Defining header: stdiobuf_defs.hh. Namespace: Parma_Polyhedra_Library. stdiobuf(FILE*); int_type underflow() override; int_type uflow() override; std::streamsize xsgetn(char_type*, std::streamsize) override; int_type pbackfail(int_type = traits_type::eof()) override; |
||
|
SW_SPEC
|
4 |
|
|
|
Under the file-lifetime and stdio sequencing conditions in 🔗 3. Borrowed stdio input and putback, bulk output through stdiobuf shall write the supplied byte prefix and return stdio's actual transferred count. Counts shall be nonnegative and the readable input array shall cover the request. Ordinary single-byte overflow shall return the stdio byte-write result. EOF overflow shall flush the file and return non-EOF exactly on success; sync() shall return the result of flushing. The adapter shall not close the file. Failures shall be observable as short counts, EOF or failed synchronization; standard ostream state and exception masks shall apply when used through an ostream. No rollback of transferred bytes shall be required. |
File output needs explicit transfer and ownership guarantees without inventing atomicity that stdio does not provide. |
|
|
|
|
|
Check every byte through single and bulk output, successful ordinary/EOF flush paths and file survival. Use a portably opened read-only file to exercise write refusal and a controlled failing stdio transport where supported for short writes and failed flush; check standard stream state. |
src/c_streambuf_defs.hh; src/c_streambuf_inlines.hh; src/c_streambuf.cc; src/stdiobuf_defs.hh; src/stdiobuf_inlines.hh; src/stdiobuf.cc; tests/cstreambuf1.cc. |
|
|
Defining header: stdiobuf_defs.hh. Namespace: Parma_Polyhedra_Library. std::streamsize xsputn(const char_type*, std::streamsize) override; int_type overflow(int_type) override; int sync() override; |