-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3rd party bindings and CMSampleBuffer usage in trampolines #5692
Comments
Myself I lean towards Solution 3. |
I'd say solution #2 with |
Oh I did not think about |
How does the generator handle all the other INativeObject subclasses? I think we should use the same pattern everywhere. |
@rolfbjarne we have some special cases but others generally are called with Other than the reflection performance impact to get the |
I had a look, and this is annoying :/ The default case in the generator is to call the IntPtr constructor directly: https://github.com/xamarin/xamarin-macios/blob/de8276445642e8589382f9c2346036b1bd8f74f8/src/generator.cs#L1634-L1638 However, for CMSampleBuffer we started calling the Turns out that fix is wrong, the correct fix is to make the CMSampleBuffer IntPtr constructor follow our INativeObject pattern like this: internal CMSampleBuffer (IntPtr handle)
: this (handle, false)
{
} and now the CMSampleBuffer special case in the generator can be removed (we'd also have to audit everybody that calls this constructor to make sure we don't start leaking CMSampleBuffers). Now this doesn't solve the problem with third-party bindings, but for that case I think Solution 3 is the best, because I don't like making the |
I don't mind #3. Ideally we would avoid the following 3 situations - but it disqualifies all options ;-)
|
Since we now have #5693 I'll go for Option 3 for now. |
Fixes dotnet#5692 3rd party bindings cannot use the `.ctor(IntPtr, bool)` of `CMSampleBuffer` because it is `private`, they must use `Runtime.GetINativeObject<T> (IntPtr, bool)` instead.
Fixes #5692 3rd party bindings cannot use the `.ctor(IntPtr, bool)` of `CMSampleBuffer` because it is `private`, they must use `Runtime.GetINativeObject<T> (IntPtr, bool)` instead.
Description
We have a report that using
CMSampleBuffer
in delegates on 3rd party bindings throws the following error:Binding code:
This happens because we are special casing
CMSampleBuffer
in our generator and we are manually calling the.ctor(IntPtr, bool)
:https://github.com/xamarin/xamarin-macios/blob/507d37eef68f13aec954121a2d441702bf87864e/src/generator.cs#L1617-L1624
But the
.ctor(IntPtr, bool)
ofCMSampleBuffer
isinternal
so it cannot be used by 3rd party bindings this way:https://github.com/xamarin/xamarin-macios/blob/507d37eef68f13aec954121a2d441702bf87864e/src/CoreMedia/CMSampleBuffer.cs#L67-L74
Posible Solutions
Solution 1
Make the generator use
Runtime.GetINativeObject<T> (IntPtr, bool)
but this adds some overhead other than simply using the.ctor(IntPtr, bool)
and most scenarios whereCMSampleBuffer
is used require speed which leads into the next solution.Solution 2
Turn the
.ctor(IntPtr, bool)
ofCMSampleBuffer
visibilitypublic
but this can lead to potential incorrect usage.Solution 3
Make the generator aware of the 3rd party binding context and special case the the usage of
Runtime.GetINativeObject<T> (IntPtr, bool)
only for 3rd party bindings and keep the current behavior for our bindings.Workaround
Bind the
CMSampleBuffer
asIntPtr
:Then in actual code usage code do:
The text was updated successfully, but these errors were encountered: