mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Add alloc functions
This commit is contained in:
1 parent
f7ea462c00
commit
873c6b400a
7 files changed
+680
-47
No files matched your search
@@ -14,6 +14,7 @@
|
||||
- Added `std/wbmp`.
|
||||
- Added `WUFFS_BASE__PIXEL_BLEND__SRC_OVER`.
|
||||
- Added `WUFFS_BASE__PIXEL_FORMAT__BGR_565`.
|
||||
- Added alloc functions.
|
||||
- Added double-curly blocks.
|
||||
- Added interfaces.
|
||||
- Added preprocessor.
|
||||
|
||||
@@ -8,18 +8,20 @@ optional](/doc/note/initialization.md#partial-zero-initialization), for
|
||||
additional performance.
|
||||
|
||||
A deliberate constraint in the Wuffs language is that struct fields cannot
|
||||
store any pointers to dynamically allocated memory, only to e.g. statically
|
||||
store any pointers to dynamically allocated memory, only to statically
|
||||
allocated error messages (a `base.status`). When a Wuffs decompressor reads
|
||||
from or writes to a buffer, that buffer has to be passed on every call, instead
|
||||
of e.g. being passed once during initialization and saved to a field. There is
|
||||
no ambiguity about whether the caller or callee owns some memory, even when
|
||||
of being passed once during initialization and saved to a field. There is no
|
||||
ambiguity about whether the caller or callee should free some memory, even when
|
||||
encountering an error. It's always caller-owned and callee-borrowed.
|
||||
|
||||
Wuffs is also trivially safe against things like memory leaks, use-after-frees
|
||||
and double-frees because Wuffs code doesn't even have the *capability* to
|
||||
allocate or free memory. Wuffs is certainly less powerful than other
|
||||
programming languages, but with less power comes easier proof-of-safety. Still,
|
||||
Wuffs is not a toy language and can do [real work](/example).
|
||||
allocate or free memory, other than its transpiled-to-C form providing
|
||||
`wuffs_foo__bar__alloc` convenience functions to set up before processing a
|
||||
single byte of input. Wuffs is certainly less powerful than other programming
|
||||
languages, but **with less power comes easier proof of safety**. Still, Wuffs
|
||||
is not a toy language and the [example programs](/example) do real work.
|
||||
|
||||
Wuffs is a language for writing libraries, and complete programs require
|
||||
combining Wuffs with another programming language. The obvious example is the
|
||||
@@ -56,8 +58,10 @@ with [coroutines](/doc/note/coroutines.md). The
|
||||
[example/zcat](/example/zcat/zcat.c) program can decompress arbitrarily large
|
||||
input using static buffers, without ever calling `malloc`. Indeed, on Linux,
|
||||
that program self-imposes a `SECCOMP_MODE_STRICT` sandbox, prohibiting dynamic
|
||||
memory allocation (amongst many other useful but dangerous things) at the
|
||||
kernel level.
|
||||
memory allocation (amongst many other powerful but dangerous things) at the
|
||||
kernel level. The [example/jsonptr](/example/jsonptr/jsonptr.cc) program, which
|
||||
parses and filters [JSON](https://www.json.org/), is another example that does
|
||||
useful work within a strict sandbox.
|
||||
|
||||
|
||||
## Thread-Safety
|
||||
|
||||
Reference in new issue
Block a user