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

70 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge 7e8e887d5d
[runtime] Throw exception for condition we don't handle in the dynamic registrar. (#20568)
Throw an exception for a condition we don't handle in the dynamic registrar:
calling a base Objective-C constructor (init method) with arguments. Our
current implementation to call the base Objective-C constructor doesn't handle
any arguments, so if the method actually takes any arguments, those will just
be random memory. In other words: a consistent exception is better than a
random invalid memory access.
2024-05-20 18:57:42 +02:00
Alex Soto 35e2e45e98 [Xcode 13.3] Initial commit to Xcode 13.3 release 2022-03-14 22:54:33 -04:00
Rolf Bjarne Kvinge 249735647a [runtime] Handle NativeHandle as IntPtr when it comes to arguments in the dynamic registrar. 2021-11-26 14:25:19 +01:00
Rolf Bjarne Kvinge 4f28fb2481
[dynamic registrar] Free the return value from mono_signature_get_params and mono_signature_get_return_type. (#11730)
Before:

    There were 258042 MonoObjects created, 235166 MonoObjects freed, so 22876 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204219 MonoObjects freed, so 1585 were not freed. (static registrar)

After:

    There were 258066 MonoObjects created, 246781 MonoObjects freed, so 11285 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204491 MonoObjects freed, so 1313 were not freed. (static registrar)
2021-05-31 08:02:45 +02:00
Rolf Bjarne Kvinge c12cb23414
[dynamic registrar] Out parameters must be released. (#11727)
Before:

    There were 258042 MonoObjects created, 235166 MonoObjects freed, so 22876 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204219 MonoObjects freed, so 1585 were not freed. (static registrar)

After:

    There were 258058 MonoObjects created, 235308 MonoObjects freed, so 22750 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204219 MonoObjects freed, so 1585 were not freed. (static registrar)
2021-05-31 08:01:24 +02:00
Rolf Bjarne Kvinge 022fa9c697
[runtime] Throw a runtime exception instead of execution engine exception. (#11599)
* One less Mono Embedding method used: good for CoreCLR.
* More consistent with the rest of our code / behavior.
2021-05-19 07:34:13 +02:00
Rolf Bjarne Kvinge 39b0ca4934
[runtime] Implement mono_reflection_type_get_type for CoreCLR. (#11513)
This also meant reviewing calling code to make sure that the return value is
released when it should be.
2021-05-12 23:37:40 +02:00
Rolf Bjarne Kvinge 6e9d9b483d
[runtime] Implement mono_array_new and mono_array_length for CoreCLR. (#11515)
* [runtime] Implement mono_array_new for CoreCLR.

* [runtime] Implement mono_array_length for CoreCLR.
2021-05-12 15:21:56 +02:00
Rolf Bjarne Kvinge 88b8c332a7
[runtime] Implement mono_method_get_object for CoreCLR. (#11488)
This also meant reviewing calling code to make sure that the return value is
released when it should be.
2021-05-11 07:21:18 +02:00
Rolf Bjarne Kvinge e4fbc5198b
[runtime] Implement several xamarin_is_class_* variants for CoreCLR. (#11481)
When using the MonoVM, we compare MonoClass instances by pointer. This turns
out a bit complicated for CoreCLR, because our MonoClass instances are not
unique (there can be multiple MonoClass instances that refer to the same
type), so instead implement helper methods that do the comparison. This also
has the benefit of not requiring any memory allocations on CoreCLR.
2021-05-10 23:12:52 +02:00
Rolf Bjarne Kvinge 8fc51f7e8e
[runtime] Implement mono_type_get_object for CoreCLR. (#11484) 2021-05-10 15:38:13 +02:00
Rolf Bjarne Kvinge 1a689d3b14
[runtime] Implement mono_class_from_mono_type for CoreCLR. (#11470) 2021-05-07 15:47:03 +02:00
Rolf Bjarne Kvinge 63db14ec7d
[runtime] Implement mono_method_signature and related signature methods for CoreCLR. (#11465) 2021-05-06 16:19:59 +02:00
Rolf Bjarne Kvinge 8e9f86aad8
[runtime] Implement mono_method_get_class for CoreCLR. (#11389) 2021-04-30 07:53:30 +02:00
Rolf Bjarne Kvinge 655f2f921f
[runtime] Implement xamarin_get_reflection_method_method for CoreCLR. (#11383) 2021-04-30 07:49:25 +02:00
Rolf Bjarne Kvinge 43f1d02dae
[CoreCLR] Implement xamarin_gchandle_get_target. (#11333)
This also meant reviewing calling code to make sure that MonoObject*s are
released when they should be, which meant reviewing every method that returns
a MonoObject*, and release the result.
2021-04-27 14:59:03 +02:00
Rolf Bjarne Kvinge ddf1645748
[runtime] Remove unnecessary cast (#10875) 2021-03-16 15:23:58 +01:00
Rolf Bjarne Kvinge bc340502fe
[runtime] Move parts of NSObject creation from native to managed. (#10869)
Move the creation of an uninitialized NSObject from native to managed, which:

* Removes the need for the mono_object_new Embedding API.
* Removes one location where we write to managed memory from native code (to
  write the handle + flags in the uninitialized NSObject).
* Makes things easier for CoreCLR.
2021-03-16 07:40:19 +01:00
Rolf Bjarne Kvinge 4cfa6928ae
[runtime] Simplify the various print_all_exceptions methods a bit. (#10847)
Unify them into a single one (xamarin_print_all_exceptions), which takes the
GCHandle of the exception to create an NSString representation of.
2021-03-12 07:37:13 +01:00
Rolf Bjarne Kvinge 4854d7b4da
[runtime] Simplify calls to xamarin_create_managed_ref. (#10826)
I don't see why we should avoid calling xamarin_create_managed_ref from
NSObject's managed code, and then immediately call xamarin_create_managed_ref
upon return from NSObject's managed code.

This code is old ([1]), and from my reading of it, there's no specific reason
it was done this way.

Simplify the logic to call xamarin_create_managed_ref from a single place
(NSObject's managed code).

[1]: e59c45d3f9
2021-03-11 08:47:36 +01:00
Rolf Bjarne Kvinge 0e79b58fa8
[registrar] Remove redundant call to xamarin_register_nsobject from the dynamic registrar. (#10817)
The ctor we just called called it already.

Also, the static registrar doesn't have this call, so the dynamic registrar
shouldn't need it either.
2021-03-10 16:49:11 +01:00
Rolf Bjarne Kvinge 598dbc8ae3
Use pointer-sized GCHandles everywhere. (#10597)
* Convert the GCHandles interface from 32-bit ints to pointer size types

This involves:

* Stop using some bits of the GCHandle to store extra flags, instead add an extra
  field to store those flags.
* Define a INVALID_GCHANDLE constant and use it instead of 0/NULL. This is not
  strictly required, but it makes the code more self-documenting.
* Define a GCHandle type (typedef'ed to void*) and change all variables and parameters
  to use it instead of guint32.
* Use our own xamarin_gchandle_* methods (with pointer-sized types) that wraps
  the mono_gchandle_* embedding API (which uses 32-bit types) everywhere.
* Update managed code (registrars, runtime code, etc) accordingly.

* [runtime] Make debug code compile.

* Fix typo.

* Fix signature of xamarin_create_gchandle.

Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
2021-02-11 08:18:38 +01:00
Rolf Bjarne Kvinge fc233a46ad Convert Registrar.WriteUnmanagedDescription to use GCHandle. 2020-05-04 11:31:19 +02:00
Rolf Bjarne Kvinge c25403bb21 Convert Runtime.RegisterNSObject to take a GCHandle. 2020-05-04 11:31:19 +02:00
Rolf Bjarne Kvinge a7d68ddfbc Convert Runtime.GetMethodAndObjectForSelector to use GCHandle. 2020-05-04 11:31:19 +02:00
Manuel de la Pena 3f0985ecac
[Runtime] Move some of the changes back to int. (#7529)
Some of the fixes done for the warnings have breaking changes. Move back
to int and ensure that we do not have any compilation errors (we are
using -Werror).

Fixes: https://github.com/xamarin/xamarin-macios/issues/7509
2019-12-11 22:17:29 -05:00
Sebastien Pouliot 387730516f
[runtime] Clarify size in marshal_return_value calls (#7439)
Static analysis (and any manual review) is easily confused by
`sizeof (id)`, `sizeof (self)` and `sizeof (*self)` when another
argument is `self` and can report false positives (or be missed
or misinterpreted by humans).

This simply clarify that `|` is an encoded pointer and will
be the size of the pointer (varying by architectures)
2019-11-14 14:50:34 +01:00
Manuel de la Pena dc0a877fed
[Runtime] Enable the -Wsign-conversion on trampolines-invoke.m (#7429)
Enable the flag that was disabled via pragmas.

Continuation of PR: https://github.com/xamarin/xamarin-macios/pull/7405
2019-11-14 05:44:51 -05:00
Manuel de la Pena 63ab48e679
[Runtime] Enable the -Wsign-conversion warnings flag and fix some of the warnings. (#7405)
The flag adds a lot (A LOT) of warnings. The diff would be huge and
dangerous to review. We enable the flag and fix file by file.
2019-11-12 15:10:16 -05:00
Manuel de la Pena 2e5b64893f
[Runtime] Enable the -Wshorten-64-to-32 flag and fix all warnings. (#7353)
* [Runtime] Enable the -Wshorten-64-to-32 flag and fix all warnings.

We want to enable the -Wconversion but that will raise too many warning
for a single commit. We are enabiling one by one the flags included in
-Wconversion so that we have smaller diffs.

-Wshorten-64-to-32 adds warnings when there is a implicit conversion that
loses integer precision. We are moving all the 32 to 64 conversions to
use 64. Expecially since most of the code changed is related with sizes,
legths and params counts that are never going to be negative.


Co-Authored-By: Rolf Bjarne Kvinge <rolf@xamarin.com>
2019-11-05 11:00:14 -05:00
Manuel de la Pena 8b45260ee4
[Runtime] Ensure that all comparisons between signed and unsigned values are fixed. (#7339)
Enable the -Wsign-compare which will raise issues when a comparison
between signed and unsigned values could produce an incorrect result
and fix all the raised warnings.
2019-10-30 15:58:13 -04:00
Sebastien Pouliot 6fca42049d
[runtime] Throw a OutOfMemoryException when processing parameters (#7308)
`calloc` can return `null` and we're writing to the memory location
which would crash the process.

An `OutOfMemoryException` is the correct way to handle this (even if
will likely crash the process anyway).
2019-10-25 15:49:22 -04: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 37a280d974
[runtime] Put LOGZ directive in a header to not duplicate it everywhere. (#6001) 2019-05-06 19:29:28 +02:00
Rolf Bjarne Kvinge 6e9afbc605 [registrar] Add support for ref/out arrays. 2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge 87a5b2dac8 [registrar] Fix support for ref string parameters. 2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge af38ac286c [registrar] Fix/implement returning SEL/Class in a ref/out parameter in the registrars. 2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge 7a9cb8372a [registrar] Extract code to create a managed array from an NSArray to a separate method. 2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge ae879324a6 [registrar] Some more simplification. 2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge 02d2dfc60e [registrar] Don't let a failure to copy back a parameter go unnoticed.
Now that we ignore parameters we're not copying back, we can throw an
exception if we run into a parameter we don't know how to copy back.
2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge 5871040bb3 [registrar] Simplify code a bit and reduce indentation.
Best reviewed by ignoring whitespace.
2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge e80f4d5dca [registrar] Simplify copyback loop a little bit.
Simplify by having a single loop variable, and remove the usage of the
other ('ofs'), since it's not needed.
2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge a3278ff178 [registrar] Improve writeback logic for out/ref parameters.
* Keep track of which parameters needs to be written back. This makes sure the
  writeback loop doesn't run into non-writeback-parameters it doesn't know how
  to handle (by skipping them completely).

* Keep track of the (post-marshal) input to the out/ref parameters, so that we
  know whether we need to marshal anything back in the writeback loop.
2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge 9b60eebaef [registrar] Fix multiple ref/out parameters for a single method.
The previous code would break the loop looking for ref/out parameters after finding the first one.
2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge ad4cc04af9 [registrar] Refactor to reduce indentation a bit.
Best viewed by ignoring whitespace.
2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge 509c5be093 [registrar] Create a xamarin_nsstring_to_string to avoid code duplication. 2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge 2b5229fe46 [registrar] Create a xamarin_string_to_nsstring function to avoid code duplication. 2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge fc6b2c0a0d [runtime] Use a 'void*' for the context in conversion functions instead of 'guint32'.
No function changes, just a refactoring to allow for pointers as context.
2019-04-26 11:20:15 +02:00
Rolf Bjarne Kvinge c8ed014af7
[runtime] Improve exception creation. (#5944)
* [runtime] Add an inner exception parameter to Runtime.CreateProductException.

This allows us to simplify code by using inner (and outer) exceptions as
a means to provide information instead of passing extra information
around in order to create decent exceptions.

One example is how we pass the selector and method name to the method
that converts from a native id to a managed NSObject instance: passing
this information is not necessary anymore if we can use two exceptions,
one for the failure to convert from an id to a NSObject instance,
wrapped in a second that tells which method/selector call ran into this
conversion problem.

* [runtime] Throw better exceptions when the dynamic registrar can't marshal something.

* [runtime] Throw a better exception when something goes wrong when trying to marshal a return value.

* [runtime] Use inner exceptions to convey failure information instead of trying to create a single exception with all we know.

* Fix merge problem.
2019-04-26 11:16:23 +02:00
Rolf Bjarne Kvinge 37a4db8335
[registrar] Use the right method to get INativeObject handles. (#5935) 2019-04-23 14:10:51 +01:00