Skip to content

Commit 35ccab7

Browse files
committed
Rename whitelist -> allowlist
For the commandline arguments I added undocumented aliases to old flags, to stay backwards compatible.
1 parent b1c4178 commit 35ccab7

File tree

71 files changed

+449
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+449
-357
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@
127127

128128
## Deprecated
129129

130+
* `bindgen::Builder::whitelist_type` is deprecated in favor of
131+
`bindgen::Builder::allowlist_type`. [#1812][]
132+
133+
* `bindgen::Builder::whitelist_function` is deprecated in favor of
134+
`bindgen::Builder::allowlist_function`. [#1812][]
135+
136+
* `bindgen::Builder::whitelist_var` is deprecated in favor of
137+
`bindgen::Builder::allowlist_var`. [#1812][]
138+
139+
* `--whitelist_type` is deprecated in favor of
140+
`--allowlist_type`. [#1812][]
141+
142+
* `--whitelist_function` is deprecated in favor of
143+
`--allowlist_function`. [#1812][]
144+
145+
* `--whitelist_var` is deprecated in favor of
146+
`--allowlist_var`. [#1812][]
147+
130148
## Removed
131149

132150
## Fixed

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- [Publish Your Crate!](./tutorial-6.md)
1313
- [Command Line Usage](./command-line-usage.md)
1414
- [Customizing the Generated Bindings](./customizing-generated-bindings.md)
15-
- [Whitelisting](./whitelisting.md)
15+
- [Allowlisting](./allowlisting.md)
1616
- [Blacklisting](./blacklisting.md)
1717
- [Treating a Type as an Opaque Blob of Bytes](./opaque.md)
1818
- [Replacing One Type with Another](./replacing-types.md)

book/src/allowlisting.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Allowlisting
2+
3+
Allowlisting allows us to be precise about which type, function, and global
4+
variable definitions `bindgen` generates bindings for. By default, if we don't
5+
specify any allowlisting rules, everything is considered allowlisted. This may
6+
not be desirable because of either
7+
8+
* the generated bindings contain a lot of extra definitions we don't plan on using, or
9+
* the header file contains C++ features for which Rust does not have a
10+
corresponding form (such as partial template specialization), and we would
11+
like to avoid these definitions
12+
13+
If we specify allowlisting rules, then `bindgen` will only generate bindings to
14+
types, functions, and global variables that match the allowlisting rules, or are
15+
transitively used by a definition that matches them.
16+
17+
### Library
18+
19+
* [`bindgen::Builder::allowlist_type`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_type)
20+
* [`bindgen::Builder::allowlist_function`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_function)
21+
* [`bindgen::Builder::allowlist_var`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_var)
22+
23+
### Command Line
24+
25+
* `--allowlist-type <type>`
26+
* `--allowlist-function <function>`
27+
* `--allowlist-var <var>`
28+
29+
### Annotations
30+
31+
None.

book/src/cpp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ it ends in `.hpp`. If it doesn't, adding `-x c++` clang args can be used to
1111
force C++ mode. You probably also want to use `-std=c++14` or similar clang args
1212
as well.
1313

14-
You pretty much **must** use [whitelisting](./whitelisting.md) when working
14+
You pretty much **must** use [allowlisting](./allowlisting.md) when working
1515
with C++ to avoid pulling in all of the `std::.*` types, many of which `bindgen`
1616
cannot handle. Additionally, you may want to mark other types as
1717
[opaque](./opaque.md) that `bindgen` stumbles on. It is recommended to mark
18-
all of `std::.*` opaque, and to whitelist only precisely the functions and types
18+
all of `std::.*` opaque, and to allowlist only precisely the functions and types
1919
you intend to use.
2020

2121
You should read up on the [FAQs](./faq.md) as well.

book/src/faq.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
55

66

7-
- [Why isn't `bindgen` generating methods for this whitelisted class?](#why-isnt-bindgen-generating-methods-for-this-whitelisted-class)
7+
- [Why isn't `bindgen` generating methods for this allowlisted class?](#why-isnt-bindgen-generating-methods-for-this-allowlisted-class)
88
- [Why isn't `bindgen` generating bindings to inline functions?](#why-isnt-bindgen-generating-bindings-to-inline-functions)
99
- [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl)
1010

1111
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1212

13-
### Why isn't `bindgen` generating methods for this whitelisted class?
13+
### Why isn't `bindgen` generating methods for this allowlisted class?
1414

1515
Are the methods `inline` methods, or defined inline in the class? For example:
1616

@@ -62,7 +62,7 @@ STL. That ties our hands when it comes to linking: ["Why isn't `bindgen` generat
6262
As far as generating opaque blobs of bytes with the correct size and alignment,
6363
`bindgen` can do pretty well. This is typically enough to let you use types that
6464
transitively contain STL things. We generally recommend marking `std::.*` as
65-
opaque, and then whitelisting only the specific things you need from the library
65+
opaque, and then allowlisting only the specific things you need from the library
6666
you're binding to that is pulling in STL headers.
6767
6868
### How to deal with bindgen generated padding fields?

book/src/whitelisting.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/codegen/impl_debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'a> ImplDebug<'a> for Item {
122122

123123
// We don't know if blacklisted items `impl Debug` or not, so we can't
124124
// add them to the format string we're building up.
125-
if !ctx.whitelisted_items().contains(&self.id()) {
125+
if !ctx.allowlisted_items().contains(&self.id()) {
126126
return None;
127127
}
128128

src/codegen/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl CodeGenerator for Item {
457457
// TODO(emilio, #453): Figure out what to do when this happens
458458
// legitimately, we could track the opaque stuff and disable the
459459
// assertion there I guess.
460-
warn!("Found non-whitelisted item in code generation: {:?}", self);
460+
warn!("Found non-allowlisted item in code generation: {:?}", self);
461461
}
462462

463463
result.set_seen(self.id());
@@ -725,7 +725,7 @@ impl CodeGenerator for Type {
725725
// These items don't need code generation, they only need to be
726726
// converted to rust types in fields, arguments, and such.
727727
// NOTE(emilio): If you add to this list, make sure to also add
728-
// it to BindgenContext::compute_whitelisted_and_codegen_items.
728+
// it to BindgenContext::compute_allowlisted_and_codegen_items.
729729
return;
730730
}
731731
TypeKind::TemplateInstantiation(ref inst) => {

src/ir/analysis/derive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'ctx> CannotDerive<'ctx> {
138138
}
139139

140140
fn constrain_type(&mut self, item: &Item, ty: &Type) -> CanDerive {
141-
if !self.ctx.whitelisted_items().contains(&item.id()) {
141+
if !self.ctx.allowlisted_items().contains(&item.id()) {
142142
trace!(
143143
" cannot derive {} for blacklisted type",
144144
self.derive_trait
@@ -640,10 +640,10 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> {
640640
}
641641

642642
fn initial_worklist(&self) -> Vec<ItemId> {
643-
// The transitive closure of all whitelisted items, including explicitly
643+
// The transitive closure of all allowlisted items, including explicitly
644644
// blacklisted items.
645645
self.ctx
646-
.whitelisted_items()
646+
.allowlisted_items()
647647
.iter()
648648
.cloned()
649649
.flat_map(|i| {

src/ir/analysis/has_destructor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
8383
}
8484

8585
fn initial_worklist(&self) -> Vec<ItemId> {
86-
self.ctx.whitelisted_items().iter().cloned().collect()
86+
self.ctx.allowlisted_items().iter().cloned().collect()
8787
}
8888

8989
fn constrain(&mut self, id: ItemId) -> ConstrainResult {

src/ir/analysis/has_float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
9494
}
9595

9696
fn initial_worklist(&self) -> Vec<ItemId> {
97-
self.ctx.whitelisted_items().iter().cloned().collect()
97+
self.ctx.allowlisted_items().iter().cloned().collect()
9898
}
9999

100100
fn constrain(&mut self, id: ItemId) -> ConstrainResult {

src/ir/analysis/has_type_param_in_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> {
100100
}
101101

102102
fn initial_worklist(&self) -> Vec<ItemId> {
103-
self.ctx.whitelisted_items().iter().cloned().collect()
103+
self.ctx.allowlisted_items().iter().cloned().collect()
104104
}
105105

106106
fn constrain(&mut self, id: ItemId) -> ConstrainResult {

src/ir/analysis/has_vtable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
147147
}
148148

149149
fn initial_worklist(&self) -> Vec<ItemId> {
150-
self.ctx.whitelisted_items().iter().cloned().collect()
150+
self.ctx.allowlisted_items().iter().cloned().collect()
151151
}
152152

153153
fn constrain(&mut self, id: ItemId) -> ConstrainResult {

src/ir/analysis/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ where
183183
{
184184
let mut dependencies = HashMap::default();
185185

186-
for &item in ctx.whitelisted_items() {
186+
for &item in ctx.allowlisted_items() {
187187
dependencies.entry(item).or_insert(vec![]);
188188

189189
{
@@ -192,7 +192,7 @@ where
192192
item.trace(
193193
ctx,
194194
&mut |sub_item: ItemId, edge_kind| {
195-
if ctx.whitelisted_items().contains(&sub_item) &&
195+
if ctx.allowlisted_items().contains(&sub_item) &&
196196
consider_edge(edge_kind)
197197
{
198198
dependencies

src/ir/analysis/sizedness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> {
194194

195195
fn initial_worklist(&self) -> Vec<TypeId> {
196196
self.ctx
197-
.whitelisted_items()
197+
.allowlisted_items()
198198
.iter()
199199
.cloned()
200200
.filter_map(|id| id.as_type_id(self.ctx))

src/ir/analysis/template_params.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ use crate::{HashMap, HashSet};
138138
/// template parameter is always used.
139139
///
140140
/// The final wrinkle is handling of blacklisted types. Normally, we say that
141-
/// the set of whitelisted items is the transitive closure of items explicitly
142-
/// called out for whitelisting, *without* any items explicitly called out as
141+
/// the set of allowlisted items is the transitive closure of items explicitly
142+
/// called out for allowlisting, *without* any items explicitly called out as
143143
/// blacklisted. However, for the purposes of this analysis's correctness, we
144144
/// simplify and consider run the analysis on the full transitive closure of
145-
/// whitelisted items. We do, however, treat instantiations of blacklisted items
145+
/// allowlisted items. We do, however, treat instantiations of blacklisted items
146146
/// specially; see `constrain_instantiation_of_blacklisted_template` and its
147147
/// documentation for details.
148148
#[derive(Debug, Clone)]
@@ -155,10 +155,10 @@ pub struct UsedTemplateParameters<'ctx> {
155155

156156
dependencies: HashMap<ItemId, Vec<ItemId>>,
157157

158-
// The set of whitelisted items, without any blacklisted items reachable
159-
// from the whitelisted items which would otherwise be considered
160-
// whitelisted as well.
161-
whitelisted_items: HashSet<ItemId>,
158+
// The set of allowlisted items, without any blacklisted items reachable
159+
// from the allowlisted items which would otherwise be considered
160+
// allowlisted as well.
161+
allowlisted_items: HashSet<ItemId>,
162162
}
163163

164164
impl<'ctx> UsedTemplateParameters<'ctx> {
@@ -379,10 +379,10 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
379379
fn new(ctx: &'ctx BindgenContext) -> UsedTemplateParameters<'ctx> {
380380
let mut used = HashMap::default();
381381
let mut dependencies = HashMap::default();
382-
let whitelisted_items: HashSet<_> =
383-
ctx.whitelisted_items().iter().cloned().collect();
382+
let allowlisted_items: HashSet<_> =
383+
ctx.allowlisted_items().iter().cloned().collect();
384384

385-
let whitelisted_and_blacklisted_items: ItemSet = whitelisted_items
385+
let allowlisted_and_blacklisted_items: ItemSet = allowlisted_items
386386
.iter()
387387
.cloned()
388388
.flat_map(|i| {
@@ -398,7 +398,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
398398
})
399399
.collect();
400400

401-
for item in whitelisted_and_blacklisted_items {
401+
for item in allowlisted_and_blacklisted_items {
402402
dependencies.entry(item).or_insert(vec![]);
403403
used.entry(item).or_insert(Some(ItemSet::new()));
404404

@@ -457,17 +457,17 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
457457
}
458458

459459
if cfg!(feature = "testing_only_extra_assertions") {
460-
// Invariant: The `used` map has an entry for every whitelisted
460+
// Invariant: The `used` map has an entry for every allowlisted
461461
// item, as well as all explicitly blacklisted items that are
462-
// reachable from whitelisted items.
462+
// reachable from allowlisted items.
463463
//
464464
// Invariant: the `dependencies` map has an entry for every
465-
// whitelisted item.
465+
// allowlisted item.
466466
//
467467
// (This is so that every item we call `constrain` on is guaranteed
468468
// to have a set of template parameters, and we can allow
469469
// blacklisted templates to use all of their parameters).
470-
for item in whitelisted_items.iter() {
470+
for item in allowlisted_items.iter() {
471471
extra_assert!(used.contains_key(item));
472472
extra_assert!(dependencies.contains_key(item));
473473
item.trace(
@@ -485,15 +485,15 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
485485
ctx: ctx,
486486
used: used,
487487
dependencies: dependencies,
488-
whitelisted_items: whitelisted_items,
488+
allowlisted_items: allowlisted_items,
489489
}
490490
}
491491

492492
fn initial_worklist(&self) -> Vec<ItemId> {
493-
// The transitive closure of all whitelisted items, including explicitly
493+
// The transitive closure of all allowlisted items, including explicitly
494494
// blacklisted items.
495495
self.ctx
496-
.whitelisted_items()
496+
.allowlisted_items()
497497
.iter()
498498
.cloned()
499499
.flat_map(|i| {
@@ -538,7 +538,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
538538
// template definition uses the corresponding template parameter.
539539
Some(&TypeKind::TemplateInstantiation(ref inst)) => {
540540
if self
541-
.whitelisted_items
541+
.allowlisted_items
542542
.contains(&inst.template_definition().into())
543543
{
544544
self.constrain_instantiation(

0 commit comments

Comments
 (0)