Skip to content

Commit ea1de38

Browse files
committed
Add PyBuffer tests, documentation, and examples
- test/py_buffer_SUITE.erl: Common Test suite with 13 tests for: - Basic buffer creation (with/without content length) - Write/read cycle, readline, readlines - Seek/tell position tracking - Fast find with memchr/memmem - Zero-copy memoryview access - Line iteration, closed/empty buffer handling - Auto-conversion when passing buffer ref to Python - GC and reference counting verification - docs/buffer.md: Documentation covering: - Erlang API (new, write, close) - Python API (file-like methods, buffer protocol, find) - Architecture diagram and memory layout - Performance tips and examples - examples/py_buffer_example.erl: Working escript demonstrating: - Basic buffer usage - HTTP body streaming simulation - File-like interface methods - Zero-copy memoryview access - Line iteration for CSV-like data - CHANGELOG.md: Added PyBuffer API entry under 2.2.0 - docs/getting-started.md: Added Zero-Copy Buffers section with link to buffer.md
1 parent de998a3 commit ea1de38

5 files changed

Lines changed: 1068 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44

55
### Added
66

7+
- **PyBuffer API** - Zero-copy WSGI input buffer for streaming HTTP bodies
8+
- `py_buffer:new/0,1` - Create buffer (chunked or with content_length)
9+
- `py_buffer:write/2` - Append data, signals waiting Python readers
10+
- `py_buffer:close/1` - Signal EOF, wake all readers
11+
- Python `PyBuffer` type with file-like interface:
12+
- `read(size)`, `readline()`, `readlines()` - Blocking reads with GIL released
13+
- `seek(offset, whence)`, `tell()` - Position tracking
14+
- `find(sub)` - Fast substring search via memmem/memchr
15+
- `memoryview(buf)` - Zero-copy buffer protocol
16+
- `for line in buf:` - Line iteration
17+
- Auto-conversion: Passing buffer ref to `py:call`/`py:eval` wraps as `PyBuffer`
18+
- Suitable for `wsgi.input` in WSGI applications
19+
- See [Buffer API docs](docs/buffer.md)
20+
721
- **Inline Continuation API** - High-performance scheduling without Erlang messaging
822
- `erlang.schedule_inline(module, func, args, kwargs)` - Chain Python calls via `enif_schedule_nif()`
923
- ~3x faster than `schedule_py` for tight loops (bypasses gen_server messaging)

0 commit comments

Comments
 (0)