Граф коммитов

28 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge 75be879708
[ObjCRuntime] Allow a null delegate in Runtime.ReleaseBlockWhenDelegateIsCollected. Fixes #20920. (#20999)
Allow a null delegate in Runtime.ReleaseBlockWhenDelegateIsCollected if the corresponding native pointer is also null.

Fixes https://github.com/xamarin/xamarin-macios/issues/20920.
2024-08-09 14:32:19 +02:00
Rolf Bjarne Kvinge f78af68fb2
[bgen] Add support for binding constructors in protocols. Fixes #14039. (#20583)
Add support for binding constructors in protocols.

Given the api definition:

```cs
[Protocol]
public interface Protocol {
    [Abstract]
    [Export ("init")]
    IntPtr Constructor ();

    [Export ("initWithValue:")]
    IntPtr Constructor (IntPtr value);

    [BindAs ("Create")]
    [Export ("initWithPlanet:")]
    IntPtr Constructor ();
}
```

we're binding it like this:

```cs
[Protocol ("Protocol")]
public interface IProtocol : INativeObject {
    [Export ("init")]
    public static T CreateInstance<T> () where T: NSObject, IProtocol { /* default implementation */ }

    [Export ("initWithValue:")]
    public static T CreateInstance<T> () where T: NSObject, IProtocol { /* default implementation */ }

    [Export ("initWithPlanet:")]
    public static T Create<T> () where T: NSObject, IProtocol { /* default implementation */ }
}
```

Also add documentation and tests.

Fixes https://github.com/xamarin/xamarin-macios/issues/14039.

