From 51405d1277690e4eb4c615fc9045a8c89bbc125b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 3 Oct 2020 23:36:14 +0300 Subject: [PATCH] Support generation of Cython bindings --- .github/workflows/cbindgen.yml | 10 + contributing.md | 3 + docs.md | 6 +- src/bindgen/bindings.rs | 112 ++++++---- src/bindgen/cdecl.rs | 8 +- src/bindgen/config.rs | 45 ++++ src/bindgen/ir/annotation.rs | 5 + src/bindgen/ir/cfg.rs | 60 ++++-- src/bindgen/ir/constant.rs | 53 +++-- src/bindgen/ir/documentation.rs | 9 + src/bindgen/ir/enumeration.rs | 112 ++++++---- src/bindgen/ir/field.rs | 10 +- src/bindgen/ir/function.rs | 23 +- src/bindgen/ir/opaque.rs | 32 ++- src/bindgen/ir/structure.rs | 47 +++-- src/bindgen/ir/ty.rs | 4 +- src/bindgen/ir/typedef.rs | 18 +- src/bindgen/ir/union.rs | 32 +-- src/bindgen/library.rs | 8 +- src/bindgen/writer.rs | 48 +++-- src/main.rs | 17 +- tests/expectations/alias.pyx | 36 ++++ tests/expectations/alias.tag.pyx | 36 ++++ tests/expectations/annotation.pyx | 59 ++++++ tests/expectations/annotation.tag.pyx | 59 ++++++ tests/expectations/array.pyx | 19 ++ tests/expectations/array.tag.pyx | 19 ++ tests/expectations/asserted_cast.pyx | 72 +++++++ tests/expectations/asserted_cast.tag.pyx | 72 +++++++ tests/expectations/assoc_const_conflict.pyx | 9 + tests/expectations/assoc_constant.pyx | 14 ++ tests/expectations/assoc_constant.tag.pyx | 14 ++ .../associated_constant_panic.pyx | 8 + tests/expectations/associated_in_body.pyx | 25 +++ tests/expectations/associated_in_body.tag.pyx | 25 +++ tests/expectations/bitfield.pyx | 13 ++ tests/expectations/bitfield.tag.pyx | 13 ++ tests/expectations/bitflags.pyx | 30 +++ tests/expectations/bitflags.tag.pyx | 30 +++ tests/expectations/body.pyx | 74 +++++++ tests/expectations/body.tag.pyx | 74 +++++++ tests/expectations/box.pyx | 21 ++ tests/expectations/box.tag.pyx | 21 ++ tests/expectations/cdecl.pyx | 41 ++++ tests/expectations/cell.pyx | 17 ++ tests/expectations/cell.tag.pyx | 17 ++ tests/expectations/cfg.pyx | 45 ++++ tests/expectations/cfg.tag.pyx | 45 ++++ tests/expectations/cfg_2.pyx | 34 +++ tests/expectations/cfg_2.tag.pyx | 34 +++ tests/expectations/cfg_field.pyx | 8 + tests/expectations/char.pyx | 12 ++ tests/expectations/char.tag.pyx | 12 ++ tests/expectations/const_conflict.pyx | 9 + tests/expectations/const_transparent.pyx | 11 + tests/expectations/constant.pyx | 47 +++++ tests/expectations/constant.tag.pyx | 47 +++++ tests/expectations/constant_big.pyx | 15 ++ tests/expectations/constant_constexpr.pyx | 21 ++ tests/expectations/constant_constexpr.tag.pyx | 21 ++ tests/expectations/constant_sort_name.pyx | 15 ++ tests/expectations/constant_sort_none.pyx | 15 ++ .../constant_user_defined_type.pyx | 21 ++ .../constant_user_defined_type.tag.pyx | 21 ++ tests/expectations/custom_header.pyx | 7 + tests/expectations/dep_v2.pyx | 13 ++ tests/expectations/dep_v2.tag.pyx | 13 ++ tests/expectations/derive_eq.pyx | 40 ++++ tests/expectations/derive_eq.tag.pyx | 40 ++++ tests/expectations/derive_ostream.pyx | 77 +++++++ tests/expectations/derive_ostream.tag.pyx | 77 +++++++ .../expectations/destructor_and_copy_ctor.pyx | 198 ++++++++++++++++++ .../destructor_and_copy_ctor.tag.pyx | 198 ++++++++++++++++++ tests/expectations/display_list.pyx | 42 ++++ tests/expectations/display_list.tag.pyx | 42 ++++ tests/expectations/docstyle_auto.pyx | 10 + tests/expectations/docstyle_c99.pyx | 10 + tests/expectations/docstyle_doxy.pyx | 10 + tests/expectations/documentation.pyx | 27 +++ tests/expectations/documentation_attr.pyx | 21 ++ tests/expectations/enum.pyx | 174 +++++++++++++++ tests/expectations/enum.tag.pyx | 174 +++++++++++++++ tests/expectations/enum_discriminant.c | 10 +- tests/expectations/enum_discriminant.compat.c | 14 +- tests/expectations/enum_discriminant.cpp | 5 + tests/expectations/enum_discriminant.pyx | 19 ++ tests/expectations/enum_self.pyx | 31 +++ tests/expectations/enum_self.tag.pyx | 31 +++ tests/expectations/euclid.pyx | 108 ++++++++++ tests/expectations/euclid.tag.pyx | 108 ++++++++++ .../exclude_generic_monomorph.pyx | 16 ++ .../exclude_generic_monomorph.tag.pyx | 16 ++ tests/expectations/expand.pyx | 12 ++ tests/expectations/expand.tag.pyx | 12 ++ .../expectations/expand_default_features.pyx | 14 ++ .../expand_default_features.tag.pyx | 14 ++ tests/expectations/expand_dep.pyx | 13 ++ tests/expectations/expand_dep.tag.pyx | 13 ++ tests/expectations/expand_dep_v2.pyx | 13 ++ tests/expectations/expand_dep_v2.tag.pyx | 13 ++ tests/expectations/expand_features.pyx | 16 ++ tests/expectations/expand_features.tag.pyx | 16 ++ .../expand_no_default_features.pyx | 12 ++ .../expand_no_default_features.tag.pyx | 12 ++ tests/expectations/export_name.pyx | 9 + tests/expectations/extern.pyx | 15 ++ tests/expectations/extern.tag.pyx | 15 ++ tests/expectations/extern_2.pyx | 11 + .../expectations/external_workspace_child.pyx | 12 ++ .../external_workspace_child.tag.pyx | 12 ++ tests/expectations/fns.pyx | 18 ++ tests/expectations/fns.tag.pyx | 18 ++ tests/expectations/function_args.pyx | 13 ++ tests/expectations/function_noreturn.pyx | 19 ++ tests/expectations/function_sort_name.pyx | 15 ++ tests/expectations/function_sort_none.pyx | 15 ++ tests/expectations/generic_pointer.pyx | 14 ++ tests/expectations/generic_pointer.tag.pyx | 14 ++ tests/expectations/global_attr.pyx | 8 + tests/expectations/global_variable.pyx | 11 + tests/expectations/ignore.pyx | 9 + tests/expectations/include.pyx | 8 + tests/expectations/include_guard.pyx | 4 + tests/expectations/include_item.pyx | 14 ++ tests/expectations/include_item.tag.pyx | 14 ++ tests/expectations/include_specific.pyx | 3 + tests/expectations/inner_mod.pyx | 12 ++ tests/expectations/inner_mod.tag.pyx | 12 ++ tests/expectations/item_types.pyx | 12 ++ tests/expectations/item_types_renamed.pyx | 12 ++ tests/expectations/layout.pyx | 72 +++++++ tests/expectations/layout.tag.pyx | 72 +++++++ tests/expectations/layout_aligned_opaque.pyx | 43 ++++ .../layout_aligned_opaque.tag.pyx | 43 ++++ tests/expectations/layout_packed_opaque.pyx | 49 +++++ .../expectations/layout_packed_opaque.tag.pyx | 49 +++++ tests/expectations/lifetime_arg.pyx | 23 ++ tests/expectations/lifetime_arg.tag.pyx | 23 ++ tests/expectations/linestyle_cr.pyx | 1 + tests/expectations/linestyle_cr.tag.pyx | 1 + tests/expectations/linestyle_crlf.pyx | 13 ++ tests/expectations/linestyle_crlf.tag.pyx | 13 ++ tests/expectations/linestyle_lf.pyx | 13 ++ tests/expectations/linestyle_lf.tag.pyx | 13 ++ tests/expectations/literal_target.pyx | 8 + tests/expectations/mangle.pyx | 14 ++ tests/expectations/mangle.tag.pyx | 14 ++ tests/expectations/manuallydrop.pyx | 23 ++ tests/expectations/manuallydrop.tag.pyx | 23 ++ tests/expectations/maybeuninit.pyx | 17 ++ tests/expectations/maybeuninit.tag.pyx | 17 ++ tests/expectations/mod_2015.pyx | 14 ++ tests/expectations/mod_2015.tag.pyx | 14 ++ tests/expectations/mod_2018.pyx | 14 ++ tests/expectations/mod_2018.tag.pyx | 14 ++ tests/expectations/mod_attr.pyx | 31 +++ tests/expectations/mod_attr.tag.pyx | 31 +++ tests/expectations/mod_path.pyx | 14 ++ tests/expectations/mod_path.tag.pyx | 14 ++ tests/expectations/monomorph_1.pyx | 44 ++++ tests/expectations/monomorph_1.tag.pyx | 44 ++++ tests/expectations/monomorph_2.pyx | 25 +++ tests/expectations/monomorph_2.tag.pyx | 25 +++ tests/expectations/monomorph_3.pyx | 44 ++++ tests/expectations/monomorph_3.tag.pyx | 44 ++++ tests/expectations/must_use.pyx | 29 +++ tests/expectations/must_use.tag.pyx | 29 +++ tests/expectations/namespace_constant.pyx | 16 ++ tests/expectations/namespace_constant.tag.pyx | 16 ++ tests/expectations/namespaces_constant.pyx | 16 ++ .../expectations/namespaces_constant.tag.pyx | 16 ++ tests/expectations/nested_import.pyx | 8 + tests/expectations/no_includes.pyx | 4 + tests/expectations/nonnull.pyx | 23 ++ tests/expectations/nonnull.tag.pyx | 23 ++ tests/expectations/nonnull_attribute.pyx | 52 +++++ tests/expectations/nonnull_attribute.tag.pyx | 52 +++++ tests/expectations/opaque.pyx | 22 ++ tests/expectations/opaque.tag.pyx | 22 ++ tests/expectations/pragma_once.pyx | 9 + tests/expectations/prefix.pyx | 31 +++ tests/expectations/prefix.tag.pyx | 31 +++ .../expectations/prefixed_struct_literal.pyx | 16 ++ .../prefixed_struct_literal.tag.pyx | 16 ++ .../prefixed_struct_literal_deep.pyx | 19 ++ .../prefixed_struct_literal_deep.tag.pyx | 19 ++ tests/expectations/ptrs_as_arrays.pyx | 17 ++ tests/expectations/raw_lines.pyx | 10 + tests/expectations/rename.pyx | 36 ++++ tests/expectations/rename.tag.pyx | 36 ++++ tests/expectations/rename_crate.pyx | 34 +++ tests/expectations/rename_crate.tag.pyx | 34 +++ .../renaming_overrides_prefixing.pyx | 16 ++ .../renaming_overrides_prefixing.tag.pyx | 16 ++ tests/expectations/reserved.pyx | 61 ++++++ tests/expectations/reserved.tag.pyx | 61 ++++++ tests/expectations/sentinel.pyx | 46 ++++ tests/expectations/sentinel.tag.pyx | 46 ++++ tests/expectations/simplify_option_ptr.pyx | 22 ++ .../expectations/simplify_option_ptr.tag.pyx | 22 ++ tests/expectations/size_types.pyx | 21 ++ tests/expectations/static.pyx | 21 ++ tests/expectations/static.tag.pyx | 21 ++ tests/expectations/std_lib.pyx | 18 ++ tests/expectations/std_lib.tag.pyx | 18 ++ tests/expectations/struct.pyx | 28 +++ tests/expectations/struct.tag.pyx | 28 +++ tests/expectations/struct_literal.pyx | 24 +++ tests/expectations/struct_literal.tag.pyx | 24 +++ tests/expectations/struct_literal_order.pyx | 25 +++ .../expectations/struct_literal_order.tag.pyx | 25 +++ tests/expectations/struct_self.pyx | 16 ++ tests/expectations/struct_self.tag.pyx | 16 ++ tests/expectations/style_crash.pyx | 8 + tests/expectations/swift_name.pyx | 54 +++++ tests/expectations/swift_name.tag.pyx | 54 +++++ tests/expectations/transform_op.pyx | 135 ++++++++++++ tests/expectations/transform_op.tag.pyx | 135 ++++++++++++ tests/expectations/transparent.pyx | 40 ++++ tests/expectations/transparent.tag.pyx | 40 ++++ tests/expectations/typedef.pyx | 15 ++ tests/expectations/typedef.tag.pyx | 15 ++ tests/expectations/union.pyx | 20 ++ tests/expectations/union.tag.pyx | 20 ++ tests/expectations/union_self.pyx | 16 ++ tests/expectations/union_self.tag.pyx | 16 ++ tests/expectations/using_namespaces.pyx | 9 + tests/expectations/va_list.pyx | 9 + tests/expectations/workspace.pyx | 14 ++ tests/expectations/workspace.tag.pyx | 14 ++ tests/rust/body.cython.toml | 17 ++ tests/rust/box.cython.toml | 10 + tests/rust/cfg.cython.toml | 15 ++ tests/rust/cfg_2.cython.toml | 9 + tests/rust/constant.cython.toml | 5 + tests/rust/custom_header.cython.toml | 5 + tests/rust/enum.cython.toml | 0 tests/rust/enum_discriminant.cython.toml | 2 + tests/rust/enum_discriminant.rs | 11 +- .../exclude_generic_monomorph.cython.toml | 9 + tests/rust/manuallydrop.cython.toml | 4 + tests/rust/maybeuninit.cython.toml | 4 + tests/rust/mod_attr.cython.toml | 9 + tests/rust/opaque.cython.toml | 0 tests/rust/prefix.cython.toml | 5 + tests/rust/rename_crate.cython.toml | 8 + tests/rust/swift_name.cython.toml | 9 + tests/tests.rs | 120 +++++++---- 248 files changed, 6652 insertions(+), 254 deletions(-) create mode 100644 tests/expectations/alias.pyx create mode 100644 tests/expectations/alias.tag.pyx create mode 100644 tests/expectations/annotation.pyx create mode 100644 tests/expectations/annotation.tag.pyx create mode 100644 tests/expectations/array.pyx create mode 100644 tests/expectations/array.tag.pyx create mode 100644 tests/expectations/asserted_cast.pyx create mode 100644 tests/expectations/asserted_cast.tag.pyx create mode 100644 tests/expectations/assoc_const_conflict.pyx create mode 100644 tests/expectations/assoc_constant.pyx create mode 100644 tests/expectations/assoc_constant.tag.pyx create mode 100644 tests/expectations/associated_constant_panic.pyx create mode 100644 tests/expectations/associated_in_body.pyx create mode 100644 tests/expectations/associated_in_body.tag.pyx create mode 100644 tests/expectations/bitfield.pyx create mode 100644 tests/expectations/bitfield.tag.pyx create mode 100644 tests/expectations/bitflags.pyx create mode 100644 tests/expectations/bitflags.tag.pyx create mode 100644 tests/expectations/body.pyx create mode 100644 tests/expectations/body.tag.pyx create mode 100644 tests/expectations/box.pyx create mode 100644 tests/expectations/box.tag.pyx create mode 100644 tests/expectations/cdecl.pyx create mode 100644 tests/expectations/cell.pyx create mode 100644 tests/expectations/cell.tag.pyx create mode 100644 tests/expectations/cfg.pyx create mode 100644 tests/expectations/cfg.tag.pyx create mode 100644 tests/expectations/cfg_2.pyx create mode 100644 tests/expectations/cfg_2.tag.pyx create mode 100644 tests/expectations/cfg_field.pyx create mode 100644 tests/expectations/char.pyx create mode 100644 tests/expectations/char.tag.pyx create mode 100644 tests/expectations/const_conflict.pyx create mode 100644 tests/expectations/const_transparent.pyx create mode 100644 tests/expectations/constant.pyx create mode 100644 tests/expectations/constant.tag.pyx create mode 100644 tests/expectations/constant_big.pyx create mode 100644 tests/expectations/constant_constexpr.pyx create mode 100644 tests/expectations/constant_constexpr.tag.pyx create mode 100644 tests/expectations/constant_sort_name.pyx create mode 100644 tests/expectations/constant_sort_none.pyx create mode 100644 tests/expectations/constant_user_defined_type.pyx create mode 100644 tests/expectations/constant_user_defined_type.tag.pyx create mode 100644 tests/expectations/custom_header.pyx create mode 100644 tests/expectations/dep_v2.pyx create mode 100644 tests/expectations/dep_v2.tag.pyx create mode 100644 tests/expectations/derive_eq.pyx create mode 100644 tests/expectations/derive_eq.tag.pyx create mode 100644 tests/expectations/derive_ostream.pyx create mode 100644 tests/expectations/derive_ostream.tag.pyx create mode 100644 tests/expectations/destructor_and_copy_ctor.pyx create mode 100644 tests/expectations/destructor_and_copy_ctor.tag.pyx create mode 100644 tests/expectations/display_list.pyx create mode 100644 tests/expectations/display_list.tag.pyx create mode 100644 tests/expectations/docstyle_auto.pyx create mode 100644 tests/expectations/docstyle_c99.pyx create mode 100644 tests/expectations/docstyle_doxy.pyx create mode 100644 tests/expectations/documentation.pyx create mode 100644 tests/expectations/documentation_attr.pyx create mode 100644 tests/expectations/enum.pyx create mode 100644 tests/expectations/enum.tag.pyx create mode 100644 tests/expectations/enum_discriminant.pyx create mode 100644 tests/expectations/enum_self.pyx create mode 100644 tests/expectations/enum_self.tag.pyx create mode 100644 tests/expectations/euclid.pyx create mode 100644 tests/expectations/euclid.tag.pyx create mode 100644 tests/expectations/exclude_generic_monomorph.pyx create mode 100644 tests/expectations/exclude_generic_monomorph.tag.pyx create mode 100644 tests/expectations/expand.pyx create mode 100644 tests/expectations/expand.tag.pyx create mode 100644 tests/expectations/expand_default_features.pyx create mode 100644 tests/expectations/expand_default_features.tag.pyx create mode 100644 tests/expectations/expand_dep.pyx create mode 100644 tests/expectations/expand_dep.tag.pyx create mode 100644 tests/expectations/expand_dep_v2.pyx create mode 100644 tests/expectations/expand_dep_v2.tag.pyx create mode 100644 tests/expectations/expand_features.pyx create mode 100644 tests/expectations/expand_features.tag.pyx create mode 100644 tests/expectations/expand_no_default_features.pyx create mode 100644 tests/expectations/expand_no_default_features.tag.pyx create mode 100644 tests/expectations/export_name.pyx create mode 100644 tests/expectations/extern.pyx create mode 100644 tests/expectations/extern.tag.pyx create mode 100644 tests/expectations/extern_2.pyx create mode 100644 tests/expectations/external_workspace_child.pyx create mode 100644 tests/expectations/external_workspace_child.tag.pyx create mode 100644 tests/expectations/fns.pyx create mode 100644 tests/expectations/fns.tag.pyx create mode 100644 tests/expectations/function_args.pyx create mode 100644 tests/expectations/function_noreturn.pyx create mode 100644 tests/expectations/function_sort_name.pyx create mode 100644 tests/expectations/function_sort_none.pyx create mode 100644 tests/expectations/generic_pointer.pyx create mode 100644 tests/expectations/generic_pointer.tag.pyx create mode 100644 tests/expectations/global_attr.pyx create mode 100644 tests/expectations/global_variable.pyx create mode 100644 tests/expectations/ignore.pyx create mode 100644 tests/expectations/include.pyx create mode 100644 tests/expectations/include_guard.pyx create mode 100644 tests/expectations/include_item.pyx create mode 100644 tests/expectations/include_item.tag.pyx create mode 100644 tests/expectations/include_specific.pyx create mode 100644 tests/expectations/inner_mod.pyx create mode 100644 tests/expectations/inner_mod.tag.pyx create mode 100644 tests/expectations/item_types.pyx create mode 100644 tests/expectations/item_types_renamed.pyx create mode 100644 tests/expectations/layout.pyx create mode 100644 tests/expectations/layout.tag.pyx create mode 100644 tests/expectations/layout_aligned_opaque.pyx create mode 100644 tests/expectations/layout_aligned_opaque.tag.pyx create mode 100644 tests/expectations/layout_packed_opaque.pyx create mode 100644 tests/expectations/layout_packed_opaque.tag.pyx create mode 100644 tests/expectations/lifetime_arg.pyx create mode 100644 tests/expectations/lifetime_arg.tag.pyx create mode 100644 tests/expectations/linestyle_cr.pyx create mode 100644 tests/expectations/linestyle_cr.tag.pyx create mode 100644 tests/expectations/linestyle_crlf.pyx create mode 100644 tests/expectations/linestyle_crlf.tag.pyx create mode 100644 tests/expectations/linestyle_lf.pyx create mode 100644 tests/expectations/linestyle_lf.tag.pyx create mode 100644 tests/expectations/literal_target.pyx create mode 100644 tests/expectations/mangle.pyx create mode 100644 tests/expectations/mangle.tag.pyx create mode 100644 tests/expectations/manuallydrop.pyx create mode 100644 tests/expectations/manuallydrop.tag.pyx create mode 100644 tests/expectations/maybeuninit.pyx create mode 100644 tests/expectations/maybeuninit.tag.pyx create mode 100644 tests/expectations/mod_2015.pyx create mode 100644 tests/expectations/mod_2015.tag.pyx create mode 100644 tests/expectations/mod_2018.pyx create mode 100644 tests/expectations/mod_2018.tag.pyx create mode 100644 tests/expectations/mod_attr.pyx create mode 100644 tests/expectations/mod_attr.tag.pyx create mode 100644 tests/expectations/mod_path.pyx create mode 100644 tests/expectations/mod_path.tag.pyx create mode 100644 tests/expectations/monomorph_1.pyx create mode 100644 tests/expectations/monomorph_1.tag.pyx create mode 100644 tests/expectations/monomorph_2.pyx create mode 100644 tests/expectations/monomorph_2.tag.pyx create mode 100644 tests/expectations/monomorph_3.pyx create mode 100644 tests/expectations/monomorph_3.tag.pyx create mode 100644 tests/expectations/must_use.pyx create mode 100644 tests/expectations/must_use.tag.pyx create mode 100644 tests/expectations/namespace_constant.pyx create mode 100644 tests/expectations/namespace_constant.tag.pyx create mode 100644 tests/expectations/namespaces_constant.pyx create mode 100644 tests/expectations/namespaces_constant.tag.pyx create mode 100644 tests/expectations/nested_import.pyx create mode 100644 tests/expectations/no_includes.pyx create mode 100644 tests/expectations/nonnull.pyx create mode 100644 tests/expectations/nonnull.tag.pyx create mode 100644 tests/expectations/nonnull_attribute.pyx create mode 100644 tests/expectations/nonnull_attribute.tag.pyx create mode 100644 tests/expectations/opaque.pyx create mode 100644 tests/expectations/opaque.tag.pyx create mode 100644 tests/expectations/pragma_once.pyx create mode 100644 tests/expectations/prefix.pyx create mode 100644 tests/expectations/prefix.tag.pyx create mode 100644 tests/expectations/prefixed_struct_literal.pyx create mode 100644 tests/expectations/prefixed_struct_literal.tag.pyx create mode 100644 tests/expectations/prefixed_struct_literal_deep.pyx create mode 100644 tests/expectations/prefixed_struct_literal_deep.tag.pyx create mode 100644 tests/expectations/ptrs_as_arrays.pyx create mode 100644 tests/expectations/raw_lines.pyx create mode 100644 tests/expectations/rename.pyx create mode 100644 tests/expectations/rename.tag.pyx create mode 100644 tests/expectations/rename_crate.pyx create mode 100644 tests/expectations/rename_crate.tag.pyx create mode 100644 tests/expectations/renaming_overrides_prefixing.pyx create mode 100644 tests/expectations/renaming_overrides_prefixing.tag.pyx create mode 100644 tests/expectations/reserved.pyx create mode 100644 tests/expectations/reserved.tag.pyx create mode 100644 tests/expectations/sentinel.pyx create mode 100644 tests/expectations/sentinel.tag.pyx create mode 100644 tests/expectations/simplify_option_ptr.pyx create mode 100644 tests/expectations/simplify_option_ptr.tag.pyx create mode 100644 tests/expectations/size_types.pyx create mode 100644 tests/expectations/static.pyx create mode 100644 tests/expectations/static.tag.pyx create mode 100644 tests/expectations/std_lib.pyx create mode 100644 tests/expectations/std_lib.tag.pyx create mode 100644 tests/expectations/struct.pyx create mode 100644 tests/expectations/struct.tag.pyx create mode 100644 tests/expectations/struct_literal.pyx create mode 100644 tests/expectations/struct_literal.tag.pyx create mode 100644 tests/expectations/struct_literal_order.pyx create mode 100644 tests/expectations/struct_literal_order.tag.pyx create mode 100644 tests/expectations/struct_self.pyx create mode 100644 tests/expectations/struct_self.tag.pyx create mode 100644 tests/expectations/style_crash.pyx create mode 100644 tests/expectations/swift_name.pyx create mode 100644 tests/expectations/swift_name.tag.pyx create mode 100644 tests/expectations/transform_op.pyx create mode 100644 tests/expectations/transform_op.tag.pyx create mode 100644 tests/expectations/transparent.pyx create mode 100644 tests/expectations/transparent.tag.pyx create mode 100644 tests/expectations/typedef.pyx create mode 100644 tests/expectations/typedef.tag.pyx create mode 100644 tests/expectations/union.pyx create mode 100644 tests/expectations/union.tag.pyx create mode 100644 tests/expectations/union_self.pyx create mode 100644 tests/expectations/union_self.tag.pyx create mode 100644 tests/expectations/using_namespaces.pyx create mode 100644 tests/expectations/va_list.pyx create mode 100644 tests/expectations/workspace.pyx create mode 100644 tests/expectations/workspace.tag.pyx create mode 100644 tests/rust/body.cython.toml create mode 100644 tests/rust/box.cython.toml create mode 100644 tests/rust/cfg.cython.toml create mode 100644 tests/rust/cfg_2.cython.toml create mode 100644 tests/rust/constant.cython.toml create mode 100644 tests/rust/custom_header.cython.toml create mode 100644 tests/rust/enum.cython.toml create mode 100644 tests/rust/enum_discriminant.cython.toml create mode 100644 tests/rust/exclude_generic_monomorph.cython.toml create mode 100644 tests/rust/manuallydrop.cython.toml create mode 100644 tests/rust/maybeuninit.cython.toml create mode 100644 tests/rust/mod_attr.cython.toml create mode 100644 tests/rust/opaque.cython.toml create mode 100644 tests/rust/prefix.cython.toml create mode 100644 tests/rust/rename_crate.cython.toml create mode 100644 tests/rust/swift_name.cython.toml diff --git a/.github/workflows/cbindgen.yml b/.github/workflows/cbindgen.yml index 099d889..1f68158 100644 --- a/.github/workflows/cbindgen.yml +++ b/.github/workflows/cbindgen.yml @@ -54,6 +54,16 @@ jobs: toolchain: nightly override: true + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.8.*' + + - name: Install Cython + run: | + python -m pip install --upgrade pip wheel + pip install Cython==0.29.* + - name: Build run: | cargo build --verbose diff --git a/contributing.md b/contributing.md index a4a8357..5cc7a1b 100644 --- a/contributing.md +++ b/contributing.md @@ -14,6 +14,9 @@ Don't worry about requesting code review, as there is nothing formally setup for There is continuous integration setup for `cbindgen` using [travis](https://travis-ci.org/). It automatically runs `cargo test` which runs `cbindgen` against a series of rust files from `tests/rust/` and checks that the output compiles using `gcc` or `g++`. +In addition to a C/C++ compiler `cargo test` requires Python and Cython +(`python -m pip install Cython`) for checking Cython bindings generated from tests (`.pyx` files). + Please run `cargo test` before filing a pull request to be sure that all tests pass. This will also update the test expectations. Rustfmt is also enforced by travis. To format your code install `rustfmt-preview` using `rustup component add rustfmt-preview` and then `cargo fmt`. Travis runs with rust nightly, so use `rustup run nightly -- cargo fmt` to guarantee consistent results. diff --git a/docs.md b/docs.md index f0ce276..f2b86f2 100644 --- a/docs.md +++ b/docs.md @@ -36,7 +36,9 @@ Then all you need to do is run it: cbindgen --config cbindgen.toml --crate my_rust_library --output my_header.h ``` -This produces a header file for C++. For C, add the `--lang c` switch. +This produces a header file for C++. For C, add the `--lang c` switch. \ +`cbindgen` also supports generation of [Cython](https://cython.org) bindings, +use `--lang cython` for that. See `cbindgen --help` for more options. @@ -372,7 +374,7 @@ Note that many options defined here only apply for one of C or C++. Usually it's ```toml # The language to output bindings in # -# possible values: "C", "C++" +# possible values: "C", "C++", "Cython" # # default: "C++" language = "C" diff --git a/src/bindgen/bindings.rs b/src/bindgen/bindings.rs index ca7d158..3135f66 100644 --- a/src/bindgen/bindings.rs +++ b/src/bindgen/bindings.rs @@ -126,14 +126,14 @@ impl Bindings { write!(out, "{}", f); out.new_line(); } - if let Some(ref f) = self.config.include_guard { + if let Some(f) = self.config.include_guard() { out.new_line_if_not_start(); write!(out, "#ifndef {}", f); out.new_line(); write!(out, "#define {}", f); out.new_line(); } - if self.config.pragma_once { + if self.config.pragma_once && self.config.language != Language::Cython { out.new_line_if_not_start(); write!(out, "#pragma once"); out.new_line(); @@ -154,8 +154,8 @@ impl Bindings { } if self.config.no_includes - && self.config.sys_includes.is_empty() - && self.config.includes.is_empty() + && self.config.sys_includes().is_empty() + && self.config.includes().is_empty() && self.config.after_includes.is_none() { return; @@ -164,50 +164,70 @@ impl Bindings { out.new_line_if_not_start(); if !self.config.no_includes { - if self.config.language == Language::C { - out.write("#include "); - out.new_line(); - out.write("#include "); - out.new_line(); - if self.config.usize_is_size_t { - out.write("#include "); + match self.config.language { + Language::C => { + out.write("#include "); + out.new_line(); + out.write("#include "); + out.new_line(); + if self.config.usize_is_size_t { + out.write("#include "); + out.new_line(); + } + out.write("#include "); + out.new_line(); + out.write("#include "); out.new_line(); } - out.write("#include "); - out.new_line(); - out.write("#include "); - out.new_line(); - } else { - out.write("#include "); - out.new_line(); - if self.config.usize_is_size_t { - out.write("#include "); + Language::Cxx => { + out.write("#include "); out.new_line(); + if self.config.usize_is_size_t { + out.write("#include "); + out.new_line(); + } + out.write("#include "); + out.new_line(); + out.write("#include "); + out.new_line(); + out.write("#include "); + out.new_line(); + out.write("#include "); + out.new_line(); + if self.config.enumeration.cast_assert_name.is_none() + && (self.config.enumeration.derive_mut_casts + || self.config.enumeration.derive_const_casts) + { + out.write("#include "); + out.new_line(); + } } - out.write("#include "); - out.new_line(); - out.write("#include "); - out.new_line(); - out.write("#include "); - out.new_line(); - out.write("#include "); - out.new_line(); - if self.config.enumeration.cast_assert_name.is_none() - && (self.config.enumeration.derive_mut_casts - || self.config.enumeration.derive_const_casts) - { - out.write("#include "); + Language::Cython => { + out.write( + "from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t", + ); out.new_line(); + out.write( + "from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t", + ); + out.new_line(); + out.write("cdef extern from *"); + out.open_brace(); + out.write("ctypedef bint bool"); + out.new_line(); + out.write("ctypedef struct va_list"); + out.new_line(); + out.close_brace(false); } } } - for include in &self.config.sys_includes { + for include in self.config.sys_includes() { write!(out, "#include <{}>", include); out.new_line(); } - for include in &self.config.includes { + for include in self.config.includes() { write!(out, "#include \"{}\"", include); out.new_line(); } @@ -320,9 +340,18 @@ impl Bindings { } } + if self.config.language == Language::Cython + && self.globals.is_empty() + && self.constants.is_empty() + && self.items.is_empty() + && self.functions.is_empty() + { + out.write("pass"); + } + self.close_namespaces(&mut out); - if let Some(ref f) = self.config.include_guard { + if let Some(f) = self.config.include_guard() { out.new_line_if_not_start(); if self.config.language == Language::C { write!(out, "#endif /* {} */", f); @@ -357,6 +386,17 @@ impl Bindings { } fn open_close_namespaces(&self, op: NamespaceOperation, out: &mut SourceWriter) { + if self.config.language == Language::Cython { + if op == NamespaceOperation::Open { + out.new_line(); + out.write("cdef extern from *"); + out.open_brace(); + } else { + out.close_brace(false); + } + return; + } + let mut namespaces = self.all_namespaces(); if namespaces.is_empty() { return; diff --git a/src/bindgen/cdecl.rs b/src/bindgen/cdecl.rs index 6b06e35..b915d9d 100644 --- a/src/bindgen/cdecl.rs +++ b/src/bindgen/cdecl.rs @@ -180,8 +180,10 @@ impl CDecl { write!(out, "{} ", self.type_qualifers); } - if let Some(ref ctype) = self.type_ctype { - write!(out, "{} ", ctype.to_str()); + if config.language != Language::Cython { + if let Some(ref ctype) = self.type_ctype { + write!(out, "{} ", ctype.to_str()); + } } write!(out, "{}", self.type_name); @@ -214,7 +216,7 @@ impl CDecl { if is_const { out.write("const "); } - if !is_nullable && !is_ref { + if !is_nullable && !is_ref && config.language != Language::Cython { if let Some(attr) = &config.pointer.non_null_attribute { write!(out, "{} ", attr); } diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs index 16047d8..1bce80d 100644 --- a/src/bindgen/config.rs +++ b/src/bindgen/config.rs @@ -22,6 +22,7 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub enum Language { Cxx, C, + Cython, } impl FromStr for Language { @@ -39,6 +40,8 @@ impl FromStr for Language { "C++" => Ok(Language::Cxx), "c" => Ok(Language::C), "C" => Ok(Language::C), + "cython" => Ok(Language::Cython), + "Cython" => Ok(Language::Cython), _ => Err(format!("Unrecognized Language: '{}'.", s)), } } @@ -46,6 +49,15 @@ impl FromStr for Language { deserialize_enum_str!(Language); +impl Language { + pub(crate) fn typedef(self) -> &'static str { + match self { + Language::Cxx | Language::C => "typedef", + Language::Cython => "ctypedef", + } + } +} + /// Controls what type of line endings are used in the generated code. #[derive(Debug, Clone, Copy)] pub enum LineEndingStyle { @@ -200,6 +212,15 @@ impl Style { Style::Tag => false, } } + + // https://cython.readthedocs.io/en/latest/src/userguide/external_C_code.html#styles-of-struct-union-and-enum-declaration + pub fn cython_def(self) -> &'static str { + if self.generate_tag() { + "cdef " + } else { + "ctypedef " + } + } } impl FromStr for Style { @@ -945,6 +966,30 @@ impl Config { self.language == Language::C && self.cpp_compat } + pub(crate) fn include_guard(&self) -> Option<&str> { + if self.language == Language::Cython { + None + } else { + self.include_guard.as_deref() + } + } + + pub(crate) fn includes(&self) -> &[String] { + if self.language == Language::Cython { + &[] + } else { + &self.includes + } + } + + pub(crate) fn sys_includes(&self) -> &[String] { + if self.language == Language::Cython { + &[] + } else { + &self.sys_includes + } + } + pub fn from_file>(file_name: P) -> Result { let config_text = fs::read_to_string(file_name.as_ref()).map_err(|_| { format!( diff --git a/src/bindgen/ir/annotation.rs b/src/bindgen/ir/annotation.rs index 79e4233..208a177 100644 --- a/src/bindgen/ir/annotation.rs +++ b/src/bindgen/ir/annotation.rs @@ -6,6 +6,7 @@ use std::collections::hash_map::Entry; use std::collections::HashMap; use std::str::FromStr; +use crate::bindgen::config::{Config, Language}; use crate::bindgen::utilities::SynAttributeHelpers; // A system for specifying properties on items. Annotations are @@ -48,6 +49,10 @@ impl AnnotationSet { self.annotations.is_empty() && !self.must_use } + pub(crate) fn must_use(&self, config: &Config) -> bool { + self.must_use && config.language != Language::Cython + } + pub fn load(attrs: &[syn::Attribute]) -> Result { let lines = attrs.get_comment_lines(); let lines: Vec<&str> = lines diff --git a/src/bindgen/ir/cfg.rs b/src/bindgen/ir/cfg.rs index 2f6bfe6..46bc7b1 100644 --- a/src/bindgen/ir/cfg.rs +++ b/src/bindgen/ir/cfg.rs @@ -6,7 +6,7 @@ use std::fmt; use std::io::Write; use crate::bindgen::cargo::cargo_metadata::Dependency; -use crate::bindgen::config::Config; +use crate::bindgen::config::{Config, Language}; use crate::bindgen::writer::SourceWriter; #[derive(PartialEq, Eq)] @@ -283,15 +283,23 @@ impl Condition { fn write(&self, config: &Config, out: &mut SourceWriter) { match *self { Condition::Define(ref define) => { - out.write("defined("); - write!(out, "{}", define); - out.write(")"); + if config.language == Language::Cython { + write!(out, "{}", define); + } else { + out.write("defined("); + write!(out, "{}", define); + out.write(")"); + } } Condition::Any(ref conditions) => { out.write("("); for (i, condition) in conditions.iter().enumerate() { if i != 0 { - out.write(" || "); + out.write(if config.language == Language::Cython { + " or " + } else { + " || " + }); } condition.write(config, out); } @@ -301,14 +309,22 @@ impl Condition { out.write("("); for (i, condition) in conditions.iter().enumerate() { if i != 0 { - out.write(" && "); + out.write(if config.language == Language::Cython { + " and " + } else { + " && " + }); } condition.write(config, out); } out.write(")"); } Condition::Not(ref condition) => { - out.write("!"); + out.write(if config.language == Language::Cython { + "not " + } else { + "!" + }); condition.write(config, out); } } @@ -323,20 +339,30 @@ pub trait ConditionWrite { impl ConditionWrite for Option { fn write_before(&self, config: &Config, out: &mut SourceWriter) { if let Some(ref cfg) = *self { - out.push_set_spaces(0); - out.write("#if "); - cfg.write(config, out); - out.pop_set_spaces(); - out.new_line(); + if config.language == Language::Cython { + out.write("IF "); + cfg.write(config, out); + out.open_brace(); + } else { + out.push_set_spaces(0); + out.write("#if "); + cfg.write(config, out); + out.pop_set_spaces(); + out.new_line(); + } } } - fn write_after(&self, _config: &Config, out: &mut SourceWriter) { + fn write_after(&self, config: &Config, out: &mut SourceWriter) { if self.is_some() { - out.new_line(); - out.push_set_spaces(0); - out.write("#endif"); - out.pop_set_spaces(); + if config.language == Language::Cython { + out.close_brace(false); + } else { + out.new_line(); + out.push_set_spaces(0); + out.write("#endif"); + out.pop_set_spaces(); + } } } } diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index 556cabb..ba64730 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -307,9 +307,17 @@ impl Literal { write!(out, ")"); } Literal::Cast { ref ty, ref value } => { - write!(out, "("); + out.write(if config.language == Language::Cython { + "<" + } else { + "(" + }); ty.write(config, out); - write!(out, ")"); + out.write(if config.language == Language::Cython { + ">" + } else { + ")" + }); value.write(config, out); } Literal::Struct { @@ -317,10 +325,10 @@ impl Literal { fields, path, } => { - if config.language == Language::C { - write!(out, "({})", export_name); - } else { - write!(out, "{}", export_name); + match config.language { + Language::C => write!(out, "({})", export_name), + Language::Cxx => write!(out, "{}", export_name), + Language::Cython => write!(out, "<{}>", export_name), } write!(out, "{{ "); @@ -334,10 +342,10 @@ impl Literal { } else { is_first_field = false; } - if config.language == Language::Cxx { - write!(out, "/* .{} = */ ", ordered_key); - } else { - write!(out, ".{} = ", ordered_key); + match config.language { + Language::Cxx => write!(out, "/* .{} = */ ", ordered_key), + Language::C => write!(out, ".{} = ", ordered_key), + Language::Cython => {} } lit.write(config, out); } @@ -551,19 +559,24 @@ impl Constant { false }; - if (config.constant.allow_static_const || allow_constexpr) - && config.language == Language::Cxx + if config.language == Language::Cython + || (config.language == Language::Cxx + && (config.constant.allow_static_const || allow_constexpr)) { - if allow_constexpr { - out.write("constexpr ") - } + if config.language == Language::Cxx { + if allow_constexpr { + out.write("constexpr ") + } - if config.constant.allow_static_const { - out.write(if in_body { "inline " } else { "static " }); - } + if config.constant.allow_static_const { + out.write(if in_body { "inline " } else { "static " }); + } - if let Type::Ptr { is_const: true, .. } = self.ty { - // Nothing. + if let Type::Ptr { is_const: true, .. } = self.ty { + // Nothing. + } else { + out.write("const "); + } } else { out.write("const "); } diff --git a/src/bindgen/ir/documentation.rs b/src/bindgen/ir/documentation.rs index 9317a4b..f08440c 100644 --- a/src/bindgen/ir/documentation.rs +++ b/src/bindgen/ir/documentation.rs @@ -43,6 +43,15 @@ impl Source for Documentation { return; } + // Cython uses Python-style comments, so `documentation_style` is not relevant. + if config.language == Language::Cython { + for line in &self.doc_comment { + write!(out, "#{}", line); + out.new_line(); + } + return; + } + let style = match config.documentation_style { DocumentationStyle::Auto if config.language == Language::C => DocumentationStyle::Doxy, DocumentationStyle::Auto if config.language == Language::Cxx => DocumentationStyle::Cxx, diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index c5fc0d3..1d5481c 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -442,7 +442,7 @@ impl Item for Enum { fn rename_for_config(&mut self, config: &Config) { config.export.rename(&mut self.export_name); - if config.language == Language::C && self.tag.is_some() { + if config.language != Language::Cxx && self.tag.is_some() { // it makes sense to always prefix Tag with type name in C let new_tag = format!("{}_Tag", self.export_name); if self.repr.style == ReprStyle::Rust { @@ -590,7 +590,7 @@ impl Source for Enum { if is_tagged && config.language == Language::Cxx { out.write(if separate_tag { "struct" } else { "union" }); - if self.annotations.must_use { + if self.annotations.must_use(config) { if let Some(ref anno) = config.structure.must_use { write!(out, " {}", anno) } @@ -615,48 +615,61 @@ impl Source for Enum { }; // Emit the actual enum - if config.language == Language::C { - if let Some(prim) = size { - // If we need to specify size, then we have no choice but to create a typedef, - // so `config.style` is not respected. - write!(out, "enum {}", enum_name); + match config.language { + Language::C => { + if let Some(prim) = size { + // If we need to specify size, then we have no choice but to create a typedef, + // so `config.style` is not respected. + write!(out, "enum {}", enum_name); - if config.cpp_compatible_c() { - out.new_line(); - out.write("#ifdef __cplusplus"); - out.new_line(); - write!(out, " : {}", prim); - out.new_line(); - out.write("#endif // __cplusplus"); - out.new_line(); - } - } else { - if config.style.generate_typedef() { - out.write("typedef "); - } - out.write("enum"); - if config.style.generate_tag() { - write!(out, " {}", enum_name); + if config.cpp_compatible_c() { + out.new_line(); + out.write("#ifdef __cplusplus"); + out.new_line(); + write!(out, " : {}", prim); + out.new_line(); + out.write("#endif // __cplusplus"); + out.new_line(); + } + } else { + if config.style.generate_typedef() { + out.write("typedef "); + } + out.write("enum"); + if config.style.generate_tag() { + write!(out, " {}", enum_name); + } } } - } else { - if config.enumeration.enum_class(&self.annotations) { - out.write("enum class"); - } else { - out.write("enum"); - } + Language::Cxx => { + if config.enumeration.enum_class(&self.annotations) { + out.write("enum class"); + } else { + out.write("enum"); + } - if self.annotations.must_use { - if let Some(ref anno) = config.enumeration.must_use { - write!(out, " {}", anno) + if self.annotations.must_use(config) { + if let Some(ref anno) = config.enumeration.must_use { + write!(out, " {}", anno) + } + } + + write!(out, " {}", enum_name); + if let Some(prim) = size { + write!(out, " : {}", prim); } } - - write!(out, " {}", enum_name); - if let Some(prim) = size { - write!(out, " : {}", prim); + Language::Cython => { + if size.is_some() { + // If we need to specify size, then we have no choice but to create a typedef, + // so `config.style` is not respected. + write!(out, "cdef enum"); + } else { + write!(out, "{}enum {}", config.style.cython_def(), enum_name); + } } } + out.open_brace(); for (i, variant) in self.variants.iter().enumerate() { if i != 0 { @@ -678,9 +691,9 @@ impl Source for Enum { out.write("#ifndef __cplusplus"); } - if config.language == Language::C { + if config.language != Language::Cxx { out.new_line(); - write!(out, "typedef {} {};", prim, enum_name); + write!(out, "{} {} {};", config.language.typedef(), prim, enum_name); } if config.cpp_compatible_c() { @@ -838,15 +851,17 @@ impl Source for Enum { out.new_line(); out.new_line(); - // Emit the actual union - if config.language == Language::C { - if config.style.generate_typedef() { - out.write("typedef "); + // Emit the actual union (code here should mirror {struct,union}.rs). + if config.language != Language::Cxx { + match config.language { + Language::C if config.style.generate_typedef() => out.write("typedef "), + Language::C | Language::Cxx => {} + Language::Cython => out.write(config.style.cython_def()), } out.write(if separate_tag { "struct" } else { "union" }); - if config.style.generate_tag() { + if config.language != Language::C || config.style.generate_tag() { write!(out, " {}", self.export_name()); } @@ -883,7 +898,11 @@ impl Source for Enum { out.new_line(); - if separate_tag { + // Cython extern declarations don't manage layouts, layouts are defined entierly by the + // corresponding C code. So we can inline the unnamed union into the struct and get the + // same observable result. Moreother we have to do it because Cython doesn't support + // unnamed unions. + if separate_tag && config.language != Language::Cython { out.write("union"); out.open_brace(); } @@ -902,7 +921,7 @@ impl Source for Enum { first = false; let condition = variant.cfg.to_condition(config); condition.write_before(config, out); - if config.style.generate_typedef() { + if config.style.generate_typedef() || config.language == Language::Cython { write!(out, "{} {};", body.export_name(), field_name); } else { write!(out, "struct {} {};", body.export_name(), field_name); @@ -911,7 +930,8 @@ impl Source for Enum { } } - if separate_tag { + // See the comment about Cython on `open_brace`. + if separate_tag && config.language != Language::Cython { out.close_brace(true); } diff --git a/src/bindgen/ir/field.rs b/src/bindgen/ir/field.rs index a20b407..6d3e966 100644 --- a/src/bindgen/ir/field.rs +++ b/src/bindgen/ir/field.rs @@ -1,7 +1,7 @@ use std::io::Write; use crate::bindgen::cdecl; -use crate::bindgen::config::Config; +use crate::bindgen::config::{Config, Language}; use crate::bindgen::ir::{AnnotationSet, Documentation, Path, Type}; use crate::bindgen::writer::{Source, SourceWriter}; @@ -46,8 +46,12 @@ impl Source for Field { fn write(&self, config: &Config, out: &mut SourceWriter) { self.documentation.write(config, out); cdecl::write_field(out, &self.ty, &self.name, config); - if let Some(bitfield) = self.annotations.atom("bitfield") { - write!(out, ": {}", bitfield.unwrap_or_default()); + // Cython extern declarations don't manage layouts, layouts are defined entierly by the + // corresponding C code. So we can omit bitfield sizes which are not supported by Cython. + if config.language != Language::Cython { + if let Some(bitfield) = self.annotations.atom("bitfield") { + write!(out, ": {}", bitfield.unwrap_or_default()); + } } } } diff --git a/src/bindgen/ir/function.rs b/src/bindgen/ir/function.rs index 9966ff3..56e8e79 100644 --- a/src/bindgen/ir/function.rs +++ b/src/bindgen/ir/function.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::io::Write; use crate::bindgen::cdecl; -use crate::bindgen::config::{Config, Layout}; +use crate::bindgen::config::{Config, Language, Layout}; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{ @@ -86,7 +86,14 @@ impl Function { }) } - pub fn swift_name(&self) -> Option { + pub(crate) fn never_return(&self, config: &Config) -> bool { + self.never_return && config.language != Language::Cython + } + + pub fn swift_name(&self, config: &Config) -> Option { + if config.language == Language::Cython { + return None; + } // If the symbol name starts with the type name, separate the two components with '.' // so that Swift recognises the association between the method and the type let (ref type_prefix, ref type_name) = match self.self_type_path { @@ -243,7 +250,7 @@ impl Source for Function { if let Some(ref prefix) = prefix { write!(out, "{} ", prefix); } - if func.annotations.must_use { + if func.annotations.must_use(config) { if let Some(ref anno) = config.function.must_use { write!(out, "{} ", anno); } @@ -258,12 +265,12 @@ impl Source for Function { } if let Some(ref swift_name_macro) = config.function.swift_name_macro { - if let Some(swift_name) = func.swift_name() { + if let Some(swift_name) = func.swift_name(config) { write!(out, " {}({})", swift_name_macro, swift_name); } } - if func.never_return { + if func.never_return(config) { if let Some(ref no_return_attr) = config.function.no_return { out.write_fmt(format_args!(" {}", no_return_attr)); } @@ -291,7 +298,7 @@ impl Source for Function { write!(out, "{}", prefix); out.new_line(); } - if func.annotations.must_use { + if func.annotations.must_use(config) { if let Some(ref anno) = config.function.must_use { write!(out, "{}", anno); out.new_line(); @@ -307,12 +314,12 @@ impl Source for Function { } if let Some(ref swift_name_macro) = config.function.swift_name_macro { - if let Some(swift_name) = func.swift_name() { + if let Some(swift_name) = func.swift_name(config) { write!(out, " {}({})", swift_name_macro, swift_name); } } - if func.never_return { + if func.never_return(config) { if let Some(ref no_return_attr) = config.function.no_return { out.write_fmt(format_args!(" {}", no_return_attr)); } diff --git a/src/bindgen/ir/opaque.rs b/src/bindgen/ir/opaque.rs index 5a9c36a..a2bcf5c 100644 --- a/src/bindgen/ir/opaque.rs +++ b/src/bindgen/ir/opaque.rs @@ -146,15 +146,29 @@ impl Source for OpaqueItem { self.generic_params.write_with_default(config, out); - if config.style.generate_typedef() && config.language == Language::C { - write!( - out, - "typedef struct {} {};", - self.export_name(), - self.export_name() - ); - } else { - write!(out, "struct {};", self.export_name()); + match config.language { + Language::C if config.style.generate_typedef() => { + write!( + out, + "typedef struct {} {};", + self.export_name(), + self.export_name() + ); + } + Language::C | Language::Cxx => { + write!(out, "struct {};", self.export_name()); + } + Language::Cython => { + write!( + out, + "{}struct {}", + config.style.cython_def(), + self.export_name() + ); + out.open_brace(); + out.write("pass"); + out.close_brace(false); + } } condition.write_after(config, out); diff --git a/src/bindgen/ir/structure.rs b/src/bindgen/ir/structure.rs index 0f1ed4c..c39f40d 100644 --- a/src/bindgen/ir/structure.rs +++ b/src/bindgen/ir/structure.rs @@ -285,7 +285,7 @@ impl Item for Struct { fn rename_for_config(&mut self, config: &Config) { // Rename the name of the struct - if !self.is_tagged || config.language == Language::C { + if !(self.is_tagged && config.language == Language::Cxx) { config.export.rename(&mut self.export_name); } @@ -438,34 +438,50 @@ impl Source for Struct { // typedef struct { // C with Both as style: // typedef struct Name { - if config.language == Language::C && config.style.generate_typedef() { - out.write("typedef "); + match config.language { + Language::C if config.style.generate_typedef() => out.write("typedef "), + Language::C | Language::Cxx => {} + Language::Cython => out.write(config.style.cython_def()), + } + + // Cython extern declarations don't manage layouts, layouts are defined entierly by the + // corresponding C code. So this `packed` is only for documentation, and missing + // `aligned(n)` is also not a problem. + if config.language == Language::Cython { + if let Some(align) = self.alignment { + match align { + ReprAlign::Packed => out.write("packed "), + ReprAlign::Align(_) => {} // Not supported + } + } } out.write("struct"); - if let Some(align) = self.alignment { - match align { - ReprAlign::Packed => { - if let Some(ref anno) = config.layout.packed { - write!(out, " {}", anno); + if config.language != Language::Cython { + if let Some(align) = self.alignment { + match align { + ReprAlign::Packed => { + if let Some(ref anno) = config.layout.packed { + write!(out, " {}", anno); + } } - } - ReprAlign::Align(n) => { - if let Some(ref anno) = config.layout.aligned_n { - write!(out, " {}({})", anno, n); + ReprAlign::Align(n) => { + if let Some(ref anno) = config.layout.aligned_n { + write!(out, " {}({})", anno, n); + } } } } } - if self.annotations.must_use { + if self.annotations.must_use(config) { if let Some(ref anno) = config.structure.must_use { write!(out, " {}", anno); } } - if config.language == Language::Cxx || config.style.generate_tag() { + if config.language != Language::C || config.style.generate_tag() { write!(out, " {}", self.export_name()); } @@ -478,6 +494,9 @@ impl Source for Struct { } out.write_vertical_source_list(&self.fields, ListType::Cap(";")); + if config.language == Language::Cython && self.fields.is_empty() { + out.write("pass"); + } if config.language == Language::Cxx { let mut wrote_start_newline = false; diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index acf2052..e50aa95 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -428,14 +428,14 @@ impl Type { is_nullable: false, is_ref: false, }), - "Box" if config.language == Language::C => Some(Type::Ptr { + "Box" if config.language != Language::Cxx => Some(Type::Ptr { ty: Box::new(generic), is_const: false, is_nullable: false, is_ref: false, }), "Cell" => Some(generic), - "ManuallyDrop" | "MaybeUninit" if config.language == Language::C => Some(generic), + "ManuallyDrop" | "MaybeUninit" if config.language != Language::Cxx => Some(generic), _ => None, } } diff --git a/src/bindgen/ir/typedef.rs b/src/bindgen/ir/typedef.rs index 73eaf79..9c779a4 100644 --- a/src/bindgen/ir/typedef.rs +++ b/src/bindgen/ir/typedef.rs @@ -203,14 +203,18 @@ impl Source for Typedef { self.generic_params.write(config, out); - if config.language == Language::C { - out.write("typedef "); - Field::from_name_and_type(self.export_name().to_owned(), self.aliased.clone()) - .write(config, out); - } else { - write!(out, "using {} = ", self.export_name()); - self.aliased.write(config, out); + match config.language { + Language::Cxx => { + write!(out, "using {} = ", self.export_name()); + self.aliased.write(config, out); + } + Language::C | Language::Cython => { + write!(out, "{} ", config.language.typedef()); + Field::from_name_and_type(self.export_name().to_owned(), self.aliased.clone()) + .write(config, out); + } } + out.write(";"); condition.write_after(config, out); diff --git a/src/bindgen/ir/union.rs b/src/bindgen/ir/union.rs index a0a9959..d5996a5 100644 --- a/src/bindgen/ir/union.rs +++ b/src/bindgen/ir/union.rs @@ -290,28 +290,33 @@ impl Source for Union { // typedef union { // C with Both as style: // typedef union Name { - if config.language == Language::C && config.style.generate_typedef() { - out.write("typedef "); + match config.language { + Language::C if config.style.generate_typedef() => out.write("typedef "), + Language::C | Language::Cxx => {} + Language::Cython => out.write(config.style.cython_def()), } out.write("union"); - if let Some(align) = self.alignment { - match align { - ReprAlign::Packed => { - if let Some(ref anno) = config.layout.packed { - write!(out, " {}", anno); + // Cython supports `packed` on structs (see comments there), but not on unions. + if config.language != Language::Cython { + if let Some(align) = self.alignment { + match align { + ReprAlign::Packed => { + if let Some(ref anno) = config.layout.packed { + write!(out, " {}", anno); + } } - } - ReprAlign::Align(n) => { - if let Some(ref anno) = config.layout.aligned_n { - write!(out, " {}({})", anno, n); + ReprAlign::Align(n) => { + if let Some(ref anno) = config.layout.aligned_n { + write!(out, " {}({})", anno, n); + } } } } } - if config.language == Language::Cxx || config.style.generate_tag() { + if config.language != Language::C || config.style.generate_tag() { write!(out, " {}", self.export_name); } @@ -324,6 +329,9 @@ impl Source for Union { } out.write_vertical_source_list(&self.fields, ListType::Cap(";")); + if config.language == Language::Cython && self.fields.is_empty() { + out.write("pass"); + } // Emit the post_body section, if relevant if let Some(body) = config.export.post_body(&self.path) { diff --git a/src/bindgen/library.rs b/src/bindgen/library.rs index fc0c44d..95b207c 100644 --- a/src/bindgen/library.rs +++ b/src/bindgen/library.rs @@ -62,12 +62,12 @@ impl Library { SortKey::None => { /* keep input order */ } } - if self.config.language == Language::C { + if self.config.language != Language::Cxx { self.instantiate_monomorphs(); - self.remove_excluded(); + } + self.remove_excluded(); + if self.config.language == Language::C { self.resolve_declaration_types(); - } else { - self.remove_excluded(); } self.rename_items(); diff --git a/src/bindgen/writer.rs b/src/bindgen/writer.rs index fd61628..04b4abc 100644 --- a/src/bindgen/writer.rs +++ b/src/bindgen/writer.rs @@ -6,7 +6,7 @@ use std::cmp; use std::io; use std::io::Write; -use crate::bindgen::config::{Braces, Config}; +use crate::bindgen::config::{Braces, Config, Language}; use crate::bindgen::Bindings; /// A type of way to format a list. @@ -153,28 +153,42 @@ impl<'a, F: Write> SourceWriter<'a, F> { } pub fn open_brace(&mut self) { - match self.bindings.config.braces { - Braces::SameLine => { - self.write(" {"); + match self.bindings.config.language { + Language::Cxx | Language::C => match self.bindings.config.braces { + Braces::SameLine => { + self.write(" {"); + self.push_tab(); + self.new_line(); + } + Braces::NextLine => { + self.new_line(); + self.write("{"); + self.push_tab(); + self.new_line(); + } + }, + Language::Cython => { + self.write(":"); + self.new_line(); self.push_tab(); - self.new_line(); - } - Braces::NextLine => { - self.new_line(); - self.write("{"); - self.push_tab(); - self.new_line(); } } } pub fn close_brace(&mut self, semicolon: bool) { - self.pop_tab(); - self.new_line(); - if semicolon { - self.write("};"); - } else { - self.write("}"); + match self.bindings.config.language { + Language::Cxx | Language::C => { + self.pop_tab(); + self.new_line(); + if semicolon { + self.write("};"); + } else { + self.write("}"); + } + } + Language::Cython => { + self.pop_tab(); + } } } diff --git a/src/main.rs b/src/main.rs index 3cf1ef2..5c5eebe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,22 +25,19 @@ use clap::{App, Arg, ArgMatches}; mod bindgen; mod logging; -use crate::bindgen::{Bindings, Builder, Cargo, Config, Error, Language, Profile, Style}; +use crate::bindgen::{Bindings, Builder, Cargo, Config, Error, Profile, Style}; fn apply_config_overrides<'a>(config: &mut Config, matches: &ArgMatches<'a>) { // We allow specifying a language to override the config default. This is // used by compile-tests. if let Some(lang) = matches.value_of("lang") { - config.language = match lang { - "C++" => Language::Cxx, - "c++" => Language::Cxx, - "C" => Language::C, - "c" => Language::C, - _ => { - error!("Unknown language specified."); + config.language = match lang.parse() { + Ok(lang) => lang, + Err(reason) => { + error!("{}", reason); return; } - }; + } } if matches.is_present("cpp-compat") { @@ -155,7 +152,7 @@ fn main() { .long("lang") .value_name("LANGUAGE") .help("Specify the language to output bindings in") - .possible_values(&["c++", "C++", "c", "C"]), + .possible_values(&["c++", "C++", "c", "C", "cython", "Cython"]), ) .arg( Arg::with_name("cpp-compat") diff --git a/tests/expectations/alias.pyx b/tests/expectations/alias.pyx new file mode 100644 index 0000000..7471fb0 --- /dev/null +++ b/tests/expectations/alias.pyx @@ -0,0 +1,36 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + Ok, + Err, + ctypedef uint32_t Status; + + ctypedef struct Dep: + int32_t a; + float b; + + ctypedef struct Foo_i32: + int32_t a; + int32_t b; + Dep c; + + ctypedef Foo_i32 IntFoo; + + ctypedef struct Foo_f64: + double a; + double b; + Dep c; + + ctypedef Foo_f64 DoubleFoo; + + ctypedef int32_t Unit; + + ctypedef Status SpecialStatus; + + void root(IntFoo x, DoubleFoo y, Unit z, SpecialStatus w); diff --git a/tests/expectations/alias.tag.pyx b/tests/expectations/alias.tag.pyx new file mode 100644 index 0000000..e6d8662 --- /dev/null +++ b/tests/expectations/alias.tag.pyx @@ -0,0 +1,36 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + Ok, + Err, + ctypedef uint32_t Status; + + cdef struct Dep: + int32_t a; + float b; + + cdef struct Foo_i32: + int32_t a; + int32_t b; + Dep c; + + ctypedef Foo_i32 IntFoo; + + cdef struct Foo_f64: + double a; + double b; + Dep c; + + ctypedef Foo_f64 DoubleFoo; + + ctypedef int32_t Unit; + + ctypedef Status SpecialStatus; + + void root(IntFoo x, DoubleFoo y, Unit z, SpecialStatus w); diff --git a/tests/expectations/annotation.pyx b/tests/expectations/annotation.pyx new file mode 100644 index 0000000..340c7ba --- /dev/null +++ b/tests/expectations/annotation.pyx @@ -0,0 +1,59 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + X = 2, + Y, + ctypedef uint32_t C; + + ctypedef struct A: + int32_t m0; + + ctypedef struct B: + int32_t x; + float y; + + cdef enum: + Foo, + Bar, + Baz, + ctypedef uint8_t F_Tag; + + ctypedef struct Foo_Body: + F_Tag tag; + int16_t _0; + + ctypedef struct Bar_Body: + F_Tag tag; + uint8_t x; + int16_t y; + + ctypedef union F: + F_Tag tag; + Foo_Body foo; + Bar_Body bar; + + cdef enum: + Hello, + There, + Everyone, + ctypedef uint8_t H_Tag; + + ctypedef struct Hello_Body: + int16_t _0; + + ctypedef struct There_Body: + uint8_t x; + int16_t y; + + ctypedef struct H: + H_Tag tag; + Hello_Body hello; + There_Body there; + + void root(A x, B y, C z, F f, H h); diff --git a/tests/expectations/annotation.tag.pyx b/tests/expectations/annotation.tag.pyx new file mode 100644 index 0000000..801bbb2 --- /dev/null +++ b/tests/expectations/annotation.tag.pyx @@ -0,0 +1,59 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + X = 2, + Y, + ctypedef uint32_t C; + + cdef struct A: + int32_t m0; + + cdef struct B: + int32_t x; + float y; + + cdef enum: + Foo, + Bar, + Baz, + ctypedef uint8_t F_Tag; + + cdef struct Foo_Body: + F_Tag tag; + int16_t _0; + + cdef struct Bar_Body: + F_Tag tag; + uint8_t x; + int16_t y; + + cdef union F: + F_Tag tag; + Foo_Body foo; + Bar_Body bar; + + cdef enum: + Hello, + There, + Everyone, + ctypedef uint8_t H_Tag; + + cdef struct Hello_Body: + int16_t _0; + + cdef struct There_Body: + uint8_t x; + int16_t y; + + cdef struct H: + H_Tag tag; + Hello_Body hello; + There_Body there; + + void root(A x, B y, C z, F f, H h); diff --git a/tests/expectations/array.pyx b/tests/expectations/array.pyx new file mode 100644 index 0000000..e393b42 --- /dev/null +++ b/tests/expectations/array.pyx @@ -0,0 +1,19 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef enum Foo_Tag: + A, + + ctypedef struct A_Body: + float _0[20]; + + ctypedef struct Foo: + Foo_Tag tag; + A_Body a; + + void root(Foo a); diff --git a/tests/expectations/array.tag.pyx b/tests/expectations/array.tag.pyx new file mode 100644 index 0000000..333af9c --- /dev/null +++ b/tests/expectations/array.tag.pyx @@ -0,0 +1,19 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum Foo_Tag: + A, + + cdef struct A_Body: + float _0[20]; + + cdef struct Foo: + Foo_Tag tag; + A_Body a; + + void root(Foo a); diff --git a/tests/expectations/asserted_cast.pyx b/tests/expectations/asserted_cast.pyx new file mode 100644 index 0000000..bd27233 --- /dev/null +++ b/tests/expectations/asserted_cast.pyx @@ -0,0 +1,72 @@ +#define MY_ASSERT(...) do { } while (0) +#define MY_ATTRS __attribute((noinline)) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct I: + pass + + cdef enum: + H_Foo, + H_Bar, + H_Baz, + ctypedef uint8_t H_Tag; + + ctypedef struct H_Foo_Body: + int16_t _0; + + ctypedef struct H_Bar_Body: + uint8_t x; + int16_t y; + + ctypedef struct H: + H_Tag tag; + H_Foo_Body foo; + H_Bar_Body bar; + + cdef enum: + J_Foo, + J_Bar, + J_Baz, + ctypedef uint8_t J_Tag; + + ctypedef struct J_Foo_Body: + int16_t _0; + + ctypedef struct J_Bar_Body: + uint8_t x; + int16_t y; + + ctypedef struct J: + J_Tag tag; + J_Foo_Body foo; + J_Bar_Body bar; + + cdef enum: + K_Foo, + K_Bar, + K_Baz, + ctypedef uint8_t K_Tag; + + ctypedef struct K_Foo_Body: + K_Tag tag; + int16_t _0; + + ctypedef struct K_Bar_Body: + K_Tag tag; + uint8_t x; + int16_t y; + + ctypedef union K: + K_Tag tag; + K_Foo_Body foo; + K_Bar_Body bar; + + void foo(H h, I i, J j, K k); diff --git a/tests/expectations/asserted_cast.tag.pyx b/tests/expectations/asserted_cast.tag.pyx new file mode 100644 index 0000000..bc75d81 --- /dev/null +++ b/tests/expectations/asserted_cast.tag.pyx @@ -0,0 +1,72 @@ +#define MY_ASSERT(...) do { } while (0) +#define MY_ATTRS __attribute((noinline)) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct I: + pass + + cdef enum: + H_Foo, + H_Bar, + H_Baz, + ctypedef uint8_t H_Tag; + + cdef struct H_Foo_Body: + int16_t _0; + + cdef struct H_Bar_Body: + uint8_t x; + int16_t y; + + cdef struct H: + H_Tag tag; + H_Foo_Body foo; + H_Bar_Body bar; + + cdef enum: + J_Foo, + J_Bar, + J_Baz, + ctypedef uint8_t J_Tag; + + cdef struct J_Foo_Body: + int16_t _0; + + cdef struct J_Bar_Body: + uint8_t x; + int16_t y; + + cdef struct J: + J_Tag tag; + J_Foo_Body foo; + J_Bar_Body bar; + + cdef enum: + K_Foo, + K_Bar, + K_Baz, + ctypedef uint8_t K_Tag; + + cdef struct K_Foo_Body: + K_Tag tag; + int16_t _0; + + cdef struct K_Bar_Body: + K_Tag tag; + uint8_t x; + int16_t y; + + cdef union K: + K_Tag tag; + K_Foo_Body foo; + K_Bar_Body bar; + + void foo(H h, I i, J j, K k); diff --git a/tests/expectations/assoc_const_conflict.pyx b/tests/expectations/assoc_const_conflict.pyx new file mode 100644 index 0000000..13c734e --- /dev/null +++ b/tests/expectations/assoc_const_conflict.pyx @@ -0,0 +1,9 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint32_t Foo_FOO = 42; diff --git a/tests/expectations/assoc_constant.pyx b/tests/expectations/assoc_constant.pyx new file mode 100644 index 0000000..d0d7d67 --- /dev/null +++ b/tests/expectations/assoc_constant.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + pass + const int32_t Foo_GA = 10; + const float Foo_ZO = 3.14; + + void root(Foo x); diff --git a/tests/expectations/assoc_constant.tag.pyx b/tests/expectations/assoc_constant.tag.pyx new file mode 100644 index 0000000..98992e0 --- /dev/null +++ b/tests/expectations/assoc_constant.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + pass + const int32_t Foo_GA = 10; + const float Foo_ZO = 3.14; + + void root(Foo x); diff --git a/tests/expectations/associated_constant_panic.pyx b/tests/expectations/associated_constant_panic.pyx new file mode 100644 index 0000000..c82ecc5 --- /dev/null +++ b/tests/expectations/associated_constant_panic.pyx @@ -0,0 +1,8 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + pass \ No newline at end of file diff --git a/tests/expectations/associated_in_body.pyx b/tests/expectations/associated_in_body.pyx new file mode 100644 index 0000000..8df05e4 --- /dev/null +++ b/tests/expectations/associated_in_body.pyx @@ -0,0 +1,25 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + # Constants shared by multiple CSS Box Alignment properties + # + # These constants match Gecko's `NS_STYLE_ALIGN_*` constants. + ctypedef struct StyleAlignFlags: + uint8_t bits; + # 'auto' + const StyleAlignFlags StyleAlignFlags_AUTO = { 0 }; + # 'normal' + const StyleAlignFlags StyleAlignFlags_NORMAL = { 1 }; + # 'start' + const StyleAlignFlags StyleAlignFlags_START = { (1 << 1) }; + # 'end' + const StyleAlignFlags StyleAlignFlags_END = { (1 << 2) }; + # 'flex-start' + const StyleAlignFlags StyleAlignFlags_FLEX_START = { (1 << 3) }; + + void root(StyleAlignFlags flags); diff --git a/tests/expectations/associated_in_body.tag.pyx b/tests/expectations/associated_in_body.tag.pyx new file mode 100644 index 0000000..e967ea7 --- /dev/null +++ b/tests/expectations/associated_in_body.tag.pyx @@ -0,0 +1,25 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + # Constants shared by multiple CSS Box Alignment properties + # + # These constants match Gecko's `NS_STYLE_ALIGN_*` constants. + cdef struct StyleAlignFlags: + uint8_t bits; + # 'auto' + const StyleAlignFlags StyleAlignFlags_AUTO = { 0 }; + # 'normal' + const StyleAlignFlags StyleAlignFlags_NORMAL = { 1 }; + # 'start' + const StyleAlignFlags StyleAlignFlags_START = { (1 << 1) }; + # 'end' + const StyleAlignFlags StyleAlignFlags_END = { (1 << 2) }; + # 'flex-start' + const StyleAlignFlags StyleAlignFlags_FLEX_START = { (1 << 3) }; + + void root(StyleAlignFlags flags); diff --git a/tests/expectations/bitfield.pyx b/tests/expectations/bitfield.pyx new file mode 100644 index 0000000..721b890 --- /dev/null +++ b/tests/expectations/bitfield.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct HasBitfields: + uint64_t foo; + uint64_t bar; + + void root(const HasBitfields*); diff --git a/tests/expectations/bitfield.tag.pyx b/tests/expectations/bitfield.tag.pyx new file mode 100644 index 0000000..d4cb32f --- /dev/null +++ b/tests/expectations/bitfield.tag.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct HasBitfields: + uint64_t foo; + uint64_t bar; + + void root(const HasBitfields*); diff --git a/tests/expectations/bitflags.pyx b/tests/expectations/bitflags.pyx new file mode 100644 index 0000000..b56b250 --- /dev/null +++ b/tests/expectations/bitflags.pyx @@ -0,0 +1,30 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + # Constants shared by multiple CSS Box Alignment properties + # + # These constants match Gecko's `NS_STYLE_ALIGN_*` constants. + ctypedef struct AlignFlags: + uint8_t bits; + # 'auto' + const AlignFlags AlignFlags_AUTO = { 0 }; + # 'normal' + const AlignFlags AlignFlags_NORMAL = { 1 }; + # 'start' + const AlignFlags AlignFlags_START = { (1 << 1) }; + # 'end' + const AlignFlags AlignFlags_END = { (1 << 2) }; + # 'flex-start' + const AlignFlags AlignFlags_FLEX_START = { (1 << 3) }; + + ctypedef struct DebugFlags: + uint32_t bits; + # Flag with the topmost bit set of the u32 + const DebugFlags DebugFlags_BIGGEST_ALLOWED = { (1 << 31) }; + + void root(AlignFlags flags, DebugFlags bigger_flags); diff --git a/tests/expectations/bitflags.tag.pyx b/tests/expectations/bitflags.tag.pyx new file mode 100644 index 0000000..4e4be34 --- /dev/null +++ b/tests/expectations/bitflags.tag.pyx @@ -0,0 +1,30 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + # Constants shared by multiple CSS Box Alignment properties + # + # These constants match Gecko's `NS_STYLE_ALIGN_*` constants. + cdef struct AlignFlags: + uint8_t bits; + # 'auto' + const AlignFlags AlignFlags_AUTO = { 0 }; + # 'normal' + const AlignFlags AlignFlags_NORMAL = { 1 }; + # 'start' + const AlignFlags AlignFlags_START = { (1 << 1) }; + # 'end' + const AlignFlags AlignFlags_END = { (1 << 2) }; + # 'flex-start' + const AlignFlags AlignFlags_FLEX_START = { (1 << 3) }; + + cdef struct DebugFlags: + uint32_t bits; + # Flag with the topmost bit set of the u32 + const DebugFlags DebugFlags_BIGGEST_ALLOWED = { (1 << 31) }; + + void root(AlignFlags flags, DebugFlags bigger_flags); diff --git a/tests/expectations/body.pyx b/tests/expectations/body.pyx new file mode 100644 index 0000000..2f496c6 --- /dev/null +++ b/tests/expectations/body.pyx @@ -0,0 +1,74 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef enum MyCLikeEnum: + Foo1, + Bar1, + Baz1, + + ctypedef enum MyCLikeEnum_Prepended: + Foo1_Prepended, + Bar1_Prepended, + Baz1_Prepended, + + ctypedef struct MyFancyStruct: + int32_t i; + + ctypedef enum MyFancyEnum_Tag: + Foo, + Bar, + Baz, + + ctypedef struct Bar_Body: + int32_t _0; + + ctypedef struct Baz_Body: + int32_t _0; + + ctypedef struct MyFancyEnum: + MyFancyEnum_Tag tag; + Bar_Body bar; + Baz_Body baz; + + ctypedef union MyUnion: + float f; + uint32_t u; + int32_t extra_member; # yolo + + ctypedef struct MyFancyStruct_Prepended: + int32_t i; + + ctypedef enum MyFancyEnum_Prepended_Tag: + Foo_Prepended, + Bar_Prepended, + Baz_Prepended, + + ctypedef struct Bar_Prepended_Body: + int32_t _0; + + ctypedef struct Baz_Prepended_Body: + int32_t _0; + + ctypedef struct MyFancyEnum_Prepended: + MyFancyEnum_Prepended_Tag tag; + Bar_Prepended_Body bar_prepended; + Baz_Prepended_Body baz_prepended; + + ctypedef union MyUnion_Prepended: + int32_t extra_member; # yolo + float f; + uint32_t u; + + void root(MyFancyStruct s, + MyFancyEnum e, + MyCLikeEnum c, + MyUnion u, + MyFancyStruct_Prepended sp, + MyFancyEnum_Prepended ep, + MyCLikeEnum_Prepended cp, + MyUnion_Prepended up); diff --git a/tests/expectations/body.tag.pyx b/tests/expectations/body.tag.pyx new file mode 100644 index 0000000..cd8e24b --- /dev/null +++ b/tests/expectations/body.tag.pyx @@ -0,0 +1,74 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum MyCLikeEnum: + Foo1, + Bar1, + Baz1, + + cdef enum MyCLikeEnum_Prepended: + Foo1_Prepended, + Bar1_Prepended, + Baz1_Prepended, + + cdef struct MyFancyStruct: + int32_t i; + + cdef enum MyFancyEnum_Tag: + Foo, + Bar, + Baz, + + cdef struct Bar_Body: + int32_t _0; + + cdef struct Baz_Body: + int32_t _0; + + cdef struct MyFancyEnum: + MyFancyEnum_Tag tag; + Bar_Body bar; + Baz_Body baz; + + cdef union MyUnion: + float f; + uint32_t u; + int32_t extra_member; # yolo + + cdef struct MyFancyStruct_Prepended: + int32_t i; + + cdef enum MyFancyEnum_Prepended_Tag: + Foo_Prepended, + Bar_Prepended, + Baz_Prepended, + + cdef struct Bar_Prepended_Body: + int32_t _0; + + cdef struct Baz_Prepended_Body: + int32_t _0; + + cdef struct MyFancyEnum_Prepended: + MyFancyEnum_Prepended_Tag tag; + Bar_Prepended_Body bar_prepended; + Baz_Prepended_Body baz_prepended; + + cdef union MyUnion_Prepended: + int32_t extra_member; # yolo + float f; + uint32_t u; + + void root(MyFancyStruct s, + MyFancyEnum e, + MyCLikeEnum c, + MyUnion u, + MyFancyStruct_Prepended sp, + MyFancyEnum_Prepended ep, + MyCLikeEnum_Prepended cp, + MyUnion_Prepended up); diff --git a/tests/expectations/box.pyx b/tests/expectations/box.pyx new file mode 100644 index 0000000..f89a5cf --- /dev/null +++ b/tests/expectations/box.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct NotReprC_Box_i32: + pass + + ctypedef NotReprC_Box_i32 Foo; + + ctypedef struct MyStruct: + int32_t *number; + + void root(const Foo *a, const MyStruct *with_box); + + void drop_box(int32_t *x); + + void drop_box_opt(int32_t *x); diff --git a/tests/expectations/box.tag.pyx b/tests/expectations/box.tag.pyx new file mode 100644 index 0000000..c347de9 --- /dev/null +++ b/tests/expectations/box.tag.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct NotReprC_Box_i32: + pass + + ctypedef NotReprC_Box_i32 Foo; + + cdef struct MyStruct: + int32_t *number; + + void root(const Foo *a, const MyStruct *with_box); + + void drop_box(int32_t *x); + + void drop_box_opt(int32_t *x); diff --git a/tests/expectations/cdecl.pyx b/tests/expectations/cdecl.pyx new file mode 100644 index 0000000..8edeb2e --- /dev/null +++ b/tests/expectations/cdecl.pyx @@ -0,0 +1,41 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef void (*A)(); + + ctypedef void (*B)(); + + ctypedef bool (*C)(int32_t, int32_t); + + ctypedef bool (*(*D)(int32_t))(float); + + ctypedef const int32_t (*(*E)())[16]; + + ctypedef const int32_t *F; + + ctypedef const int32_t *const *G; + + ctypedef int32_t *const *H; + + ctypedef const int32_t (*I)[16]; + + ctypedef double (**J)(float); + + ctypedef int32_t K[16]; + + ctypedef const int32_t *L[16]; + + ctypedef bool (*M[16])(int32_t, int32_t); + + ctypedef void (*N[16])(int32_t, int32_t); + + ctypedef void (*P)(int32_t named1st, bool, bool named3rd, int32_t _); + + void (*O())(); + + void root(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, P p); diff --git a/tests/expectations/cell.pyx b/tests/expectations/cell.pyx new file mode 100644 index 0000000..4637419 --- /dev/null +++ b/tests/expectations/cell.pyx @@ -0,0 +1,17 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct NotReprC_RefCell_i32: + pass + + ctypedef NotReprC_RefCell_i32 Foo; + + ctypedef struct MyStruct: + int32_t number; + + void root(const Foo *a, const MyStruct *with_cell); diff --git a/tests/expectations/cell.tag.pyx b/tests/expectations/cell.tag.pyx new file mode 100644 index 0000000..a4682b0 --- /dev/null +++ b/tests/expectations/cell.tag.pyx @@ -0,0 +1,17 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct NotReprC_RefCell_i32: + pass + + ctypedef NotReprC_RefCell_i32 Foo; + + cdef struct MyStruct: + int32_t number; + + void root(const Foo *a, const MyStruct *with_cell); diff --git a/tests/expectations/cfg.pyx b/tests/expectations/cfg.pyx new file mode 100644 index 0000000..94ba1fb --- /dev/null +++ b/tests/expectations/cfg.pyx @@ -0,0 +1,45 @@ +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +DEF X11 = 0 +DEF M_32 = 0 + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + IF (PLATFORM_WIN or M_32): + cdef enum: + A, + B, + C, + ctypedef uint32_t BarType; + + IF (PLATFORM_UNIX and X11): + cdef enum: + A, + B, + C, + ctypedef uint32_t FooType; + + IF (PLATFORM_UNIX and X11): + ctypedef struct FooHandle: + FooType ty; + int32_t x; + float y; + + IF (PLATFORM_WIN or M_32): + ctypedef struct BarHandle: + BarType ty; + int32_t x; + float y; + + IF (PLATFORM_UNIX and X11): + void root(FooHandle a, C c); + + IF (PLATFORM_WIN or M_32): + void root(BarHandle a, C c); diff --git a/tests/expectations/cfg.tag.pyx b/tests/expectations/cfg.tag.pyx new file mode 100644 index 0000000..7b7de4a --- /dev/null +++ b/tests/expectations/cfg.tag.pyx @@ -0,0 +1,45 @@ +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +DEF X11 = 0 +DEF M_32 = 0 + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + IF (PLATFORM_WIN or M_32): + cdef enum: + A, + B, + C, + ctypedef uint32_t BarType; + + IF (PLATFORM_UNIX and X11): + cdef enum: + A, + B, + C, + ctypedef uint32_t FooType; + + IF (PLATFORM_UNIX and X11): + cdef struct FooHandle: + FooType ty; + int32_t x; + float y; + + IF (PLATFORM_WIN or M_32): + cdef struct BarHandle: + BarType ty; + int32_t x; + float y; + + IF (PLATFORM_UNIX and X11): + void root(FooHandle a, C c); + + IF (PLATFORM_WIN or M_32): + void root(BarHandle a, C c); diff --git a/tests/expectations/cfg_2.pyx b/tests/expectations/cfg_2.pyx new file mode 100644 index 0000000..ba9383a --- /dev/null +++ b/tests/expectations/cfg_2.pyx @@ -0,0 +1,34 @@ +DEF DEFINED = 1 +DEF NOT_DEFINED = 0 + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + IF NOT_DEFINED: + const int32_t DEFAULT_X = 8; + + IF DEFINED: + const int32_t DEFAULT_X = 42; + + IF (NOT_DEFINED or DEFINED): + ctypedef struct Foo: + int32_t x; + + IF NOT_DEFINED: + ctypedef struct Bar: + Foo y; + + IF DEFINED: + ctypedef struct Bar: + Foo z; + + ctypedef struct Root: + Bar w; + + void root(Root a); diff --git a/tests/expectations/cfg_2.tag.pyx b/tests/expectations/cfg_2.tag.pyx new file mode 100644 index 0000000..d6813fe --- /dev/null +++ b/tests/expectations/cfg_2.tag.pyx @@ -0,0 +1,34 @@ +DEF DEFINED = 1 +DEF NOT_DEFINED = 0 + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + IF NOT_DEFINED: + const int32_t DEFAULT_X = 8; + + IF DEFINED: + const int32_t DEFAULT_X = 42; + + IF (NOT_DEFINED or DEFINED): + cdef struct Foo: + int32_t x; + + IF NOT_DEFINED: + cdef struct Bar: + Foo y; + + IF DEFINED: + cdef struct Bar: + Foo z; + + cdef struct Root: + Bar w; + + void root(Root a); diff --git a/tests/expectations/cfg_field.pyx b/tests/expectations/cfg_field.pyx new file mode 100644 index 0000000..c82ecc5 --- /dev/null +++ b/tests/expectations/cfg_field.pyx @@ -0,0 +1,8 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + pass \ No newline at end of file diff --git a/tests/expectations/char.pyx b/tests/expectations/char.pyx new file mode 100644 index 0000000..bcafe98 --- /dev/null +++ b/tests/expectations/char.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + uint32_t a; + + void root(Foo a); diff --git a/tests/expectations/char.tag.pyx b/tests/expectations/char.tag.pyx new file mode 100644 index 0000000..9e854ed --- /dev/null +++ b/tests/expectations/char.tag.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + uint32_t a; + + void root(Foo a); diff --git a/tests/expectations/const_conflict.pyx b/tests/expectations/const_conflict.pyx new file mode 100644 index 0000000..13c734e --- /dev/null +++ b/tests/expectations/const_conflict.pyx @@ -0,0 +1,9 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint32_t Foo_FOO = 42; diff --git a/tests/expectations/const_transparent.pyx b/tests/expectations/const_transparent.pyx new file mode 100644 index 0000000..d05be79 --- /dev/null +++ b/tests/expectations/const_transparent.pyx @@ -0,0 +1,11 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef uint8_t Transparent; + + const Transparent FOO = 0; diff --git a/tests/expectations/constant.pyx b/tests/expectations/constant.pyx new file mode 100644 index 0000000..48a3aa5 --- /dev/null +++ b/tests/expectations/constant.pyx @@ -0,0 +1,47 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t FOO = 10; + + const uint32_t DELIMITER = ':'; + + const uint32_t LEFTCURLY = '{'; + + const uint32_t QUOTE = '\''; + + const uint32_t TAB = '\t'; + + const uint32_t NEWLINE = '\n'; + + const uint32_t HEART = U'\U00002764'; + + const uint32_t EQUID = U'\U00010083'; + + const float ZOM = 3.14; + + # A single-line doc comment. + const int8_t POS_ONE = 1; + + # A + # multi-line + # doc + # comment. + const int8_t NEG_ONE = -1; + + const int64_t SHIFT = 3; + + const int64_t XBOOL = 1; + + const uint8_t CAST = 'A'; + + const uint32_t DOUBLE_CAST = 1; + + ctypedef struct Foo: + int32_t x[FOO]; + + void root(Foo x); diff --git a/tests/expectations/constant.tag.pyx b/tests/expectations/constant.tag.pyx new file mode 100644 index 0000000..e64f5bf --- /dev/null +++ b/tests/expectations/constant.tag.pyx @@ -0,0 +1,47 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t FOO = 10; + + const uint32_t DELIMITER = ':'; + + const uint32_t LEFTCURLY = '{'; + + const uint32_t QUOTE = '\''; + + const uint32_t TAB = '\t'; + + const uint32_t NEWLINE = '\n'; + + const uint32_t HEART = U'\U00002764'; + + const uint32_t EQUID = U'\U00010083'; + + const float ZOM = 3.14; + + # A single-line doc comment. + const int8_t POS_ONE = 1; + + # A + # multi-line + # doc + # comment. + const int8_t NEG_ONE = -1; + + const int64_t SHIFT = 3; + + const int64_t XBOOL = 1; + + const uint8_t CAST = 'A'; + + const uint32_t DOUBLE_CAST = 1; + + cdef struct Foo: + int32_t x[FOO]; + + void root(Foo x); diff --git a/tests/expectations/constant_big.pyx b/tests/expectations/constant_big.pyx new file mode 100644 index 0000000..49ba699 --- /dev/null +++ b/tests/expectations/constant_big.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint64_t UNSIGNED_NEEDS_ULL_SUFFIX = 9223372036854775808ULL; + + const uint64_t UNSIGNED_DOESNT_NEED_ULL_SUFFIX = 8070450532247928832; + + const int64_t SIGNED_NEEDS_ULL_SUFFIX = -9223372036854775808ULL; + + const int64_t SIGNED_DOESNT_NEED_ULL_SUFFIX = -9223372036854775807; diff --git a/tests/expectations/constant_constexpr.pyx b/tests/expectations/constant_constexpr.pyx new file mode 100644 index 0000000..f1e28bb --- /dev/null +++ b/tests/expectations/constant_constexpr.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int64_t CONSTANT_I64 = 216; + + const float CONSTANT_FLOAT32 = 312.292; + + const uint32_t DELIMITER = ':'; + + const uint32_t LEFTCURLY = '{'; + + ctypedef struct Foo: + int32_t x; + const int64_t Foo_CONSTANT_I64_BODY = 216; + + const Foo SomeFoo = { 99 }; diff --git a/tests/expectations/constant_constexpr.tag.pyx b/tests/expectations/constant_constexpr.tag.pyx new file mode 100644 index 0000000..32ab3e4 --- /dev/null +++ b/tests/expectations/constant_constexpr.tag.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int64_t CONSTANT_I64 = 216; + + const float CONSTANT_FLOAT32 = 312.292; + + const uint32_t DELIMITER = ':'; + + const uint32_t LEFTCURLY = '{'; + + cdef struct Foo: + int32_t x; + const int64_t Foo_CONSTANT_I64_BODY = 216; + + const Foo SomeFoo = { 99 }; diff --git a/tests/expectations/constant_sort_name.pyx b/tests/expectations/constant_sort_name.pyx new file mode 100644 index 0000000..8065183 --- /dev/null +++ b/tests/expectations/constant_sort_name.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint8_t A = 0; + + const uint8_t B = 0; + + extern const uint8_t C; + + extern const uint8_t D; diff --git a/tests/expectations/constant_sort_none.pyx b/tests/expectations/constant_sort_none.pyx new file mode 100644 index 0000000..3ac9e6e --- /dev/null +++ b/tests/expectations/constant_sort_none.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint8_t B = 0; + + const uint8_t A = 0; + + extern const uint8_t D; + + extern const uint8_t C; diff --git a/tests/expectations/constant_user_defined_type.pyx b/tests/expectations/constant_user_defined_type.pyx new file mode 100644 index 0000000..cb404fd --- /dev/null +++ b/tests/expectations/constant_user_defined_type.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef enum E: + V, + + ctypedef struct S: + uint8_t field; + + ctypedef uint8_t A; + + const S C1 = { 0 }; + + const E C2 = V; + + const A C3 = 0; diff --git a/tests/expectations/constant_user_defined_type.tag.pyx b/tests/expectations/constant_user_defined_type.tag.pyx new file mode 100644 index 0000000..c8b2315 --- /dev/null +++ b/tests/expectations/constant_user_defined_type.tag.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum E: + V, + + cdef struct S: + uint8_t field; + + ctypedef uint8_t A; + + const S C1 = { 0 }; + + const E C2 = V; + + const A C3 = 0; diff --git a/tests/expectations/custom_header.pyx b/tests/expectations/custom_header.pyx new file mode 100644 index 0000000..ebba482 --- /dev/null +++ b/tests/expectations/custom_header.pyx @@ -0,0 +1,7 @@ +# This file is generated by cbindgen. DO NOT EDIT + +cdef extern from *: + + void root(); + +# This is a simple test to ensure that trailers don't cause extra newlines in files diff --git a/tests/expectations/dep_v2.pyx b/tests/expectations/dep_v2.pyx new file mode 100644 index 0000000..038a566 --- /dev/null +++ b/tests/expectations/dep_v2.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct dep_struct: + uint32_t x; + double y; + + uint32_t get_x(const dep_struct *dep_struct); diff --git a/tests/expectations/dep_v2.tag.pyx b/tests/expectations/dep_v2.tag.pyx new file mode 100644 index 0000000..74d296b --- /dev/null +++ b/tests/expectations/dep_v2.tag.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct dep_struct: + uint32_t x; + double y; + + uint32_t get_x(const dep_struct *dep_struct); diff --git a/tests/expectations/derive_eq.pyx b/tests/expectations/derive_eq.pyx new file mode 100644 index 0000000..0281a8a --- /dev/null +++ b/tests/expectations/derive_eq.pyx @@ -0,0 +1,40 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + bool a; + int32_t b; + + cdef enum: + Baz, + Bazz, + FooNamed, + FooParen, + ctypedef uint8_t Bar_Tag; + + ctypedef struct Bazz_Body: + Bar_Tag tag; + Foo named; + + ctypedef struct FooNamed_Body: + Bar_Tag tag; + int32_t different; + uint32_t fields; + + ctypedef struct FooParen_Body: + Bar_Tag tag; + int32_t _0; + Foo _1; + + ctypedef union Bar: + Bar_Tag tag; + Bazz_Body bazz; + FooNamed_Body foo_named; + FooParen_Body foo_paren; + + Foo root(Bar aBar); diff --git a/tests/expectations/derive_eq.tag.pyx b/tests/expectations/derive_eq.tag.pyx new file mode 100644 index 0000000..10024bb --- /dev/null +++ b/tests/expectations/derive_eq.tag.pyx @@ -0,0 +1,40 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + bool a; + int32_t b; + + cdef enum: + Baz, + Bazz, + FooNamed, + FooParen, + ctypedef uint8_t Bar_Tag; + + cdef struct Bazz_Body: + Bar_Tag tag; + Foo named; + + cdef struct FooNamed_Body: + Bar_Tag tag; + int32_t different; + uint32_t fields; + + cdef struct FooParen_Body: + Bar_Tag tag; + int32_t _0; + Foo _1; + + cdef union Bar: + Bar_Tag tag; + Bazz_Body bazz; + FooNamed_Body foo_named; + FooParen_Body foo_paren; + + Foo root(Bar aBar); diff --git a/tests/expectations/derive_ostream.pyx b/tests/expectations/derive_ostream.pyx new file mode 100644 index 0000000..388ae85 --- /dev/null +++ b/tests/expectations/derive_ostream.pyx @@ -0,0 +1,77 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + X = 2, + Y, + ctypedef uint32_t C; + + ctypedef struct A: + int32_t _0; + + ctypedef struct B: + int32_t x; + float y; + + ctypedef struct D: + uint8_t List; + uintptr_t Of; + B Things; + + cdef enum: + Foo, + Bar, + Baz, + ctypedef uint8_t F_Tag; + + ctypedef struct Foo_Body: + F_Tag tag; + int16_t _0; + + ctypedef struct Bar_Body: + F_Tag tag; + uint8_t x; + int16_t y; + + ctypedef union F: + F_Tag tag; + Foo_Body foo; + Bar_Body bar; + + cdef enum: + Hello, + There, + Everyone, + ctypedef uint8_t H_Tag; + + ctypedef struct Hello_Body: + int16_t _0; + + ctypedef struct There_Body: + uint8_t x; + int16_t y; + + ctypedef struct H: + H_Tag tag; + Hello_Body hello; + There_Body there; + + cdef enum: + ThereAgain, + SomethingElse, + ctypedef uint8_t I_Tag; + + ctypedef struct ThereAgain_Body: + uint8_t x; + int16_t y; + + ctypedef struct I: + I_Tag tag; + ThereAgain_Body there_again; + + void root(A a, B b, C c, D d, F f, H h, I i); diff --git a/tests/expectations/derive_ostream.tag.pyx b/tests/expectations/derive_ostream.tag.pyx new file mode 100644 index 0000000..f81d035 --- /dev/null +++ b/tests/expectations/derive_ostream.tag.pyx @@ -0,0 +1,77 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + X = 2, + Y, + ctypedef uint32_t C; + + cdef struct A: + int32_t _0; + + cdef struct B: + int32_t x; + float y; + + cdef struct D: + uint8_t List; + uintptr_t Of; + B Things; + + cdef enum: + Foo, + Bar, + Baz, + ctypedef uint8_t F_Tag; + + cdef struct Foo_Body: + F_Tag tag; + int16_t _0; + + cdef struct Bar_Body: + F_Tag tag; + uint8_t x; + int16_t y; + + cdef union F: + F_Tag tag; + Foo_Body foo; + Bar_Body bar; + + cdef enum: + Hello, + There, + Everyone, + ctypedef uint8_t H_Tag; + + cdef struct Hello_Body: + int16_t _0; + + cdef struct There_Body: + uint8_t x; + int16_t y; + + cdef struct H: + H_Tag tag; + Hello_Body hello; + There_Body there; + + cdef enum: + ThereAgain, + SomethingElse, + ctypedef uint8_t I_Tag; + + cdef struct ThereAgain_Body: + uint8_t x; + int16_t y; + + cdef struct I: + I_Tag tag; + ThereAgain_Body there_again; + + void root(A a, B b, C c, D d, F f, H h, I i); diff --git a/tests/expectations/destructor_and_copy_ctor.pyx b/tests/expectations/destructor_and_copy_ctor.pyx new file mode 100644 index 0000000..796c6c4 --- /dev/null +++ b/tests/expectations/destructor_and_copy_ctor.pyx @@ -0,0 +1,198 @@ +#define NOINLINE __attribute__((noinline)) +#define NODISCARD [[nodiscard]] + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + A, + B, + ctypedef uint8_t FillRule; + + # This will have a destructor manually implemented via variant_body, and + # similarly a Drop impl in Rust. + ctypedef struct OwnedSlice_u32: + uintptr_t len; + uint32_t *ptr; + + ctypedef struct Polygon_u32: + FillRule fill; + OwnedSlice_u32 coordinates; + + # This will have a destructor manually implemented via variant_body, and + # similarly a Drop impl in Rust. + ctypedef struct OwnedSlice_i32: + uintptr_t len; + int32_t *ptr; + + cdef enum: + Bar_u32, + Polygon1_u32, + Slice1_u32, + Slice2_u32, + Slice3_u32, + Slice4_u32, + ctypedef uint8_t Foo_u32_Tag; + + ctypedef struct Polygon1_Body_u32: + Polygon_u32 _0; + + ctypedef struct Slice1_Body_u32: + OwnedSlice_u32 _0; + + ctypedef struct Slice2_Body_u32: + OwnedSlice_i32 _0; + + ctypedef struct Slice3_Body_u32: + FillRule fill; + OwnedSlice_u32 coords; + + ctypedef struct Slice4_Body_u32: + FillRule fill; + OwnedSlice_i32 coords; + + ctypedef struct Foo_u32: + Foo_u32_Tag tag; + Polygon1_Body_u32 polygon1; + Slice1_Body_u32 slice1; + Slice2_Body_u32 slice2; + Slice3_Body_u32 slice3; + Slice4_Body_u32 slice4; + + ctypedef struct Polygon_i32: + FillRule fill; + OwnedSlice_i32 coordinates; + + cdef enum: + Bar2_i32, + Polygon21_i32, + Slice21_i32, + Slice22_i32, + Slice23_i32, + Slice24_i32, + ctypedef uint8_t Baz_i32_Tag; + + ctypedef struct Polygon21_Body_i32: + Baz_i32_Tag tag; + Polygon_i32 _0; + + ctypedef struct Slice21_Body_i32: + Baz_i32_Tag tag; + OwnedSlice_i32 _0; + + ctypedef struct Slice22_Body_i32: + Baz_i32_Tag tag; + OwnedSlice_i32 _0; + + ctypedef struct Slice23_Body_i32: + Baz_i32_Tag tag; + FillRule fill; + OwnedSlice_i32 coords; + + ctypedef struct Slice24_Body_i32: + Baz_i32_Tag tag; + FillRule fill; + OwnedSlice_i32 coords; + + ctypedef union Baz_i32: + Baz_i32_Tag tag; + Polygon21_Body_i32 polygon21; + Slice21_Body_i32 slice21; + Slice22_Body_i32 slice22; + Slice23_Body_i32 slice23; + Slice24_Body_i32 slice24; + + cdef enum: + Bar3, + Taz1, + Taz3, + ctypedef uint8_t Taz_Tag; + + ctypedef struct Taz1_Body: + Taz_Tag tag; + int32_t _0; + + ctypedef struct Taz3_Body: + Taz_Tag tag; + OwnedSlice_i32 _0; + + ctypedef union Taz: + Taz_Tag tag; + Taz1_Body taz1; + Taz3_Body taz3; + + cdef enum: + Bar4, + Taz2, + ctypedef uint8_t Tazz_Tag; + + ctypedef struct Taz2_Body: + Tazz_Tag tag; + int32_t _0; + + ctypedef union Tazz: + Tazz_Tag tag; + Taz2_Body taz2; + + cdef enum: + Bar5, + Taz5, + ctypedef uint8_t Tazzz_Tag; + + ctypedef struct Taz5_Body: + Tazzz_Tag tag; + int32_t _0; + + ctypedef union Tazzz: + Tazzz_Tag tag; + Taz5_Body taz5; + + cdef enum: + Taz6, + Taz7, + ctypedef uint8_t Tazzzz_Tag; + + ctypedef struct Taz6_Body: + Tazzzz_Tag tag; + int32_t _0; + + ctypedef struct Taz7_Body: + Tazzzz_Tag tag; + uint32_t _0; + + ctypedef union Tazzzz: + Tazzzz_Tag tag; + Taz6_Body taz6; + Taz7_Body taz7; + + cdef enum: + Qux1, + Qux2, + ctypedef uint8_t Qux_Tag; + + ctypedef struct Qux1_Body: + Qux_Tag tag; + int32_t _0; + + ctypedef struct Qux2_Body: + Qux_Tag tag; + uint32_t _0; + + ctypedef union Qux: + Qux_Tag tag; + Qux1_Body qux1; + Qux2_Body qux2; + + void root(const Foo_u32 *a, + const Baz_i32 *b, + const Taz *c, + Tazz d, + const Tazzz *e, + const Tazzzz *f, + const Qux *g); diff --git a/tests/expectations/destructor_and_copy_ctor.tag.pyx b/tests/expectations/destructor_and_copy_ctor.tag.pyx new file mode 100644 index 0000000..dbc1e55 --- /dev/null +++ b/tests/expectations/destructor_and_copy_ctor.tag.pyx @@ -0,0 +1,198 @@ +#define NOINLINE __attribute__((noinline)) +#define NODISCARD [[nodiscard]] + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + A, + B, + ctypedef uint8_t FillRule; + + # This will have a destructor manually implemented via variant_body, and + # similarly a Drop impl in Rust. + cdef struct OwnedSlice_u32: + uintptr_t len; + uint32_t *ptr; + + cdef struct Polygon_u32: + FillRule fill; + OwnedSlice_u32 coordinates; + + # This will have a destructor manually implemented via variant_body, and + # similarly a Drop impl in Rust. + cdef struct OwnedSlice_i32: + uintptr_t len; + int32_t *ptr; + + cdef enum: + Bar_u32, + Polygon1_u32, + Slice1_u32, + Slice2_u32, + Slice3_u32, + Slice4_u32, + ctypedef uint8_t Foo_u32_Tag; + + cdef struct Polygon1_Body_u32: + Polygon_u32 _0; + + cdef struct Slice1_Body_u32: + OwnedSlice_u32 _0; + + cdef struct Slice2_Body_u32: + OwnedSlice_i32 _0; + + cdef struct Slice3_Body_u32: + FillRule fill; + OwnedSlice_u32 coords; + + cdef struct Slice4_Body_u32: + FillRule fill; + OwnedSlice_i32 coords; + + cdef struct Foo_u32: + Foo_u32_Tag tag; + Polygon1_Body_u32 polygon1; + Slice1_Body_u32 slice1; + Slice2_Body_u32 slice2; + Slice3_Body_u32 slice3; + Slice4_Body_u32 slice4; + + cdef struct Polygon_i32: + FillRule fill; + OwnedSlice_i32 coordinates; + + cdef enum: + Bar2_i32, + Polygon21_i32, + Slice21_i32, + Slice22_i32, + Slice23_i32, + Slice24_i32, + ctypedef uint8_t Baz_i32_Tag; + + cdef struct Polygon21_Body_i32: + Baz_i32_Tag tag; + Polygon_i32 _0; + + cdef struct Slice21_Body_i32: + Baz_i32_Tag tag; + OwnedSlice_i32 _0; + + cdef struct Slice22_Body_i32: + Baz_i32_Tag tag; + OwnedSlice_i32 _0; + + cdef struct Slice23_Body_i32: + Baz_i32_Tag tag; + FillRule fill; + OwnedSlice_i32 coords; + + cdef struct Slice24_Body_i32: + Baz_i32_Tag tag; + FillRule fill; + OwnedSlice_i32 coords; + + cdef union Baz_i32: + Baz_i32_Tag tag; + Polygon21_Body_i32 polygon21; + Slice21_Body_i32 slice21; + Slice22_Body_i32 slice22; + Slice23_Body_i32 slice23; + Slice24_Body_i32 slice24; + + cdef enum: + Bar3, + Taz1, + Taz3, + ctypedef uint8_t Taz_Tag; + + cdef struct Taz1_Body: + Taz_Tag tag; + int32_t _0; + + cdef struct Taz3_Body: + Taz_Tag tag; + OwnedSlice_i32 _0; + + cdef union Taz: + Taz_Tag tag; + Taz1_Body taz1; + Taz3_Body taz3; + + cdef enum: + Bar4, + Taz2, + ctypedef uint8_t Tazz_Tag; + + cdef struct Taz2_Body: + Tazz_Tag tag; + int32_t _0; + + cdef union Tazz: + Tazz_Tag tag; + Taz2_Body taz2; + + cdef enum: + Bar5, + Taz5, + ctypedef uint8_t Tazzz_Tag; + + cdef struct Taz5_Body: + Tazzz_Tag tag; + int32_t _0; + + cdef union Tazzz: + Tazzz_Tag tag; + Taz5_Body taz5; + + cdef enum: + Taz6, + Taz7, + ctypedef uint8_t Tazzzz_Tag; + + cdef struct Taz6_Body: + Tazzzz_Tag tag; + int32_t _0; + + cdef struct Taz7_Body: + Tazzzz_Tag tag; + uint32_t _0; + + cdef union Tazzzz: + Tazzzz_Tag tag; + Taz6_Body taz6; + Taz7_Body taz7; + + cdef enum: + Qux1, + Qux2, + ctypedef uint8_t Qux_Tag; + + cdef struct Qux1_Body: + Qux_Tag tag; + int32_t _0; + + cdef struct Qux2_Body: + Qux_Tag tag; + uint32_t _0; + + cdef union Qux: + Qux_Tag tag; + Qux1_Body qux1; + Qux2_Body qux2; + + void root(const Foo_u32 *a, + const Baz_i32 *b, + const Taz *c, + Tazz d, + const Tazzz *e, + const Tazzzz *f, + const Qux *g); diff --git a/tests/expectations/display_list.pyx b/tests/expectations/display_list.pyx new file mode 100644 index 0000000..45d6b05 --- /dev/null +++ b/tests/expectations/display_list.pyx @@ -0,0 +1,42 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Rect: + float x; + float y; + float w; + float h; + + ctypedef struct Color: + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; + + cdef enum: + Fill, + Image, + ClearScreen, + ctypedef uint8_t DisplayItem_Tag; + + ctypedef struct Fill_Body: + DisplayItem_Tag tag; + Rect _0; + Color _1; + + ctypedef struct Image_Body: + DisplayItem_Tag tag; + uint32_t id; + Rect bounds; + + ctypedef union DisplayItem: + DisplayItem_Tag tag; + Fill_Body fill; + Image_Body image; + + bool push_item(DisplayItem item); diff --git a/tests/expectations/display_list.tag.pyx b/tests/expectations/display_list.tag.pyx new file mode 100644 index 0000000..6bf900e --- /dev/null +++ b/tests/expectations/display_list.tag.pyx @@ -0,0 +1,42 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Rect: + float x; + float y; + float w; + float h; + + cdef struct Color: + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; + + cdef enum: + Fill, + Image, + ClearScreen, + ctypedef uint8_t DisplayItem_Tag; + + cdef struct Fill_Body: + DisplayItem_Tag tag; + Rect _0; + Color _1; + + cdef struct Image_Body: + DisplayItem_Tag tag; + uint32_t id; + Rect bounds; + + cdef union DisplayItem: + DisplayItem_Tag tag; + Fill_Body fill; + Image_Body image; + + bool push_item(DisplayItem item); diff --git a/tests/expectations/docstyle_auto.pyx b/tests/expectations/docstyle_auto.pyx new file mode 100644 index 0000000..5268ff4 --- /dev/null +++ b/tests/expectations/docstyle_auto.pyx @@ -0,0 +1,10 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + # The root of all evil. + void root(); diff --git a/tests/expectations/docstyle_c99.pyx b/tests/expectations/docstyle_c99.pyx new file mode 100644 index 0000000..5268ff4 --- /dev/null +++ b/tests/expectations/docstyle_c99.pyx @@ -0,0 +1,10 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + # The root of all evil. + void root(); diff --git a/tests/expectations/docstyle_doxy.pyx b/tests/expectations/docstyle_doxy.pyx new file mode 100644 index 0000000..5268ff4 --- /dev/null +++ b/tests/expectations/docstyle_doxy.pyx @@ -0,0 +1,10 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + # The root of all evil. + void root(); diff --git a/tests/expectations/documentation.pyx b/tests/expectations/documentation.pyx new file mode 100644 index 0000000..340b38a --- /dev/null +++ b/tests/expectations/documentation.pyx @@ -0,0 +1,27 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + # The root of all evil. + # + # But at least it contains some more documentation as someone would expect + # from a simple test case like this. + # + # # Hint + # + # Always ensure that everything is properly documented, even if you feel lazy. + # **Sometimes** it is also helpful to include some markdown formatting. + # + # //////////////////////////////////////////////////////////////////////////// + # + # Attention: + # + # Rust is going to trim all leading `/` symbols. If you want to use them as a + # marker you need to add at least a single whitespace inbetween the tripple + # slash doc-comment marker and the rest. + # + void root(); diff --git a/tests/expectations/documentation_attr.pyx b/tests/expectations/documentation_attr.pyx new file mode 100644 index 0000000..88070eb --- /dev/null +++ b/tests/expectations/documentation_attr.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + #With doc attr, each attr contribute to one line of document + #like this one with a new line character at its end + #and this one as well. So they are in the same paragraph + # + #Line ends with one new line should not break + # + #Line ends with two spaces and a new line + #should break to next line + # + #Line ends with two new lines + # + #Should break to next paragraph + void root(); diff --git a/tests/expectations/enum.pyx b/tests/expectations/enum.pyx new file mode 100644 index 0000000..7b099f7 --- /dev/null +++ b/tests/expectations/enum.pyx @@ -0,0 +1,174 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + a1 = 0, + a2 = 2, + a3, + a4 = 5, + ctypedef uint64_t A; + + cdef enum: + b1 = 0, + b2 = 2, + b3, + b4 = 5, + ctypedef uint32_t B; + + cdef enum: + c1 = 0, + c2 = 2, + c3, + c4 = 5, + ctypedef uint16_t C; + + cdef enum: + d1 = 0, + d2 = 2, + d3, + d4 = 5, + ctypedef uint8_t D; + + cdef enum: + e1 = 0, + e2 = 2, + e3, + e4 = 5, + ctypedef uintptr_t E; + + cdef enum: + f1 = 0, + f2 = 2, + f3, + f4 = 5, + ctypedef intptr_t F; + + ctypedef enum L: + l1, + l2, + l3, + l4, + + cdef enum: + m1 = -1, + m2 = 0, + m3 = 1, + ctypedef int8_t M; + + ctypedef enum N: + n1, + n2, + n3, + n4, + + cdef enum: + o1, + o2, + o3, + o4, + ctypedef int8_t O; + + ctypedef struct J: + pass + + ctypedef struct K: + pass + + ctypedef struct Opaque: + pass + + cdef enum: + Foo, + Bar, + Baz, + ctypedef uint8_t G_Tag; + + ctypedef struct Foo_Body: + G_Tag tag; + int16_t _0; + + ctypedef struct Bar_Body: + G_Tag tag; + uint8_t x; + int16_t y; + + ctypedef union G: + G_Tag tag; + Foo_Body foo; + Bar_Body bar; + + ctypedef enum H_Tag: + H_Foo, + H_Bar, + H_Baz, + + ctypedef struct H_Foo_Body: + int16_t _0; + + ctypedef struct H_Bar_Body: + uint8_t x; + int16_t y; + + ctypedef struct H: + H_Tag tag; + H_Foo_Body foo; + H_Bar_Body bar; + + cdef enum: + I_Foo, + I_Bar, + I_Baz, + ctypedef uint8_t I_Tag; + + ctypedef struct I_Foo_Body: + int16_t _0; + + ctypedef struct I_Bar_Body: + uint8_t x; + int16_t y; + + ctypedef struct I: + I_Tag tag; + I_Foo_Body foo; + I_Bar_Body bar; + + cdef enum: + P0, + P1, + ctypedef uint8_t P_Tag; + + ctypedef struct P0_Body: + uint8_t _0; + + ctypedef struct P1_Body: + uint8_t _0; + uint8_t _1; + uint8_t _2; + + ctypedef struct P: + P_Tag tag; + P0_Body p0; + P1_Body p1; + + void root(Opaque *opaque, + A a, + B b, + C c, + D d, + E e, + F f, + G g, + H h, + I i, + J j, + K k, + L l, + M m, + N n, + O o, + P p); diff --git a/tests/expectations/enum.tag.pyx b/tests/expectations/enum.tag.pyx new file mode 100644 index 0000000..87b24e6 --- /dev/null +++ b/tests/expectations/enum.tag.pyx @@ -0,0 +1,174 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + a1 = 0, + a2 = 2, + a3, + a4 = 5, + ctypedef uint64_t A; + + cdef enum: + b1 = 0, + b2 = 2, + b3, + b4 = 5, + ctypedef uint32_t B; + + cdef enum: + c1 = 0, + c2 = 2, + c3, + c4 = 5, + ctypedef uint16_t C; + + cdef enum: + d1 = 0, + d2 = 2, + d3, + d4 = 5, + ctypedef uint8_t D; + + cdef enum: + e1 = 0, + e2 = 2, + e3, + e4 = 5, + ctypedef uintptr_t E; + + cdef enum: + f1 = 0, + f2 = 2, + f3, + f4 = 5, + ctypedef intptr_t F; + + cdef enum L: + l1, + l2, + l3, + l4, + + cdef enum: + m1 = -1, + m2 = 0, + m3 = 1, + ctypedef int8_t M; + + cdef enum N: + n1, + n2, + n3, + n4, + + cdef enum: + o1, + o2, + o3, + o4, + ctypedef int8_t O; + + cdef struct J: + pass + + cdef struct K: + pass + + cdef struct Opaque: + pass + + cdef enum: + Foo, + Bar, + Baz, + ctypedef uint8_t G_Tag; + + cdef struct Foo_Body: + G_Tag tag; + int16_t _0; + + cdef struct Bar_Body: + G_Tag tag; + uint8_t x; + int16_t y; + + cdef union G: + G_Tag tag; + Foo_Body foo; + Bar_Body bar; + + cdef enum H_Tag: + H_Foo, + H_Bar, + H_Baz, + + cdef struct H_Foo_Body: + int16_t _0; + + cdef struct H_Bar_Body: + uint8_t x; + int16_t y; + + cdef struct H: + H_Tag tag; + H_Foo_Body foo; + H_Bar_Body bar; + + cdef enum: + I_Foo, + I_Bar, + I_Baz, + ctypedef uint8_t I_Tag; + + cdef struct I_Foo_Body: + int16_t _0; + + cdef struct I_Bar_Body: + uint8_t x; + int16_t y; + + cdef struct I: + I_Tag tag; + I_Foo_Body foo; + I_Bar_Body bar; + + cdef enum: + P0, + P1, + ctypedef uint8_t P_Tag; + + cdef struct P0_Body: + uint8_t _0; + + cdef struct P1_Body: + uint8_t _0; + uint8_t _1; + uint8_t _2; + + cdef struct P: + P_Tag tag; + P0_Body p0; + P1_Body p1; + + void root(Opaque *opaque, + A a, + B b, + C c, + D d, + E e, + F f, + G g, + H h, + I i, + J j, + K k, + L l, + M m, + N n, + O o, + P p); diff --git a/tests/expectations/enum_discriminant.c b/tests/expectations/enum_discriminant.c index e313cb6..cbc7aea 100644 --- a/tests/expectations/enum_discriminant.c +++ b/tests/expectations/enum_discriminant.c @@ -11,9 +11,15 @@ enum E { C = (1 + 2), D = FOUR, F = 5, - G = (int8_t)'6', - H = (int8_t)false, }; typedef int8_t E; +enum E_NoCython { + G = (int8_t)'6', + H = (int8_t)false, +}; +typedef int8_t E_NoCython; + void root(const E*); + +void root_no_cython(const E_NoCython*); diff --git a/tests/expectations/enum_discriminant.compat.c b/tests/expectations/enum_discriminant.compat.c index f0803e1..4aea7e0 100644 --- a/tests/expectations/enum_discriminant.compat.c +++ b/tests/expectations/enum_discriminant.compat.c @@ -15,11 +15,21 @@ enum E C = (1 + 2), D = FOUR, F = 5, +}; +#ifndef __cplusplus +typedef int8_t E; +#endif // __cplusplus + +enum E_NoCython +#ifdef __cplusplus + : int8_t +#endif // __cplusplus + { G = (int8_t)'6', H = (int8_t)false, }; #ifndef __cplusplus -typedef int8_t E; +typedef int8_t E_NoCython; #endif // __cplusplus #ifdef __cplusplus @@ -28,6 +38,8 @@ extern "C" { void root(const E*); +void root_no_cython(const E_NoCython*); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/tests/expectations/enum_discriminant.cpp b/tests/expectations/enum_discriminant.cpp index 729d585..1d17ace 100644 --- a/tests/expectations/enum_discriminant.cpp +++ b/tests/expectations/enum_discriminant.cpp @@ -12,6 +12,9 @@ enum class E : int8_t { C = (1 + 2), D = FOUR, F = 5, +}; + +enum class E_NoCython : int8_t { G = (int8_t)'6', H = (int8_t)false, }; @@ -20,4 +23,6 @@ extern "C" { void root(const E*); +void root_no_cython(const E_NoCython*); + } // extern "C" diff --git a/tests/expectations/enum_discriminant.pyx b/tests/expectations/enum_discriminant.pyx new file mode 100644 index 0000000..8f475d9 --- /dev/null +++ b/tests/expectations/enum_discriminant.pyx @@ -0,0 +1,19 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int8_t FOUR = 4; + + cdef enum: + A = 1, + B = -1, + C = (1 + 2), + D = FOUR, + F = 5, + ctypedef int8_t E; + + void root(const E*); diff --git a/tests/expectations/enum_self.pyx b/tests/expectations/enum_self.pyx new file mode 100644 index 0000000..f3e67f0 --- /dev/null +++ b/tests/expectations/enum_self.pyx @@ -0,0 +1,31 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo_Bar: + const int32_t *something; + + cdef enum: + Min, + Max, + Other, + ctypedef uint8_t Bar_Tag; + + ctypedef struct Min_Body: + Bar_Tag tag; + Foo_Bar _0; + + ctypedef struct Max_Body: + Bar_Tag tag; + Foo_Bar _0; + + ctypedef union Bar: + Bar_Tag tag; + Min_Body min; + Max_Body max; + + void root(Bar b); diff --git a/tests/expectations/enum_self.tag.pyx b/tests/expectations/enum_self.tag.pyx new file mode 100644 index 0000000..565586c --- /dev/null +++ b/tests/expectations/enum_self.tag.pyx @@ -0,0 +1,31 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo_Bar: + const int32_t *something; + + cdef enum: + Min, + Max, + Other, + ctypedef uint8_t Bar_Tag; + + cdef struct Min_Body: + Bar_Tag tag; + Foo_Bar _0; + + cdef struct Max_Body: + Bar_Tag tag; + Foo_Bar _0; + + cdef union Bar: + Bar_Tag tag; + Min_Body min; + Max_Body max; + + void root(Bar b); diff --git a/tests/expectations/euclid.pyx b/tests/expectations/euclid.pyx new file mode 100644 index 0000000..6448584 --- /dev/null +++ b/tests/expectations/euclid.pyx @@ -0,0 +1,108 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct TypedLength_f32__UnknownUnit: + float _0; + + ctypedef struct TypedLength_f32__LayoutUnit: + float _0; + + ctypedef TypedLength_f32__UnknownUnit Length_f32; + + ctypedef TypedLength_f32__LayoutUnit LayoutLength; + + ctypedef struct TypedSideOffsets2D_f32__UnknownUnit: + float top; + float right; + float bottom; + float left; + + ctypedef struct TypedSideOffsets2D_f32__LayoutUnit: + float top; + float right; + float bottom; + float left; + + ctypedef TypedSideOffsets2D_f32__UnknownUnit SideOffsets2D_f32; + + ctypedef TypedSideOffsets2D_f32__LayoutUnit LayoutSideOffsets2D; + + ctypedef struct TypedSize2D_f32__UnknownUnit: + float width; + float height; + + ctypedef struct TypedSize2D_f32__LayoutUnit: + float width; + float height; + + ctypedef TypedSize2D_f32__UnknownUnit Size2D_f32; + + ctypedef TypedSize2D_f32__LayoutUnit LayoutSize2D; + + ctypedef struct TypedPoint2D_f32__UnknownUnit: + float x; + float y; + + ctypedef struct TypedPoint2D_f32__LayoutUnit: + float x; + float y; + + ctypedef TypedPoint2D_f32__UnknownUnit Point2D_f32; + + ctypedef TypedPoint2D_f32__LayoutUnit LayoutPoint2D; + + ctypedef struct TypedRect_f32__UnknownUnit: + TypedPoint2D_f32__UnknownUnit origin; + TypedSize2D_f32__UnknownUnit size; + + ctypedef struct TypedRect_f32__LayoutUnit: + TypedPoint2D_f32__LayoutUnit origin; + TypedSize2D_f32__LayoutUnit size; + + ctypedef TypedRect_f32__UnknownUnit Rect_f32; + + ctypedef TypedRect_f32__LayoutUnit LayoutRect; + + ctypedef struct TypedTransform2D_f32__UnknownUnit__LayoutUnit: + float m11; + float m12; + float m21; + float m22; + float m31; + float m32; + + ctypedef struct TypedTransform2D_f32__LayoutUnit__UnknownUnit: + float m11; + float m12; + float m21; + float m22; + float m31; + float m32; + + void root(TypedLength_f32__UnknownUnit length_a, + TypedLength_f32__LayoutUnit length_b, + Length_f32 length_c, + LayoutLength length_d, + TypedSideOffsets2D_f32__UnknownUnit side_offsets_a, + TypedSideOffsets2D_f32__LayoutUnit side_offsets_b, + SideOffsets2D_f32 side_offsets_c, + LayoutSideOffsets2D side_offsets_d, + TypedSize2D_f32__UnknownUnit size_a, + TypedSize2D_f32__LayoutUnit size_b, + Size2D_f32 size_c, + LayoutSize2D size_d, + TypedPoint2D_f32__UnknownUnit point_a, + TypedPoint2D_f32__LayoutUnit point_b, + Point2D_f32 point_c, + LayoutPoint2D point_d, + TypedRect_f32__UnknownUnit rect_a, + TypedRect_f32__LayoutUnit rect_b, + Rect_f32 rect_c, + LayoutRect rect_d, + TypedTransform2D_f32__UnknownUnit__LayoutUnit transform_a, + TypedTransform2D_f32__LayoutUnit__UnknownUnit transform_b); diff --git a/tests/expectations/euclid.tag.pyx b/tests/expectations/euclid.tag.pyx new file mode 100644 index 0000000..ed420a4 --- /dev/null +++ b/tests/expectations/euclid.tag.pyx @@ -0,0 +1,108 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct TypedLength_f32__UnknownUnit: + float _0; + + cdef struct TypedLength_f32__LayoutUnit: + float _0; + + ctypedef TypedLength_f32__UnknownUnit Length_f32; + + ctypedef TypedLength_f32__LayoutUnit LayoutLength; + + cdef struct TypedSideOffsets2D_f32__UnknownUnit: + float top; + float right; + float bottom; + float left; + + cdef struct TypedSideOffsets2D_f32__LayoutUnit: + float top; + float right; + float bottom; + float left; + + ctypedef TypedSideOffsets2D_f32__UnknownUnit SideOffsets2D_f32; + + ctypedef TypedSideOffsets2D_f32__LayoutUnit LayoutSideOffsets2D; + + cdef struct TypedSize2D_f32__UnknownUnit: + float width; + float height; + + cdef struct TypedSize2D_f32__LayoutUnit: + float width; + float height; + + ctypedef TypedSize2D_f32__UnknownUnit Size2D_f32; + + ctypedef TypedSize2D_f32__LayoutUnit LayoutSize2D; + + cdef struct TypedPoint2D_f32__UnknownUnit: + float x; + float y; + + cdef struct TypedPoint2D_f32__LayoutUnit: + float x; + float y; + + ctypedef TypedPoint2D_f32__UnknownUnit Point2D_f32; + + ctypedef TypedPoint2D_f32__LayoutUnit LayoutPoint2D; + + cdef struct TypedRect_f32__UnknownUnit: + TypedPoint2D_f32__UnknownUnit origin; + TypedSize2D_f32__UnknownUnit size; + + cdef struct TypedRect_f32__LayoutUnit: + TypedPoint2D_f32__LayoutUnit origin; + TypedSize2D_f32__LayoutUnit size; + + ctypedef TypedRect_f32__UnknownUnit Rect_f32; + + ctypedef TypedRect_f32__LayoutUnit LayoutRect; + + cdef struct TypedTransform2D_f32__UnknownUnit__LayoutUnit: + float m11; + float m12; + float m21; + float m22; + float m31; + float m32; + + cdef struct TypedTransform2D_f32__LayoutUnit__UnknownUnit: + float m11; + float m12; + float m21; + float m22; + float m31; + float m32; + + void root(TypedLength_f32__UnknownUnit length_a, + TypedLength_f32__LayoutUnit length_b, + Length_f32 length_c, + LayoutLength length_d, + TypedSideOffsets2D_f32__UnknownUnit side_offsets_a, + TypedSideOffsets2D_f32__LayoutUnit side_offsets_b, + SideOffsets2D_f32 side_offsets_c, + LayoutSideOffsets2D side_offsets_d, + TypedSize2D_f32__UnknownUnit size_a, + TypedSize2D_f32__LayoutUnit size_b, + Size2D_f32 size_c, + LayoutSize2D size_d, + TypedPoint2D_f32__UnknownUnit point_a, + TypedPoint2D_f32__LayoutUnit point_b, + Point2D_f32 point_c, + LayoutPoint2D point_d, + TypedRect_f32__UnknownUnit rect_a, + TypedRect_f32__LayoutUnit rect_b, + Rect_f32 rect_c, + LayoutRect rect_d, + TypedTransform2D_f32__UnknownUnit__LayoutUnit transform_a, + TypedTransform2D_f32__LayoutUnit__UnknownUnit transform_b); diff --git a/tests/expectations/exclude_generic_monomorph.pyx b/tests/expectations/exclude_generic_monomorph.pyx new file mode 100644 index 0000000..2b4faba --- /dev/null +++ b/tests/expectations/exclude_generic_monomorph.pyx @@ -0,0 +1,16 @@ +from libc.stdint cimport uint64_t +ctypedef uint64_t Option_Foo + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Bar: + Option_Foo foo; + + void root(Bar f); diff --git a/tests/expectations/exclude_generic_monomorph.tag.pyx b/tests/expectations/exclude_generic_monomorph.tag.pyx new file mode 100644 index 0000000..d0b3aeb --- /dev/null +++ b/tests/expectations/exclude_generic_monomorph.tag.pyx @@ -0,0 +1,16 @@ +from libc.stdint cimport uint64_t +ctypedef uint64_t Option_Foo + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Bar: + Option_Foo foo; + + void root(Bar f); diff --git a/tests/expectations/expand.pyx b/tests/expectations/expand.pyx new file mode 100644 index 0000000..9543018 --- /dev/null +++ b/tests/expectations/expand.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + pass + + void root(Foo a); diff --git a/tests/expectations/expand.tag.pyx b/tests/expectations/expand.tag.pyx new file mode 100644 index 0000000..977a424 --- /dev/null +++ b/tests/expectations/expand.tag.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + pass + + void root(Foo a); diff --git a/tests/expectations/expand_default_features.pyx b/tests/expectations/expand_default_features.pyx new file mode 100644 index 0000000..e7c0dbb --- /dev/null +++ b/tests/expectations/expand_default_features.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + pass + + void extra_debug_fn(); + + void root(Foo a); diff --git a/tests/expectations/expand_default_features.tag.pyx b/tests/expectations/expand_default_features.tag.pyx new file mode 100644 index 0000000..0699dbc --- /dev/null +++ b/tests/expectations/expand_default_features.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + pass + + void extra_debug_fn(); + + void root(Foo a); diff --git a/tests/expectations/expand_dep.pyx b/tests/expectations/expand_dep.pyx new file mode 100644 index 0000000..038a566 --- /dev/null +++ b/tests/expectations/expand_dep.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct dep_struct: + uint32_t x; + double y; + + uint32_t get_x(const dep_struct *dep_struct); diff --git a/tests/expectations/expand_dep.tag.pyx b/tests/expectations/expand_dep.tag.pyx new file mode 100644 index 0000000..74d296b --- /dev/null +++ b/tests/expectations/expand_dep.tag.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct dep_struct: + uint32_t x; + double y; + + uint32_t get_x(const dep_struct *dep_struct); diff --git a/tests/expectations/expand_dep_v2.pyx b/tests/expectations/expand_dep_v2.pyx new file mode 100644 index 0000000..038a566 --- /dev/null +++ b/tests/expectations/expand_dep_v2.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct dep_struct: + uint32_t x; + double y; + + uint32_t get_x(const dep_struct *dep_struct); diff --git a/tests/expectations/expand_dep_v2.tag.pyx b/tests/expectations/expand_dep_v2.tag.pyx new file mode 100644 index 0000000..74d296b --- /dev/null +++ b/tests/expectations/expand_dep_v2.tag.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct dep_struct: + uint32_t x; + double y; + + uint32_t get_x(const dep_struct *dep_struct); diff --git a/tests/expectations/expand_features.pyx b/tests/expectations/expand_features.pyx new file mode 100644 index 0000000..e04531c --- /dev/null +++ b/tests/expectations/expand_features.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + pass + + void extra_debug_fn(); + + void cbindgen(); + + void root(Foo a); diff --git a/tests/expectations/expand_features.tag.pyx b/tests/expectations/expand_features.tag.pyx new file mode 100644 index 0000000..e1adc67 --- /dev/null +++ b/tests/expectations/expand_features.tag.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + pass + + void extra_debug_fn(); + + void cbindgen(); + + void root(Foo a); diff --git a/tests/expectations/expand_no_default_features.pyx b/tests/expectations/expand_no_default_features.pyx new file mode 100644 index 0000000..9543018 --- /dev/null +++ b/tests/expectations/expand_no_default_features.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + pass + + void root(Foo a); diff --git a/tests/expectations/expand_no_default_features.tag.pyx b/tests/expectations/expand_no_default_features.tag.pyx new file mode 100644 index 0000000..977a424 --- /dev/null +++ b/tests/expectations/expand_no_default_features.tag.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + pass + + void root(Foo a); diff --git a/tests/expectations/export_name.pyx b/tests/expectations/export_name.pyx new file mode 100644 index 0000000..5fb9644 --- /dev/null +++ b/tests/expectations/export_name.pyx @@ -0,0 +1,9 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void do_the_thing_with_export_name(); diff --git a/tests/expectations/extern.pyx b/tests/expectations/extern.pyx new file mode 100644 index 0000000..dca17ac --- /dev/null +++ b/tests/expectations/extern.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Normal: + int32_t x; + float y; + + extern int32_t foo(); + + extern void bar(Normal a); diff --git a/tests/expectations/extern.tag.pyx b/tests/expectations/extern.tag.pyx new file mode 100644 index 0000000..9cb7214 --- /dev/null +++ b/tests/expectations/extern.tag.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Normal: + int32_t x; + float y; + + extern int32_t foo(); + + extern void bar(Normal a); diff --git a/tests/expectations/extern_2.pyx b/tests/expectations/extern_2.pyx new file mode 100644 index 0000000..bea4ede --- /dev/null +++ b/tests/expectations/extern_2.pyx @@ -0,0 +1,11 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void first(); + + void second(); diff --git a/tests/expectations/external_workspace_child.pyx b/tests/expectations/external_workspace_child.pyx new file mode 100644 index 0000000..d42b68a --- /dev/null +++ b/tests/expectations/external_workspace_child.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct ExtType: + uint32_t data; + + void consume_ext(ExtType _ext); diff --git a/tests/expectations/external_workspace_child.tag.pyx b/tests/expectations/external_workspace_child.tag.pyx new file mode 100644 index 0000000..6850ae3 --- /dev/null +++ b/tests/expectations/external_workspace_child.tag.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct ExtType: + uint32_t data; + + void consume_ext(ExtType _ext); diff --git a/tests/expectations/fns.pyx b/tests/expectations/fns.pyx new file mode 100644 index 0000000..5caad22 --- /dev/null +++ b/tests/expectations/fns.pyx @@ -0,0 +1,18 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Fns: + void (*noArgs)(); + void (*anonymousArg)(int32_t); + int32_t (*returnsNumber)(); + int8_t (*namedArgs)(int32_t first, int16_t snd); + int8_t (*namedArgsWildcards)(int32_t _, int16_t named, int64_t _1); + + void root(Fns _fns); + + void no_return(); diff --git a/tests/expectations/fns.tag.pyx b/tests/expectations/fns.tag.pyx new file mode 100644 index 0000000..127da71 --- /dev/null +++ b/tests/expectations/fns.tag.pyx @@ -0,0 +1,18 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Fns: + void (*noArgs)(); + void (*anonymousArg)(int32_t); + int32_t (*returnsNumber)(); + int8_t (*namedArgs)(int32_t first, int16_t snd); + int8_t (*namedArgsWildcards)(int32_t _, int16_t named, int64_t _1); + + void root(Fns _fns); + + void no_return(); diff --git a/tests/expectations/function_args.pyx b/tests/expectations/function_args.pyx new file mode 100644 index 0000000..498360c --- /dev/null +++ b/tests/expectations/function_args.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void unnamed(const uint64_t*); + + void pointer_test(const uint64_t *a); + + void print_from_rust(); diff --git a/tests/expectations/function_noreturn.pyx b/tests/expectations/function_noreturn.pyx new file mode 100644 index 0000000..1af76c5 --- /dev/null +++ b/tests/expectations/function_noreturn.pyx @@ -0,0 +1,19 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list +#ifndef NO_RETURN_ATTR + #ifdef __GNUC__ + #define NO_RETURN_ATTR __attribute__ ((noreturn)) + #else // __GNUC__ + #define NO_RETURN_ATTR + #endif // __GNUC__ +#endif // NO_RETURN_ATTR + + +cdef extern from *: + + void loop_forever(); + + uint8_t normal_return(); diff --git a/tests/expectations/function_sort_name.pyx b/tests/expectations/function_sort_name.pyx new file mode 100644 index 0000000..bda8fc6 --- /dev/null +++ b/tests/expectations/function_sort_name.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void A(); + + void B(); + + void C(); + + void D(); diff --git a/tests/expectations/function_sort_none.pyx b/tests/expectations/function_sort_none.pyx new file mode 100644 index 0000000..d716783 --- /dev/null +++ b/tests/expectations/function_sort_none.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void C(); + + void B(); + + void D(); + + void A(); diff --git a/tests/expectations/generic_pointer.pyx b/tests/expectations/generic_pointer.pyx new file mode 100644 index 0000000..4d4e36b --- /dev/null +++ b/tests/expectations/generic_pointer.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo_____u8: + uint8_t *a; + + ctypedef Foo_____u8 Boo; + + void root(Boo x); diff --git a/tests/expectations/generic_pointer.tag.pyx b/tests/expectations/generic_pointer.tag.pyx new file mode 100644 index 0000000..0f541a1 --- /dev/null +++ b/tests/expectations/generic_pointer.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo_____u8: + uint8_t *a; + + ctypedef Foo_____u8 Boo; + + void root(Boo x); diff --git a/tests/expectations/global_attr.pyx b/tests/expectations/global_attr.pyx new file mode 100644 index 0000000..c82ecc5 --- /dev/null +++ b/tests/expectations/global_attr.pyx @@ -0,0 +1,8 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + pass \ No newline at end of file diff --git a/tests/expectations/global_variable.pyx b/tests/expectations/global_variable.pyx new file mode 100644 index 0000000..2966886 --- /dev/null +++ b/tests/expectations/global_variable.pyx @@ -0,0 +1,11 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + extern char MUT_GLOBAL_ARRAY[128]; + + extern const char CONST_GLOBAL_ARRAY[128]; diff --git a/tests/expectations/ignore.pyx b/tests/expectations/ignore.pyx new file mode 100644 index 0000000..97162bd --- /dev/null +++ b/tests/expectations/ignore.pyx @@ -0,0 +1,9 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void no_ignore_root(); diff --git a/tests/expectations/include.pyx b/tests/expectations/include.pyx new file mode 100644 index 0000000..c82ecc5 --- /dev/null +++ b/tests/expectations/include.pyx @@ -0,0 +1,8 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + pass \ No newline at end of file diff --git a/tests/expectations/include_guard.pyx b/tests/expectations/include_guard.pyx new file mode 100644 index 0000000..d5f4496 --- /dev/null +++ b/tests/expectations/include_guard.pyx @@ -0,0 +1,4 @@ + +cdef extern from *: + + void root(); diff --git a/tests/expectations/include_item.pyx b/tests/expectations/include_item.pyx new file mode 100644 index 0000000..b242c5c --- /dev/null +++ b/tests/expectations/include_item.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct A: + int32_t x; + float y; + + ctypedef struct B: + A data; diff --git a/tests/expectations/include_item.tag.pyx b/tests/expectations/include_item.tag.pyx new file mode 100644 index 0000000..47a81c6 --- /dev/null +++ b/tests/expectations/include_item.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct A: + int32_t x; + float y; + + cdef struct B: + A data; diff --git a/tests/expectations/include_specific.pyx b/tests/expectations/include_specific.pyx new file mode 100644 index 0000000..fac918e --- /dev/null +++ b/tests/expectations/include_specific.pyx @@ -0,0 +1,3 @@ + +cdef extern from *: + pass \ No newline at end of file diff --git a/tests/expectations/inner_mod.pyx b/tests/expectations/inner_mod.pyx new file mode 100644 index 0000000..d287a70 --- /dev/null +++ b/tests/expectations/inner_mod.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + float x; + + void root(Foo a); diff --git a/tests/expectations/inner_mod.tag.pyx b/tests/expectations/inner_mod.tag.pyx new file mode 100644 index 0000000..05ef846 --- /dev/null +++ b/tests/expectations/inner_mod.tag.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + float x; + + void root(Foo a); diff --git a/tests/expectations/item_types.pyx b/tests/expectations/item_types.pyx new file mode 100644 index 0000000..740710c --- /dev/null +++ b/tests/expectations/item_types.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + Foo, + Bar, + ctypedef uint8_t OnlyThisShouldBeGenerated; diff --git a/tests/expectations/item_types_renamed.pyx b/tests/expectations/item_types_renamed.pyx new file mode 100644 index 0000000..c922a7f --- /dev/null +++ b/tests/expectations/item_types_renamed.pyx @@ -0,0 +1,12 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + Foo, + Bar, + ctypedef uint8_t StyleOnlyThisShouldBeGenerated; diff --git a/tests/expectations/layout.pyx b/tests/expectations/layout.pyx new file mode 100644 index 0000000..f5ec67f --- /dev/null +++ b/tests/expectations/layout.pyx @@ -0,0 +1,72 @@ +#define CBINDGEN_PACKED __attribute__ ((packed)) +#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n))) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct RustAlign4Struct: + pass + + ctypedef struct RustAlign4Union: + pass + + ctypedef struct RustPackedStruct: + pass + + ctypedef struct RustPackedUnion: + pass + + ctypedef struct UnsupportedAlign4Enum: + pass + + ctypedef struct UnsupportedPacked4Struct: + pass + + ctypedef struct UnsupportedPacked4Union: + pass + + ctypedef struct Align1Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef struct Align2Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef struct Align4Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef struct Align8Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef struct Align32Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef packed struct PackedStruct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef union Align1Union: + uintptr_t variant1; + uint8_t *variant2; + + ctypedef union Align4Union: + uintptr_t variant1; + uint8_t *variant2; + + ctypedef union Align16Union: + uintptr_t variant1; + uint8_t *variant2; + + ctypedef union PackedUnion: + uintptr_t variant1; + uint8_t *variant2; diff --git a/tests/expectations/layout.tag.pyx b/tests/expectations/layout.tag.pyx new file mode 100644 index 0000000..c16711e --- /dev/null +++ b/tests/expectations/layout.tag.pyx @@ -0,0 +1,72 @@ +#define CBINDGEN_PACKED __attribute__ ((packed)) +#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n))) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct RustAlign4Struct: + pass + + cdef struct RustAlign4Union: + pass + + cdef struct RustPackedStruct: + pass + + cdef struct RustPackedUnion: + pass + + cdef struct UnsupportedAlign4Enum: + pass + + cdef struct UnsupportedPacked4Struct: + pass + + cdef struct UnsupportedPacked4Union: + pass + + cdef struct Align1Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef struct Align2Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef struct Align4Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef struct Align8Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef struct Align32Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef packed struct PackedStruct: + uintptr_t arg1; + uint8_t *arg2; + + cdef union Align1Union: + uintptr_t variant1; + uint8_t *variant2; + + cdef union Align4Union: + uintptr_t variant1; + uint8_t *variant2; + + cdef union Align16Union: + uintptr_t variant1; + uint8_t *variant2; + + cdef union PackedUnion: + uintptr_t variant1; + uint8_t *variant2; diff --git a/tests/expectations/layout_aligned_opaque.pyx b/tests/expectations/layout_aligned_opaque.pyx new file mode 100644 index 0000000..8c3f6ee --- /dev/null +++ b/tests/expectations/layout_aligned_opaque.pyx @@ -0,0 +1,43 @@ +#define CBINDGEN_PACKED __attribute__ ((packed)) +#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n))) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct OpaqueAlign16Union: + pass + + ctypedef struct OpaqueAlign1Struct: + pass + + ctypedef struct OpaqueAlign1Union: + pass + + ctypedef struct OpaqueAlign2Struct: + pass + + ctypedef struct OpaqueAlign32Struct: + pass + + ctypedef struct OpaqueAlign4Struct: + pass + + ctypedef struct OpaqueAlign4Union: + pass + + ctypedef struct OpaqueAlign8Struct: + pass + + ctypedef packed struct PackedStruct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef union PackedUnion: + uintptr_t variant1; + uint8_t *variant2; diff --git a/tests/expectations/layout_aligned_opaque.tag.pyx b/tests/expectations/layout_aligned_opaque.tag.pyx new file mode 100644 index 0000000..a5515a0 --- /dev/null +++ b/tests/expectations/layout_aligned_opaque.tag.pyx @@ -0,0 +1,43 @@ +#define CBINDGEN_PACKED __attribute__ ((packed)) +#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n))) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct OpaqueAlign16Union: + pass + + cdef struct OpaqueAlign1Struct: + pass + + cdef struct OpaqueAlign1Union: + pass + + cdef struct OpaqueAlign2Struct: + pass + + cdef struct OpaqueAlign32Struct: + pass + + cdef struct OpaqueAlign4Struct: + pass + + cdef struct OpaqueAlign4Union: + pass + + cdef struct OpaqueAlign8Struct: + pass + + cdef packed struct PackedStruct: + uintptr_t arg1; + uint8_t *arg2; + + cdef union PackedUnion: + uintptr_t variant1; + uint8_t *variant2; diff --git a/tests/expectations/layout_packed_opaque.pyx b/tests/expectations/layout_packed_opaque.pyx new file mode 100644 index 0000000..5b84f93 --- /dev/null +++ b/tests/expectations/layout_packed_opaque.pyx @@ -0,0 +1,49 @@ +#define CBINDGEN_PACKED __attribute__ ((packed)) +#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n))) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct OpaquePackedStruct: + pass + + ctypedef struct OpaquePackedUnion: + pass + + ctypedef union Align1Union: + uintptr_t variant1; + uint8_t *variant2; + + ctypedef union Align4Union: + uintptr_t variant1; + uint8_t *variant2; + + ctypedef union Align16Union: + uintptr_t variant1; + uint8_t *variant2; + + ctypedef struct Align1Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef struct Align2Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef struct Align4Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef struct Align8Struct: + uintptr_t arg1; + uint8_t *arg2; + + ctypedef struct Align32Struct: + uintptr_t arg1; + uint8_t *arg2; diff --git a/tests/expectations/layout_packed_opaque.tag.pyx b/tests/expectations/layout_packed_opaque.tag.pyx new file mode 100644 index 0000000..548b112 --- /dev/null +++ b/tests/expectations/layout_packed_opaque.tag.pyx @@ -0,0 +1,49 @@ +#define CBINDGEN_PACKED __attribute__ ((packed)) +#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n))) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct OpaquePackedStruct: + pass + + cdef struct OpaquePackedUnion: + pass + + cdef union Align1Union: + uintptr_t variant1; + uint8_t *variant2; + + cdef union Align4Union: + uintptr_t variant1; + uint8_t *variant2; + + cdef union Align16Union: + uintptr_t variant1; + uint8_t *variant2; + + cdef struct Align1Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef struct Align2Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef struct Align4Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef struct Align8Struct: + uintptr_t arg1; + uint8_t *arg2; + + cdef struct Align32Struct: + uintptr_t arg1; + uint8_t *arg2; diff --git a/tests/expectations/lifetime_arg.pyx b/tests/expectations/lifetime_arg.pyx new file mode 100644 index 0000000..abb3dfc --- /dev/null +++ b/tests/expectations/lifetime_arg.pyx @@ -0,0 +1,23 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct A: + const int32_t *data; + + ctypedef enum E_Tag: + V, + U, + + ctypedef struct U_Body: + const uint8_t *_0; + + ctypedef struct E: + E_Tag tag; + U_Body u; + + void root(A _a, E _e); diff --git a/tests/expectations/lifetime_arg.tag.pyx b/tests/expectations/lifetime_arg.tag.pyx new file mode 100644 index 0000000..4836075 --- /dev/null +++ b/tests/expectations/lifetime_arg.tag.pyx @@ -0,0 +1,23 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct A: + const int32_t *data; + + cdef enum E_Tag: + V, + U, + + cdef struct U_Body: + const uint8_t *_0; + + cdef struct E: + E_Tag tag; + U_Body u; + + void root(A _a, E _e); diff --git a/tests/expectations/linestyle_cr.pyx b/tests/expectations/linestyle_cr.pyx new file mode 100644 index 0000000..945bc0e --- /dev/null +++ b/tests/expectations/linestyle_cr.pyx @@ -0,0 +1 @@ +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 *: ctypedef bint bool ctypedef struct va_list cdef extern from *: ctypedef struct Dummy: int32_t x; float y; void root(Dummy d); \ No newline at end of file diff --git a/tests/expectations/linestyle_cr.tag.pyx b/tests/expectations/linestyle_cr.tag.pyx new file mode 100644 index 0000000..4918d64 --- /dev/null +++ b/tests/expectations/linestyle_cr.tag.pyx @@ -0,0 +1 @@ +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 *: ctypedef bint bool ctypedef struct va_list cdef extern from *: cdef struct Dummy: int32_t x; float y; void root(Dummy d); \ No newline at end of file diff --git a/tests/expectations/linestyle_crlf.pyx b/tests/expectations/linestyle_crlf.pyx new file mode 100644 index 0000000..830158e --- /dev/null +++ b/tests/expectations/linestyle_crlf.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Dummy: + int32_t x; + float y; + + void root(Dummy d); diff --git a/tests/expectations/linestyle_crlf.tag.pyx b/tests/expectations/linestyle_crlf.tag.pyx new file mode 100644 index 0000000..60cc864 --- /dev/null +++ b/tests/expectations/linestyle_crlf.tag.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Dummy: + int32_t x; + float y; + + void root(Dummy d); diff --git a/tests/expectations/linestyle_lf.pyx b/tests/expectations/linestyle_lf.pyx new file mode 100644 index 0000000..9a2a90e --- /dev/null +++ b/tests/expectations/linestyle_lf.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Dummy: + int32_t x; + float y; + + void root(Dummy d); diff --git a/tests/expectations/linestyle_lf.tag.pyx b/tests/expectations/linestyle_lf.tag.pyx new file mode 100644 index 0000000..afb0b5d --- /dev/null +++ b/tests/expectations/linestyle_lf.tag.pyx @@ -0,0 +1,13 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Dummy: + int32_t x; + float y; + + void root(Dummy d); diff --git a/tests/expectations/literal_target.pyx b/tests/expectations/literal_target.pyx new file mode 100644 index 0000000..c82ecc5 --- /dev/null +++ b/tests/expectations/literal_target.pyx @@ -0,0 +1,8 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + pass \ No newline at end of file diff --git a/tests/expectations/mangle.pyx b/tests/expectations/mangle.pyx new file mode 100644 index 0000000..7422359 --- /dev/null +++ b/tests/expectations/mangle.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct FooU8: + uint8_t a; + + ctypedef FooU8 Boo; + + void root(Boo x); diff --git a/tests/expectations/mangle.tag.pyx b/tests/expectations/mangle.tag.pyx new file mode 100644 index 0000000..d362ca8 --- /dev/null +++ b/tests/expectations/mangle.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct FooU8: + uint8_t a; + + ctypedef FooU8 Boo; + + void root(Boo x); diff --git a/tests/expectations/manuallydrop.pyx b/tests/expectations/manuallydrop.pyx new file mode 100644 index 0000000..423bdc7 --- /dev/null +++ b/tests/expectations/manuallydrop.pyx @@ -0,0 +1,23 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct NotReprC_ManuallyDrop_Point: + pass + + ctypedef NotReprC_ManuallyDrop_Point Foo; + + ctypedef struct Point: + int32_t x; + int32_t y; + + ctypedef struct MyStruct: + Point point; + + void root(const Foo *a, const MyStruct *with_manual_drop); + + void take(Point with_manual_drop); diff --git a/tests/expectations/manuallydrop.tag.pyx b/tests/expectations/manuallydrop.tag.pyx new file mode 100644 index 0000000..e326533 --- /dev/null +++ b/tests/expectations/manuallydrop.tag.pyx @@ -0,0 +1,23 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct NotReprC_ManuallyDrop_Point: + pass + + ctypedef NotReprC_ManuallyDrop_Point Foo; + + cdef struct Point: + int32_t x; + int32_t y; + + cdef struct MyStruct: + Point point; + + void root(const Foo *a, const MyStruct *with_manual_drop); + + void take(Point with_manual_drop); diff --git a/tests/expectations/maybeuninit.pyx b/tests/expectations/maybeuninit.pyx new file mode 100644 index 0000000..6914dd5 --- /dev/null +++ b/tests/expectations/maybeuninit.pyx @@ -0,0 +1,17 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct NotReprC_MaybeUninit______i32: + pass + + ctypedef NotReprC_MaybeUninit______i32 Foo; + + ctypedef struct MyStruct: + const int32_t *number; + + void root(const Foo *a, const MyStruct *with_maybe_uninit); diff --git a/tests/expectations/maybeuninit.tag.pyx b/tests/expectations/maybeuninit.tag.pyx new file mode 100644 index 0000000..0a2dae4 --- /dev/null +++ b/tests/expectations/maybeuninit.tag.pyx @@ -0,0 +1,17 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct NotReprC_MaybeUninit______i32: + pass + + ctypedef NotReprC_MaybeUninit______i32 Foo; + + cdef struct MyStruct: + const int32_t *number; + + void root(const Foo *a, const MyStruct *with_maybe_uninit); diff --git a/tests/expectations/mod_2015.pyx b/tests/expectations/mod_2015.pyx new file mode 100644 index 0000000..d6740fb --- /dev/null +++ b/tests/expectations/mod_2015.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint8_t EXPORT_ME_TOO = 42; + + ctypedef struct ExportMe: + uint64_t val; + + void export_me(ExportMe *val); diff --git a/tests/expectations/mod_2015.tag.pyx b/tests/expectations/mod_2015.tag.pyx new file mode 100644 index 0000000..a0777cc --- /dev/null +++ b/tests/expectations/mod_2015.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint8_t EXPORT_ME_TOO = 42; + + cdef struct ExportMe: + uint64_t val; + + void export_me(ExportMe *val); diff --git a/tests/expectations/mod_2018.pyx b/tests/expectations/mod_2018.pyx new file mode 100644 index 0000000..d6740fb --- /dev/null +++ b/tests/expectations/mod_2018.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint8_t EXPORT_ME_TOO = 42; + + ctypedef struct ExportMe: + uint64_t val; + + void export_me(ExportMe *val); diff --git a/tests/expectations/mod_2018.tag.pyx b/tests/expectations/mod_2018.tag.pyx new file mode 100644 index 0000000..a0777cc --- /dev/null +++ b/tests/expectations/mod_2018.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint8_t EXPORT_ME_TOO = 42; + + cdef struct ExportMe: + uint64_t val; + + void export_me(ExportMe *val); diff --git a/tests/expectations/mod_attr.pyx b/tests/expectations/mod_attr.pyx new file mode 100644 index 0000000..e848688 --- /dev/null +++ b/tests/expectations/mod_attr.pyx @@ -0,0 +1,31 @@ +DEF FOO = 0 +DEF BAR = 0 + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + IF FOO: + const int32_t FOO = 1; + + IF BAR: + const int32_t BAR = 2; + + IF FOO: + ctypedef struct Foo: + pass + + IF BAR: + ctypedef struct Bar: + pass + + IF FOO: + void foo(const Foo *foo); + + IF BAR: + void bar(const Bar *bar); diff --git a/tests/expectations/mod_attr.tag.pyx b/tests/expectations/mod_attr.tag.pyx new file mode 100644 index 0000000..6eb149d --- /dev/null +++ b/tests/expectations/mod_attr.tag.pyx @@ -0,0 +1,31 @@ +DEF FOO = 0 +DEF BAR = 0 + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + IF FOO: + const int32_t FOO = 1; + + IF BAR: + const int32_t BAR = 2; + + IF FOO: + cdef struct Foo: + pass + + IF BAR: + cdef struct Bar: + pass + + IF FOO: + void foo(const Foo *foo); + + IF BAR: + void bar(const Bar *bar); diff --git a/tests/expectations/mod_path.pyx b/tests/expectations/mod_path.pyx new file mode 100644 index 0000000..d6740fb --- /dev/null +++ b/tests/expectations/mod_path.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint8_t EXPORT_ME_TOO = 42; + + ctypedef struct ExportMe: + uint64_t val; + + void export_me(ExportMe *val); diff --git a/tests/expectations/mod_path.tag.pyx b/tests/expectations/mod_path.tag.pyx new file mode 100644 index 0000000..a0777cc --- /dev/null +++ b/tests/expectations/mod_path.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint8_t EXPORT_ME_TOO = 42; + + cdef struct ExportMe: + uint64_t val; + + void export_me(ExportMe *val); diff --git a/tests/expectations/monomorph_1.pyx b/tests/expectations/monomorph_1.pyx new file mode 100644 index 0000000..df95cb7 --- /dev/null +++ b/tests/expectations/monomorph_1.pyx @@ -0,0 +1,44 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Bar_Bar_f32: + pass + + ctypedef struct Bar_Foo_f32: + pass + + ctypedef struct Bar_f32: + pass + + ctypedef struct Foo_i32: + const int32_t *data; + + ctypedef struct Foo_f32: + const float *data; + + ctypedef struct Foo_Bar_f32: + const Bar_f32 *data; + + ctypedef struct Tuple_Foo_f32_____f32: + const Foo_f32 *a; + const float *b; + + ctypedef struct Tuple_f32__f32: + const float *a; + const float *b; + + ctypedef Tuple_f32__f32 Indirection_f32; + + void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); diff --git a/tests/expectations/monomorph_1.tag.pyx b/tests/expectations/monomorph_1.tag.pyx new file mode 100644 index 0000000..2727476 --- /dev/null +++ b/tests/expectations/monomorph_1.tag.pyx @@ -0,0 +1,44 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Bar_Bar_f32: + pass + + cdef struct Bar_Foo_f32: + pass + + cdef struct Bar_f32: + pass + + cdef struct Foo_i32: + const int32_t *data; + + cdef struct Foo_f32: + const float *data; + + cdef struct Foo_Bar_f32: + const Bar_f32 *data; + + cdef struct Tuple_Foo_f32_____f32: + const Foo_f32 *a; + const float *b; + + cdef struct Tuple_f32__f32: + const float *a; + const float *b; + + ctypedef Tuple_f32__f32 Indirection_f32; + + void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); diff --git a/tests/expectations/monomorph_2.pyx b/tests/expectations/monomorph_2.pyx new file mode 100644 index 0000000..00f8e7d --- /dev/null +++ b/tests/expectations/monomorph_2.pyx @@ -0,0 +1,25 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct A: + pass + + ctypedef struct B: + pass + + ctypedef struct List_A: + A *members; + uintptr_t count; + + ctypedef struct List_B: + B *members; + uintptr_t count; + + void foo(List_A a); + + void bar(List_B b); diff --git a/tests/expectations/monomorph_2.tag.pyx b/tests/expectations/monomorph_2.tag.pyx new file mode 100644 index 0000000..98732a1 --- /dev/null +++ b/tests/expectations/monomorph_2.tag.pyx @@ -0,0 +1,25 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct A: + pass + + cdef struct B: + pass + + cdef struct List_A: + A *members; + uintptr_t count; + + cdef struct List_B: + B *members; + uintptr_t count; + + void foo(List_A a); + + void bar(List_B b); diff --git a/tests/expectations/monomorph_3.pyx b/tests/expectations/monomorph_3.pyx new file mode 100644 index 0000000..b8de095 --- /dev/null +++ b/tests/expectations/monomorph_3.pyx @@ -0,0 +1,44 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Bar_Bar_f32: + pass + + ctypedef struct Bar_Foo_f32: + pass + + ctypedef struct Bar_f32: + pass + + ctypedef union Foo_i32: + const int32_t *data; + + ctypedef union Foo_f32: + const float *data; + + ctypedef union Foo_Bar_f32: + const Bar_f32 *data; + + ctypedef union Tuple_Foo_f32_____f32: + const Foo_f32 *a; + const float *b; + + ctypedef union Tuple_f32__f32: + const float *a; + const float *b; + + ctypedef Tuple_f32__f32 Indirection_f32; + + void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); diff --git a/tests/expectations/monomorph_3.tag.pyx b/tests/expectations/monomorph_3.tag.pyx new file mode 100644 index 0000000..93690a6 --- /dev/null +++ b/tests/expectations/monomorph_3.tag.pyx @@ -0,0 +1,44 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Bar_Bar_f32: + pass + + cdef struct Bar_Foo_f32: + pass + + cdef struct Bar_f32: + pass + + cdef union Foo_i32: + const int32_t *data; + + cdef union Foo_f32: + const float *data; + + cdef union Foo_Bar_f32: + const Bar_f32 *data; + + cdef union Tuple_Foo_f32_____f32: + const Foo_f32 *a; + const float *b; + + cdef union Tuple_f32__f32: + const float *a; + const float *b; + + ctypedef Tuple_f32__f32 Indirection_f32; + + void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); diff --git a/tests/expectations/must_use.pyx b/tests/expectations/must_use.pyx new file mode 100644 index 0000000..ee1bc64 --- /dev/null +++ b/tests/expectations/must_use.pyx @@ -0,0 +1,29 @@ +#define MUST_USE_FUNC __attribute__((warn_unused_result)) +#define MUST_USE_STRUCT __attribute__((warn_unused)) +#define MUST_USE_ENUM /* nothing */ + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + Owned_i32, + None_i32, + ctypedef uint8_t MaybeOwnedPtr_i32_Tag; + + ctypedef struct Owned_Body_i32: + int32_t *_0; + + ctypedef struct MaybeOwnedPtr_i32: + MaybeOwnedPtr_i32_Tag tag; + Owned_Body_i32 owned; + + ctypedef struct OwnedPtr_i32: + int32_t *ptr; + + MaybeOwnedPtr_i32 maybe_consume(OwnedPtr_i32 input); diff --git a/tests/expectations/must_use.tag.pyx b/tests/expectations/must_use.tag.pyx new file mode 100644 index 0000000..5eb2ab7 --- /dev/null +++ b/tests/expectations/must_use.tag.pyx @@ -0,0 +1,29 @@ +#define MUST_USE_FUNC __attribute__((warn_unused_result)) +#define MUST_USE_STRUCT __attribute__((warn_unused)) +#define MUST_USE_ENUM /* nothing */ + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + Owned_i32, + None_i32, + ctypedef uint8_t MaybeOwnedPtr_i32_Tag; + + cdef struct Owned_Body_i32: + int32_t *_0; + + cdef struct MaybeOwnedPtr_i32: + MaybeOwnedPtr_i32_Tag tag; + Owned_Body_i32 owned; + + cdef struct OwnedPtr_i32: + int32_t *ptr; + + MaybeOwnedPtr_i32 maybe_consume(OwnedPtr_i32 input); diff --git a/tests/expectations/namespace_constant.pyx b/tests/expectations/namespace_constant.pyx new file mode 100644 index 0000000..f19370f --- /dev/null +++ b/tests/expectations/namespace_constant.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t FOO = 10; + + const float ZOM = 3.14; + + ctypedef struct Foo: + int32_t x[FOO]; + + void root(Foo x); diff --git a/tests/expectations/namespace_constant.tag.pyx b/tests/expectations/namespace_constant.tag.pyx new file mode 100644 index 0000000..af87011 --- /dev/null +++ b/tests/expectations/namespace_constant.tag.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t FOO = 10; + + const float ZOM = 3.14; + + cdef struct Foo: + int32_t x[FOO]; + + void root(Foo x); diff --git a/tests/expectations/namespaces_constant.pyx b/tests/expectations/namespaces_constant.pyx new file mode 100644 index 0000000..f19370f --- /dev/null +++ b/tests/expectations/namespaces_constant.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t FOO = 10; + + const float ZOM = 3.14; + + ctypedef struct Foo: + int32_t x[FOO]; + + void root(Foo x); diff --git a/tests/expectations/namespaces_constant.tag.pyx b/tests/expectations/namespaces_constant.tag.pyx new file mode 100644 index 0000000..af87011 --- /dev/null +++ b/tests/expectations/namespaces_constant.tag.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t FOO = 10; + + const float ZOM = 3.14; + + cdef struct Foo: + int32_t x[FOO]; + + void root(Foo x); diff --git a/tests/expectations/nested_import.pyx b/tests/expectations/nested_import.pyx new file mode 100644 index 0000000..c82ecc5 --- /dev/null +++ b/tests/expectations/nested_import.pyx @@ -0,0 +1,8 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + pass \ No newline at end of file diff --git a/tests/expectations/no_includes.pyx b/tests/expectations/no_includes.pyx new file mode 100644 index 0000000..d5f4496 --- /dev/null +++ b/tests/expectations/no_includes.pyx @@ -0,0 +1,4 @@ + +cdef extern from *: + + void root(); diff --git a/tests/expectations/nonnull.pyx b/tests/expectations/nonnull.pyx new file mode 100644 index 0000000..15ce8b2 --- /dev/null +++ b/tests/expectations/nonnull.pyx @@ -0,0 +1,23 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Opaque: + pass + + ctypedef struct Foo_u64: + float *a; + uint64_t *b; + Opaque *c; + uint64_t **d; + float **e; + Opaque **f; + uint64_t *g; + int32_t *h; + int32_t **i; + + void root(int32_t *arg, Foo_u64 *foo, Opaque **d); diff --git a/tests/expectations/nonnull.tag.pyx b/tests/expectations/nonnull.tag.pyx new file mode 100644 index 0000000..ce3e8d2 --- /dev/null +++ b/tests/expectations/nonnull.tag.pyx @@ -0,0 +1,23 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Opaque: + pass + + cdef struct Foo_u64: + float *a; + uint64_t *b; + Opaque *c; + uint64_t **d; + float **e; + Opaque **f; + uint64_t *g; + int32_t *h; + int32_t **i; + + void root(int32_t *arg, Foo_u64 *foo, Opaque **d); diff --git a/tests/expectations/nonnull_attribute.pyx b/tests/expectations/nonnull_attribute.pyx new file mode 100644 index 0000000..c6f90fa --- /dev/null +++ b/tests/expectations/nonnull_attribute.pyx @@ -0,0 +1,52 @@ +#ifdef __clang__ +#define CBINDGEN_NONNULL _Nonnull +#else +#define CBINDGEN_NONNULL +#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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Opaque: + pass + + ctypedef struct References: + const Opaque *a; + Opaque *b; + const Opaque *c; + Opaque *d; + + ctypedef struct Pointers_u64: + float *a; + uint64_t *b; + Opaque *c; + uint64_t **d; + float **e; + Opaque **f; + uint64_t *g; + int32_t *h; + int32_t **i; + const uint64_t *j; + uint64_t *k; + + void value_arg(References arg); + + void mutltiple_args(int32_t *arg, Pointers_u64 *foo, Opaque **d); + + void ref_arg(const Pointers_u64 *arg); + + void mut_ref_arg(Pointers_u64 *arg); + + void optional_ref_arg(const Pointers_u64 *arg); + + void optional_mut_ref_arg(Pointers_u64 *arg); + + void nullable_const_ptr(const Pointers_u64 *arg); + + void nullable_mut_ptr(Pointers_u64 *arg); diff --git a/tests/expectations/nonnull_attribute.tag.pyx b/tests/expectations/nonnull_attribute.tag.pyx new file mode 100644 index 0000000..16327ab --- /dev/null +++ b/tests/expectations/nonnull_attribute.tag.pyx @@ -0,0 +1,52 @@ +#ifdef __clang__ +#define CBINDGEN_NONNULL _Nonnull +#else +#define CBINDGEN_NONNULL +#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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Opaque: + pass + + cdef struct References: + const Opaque *a; + Opaque *b; + const Opaque *c; + Opaque *d; + + cdef struct Pointers_u64: + float *a; + uint64_t *b; + Opaque *c; + uint64_t **d; + float **e; + Opaque **f; + uint64_t *g; + int32_t *h; + int32_t **i; + const uint64_t *j; + uint64_t *k; + + void value_arg(References arg); + + void mutltiple_args(int32_t *arg, Pointers_u64 *foo, Opaque **d); + + void ref_arg(const Pointers_u64 *arg); + + void mut_ref_arg(Pointers_u64 *arg); + + void optional_ref_arg(const Pointers_u64 *arg); + + void optional_mut_ref_arg(Pointers_u64 *arg); + + void nullable_const_ptr(const Pointers_u64 *arg); + + void nullable_mut_ptr(Pointers_u64 *arg); diff --git a/tests/expectations/opaque.pyx b/tests/expectations/opaque.pyx new file mode 100644 index 0000000..8c5059b --- /dev/null +++ b/tests/expectations/opaque.pyx @@ -0,0 +1,22 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct HashMap_i32__i32__BuildHasherDefault_DefaultHasher: + pass + + ctypedef struct Result_Foo: + pass + + # Fast hash map used internally. + ctypedef HashMap_i32__i32__BuildHasherDefault_DefaultHasher FastHashMap_i32__i32; + + ctypedef FastHashMap_i32__i32 Foo; + + ctypedef Result_Foo Bar; + + void root(const Foo *a, const Bar *b); diff --git a/tests/expectations/opaque.tag.pyx b/tests/expectations/opaque.tag.pyx new file mode 100644 index 0000000..8dd33f8 --- /dev/null +++ b/tests/expectations/opaque.tag.pyx @@ -0,0 +1,22 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct HashMap_i32__i32__BuildHasherDefault_DefaultHasher: + pass + + cdef struct Result_Foo: + pass + + # Fast hash map used internally. + ctypedef HashMap_i32__i32__BuildHasherDefault_DefaultHasher FastHashMap_i32__i32; + + ctypedef FastHashMap_i32__i32 Foo; + + ctypedef Result_Foo Bar; + + void root(const Foo *a, const Bar *b); diff --git a/tests/expectations/pragma_once.pyx b/tests/expectations/pragma_once.pyx new file mode 100644 index 0000000..133a763 --- /dev/null +++ b/tests/expectations/pragma_once.pyx @@ -0,0 +1,9 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void root(); diff --git a/tests/expectations/prefix.pyx b/tests/expectations/prefix.pyx new file mode 100644 index 0000000..76d7a1b --- /dev/null +++ b/tests/expectations/prefix.pyx @@ -0,0 +1,31 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t PREFIX_LEN = 22; + + const int64_t PREFIX_X = (22 << 22); + + ctypedef int32_t PREFIX_NamedLenArray[PREFIX_LEN]; + + ctypedef int32_t PREFIX_ValuedLenArray[22]; + + cdef enum: + Weight, + Normal, + Bold, + ctypedef uint8_t PREFIX_AbsoluteFontWeight_Tag; + + ctypedef struct PREFIX_Weight_Body: + PREFIX_AbsoluteFontWeight_Tag tag; + float _0; + + ctypedef union PREFIX_AbsoluteFontWeight: + PREFIX_AbsoluteFontWeight_Tag tag; + PREFIX_Weight_Body weight; + + void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y, PREFIX_AbsoluteFontWeight z); diff --git a/tests/expectations/prefix.tag.pyx b/tests/expectations/prefix.tag.pyx new file mode 100644 index 0000000..8e61bce --- /dev/null +++ b/tests/expectations/prefix.tag.pyx @@ -0,0 +1,31 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t PREFIX_LEN = 22; + + const int64_t PREFIX_X = (22 << 22); + + ctypedef int32_t PREFIX_NamedLenArray[PREFIX_LEN]; + + ctypedef int32_t PREFIX_ValuedLenArray[22]; + + cdef enum: + Weight, + Normal, + Bold, + ctypedef uint8_t PREFIX_AbsoluteFontWeight_Tag; + + cdef struct PREFIX_Weight_Body: + PREFIX_AbsoluteFontWeight_Tag tag; + float _0; + + cdef union PREFIX_AbsoluteFontWeight: + PREFIX_AbsoluteFontWeight_Tag tag; + PREFIX_Weight_Body weight; + + void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y, PREFIX_AbsoluteFontWeight z); diff --git a/tests/expectations/prefixed_struct_literal.pyx b/tests/expectations/prefixed_struct_literal.pyx new file mode 100644 index 0000000..9ed4c8c --- /dev/null +++ b/tests/expectations/prefixed_struct_literal.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct PREFIXFoo: + int32_t a; + uint32_t b; + const PREFIXFoo PREFIXFoo_FOO = { 42, 47 }; + + const PREFIXFoo PREFIXBAR = { 42, 1337 }; + + void root(PREFIXFoo x); diff --git a/tests/expectations/prefixed_struct_literal.tag.pyx b/tests/expectations/prefixed_struct_literal.tag.pyx new file mode 100644 index 0000000..506ca74 --- /dev/null +++ b/tests/expectations/prefixed_struct_literal.tag.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct PREFIXFoo: + int32_t a; + uint32_t b; + const PREFIXFoo PREFIXFoo_FOO = { 42, 47 }; + + const PREFIXFoo PREFIXBAR = { 42, 1337 }; + + void root(PREFIXFoo x); diff --git a/tests/expectations/prefixed_struct_literal_deep.pyx b/tests/expectations/prefixed_struct_literal_deep.pyx new file mode 100644 index 0000000..aee7794 --- /dev/null +++ b/tests/expectations/prefixed_struct_literal_deep.pyx @@ -0,0 +1,19 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct PREFIXBar: + int32_t a; + + ctypedef struct PREFIXFoo: + int32_t a; + uint32_t b; + PREFIXBar bar; + + const PREFIXFoo PREFIXVAL = { 42, 1337, { 323 } }; + + void root(PREFIXFoo x); diff --git a/tests/expectations/prefixed_struct_literal_deep.tag.pyx b/tests/expectations/prefixed_struct_literal_deep.tag.pyx new file mode 100644 index 0000000..a2b0be9 --- /dev/null +++ b/tests/expectations/prefixed_struct_literal_deep.tag.pyx @@ -0,0 +1,19 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct PREFIXBar: + int32_t a; + + cdef struct PREFIXFoo: + int32_t a; + uint32_t b; + PREFIXBar bar; + + const PREFIXFoo PREFIXVAL = { 42, 1337, { 323 } }; + + void root(PREFIXFoo x); diff --git a/tests/expectations/ptrs_as_arrays.pyx b/tests/expectations/ptrs_as_arrays.pyx new file mode 100644 index 0000000..333abd1 --- /dev/null +++ b/tests/expectations/ptrs_as_arrays.pyx @@ -0,0 +1,17 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void ptr_as_array(uint32_t n, const uint32_t arg[3], const uint64_t *v); + + void ptr_as_array1(uint32_t n, const uint32_t arg[3], uint64_t v[4]); + + void ptr_as_array2(uint32_t n, uint32_t arg[], const uint64_t v[]); + + void ptr_as_array_wrong_syntax(uint32_t *arg, const uint32_t *v, const uint32_t*); + + void ptr_as_array_unnamed(uint32_t*, const uint32_t*); diff --git a/tests/expectations/raw_lines.pyx b/tests/expectations/raw_lines.pyx new file mode 100644 index 0000000..3a6b9ec --- /dev/null +++ b/tests/expectations/raw_lines.pyx @@ -0,0 +1,10 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list +#define VERSION 1 + +cdef extern from *: + + void root(); diff --git a/tests/expectations/rename.pyx b/tests/expectations/rename.pyx new file mode 100644 index 0000000..6837861 --- /dev/null +++ b/tests/expectations/rename.pyx @@ -0,0 +1,36 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t C_H = 10; + + cdef enum: + x = 0, + y = 1, + ctypedef uint8_t C_E; + + ctypedef struct C_A: + pass + + ctypedef struct C_C: + pass + + ctypedef struct C_AwesomeB: + int32_t x; + float y; + + ctypedef union C_D: + int32_t x; + float y; + + ctypedef C_A C_F; + + const intptr_t C_I = 10; + + extern const int32_t G; + + void root(const C_A *a, C_AwesomeB b, C_C c, C_D d, C_E e, C_F f); diff --git a/tests/expectations/rename.tag.pyx b/tests/expectations/rename.tag.pyx new file mode 100644 index 0000000..f477207 --- /dev/null +++ b/tests/expectations/rename.tag.pyx @@ -0,0 +1,36 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t C_H = 10; + + cdef enum: + x = 0, + y = 1, + ctypedef uint8_t C_E; + + cdef struct C_A: + pass + + cdef struct C_C: + pass + + cdef struct C_AwesomeB: + int32_t x; + float y; + + cdef union C_D: + int32_t x; + float y; + + ctypedef C_A C_F; + + const intptr_t C_I = 10; + + extern const int32_t G; + + void root(const C_A *a, C_AwesomeB b, C_C c, C_D d, C_E e, C_F f); diff --git a/tests/expectations/rename_crate.pyx b/tests/expectations/rename_crate.pyx new file mode 100644 index 0000000..c294dfa --- /dev/null +++ b/tests/expectations/rename_crate.pyx @@ -0,0 +1,34 @@ +DEF DEFINE_FREEBSD = 0 + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo: + int32_t x; + + ctypedef struct RenamedTy: + uint64_t y; + + IF not DEFINE_FREEBSD: + ctypedef struct NoExternTy: + uint8_t field; + + IF not DEFINE_FREEBSD: + ctypedef struct ContainsNoExternTy: + NoExternTy field; + + IF DEFINE_FREEBSD: + ctypedef struct ContainsNoExternTy: + uint64_t field; + + void root(Foo a); + + void renamed_func(RenamedTy a); + + void no_extern_func(ContainsNoExternTy a); diff --git a/tests/expectations/rename_crate.tag.pyx b/tests/expectations/rename_crate.tag.pyx new file mode 100644 index 0000000..cf1fe77 --- /dev/null +++ b/tests/expectations/rename_crate.tag.pyx @@ -0,0 +1,34 @@ +DEF DEFINE_FREEBSD = 0 + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo: + int32_t x; + + cdef struct RenamedTy: + uint64_t y; + + IF not DEFINE_FREEBSD: + cdef struct NoExternTy: + uint8_t field; + + IF not DEFINE_FREEBSD: + cdef struct ContainsNoExternTy: + NoExternTy field; + + IF DEFINE_FREEBSD: + cdef struct ContainsNoExternTy: + uint64_t field; + + void root(Foo a); + + void renamed_func(RenamedTy a); + + void no_extern_func(ContainsNoExternTy a); diff --git a/tests/expectations/renaming_overrides_prefixing.pyx b/tests/expectations/renaming_overrides_prefixing.pyx new file mode 100644 index 0000000..f857c8e --- /dev/null +++ b/tests/expectations/renaming_overrides_prefixing.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct StyleA: + pass + + ctypedef struct B: + int32_t x; + float y; + + void root(const StyleA *a, B b); diff --git a/tests/expectations/renaming_overrides_prefixing.tag.pyx b/tests/expectations/renaming_overrides_prefixing.tag.pyx new file mode 100644 index 0000000..812a652 --- /dev/null +++ b/tests/expectations/renaming_overrides_prefixing.tag.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct StyleA: + pass + + cdef struct B: + int32_t x; + float y; + + void root(const StyleA *a, B b); diff --git a/tests/expectations/reserved.pyx b/tests/expectations/reserved.pyx new file mode 100644 index 0000000..24423b3 --- /dev/null +++ b/tests/expectations/reserved.pyx @@ -0,0 +1,61 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct A: + int32_t namespace_; + float float_; + + ctypedef struct B: + int32_t namespace_; + float float_; + + cdef enum: + D, + ctypedef uint8_t C_Tag; + + ctypedef struct D_Body: + int32_t namespace_; + float float_; + + ctypedef struct C: + C_Tag tag; + D_Body d; + + cdef enum: + Double, + Float, + ctypedef uint8_t E_Tag; + + ctypedef struct Double_Body: + double _0; + + ctypedef struct Float_Body: + float _0; + + ctypedef struct E: + E_Tag tag; + Double_Body double_; + Float_Body float_; + + cdef enum: + double_, + float_, + ctypedef uint8_t F_Tag; + + ctypedef struct double_Body: + double _0; + + ctypedef struct float_Body: + float _0; + + ctypedef struct F: + F_Tag tag; + double_Body double_; + float_Body float_; + + void root(A a, B b, C c, E e, F f, int32_t namespace_, float float_); diff --git a/tests/expectations/reserved.tag.pyx b/tests/expectations/reserved.tag.pyx new file mode 100644 index 0000000..a64424b --- /dev/null +++ b/tests/expectations/reserved.tag.pyx @@ -0,0 +1,61 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct A: + int32_t namespace_; + float float_; + + cdef struct B: + int32_t namespace_; + float float_; + + cdef enum: + D, + ctypedef uint8_t C_Tag; + + cdef struct D_Body: + int32_t namespace_; + float float_; + + cdef struct C: + C_Tag tag; + D_Body d; + + cdef enum: + Double, + Float, + ctypedef uint8_t E_Tag; + + cdef struct Double_Body: + double _0; + + cdef struct Float_Body: + float _0; + + cdef struct E: + E_Tag tag; + Double_Body double_; + Float_Body float_; + + cdef enum: + double_, + float_, + ctypedef uint8_t F_Tag; + + cdef struct double_Body: + double _0; + + cdef struct float_Body: + float _0; + + cdef struct F: + F_Tag tag; + double_Body double_; + float_Body float_; + + void root(A a, B b, C c, E e, F f, int32_t namespace_, float float_); diff --git a/tests/expectations/sentinel.pyx b/tests/expectations/sentinel.pyx new file mode 100644 index 0000000..828705d --- /dev/null +++ b/tests/expectations/sentinel.pyx @@ -0,0 +1,46 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + A_A1, + A_A2, + A_A3, + # Must be last for serialization purposes + A_Sentinel, + ctypedef uint8_t A; + + cdef enum: + B_B1, + B_B2, + B_B3, + # Must be last for serialization purposes + B_Sentinel, + ctypedef uint8_t B; + + cdef enum: + C_C1, + C_C2, + C_C3, + # Must be last for serialization purposes + C_Sentinel, + ctypedef uint8_t C_Tag; + + ctypedef struct C_C1_Body: + C_Tag tag; + uint32_t a; + + ctypedef struct C_C2_Body: + C_Tag tag; + uint32_t b; + + ctypedef union C: + C_Tag tag; + C_C1_Body c1; + C_C2_Body c2; + + void root(A a, B b, C c); diff --git a/tests/expectations/sentinel.tag.pyx b/tests/expectations/sentinel.tag.pyx new file mode 100644 index 0000000..e68c9d2 --- /dev/null +++ b/tests/expectations/sentinel.tag.pyx @@ -0,0 +1,46 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + A_A1, + A_A2, + A_A3, + # Must be last for serialization purposes + A_Sentinel, + ctypedef uint8_t A; + + cdef enum: + B_B1, + B_B2, + B_B3, + # Must be last for serialization purposes + B_Sentinel, + ctypedef uint8_t B; + + cdef enum: + C_C1, + C_C2, + C_C3, + # Must be last for serialization purposes + C_Sentinel, + ctypedef uint8_t C_Tag; + + cdef struct C_C1_Body: + C_Tag tag; + uint32_t a; + + cdef struct C_C2_Body: + C_Tag tag; + uint32_t b; + + cdef union C: + C_Tag tag; + C_C1_Body c1; + C_C2_Body c2; + + void root(A a, B b, C c); diff --git a/tests/expectations/simplify_option_ptr.pyx b/tests/expectations/simplify_option_ptr.pyx new file mode 100644 index 0000000..f2f6892 --- /dev/null +++ b/tests/expectations/simplify_option_ptr.pyx @@ -0,0 +1,22 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Opaque: + pass + + ctypedef struct Foo: + const Opaque *x; + Opaque *y; + void (*z)(); + + ctypedef union Bar: + const Opaque *x; + Opaque *y; + void (*z)(); + + void root(const Opaque *a, Opaque *b, Foo c, Bar d); diff --git a/tests/expectations/simplify_option_ptr.tag.pyx b/tests/expectations/simplify_option_ptr.tag.pyx new file mode 100644 index 0000000..72890fb --- /dev/null +++ b/tests/expectations/simplify_option_ptr.tag.pyx @@ -0,0 +1,22 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Opaque: + pass + + cdef struct Foo: + const Opaque *x; + Opaque *y; + void (*z)(); + + cdef union Bar: + const Opaque *x; + Opaque *y; + void (*z)(); + + void root(const Opaque *a, Opaque *b, Foo c, Bar d); diff --git a/tests/expectations/size_types.pyx b/tests/expectations/size_types.pyx new file mode 100644 index 0000000..c08b7c6 --- /dev/null +++ b/tests/expectations/size_types.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum: + IV, + ctypedef ptrdiff_t IE; + + cdef enum: + UV, + ctypedef size_t UE; + + ctypedef size_t Usize; + + ctypedef ptrdiff_t Isize; + + void root(Usize, Isize, UE, IE); diff --git a/tests/expectations/static.pyx b/tests/expectations/static.pyx new file mode 100644 index 0000000..923621a --- /dev/null +++ b/tests/expectations/static.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Bar: + pass + + ctypedef struct Foo: + pass + + extern const int32_t NUMBER; + + extern Foo FOO; + + extern const Bar BAR; + + void root(); diff --git a/tests/expectations/static.tag.pyx b/tests/expectations/static.tag.pyx new file mode 100644 index 0000000..ccf603f --- /dev/null +++ b/tests/expectations/static.tag.pyx @@ -0,0 +1,21 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Bar: + pass + + cdef struct Foo: + pass + + extern const int32_t NUMBER; + + extern Foo FOO; + + extern const Bar BAR; + + void root(); diff --git a/tests/expectations/std_lib.pyx b/tests/expectations/std_lib.pyx new file mode 100644 index 0000000..37b4590 --- /dev/null +++ b/tests/expectations/std_lib.pyx @@ -0,0 +1,18 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Option_i32: + pass + + ctypedef struct Result_i32__String: + pass + + ctypedef struct Vec_String: + pass + + void root(const Vec_String *a, const Option_i32 *b, const Result_i32__String *c); diff --git a/tests/expectations/std_lib.tag.pyx b/tests/expectations/std_lib.tag.pyx new file mode 100644 index 0000000..22f248d --- /dev/null +++ b/tests/expectations/std_lib.tag.pyx @@ -0,0 +1,18 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Option_i32: + pass + + cdef struct Result_i32__String: + pass + + cdef struct Vec_String: + pass + + void root(const Vec_String *a, const Option_i32 *b, const Result_i32__String *c); diff --git a/tests/expectations/struct.pyx b/tests/expectations/struct.pyx new file mode 100644 index 0000000..3342101 --- /dev/null +++ b/tests/expectations/struct.pyx @@ -0,0 +1,28 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Opaque: + pass + + ctypedef struct Normal: + int32_t x; + float y; + + ctypedef struct NormalWithZST: + int32_t x; + float y; + + ctypedef struct TupleRenamed: + int32_t m0; + float m1; + + ctypedef struct TupleNamed: + int32_t x; + float y; + + void root(Opaque *a, Normal b, NormalWithZST c, TupleRenamed d, TupleNamed e); diff --git a/tests/expectations/struct.tag.pyx b/tests/expectations/struct.tag.pyx new file mode 100644 index 0000000..768f375 --- /dev/null +++ b/tests/expectations/struct.tag.pyx @@ -0,0 +1,28 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Opaque: + pass + + cdef struct Normal: + int32_t x; + float y; + + cdef struct NormalWithZST: + int32_t x; + float y; + + cdef struct TupleRenamed: + int32_t m0; + float m1; + + cdef struct TupleNamed: + int32_t x; + float y; + + void root(Opaque *a, Normal b, NormalWithZST c, TupleRenamed d, TupleNamed e); diff --git a/tests/expectations/struct_literal.pyx b/tests/expectations/struct_literal.pyx new file mode 100644 index 0000000..f354828 --- /dev/null +++ b/tests/expectations/struct_literal.pyx @@ -0,0 +1,24 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Bar: + pass + + ctypedef struct Foo: + int32_t a; + uint32_t b; + const Foo Foo_FOO = { 42, 47 }; + const Foo Foo_FOO2 = { 42, 47 }; + const Foo Foo_FOO3 = { 42, 47 }; + + + const Foo BAR = { 42, 1337 }; + + + + void root(Foo x, Bar bar); diff --git a/tests/expectations/struct_literal.tag.pyx b/tests/expectations/struct_literal.tag.pyx new file mode 100644 index 0000000..9aea178 --- /dev/null +++ b/tests/expectations/struct_literal.tag.pyx @@ -0,0 +1,24 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Bar: + pass + + cdef struct Foo: + int32_t a; + uint32_t b; + const Foo Foo_FOO = { 42, 47 }; + const Foo Foo_FOO2 = { 42, 47 }; + const Foo Foo_FOO3 = { 42, 47 }; + + + const Foo BAR = { 42, 1337 }; + + + + void root(Foo x, Bar bar); diff --git a/tests/expectations/struct_literal_order.pyx b/tests/expectations/struct_literal_order.pyx new file mode 100644 index 0000000..63ad71c --- /dev/null +++ b/tests/expectations/struct_literal_order.pyx @@ -0,0 +1,25 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct ABC: + float a; + uint32_t b; + uint32_t c; + const ABC ABC_abc = { 1.0, 2, 3 }; + const ABC ABC_bac = { 1.0, 2, 3 }; + const ABC ABC_cba = { 1.0, 2, 3 }; + + ctypedef struct BAC: + uint32_t b; + float a; + int32_t c; + const BAC BAC_abc = { 1, 2.0, 3 }; + const BAC BAC_bac = { 1, 2.0, 3 }; + const BAC BAC_cba = { 1, 2.0, 3 }; + + void root(ABC a1, BAC a2); diff --git a/tests/expectations/struct_literal_order.tag.pyx b/tests/expectations/struct_literal_order.tag.pyx new file mode 100644 index 0000000..8b67697 --- /dev/null +++ b/tests/expectations/struct_literal_order.tag.pyx @@ -0,0 +1,25 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct ABC: + float a; + uint32_t b; + uint32_t c; + const ABC ABC_abc = { 1.0, 2, 3 }; + const ABC ABC_bac = { 1.0, 2, 3 }; + const ABC ABC_cba = { 1.0, 2, 3 }; + + cdef struct BAC: + uint32_t b; + float a; + int32_t c; + const BAC BAC_abc = { 1, 2.0, 3 }; + const BAC BAC_bac = { 1, 2.0, 3 }; + const BAC BAC_cba = { 1, 2.0, 3 }; + + void root(ABC a1, BAC a2); diff --git a/tests/expectations/struct_self.pyx b/tests/expectations/struct_self.pyx new file mode 100644 index 0000000..ec3c345 --- /dev/null +++ b/tests/expectations/struct_self.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo_Bar: + const int32_t *something; + + ctypedef struct Bar: + int32_t something; + Foo_Bar subexpressions; + + void root(Bar b); diff --git a/tests/expectations/struct_self.tag.pyx b/tests/expectations/struct_self.tag.pyx new file mode 100644 index 0000000..3dc9d07 --- /dev/null +++ b/tests/expectations/struct_self.tag.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo_Bar: + const int32_t *something; + + cdef struct Bar: + int32_t something; + Foo_Bar subexpressions; + + void root(Bar b); diff --git a/tests/expectations/style_crash.pyx b/tests/expectations/style_crash.pyx new file mode 100644 index 0000000..c82ecc5 --- /dev/null +++ b/tests/expectations/style_crash.pyx @@ -0,0 +1,8 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + pass \ No newline at end of file diff --git a/tests/expectations/swift_name.pyx b/tests/expectations/swift_name.pyx new file mode 100644 index 0000000..93ded0c --- /dev/null +++ b/tests/expectations/swift_name.pyx @@ -0,0 +1,54 @@ +#define CF_SWIFT_NAME(_name) __attribute__((swift_name(#_name))) + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Opaque: + pass + + ctypedef struct SelfTypeTestStruct: + uint8_t times; + + ctypedef struct PointerToOpaque: + Opaque *ptr; + + void rust_print_hello_world(); + + void SelfTypeTestStruct_should_exist_ref(const SelfTypeTestStruct *self); + + void SelfTypeTestStruct_should_exist_ref_mut(SelfTypeTestStruct *self); + + void SelfTypeTestStruct_should_not_exist_box(SelfTypeTestStruct *self); + + SelfTypeTestStruct *SelfTypeTestStruct_should_not_exist_return_box(); + + void SelfTypeTestStruct_should_exist_annotated_self(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_mut_self(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_by_name(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_mut_by_name(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_unannotated(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_mut_unannotated(SelfTypeTestStruct self); + + void free_function_should_exist_ref(const SelfTypeTestStruct *test_struct); + + void free_function_should_exist_ref_mut(SelfTypeTestStruct *test_struct); + + void unnamed_argument(SelfTypeTestStruct*); + + void free_function_should_not_exist_box(SelfTypeTestStruct *boxed); + + void free_function_should_exist_annotated_by_name(SelfTypeTestStruct test_struct); + + void free_function_should_exist_annotated_mut_by_name(SelfTypeTestStruct test_struct); + + PointerToOpaque PointerToOpaque_create(uint8_t times); diff --git a/tests/expectations/swift_name.tag.pyx b/tests/expectations/swift_name.tag.pyx new file mode 100644 index 0000000..b234839 --- /dev/null +++ b/tests/expectations/swift_name.tag.pyx @@ -0,0 +1,54 @@ +#define CF_SWIFT_NAME(_name) __attribute__((swift_name(#_name))) + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Opaque: + pass + + cdef struct SelfTypeTestStruct: + uint8_t times; + + cdef struct PointerToOpaque: + Opaque *ptr; + + void rust_print_hello_world(); + + void SelfTypeTestStruct_should_exist_ref(const SelfTypeTestStruct *self); + + void SelfTypeTestStruct_should_exist_ref_mut(SelfTypeTestStruct *self); + + void SelfTypeTestStruct_should_not_exist_box(SelfTypeTestStruct *self); + + SelfTypeTestStruct *SelfTypeTestStruct_should_not_exist_return_box(); + + void SelfTypeTestStruct_should_exist_annotated_self(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_mut_self(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_by_name(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_mut_by_name(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_unannotated(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_mut_unannotated(SelfTypeTestStruct self); + + void free_function_should_exist_ref(const SelfTypeTestStruct *test_struct); + + void free_function_should_exist_ref_mut(SelfTypeTestStruct *test_struct); + + void unnamed_argument(SelfTypeTestStruct*); + + void free_function_should_not_exist_box(SelfTypeTestStruct *boxed); + + void free_function_should_exist_annotated_by_name(SelfTypeTestStruct test_struct); + + void free_function_should_exist_annotated_mut_by_name(SelfTypeTestStruct test_struct); + + PointerToOpaque PointerToOpaque_create(uint8_t times); diff --git a/tests/expectations/transform_op.pyx b/tests/expectations/transform_op.pyx new file mode 100644 index 0000000..96cca1a --- /dev/null +++ b/tests/expectations/transform_op.pyx @@ -0,0 +1,135 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct StylePoint_i32: + int32_t x; + int32_t y; + + ctypedef struct StylePoint_f32: + float x; + float y; + + cdef enum: + Foo_i32, + Bar_i32, + Baz_i32, + Bazz_i32, + ctypedef uint8_t StyleFoo_i32_Tag; + + ctypedef struct StyleFoo_Body_i32: + StyleFoo_i32_Tag tag; + int32_t x; + StylePoint_i32 y; + StylePoint_f32 z; + + ctypedef struct StyleBar_Body_i32: + StyleFoo_i32_Tag tag; + int32_t _0; + + ctypedef struct StyleBaz_Body_i32: + StyleFoo_i32_Tag tag; + StylePoint_i32 _0; + + ctypedef union StyleFoo_i32: + StyleFoo_i32_Tag tag; + StyleFoo_Body_i32 foo; + StyleBar_Body_i32 bar; + StyleBaz_Body_i32 baz; + + ctypedef enum StyleBar_i32_Tag: + Bar1_i32, + Bar2_i32, + Bar3_i32, + Bar4_i32, + + ctypedef struct StyleBar1_Body_i32: + int32_t x; + StylePoint_i32 y; + StylePoint_f32 z; + int32_t (*u)(int32_t); + + ctypedef struct StyleBar2_Body_i32: + int32_t _0; + + ctypedef struct StyleBar3_Body_i32: + StylePoint_i32 _0; + + ctypedef struct StyleBar_i32: + StyleBar_i32_Tag tag; + StyleBar1_Body_i32 bar1; + StyleBar2_Body_i32 bar2; + StyleBar3_Body_i32 bar3; + + ctypedef struct StylePoint_u32: + uint32_t x; + uint32_t y; + + ctypedef enum StyleBar_u32_Tag: + Bar1_u32, + Bar2_u32, + Bar3_u32, + Bar4_u32, + + ctypedef struct StyleBar1_Body_u32: + int32_t x; + StylePoint_u32 y; + StylePoint_f32 z; + int32_t (*u)(int32_t); + + ctypedef struct StyleBar2_Body_u32: + uint32_t _0; + + ctypedef struct StyleBar3_Body_u32: + StylePoint_u32 _0; + + ctypedef struct StyleBar_u32: + StyleBar_u32_Tag tag; + StyleBar1_Body_u32 bar1; + StyleBar2_Body_u32 bar2; + StyleBar3_Body_u32 bar3; + + cdef enum: + Baz1, + Baz2, + Baz3, + ctypedef uint8_t StyleBaz_Tag; + + ctypedef struct StyleBaz1_Body: + StyleBaz_Tag tag; + StyleBar_u32 _0; + + ctypedef struct StyleBaz2_Body: + StyleBaz_Tag tag; + StylePoint_i32 _0; + + ctypedef union StyleBaz: + StyleBaz_Tag tag; + StyleBaz1_Body baz1; + StyleBaz2_Body baz2; + + cdef enum: + Taz1, + Taz2, + Taz3, + ctypedef uint8_t StyleTaz_Tag; + + ctypedef struct StyleTaz1_Body: + StyleBar_u32 _0; + + ctypedef struct StyleTaz2_Body: + StyleBaz _0; + + ctypedef struct StyleTaz: + StyleTaz_Tag tag; + StyleTaz1_Body taz1; + StyleTaz2_Body taz2; + + void foo(const StyleFoo_i32 *foo, + const StyleBar_i32 *bar, + const StyleBaz *baz, + const StyleTaz *taz); diff --git a/tests/expectations/transform_op.tag.pyx b/tests/expectations/transform_op.tag.pyx new file mode 100644 index 0000000..1f995a2 --- /dev/null +++ b/tests/expectations/transform_op.tag.pyx @@ -0,0 +1,135 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct StylePoint_i32: + int32_t x; + int32_t y; + + cdef struct StylePoint_f32: + float x; + float y; + + cdef enum: + Foo_i32, + Bar_i32, + Baz_i32, + Bazz_i32, + ctypedef uint8_t StyleFoo_i32_Tag; + + cdef struct StyleFoo_Body_i32: + StyleFoo_i32_Tag tag; + int32_t x; + StylePoint_i32 y; + StylePoint_f32 z; + + cdef struct StyleBar_Body_i32: + StyleFoo_i32_Tag tag; + int32_t _0; + + cdef struct StyleBaz_Body_i32: + StyleFoo_i32_Tag tag; + StylePoint_i32 _0; + + cdef union StyleFoo_i32: + StyleFoo_i32_Tag tag; + StyleFoo_Body_i32 foo; + StyleBar_Body_i32 bar; + StyleBaz_Body_i32 baz; + + cdef enum StyleBar_i32_Tag: + Bar1_i32, + Bar2_i32, + Bar3_i32, + Bar4_i32, + + cdef struct StyleBar1_Body_i32: + int32_t x; + StylePoint_i32 y; + StylePoint_f32 z; + int32_t (*u)(int32_t); + + cdef struct StyleBar2_Body_i32: + int32_t _0; + + cdef struct StyleBar3_Body_i32: + StylePoint_i32 _0; + + cdef struct StyleBar_i32: + StyleBar_i32_Tag tag; + StyleBar1_Body_i32 bar1; + StyleBar2_Body_i32 bar2; + StyleBar3_Body_i32 bar3; + + cdef struct StylePoint_u32: + uint32_t x; + uint32_t y; + + cdef enum StyleBar_u32_Tag: + Bar1_u32, + Bar2_u32, + Bar3_u32, + Bar4_u32, + + cdef struct StyleBar1_Body_u32: + int32_t x; + StylePoint_u32 y; + StylePoint_f32 z; + int32_t (*u)(int32_t); + + cdef struct StyleBar2_Body_u32: + uint32_t _0; + + cdef struct StyleBar3_Body_u32: + StylePoint_u32 _0; + + cdef struct StyleBar_u32: + StyleBar_u32_Tag tag; + StyleBar1_Body_u32 bar1; + StyleBar2_Body_u32 bar2; + StyleBar3_Body_u32 bar3; + + cdef enum: + Baz1, + Baz2, + Baz3, + ctypedef uint8_t StyleBaz_Tag; + + cdef struct StyleBaz1_Body: + StyleBaz_Tag tag; + StyleBar_u32 _0; + + cdef struct StyleBaz2_Body: + StyleBaz_Tag tag; + StylePoint_i32 _0; + + cdef union StyleBaz: + StyleBaz_Tag tag; + StyleBaz1_Body baz1; + StyleBaz2_Body baz2; + + cdef enum: + Taz1, + Taz2, + Taz3, + ctypedef uint8_t StyleTaz_Tag; + + cdef struct StyleTaz1_Body: + StyleBar_u32 _0; + + cdef struct StyleTaz2_Body: + StyleBaz _0; + + cdef struct StyleTaz: + StyleTaz_Tag tag; + StyleTaz1_Body taz1; + StyleTaz2_Body taz2; + + void foo(const StyleFoo_i32 *foo, + const StyleBar_i32 *bar, + const StyleBaz *baz, + const StyleTaz *taz); diff --git a/tests/expectations/transparent.pyx b/tests/expectations/transparent.pyx new file mode 100644 index 0000000..8a0c243 --- /dev/null +++ b/tests/expectations/transparent.pyx @@ -0,0 +1,40 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct DummyStruct: + pass + + ctypedef struct EnumWithAssociatedConstantInImpl: + pass + + ctypedef DummyStruct TransparentComplexWrappingStructTuple; + + ctypedef uint32_t TransparentPrimitiveWrappingStructTuple; + + ctypedef DummyStruct TransparentComplexWrappingStructure; + + ctypedef uint32_t TransparentPrimitiveWrappingStructure; + + ctypedef DummyStruct TransparentComplexWrapper_i32; + + ctypedef uint32_t TransparentPrimitiveWrapper_i32; + + ctypedef uint32_t TransparentPrimitiveWithAssociatedConstants; + const TransparentPrimitiveWithAssociatedConstants TransparentPrimitiveWithAssociatedConstants_ZERO = 0; + const TransparentPrimitiveWithAssociatedConstants TransparentPrimitiveWithAssociatedConstants_ONE = 1; + + const TransparentPrimitiveWrappingStructure EnumWithAssociatedConstantInImpl_TEN = 10; + + void root(TransparentComplexWrappingStructTuple a, + TransparentPrimitiveWrappingStructTuple b, + TransparentComplexWrappingStructure c, + TransparentPrimitiveWrappingStructure d, + TransparentComplexWrapper_i32 e, + TransparentPrimitiveWrapper_i32 f, + TransparentPrimitiveWithAssociatedConstants g, + EnumWithAssociatedConstantInImpl h); diff --git a/tests/expectations/transparent.tag.pyx b/tests/expectations/transparent.tag.pyx new file mode 100644 index 0000000..1a458fd --- /dev/null +++ b/tests/expectations/transparent.tag.pyx @@ -0,0 +1,40 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct DummyStruct: + pass + + cdef struct EnumWithAssociatedConstantInImpl: + pass + + ctypedef DummyStruct TransparentComplexWrappingStructTuple; + + ctypedef uint32_t TransparentPrimitiveWrappingStructTuple; + + ctypedef DummyStruct TransparentComplexWrappingStructure; + + ctypedef uint32_t TransparentPrimitiveWrappingStructure; + + ctypedef DummyStruct TransparentComplexWrapper_i32; + + ctypedef uint32_t TransparentPrimitiveWrapper_i32; + + ctypedef uint32_t TransparentPrimitiveWithAssociatedConstants; + const TransparentPrimitiveWithAssociatedConstants TransparentPrimitiveWithAssociatedConstants_ZERO = 0; + const TransparentPrimitiveWithAssociatedConstants TransparentPrimitiveWithAssociatedConstants_ONE = 1; + + const TransparentPrimitiveWrappingStructure EnumWithAssociatedConstantInImpl_TEN = 10; + + void root(TransparentComplexWrappingStructTuple a, + TransparentPrimitiveWrappingStructTuple b, + TransparentComplexWrappingStructure c, + TransparentPrimitiveWrappingStructure d, + TransparentComplexWrapper_i32 e, + TransparentPrimitiveWrapper_i32 f, + TransparentPrimitiveWithAssociatedConstants g, + EnumWithAssociatedConstantInImpl h); diff --git a/tests/expectations/typedef.pyx b/tests/expectations/typedef.pyx new file mode 100644 index 0000000..ba0cc6e --- /dev/null +++ b/tests/expectations/typedef.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo_i32__i32: + int32_t x; + int32_t y; + + ctypedef Foo_i32__i32 IntFoo_i32; + + void root(IntFoo_i32 a); diff --git a/tests/expectations/typedef.tag.pyx b/tests/expectations/typedef.tag.pyx new file mode 100644 index 0000000..76ef246 --- /dev/null +++ b/tests/expectations/typedef.tag.pyx @@ -0,0 +1,15 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo_i32__i32: + int32_t x; + int32_t y; + + ctypedef Foo_i32__i32 IntFoo_i32; + + void root(IntFoo_i32 a); diff --git a/tests/expectations/union.pyx b/tests/expectations/union.pyx new file mode 100644 index 0000000..9f167b5 --- /dev/null +++ b/tests/expectations/union.pyx @@ -0,0 +1,20 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Opaque: + pass + + ctypedef union Normal: + int32_t x; + float y; + + ctypedef union NormalWithZST: + int32_t x; + float y; + + void root(Opaque *a, Normal b, NormalWithZST c); diff --git a/tests/expectations/union.tag.pyx b/tests/expectations/union.tag.pyx new file mode 100644 index 0000000..42c5454 --- /dev/null +++ b/tests/expectations/union.tag.pyx @@ -0,0 +1,20 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Opaque: + pass + + cdef union Normal: + int32_t x; + float y; + + cdef union NormalWithZST: + int32_t x; + float y; + + void root(Opaque *a, Normal b, NormalWithZST c); diff --git a/tests/expectations/union_self.pyx b/tests/expectations/union_self.pyx new file mode 100644 index 0000000..e4711a6 --- /dev/null +++ b/tests/expectations/union_self.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + ctypedef struct Foo_Bar: + const int32_t *something; + + ctypedef union Bar: + int32_t something; + Foo_Bar subexpressions; + + void root(Bar b); diff --git a/tests/expectations/union_self.tag.pyx b/tests/expectations/union_self.tag.pyx new file mode 100644 index 0000000..9d4eb75 --- /dev/null +++ b/tests/expectations/union_self.tag.pyx @@ -0,0 +1,16 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct Foo_Bar: + const int32_t *something; + + cdef union Bar: + int32_t something; + Foo_Bar subexpressions; + + void root(Bar b); diff --git a/tests/expectations/using_namespaces.pyx b/tests/expectations/using_namespaces.pyx new file mode 100644 index 0000000..133a763 --- /dev/null +++ b/tests/expectations/using_namespaces.pyx @@ -0,0 +1,9 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void root(); diff --git a/tests/expectations/va_list.pyx b/tests/expectations/va_list.pyx new file mode 100644 index 0000000..a692808 --- /dev/null +++ b/tests/expectations/va_list.pyx @@ -0,0 +1,9 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + int32_t va_list_test(va_list ap); diff --git a/tests/expectations/workspace.pyx b/tests/expectations/workspace.pyx new file mode 100644 index 0000000..32d2163 --- /dev/null +++ b/tests/expectations/workspace.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t EXT_CONST = 0; + + ctypedef struct ExtType: + uint32_t data; + + void consume_ext(ExtType _ext); diff --git a/tests/expectations/workspace.tag.pyx b/tests/expectations/workspace.tag.pyx new file mode 100644 index 0000000..96a7f5c --- /dev/null +++ b/tests/expectations/workspace.tag.pyx @@ -0,0 +1,14 @@ +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const int32_t EXT_CONST = 0; + + cdef struct ExtType: + uint32_t data; + + void consume_ext(ExtType _ext); diff --git a/tests/rust/body.cython.toml b/tests/rust/body.cython.toml new file mode 100644 index 0000000..0248608 --- /dev/null +++ b/tests/rust/body.cython.toml @@ -0,0 +1,17 @@ +[export.body] +"MyCLikeEnum" = """ + BogusVariantForSerializationForExample, +""" + +"MyUnion" = """ + int32_t extra_member; # yolo +""" + +[export.pre_body] +"MyCLikeEnum_Prepended" = """ + BogusVariantForSerializationForExample, +""" + +"MyUnion_Prepended" = """ + int32_t extra_member; # yolo +""" diff --git a/tests/rust/box.cython.toml b/tests/rust/box.cython.toml new file mode 100644 index 0000000..7748f8a --- /dev/null +++ b/tests/rust/box.cython.toml @@ -0,0 +1,10 @@ +# header = """ +# #ifdef __cplusplus +# template +# using Box = T*; +# #endif +# """ +[export] +exclude = [ + "Box", +] diff --git a/tests/rust/cfg.cython.toml b/tests/rust/cfg.cython.toml new file mode 100644 index 0000000..e3e5b08 --- /dev/null +++ b/tests/rust/cfg.cython.toml @@ -0,0 +1,15 @@ +header = """ +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +DEF X11 = 0 +DEF M_32 = 0 +""" + +[defines] +"unix" = "PLATFORM_UNIX" +"windows" = "PLATFORM_WIN" +"x11" = "X11" +"target_pointer_width = 32" = "M_32" + +[export] +exclude = ["C"] # conditional compilation is not supported for enumerators diff --git a/tests/rust/cfg_2.cython.toml b/tests/rust/cfg_2.cython.toml new file mode 100644 index 0000000..98f1e6e --- /dev/null +++ b/tests/rust/cfg_2.cython.toml @@ -0,0 +1,9 @@ +header = """ +DEF DEFINED = 1 +DEF NOT_DEFINED = 0 +""" + +[defines] +"unix" = "DEFINED" +"macos" = "NOT_DEFINED" +"windows" = "NOT_DEFINED" diff --git a/tests/rust/constant.cython.toml b/tests/rust/constant.cython.toml new file mode 100644 index 0000000..2d2acf4 --- /dev/null +++ b/tests/rust/constant.cython.toml @@ -0,0 +1,5 @@ +[export] +exclude = [ + "XFALSE", # right hand side crashes Cython compiler + "XTRUE", # right hand side crashes Cython compiler +] diff --git a/tests/rust/custom_header.cython.toml b/tests/rust/custom_header.cython.toml new file mode 100644 index 0000000..a237c7d --- /dev/null +++ b/tests/rust/custom_header.cython.toml @@ -0,0 +1,5 @@ +no_includes = true +header = "# This file is generated by cbindgen. DO NOT EDIT" +trailer = """ +# This is a simple test to ensure that trailers don't cause extra newlines in files +""" diff --git a/tests/rust/enum.cython.toml b/tests/rust/enum.cython.toml new file mode 100644 index 0000000..e69de29 diff --git a/tests/rust/enum_discriminant.cython.toml b/tests/rust/enum_discriminant.cython.toml new file mode 100644 index 0000000..9cf3349 --- /dev/null +++ b/tests/rust/enum_discriminant.cython.toml @@ -0,0 +1,2 @@ +[export] +exclude = ["root_no_cython"] diff --git a/tests/rust/enum_discriminant.rs b/tests/rust/enum_discriminant.rs index a8735bf..fbf2733 100644 --- a/tests/rust/enum_discriminant.rs +++ b/tests/rust/enum_discriminant.rs @@ -7,9 +7,16 @@ enum E { C = 1 + 2, D = FOUR, F = (5), - G = '6' as i8, - H = false as i8, +} + +#[repr(i8)] +enum E_NoCython { + G = '6' as i8, // Not supported + H = false as i8, // Not supported } #[no_mangle] pub extern "C" fn root(_: &E) {} + +#[no_mangle] +pub extern "C" fn root_no_cython(_: &E_NoCython) {} diff --git a/tests/rust/exclude_generic_monomorph.cython.toml b/tests/rust/exclude_generic_monomorph.cython.toml new file mode 100644 index 0000000..fbcb05d --- /dev/null +++ b/tests/rust/exclude_generic_monomorph.cython.toml @@ -0,0 +1,9 @@ +header = """ +from libc.stdint cimport uint64_t +ctypedef uint64_t Option_Foo +""" + +[export] +exclude = [ + "Option_Foo", +] diff --git a/tests/rust/manuallydrop.cython.toml b/tests/rust/manuallydrop.cython.toml new file mode 100644 index 0000000..6b8ba3d --- /dev/null +++ b/tests/rust/manuallydrop.cython.toml @@ -0,0 +1,4 @@ +[export] +exclude = [ + "ManuallyDrop", +] diff --git a/tests/rust/maybeuninit.cython.toml b/tests/rust/maybeuninit.cython.toml new file mode 100644 index 0000000..35b5ca8 --- /dev/null +++ b/tests/rust/maybeuninit.cython.toml @@ -0,0 +1,4 @@ +[export] +exclude = [ + "MaybeUninit", +] diff --git a/tests/rust/mod_attr.cython.toml b/tests/rust/mod_attr.cython.toml new file mode 100644 index 0000000..d64a97a --- /dev/null +++ b/tests/rust/mod_attr.cython.toml @@ -0,0 +1,9 @@ +header = """ +DEF FOO = 0 +DEF BAR = 0 +""" + +[defines] +"foo" = "FOO" +"bar" = "BAR" +# "feature = foobar" = "FOOBAR" diff --git a/tests/rust/opaque.cython.toml b/tests/rust/opaque.cython.toml new file mode 100644 index 0000000..e69de29 diff --git a/tests/rust/prefix.cython.toml b/tests/rust/prefix.cython.toml new file mode 100644 index 0000000..0360704 --- /dev/null +++ b/tests/rust/prefix.cython.toml @@ -0,0 +1,5 @@ +[export] +prefix = "PREFIX_" +exclude = [ + "Y", # right hand side crashes Cython compiler +] diff --git a/tests/rust/rename_crate.cython.toml b/tests/rust/rename_crate.cython.toml new file mode 100644 index 0000000..eb8c79f --- /dev/null +++ b/tests/rust/rename_crate.cython.toml @@ -0,0 +1,8 @@ +header = """ +DEF DEFINE_FREEBSD = 0 +""" + +[parse] +parse_deps = true +[defines] +"target_os = freebsd" = "DEFINE_FREEBSD" diff --git a/tests/rust/swift_name.cython.toml b/tests/rust/swift_name.cython.toml new file mode 100644 index 0000000..1de9501 --- /dev/null +++ b/tests/rust/swift_name.cython.toml @@ -0,0 +1,9 @@ +header = "#define CF_SWIFT_NAME(_name) __attribute__((swift_name(#_name)))" + +[fn] +swift_name_macro = "CF_SWIFT_NAME" + +[export] +exclude = [ + "PointerToOpaque_sayHello", # has postfix with a C-style comment incompatible with Cython +] diff --git a/tests/tests.rs b/tests/tests.rs index aadda52..f39dab3 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -33,16 +33,25 @@ fn run_cbindgen( command.arg("--cpp-compat"); } } + Language::Cython => { + command.arg("--lang").arg("cython"); + } } if let Some(style) = style { command.arg("--style").arg(style_str(style)); } - let mut config = path.clone().to_path_buf(); - config.set_extension("toml"); - if config.exists() { - command.arg("--config").arg(config); + let config_exts = match language { + Language::Cython => &["cython.toml", "toml"][..], + _ => &["toml"], + }; + for config_ext in config_exts { + let config = path.with_extension(config_ext); + if config.exists() { + command.arg("--config").arg(config); + break; + } } command.arg(path); @@ -69,6 +78,7 @@ fn compile( let cc = match language { Language::Cxx => env::var("CXX").unwrap_or_else(|_| "g++".to_owned()), Language::C => env::var("CC").unwrap_or_else(|_| "gcc".to_owned()), + Language::Cython => env::var("CYTHON").unwrap_or_else(|_| "cython".to_owned()), }; let file_name = cbindgen_output @@ -78,45 +88,58 @@ fn compile( object.set_extension("o"); let mut command = Command::new(cc); - command.arg("-D").arg("DEFINED"); - command.arg("-I").arg(tests_path); - command.arg("-Wall"); - if !skip_warning_as_error { - command.arg("-Werror"); - } - // `swift_name` is not recognzied by gcc. - command.arg("-Wno-attributes"); - // clang warns about unused const variables. - command.arg("-Wno-unused-const-variable"); - // clang also warns about returning non-instantiated templates (they could - // be specialized, but they're not so it's fine). - command.arg("-Wno-return-type-c-linkage"); - if let Language::Cxx = language { - // enum class is a c++11 extension which makes g++ on macos 10.14 error out - // inline variables are are a c++17 extension - command.arg("-std=c++17"); - // Prevents warnings when compiling .c files as c++. - command.arg("-x").arg("c++"); - if let Ok(extra_flags) = env::var("CXXFLAGS") { - command.args(extra_flags.split_whitespace()); + match language { + Language::Cxx | Language::C => { + command.arg("-D").arg("DEFINED"); + command.arg("-I").arg(tests_path); + command.arg("-Wall"); + if !skip_warning_as_error { + command.arg("-Werror"); + } + // `swift_name` is not recognzied by gcc. + command.arg("-Wno-attributes"); + // clang warns about unused const variables. + command.arg("-Wno-unused-const-variable"); + // clang also warns about returning non-instantiated templates (they could + // be specialized, but they're not so it's fine). + command.arg("-Wno-return-type-c-linkage"); + if let Language::Cxx = language { + // enum class is a c++11 extension which makes g++ on macos 10.14 error out + // inline variables are are a c++17 extension + command.arg("-std=c++17"); + // Prevents warnings when compiling .c files as c++. + command.arg("-x").arg("c++"); + if let Ok(extra_flags) = env::var("CXXFLAGS") { + command.args(extra_flags.split_whitespace()); + } + } else { + if let Ok(extra_flags) = env::var("CFLAGS") { + command.args(extra_flags.split_whitespace()); + } + } + + if let Some(style) = style { + command.arg("-D"); + command.arg(format!( + "CBINDGEN_STYLE_{}", + style_str(style).to_uppercase() + )); + } + + command.arg("-o").arg(&object); + command.arg("-c").arg(cbindgen_output); } - } else { - if let Ok(extra_flags) = env::var("CFLAGS") { - command.args(extra_flags.split_whitespace()); + Language::Cython => { + command.arg("-Wextra"); + if !skip_warning_as_error { + command.arg("-Werror"); + } + command.arg("-3"); + command.arg("-o").arg(&object); + command.arg(cbindgen_output); } } - if let Some(style) = style { - command.arg("-D"); - command.arg(format!( - "CBINDGEN_STYLE_{}", - style_str(style).to_uppercase() - )); - } - - command.arg("-o").arg(&object); - command.arg("-c").arg(cbindgen_output); - println!("Running: {:?}", command); let out = command.output().expect("failed to compile"); assert!(out.status.success(), "Output failed to compile: {:?}", out); @@ -154,6 +177,10 @@ fn run_compile_test( Language::Cxx => ".cpp", Language::C if cpp_compat => ".compat.c", Language::C => ".c", + // cbindgen is supposed to generate declaration files (`.pxd`), but `cython` compiler + // is extension-sensitive and won't work on them, so we use implementation files (`.pyx`) + // in the test suite. + Language::Cython => ".pyx", }; let skip_warning_as_error = name.rfind(SKIP_WARNING_AS_ERROR_SUFFIX).is_some(); @@ -248,6 +275,21 @@ fn test_file(cbindgen_path: &'static str, name: &'static str, filename: &'static None, &mut HashSet::new(), ); + + // `Style::Both` should be identical to `Style::Tag` for Cython. + let mut cbindgen_outputs = HashSet::new(); + for style in &[Style::Type, Style::Tag] { + run_compile_test( + cbindgen_path, + name, + &test, + tmp_dir, + Language::Cython, + /* cpp_compat = */ false, + Some(*style), + &mut cbindgen_outputs, + ); + } } macro_rules! test_file {