Skip to content

Commit e570143

Browse files
committed
Support complex macros.
1 parent beffdf0 commit e570143

36 files changed

+929
-569
lines changed

.github/workflows/bindgen.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: bindgen
22

33
on:
44
push:
5-
branches:
6-
- main
5+
# branches:
6+
# - master
77
pull_request:
8-
branches:
9-
- main
8+
# branches:
9+
# - master
1010

1111
jobs:
1212
rustfmt-clippy:

Cargo.lock

+74-49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-integration/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "bindgen-integration"
33
description = "A package to test various bindgen features"
44
version = "0.1.0"
5+
edition = "2018"
56
authors = ["Emilio Cobos Álvarez <[email protected]>"]
67
publish = false
78
build = "build.rs"

bindgen-integration/build.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extern crate cc;
44
use bindgen::callbacks::{
55
DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks,
66
};
7-
use bindgen::{Builder, CargoCallbacks, EnumVariation};
7+
use bindgen::{Builder, EnumVariation};
88
use std::collections::HashSet;
99
use std::env;
1010
use std::path::PathBuf;
@@ -60,36 +60,41 @@ impl ParseCallbacks for MacroCallback {
6060
}
6161
}
6262

63-
fn func_macro(&self, name: &str, value: &[&[u8]]) {
63+
fn func_macro(&self, name: &str, args: &[&str], value: &[&[u8]]) {
6464
match name {
6565
"TESTMACRO_NONFUNCTIONAL" => {
6666
panic!("func_macro was called for a non-functional macro");
6767
}
68-
"TESTMACRO_FUNCTIONAL_NONEMPTY(TESTMACRO_INTEGER)" => {
68+
"TESTMACRO_FUNCTIONAL_NONEMPTY" => {
6969
// Spaces are inserted into the right-hand side of a functional
7070
// macro during reconstruction from the tokenization. This might
7171
// change in the future, but it is safe by the definition of a
7272
// token in C, whereas leaving the spaces out could change
7373
// tokenization.
74+
assert_eq!(args, &["TESTMACRO_INTEGER"]);
7475
assert_eq!(value, &[b"-" as &[u8], b"TESTMACRO_INTEGER"]);
7576
*self.seen_funcs.lock().unwrap() += 1;
7677
}
77-
"TESTMACRO_FUNCTIONAL_EMPTY(TESTMACRO_INTEGER)" => {
78+
"TESTMACRO_FUNCTIONAL_EMPTY" => {
79+
assert_eq!(args, &["TESTMACRO_INTEGER"]);
7880
assert_eq!(value, &[] as &[&[u8]]);
7981
*self.seen_funcs.lock().unwrap() += 1;
8082
}
81-
"TESTMACRO_FUNCTIONAL_TOKENIZED(a,b,c,d,e)" => {
83+
"TESTMACRO_FUNCTIONAL_TOKENIZED" => {
84+
assert_eq!(args, &["a", "b", "c", "d", "e"]);
8285
assert_eq!(
8386
value,
8487
&[b"a" as &[u8], b"/", b"b", b"c", b"d", b"##", b"e"]
8588
);
8689
*self.seen_funcs.lock().unwrap() += 1;
8790
}
88-
"TESTMACRO_FUNCTIONAL_SPLIT(a,b)" => {
91+
"TESTMACRO_FUNCTIONAL_SPLIT" => {
92+
assert_eq!(args, &["a", "b"]);
8993
assert_eq!(value, &[b"b", b",", b"a"]);
9094
*self.seen_funcs.lock().unwrap() += 1;
9195
}
92-
"TESTMACRO_STRING_FUNC_NON_UTF8(x)" => {
96+
"TESTMACRO_STRING_FUNC_NON_UTF8" => {
97+
assert_eq!(args, &["x"]);
9398
assert_eq!(
9499
value,
95100
&[b"(" as &[u8], b"x", b"\"\xff\xff\"", b")"]

bindgen-tests/tests/expectations/tests/func_wrapper.rs

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/infinite-macro.rs

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)