---------

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
Co-authored-by: Alex Soto <alex@soto.dev>
2024-05-24 11:29:53 +02:00
Rolf Bjarne Kvinge 29633a6231
[generator] Make the block callbacks UnmanagedCallersOnly functions in .NET. (#17741)
This also required updating a manual binding since it poked into
generated internals.

Contributes towards https://github.com/xamarin/xamarin-macios/issues/15783.
2023-03-14 10:08:28 +01:00
Rolf Bjarne Kvinge 8285c08c17
[registrar] Improve support for pointers to value types in exported signatures. (#17608)
This will be required when we make blocks use blittable callbacks, since we'll
have to use pointers in a few cases (because ref/out arguments aren't
blittable).
2023-02-28 11:48:27 +01:00
Rolf Bjarne Kvinge 42c1c66a14
[SceneKit] Fix SCNMatrix4 in .NET. Fixes #15094. (#15160)
When we changed SCNMatrix4 to be column-major instead of row-major in .NET, there
were several other related changes we should have done but didn't do. In particular
we should have made transformation operations based on column-vectors instead of
row-vectors.

In legacy Xamarin, a vector would be transformed by a transformation matrix by doing
matrix multiplication like this:

    [ x y z w] * [ 11 21 31 41 ]
                 | 12 22 32 42 |
                 | 13 23 33 43 |
                 [ 14 24 34 41 ]

In this case the vector is a row-vector, and it's the left operand in the multiplication.
When using column-major matrices, we want to use column-vectors, where the vector
is the right operand, like this:

    [ 11 21 31 41 ] * [ x ]
    | 12 22 32 42 |   | y |
    | 13 23 33 43 |   | z |
    [ 14 24 34 41 ]   [ w ]

This affects numerous APIs in SCNMatrix4, SCNVector3 and SCNVector4:

* The M## fields have been changed to make the first number the column and the
  second number the row, to reflect that it's a column-major matrix (this is
  also how it's defined in the native SCNMatrix4 type).
* Functions that return a transformation matrix have been modified to return column-vector
  transformers. Technically this means that these matrices are transposed compared
  to legacy Xamarin. The functions involved are:
    * CreateFromAxisAngle
    * CreateRotation[X|Y|Z]
    * CreateTranslation
    * CreatePerspectiveFieldOfView
    * CreatePerspectiveOffCenter
    * Rotate
    * LookAt
* Combining two column-vector transforming transformation matrices is done by multiplying
  them in the reverse order, so the Mult function (and the multiplication operator)
  have been modified to multiply the given matrices in the opposite order (this matches
  how the SCNMatrix4Mult function does it). To make things clearer I've changed the
  parameter names for XAMCORE_5_0.
* Functions that transform a vector using a transformation matrix have been modified
  to do a column-vector transformation instead of a row-vector transformation. This
  involves the following functions:
    * SCNVector3.TransformVector
    * SCNVector3.TransformNormal
    * SCNVector3.TransformNormalInverse
    * SCNVector3.TransformPosition
    * SCNVector4.Transform
* Numerous new tests.

Fixes https://github.com/xamarin/xamarin-macios/issues/15094.
2022-06-17 20:17:05 +02:00
Rolf Bjarne Kvinge d15f683500
[tests] Add a performance test using BenchmarkDotNet. (#11298) 2021-04-23 13:29:06 +02:00
michizhou e9b18d4c2f [CoreFoundation] [tests] Add new DispatchQueue overloaded method (#7343)
* [CoreFoundation] [tests] Add new DispatchQueue overloaded method with unit tests. Fixes #6783

* [CoreFoundation] [tests] Add new variant method to DispatchQueue

* [CoreFoundation] [tests] Remove nonexistent DispatchQueue methods

* [CoreFoundation] [tests] Restore existing methods and tests
2019-11-12 14:56:45 +01:00
Rolf Bjarne Kvinge 678a422604
[registrar] Ignore method encodings when processing copyback arguments in the dynamic registrar. Fixes #6883. (#6904)
Method encodings do not change anything for us, so skip them when processing
copyback arguments so that they don't confuse the rest of the code.

Fixes https://github.com/xamarin/xamarin-macios/issues/6883.
2019-09-04 07:02:33 -07:00
Rolf Bjarne Kvinge b51aaf4b8b [tests] Add tests for out/ref parameters. 2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge 18b13ac876
[runtime] Use mono_array_setref instead of mono_array_set. (#5782)
* [Foundation] Add an NSArray.FromNSObjects overload that can take an array of INativeObjects.

* [runtime] Use mono_array_setref instead of mono_array_set.

Otherwise the GC won't know about the assignment, and the assigned value can
be freed if it's no longer referenced anywhere else.
2019-03-18 15:00:32 +01:00
Rolf Bjarne Kvinge bd32b74347
Add support for delegates as return values in protocol members. Fixes #4102. (#4758)
* Add support for delegates as return values in protocol members. Fixes #4102.

This required a few changes:

* The generator now emits the DelegateProxy attribute for property getters in
  protocol interfaces.
* The generator now emits the DelegateProxy attribute in ProtocolMember
  attributes (and the ProtocolMember attribute has been extended with
  additional properties for this purpose).
* The generator now emits the BlockProxy attribute for the parameter in
  property setters.
* The generator now emits the BlockProxy attribute in ProtocolMember
  attributes for property setters.
* The static registrar now emits the metadata token for the
  DelegateProxy.DelegateType property into the generated code so that the
  DelegateProxy attribute itself isn't needed at runtime. This is required
  when the dynamic registrar has been optimized away.

Fixes https://github.com/xamarin/xamarin-macios/issues/4102.

* [tests] Update MX4105 test to expect new warnings.
2018-09-06 16:20:23 +02:00
Rolf Bjarne Kvinge 0a24bd603d
[runtime] Always release blocks on the main thread. Fixes #4130. (#4312)
Fixes https://github.com/xamarin/xamarin-macios/issues/4130.
2018-06-29 10:42:25 +02:00
Rolf Bjarne Kvinge 10481fcf62
[runtime] Don't throw exceptions when checking if a token reference exists (and not finding any). Fixes #3830. (#3995)
* [runtime] Don't throw exceptions when checking if a token reference exists (and not finding any). Fixes #3830.

It's not necessarily bad to not be able to find a token reference for a class:
in particular not if we're just checking if a token reference exists. In this
case, don't throw any exceptions, so that the fall-back code path (if no token
references were found) can execute properly.

This scenario occurs when all the following are true:

* The runtime runs into a native object that is exposed in managed as a protocol.
* The native type's managed type does not implement the protocol.
* The dynamic registrar is being used.

Fixes https://github.com/xamarin/xamarin-macios/issues/3830.
2018-04-27 11:33:33 +02:00
Rolf Bjarne Kvinge 1206b868c2
[runtime] Don't lock while calling selectors that can up calling managed code. Fixes #3943. (#3979)
* [runtime] Don't lock while calling selectors that can up calling managed code. Fixes #3943.

Instead of locking the framework peer lock while we call release on dying
object, we just lock and then immediately unlock again before calling release.

This enforces an execution order that still strong enough to not run into race
conditions, while at the same time not running into deadlocks.

Fixes https://github.com/xamarin/xamarin-macios/issues/3943.
2018-04-27 07:40:03 +02:00
Rolf Bjarne Kvinge 5272ede1b9
[generator/registrar] Add support for blocks in static protocol members. Fixes #41226. (#3763)
Add support for blocks in static protocol members by adding another field to
the [ProtocolMember] attribute that specifies the block proxy type.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=41226.
2018-03-16 23:01:56 +01:00
Rolf Bjarne Kvinge 2fe44b9890
[ObjCRuntime] Don't double-retain blocks. (#3717)
* [ObjCRuntime] Don't double-retain blocks.

First there was darkness; no blocks were retained.

Then came the light; and all blocks were retained [1]

Forever.

But all that once is, must one day not be,
and thus the light gave way to darkness,
and blocks were only retained as long as need be [2].

But before there was a balance, there was a crossroad.

In some places the light shone forever,
and all blocks were retained.

In other places there was a balance,
and the light shone only as long as needed.

A desire to unify arose.

Alas, it could not be.

It was a bright and sunny day

When a merge failed [3].

And all blocks were retained. Twice.

Once [here][4] and once [there][5].

For many years we could not see.

Until a dark and rainy night,
when an awareness arose.

And the desire to unify the balance could finally be fulfilled.

[1]: 6efca92acb
[2]: a22f877539
[3]: befa0477cf
[4]: 5158a3c001/src/ObjCRuntime/Runtime.cs (L858)
[5]: 5158a3c001/runtime/runtime.m (L2091)

* [tests] Fix test builds.

* [monotouch-test] RegistrarTest.BlockCollection: allocate more and wait longer for the GC.

Allocate more objects and wait longer for the GC to run.

Hopefully fixes this problem:

    	[FAIL] RegistrarTest.BlockCollection :   freed blocks
      Expected: greater than 0
      But was:  0

The blocks are freed if we just wait long enough... The problem is that we
don't want to wait very long (makes the tests slow to run), so try to speed
things up by allocating more.
2018-03-13 12:30:32 +01:00
Rolf Bjarne Kvinge b131a54be5
[static registrar] Optimize creation of delegates for blocks. (#3623)
* [static registrar] Optimize creation of delegates for blocks.

Optimize creation of delegates for blocks so that it doesn't require the
dynamic registrar.

This is done by getting the metadata token for the Create method that creates
the delegate, and embed that metadata token in the generated code from the
static registrar.

Also add tests, since this scenario was not covered by tests already.

* [mmptest] Fix test after recent changes.

* [test-libraries] Avoid duplicate symbols.

* [tests] Update according to changes.
2018-03-02 14:30:18 +01:00
Rolf Bjarne Kvinge 97230c28e1
Optimize calls to BlockLiteral.SetupBlock to inject the block signature. (#3391)
* [linker] Optimize calls to BlockLiteral.SetupBlock to inject the block signature.

Optimize calls to BlockLiteral.SetupBlock[Unsafe] to calculate the block
signature at build time, and inject it into the call site.

This makes block invocations 10-15x faster (I've added tests that asserts at
least an 8x increase).

It's also required in order to be able to remove the dynamic registrar code in
the future (since calculating the block signature at runtime requires the
dynamic registrar).

* [mtouch/mmp] Add support for reporting errors/warnings that point to the code line causing the error/warning.

Add support for reporting errors/warnings that point to the code line causing
the error/warning by adding ErrorHelper overloads that take the exact
instruction to report (previously we defaulted to the first line/instruction
in a method).

* [tests] Add support for asserting filename/linenumber in warning messages.

* Make all methods that manually create BlockLiterals optimizable.

* [tests] Create a BaseOptimizeGeneratedCodeTest test that's included in both XI's and XM's link all test.

* [tests] Add link all test (for both XI and XM) to test the BlockLiteral.SetupBlock optimization.

* [tests] Add mtouch/mmp tests for the BlockLiteral.SetupBlock optimization.

* [tests][linker] Make the base test class abstract, so tests in the base class aren't executed twice.

* [tests][linker] Don't execute linkall-only tests in linksdk.

The optimization tests only apply when the test assembly is linked, and that
only happens in linkall, so exclude those tests in linksdk.

* [tests][mmptest] Update test according to mmp changes.

Fixes these test failures:

    1) Failed : Xamarin.MMP.Tests.MMPTests.MM0132("inline-runtime-arch")
    The warning 'MM0132: Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.' was not found in the output:
    	Message #1 did not match:
    		actual:   'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
    		expected: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
    	Message #2 did not match:
    		actual:   'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
    		expected: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'

    2) Failed : Xamarin.MMP.Tests.MMPTests.MM0132("foo")
    The warning 'MM0132: Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.' was not found in the output:
    	Message #1 did not match:
    		actual:   'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
    		expected: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
    	Message #2 did not match:
    		actual:   'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
    		expected: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'

* [tests][linker] Fix typo.

Fixes this test failure:

    1) SetupBlock_CustomDelegate (Linker.Shared.BaseOptimizeGeneratedCodeTest.SetupBlock_CustomDelegate)
         Counter
      Expected: 1
      But was:  2

* [registrar] Minor adjustment to error message to match previous (and better) behavior.

Fixes this test failure:

    1) Failed : Xamarin.Registrar.GenericType_WithInvalidParameterTypes
    The error 'MT4136: The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<U>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)'' was not found in the output:
    	Message #1 did not match:
    		actual:   'The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<Foundation.NSObject>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)''
    		expected: 'The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<U>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)''

* [docs] mmp shows MM errors/warnings.

* [docs] Improve according to reviews.

* [tests] Fix merge failure causing test duplication.
2018-02-06 07:08:15 +01:00
Rolf Bjarne Kvinge a979a10412 Merge remote-tracking branch 'origin/master' into bindas-registrar-support 2017-09-22 10:50:07 +02:00
Sebastien Pouliot 05eb96d0a7 Merge branch 'xcode9' into xcode9-master-merge 2017-09-15 11:05:30 -04:00
Rolf Bjarne Kvinge 9fbfd97a8a [AVFoundation] Use Simd-matrix for API that needs it. (#2679)
This also requires implementing the corresponding matrix (NMatrix4x3).

Fixes this xtro issue:

> !unknown-simd-type-in-signature! OpenTK.Matrix3 AVFoundation.AVCameraCalibrationData::get_GetIntrinsicMatrix(): the native signature has a simd type (matrix_float3x3), while the corresponding managed method is using an incorrect (non-simd) type.
2017-09-13 18:46:06 +02:00
Rolf Bjarne Kvinge 788cd94355 [ModelIO] Use the new Simd-compatible matrix types, and deprecate the old API. 2017-08-31 14:03:12 +02:00
Rolf Bjarne Kvinge f2d0a80699 [runtime] Parameters passed on the stack use at least 8 bytes on x86-64. Fixes #58367. (#2393)
* [runtime] Make debug spew compile.

* [tests] Add test case for bug #58367.

https://bugzilla.xamarin.com/show_bug.cgi?id=58367

* [runtime] Parameters passed on the stack use at least 8 bytes on x86-64. Fixes #58367.

https://bugzilla.xamarin.com/show_bug.cgi?id=58367
2017-08-02 08:26:29 +02:00
Rolf Bjarne Kvinge 2fb35682a2 [tests] Add generated runtime tests for the BindAs attribute. 2017-07-04 07:35:28 +02:00
Rolf Bjarne Kvinge d395e8df59 [tests] Generate some trampoline and registrar tests.
Generate trampoline and registrar tests that tests if a return type requires objc_msgSend or objc_msgSend_stret.

Now it's much easier to test new return types (a single line of code), which
avoids a _lot_ of copy-pasting, and makes sure all the different variations
are tested properly.

These new tests found several bugs, which are fixed in subsequent commits.
2016-10-13 15:10:43 +02:00
Rolf Bjarne Kvinge db68e69a1d [runtime] Support binding NSObjects as IntPtr. Fixes #41132. (#103)
Support binding NSObjects as IntPtr. This is usually not
a problem, because when we fetch the ObjC signature for a
method, we usually get the signature as exported by us,
(in which case a parameter bound as 'IntPtr' would be treated
as 'void *' in the dynamic registrar) *except* when the
selector corresponds with a protocol the type implements,
in which case we get the signature as defined in the protocol.

https://bugzilla.xamarin.com/show_bug.cgi?id=41132
2016-05-31 11:58:27 +02:00
Rolf Bjarne Kvinge 1f1f6991a3 Implement support for exception marshalling. 2016-05-17 11:23:48 +02:00
Rolf Bjarne Kvinge 842a86cb0d [tests] Add test-libraries. 2016-04-26 08:00:35 -04:00