Skip to content

Commit

Permalink
Fix owned opaque in out struct (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Jan 15, 2025
1 parent c94ac61 commit 22aa043
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 21 deletions.
4 changes: 4 additions & 0 deletions core/src/hir/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl<Owner: OpaqueOwner> OpaquePath<Optional, Owner> {
pub fn is_optional(&self) -> bool {
self.optional.0
}

pub fn is_owned(&self) -> bool {
self.owner.is_owned()
}
}

impl<Owner: OpaqueOwner> OpaquePath<NonOptional, Owner> {
Expand Down
2 changes: 1 addition & 1 deletion feature_tests/cpp/include/OptionStruct.hpp

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

1 change: 0 additions & 1 deletion feature_tests/cpp/tests/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ int main(int argc, char *argv[]) {
simple_assert("new_struct_nones() returns None", !s.a);
simple_assert("new_struct_nones() returns None", !s.b);
simple_assert_eq("correct struct returned", s.c, 908);
simple_assert("new_struct_nones() returns None", !s.d);

auto opt_u8 = OptionOpaque::accepts_option_u8(std::nullopt);
simple_assert("accepts_option_u8 is idempotent", !opt_u8.has_value());
Expand Down
6 changes: 3 additions & 3 deletions feature_tests/dart/lib/src/OptionStruct.g.dart

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

1 change: 0 additions & 1 deletion feature_tests/dart/test/option_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void main() {
expect(sn.a, null);
expect(sn.b, null);
expect(sn.c, 908);
expect(sn.d, null);

var maybeU8 = OptionOpaque.acceptsOptionU8(null);
expect(maybeU8, null);
Expand Down
2 changes: 1 addition & 1 deletion feature_tests/js/api/OptionStruct.d.ts

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

6 changes: 3 additions & 3 deletions feature_tests/js/api/OptionStruct.mjs

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

1 change: 0 additions & 1 deletion feature_tests/js/test/option.mts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ test("Verify option methods", t => {
t.assert(!sn.a);
t.assert(!sn.b);
t.is(sn.c, 908);
t.assert(!sn.d);
});

test("DiplomatOption tests", t => {
Expand Down

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

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

6 changes: 3 additions & 3 deletions feature_tests/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub mod ffi {
a: Option<Box<OptionOpaque>>,
b: Option<Box<OptionOpaqueChar>>,
c: u32,
d: Option<Box<OptionOpaque>>,
d: Box<OptionOpaque>,
}

#[diplomat::attr(not(supports = option), disable)]
Expand Down Expand Up @@ -101,7 +101,7 @@ pub mod ffi {
a: Some(Box::new(OptionOpaque(101))),
b: Some(Box::new(OptionOpaqueChar('餐'))),
c: 904,
d: Some(Box::new(OptionOpaque(926535))),
d: Box::new(OptionOpaque(926535)),
}
}

Expand All @@ -110,7 +110,7 @@ pub mod ffi {
a: None,
b: None,
c: 908,
d: None,
d: Box::new(OptionOpaque(926535)),
}
}

Expand Down
1 change: 1 addition & 0 deletions tool/src/cpp/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ impl<'ccx, 'tcx: 'ccx> TyGenContext<'ccx, 'tcx, '_> {
Type::Opaque(ref op) if op.is_optional() => {
format!("{cpp_name} ? {cpp_name}->AsFFI() : nullptr").into()
}
Type::Opaque(ref path) if path.is_owned() => format!("{cpp_name}->AsFFI()").into(),
Type::Opaque(..) => format!("{cpp_name}.AsFFI()").into(),
Type::Struct(..) => format!("{cpp_name}.AsFFI()").into(),
Type::Enum(..) => format!("{cpp_name}.AsFFI()").into(),
Expand Down

0 comments on commit 22aa043

Please sign in to comment.