Skip to content

Commit

Permalink
Merge pull request #959 from gircore/fix-boxed-wrapper-for-opaque-typ…
Browse files Browse the repository at this point in the history
…ed-records

Fix wrapping opaque typed records
  • Loading branch information
badcel authored Oct 11, 2023
2 parents 372b389 + 27bed06 commit 87fc0b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Generation/Generator/Renderer/Public/OpaqueTypedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public partial class {name}
Initialize();
}}
//TODO: This is a workaround constructor as long as we are
//not having https://github.com/gircore/gir.core/issues/397
private {name}(IntPtr ptr, bool ownsHandle) : this(ownsHandle
? new {Model.OpaqueTypedRecord.GetFullyQuallifiedOwnedHandle(record)}(ptr)
: new {Model.OpaqueTypedRecord.GetFullyQuallifiedUnownedHandle(record)}(ptr).OwnedCopy()){{ }}
// Implement this to perform additional steps in the constructor
partial void Initialize();
Expand Down
16 changes: 16 additions & 0 deletions src/Tests/Libs/GirTest-0.1.Tests/OpaqueTypedRecordTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,20 @@ void Callback(OpaqueTypedRecordTester? obj)

called.Should().BeTrue();
}

[TestMethod]
public void SupportsWrapHandle()
{
var recordTester = OpaqueTypedRecordTester.New();

var wrapped = (OpaqueTypedRecordTester) GObject.Internal.BoxedWrapper.WrapHandle(
handle: recordTester.Handle.DangerousGetHandle(),
ownsHandle: false,
gtype: OpaqueTypedRecordTester.GetGType()
);

wrapped.Handle.DangerousGetHandle().Should().Be(recordTester.Handle.DangerousGetHandle());
recordTester.GetRefCount().Should().Be(2);
wrapped.GetRefCount().Should().Be(2);
}
}

0 comments on commit 87fc0b8

Please sign in to comment.