From 40346bce47e2e082af3a26a85237193c3e1ea4e9 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 20 Jun 2020 13:52:07 -0700 Subject: [PATCH] Demonstrate support for non-UTF8 macro contents --- bindgen-integration/build.rs | 9 ++++++++- bindgen-integration/cpp/Test.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index c40b672da7..0a28e8f56b 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -105,6 +105,13 @@ impl ParseCallbacks for MacroCallback { assert_eq!(value, &[b"b", b",", b"a"]); *self.seen_funcs.lock().unwrap() += 1; } + "TESTMACRO_STRING_FUNC_NON_UTF8(x)" => { + assert_eq!( + value, + &[b"(" as &[u8], b"x", b"\"\xff\xff\"", b")"] + ); + *self.seen_funcs.lock().unwrap() += 1; + } _ => { // The system might provide lots of functional macros. // Ensure we did not miss handling one that we meant to handle. @@ -123,7 +130,7 @@ impl Drop for MacroCallback { ); assert_eq!( *self.seen_funcs.lock().unwrap(), - 4, + 5, "func_macro handle was not called once for all relevant macros" ); } diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index e91c570b6e..f8b2263f6d 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -18,6 +18,7 @@ a //#define TESTMACRO_INVALID("string") // A conforming preprocessor rejects this #define TESTMACRO_STRING_EXPR ("string") +#define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ÿÿ") /* invalid UTF-8 on purpose */ #include