1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// libwebp v1.6.0, src/webp/types.h:
//
// Copyright 2010 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
// Common types + memory wrappers
//
// Author: Skal (pascal.massimino@gmail.com)
//! C ABI export of `src/webp/types.h` from libwebp v1.6.0.
//!
//! Mirrors the header's structs with `repr(C)` and converts them to the
//! safe representations at the boundary; see
//! `docs/adr/0004-c-abi-boundary.md`.
//!
//! Work package: WP12 (decoder integration); exports `WebPMalloc` and `WebPFree`, which the decoder tools need first.
//!
//! Memory that C callers release with `WebPFree()` or `free()` comes from the
//! platform `malloc`, which this module declares (ADR 0004, memory). The other
//! ABI modules hand decoded samples to C through [`malloc_copy`].
//!
//! # Excluded undefined behavior
//!
//! Inputs that are undefined behavior (or assertion failures) in C and are
//! therefore excluded from the oracle comparison (PORTING rule 8):
//!
//! 1. **`WebPMalloc(0)`**: C asserts `nmemb * size > 0` in debug builds; the
//! ABI returns `malloc(0)`.
use c_void;
use cratewebp_safe_malloc;
// The platform allocator of the C library that Rust's standard library links
// already (ADR 0004).
unsafe extern "C"
/// Allocates `size` bytes with the platform `malloc`; null when it fails.
pub
/// Releases a block of the platform `malloc`.
///
/// # Safety
///
/// `ptr` is null or a block of the platform `malloc` that is not used again.
pub unsafe
/// Copies `bytes` into a new block of the platform `malloc`, which C releases
/// with `free()` or `WebPFree()`; null when the allocation fails.
pub
// upstream: src/utils/utils.c WebPMalloc
/// Allocates `size` bytes of memory. Returns null upon error. Memory must be
/// deallocated by calling `WebPFree()`. This function is made available by the
/// core `libwebp` library. C applies the size test of
/// `WebPSafeMalloc(1, size)` and then calls `malloc`; the test is the Rust
/// translation's, and the block comes from the platform `malloc`.
pub extern "C"
// upstream: src/utils/utils.c WebPFree
/// Releases memory returned by the `WebPDecode*()` functions (from
/// `decode.h`) and by `WebPMalloc()`.
///
/// # Safety
///
/// `ptr` is null or a block that this library returned and that is not used
/// again.
pub unsafe extern "C"