Skip to content

Commit

Permalink
Support complex macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Mar 11, 2023
1 parent 59b897d commit 1137369
Show file tree
Hide file tree
Showing 36 changed files with 927 additions and 572 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/bindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: bindgen

on:
push:
branches:
- main
# branches:
# - master
pull_request:
branches:
- main
# branches:
# - master

jobs:
rustfmt-clippy:
Expand Down
123 changes: 74 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bindgen-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "bindgen-integration"
description = "A package to test various bindgen features"
version = "0.1.0"
edition = "2018"
authors = ["Emilio Cobos Álvarez <[email protected]>"]
publish = false
build = "build.rs"
Expand Down
19 changes: 12 additions & 7 deletions bindgen-integration/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate cc;
use bindgen::callbacks::{
DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks,
};
use bindgen::{Builder, CargoCallbacks, EnumVariation};
use bindgen::{Builder, EnumVariation};
use std::collections::HashSet;
use std::env;
use std::path::PathBuf;
Expand Down Expand Up @@ -60,36 +60,41 @@ impl ParseCallbacks for MacroCallback {
}
}

fn func_macro(&self, name: &str, value: &[&[u8]]) {
fn func_macro(&self, name: &str, args: &[&str], value: &[&[u8]]) {
match name {
"TESTMACRO_NONFUNCTIONAL" => {
panic!("func_macro was called for a non-functional macro");
}
"TESTMACRO_FUNCTIONAL_NONEMPTY(TESTMACRO_INTEGER)" => {
"TESTMACRO_FUNCTIONAL_NONEMPTY" => {
// Spaces are inserted into the right-hand side of a functional
// macro during reconstruction from the tokenization. This might
// change in the future, but it is safe by the definition of a
// token in C, whereas leaving the spaces out could change
// tokenization.
assert_eq!(args, &["TESTMACRO_INTEGER"]);
assert_eq!(value, &[b"-" as &[u8], b"TESTMACRO_INTEGER"]);
*self.seen_funcs.lock().unwrap() += 1;
}
"TESTMACRO_FUNCTIONAL_EMPTY(TESTMACRO_INTEGER)" => {
"TESTMACRO_FUNCTIONAL_EMPTY" => {
assert_eq!(args, &["TESTMACRO_INTEGER"]);
assert_eq!(value, &[] as &[&[u8]]);
*self.seen_funcs.lock().unwrap() += 1;
}
"TESTMACRO_FUNCTIONAL_TOKENIZED(a,b,c,d,e)" => {
"TESTMACRO_FUNCTIONAL_TOKENIZED" => {
assert_eq!(args, &["a", "b", "c", "d", "e"]);
assert_eq!(
value,
&[b"a" as &[u8], b"/", b"b", b"c", b"d", b"##", b"e"]
);
*self.seen_funcs.lock().unwrap() += 1;
}
"TESTMACRO_FUNCTIONAL_SPLIT(a,b)" => {
"TESTMACRO_FUNCTIONAL_SPLIT" => {
assert_eq!(args, &["a", "b"]);
assert_eq!(value, &[b"b", b",", b"a"]);
*self.seen_funcs.lock().unwrap() += 1;
}
"TESTMACRO_STRING_FUNC_NON_UTF8(x)" => {
"TESTMACRO_STRING_FUNC_NON_UTF8" => {
assert_eq!(args, &["x"]);
assert_eq!(
value,
&[b"(" as &[u8], b"x", b"\"\xff\xff\"", b")"]
Expand Down
16 changes: 16 additions & 0 deletions bindgen-tests/tests/expectations/tests/func_wrapper.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bindgen-tests/tests/expectations/tests/infinite-macro.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1137369

Please sign in to comment.