From c15874917393caa375eddcbc936327f2c32742cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20J=2E=20Saraiva?= Date: Tue, 18 Jun 2024 10:27:01 +0100 Subject: [PATCH] Convert config fields header, trailer, after_includes to text fields. --- src/bindgen/builder.rs | 6 +- src/bindgen/config.rs | 84 +++++++++++++++++-- src/bindgen/language_backend/clike.rs | 8 +- src/bindgen/language_backend/cython.rs | 8 +- src/bindgen/language_backend/mod.rs | 6 +- tests/expectations/box.c | 14 ---- tests/expectations/box.compat.c | 14 ---- tests/expectations/box.cpp | 10 --- tests/expectations/box.pyx | 14 ---- tests/expectations/box_both.c | 14 ---- tests/expectations/box_both.compat.c | 14 ---- tests/expectations/box_tag.c | 14 ---- tests/expectations/box_tag.compat.c | 14 ---- tests/expectations/box_tag.pyx | 14 ---- tests/expectations/enum.c | 22 ----- tests/expectations/enum.compat.c | 22 ----- tests/expectations/enum.cpp | 18 ---- tests/expectations/enum.pyx | 18 ---- tests/expectations/enum_both.c | 22 ----- tests/expectations/enum_both.compat.c | 22 ----- tests/expectations/enum_tag.c | 22 ----- tests/expectations/enum_tag.compat.c | 22 ----- tests/expectations/enum_tag.pyx | 18 ---- .../expectations/exclude_generic_monomorph.c | 13 --- .../exclude_generic_monomorph.compat.c | 13 --- .../exclude_generic_monomorph.cpp | 13 --- .../exclude_generic_monomorph.pyx | 12 +-- .../exclude_generic_monomorph_both.c | 13 --- .../exclude_generic_monomorph_both.compat.c | 13 --- .../exclude_generic_monomorph_tag.c | 13 --- .../exclude_generic_monomorph_tag.compat.c | 13 --- .../exclude_generic_monomorph_tag.pyx | 12 +-- tests/expectations/forward_declaration.c | 12 --- .../expectations/forward_declaration.compat.c | 12 --- tests/expectations/forward_declaration.cpp | 12 --- tests/expectations/forward_declaration.pyx | 14 ++-- tests/expectations/forward_declaration_both.c | 12 --- .../forward_declaration_both.compat.c | 12 --- tests/expectations/forward_declaration_tag.c | 12 --- .../forward_declaration_tag.compat.c | 12 --- .../expectations/forward_declaration_tag.pyx | 14 ++-- tests/expectations/manuallydrop.c | 14 ---- tests/expectations/manuallydrop.compat.c | 14 ---- tests/expectations/manuallydrop.cpp | 10 --- tests/expectations/manuallydrop.pyx | 14 ---- tests/expectations/manuallydrop_both.c | 14 ---- tests/expectations/manuallydrop_both.compat.c | 14 ---- tests/expectations/manuallydrop_tag.c | 14 ---- tests/expectations/manuallydrop_tag.compat.c | 14 ---- tests/expectations/manuallydrop_tag.pyx | 14 ---- tests/expectations/maybeuninit.c | 14 ---- tests/expectations/maybeuninit.compat.c | 14 ---- tests/expectations/maybeuninit.cpp | 10 --- tests/expectations/maybeuninit.pyx | 14 ---- tests/expectations/maybeuninit_both.c | 14 ---- tests/expectations/maybeuninit_both.compat.c | 14 ---- tests/expectations/maybeuninit_tag.c | 14 ---- tests/expectations/maybeuninit_tag.compat.c | 14 ---- tests/expectations/maybeuninit_tag.pyx | 14 ---- tests/expectations/nonzero.c | 13 --- tests/expectations/nonzero.compat.c | 13 --- tests/expectations/nonzero.cpp | 10 --- tests/expectations/nonzero.pyx | 13 --- tests/expectations/nonzero_both.c | 13 --- tests/expectations/nonzero_both.compat.c | 13 --- tests/expectations/nonzero_tag.c | 13 --- tests/expectations/nonzero_tag.compat.c | 13 --- tests/expectations/nonzero_tag.pyx | 13 --- tests/expectations/opaque.c | 17 ---- tests/expectations/opaque.compat.c | 17 ---- tests/expectations/opaque.cpp | 10 --- tests/expectations/opaque.pyx | 17 ---- tests/expectations/opaque_both.c | 17 ---- tests/expectations/opaque_both.compat.c | 17 ---- tests/expectations/opaque_tag.c | 17 ---- tests/expectations/opaque_tag.compat.c | 17 ---- tests/expectations/opaque_tag.pyx | 17 ---- tests/expectations/pin.c | 16 ---- tests/expectations/pin.compat.c | 16 ---- tests/expectations/pin.cpp | 10 --- tests/expectations/pin.pyx | 16 ---- tests/expectations/pin_both.c | 16 ---- tests/expectations/pin_both.compat.c | 16 ---- tests/expectations/pin_tag.c | 16 ---- tests/expectations/pin_tag.compat.c | 16 ---- tests/expectations/pin_tag.pyx | 16 ---- tests/rust/box.toml | 13 +-- tests/rust/enum.toml | 30 ++----- tests/rust/exclude_generic_monomorph.toml | 19 ++--- tests/rust/forward_declaration.toml | 28 +++---- tests/rust/manuallydrop.toml | 13 +-- tests/rust/maybeuninit.toml | 13 +-- tests/rust/nonzero.toml | 14 +--- tests/rust/opaque.toml | 14 +--- tests/rust/pin.toml | 13 +-- 95 files changed, 147 insertions(+), 1299 deletions(-) diff --git a/src/bindgen/builder.rs b/src/bindgen/builder.rs index d47919b98..1064935bb 100644 --- a/src/bindgen/builder.rs +++ b/src/bindgen/builder.rs @@ -37,7 +37,7 @@ impl Builder { #[allow(unused)] pub fn with_header>(mut self, header: S) -> Builder { - self.config.header = Some(String::from(header.as_ref())); + self.config.header = String::from(header.as_ref()).into(); self } @@ -63,13 +63,13 @@ impl Builder { #[allow(unused)] pub fn with_after_include>(mut self, line: S) -> Builder { - self.config.after_includes = Some(String::from(line.as_ref())); + self.config.after_includes = String::from(line.as_ref()).into(); self } #[allow(unused)] pub fn with_trailer>(mut self, trailer: S) -> Builder { - self.config.trailer = Some(String::from(trailer.as_ref())); + self.config.trailer = String::from(trailer.as_ref()).into(); self } diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs index 31316503d..55eac9c3e 100644 --- a/src/bindgen/config.rs +++ b/src/bindgen/config.rs @@ -894,6 +894,78 @@ pub struct CythonConfig { pub cimports: BTreeMap>, } +/// A line field can be a single line `field = "line"` or a struct `field = { language = "C", line = "struct" }`. +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum Line { + AnyBackend(String), + WithBackend { language: Language, line: String }, +} +impl Line { + pub fn line_for(&self, target: Language) -> Option<&str> { + match *self { + Line::AnyBackend(ref line) => Some(line.as_str()), + Line::WithBackend { language, ref line } if language == target => Some(line.as_str()), + _ => None, + } + } +} +impl From for Line { + fn from(value: String) -> Self { + Self::AnyBackend(value) + } +} + +/// A text field can be a line field or a sequence of lines or structs: +/// ```toml +/// field = [ +/// "sequence of lines", +/// { language = "C", line = "or structs" }, +/// ] +/// ``` +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum Text { + Line(Line), + Lines(Vec), +} +impl Text { + pub fn is_empty(&self) -> bool { + match *self { + Text::Line(_) => false, + Text::Lines(ref lines) => lines.is_empty(), + } + } + pub fn text_for(&self, target: Language) -> Vec<&str> { + let mut text = Vec::new(); + match self { + Text::Line(line) => { + if let Some(s) = line.line_for(target) { + text.push(s); + } + } + Text::Lines(lines) => { + for line in lines.iter() { + if let Some(s) = line.line_for(target) { + text.push(s); + } + } + } + } + text + } +} +impl From for Text { + fn from(value: String) -> Self { + Self::Line(value.into()) + } +} +impl Default for Text { + fn default() -> Self { + Self::Lines(Vec::new()) + } +} + /// A collection of settings to customize the generated bindings. #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "snake_case")] @@ -901,15 +973,15 @@ pub struct CythonConfig { #[serde(default)] pub struct Config { /// Optional text to output at the beginning of the file - pub header: Option, + pub header: Text, /// A list of additional includes to put at the beginning of the generated header pub includes: Vec, /// A list of additional system includes to put at the beginning of the generated header pub sys_includes: Vec, /// Optional verbatim code added after the include blocks - pub after_includes: Option, + pub after_includes: Text, /// Optional text to output at the end of the file - pub trailer: Option, + pub trailer: Text, /// Optional name to use for an include guard pub include_guard: Option, /// Add a `#pragma once` guard @@ -1032,11 +1104,11 @@ pub struct Config { impl Default for Config { fn default() -> Config { Config { - header: None, + header: Text::default(), includes: Vec::new(), sys_includes: Vec::new(), - after_includes: None, - trailer: None, + after_includes: Text::default(), + trailer: Text::default(), include_guard: None, pragma_once: false, autogen_warning: None, diff --git a/src/bindgen/language_backend/clike.rs b/src/bindgen/language_backend/clike.rs index 5da079c3d..2efcb19fb 100644 --- a/src/bindgen/language_backend/clike.rs +++ b/src/bindgen/language_backend/clike.rs @@ -344,9 +344,9 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { write!(out, "/* Package version: {} */", package_version); out.new_line(); } - if let Some(ref f) = self.config.header { + for line in self.config.header.text_for(self.config.language) { out.new_line_if_not_start(); - write!(out, "{}", f); + write!(out, "{}", line); out.new_line(); } if let Some(f) = self.config.include_guard() { @@ -379,7 +379,7 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { if self.config.no_includes && self.config.sys_includes().is_empty() && self.config.includes().is_empty() - && self.config.after_includes.is_none() + && self.config.after_includes.is_empty() { return; } @@ -439,7 +439,7 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { out.new_line(); } - if let Some(ref line) = self.config.after_includes { + for line in self.config.after_includes.text_for(self.config.language) { write!(out, "{}", line); out.new_line(); } diff --git a/src/bindgen/language_backend/cython.rs b/src/bindgen/language_backend/cython.rs index 5c85b2d02..cda768c3a 100644 --- a/src/bindgen/language_backend/cython.rs +++ b/src/bindgen/language_backend/cython.rs @@ -47,9 +47,9 @@ impl LanguageBackend for CythonLanguageBackend<'_> { write!(out, "''' Package version: {} '''", package_version); out.new_line(); } - if let Some(ref f) = self.config.header { + for line in self.config.header.text_for(self.config.language) { out.new_line_if_not_start(); - write!(out, "{}", f); + write!(out, "{}", line); out.new_line(); } @@ -72,7 +72,7 @@ impl LanguageBackend for CythonLanguageBackend<'_> { && self.config.sys_includes().is_empty() && self.config.includes().is_empty() && (self.config.cython.cimports.is_empty()) - && self.config.after_includes.is_none() + && self.config.after_includes.is_empty() { return; } @@ -98,7 +98,7 @@ impl LanguageBackend for CythonLanguageBackend<'_> { out.new_line(); } - if let Some(ref line) = &self.config.after_includes { + for line in self.config.after_includes.text_for(self.config.language) { write!(out, "{}", line); out.new_line(); } diff --git a/src/bindgen/language_backend/mod.rs b/src/bindgen/language_backend/mod.rs index adb7d8507..d4ae1856d 100644 --- a/src/bindgen/language_backend/mod.rs +++ b/src/bindgen/language_backend/mod.rs @@ -199,10 +199,10 @@ pub trait LanguageBackend: Sized { } fn write_trailer(&mut self, out: &mut SourceWriter, b: &Bindings) { - if let Some(ref f) = b.config.trailer { + for line in b.config.trailer.text_for(b.config.language) { out.new_line_if_not_start(); - write!(out, "{}", f); - if !f.ends_with('\n') { + write!(out, "{}", line); + if !line.ends_with('\n') { out.new_line(); } } diff --git a/tests/expectations/box.c b/tests/expectations/box.c index 384632b5a..230492a42 100644 --- a/tests/expectations/box.c +++ b/tests/expectations/box.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/box.compat.c b/tests/expectations/box.compat.c index 686d2a38a..f56320efc 100644 --- a/tests/expectations/box.compat.c +++ b/tests/expectations/box.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/box.cpp b/tests/expectations/box.cpp index 76a5ef773..16944d348 100644 --- a/tests/expectations/box.cpp +++ b/tests/expectations/box.cpp @@ -1,15 +1,5 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus template using Box = T*; -#endif - -#if 0 -' ''' -#endif #include diff --git a/tests/expectations/box.pyx b/tests/expectations/box.pyx index 366dafee8..a6b4ef9c3 100644 --- a/tests/expectations/box.pyx +++ b/tests/expectations/box.pyx @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/box_both.c b/tests/expectations/box_both.c index 3a9f76aea..c08168640 100644 --- a/tests/expectations/box_both.c +++ b/tests/expectations/box_both.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/box_both.compat.c b/tests/expectations/box_both.compat.c index dc8c3cba2..1a18e6dcc 100644 --- a/tests/expectations/box_both.compat.c +++ b/tests/expectations/box_both.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/box_tag.c b/tests/expectations/box_tag.c index da0eb4a00..bf4c2f6f9 100644 --- a/tests/expectations/box_tag.c +++ b/tests/expectations/box_tag.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/box_tag.compat.c b/tests/expectations/box_tag.compat.c index 2290dc3b1..e3b67a554 100644 --- a/tests/expectations/box_tag.compat.c +++ b/tests/expectations/box_tag.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/box_tag.pyx b/tests/expectations/box_tag.pyx index e50f19e3c..25cb0e39e 100644 --- a/tests/expectations/box_tag.pyx +++ b/tests/expectations/box_tag.pyx @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/enum.c b/tests/expectations/enum.c index 0562a56a6..4884fdac3 100644 --- a/tests/expectations/enum.c +++ b/tests/expectations/enum.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include @@ -245,17 +231,9 @@ void root(Opaque *opaque, Q q, R r); -#if 0 -''' ' -#endif - #include #include "testing-helpers.h" static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); - -#if 0 -' ''' -#endif diff --git a/tests/expectations/enum.compat.c b/tests/expectations/enum.compat.c index 86cedb9f2..fd5e2e961 100644 --- a/tests/expectations/enum.compat.c +++ b/tests/expectations/enum.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include @@ -319,17 +305,9 @@ void root(Opaque *opaque, } // extern "C" #endif // __cplusplus -#if 0 -''' ' -#endif - #include #include "testing-helpers.h" static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); - -#if 0 -' ''' -#endif diff --git a/tests/expectations/enum.cpp b/tests/expectations/enum.cpp index 66d9209bf..0e3972c54 100644 --- a/tests/expectations/enum.cpp +++ b/tests/expectations/enum.cpp @@ -1,15 +1,5 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus template using Box = T*; -#endif - -#if 0 -' ''' -#endif #include @@ -255,17 +245,9 @@ void root(Opaque *opaque, } // extern "C" -#if 0 -''' ' -#endif - #include #include "testing-helpers.h" static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); - -#if 0 -' ''' -#endif diff --git a/tests/expectations/enum.pyx b/tests/expectations/enum.pyx index 03570f2c3..388688030 100644 --- a/tests/expectations/enum.pyx +++ b/tests/expectations/enum.pyx @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: @@ -199,9 +185,7 @@ cdef extern from *: Q q, R r); -#if 0 ''' ' -#endif #include #include "testing-helpers.h" @@ -210,6 +194,4 @@ static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0") static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); -#if 0 ' ''' -#endif diff --git a/tests/expectations/enum_both.c b/tests/expectations/enum_both.c index a0f88c13e..5a28949ab 100644 --- a/tests/expectations/enum_both.c +++ b/tests/expectations/enum_both.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include @@ -245,17 +231,9 @@ void root(struct Opaque *opaque, struct Q q, struct R r); -#if 0 -''' ' -#endif - #include #include "testing-helpers.h" static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); - -#if 0 -' ''' -#endif diff --git a/tests/expectations/enum_both.compat.c b/tests/expectations/enum_both.compat.c index 35488252b..9ea0e2369 100644 --- a/tests/expectations/enum_both.compat.c +++ b/tests/expectations/enum_both.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include @@ -319,17 +305,9 @@ void root(struct Opaque *opaque, } // extern "C" #endif // __cplusplus -#if 0 -''' ' -#endif - #include #include "testing-helpers.h" static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); - -#if 0 -' ''' -#endif diff --git a/tests/expectations/enum_tag.c b/tests/expectations/enum_tag.c index a7f104688..8851f799b 100644 --- a/tests/expectations/enum_tag.c +++ b/tests/expectations/enum_tag.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include @@ -245,17 +231,9 @@ void root(struct Opaque *opaque, struct Q q, struct R r); -#if 0 -''' ' -#endif - #include #include "testing-helpers.h" static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); - -#if 0 -' ''' -#endif diff --git a/tests/expectations/enum_tag.compat.c b/tests/expectations/enum_tag.compat.c index 9662a6529..1942cf1b0 100644 --- a/tests/expectations/enum_tag.compat.c +++ b/tests/expectations/enum_tag.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include @@ -319,17 +305,9 @@ void root(struct Opaque *opaque, } // extern "C" #endif // __cplusplus -#if 0 -''' ' -#endif - #include #include "testing-helpers.h" static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); - -#if 0 -' ''' -#endif diff --git a/tests/expectations/enum_tag.pyx b/tests/expectations/enum_tag.pyx index a0c9ef082..b5c8b8ec3 100644 --- a/tests/expectations/enum_tag.pyx +++ b/tests/expectations/enum_tag.pyx @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: @@ -199,9 +185,7 @@ cdef extern from *: Q q, R r); -#if 0 ''' ' -#endif #include #include "testing-helpers.h" @@ -210,6 +194,4 @@ static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0") static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); -#if 0 ' ''' -#endif diff --git a/tests/expectations/exclude_generic_monomorph.c b/tests/expectations/exclude_generic_monomorph.c index a593dd7ab..e71783677 100644 --- a/tests/expectations/exclude_generic_monomorph.c +++ b/tests/expectations/exclude_generic_monomorph.c @@ -1,20 +1,7 @@ #include -#if 0 -''' ' -#endif - typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif - -#if 0 -from libc.stdint cimport uint64_t -ctypedef uint64_t Option_Foo -#endif - #include #include diff --git a/tests/expectations/exclude_generic_monomorph.compat.c b/tests/expectations/exclude_generic_monomorph.compat.c index a02632200..3bc818e4c 100644 --- a/tests/expectations/exclude_generic_monomorph.compat.c +++ b/tests/expectations/exclude_generic_monomorph.compat.c @@ -1,20 +1,7 @@ #include -#if 0 -''' ' -#endif - typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif - -#if 0 -from libc.stdint cimport uint64_t -ctypedef uint64_t Option_Foo -#endif - #include #include diff --git a/tests/expectations/exclude_generic_monomorph.cpp b/tests/expectations/exclude_generic_monomorph.cpp index 09b5455dd..e5157486f 100644 --- a/tests/expectations/exclude_generic_monomorph.cpp +++ b/tests/expectations/exclude_generic_monomorph.cpp @@ -1,20 +1,7 @@ #include -#if 0 -''' ' -#endif - typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif - -#if 0 -from libc.stdint cimport uint64_t -ctypedef uint64_t Option_Foo -#endif - #include #include diff --git a/tests/expectations/exclude_generic_monomorph.pyx b/tests/expectations/exclude_generic_monomorph.pyx index 48cd1e242..f1a72d4c5 100644 --- a/tests/expectations/exclude_generic_monomorph.pyx +++ b/tests/expectations/exclude_generic_monomorph.pyx @@ -1,19 +1,13 @@ -#include - -#if 0 ''' ' -#endif + +#include typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif -#if 0 +' ''' from libc.stdint cimport uint64_t ctypedef uint64_t Option_Foo -#endif from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t diff --git a/tests/expectations/exclude_generic_monomorph_both.c b/tests/expectations/exclude_generic_monomorph_both.c index 09b5455dd..e5157486f 100644 --- a/tests/expectations/exclude_generic_monomorph_both.c +++ b/tests/expectations/exclude_generic_monomorph_both.c @@ -1,20 +1,7 @@ #include -#if 0 -''' ' -#endif - typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif - -#if 0 -from libc.stdint cimport uint64_t -ctypedef uint64_t Option_Foo -#endif - #include #include diff --git a/tests/expectations/exclude_generic_monomorph_both.compat.c b/tests/expectations/exclude_generic_monomorph_both.compat.c index 2447ac44c..1a97f376d 100644 --- a/tests/expectations/exclude_generic_monomorph_both.compat.c +++ b/tests/expectations/exclude_generic_monomorph_both.compat.c @@ -1,20 +1,7 @@ #include -#if 0 -''' ' -#endif - typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif - -#if 0 -from libc.stdint cimport uint64_t -ctypedef uint64_t Option_Foo -#endif - #include #include diff --git a/tests/expectations/exclude_generic_monomorph_tag.c b/tests/expectations/exclude_generic_monomorph_tag.c index 116a170fc..32686ad9d 100644 --- a/tests/expectations/exclude_generic_monomorph_tag.c +++ b/tests/expectations/exclude_generic_monomorph_tag.c @@ -1,20 +1,7 @@ #include -#if 0 -''' ' -#endif - typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif - -#if 0 -from libc.stdint cimport uint64_t -ctypedef uint64_t Option_Foo -#endif - #include #include diff --git a/tests/expectations/exclude_generic_monomorph_tag.compat.c b/tests/expectations/exclude_generic_monomorph_tag.compat.c index 73d9650f5..397993be6 100644 --- a/tests/expectations/exclude_generic_monomorph_tag.compat.c +++ b/tests/expectations/exclude_generic_monomorph_tag.compat.c @@ -1,20 +1,7 @@ #include -#if 0 -''' ' -#endif - typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif - -#if 0 -from libc.stdint cimport uint64_t -ctypedef uint64_t Option_Foo -#endif - #include #include diff --git a/tests/expectations/exclude_generic_monomorph_tag.pyx b/tests/expectations/exclude_generic_monomorph_tag.pyx index 934536f40..61ef37e19 100644 --- a/tests/expectations/exclude_generic_monomorph_tag.pyx +++ b/tests/expectations/exclude_generic_monomorph_tag.pyx @@ -1,19 +1,13 @@ -#include - -#if 0 ''' ' -#endif + +#include typedef uint64_t Option_Foo; -#if 0 -' ''' -#endif -#if 0 +' ''' from libc.stdint cimport uint64_t ctypedef uint64_t Option_Foo -#endif from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t diff --git a/tests/expectations/forward_declaration.c b/tests/expectations/forward_declaration.c index f77076dd9..3bbf38dea 100644 --- a/tests/expectations/forward_declaration.c +++ b/tests/expectations/forward_declaration.c @@ -1,12 +1,6 @@ -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif #include @@ -39,12 +33,6 @@ typedef struct { void root(TypeInfo x); -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 -' ''' -#endif diff --git a/tests/expectations/forward_declaration.compat.c b/tests/expectations/forward_declaration.compat.c index 375fc8dce..27afb7e65 100644 --- a/tests/expectations/forward_declaration.compat.c +++ b/tests/expectations/forward_declaration.compat.c @@ -1,12 +1,6 @@ -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif #include @@ -47,12 +41,6 @@ void root(TypeInfo x); } // extern "C" #endif // __cplusplus -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 -' ''' -#endif diff --git a/tests/expectations/forward_declaration.cpp b/tests/expectations/forward_declaration.cpp index 766b79946..a7a22a919 100644 --- a/tests/expectations/forward_declaration.cpp +++ b/tests/expectations/forward_declaration.cpp @@ -1,12 +1,6 @@ -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif #include @@ -46,12 +40,6 @@ void root(TypeInfo x); } // extern "C" -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 -' ''' -#endif diff --git a/tests/expectations/forward_declaration.pyx b/tests/expectations/forward_declaration.pyx index 451852e66..6ae63c4bf 100644 --- a/tests/expectations/forward_declaration.pyx +++ b/tests/expectations/forward_declaration.pyx @@ -1,14 +1,12 @@ -#if 0 ''' ' -#endif + #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif +' ''' + from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: @@ -34,12 +32,10 @@ cdef extern from *: void root(TypeInfo x); -#if 0 ''' ' -#endif + #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 + ' ''' -#endif diff --git a/tests/expectations/forward_declaration_both.c b/tests/expectations/forward_declaration_both.c index 9e88bab21..94c3f2793 100644 --- a/tests/expectations/forward_declaration_both.c +++ b/tests/expectations/forward_declaration_both.c @@ -1,12 +1,6 @@ -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif #include @@ -39,12 +33,6 @@ typedef struct TypeInfo { void root(struct TypeInfo x); -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 -' ''' -#endif diff --git a/tests/expectations/forward_declaration_both.compat.c b/tests/expectations/forward_declaration_both.compat.c index 031e40c0a..f510662ab 100644 --- a/tests/expectations/forward_declaration_both.compat.c +++ b/tests/expectations/forward_declaration_both.compat.c @@ -1,12 +1,6 @@ -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif #include @@ -47,12 +41,6 @@ void root(struct TypeInfo x); } // extern "C" #endif // __cplusplus -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 -' ''' -#endif diff --git a/tests/expectations/forward_declaration_tag.c b/tests/expectations/forward_declaration_tag.c index acd820428..813fcbe64 100644 --- a/tests/expectations/forward_declaration_tag.c +++ b/tests/expectations/forward_declaration_tag.c @@ -1,12 +1,6 @@ -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif #include @@ -39,12 +33,6 @@ struct TypeInfo { void root(struct TypeInfo x); -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 -' ''' -#endif diff --git a/tests/expectations/forward_declaration_tag.compat.c b/tests/expectations/forward_declaration_tag.compat.c index 1a61c5e2d..48fd3c9ae 100644 --- a/tests/expectations/forward_declaration_tag.compat.c +++ b/tests/expectations/forward_declaration_tag.compat.c @@ -1,12 +1,6 @@ -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif #include @@ -47,12 +41,6 @@ void root(struct TypeInfo x); } // extern "C" #endif // __cplusplus -#if 0 -''' ' -#endif #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 -' ''' -#endif diff --git a/tests/expectations/forward_declaration_tag.pyx b/tests/expectations/forward_declaration_tag.pyx index af110c230..0dff71db6 100644 --- a/tests/expectations/forward_declaration_tag.pyx +++ b/tests/expectations/forward_declaration_tag.pyx @@ -1,14 +1,12 @@ -#if 0 ''' ' -#endif + #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif +' ''' + from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: @@ -34,12 +32,10 @@ cdef extern from *: void root(TypeInfo x); -#if 0 ''' ' -#endif + #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 + ' ''' -#endif diff --git a/tests/expectations/manuallydrop.c b/tests/expectations/manuallydrop.c index 869dea727..90bce0068 100644 --- a/tests/expectations/manuallydrop.c +++ b/tests/expectations/manuallydrop.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/manuallydrop.compat.c b/tests/expectations/manuallydrop.compat.c index b8bdf43ed..76e134ff9 100644 --- a/tests/expectations/manuallydrop.compat.c +++ b/tests/expectations/manuallydrop.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/manuallydrop.cpp b/tests/expectations/manuallydrop.cpp index df517dcba..6759fe6ce 100644 --- a/tests/expectations/manuallydrop.cpp +++ b/tests/expectations/manuallydrop.cpp @@ -1,15 +1,5 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus template using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif #include diff --git a/tests/expectations/manuallydrop.pyx b/tests/expectations/manuallydrop.pyx index 370d0df8a..2635a4923 100644 --- a/tests/expectations/manuallydrop.pyx +++ b/tests/expectations/manuallydrop.pyx @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/manuallydrop_both.c b/tests/expectations/manuallydrop_both.c index 255f4f520..9b1c67bd2 100644 --- a/tests/expectations/manuallydrop_both.c +++ b/tests/expectations/manuallydrop_both.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/manuallydrop_both.compat.c b/tests/expectations/manuallydrop_both.compat.c index 1975e2684..461c08e0f 100644 --- a/tests/expectations/manuallydrop_both.compat.c +++ b/tests/expectations/manuallydrop_both.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/manuallydrop_tag.c b/tests/expectations/manuallydrop_tag.c index 5d44aa216..7f56facee 100644 --- a/tests/expectations/manuallydrop_tag.c +++ b/tests/expectations/manuallydrop_tag.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/manuallydrop_tag.compat.c b/tests/expectations/manuallydrop_tag.compat.c index 08d952c8b..571a36168 100644 --- a/tests/expectations/manuallydrop_tag.compat.c +++ b/tests/expectations/manuallydrop_tag.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/manuallydrop_tag.pyx b/tests/expectations/manuallydrop_tag.pyx index 388c3ef1f..9cc1f55f4 100644 --- a/tests/expectations/manuallydrop_tag.pyx +++ b/tests/expectations/manuallydrop_tag.pyx @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using ManuallyDrop = T; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/maybeuninit.c b/tests/expectations/maybeuninit.c index 1eddcdc36..3434287db 100644 --- a/tests/expectations/maybeuninit.c +++ b/tests/expectations/maybeuninit.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/maybeuninit.compat.c b/tests/expectations/maybeuninit.compat.c index a97929997..b38f0dd83 100644 --- a/tests/expectations/maybeuninit.compat.c +++ b/tests/expectations/maybeuninit.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/maybeuninit.cpp b/tests/expectations/maybeuninit.cpp index 638cdfd16..217aea482 100644 --- a/tests/expectations/maybeuninit.cpp +++ b/tests/expectations/maybeuninit.cpp @@ -1,15 +1,5 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus template using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif #include diff --git a/tests/expectations/maybeuninit.pyx b/tests/expectations/maybeuninit.pyx index 75d82b38d..5705d26c7 100644 --- a/tests/expectations/maybeuninit.pyx +++ b/tests/expectations/maybeuninit.pyx @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/maybeuninit_both.c b/tests/expectations/maybeuninit_both.c index 850e3eb1c..b0045d715 100644 --- a/tests/expectations/maybeuninit_both.c +++ b/tests/expectations/maybeuninit_both.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/maybeuninit_both.compat.c b/tests/expectations/maybeuninit_both.compat.c index 046822d6e..fe7bb5411 100644 --- a/tests/expectations/maybeuninit_both.compat.c +++ b/tests/expectations/maybeuninit_both.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/maybeuninit_tag.c b/tests/expectations/maybeuninit_tag.c index a2f5a0845..15cd05083 100644 --- a/tests/expectations/maybeuninit_tag.c +++ b/tests/expectations/maybeuninit_tag.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/maybeuninit_tag.compat.c b/tests/expectations/maybeuninit_tag.compat.c index 8ec05f152..1fda1e5d3 100644 --- a/tests/expectations/maybeuninit_tag.compat.c +++ b/tests/expectations/maybeuninit_tag.compat.c @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/maybeuninit_tag.pyx b/tests/expectations/maybeuninit_tag.pyx index 82497d85c..aa4faa8b8 100644 --- a/tests/expectations/maybeuninit_tag.pyx +++ b/tests/expectations/maybeuninit_tag.pyx @@ -1,17 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using MaybeUninit = T; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/nonzero.c b/tests/expectations/nonzero.c index ec7d8e0c4..884d9ddc2 100644 --- a/tests/expectations/nonzero.c +++ b/tests/expectations/nonzero.c @@ -1,16 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/nonzero.compat.c b/tests/expectations/nonzero.compat.c index f9e1703bb..1315a22aa 100644 --- a/tests/expectations/nonzero.compat.c +++ b/tests/expectations/nonzero.compat.c @@ -1,16 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/nonzero.cpp b/tests/expectations/nonzero.cpp index 25a930c79..c58161c2d 100644 --- a/tests/expectations/nonzero.cpp +++ b/tests/expectations/nonzero.cpp @@ -1,14 +1,4 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif #include diff --git a/tests/expectations/nonzero.pyx b/tests/expectations/nonzero.pyx index 737c44129..c9b0a0b18 100644 --- a/tests/expectations/nonzero.pyx +++ b/tests/expectations/nonzero.pyx @@ -1,16 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/nonzero_both.c b/tests/expectations/nonzero_both.c index 6f47e7511..9ce5dfba8 100644 --- a/tests/expectations/nonzero_both.c +++ b/tests/expectations/nonzero_both.c @@ -1,16 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/nonzero_both.compat.c b/tests/expectations/nonzero_both.compat.c index ee8433e23..e017c750f 100644 --- a/tests/expectations/nonzero_both.compat.c +++ b/tests/expectations/nonzero_both.compat.c @@ -1,16 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/nonzero_tag.c b/tests/expectations/nonzero_tag.c index cf67b3d6f..980201fc3 100644 --- a/tests/expectations/nonzero_tag.c +++ b/tests/expectations/nonzero_tag.c @@ -1,16 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/nonzero_tag.compat.c b/tests/expectations/nonzero_tag.compat.c index 896ddbf2c..af9971eda 100644 --- a/tests/expectations/nonzero_tag.compat.c +++ b/tests/expectations/nonzero_tag.compat.c @@ -1,16 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/nonzero_tag.pyx b/tests/expectations/nonzero_tag.pyx index 0f3caf347..c481cf168 100644 --- a/tests/expectations/nonzero_tag.pyx +++ b/tests/expectations/nonzero_tag.pyx @@ -1,16 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/opaque.c b/tests/expectations/opaque.c index 3a920e540..ea3ab6272 100644 --- a/tests/expectations/opaque.c +++ b/tests/expectations/opaque.c @@ -1,20 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -// These could be added as opaque types I guess. -template -struct BuildHasherDefault; - -struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/opaque.compat.c b/tests/expectations/opaque.compat.c index 61a93ed27..2ea3f274c 100644 --- a/tests/expectations/opaque.compat.c +++ b/tests/expectations/opaque.compat.c @@ -1,20 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -// These could be added as opaque types I guess. -template -struct BuildHasherDefault; - -struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/opaque.cpp b/tests/expectations/opaque.cpp index 0e22c0eb3..131e81d2e 100644 --- a/tests/expectations/opaque.cpp +++ b/tests/expectations/opaque.cpp @@ -1,18 +1,8 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus // These could be added as opaque types I guess. template struct BuildHasherDefault; struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif #include diff --git a/tests/expectations/opaque.pyx b/tests/expectations/opaque.pyx index f60cfdbcd..8c5059bae 100644 --- a/tests/expectations/opaque.pyx +++ b/tests/expectations/opaque.pyx @@ -1,20 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -// These could be added as opaque types I guess. -template -struct BuildHasherDefault; - -struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/opaque_both.c b/tests/expectations/opaque_both.c index 6b36d9ec1..c08936ccf 100644 --- a/tests/expectations/opaque_both.c +++ b/tests/expectations/opaque_both.c @@ -1,20 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -// These could be added as opaque types I guess. -template -struct BuildHasherDefault; - -struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/opaque_both.compat.c b/tests/expectations/opaque_both.compat.c index fa057a16a..de0c5f2ff 100644 --- a/tests/expectations/opaque_both.compat.c +++ b/tests/expectations/opaque_both.compat.c @@ -1,20 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -// These could be added as opaque types I guess. -template -struct BuildHasherDefault; - -struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/opaque_tag.c b/tests/expectations/opaque_tag.c index 67d7740d9..953c9bdfb 100644 --- a/tests/expectations/opaque_tag.c +++ b/tests/expectations/opaque_tag.c @@ -1,20 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -// These could be added as opaque types I guess. -template -struct BuildHasherDefault; - -struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/opaque_tag.compat.c b/tests/expectations/opaque_tag.compat.c index 71ab06c37..d71dd6069 100644 --- a/tests/expectations/opaque_tag.compat.c +++ b/tests/expectations/opaque_tag.compat.c @@ -1,20 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -// These could be added as opaque types I guess. -template -struct BuildHasherDefault; - -struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/opaque_tag.pyx b/tests/expectations/opaque_tag.pyx index 694073fdb..8dd33f849 100644 --- a/tests/expectations/opaque_tag.pyx +++ b/tests/expectations/opaque_tag.pyx @@ -1,20 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -// These could be added as opaque types I guess. -template -struct BuildHasherDefault; - -struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/pin.c b/tests/expectations/pin.c index df4cd3200..5af2908dd 100644 --- a/tests/expectations/pin.c +++ b/tests/expectations/pin.c @@ -1,19 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Pin = T; -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/pin.compat.c b/tests/expectations/pin.compat.c index 117641d30..a27bc2d09 100644 --- a/tests/expectations/pin.compat.c +++ b/tests/expectations/pin.compat.c @@ -1,19 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Pin = T; -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/pin.cpp b/tests/expectations/pin.cpp index f8a16c7be..da935b548 100644 --- a/tests/expectations/pin.cpp +++ b/tests/expectations/pin.cpp @@ -1,17 +1,7 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus template using Pin = T; template using Box = T*; -#endif - -#if 0 -' ''' -#endif #include diff --git a/tests/expectations/pin.pyx b/tests/expectations/pin.pyx index f5336e606..fde283ea5 100644 --- a/tests/expectations/pin.pyx +++ b/tests/expectations/pin.pyx @@ -1,19 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Pin = T; -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/expectations/pin_both.c b/tests/expectations/pin_both.c index c43b4c345..da5e1aad4 100644 --- a/tests/expectations/pin_both.c +++ b/tests/expectations/pin_both.c @@ -1,19 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Pin = T; -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/pin_both.compat.c b/tests/expectations/pin_both.compat.c index 9424fbf72..1067fe2fe 100644 --- a/tests/expectations/pin_both.compat.c +++ b/tests/expectations/pin_both.compat.c @@ -1,19 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Pin = T; -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/pin_tag.c b/tests/expectations/pin_tag.c index 49fb9d849..3530410de 100644 --- a/tests/expectations/pin_tag.c +++ b/tests/expectations/pin_tag.c @@ -1,19 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Pin = T; -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/pin_tag.compat.c b/tests/expectations/pin_tag.compat.c index 2bb04fd83..f7d09d68a 100644 --- a/tests/expectations/pin_tag.compat.c +++ b/tests/expectations/pin_tag.compat.c @@ -1,19 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Pin = T; -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - #include #include #include diff --git a/tests/expectations/pin_tag.pyx b/tests/expectations/pin_tag.pyx index 04a60d73f..d84ac2f0f 100644 --- a/tests/expectations/pin_tag.pyx +++ b/tests/expectations/pin_tag.pyx @@ -1,19 +1,3 @@ -#if 0 -''' ' -#endif - -#ifdef __cplusplus -template -using Pin = T; -template -using Box = T*; -#endif - -#if 0 -' ''' -#endif - - from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: diff --git a/tests/rust/box.toml b/tests/rust/box.toml index 84cb6b08b..79842d035 100644 --- a/tests/rust/box.toml +++ b/tests/rust/box.toml @@ -1,17 +1,8 @@ -header = """ -#if 0 -''' ' -#endif - -#ifdef __cplusplus +header = { language = "C++", line = """ template using Box = T*; -#endif +""" } -#if 0 -' ''' -#endif -""" [export] exclude = [ "Box", diff --git a/tests/rust/enum.toml b/tests/rust/enum.toml index 20073cf8d..ab4556f64 100644 --- a/tests/rust/enum.toml +++ b/tests/rust/enum.toml @@ -1,34 +1,20 @@ -header = """ -#if 0 -''' ' -#endif - -#ifdef __cplusplus +header = { language = "C++", line = """ template using Box = T*; -#endif - -#if 0 -' ''' -#endif -""" - -trailer = """ -#if 0 -''' ' -#endif +""" } +trailer = [ + { language = "Cython", line = "''' '" }, + """ #include #include "testing-helpers.h" static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); - -#if 0 -' ''' -#endif -""" +""", + { language = "Cython", line = "' '''" }, +] [export] exclude = [ diff --git a/tests/rust/exclude_generic_monomorph.toml b/tests/rust/exclude_generic_monomorph.toml index 15711ae3f..585db47d0 100644 --- a/tests/rust/exclude_generic_monomorph.toml +++ b/tests/rust/exclude_generic_monomorph.toml @@ -1,22 +1,17 @@ language = "C" -header = """ +header = [ + { language = "Cython", line = "''' '" }, + """ #include -#if 0 -''' ' -#endif - typedef uint64_t Option_Foo; - -#if 0 +""", + { language = "Cython", line = """ ' ''' -#endif - -#if 0 from libc.stdint cimport uint64_t ctypedef uint64_t Option_Foo -#endif -""" +""" }, +] [export] exclude = [ diff --git a/tests/rust/forward_declaration.toml b/tests/rust/forward_declaration.toml index 4f1d1ad7f..3afdd5928 100644 --- a/tests/rust/forward_declaration.toml +++ b/tests/rust/forward_declaration.toml @@ -1,23 +1,19 @@ -header = """ -#if 0 -''' ' -#endif +header = [ + { language = "Cython", line = "''' '" }, + """ #if defined(CBINDGEN_STYLE_TYPE) /* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS! #endif -#if 0 -' ''' -#endif -""" +""", + { language = "Cython", line = "' '''" }, +] -trailer = """ -#if 0 -''' ' -#endif +trailer = [ + { language = "Cython", line = "''' '" }, + """ #if defined(CBINDGEN_STYLE_TYPE) */ #endif -#if 0 -' ''' -#endif -""" +""", + { language = "Cython", line = "' '''" }, +] diff --git a/tests/rust/manuallydrop.toml b/tests/rust/manuallydrop.toml index 7ffee9acd..0240d83d6 100644 --- a/tests/rust/manuallydrop.toml +++ b/tests/rust/manuallydrop.toml @@ -1,17 +1,8 @@ -header = """ -#if 0 -''' ' -#endif - -#ifdef __cplusplus +header = { language = "C++", line = """ template using ManuallyDrop = T; -#endif +""" } -#if 0 -' ''' -#endif -""" [export] exclude = [ "ManuallyDrop", diff --git a/tests/rust/maybeuninit.toml b/tests/rust/maybeuninit.toml index ba671fa17..10fd7cb7a 100644 --- a/tests/rust/maybeuninit.toml +++ b/tests/rust/maybeuninit.toml @@ -1,17 +1,8 @@ -header = """ -#if 0 -''' ' -#endif - -#ifdef __cplusplus +header = { language = "C++", line = """ template using MaybeUninit = T; -#endif +""" } -#if 0 -' ''' -#endif -""" [export] exclude = [ "MaybeUninit", diff --git a/tests/rust/nonzero.toml b/tests/rust/nonzero.toml index 3c656dc7c..656b03099 100644 --- a/tests/rust/nonzero.toml +++ b/tests/rust/nonzero.toml @@ -1,13 +1,3 @@ -header = """ -#if 0 -''' ' -#endif - -#ifdef __cplusplus +header = { language = "C++", line = """ struct NonZeroI64; -#endif - -#if 0 -' ''' -#endif -""" +""" } diff --git a/tests/rust/opaque.toml b/tests/rust/opaque.toml index cf56c9761..16bc8a537 100644 --- a/tests/rust/opaque.toml +++ b/tests/rust/opaque.toml @@ -1,17 +1,7 @@ -header = """ -#if 0 -''' ' -#endif - -#ifdef __cplusplus +header = { language = "C++", line = """ // These could be added as opaque types I guess. template struct BuildHasherDefault; struct DefaultHasher; -#endif - -#if 0 -' ''' -#endif -""" +""" } diff --git a/tests/rust/pin.toml b/tests/rust/pin.toml index 5aeccf9df..f1be1416f 100644 --- a/tests/rust/pin.toml +++ b/tests/rust/pin.toml @@ -1,19 +1,10 @@ -header = """ -#if 0 -''' ' -#endif - -#ifdef __cplusplus +header = { language = "C++", line = """ template using Pin = T; template using Box = T*; -#endif +""" } -#if 0 -' ''' -#endif -""" [export] exclude = [ "Pin",