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>
This commit is contained in:
Rolf Bjarne Kvinge 2021-02-11 08:18:38 +01:00 коммит произвёл GitHub
Родитель f76f3f0cec
Коммит 598dbc8ae3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
24 изменённых файлов: 814 добавлений и 625 удалений

Просмотреть файл

@ -40,7 +40,7 @@ namespace ObjCRuntime {
static <#= d.ReturnType.MType #> <#= d.SimpleEntryPoint #> (<#= d.MArgumentSignature #>)
<# if (d.ExceptionHandling) { #>
{
exception_gchandle = 0;
exception_gchandle = IntPtr.Zero;
try {
<# if (string.IsNullOrEmpty (d.WrappedManagedFunction)) { #>
throw new NotImplementedException ();
@ -49,7 +49,7 @@ namespace ObjCRuntime {
<# } #>
} catch (Exception ex) {
var handle = GCHandle.Alloc (ex, GCHandleType.Normal);
exception_gchandle = GCHandle.ToIntPtr (handle).ToInt32 ();
exception_gchandle = GCHandle.ToIntPtr (handle);
<# if (d.SimpleEntryPoint == "get_nsobject_with_type") { #> created = false;
<# } #>
<# if (d.ReturnType.MType != "void") { #> return default (<#= d.ReturnType.MType #>);

Просмотреть файл

@ -27,11 +27,11 @@ struct Delegates {
static struct Delegates delegates = { 0 };
static guint32
static GCHandle
create_linked_away_exception (const char *func)
{
char *msg = xamarin_strdup_printf ("The runtime function %s has been linked away.", func);
guint32 gchandle = xamarin_create_product_exception (8028, msg);
GCHandle gchandle = xamarin_create_product_exception (8028, msg);
xamarin_free (msg);
return gchandle;
}

Просмотреть файл

@ -34,13 +34,13 @@
},
new XDelegate ("void", "void", "xamarin_rethrow_managed_exception",
"guint32", "uint", "original_exception_gchandle"
"GCHandle", "IntPtr", "original_exception_gchandle"
) {
WrappedManagedFunction = "RethrowManagedException",
OnlyDynamicUsage = false,
},
new XDelegate ("int", "int", "xamarin_create_ns_exception",
new XDelegate ("GCHandle", "IntPtr", "xamarin_create_ns_exception",
"NSException *", "IntPtr", "exc"
) {
WrappedManagedFunction = "CreateNSException",
@ -48,7 +48,7 @@
},
new XDelegate ("NSException *", "IntPtr", "xamarin_unwrap_ns_exception",
"uint32_t", "uint", "exc_handle"
"GCHandle", "IntPtr", "exc_handle"
) {
WrappedManagedFunction = "UnwrapNSException",
OnlyDynamicUsage = false,
@ -225,9 +225,9 @@
OnlyDynamicUsage = true,
},
new XDelegate ("guint32", "int", "xamarin_create_product_exception_for_error",
new XDelegate ("GCHandle", "IntPtr", "xamarin_create_product_exception_for_error",
"int", "int", "code",
"guint32", "uint", "inner_exception_gchandle",
"GCHandle", "IntPtr", "inner_exception_gchandle",
"const char *", "string", "message"
) {
WrappedManagedFunction = "CreateProductException",
@ -249,7 +249,7 @@
},
new XDelegate ("enum MarshalManagedExceptionMode", "MarshalManagedExceptionMode", "xamarin_on_marshal_managed_exception",
"int", "int", "exception"
"GCHandle", "IntPtr", "exception"
) {
WrappedManagedFunction = "OnMarshalManagedException",
OnlyDynamicUsage = false,
@ -278,7 +278,7 @@
OnlyDynamicUsage = true,
},
new XDelegate ("int32_t", "int", "xamarin_create_runtime_exception",
new XDelegate ("GCHandle", "IntPtr", "xamarin_create_runtime_exception",
"int32_t", "int", "code",
"const char *", "IntPtr", "message"
) {
@ -487,7 +487,7 @@
if (nameOnly) {
builder.Append (", exception_gchandle");
} else {
builder.Append (", guint32 *exception_gchandle");
builder.Append (", GCHandle *exception_gchandle");
}
}
@ -521,7 +521,7 @@
if (nameOnly) {
// nothing to do
} else {
builder.Append (", out int exception_gchandle");
builder.Append (", out IntPtr exception_gchandle");
}
}

Просмотреть файл

@ -18,6 +18,15 @@
extern "C" {
#endif
/*
* Wrapper GCHandle functions that takes pointer sized handles instead of ints,
* so that we can adapt our code incrementally to use pointers instead of ints
* until Mono's pointer-sized API is available for us.
* Ref: https://github.com/dotnet/runtime/commit/3886a63841434af716292172737a42757a15c6a6
*/
#define INVALID_GCHANDLE NULL
typedef void* GCHandle;
/* This is copied from eglib's header files */
typedef unsigned int guint;
typedef int32_t gboolean;
@ -271,7 +280,9 @@ typedef enum {
/* metadata/marshal.h */
typedef void (*MonoFtnPtrEHCallback) (guint32 gchandle);
// The 'gchandle' parameter is defined as a 'guint32' in mono/mono's 2020-02 branch, and as a 'MonoGCHandle' (aka void*) in mono/mono's main branch.
// Here we go with the latter (void*), because that's the future, and it should also be compatible with the 2020-02 branch.
typedef void (*MonoFtnPtrEHCallback) (GCHandle gchandle);
/* not in any header */
@ -295,14 +306,7 @@ bool
<# } #>
/*
* Wrapper GCHandle functions that takes pointer sized handles instead of ints,
* so that we can adapt our code incrementally to use pointers instead of ints
* until Mono's pointer-sized API is available for us.
* Ref: https://github.com/dotnet/runtime/commit/3886a63841434af716292172737a42757a15c6a6
*/
#define INVALID_GCHANDLE 0
typedef void* GCHandle;
#ifdef __cplusplus
} /* extern "C" */

Просмотреть файл

@ -255,7 +255,7 @@ xamarin_main (int argc, char *argv[], enum XamarinLaunchMode launch_mode)
DEBUG_LAUNCH_TIME_PRINT ("MonoTouch setup time");
MonoAssembly *assembly;
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = NULL;
const char *c_bundle_path = xamarin_get_bundle_path ();
@ -442,12 +442,12 @@ xamarin_main (int argc, char *argv[], enum XamarinLaunchMode launch_mode)
#if defined (__arm__) || defined(__aarch64__)
xamarin_register_assemblies ();
assembly = xamarin_open_and_register (xamarin_executable_name, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != NULL)
xamarin_process_managed_exception_gchandle (exception_gchandle);
#else
if (xamarin_executable_name) {
assembly = xamarin_open_and_register (xamarin_executable_name, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != NULL)
xamarin_process_managed_exception_gchandle (exception_gchandle);
} else {
const char *last_slash = strrchr (argv [0], '/');
@ -457,13 +457,13 @@ xamarin_main (int argc, char *argv[], enum XamarinLaunchMode launch_mode)
assembly = xamarin_open_and_register (aname, &exception_gchandle);
xamarin_free (aname);
if (exception_gchandle != 0)
if (exception_gchandle != NULL)
xamarin_process_managed_exception_gchandle (exception_gchandle);
}
if (xamarin_supports_dynamic_registration) {
xamarin_register_entry_assembly (mono_assembly_get_object (mono_domain_get (), assembly), &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != NULL)
xamarin_process_managed_exception_gchandle (exception_gchandle);
}
#endif

Просмотреть файл

@ -29,7 +29,7 @@
extern "C" {
#endif
void *xamarin_marshal_return_value (SEL sel, MonoType *mtype, const char *type, MonoObject *retval, bool retain, MonoMethod *method, MethodDescription *desc, guint32 *exception_gchandle);
void *xamarin_marshal_return_value (SEL sel, MonoType *mtype, const char *type, MonoObject *retval, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle);
#ifdef __cplusplus
}
@ -42,11 +42,11 @@ void *xamarin_marshal_return_value (SEL sel, MonoType *mtype, const char *type,
*/
@interface XamarinGCHandle : NSObject {
@public
uint32_t handle;
GCHandle handle;
}
+(XamarinGCHandle *) createWithHandle: (uint32_t) handle;
+(XamarinGCHandle *) createWithHandle: (GCHandle) handle;
-(void) dealloc;
-(uint32_t) getHandle;
-(GCHandle) getHandle;
@end
#endif /* __RUNTIME_INTERNAL_H__ */

Просмотреть файл

@ -122,6 +122,8 @@ struct Trampolines {
#endif
void* get_gchandle_tramp;
void* set_gchandle_tramp;
void* get_flags_tramp;
void* set_flags_tramp;
};
enum InitializationFlags : int {
@ -177,6 +179,8 @@ static struct Trampolines trampolines = {
#endif
(void *) &xamarin_get_gchandle_trampoline,
(void *) &xamarin_set_gchandle_trampoline,
(void *) &xamarin_get_flags_trampoline,
(void *) &xamarin_set_flags_trampoline,
};
static struct InitializationOptions options = { 0 };
@ -268,7 +272,7 @@ xamarin_get_parameter_type (MonoMethod *managed_method, int index)
}
MonoObject *
xamarin_get_nsobject_with_type_for_ptr (id self, bool owns, MonoType* type, guint32 *exception_gchandle)
xamarin_get_nsobject_with_type_for_ptr (id self, bool owns, MonoType* type, GCHandle *exception_gchandle)
{
// COOP: Reading managed data, must be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
@ -278,13 +282,13 @@ xamarin_get_nsobject_with_type_for_ptr (id self, bool owns, MonoType* type, guin
}
MonoObject *
xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *type, int32_t *created, guint32 *exception_gchandle)
xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *type, int32_t *created, GCHandle *exception_gchandle)
{
// COOP: Reading managed data, must be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
MonoObject *mobj = NULL;
uint32_t gchandle = 0;
GCHandle gchandle = INVALID_GCHANDLE;
*created = false;
@ -293,8 +297,8 @@ xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *ty
gchandle = xamarin_get_gchandle (self);
if (gchandle != 0) {
mobj = mono_gchandle_get_target (gchandle);
if (gchandle != INVALID_GCHANDLE) {
mobj = xamarin_gchandle_get_target (gchandle);
if (mono_object_isinst (mobj, mono_class_from_mono_type (type)) != NULL)
return mobj;
}
@ -303,20 +307,20 @@ xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *ty
}
MonoObject *
xamarin_get_managed_object_for_ptr_fast (id self, guint32 *exception_gchandle)
xamarin_get_managed_object_for_ptr_fast (id self, GCHandle *exception_gchandle)
{
// COOP: Reading managed data, must be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
MonoObject *mobj = NULL;
uint32_t gchandle = 0;
GCHandle gchandle = INVALID_GCHANDLE;
gchandle = xamarin_get_gchandle (self);
if (gchandle == 0) {
if (gchandle == INVALID_GCHANDLE) {
mobj = xamarin_try_get_or_construct_nsobject (self, exception_gchandle);
} else {
mobj = mono_gchandle_get_target (gchandle);
mobj = xamarin_gchandle_get_target (gchandle);
#if DEBUG
if (self != xamarin_get_nsobject_handle (mobj)) {
xamarin_assertion_message ("Internal consistency error, please file a bug (https://github.com/xamarin/xamarin-macios/issues/new). Additional data: found managed object %p=%p (%s) in native object %p (%s).\n",
@ -425,7 +429,7 @@ xamarin_is_class_nsstring (MonoClass *cls)
// Returns if a MonoClass is nullable.
// Will also return the element type (it the type is nullable, and if out pointer is not NULL).
bool
xamarin_is_class_nullable (MonoClass *cls, MonoClass **element_type, guint32 *exception_gchandle)
xamarin_is_class_nullable (MonoClass *cls, MonoClass **element_type, GCHandle *exception_gchandle)
{
#ifdef DYNAMIC_MONO_RUNTIME
// mono_class_is_nullable/mono_class_get_nullable_param are private
@ -446,7 +450,7 @@ xamarin_is_class_nullable (MonoClass *cls, MonoClass **element_type, guint32 *ex
MonoReflectionType *nullable_type = (MonoReflectionType *) xamarin_gchandle_unwrap (mono_runtime_invoke (get_nullable_type, NULL, args, &exc));
xamarin_gchandle_free (type_handle);
if (exc != NULL) {
*exception_gchandle = mono_gchandle_new (exc, FALSE);
*exception_gchandle = xamarin_gchandle_new (exc, FALSE);
return false;
}
@ -463,93 +467,144 @@ xamarin_is_class_nullable (MonoClass *cls, MonoClass **element_type, guint32 *ex
}
MonoClass *
xamarin_get_nullable_type (MonoClass *cls, guint32 *exception_gchandle)
xamarin_get_nullable_type (MonoClass *cls, GCHandle *exception_gchandle)
{
MonoClass *rv = NULL;
xamarin_is_class_nullable (cls, &rv, exception_gchandle);
return rv;
}
#define MANAGED_REF_BIT (1u << 31u)
#define GCHANDLE_WEAK (1u << 30u)
#define GCHANDLE_MASK (MANAGED_REF_BIT | GCHANDLE_WEAK)
// The XamarinExtendedObject protocol is just to avoid a
// compiler warning (no 'xamarinGetGChandle' selector found).
@protocol XamarinExtendedObject
-(uint32_t) xamarinGetGCHandle;
-(void) xamarinSetGCHandle: (uint32_t) gc_handle;
-(GCHandle) xamarinGetGCHandle;
-(void) xamarinSetGCHandle: (GCHandle) gc_handle flags: (enum XamarinGCHandleFlags) flags;
-(enum XamarinGCHandleFlags) xamarinGetFlags;
-(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
@end
static inline uint32_t
get_raw_gchandle_safe (id self)
static inline GCHandle
get_gchandle_safe (id self, enum XamarinGCHandleFlags *flags)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_SAFE_OR_DETACHED;
id<XamarinExtendedObject> xself = self;
return (uint32_t) [xself xamarinGetGCHandle];
GCHandle rv = [xself xamarinGetGCHandle];
if (flags)
*flags = [xself xamarinGetFlags];
return rv;
}
static inline uint32_t
get_raw_gchandle (id self)
static inline void
set_gchandle (id self, GCHandle gc_handle, enum XamarinGCHandleFlags flags)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_UNSAFE;
uint32_t rv;
MONO_ENTER_GC_SAFE;
id<XamarinExtendedObject> xself = self;
rv = (uint32_t) [xself xamarinGetGCHandle];
[xself xamarinSetGCHandle: gc_handle flags: flags];
MONO_EXIT_GC_SAFE;
}
static inline GCHandle
get_gchandle_without_flags (id self)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_UNSAFE;
GCHandle rv;
MONO_ENTER_GC_SAFE;
id<XamarinExtendedObject> xself = self;
rv = (GCHandle) [xself xamarinGetGCHandle];
MONO_EXIT_GC_SAFE;
return rv;
}
static inline void
set_raw_gchandle (id self, uint32_t gc_handle)
static inline GCHandle
get_gchandle_with_flags (id self, enum XamarinGCHandleFlags* flags)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_UNSAFE;
GCHandle rv;
MONO_ENTER_GC_SAFE;
id<XamarinExtendedObject> xself = self;
[xself xamarinSetGCHandle: gc_handle];
rv = (GCHandle) [xself xamarinGetGCHandle];
if (flags != NULL)
*flags = [xself xamarinGetFlags];
MONO_EXIT_GC_SAFE;
return rv;
}
static inline enum XamarinGCHandleFlags
get_flags (id self)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_UNSAFE;
enum XamarinGCHandleFlags rv;
MONO_ENTER_GC_SAFE;
id<XamarinExtendedObject> xself = self;
rv = [xself xamarinGetFlags];
MONO_EXIT_GC_SAFE;
return rv;
}
static inline void
set_flags (id self, enum XamarinGCHandleFlags flags)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_UNSAFE;
MONO_ENTER_GC_SAFE;
id<XamarinExtendedObject> xself = self;
[xself xamarinSetFlags: flags];
MONO_EXIT_GC_SAFE;
}
static inline uint32_t
get_gchandle (id self)
static inline enum XamarinGCHandleFlags
get_flags_safe (id self)
{
// COOP: does not access managed memory: any mode
return get_raw_gchandle (self) & ~GCHANDLE_MASK;
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_SAFE_OR_DETACHED;
enum XamarinGCHandleFlags rv;
id<XamarinExtendedObject> xself = self;
rv = [xself xamarinGetFlags];
return rv;
}
uint32_t
GCHandle
xamarin_get_gchandle (id self)
{
// COOP: does not access managed memory: any mode
return get_gchandle (self);
return get_gchandle_without_flags (self);
}
uint32_t
xamarin_get_gchandle_with_flags (id self)
GCHandle
xamarin_get_gchandle_with_flags (id self, enum XamarinGCHandleFlags* flags)
{
// COOP: does not access managed memory: any mode
return get_raw_gchandle (self);
return get_gchandle_with_flags (self, flags);
}
bool
xamarin_has_managed_ref (id self)
{
// COOP: get_raw_gchandle requires UNSAFE mode, so this function requires it too.
return get_raw_gchandle (self) & MANAGED_REF_BIT;
// COOP: get_flags requires UNSAFE mode, so this function requires it too.
return (get_flags (self) & XamarinGCHandleFlags_HasManagedRef) == XamarinGCHandleFlags_HasManagedRef;
}
bool
xamarin_has_managed_ref_safe (id self)
{
// COOP: variation of xamarin_has_managed_ref for SAFE mode.
return get_raw_gchandle_safe (self) & MANAGED_REF_BIT;
return (get_flags_safe (self) & XamarinGCHandleFlags_HasManagedRef) == XamarinGCHandleFlags_HasManagedRef;
}
MonoException *
@ -579,7 +634,7 @@ xamarin_get_reflection_method_method (MonoReflectionMethod *method)
}
id
xamarin_get_handle (MonoObject *obj, guint32 *exception_gchandle)
xamarin_get_handle (MonoObject *obj, GCHandle *exception_gchandle)
{
// COOP: Reads managed memory, needs to be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
@ -602,7 +657,7 @@ xamarin_get_handle (MonoObject *obj, guint32 *exception_gchandle)
mono_class_get_namespace (klass), mono_class_get_name (klass));
MonoException *exc = mono_get_exception_execution_engine (msg);
xamarin_free (msg);
*exception_gchandle = mono_gchandle_new ((MonoObject *) exc, FALSE);
*exception_gchandle = xamarin_gchandle_new ((MonoObject *) exc, FALSE);
}
return rv;
@ -610,7 +665,7 @@ xamarin_get_handle (MonoObject *obj, guint32 *exception_gchandle)
#if DEBUG
static void
verify_cast (MonoClass *to, MonoObject *obj, Class from_class, SEL sel, MonoMethod *method, guint32 *exception_gchandle)
verify_cast (MonoClass *to, MonoObject *obj, Class from_class, SEL sel, MonoMethod *method, GCHandle *exception_gchandle)
{
// COOP: Reads managed memory, needs to be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
@ -632,13 +687,13 @@ verify_cast (MonoClass *to, MonoObject *obj, Class from_class, SEL sel, MonoMeth
mono_free (to_name);
xamarin_free (msg);
mono_free (method_full_name);
*exception_gchandle = mono_gchandle_new ((MonoObject *) mono_ex, FALSE);
*exception_gchandle = xamarin_gchandle_new ((MonoObject *) mono_ex, FALSE);
}
}
#endif
void
xamarin_check_for_gced_object (MonoObject *obj, SEL sel, id self, MonoMethod *method, guint32 *exception_gchandle)
xamarin_check_for_gced_object (MonoObject *obj, SEL sel, id self, MonoMethod *method, GCHandle *exception_gchandle)
{
// COOP: Reads managed memory, needs to be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
@ -660,11 +715,11 @@ xamarin_check_for_gced_object (MonoObject *obj, SEL sel, id self, MonoMethod *me
char *method_full_name = mono_method_full_name (method, TRUE);
char *type_name = xamarin_lookup_managed_type_name ([self class], exception_gchandle);
if (*exception_gchandle == 0) {
if (*exception_gchandle == INVALID_GCHANDLE) {
char *msg = xamarin_strdup_printf (m, self, object_getClassName (self), type_name, sel_getName (sel), method_full_name);
guint32 ex_handle = (guint32) xamarin_create_runtime_exception (8027, msg, exception_gchandle);
GCHandle ex_handle = xamarin_create_runtime_exception (8027, msg, exception_gchandle);
xamarin_free (msg);
if (*exception_gchandle == 0)
if (*exception_gchandle == INVALID_GCHANDLE)
*exception_gchandle = ex_handle;
}
mono_free (type_name);
@ -743,7 +798,7 @@ xamarin_check_objc_type (id obj, Class expected_class, SEL sel, id self, int ind
#endif
char *
xamarin_class_get_full_name (MonoClass *klass, guint32 *exception_gchandle)
xamarin_class_get_full_name (MonoClass *klass, GCHandle *exception_gchandle)
{
// COOP: Reads managed memory, needs to be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
@ -752,7 +807,7 @@ xamarin_class_get_full_name (MonoClass *klass, guint32 *exception_gchandle)
}
char *
xamarin_type_get_full_name (MonoType *type, guint32 *exception_gchandle)
xamarin_type_get_full_name (MonoType *type, GCHandle *exception_gchandle)
{
// COOP: Reads managed memory, needs to be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
@ -773,11 +828,13 @@ gc_register_toggleref (MonoObject *obj, id self, bool isCustomType)
#ifdef DEBUG_TOGGLEREF
id handle = xamarin_get_nsobject_handle (obj);
PRINT ("**Registering object %p handle %p RC %d flags: %i",
PRINT ("**Registering object %p handle %p RC %d flags: %i isCustomType: %i",
obj,
handle,
(int) (handle ? [handle retainCount] : 0),
xamarin_get_nsobject_flags (obj));
xamarin_get_nsobject_flags (obj),
isCustomType
);
#endif
mono_gc_toggleref_add (obj, TRUE);
@ -946,7 +1003,7 @@ xamarin_open_assembly (const char *name)
}
static bool
register_assembly (MonoAssembly *assembly, guint32 *exception_gchandle)
register_assembly (MonoAssembly *assembly, GCHandle *exception_gchandle)
{
// COOP: this is a function executed only at startup, I believe the mode here doesn't matter.
if (!xamarin_supports_dynamic_registration) {
@ -954,11 +1011,11 @@ register_assembly (MonoAssembly *assembly, guint32 *exception_gchandle)
return true;
}
xamarin_register_assembly (mono_assembly_get_object (mono_domain_get (), assembly), exception_gchandle);
return *exception_gchandle == 0;
return *exception_gchandle == INVALID_GCHANDLE;
}
MonoAssembly *
xamarin_open_and_register (const char *aname, guint32 *exception_gchandle)
xamarin_open_and_register (const char *aname, GCHandle *exception_gchandle)
{
// COOP: this is a function executed only at startup, I believe the mode here doesn't matter.
MonoAssembly *assembly;
@ -1129,19 +1186,19 @@ xamarin_print_all_exceptions (MonoObject *exc)
}
void
xamarin_ftnptr_exception_handler (guint32 gchandle)
xamarin_ftnptr_exception_handler (GCHandle gchandle)
{
xamarin_process_managed_exception_gchandle (gchandle);
}
void
xamarin_process_managed_exception_gchandle (guint32 gchandle)
xamarin_process_managed_exception_gchandle (GCHandle gchandle)
{
if (gchandle == 0)
if (gchandle == INVALID_GCHANDLE)
return;
MonoObject *exc = mono_gchandle_get_target (gchandle);
mono_gchandle_free (gchandle);
MonoObject *exc = xamarin_gchandle_get_target (gchandle);
xamarin_gchandle_free (gchandle);
xamarin_process_managed_exception (exc);
}
@ -1273,7 +1330,7 @@ xamarin_initialize ()
MonoAssembly *assembly = NULL;
MonoMethod *runtime_initialize;
void* params[2];
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
MonoObject *exc = NULL;
initialize_started = TRUE;
@ -1727,7 +1784,7 @@ xamarin_objc_type_size (const char *type)
*/
//#define DEBUG_REF_COUNTING
void
xamarin_create_gchandle (id self, void *managed_object, uint32_t flags, bool force_weak)
xamarin_create_gchandle (id self, void *managed_object, enum XamarinGCHandleFlags flags, bool force_weak)
{
// COOP: reads managed memory: unsafe mode
MONO_ASSERT_GC_UNSAFE;
@ -1735,19 +1792,18 @@ xamarin_create_gchandle (id self, void *managed_object, uint32_t flags, bool for
// force_weak is to avoid calling retainCount unless needed, since some classes (UIWebView in iOS 5)
// will crash if retainCount is called before init. See bug #9261.
bool weak = force_weak || ([self retainCount] == 1);
uint32_t gchandle;
GCHandle gchandle;
if (weak) {
gchandle = mono_gchandle_new_weakref ((MonoObject *) managed_object, TRUE);
flags |= GCHANDLE_WEAK;
gchandle = xamarin_gchandle_new_weakref ((MonoObject *) managed_object, TRUE);
flags = (enum XamarinGCHandleFlags) (flags | XamarinGCHandleFlags_WeakGCHandle);
} else {
gchandle = mono_gchandle_new ((MonoObject *) managed_object, FALSE);
flags &= ~GCHANDLE_WEAK;
gchandle = xamarin_gchandle_new ((MonoObject *) managed_object, FALSE);
flags = (enum XamarinGCHandleFlags) (flags & ~XamarinGCHandleFlags_WeakGCHandle);
}
assert ((gchandle & GCHANDLE_MASK) == 0); // Make sure we don't create too many gchandles...
set_raw_gchandle (self, gchandle | flags);
set_gchandle (self, gchandle, flags);
#if defined(DEBUG_REF_COUNTING)
PRINT ("\tGCHandle created for %p: %d (flags: %p) = %d %s\n", self, gchandle, GINT_TO_POINTER (flags), get_raw_gchandle (self), weak ? "weak" : "strong");
PRINT ("\tGCHandle created for %p: %d (flags: %p) = %s managed object: %p\n", self, gchandle, GINT_TO_POINTER (flags), weak ? "weak" : "strong", managed_object);
#endif
}
@ -1757,16 +1813,14 @@ xamarin_switch_gchandle (id self, bool to_weak)
// COOP: reads managed memory: unsafe mode
MONO_ASSERT_GC_SAFE_OR_DETACHED;
uint32_t new_gchandle;
uint32_t old_gchandle;
uint32_t old_gchandle_raw;
GCHandle new_gchandle;
GCHandle old_gchandle;
MonoObject *managed_object;
uint32_t flags = MANAGED_REF_BIT;
enum XamarinGCHandleFlags flags = XamarinGCHandleFlags_None;
old_gchandle_raw = get_raw_gchandle_safe (self);
old_gchandle = old_gchandle_raw & ~GCHANDLE_MASK;
old_gchandle = get_gchandle_safe (self, &flags);
if (old_gchandle) {
bool is_weak = (old_gchandle_raw & GCHANDLE_WEAK) == GCHANDLE_WEAK;
bool is_weak = (flags & XamarinGCHandleFlags_WeakGCHandle) == XamarinGCHandleFlags_WeakGCHandle;
if (to_weak == is_weak) {
// we already have the GCHandle we need
#if defined(DEBUG_REF_COUNTING)
@ -1792,16 +1846,17 @@ xamarin_switch_gchandle (id self, bool to_weak)
MONO_THREAD_ATTACH; // COOP: will switch to GC_UNSAFE
managed_object = mono_gchandle_get_target (old_gchandle);
managed_object = xamarin_gchandle_get_target (old_gchandle);
if (to_weak) {
new_gchandle = mono_gchandle_new_weakref (managed_object, TRUE);
flags |= GCHANDLE_WEAK;
new_gchandle = xamarin_gchandle_new_weakref (managed_object, TRUE);
flags = (enum XamarinGCHandleFlags) (flags | XamarinGCHandleFlags_WeakGCHandle);
} else {
new_gchandle = mono_gchandle_new (managed_object, FALSE);
new_gchandle = xamarin_gchandle_new (managed_object, FALSE);
flags = (enum XamarinGCHandleFlags) (flags & ~XamarinGCHandleFlags_WeakGCHandle);
}
mono_gchandle_free (old_gchandle);
xamarin_gchandle_free (old_gchandle);
if (managed_object) {
// It's possible to not have a managed object if:
@ -1814,26 +1869,26 @@ xamarin_switch_gchandle (id self, bool to_weak)
// null, because the target would be collected.
xamarin_set_nsobject_flags (managed_object, xamarin_get_nsobject_flags (managed_object) | NSObjectFlagsHasManagedRef);
}
set_raw_gchandle (self, new_gchandle | flags);
set_gchandle (self, new_gchandle, flags);
MONO_THREAD_DETACH; // COOP: this will switch to GC_SAFE
#if defined(DEBUG_REF_COUNTING)
PRINT ("Switched object %p to %s GCHandle = %d\n", self, to_weak ? "weak" : "strong", new_gchandle);
PRINT ("Switched object %p to %s GCHandle = %d managed object = %p\n", self, to_weak ? "weak" : "strong", new_gchandle, managed_object);
#endif
}
void
xamarin_free_gchandle (id self, uint32_t gchandle)
xamarin_free_gchandle (id self, GCHandle gchandle)
{
// COOP: no managed memory access, but calls mono function mono_gc_handle_free. Assuming that function can be called with any mode: this function can be called with any mode as well
if (gchandle) {
#if defined(DEBUG_REF_COUNTING)
PRINT ("\tGCHandle %i destroyed for object %p\n", gchandle, self);
#endif
mono_gchandle_free (gchandle);
xamarin_gchandle_free (gchandle);
set_raw_gchandle (self, 0);
set_gchandle (self, INVALID_GCHANDLE, XamarinGCHandleFlags_None);
} else {
#if defined(DEBUG_REF_COUNTING)
PRINT ("\tNo GCHandle for the object %p\n", self);
@ -1845,14 +1900,14 @@ void
xamarin_clear_gchandle (id self)
{
// COOP: no managed memory access: any mode
set_raw_gchandle (self, 0);
set_gchandle (self, INVALID_GCHANDLE, XamarinGCHandleFlags_None);
}
void
xamarin_set_gchandle (id self, uint32_t gchandle)
xamarin_set_gchandle_with_flags (id self, GCHandle gchandle, enum XamarinGCHandleFlags flags)
{
// COOP: no managed memory access: any mode
set_raw_gchandle (self, gchandle);
set_gchandle (self, gchandle, flags);
}
static int
@ -1890,7 +1945,7 @@ is_user_type (id self)
}
// COOP: no managed memory access: any mode
return class_getInstanceMethod (cls, @selector (xamarinSetGCHandle:)) != NULL;
return class_getInstanceMethod (cls, @selector (xamarinSetGCHandle:flags:)) != NULL;
}
#if defined(DEBUG_REF_COUNTING)
@ -1904,7 +1959,7 @@ get_safe_retainCount (id self)
// NSCalendar/NSInputStream may end up with a stack overflow where CFGetRetainCount calls itself
return 666;
} else {
return [self retainCount];
return (int) [self retainCount];
}
}
#endif
@ -1917,18 +1972,18 @@ xamarin_release_managed_ref (id self, MonoObject *managed_obj)
MONO_ASSERT_GC_UNSAFE;
bool user_type = is_user_type (self);
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
#if defined(DEBUG_REF_COUNTING)
PRINT ("monotouch_release_managed_ref (%s Handle=%p) retainCount=%d; HasManagedRef=%i GCHandle=%i IsUserType=%i\n",
class_getName (object_getClass (self)), self, (int32_t) [self retainCount], user_type ? xamarin_has_managed_ref (self) : 666, user_type ? get_gchandle (self) : 666, user_type);
PRINT ("monotouch_release_managed_ref (%s Handle=%p) retainCount=%d; HasManagedRef=%i GCHandle=%p IsUserType=%i managed_obj=%p\n",
class_getName (object_getClass (self)), self, (int32_t) [self retainCount], user_type ? xamarin_has_managed_ref (self) : 666, user_type ? get_gchandle_without_flags (self) : (void*) 666, user_type, managed_obj);
#endif
xamarin_set_nsobject_flags (managed_obj, xamarin_get_nsobject_flags (managed_obj) & ~NSObjectFlagsHasManagedRef);
if (user_type) {
/* clear MANAGED_REF_BIT */
set_raw_gchandle (self, get_raw_gchandle (self) & ~MANAGED_REF_BIT);
set_flags (self, (enum XamarinGCHandleFlags) (get_flags (self) & ~XamarinGCHandleFlags_HasManagedRef));
MONO_ENTER_GC_SAFE;
[self release];
MONO_EXIT_GC_SAFE;
@ -2021,20 +2076,20 @@ xamarin_create_managed_ref (id self, gpointer managed_object, bool retain)
// COOP: we stay in unsafe mode (since we write to the managed memory) unless calling a selector (which must be done in safe mode)
MONO_ASSERT_GC_UNSAFE;
uint32_t gchandle;
GCHandle gchandle;
bool user_type = is_user_type (self);
#if defined(DEBUG_REF_COUNTING)
PRINT ("monotouch_create_managed_ref (%s Handle=%p) retainCount=%d; HasManagedRef=%i GCHandle=%i IsUserType=%i\n",
class_getName ([self class]), self, get_safe_retainCount (self), user_type ? xamarin_has_managed_ref (self) : 666, user_type ? get_gchandle (self) : 666, user_type);
PRINT ("monotouch_create_managed_ref (%s Handle=%p) retainCount=%d; HasManagedRef=%i GCHandle=%i IsUserType=%i managed_object=%p\n",
class_getName ([self class]), self, get_safe_retainCount (self), user_type ? xamarin_has_managed_ref (self) : 666, user_type ? get_gchandle_without_flags (self) : (void*) 666, user_type, managed_object);
#endif
xamarin_set_nsobject_flags ((MonoObject *) managed_object, xamarin_get_nsobject_flags ((MonoObject *) managed_object) | NSObjectFlagsHasManagedRef);
if (user_type) {
gchandle = get_gchandle (self);
gchandle = get_gchandle_without_flags (self);
if (!gchandle) {
xamarin_create_gchandle (self, managed_object, MANAGED_REF_BIT, !retain);
xamarin_create_gchandle (self, managed_object, XamarinGCHandleFlags_HasManagedRef, !retain);
} else {
#if defined(DEBUG_REF_COUNTING)
xamarin_assertion_message ("GCHandle already exists for %p: %d\n", self, gchandle);
@ -2084,7 +2139,7 @@ static MonoReferenceQueue *block_wrapper_queue;
* create the method
*/
static GCHandle
get_method_block_wrapper_creator (MonoMethod *method, int par, guint32 *exception_gchandle)
get_method_block_wrapper_creator (MonoMethod *method, int par, GCHandle *exception_gchandle)
{
// COOP: accesses managed memory: unsafe mode.
MONO_ASSERT_GC_UNSAFE;
@ -2111,7 +2166,7 @@ get_method_block_wrapper_creator (MonoMethod *method, int par, guint32 *exceptio
}
res = xamarin_get_block_wrapper_creator (mono_method_get_object (mono_domain_get (), method, NULL), (int) par, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return INVALID_GCHANDLE;
// PRINT ("New value: %x", (int) res);
@ -2152,7 +2207,7 @@ xamarin_release_block_on_main_thread (void *obj)
* Returns: the instantiated delegate.
*/
MonoObject *
xamarin_get_delegate_for_block_parameter (MonoMethod *method, guint32 token_ref, int par, void *nativeBlock, guint32 *exception_gchandle)
xamarin_get_delegate_for_block_parameter (MonoMethod *method, guint32 token_ref, int par, void *nativeBlock, GCHandle *exception_gchandle)
{
// COOP: accesses managed memory: unsafe mode.
MONO_ASSERT_GC_UNSAFE;
@ -2168,14 +2223,14 @@ xamarin_get_delegate_for_block_parameter (MonoMethod *method, guint32 token_ref,
} else {
obj_handle = get_method_block_wrapper_creator (method, par, exception_gchandle);
}
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto cleanup;
/* retain or copy (if it's a stack block) the block */
nativeBlock = _Block_copy (nativeBlock);
delegate = xamarin_create_block_proxy (obj_handle, nativeBlock, exception_gchandle);
if (*exception_gchandle != 0) {
if (*exception_gchandle != INVALID_GCHANDLE) {
_Block_release (nativeBlock);
delegate = NULL;
goto cleanup;
@ -2197,7 +2252,7 @@ cleanup:
}
id
xamarin_get_block_for_delegate (MonoMethod *method, MonoObject *delegate, const char *signature, guint32 token_ref, guint32 *exception_gchandle)
xamarin_get_block_for_delegate (MonoMethod *method, MonoObject *delegate, const char *signature, guint32 token_ref, GCHandle *exception_gchandle)
{
// COOP: accesses managed memory: unsafe mode.
return xamarin_create_delegate_proxy (mono_method_get_object (mono_domain_get (), method, NULL), delegate, signature, token_ref, exception_gchandle);
@ -2254,16 +2309,16 @@ void
xamarin_process_nsexception_using_mode (NSException *ns_exception, bool throwManagedAsDefault)
{
XamarinGCHandle *exc_handle;
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
MarshalObjectiveCExceptionMode mode;
mode = xamarin_on_marshal_objectivec_exception (ns_exception, throwManagedAsDefault, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
PRINT (PRODUCT ": Got an exception while executing the MarshalObjectiveCException event (this exception will be ignored):");
PRINT ("%@", print_all_exceptions (mono_gchandle_get_target (exception_gchandle)));
mono_gchandle_free (exception_gchandle);
exception_gchandle = 0;
PRINT ("%@", print_all_exceptions (xamarin_gchandle_get_target (exception_gchandle)));
xamarin_gchandle_free (exception_gchandle);
exception_gchandle = INVALID_GCHANDLE;
}
if (mode == MarshalObjectiveCExceptionModeDefault)
@ -2278,23 +2333,23 @@ xamarin_process_nsexception_using_mode (NSException *ns_exception, bool throwMan
case MarshalObjectiveCExceptionModeThrowManagedException:
exc_handle = [[ns_exception userInfo] objectForKey: @"XamarinManagedExceptionHandle"];
if (exc_handle != NULL) {
uint32_t handle = [exc_handle getHandle];
GCHandle handle = [exc_handle getHandle];
MONO_ENTER_GC_UNSAFE;
MonoObject *exc = mono_gchandle_get_target (handle);
MonoObject *exc = xamarin_gchandle_get_target (handle);
mono_runtime_set_pending_exception ((MonoException *) exc, false);
MONO_EXIT_GC_UNSAFE;
} else {
uint32_t handle = (uint32_t) xamarin_create_ns_exception (ns_exception, &exception_gchandle);
if (exception_gchandle != 0) {
GCHandle handle = xamarin_create_ns_exception (ns_exception, &exception_gchandle);
if (exception_gchandle != INVALID_GCHANDLE) {
PRINT (PRODUCT ": Got an exception while creating a managed NSException wrapper (will throw this exception instead):");
PRINT ("%@", print_all_exceptions (mono_gchandle_get_target (exception_gchandle)));
PRINT ("%@", print_all_exceptions (xamarin_gchandle_get_target (exception_gchandle)));
handle = exception_gchandle;
exception_gchandle = 0;
exception_gchandle = INVALID_GCHANDLE;
}
MONO_ENTER_GC_UNSAFE;
MonoObject *exc = mono_gchandle_get_target (handle);
MonoObject *exc = xamarin_gchandle_get_target (handle);
mono_runtime_set_pending_exception ((MonoException *) exc, false);
mono_gchandle_free (handle);
xamarin_gchandle_free (handle);
MONO_EXIT_GC_UNSAFE;
}
break;
@ -2312,17 +2367,17 @@ xamarin_process_managed_exception (MonoObject *exception)
return;
MarshalManagedExceptionMode mode;
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
uint32_t handle = mono_gchandle_new (exception, false);
mode = xamarin_on_marshal_managed_exception ((int) handle, &exception_gchandle);
mono_gchandle_free (handle);
GCHandle handle = xamarin_gchandle_new (exception, false);
mode = xamarin_on_marshal_managed_exception (handle, &exception_gchandle);
xamarin_gchandle_free (handle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
PRINT (PRODUCT ": Got an exception while executing the MarshalManagedException event (this exception will be ignored):");
PRINT ("%@", print_all_exceptions (mono_gchandle_get_target (exception_gchandle)));
mono_gchandle_free (exception_gchandle);
exception_gchandle = 0;
PRINT ("%@", print_all_exceptions (xamarin_gchandle_get_target (exception_gchandle)));
xamarin_gchandle_free (exception_gchandle);
exception_gchandle = INVALID_GCHANDLE;
mode = MarshalManagedExceptionModeDefault;
}
@ -2347,34 +2402,34 @@ xamarin_process_managed_exception (MonoObject *exception)
// to throw an exception that contains the original stack trace.
//
handle = mono_gchandle_new (exception, false);
handle = xamarin_gchandle_new (exception, false);
xamarin_rethrow_managed_exception (handle, &exception_gchandle);
mono_gchandle_free (handle);
xamarin_gchandle_free (handle);
if (exception_gchandle == 0) {
if (exception_gchandle == INVALID_GCHANDLE) {
PRINT (PRODUCT ": Did not get a rethrow exception, will throw the original exception. The original stack trace will be lost.");
} else {
exception = mono_gchandle_get_target (exception_gchandle);
mono_gchandle_free (exception_gchandle);
exception = xamarin_gchandle_get_target (exception_gchandle);
xamarin_gchandle_free (exception_gchandle);
}
mono_raise_exception ((MonoException *) exception);
break;
case MarshalManagedExceptionModeThrowObjectiveCException: {
uint32_t handle = mono_gchandle_new (exception, false);
GCHandle handle = xamarin_gchandle_new (exception, false);
NSException *ns_exc = xamarin_unwrap_ns_exception (handle, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
PRINT (PRODUCT ": Got an exception while unwrapping a managed NSException wrapper (this exception will be ignored):");
PRINT ("%@", print_all_exceptions (mono_gchandle_get_target (exception_gchandle)));
mono_gchandle_free (exception_gchandle);
exception_gchandle = 0;
PRINT ("%@", print_all_exceptions (xamarin_gchandle_get_target (exception_gchandle)));
xamarin_gchandle_free (exception_gchandle);
exception_gchandle = INVALID_GCHANDLE;
ns_exc = NULL;
}
if (ns_exc != NULL) {
mono_gchandle_free (handle);
xamarin_gchandle_free (handle);
@throw ns_exc;
} else {
// Strangely enough the thread might be detached, if xamarin_process_managed_exception was called from
@ -2388,11 +2443,11 @@ xamarin_process_managed_exception (MonoObject *exception)
MONO_THREAD_ATTACH; // COOP: will switch to GC_UNSAFE
fullname = xamarin_type_get_full_name (mono_class_get_type (mono_object_get_class (exception)), &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
PRINT (PRODUCT ": Got an exception when trying to get the typename for an exception (this exception will be ignored):");
PRINT ("%@", print_all_exceptions (mono_gchandle_get_target (exception_gchandle)));
mono_gchandle_free (exception_gchandle);
exception_gchandle = 0;
PRINT ("%@", print_all_exceptions (xamarin_gchandle_get_target (exception_gchandle)));
xamarin_gchandle_free (exception_gchandle);
exception_gchandle = INVALID_GCHANDLE;
fullname = "Unknown";
}
@ -2422,18 +2477,18 @@ xamarin_throw_product_exception (int code, const char *message)
xamarin_process_managed_exception_gchandle (xamarin_create_product_exception (code, message));
}
guint32
GCHandle
xamarin_create_product_exception (int code, const char *message)
{
return xamarin_create_product_exception_with_inner_exception (code, 0, message);
}
guint32
xamarin_create_product_exception_with_inner_exception (int code, guint32 inner_exception_gchandle, const char *message)
GCHandle
xamarin_create_product_exception_with_inner_exception (int code, GCHandle inner_exception_gchandle, const char *message)
{
guint32 exception_gchandle = 0;
guint32 handle = xamarin_create_product_exception_for_error (code, inner_exception_gchandle, message, &exception_gchandle);
if (exception_gchandle != 0)
GCHandle exception_gchandle = INVALID_GCHANDLE;
GCHandle handle = xamarin_create_product_exception_for_error (code, inner_exception_gchandle, message, &exception_gchandle);
if (exception_gchandle != INVALID_GCHANDLE)
return exception_gchandle;
return handle;
}
@ -2678,12 +2733,12 @@ xamarin_find_assembly_directory (const char *assembly_name)
}
MonoMethod *
xamarin_get_managed_method_for_token (guint32 token_ref, guint32 *exception_gchandle)
xamarin_get_managed_method_for_token (guint32 token_ref, GCHandle *exception_gchandle)
{
MonoReflectionMethod *reflection_method;
reflection_method = (MonoReflectionMethod *) xamarin_gchandle_unwrap (xamarin_get_method_from_token (token_ref, exception_gchandle));
if (*exception_gchandle != 0) return NULL;
if (*exception_gchandle != INVALID_GCHANDLE) return NULL;
return xamarin_get_reflection_method_method (reflection_method);
}
@ -2691,16 +2746,12 @@ xamarin_get_managed_method_for_token (guint32 token_ref, guint32 *exception_gcha
GCHandle
xamarin_gchandle_new (MonoObject *obj, bool track_resurrection)
{
if (obj == NULL)
return INVALID_GCHANDLE;
return GINT_TO_POINTER (mono_gchandle_new (obj, track_resurrection));
}
GCHandle
xamarin_gchandle_new_weakref (MonoObject *obj, bool pinned)
{
if (obj == NULL)
return INVALID_GCHANDLE;
return GINT_TO_POINTER (mono_gchandle_new_weakref (obj, pinned));
}
@ -2725,7 +2776,7 @@ xamarin_gchandle_unwrap (GCHandle handle)
{
if (handle == INVALID_GCHANDLE)
return NULL;
MonoObject *rv = mono_gchandle_get_target (GPOINTER_TO_UINT (handle));
MonoObject *rv = xamarin_gchandle_get_target (handle);
mono_gchandle_free (GPOINTER_TO_UINT (handle));
return rv;
}
@ -2813,12 +2864,12 @@ XamarinObject::~XamarinObject ()
{
// COOP: no managed memory access: any mode.
@try {
xamarin_notify_dealloc (native_object, gc_handle & ~GCHANDLE_MASK);
xamarin_notify_dealloc (native_object, gc_handle);
} @catch (NSException *ex) {
NSLog (@"%@", ex);
}
native_object = NULL;
gc_handle = 0;
gc_handle = INVALID_GCHANDLE;
}
/*
@ -2833,9 +2884,9 @@ XamarinObject::~XamarinObject ()
-(void) dealloc
{
// COOP: no managed memory access: any mode.
xamarin_notify_dealloc (native_object, gc_handle & ~GCHANDLE_MASK);
xamarin_notify_dealloc (native_object, gc_handle);
native_object = NULL;
gc_handle = 0;
gc_handle = INVALID_GCHANDLE;
[super dealloc];
}
@end
@ -2848,16 +2899,22 @@ XamarinObject::~XamarinObject ()
* calling xamarinGetGCHandle. TODO: verify if this is really faster than
* checking the type first.
*
* Do not add a xamarinSetGCHandle: method, since we use the presence
* Do not add a xamarinSetGCHandle:flags: method, since we use the presence
* of it to detect whether a particular type is a user type or not
* (see is_user_type).
*/
@implementation NSObject (NonXamarinObject)
-(uint32_t) xamarinGetGCHandle
-(GCHandle) xamarinGetGCHandle
{
// COOP: no managed memory access: any mode.
return 0;
return INVALID_GCHANDLE;
}
-(enum XamarinGCHandleFlags) xamarinGetFlags
{
// COOP: no managed memory access: any mode.
return XamarinGCHandleFlags_None;
}
@end
@ -2922,7 +2979,7 @@ xamarin_is_managed_exception_marshaling_disabled ()
* XamarinGCHandle
*/
@implementation XamarinGCHandle
+(XamarinGCHandle *) createWithHandle: (uint32_t) h
+(XamarinGCHandle *) createWithHandle: (GCHandle) h
{
XamarinGCHandle *rv = [[XamarinGCHandle alloc] init];
rv->handle = h;
@ -2932,11 +2989,11 @@ xamarin_is_managed_exception_marshaling_disabled ()
-(void) dealloc
{
mono_gchandle_free (handle);
xamarin_gchandle_free (handle);
[super dealloc];
}
-(uint32_t) getHandle
-(GCHandle) getHandle
{
return handle;
}

Просмотреть файл

@ -14,6 +14,8 @@
#include <stdbool.h>
#include <stdatomic.h>
#include "xamarin/mono-runtime.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -47,8 +49,8 @@ struct Block_literal {
int reserved;
void (*invoke)(void *, ...);
struct Xamarin_block_descriptor *descriptor;
void *local_handle;
void *global_handle;
GCHandle local_handle;
GCHandle global_handle;
};
struct Xamarin_block_descriptor * xamarin_get_block_descriptor ();

Просмотреть файл

@ -245,9 +245,8 @@ xamarin_dispose_helper (void *a)
// COOP: this method is executed by the ObjC runtime when a block must be freed.
// COOP: it does not touch any managed memory (except to free a gchandle), so any mode goes.
struct Block_literal *bl = (struct Block_literal *) a;
uint32_t handle = GPOINTER_TO_UINT (bl->global_handle);
mono_gchandle_free (handle);
bl->global_handle = GINT_TO_POINTER (-1);
xamarin_gchandle_free (bl->global_handle);
bl->global_handle = INVALID_GCHANDLE;
if (atomic_fetch_sub (&bl->descriptor->ref_count, 1) == 0) {
free (bl->descriptor); // allocated using Marshal.AllocHGlobal.
}
@ -261,10 +260,7 @@ xamarin_copy_helper (void *dst, void *src)
// COOP: it does not touch any managed memory (except to allocate a gchandle), so any mode goes.
struct Block_literal *source = (struct Block_literal *) src;
struct Block_literal *target = (struct Block_literal *) dst;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast"
target->global_handle = GINT_TO_POINTER (mono_gchandle_new (mono_gchandle_get_target (GPOINTER_TO_UINT (source->local_handle)), FALSE));
#pragma clang diagnostic pop
target->global_handle = xamarin_gchandle_new (xamarin_gchandle_get_target (source->local_handle), FALSE);
atomic_fetch_add (&source->descriptor->ref_count, 1);
target->descriptor = source->descriptor;

Просмотреть файл

@ -41,7 +41,7 @@ dump_state (struct XamarinCallState *state, const char *prefix)
#endif
static int
param_read_primitive (struct ParamIterator *it, const char *type_ptr, void *target, size_t total_size, guint32 *exception_gchandle)
param_read_primitive (struct ParamIterator *it, const char *type_ptr, void *target, size_t total_size, GCHandle *exception_gchandle)
{
// COOP: does not access managed memory: any mode.
char type = *type_ptr;
@ -136,7 +136,7 @@ param_read_primitive (struct ParamIterator *it, const char *type_ptr, void *targ
}
static void
param_iter_next (enum IteratorAction action, void *context, const char *type, size_t size, void *target, guint32 *exception_gchandle)
param_iter_next (enum IteratorAction action, void *context, const char *type, size_t size, void *target, GCHandle *exception_gchandle)
{
// COOP: does not access managed memory: any mode.
struct ParamIterator *it = (struct ParamIterator *) context;
@ -159,7 +159,7 @@ param_iter_next (enum IteratorAction action, void *context, const char *type, si
char struct_name [5]; // we don't care about structs with more than 4 fields.
xamarin_collapse_struct_name (type, struct_name, sizeof (struct_name), exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return;
if (size > 16 && strcmp (struct_name, "dddd") && strcmp (struct_name, "ddd")) {
@ -183,7 +183,7 @@ param_iter_next (enum IteratorAction action, void *context, const char *type, si
uint8_t *targ = (uint8_t *) target;
do {
int c = param_read_primitive (it, t, targ, size, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return;
if (targ != NULL)
targ += c;
@ -191,7 +191,7 @@ param_iter_next (enum IteratorAction action, void *context, const char *type, si
}
static void
marshal_return_value (void *context, const char *type, size_t size, void *vvalue, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, guint32 *exception_gchandle)
marshal_return_value (void *context, const char *type, size_t size, void *vvalue, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle)
{
// COOP: accessing managed memory (as input), so must be in unsafe mode.
MONO_ASSERT_GC_UNSAFE;
@ -221,7 +221,7 @@ marshal_return_value (void *context, const char *type, size_t size, void *vvalue
*/
xamarin_collapse_struct_name (type, struct_name, sizeof (struct_name), exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return;
if ((size == 32 && !strncmp (struct_name, "dddd", 4)) ||

Просмотреть файл

@ -28,7 +28,7 @@ dump_state (struct XamarinCallState *state)
#endif
static void
param_iter_next (enum IteratorAction action, void *context, const char *type, size_t size, void *target, guint32 *exception_gchandle)
param_iter_next (enum IteratorAction action, void *context, const char *type, size_t size, void *target, GCHandle *exception_gchandle)
{
struct ParamIterator *it = (struct ParamIterator *) context;
@ -67,7 +67,7 @@ param_iter_next (enum IteratorAction action, void *context, const char *type, si
}
static void
marshal_return_value (void *context, const char *type, size_t size, void *vvalue, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, guint32 *exception_gchandle)
marshal_return_value (void *context, const char *type, size_t size, void *vvalue, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle)
{
MonoObject *value = (MonoObject *) vvalue;
struct ParamIterator *it = (struct ParamIterator *) context;

Просмотреть файл

@ -43,8 +43,8 @@ enum IteratorAction {
// type: pass NULL to start iterating.
// target: can be null if not interested in the value.
typedef void (*iterator_func) (enum IteratorAction action, void *context, const char *type, size_t size, void *target, guint32 *exception_gchandle);
typedef void (*marshal_return_value_func) (void *context, const char *type, size_t size, void *value, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, guint32 *exception_gchandle);
typedef void (*iterator_func) (enum IteratorAction action, void *context, const char *type, size_t size, void *target, GCHandle *exception_gchandle);
typedef void (*marshal_return_value_func) (void *context, const char *type, size_t size, void *value, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle);
void xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_func iterator, marshal_return_value_func marshal_return_value, void *context);

Просмотреть файл

@ -12,10 +12,10 @@
#include "delegates.h"
#include "product.h"
static guint32
xamarin_get_exception_for_method (int code, guint32 inner_exception_gchandle, const char *reason, SEL sel, id self)
static GCHandle
xamarin_get_exception_for_method (int code, GCHandle inner_exception_gchandle, const char *reason, SEL sel, id self)
{
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
char *msg = xamarin_strdup_printf ("%s\n"
"Additional information:\n"
"\tSelector: %s\n"
@ -25,12 +25,12 @@ xamarin_get_exception_for_method (int code, guint32 inner_exception_gchandle, co
return exception_gchandle;
}
guint32
xamarin_get_exception_for_parameter (int code, guint32 inner_exception_gchandle, const char *reason, SEL sel, MonoMethod *method, MonoType *p, int i, bool to_managed)
GCHandle
xamarin_get_exception_for_parameter (int code, GCHandle inner_exception_gchandle, const char *reason, SEL sel, MonoMethod *method, MonoType *p, int i, bool to_managed)
{
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
char *to_name = xamarin_type_get_full_name (p, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
return exception_gchandle;
char *method_full_name = mono_method_full_name (method, TRUE);
char *msg = xamarin_strdup_printf ("%s #%i whose managed type is '%s' %s.\n"
@ -87,14 +87,14 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
MonoObject *exception = NULL;
MonoObject **exception_ptr = xamarin_is_managed_exception_marshaling_disabled () ? NULL : &exception;
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
bool is_static = (type & Tramp_Static) == Tramp_Static;
bool is_ctor = type == Tramp_Ctor;
const char *ret_type = NULL;
if (is_ctor) {
bool has_nsobject = xamarin_has_nsobject (self, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
xamarin_process_managed_exception_gchandle (exception_gchandle);
return; // we shouldn't get here.
}
@ -160,7 +160,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
mthis = xamarin_gchandle_get_target (mthis_handle);
xamarin_gchandle_free (mthis_handle);
}
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
exception_gchandle = xamarin_get_exception_for_method (8034, exception_gchandle, "Failed to lookup the required marshalling information.", sel, self);
goto exception_handling;
}
@ -183,7 +183,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
// we know this must be an id
p = mono_signature_get_params (msig, &iter);
arg_ptrs [0] = xamarin_get_nsobject_with_type_for_ptr (self, false, p, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
exception_gchandle = xamarin_get_exception_for_parameter (8029, exception_gchandle, "Unable to marshal the parameter", sel, method, p, 0, true);
goto exception_handling;
}
@ -191,7 +191,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
}
iterator (IteratorStart, context, NULL, 0, NULL, &exception_gchandle); // start
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
for (i = 0, ofs = 0; i < num_arg; i++) {
@ -211,7 +211,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
// we end up in this condition because it's a [Native] enum.
iterator (IteratorIterate, context, type, size, &arg_frame [ofs++], &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
arg_frame [ofs++] = 0;
arg_ptrs [i + mofs] = &arg_frame [frameofs];
@ -222,19 +222,19 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
if (size > sizeof (void *)) {
iterator (IteratorIterate, context, type, size, &arg_frame [ofs], &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
ofs += size / sizeof (void *);
arg_ptrs [i + mofs] = &arg_frame [frameofs];
} else {
void *arg;
iterator (IteratorIterate, context, type, size, &arg, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (desc->bindas [i + 1].original_type_handle != INVALID_GCHANDLE) {
MonoReflectionType *original_type = (MonoReflectionType *) xamarin_gchandle_get_target (desc->bindas [i + 1].original_type_handle);
arg_ptrs [i + mofs] = xamarin_generate_conversion_to_managed ((id) arg, mono_reflection_type_get_type (original_type), p, method, &exception_gchandle, (void *) INVALID_TOKEN_REF, (void **) &free_list);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
ofs++;
continue;
@ -251,7 +251,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
goto exception_handling;
}
bool is_parameter_out = xamarin_is_parameter_out (mono_method_get_object (domain, method, NULL), (int) i, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (!needs_writeback) {
@ -275,14 +275,14 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
}
} else if (xamarin_is_class_nsobject (p_klass)) {
arg_frame [ofs] = xamarin_get_nsobject_with_type_for_ptr (*(NSObject **) arg, false, p, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
exception_gchandle = xamarin_get_exception_for_parameter (8029, exception_gchandle, "Unable to marshal the byref parameter", sel, method, p, (int) i, true);
goto exception_handling;
}
LOGZ (" argument %i is a ref NSObject parameter: %p = %p\n", i + 1, arg, arg_frame [ofs]);
} else if (xamarin_is_class_inativeobject (p_klass)) {
arg_frame [ofs] = xamarin_get_inative_object_dynamic (*(NSObject **) arg, false, mono_type_get_object (domain, p), &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
LOGZ (" argument %i is a ref ptr/INativeObject %p: %p\n", i + 1, arg, arg_frame [ofs]);
} else if (p_klass == mono_get_string_class ()) {
@ -290,7 +290,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
LOGZ (" argument %i is a ref NSString %p: %p\n", i + 1, arg, arg_frame [ofs]);
} else if (xamarin_is_class_array (p_klass)) {
arg_frame [ofs] = xamarin_nsarray_to_managed_array (*(NSArray **) arg, p, p_klass, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
exception_gchandle = xamarin_get_exception_for_parameter (8029, exception_gchandle, "Unable to marshal the byref parameter", sel, method, p, (int) i, true);
goto exception_handling;
}
@ -316,7 +316,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
MonoClass *p_klass = mono_class_from_mono_type (p);
if (mono_class_is_delegate (p_klass)) {
arg_ptrs [i + mofs] = xamarin_get_delegate_for_block_parameter (method, INVALID_TOKEN_REF, (int) i, arg, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
} else if (xamarin_is_class_inativeobject (p_klass)) {
id id_arg = (id) arg;
@ -326,7 +326,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
}
MonoObject *obj;
obj = xamarin_get_inative_object_dynamic (id_arg, false, mono_type_get_object (domain, p), &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
LOGZ (" argument %i is ptr/INativeObject %p: %p\n", i + 1, id_arg, obj);
arg_ptrs [i + mofs] = obj;
@ -352,7 +352,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
break;
} else {
arg_ptrs [i + mofs] = (void *) xamarin_get_class ((Class) arg, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
LOGZ (" argument %i is Class: %p = %s\n", i + 1, arg, class_getName ((Class) arg));
break;
@ -365,7 +365,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
break;
} else {
arg_ptrs [i + mofs] = (void *) xamarin_get_selector ((SEL) arg, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
LOGZ (" argument %i is SEL: %p = %s\n", i + 1, arg, sel_getName ((SEL) arg));
break;
@ -400,7 +400,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
LOGZ (" argument %i is NSString: %p = %s\n", i + 1, id_arg, [str UTF8String]);
} else if (xamarin_is_class_array (p_klass)) {
arg_ptrs [i + mofs] = xamarin_nsarray_to_managed_array ((NSArray *) id_arg, p, p_klass, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
exception_gchandle = xamarin_get_exception_for_parameter (8029, exception_gchandle, "Unable to marshal the array parameter", sel, method, p, (int) i, true);
goto exception_handling;
}
@ -413,14 +413,14 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
MonoObject *obj;
int32_t created = false;
obj = xamarin_get_nsobject_with_type_for_ptr_created (id_arg, false, p, &created, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
exception_gchandle = xamarin_get_exception_for_parameter (8029, exception_gchandle, "Unable to marshal the parameter", sel, method, p, (int) i, true);
goto exception_handling;
}
if (created && obj) {
bool is_transient = xamarin_is_parameter_transient (mono_method_get_object (domain, method, NULL), (int32_t) i, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (is_transient)
dispose_list = s_list_prepend (dispose_list, obj);
@ -437,13 +437,13 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
}
MonoObject *obj;
obj = xamarin_get_inative_object_dynamic (id_arg, false, mono_type_get_object (domain, p), &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
LOGZ (" argument %i is NSObject/INativeObject %p: %p\n", i + 1, id_arg, obj);
arg_ptrs [i + mofs] = obj;
} else if (mono_class_is_delegate (p_klass)) {
arg_ptrs [i + mofs] = xamarin_get_delegate_for_block_parameter (method, INVALID_TOKEN_REF, (int) i, id_arg, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
} else {
if (semantic == ArgumentSemanticCopy) {
@ -452,7 +452,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
}
MonoObject *obj;
obj = xamarin_get_nsobject_with_type_for_ptr (id_arg, false, p, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
#if DEBUG
xamarin_verify_parameter (obj, sel, self, id_arg, i, p_klass, method);
@ -472,7 +472,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
}
iterator (IteratorEnd, context, NULL, 0, NULL, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
// invoke
@ -513,7 +513,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
xamarin_create_managed_ref (self, retval, true);
xamarin_register_nsobject (xamarin_gchandle_new_weakref (retval, false), self, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
} else {
@ -543,7 +543,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
if (needs_writeback) {
iter = NULL;
iterator (IteratorStart, context, NULL, 0, NULL, &exception_gchandle); // start
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
for (i = 0; i < num_arg; i++) {
const char *type = [sig getArgumentTypeAtIndex: (i+2)];
@ -559,7 +559,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
bool skip = size > sizeof (void *) || !writeback [i + mofs];
void *arg;
iterator (IteratorIterate, context, type, size, skip ? NULL : &arg, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (skip) {
LOGZ (" skipping argument %i (size: %i, pointer: %p)\n", i, size, arg_copy [i + mofs]);
@ -591,17 +591,17 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
LOGZ (" writing back managed string %p to argument at index %i (%p)\n", value, i + 1, arg);
} else if (xamarin_is_class_nsobject (p_klass)) {
obj = xamarin_get_handle (value, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
LOGZ (" writing back managed NSObject %p to argument at index %i (%p)\n", value, i + 1, arg);
} else if (xamarin_is_class_inativeobject (p_klass)) {
obj = xamarin_get_handle_for_inativeobject (value, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
LOGZ (" writing back managed INativeObject %p to argument at index %i (%p)\n", value, i + 1, arg);
} else if (xamarin_is_class_array (p_klass)) {
obj = xamarin_managed_array_to_nsarray ((MonoArray *) value, p, p_klass, &exception_gchandle);
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
exception_gchandle = xamarin_get_exception_for_parameter (8030, exception_gchandle, "Unable to marshal the out/ref parameter", sel, method, p, (int) i, false);
goto exception_handling;
}
@ -617,7 +617,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
}
}
iterator (IteratorEnd, context, NULL, 0, NULL, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
}
@ -635,17 +635,17 @@ exception_handling:
if (dispose_list) {
SList *list = dispose_list;
while (list) {
guint32 dispose_exception_gchandle = 0;
GCHandle dispose_exception_gchandle = INVALID_GCHANDLE;
xamarin_dispose ((MonoObject *) list->data, &dispose_exception_gchandle);
if (dispose_exception_gchandle != 0) {
if (exception_gchandle == 0) {
if (dispose_exception_gchandle != INVALID_GCHANDLE) {
if (exception_gchandle == INVALID_GCHANDLE) {
// If we get an exception while disposing, and we don't already have an exception, then we need to throw the dispose exception (later, when done disposing)
exception_gchandle = dispose_exception_gchandle;
} else {
// If we already have an exception, don't overwrite it with an exception from disposing something.
// However we don't want to silently ignore it, so print it.
NSLog (@PRODUCT ": An exception occurred while disposing the object %p:", list->data);
NSLog (@"%@", xamarin_print_all_exceptions (mono_gchandle_get_target (dispose_exception_gchandle)));
NSLog (@"%@", xamarin_print_all_exceptions (xamarin_gchandle_get_target (dispose_exception_gchandle)));
}
}
list = list->next;
@ -680,7 +680,7 @@ exception_handling:
MONO_THREAD_DETACH; // COOP: This will switch to GC_SAFE
if (exception_gchandle != 0) {
if (exception_gchandle != INVALID_GCHANDLE) {
xamarin_process_managed_exception_gchandle (exception_gchandle);
} else {
xamarin_process_managed_exception (exception);

Просмотреть файл

@ -31,7 +31,7 @@ dump_state (struct XamarinCallState *state)
#endif
static void
param_iter_next (enum IteratorAction action, void *context, const char *type, size_t size, void *target, guint32 *exception_gchandle)
param_iter_next (enum IteratorAction action, void *context, const char *type, size_t size, void *target, GCHandle *exception_gchandle)
{
struct ParamIterator *it = (struct ParamIterator *) context;
struct XamarinCallState *state = it->state;
@ -74,7 +74,7 @@ param_iter_next (enum IteratorAction action, void *context, const char *type, si
}
static void
marshal_return_value (void *context, const char *type, size_t size, void *vvalue, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, guint32 *exception_gchandle)
marshal_return_value (void *context, const char *type, size_t size, void *vvalue, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle)
{
MonoObject *value = (MonoObject *) vvalue;
struct ParamIterator *it = (struct ParamIterator *) context;

Просмотреть файл

@ -48,7 +48,7 @@ static const char* registers[] = { "rdi", "rsi", "rdx", "rcx", "r8", "r9", "err
#endif
static unsigned long
param_read_primitive (struct ParamIterator *it, const char **type_ptr, void *target, size_t total_size, guint32 *exception_gchandle)
param_read_primitive (struct ParamIterator *it, const char **type_ptr, void *target, size_t total_size, GCHandle *exception_gchandle)
{
// COOP: does not access managed memory: any mode.
char type = **type_ptr;
@ -176,7 +176,7 @@ param_read_primitive (struct ParamIterator *it, const char **type_ptr, void *tar
}
static void
param_iter_next (enum IteratorAction action, void *context, const char *type, size_t size, void *target, guint32 *exception_gchandle)
param_iter_next (enum IteratorAction action, void *context, const char *type, size_t size, void *target, GCHandle *exception_gchandle)
{
// COOP: does not access managed memory: any mode.
struct ParamIterator *it = (struct ParamIterator *) context;
@ -227,7 +227,7 @@ param_iter_next (enum IteratorAction action, void *context, const char *type, si
break;
unsigned long c = param_read_primitive (it, &t, targ, size, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != NULL)
return;
if (targ != NULL)
targ += c;
@ -247,7 +247,7 @@ param_iter_next (enum IteratorAction action, void *context, const char *type, si
}
static void
marshal_return_value (void *context, const char *type, size_t size, void *vvalue, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, guint32 *exception_gchandle)
marshal_return_value (void *context, const char *type, size_t size, void *vvalue, MonoType *mtype, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle)
{
// COOP: accessing managed memory (as input), so must be in unsafe mode.
MONO_ASSERT_GC_UNSAFE;

Просмотреть файл

@ -72,7 +72,7 @@ xamarin_get_primitive_size (char type)
}
static void *
xamarin_marshal_return_value_impl (MonoType *mtype, const char *type, MonoObject *retval, bool retain, MonoMethod *method, MethodDescription *desc, guint32 *exception_gchandle)
xamarin_marshal_return_value_impl (MonoType *mtype, const char *type, MonoObject *retval, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle)
{
// COOP: accesses managed memory: unsafe mode.
MONO_ASSERT_GC_UNSAFE;
@ -106,7 +106,7 @@ xamarin_marshal_return_value_impl (MonoType *mtype, const char *type, MonoObject
return rv;
} else if (xamarin_is_class_nsobject (r_klass)) {
id i = xamarin_get_handle (retval, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return NULL;
xamarin_framework_peer_lock ();
@ -132,22 +132,22 @@ xamarin_marshal_return_value_impl (MonoType *mtype, const char *type, MonoObject
}
}
static guint32
xamarin_get_exception_for_element_conversion_failure (guint32 inner_exception_gchandle, unsigned long index)
static GCHandle
xamarin_get_exception_for_element_conversion_failure (GCHandle inner_exception_gchandle, unsigned long index)
{
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
char *msg = xamarin_strdup_printf ("Failed to marshal the value at index %lu.", index);
exception_gchandle = xamarin_create_product_exception_with_inner_exception (8036, inner_exception_gchandle, msg);
xamarin_free (msg);
return exception_gchandle;
}
static guint32
xamarin_get_exception_for_return_value (int code, guint32 inner_exception_gchandle, SEL sel, MonoMethod *method, MonoType *returnType)
static GCHandle
xamarin_get_exception_for_return_value (int code, GCHandle inner_exception_gchandle, SEL sel, MonoMethod *method, MonoType *returnType)
{
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
char *to_name = xamarin_type_get_full_name (returnType, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
return exception_gchandle;
char *method_full_name = mono_method_full_name (method, TRUE);
char *msg = xamarin_strdup_printf ("Unable to marshal the return value of type '%s' to Objective-C.\n"
@ -162,11 +162,11 @@ xamarin_get_exception_for_return_value (int code, guint32 inner_exception_gchand
}
void *
xamarin_marshal_return_value (SEL sel, MonoType *mtype, const char *type, MonoObject *retval, bool retain, MonoMethod *method, MethodDescription *desc, guint32 *exception_gchandle)
xamarin_marshal_return_value (SEL sel, MonoType *mtype, const char *type, MonoObject *retval, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle)
{
void *rv;
rv = xamarin_marshal_return_value_impl (mtype, type, retval, retain, method, desc, exception_gchandle);
if (*exception_gchandle != 0) {
if (*exception_gchandle != INVALID_GCHANDLE) {
*exception_gchandle = xamarin_get_exception_for_return_value (8033, *exception_gchandle, sel, method, mtype);
return NULL;
}
@ -316,12 +316,12 @@ get_type_description_length (const char *desc)
}
// The input string will be freed (so that the caller can use xamarin_strdup_printf easily).
guint32
GCHandle
xamarin_create_mt_exception (char *msg)
{
MonoException *ex = xamarin_create_exception (msg);
xamarin_free (msg);
return mono_gchandle_new ((MonoObject *) ex, FALSE);
return xamarin_gchandle_new ((MonoObject *) ex, FALSE);
}
// Skips any brace and the content within. Supports nested braced content.
@ -362,7 +362,7 @@ skip_nested_brace (const char *type)
// max_char: the maximum number of characters to write to struct_name
// return value: false if something went wrong (an exception thrown, or struct_name wasn't big enough).
bool
xamarin_collapse_struct_name (const char *type, char struct_name[], int max_char, guint32 *exception_gchandle)
xamarin_collapse_struct_name (const char *type, char struct_name[], int max_char, GCHandle *exception_gchandle)
{
const char *input = type;
int c = 0;
@ -560,7 +560,8 @@ xamarin_copyWithZone_trampoline1 (id self, SEL sel, NSZone *zone)
// This is for subclasses that themselves do not implement Copy (NSZone)
id rv;
int gchandle;
GCHandle gchandle;
enum XamarinGCHandleFlags flags = XamarinGCHandleFlags_None;
struct objc_super sup;
#if defined (DEBUG_REF_COUNTING)
@ -568,9 +569,9 @@ xamarin_copyWithZone_trampoline1 (id self, SEL sel, NSZone *zone)
#endif
// Clear out our own GCHandle
gchandle = xamarin_get_gchandle_with_flags (self);
if (gchandle != 0)
xamarin_set_gchandle (self, 0);
gchandle = xamarin_get_gchandle_with_flags (self, &flags);
if (gchandle != INVALID_GCHANDLE)
xamarin_set_gchandle_with_flags (self, INVALID_GCHANDLE, XamarinGCHandleFlags_None);
// Call the base class implementation
id (*invoke) (struct objc_super *, SEL, NSZone*) = (id (*)(struct objc_super *, SEL, NSZone*)) objc_msgSendSuper;
@ -578,8 +579,8 @@ xamarin_copyWithZone_trampoline1 (id self, SEL sel, NSZone *zone)
rv = invoke (&sup, sel, zone);
// Restore our GCHandle
if (gchandle != 0)
xamarin_set_gchandle (self, gchandle);
if (gchandle != INVALID_GCHANDLE)
xamarin_set_gchandle_with_flags (self, gchandle, flags);
return rv;
}
@ -591,24 +592,25 @@ xamarin_copyWithZone_trampoline2 (id self, SEL sel, NSZone *zone)
// This is for subclasses that already implement Copy (NSZone)
id rv;
int gchandle;
GCHandle gchandle;
enum XamarinGCHandleFlags flags = XamarinGCHandleFlags_None;
#if defined (DEBUG_REF_COUNTING)
PRINT ("xamarin_copyWithZone_trampoline2 (%p, %s, %p)\n", self, sel_getName (sel), zone);
#endif
// Clear out our own GCHandle
gchandle = xamarin_get_gchandle_with_flags (self);
if (gchandle != 0)
xamarin_set_gchandle (self, 0);
gchandle = xamarin_get_gchandle_with_flags (self, &flags);
if (gchandle != INVALID_GCHANDLE)
xamarin_set_gchandle_with_flags (self, INVALID_GCHANDLE, XamarinGCHandleFlags_None);
// Call the managed implementation
id (*invoke) (id, SEL, NSZone*) = (id (*)(id, SEL, NSZone*)) xamarin_trampoline;
rv = invoke (self, sel, zone);
// Restore our GCHandle
if (gchandle != 0)
xamarin_set_gchandle (self, gchandle);
if (gchandle != INVALID_GCHANDLE)
xamarin_set_gchandle_with_flags (self, gchandle, flags);
return rv;
}
@ -652,9 +654,9 @@ xamarin_release_trampoline (id self, SEL sel)
}
void
xamarin_notify_dealloc (id self, uint32_t gchandle)
xamarin_notify_dealloc (id self, GCHandle gchandle)
{
guint32 exception_gchandle = 0;
GCHandle exception_gchandle = INVALID_GCHANDLE;
// COOP: safe mode upon entry, switches to unsafe when acccessing managed memory.
MONO_ASSERT_GC_SAFE_OR_DETACHED;
@ -685,9 +687,9 @@ xamarin_retain_trampoline (id self, SEL sel)
pthread_mutex_lock (&refcount_mutex);
#if defined(DEBUG_REF_COUNTING)
int ref_count = [self retainCount];
int ref_count = (int) [self retainCount];
bool had_managed_ref = xamarin_has_managed_ref (self);
int pre_gchandle = xamarin_get_gchandle (self);
GCHandle pre_gchandle = xamarin_get_gchandle (self);
#endif
/*
@ -721,40 +723,60 @@ xamarin_retain_trampoline (id self, SEL sel)
static CFMutableDictionaryRef gchandle_hash = NULL;
static pthread_mutex_t gchandle_hash_lock = PTHREAD_MUTEX_INITIALIZER;
struct gchandle_dictionary_entry {
GCHandle gc_handle;
enum XamarinGCHandleFlags flags;
};
static void
release_gchandle_dictionary_entry (CFAllocatorRef allocator, const void *value)
{
free ((void *) value);
}
static const char *associated_key = "x"; // the string value doesn't matter, only the pointer value.
void
xamarin_set_gchandle_trampoline (id self, SEL sel, uint32_t gc_handle)
xamarin_set_gchandle_trampoline (id self, SEL sel, GCHandle gc_handle, enum XamarinGCHandleFlags flags)
{
// COOP: Called by ObjC (when the setGCHandle: selector is called on an object).
// COOP: Called by ObjC (when the setGCHandle:flags: selector is called on an object).
// COOP: Safe mode upon entry, and doesn't access managed memory, so no need to change.
MONO_ASSERT_GC_SAFE;
/* This is for types registered using the dynamic registrar */
XamarinAssociatedObject *obj;
obj = objc_getAssociatedObject (self, associated_key);
if (obj == NULL && gc_handle != 0) {
if (obj == NULL && gc_handle != INVALID_GCHANDLE) {
obj = [[XamarinAssociatedObject alloc] init];
obj->gc_handle = gc_handle;
obj->flags = flags;
obj->native_object = self;
objc_setAssociatedObject (self, associated_key, obj, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[obj release];
}
if (obj != NULL)
if (obj != NULL) {
obj->gc_handle = gc_handle;
obj->flags = flags;
}
pthread_mutex_lock (&gchandle_hash_lock);
if (gchandle_hash == NULL)
if (gchandle_hash == NULL) {
CFDictionaryValueCallBacks value_callbacks;
value_callbacks.release = release_gchandle_dictionary_entry;
gchandle_hash = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, NULL, NULL);
if (gc_handle == 0) {
}
if (gc_handle == INVALID_GCHANDLE) {
CFDictionaryRemoveValue (gchandle_hash, self);
} else {
CFDictionarySetValue (gchandle_hash, self, GINT_TO_POINTER (gc_handle));
struct gchandle_dictionary_entry *entry = (struct gchandle_dictionary_entry *) malloc (sizeof (struct gchandle_dictionary_entry));
entry->gc_handle = gc_handle;
entry->flags = flags;
CFDictionarySetValue (gchandle_hash, self, entry);
}
pthread_mutex_unlock (&gchandle_hash_lock);
}
uint32_t
GCHandle
xamarin_get_gchandle_trampoline (id self, SEL sel)
{
// COOP: Called by ObjC (when the getGCHandle selector is called on an object).
@ -762,16 +784,58 @@ xamarin_get_gchandle_trampoline (id self, SEL sel)
MONO_ASSERT_GC_SAFE;
/* This is for types registered using the dynamic registrar */
uint32_t gc_handle = 0;
GCHandle gc_handle = INVALID_GCHANDLE;
pthread_mutex_lock (&gchandle_hash_lock);
if (gchandle_hash != NULL)
gc_handle = GPOINTER_TO_UINT (CFDictionaryGetValue (gchandle_hash, self));
if (gchandle_hash != NULL) {
struct gchandle_dictionary_entry *entry;
entry = (struct gchandle_dictionary_entry *) CFDictionaryGetValue (gchandle_hash, self);
if (entry != NULL)
gc_handle = entry->gc_handle;
}
pthread_mutex_unlock (&gchandle_hash_lock);
return gc_handle;
}
enum XamarinGCHandleFlags
xamarin_get_flags_trampoline (id self, SEL sel)
{
// COOP: Called by ObjC (when the getFlags selector is called on an object).
// COOP: Safe mode upon entry, and doesn't access managed memory, so no need to switch.
MONO_ASSERT_GC_SAFE;
/* This is for types registered using the dynamic registrar */
enum XamarinGCHandleFlags flags = XamarinGCHandleFlags_None;
pthread_mutex_lock (&gchandle_hash_lock);
if (gchandle_hash != NULL) {
struct gchandle_dictionary_entry *entry;
entry = (struct gchandle_dictionary_entry *) CFDictionaryGetValue (gchandle_hash, self);
if (entry != NULL)
flags = entry->flags;
}
pthread_mutex_unlock (&gchandle_hash_lock);
return flags;
}
void
xamarin_set_flags_trampoline (id self, SEL sel, enum XamarinGCHandleFlags flags)
{
// COOP: Called by ObjC (when the setFlags: selector is called on an object).
// COOP: Safe mode upon entry, and doesn't access managed memory, so no need to switch.
MONO_ASSERT_GC_SAFE;
/* This is for types registered using the dynamic registrar */
pthread_mutex_lock (&gchandle_hash_lock);
if (gchandle_hash != NULL) {
struct gchandle_dictionary_entry *entry;
entry = (struct gchandle_dictionary_entry *) CFDictionaryGetValue (gchandle_hash, self);
if (entry != NULL)
entry->flags = flags;
}
pthread_mutex_unlock (&gchandle_hash_lock);
}
id
xamarin_generate_conversion_to_native (MonoObject *value, MonoType *inputType, MonoType *outputType, MonoMethod *method, void *context, guint32 *exception_gchandle)
xamarin_generate_conversion_to_native (MonoObject *value, MonoType *inputType, MonoType *outputType, MonoMethod *method, void *context, GCHandle *exception_gchandle)
{
// COOP: Reads managed memory, needs to be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
@ -791,7 +855,7 @@ xamarin_generate_conversion_to_native (MonoObject *value, MonoType *inputType, M
MonoClass *nullableManagedType = NULL;
bool isManagedNullable = xamarin_is_class_nullable (managedType, &nullableManagedType, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (isManagedArray != isNativeArray) {
@ -822,16 +886,16 @@ xamarin_generate_conversion_to_native (MonoObject *value, MonoType *inputType, M
*exception_gchandle = xamarin_create_bindas_exception (inputType, outputType, method);
goto exception_handling;
}
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (isManagedArray) {
convertedValue = xamarin_convert_managed_to_nsarray_with_func ((MonoArray *) value, func, context, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
} else {
convertedValue = func (value, context, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
}
}
@ -843,7 +907,7 @@ exception_handling:
void *
xamarin_generate_conversion_to_managed (id value, MonoType *inputType, MonoType *outputType, MonoMethod *method, guint32 *exception_gchandle, void *context, /*SList*/ void **free_list)
xamarin_generate_conversion_to_managed (id value, MonoType *inputType, MonoType *outputType, MonoMethod *method, GCHandle *exception_gchandle, void *context, /*SList*/ void **free_list)
{
// COOP: Reads managed memory, needs to be in UNSAFE mode
MONO_ASSERT_GC_UNSAFE;
@ -863,7 +927,7 @@ xamarin_generate_conversion_to_managed (id value, MonoType *inputType, MonoType
MonoClass *nullableManagedType = NULL;
bool isManagedNullable = xamarin_is_class_nullable (managedType, &nullableManagedType, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (isManagedArray != isNativeArray) {
@ -894,16 +958,16 @@ xamarin_generate_conversion_to_managed (id value, MonoType *inputType, MonoType
*exception_gchandle = xamarin_create_bindas_exception (inputType, outputType, method);
goto exception_handling;
}
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (isManagedArray) {
convertedValue = xamarin_convert_nsarray_to_managed_with_func (value, underlyingManagedType, func, context, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
} else {
convertedValue = func (value, NULL, underlyingManagedType, context, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
*(SList **) free_list = s_list_prepend (*(SList **) free_list, convertedValue);
@ -922,55 +986,55 @@ exception_handling:
// Returns a pointer to the value type, which must be freed using xamarin_free.
// If called multiple times in succession, the returned pointer can be passed as the second ptr argument, and it need only be freed once done iterating.
void *xamarin_nsnumber_to_bool (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { BOOL *valueptr = (BOOL *) (ptr ? ptr : xamarin_calloc (sizeof (BOOL))); *valueptr = [number boolValue]; return valueptr; }
void *xamarin_nsnumber_to_sbyte (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { int8_t *valueptr = (int8_t *) (ptr ? ptr : xamarin_calloc (sizeof (int8_t))); *valueptr = [number charValue]; return valueptr; }
void *xamarin_nsnumber_to_byte (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { uint8_t *valueptr = (uint8_t *) (ptr ? ptr : xamarin_calloc (sizeof (uint8_t))); *valueptr = [number unsignedCharValue]; return valueptr; }
void *xamarin_nsnumber_to_short (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { int16_t *valueptr = (int16_t *) (ptr ? ptr : xamarin_calloc (sizeof (int16_t))); *valueptr = [number shortValue]; return valueptr; }
void *xamarin_nsnumber_to_ushort (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { uint16_t *valueptr = (uint16_t *) (ptr ? ptr : xamarin_calloc (sizeof (uint16_t))); *valueptr = [number unsignedShortValue]; return valueptr; }
void *xamarin_nsnumber_to_int (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { int32_t *valueptr = (int32_t *) (ptr ? ptr : xamarin_calloc (sizeof (int32_t))); *valueptr = [number intValue]; return valueptr; }
void *xamarin_nsnumber_to_uint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { uint32_t *valueptr = (uint32_t *) (ptr ? ptr : xamarin_calloc (sizeof (uint32_t))); *valueptr = [number unsignedIntValue]; return valueptr; }
void *xamarin_nsnumber_to_long (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { int64_t *valueptr = (int64_t *) (ptr ? ptr : xamarin_calloc (sizeof (int64_t))); *valueptr = [number longLongValue]; return valueptr; }
void *xamarin_nsnumber_to_ulong (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { uint64_t *valueptr = (uint64_t *) (ptr ? ptr : xamarin_calloc (sizeof (uint64_t))); *valueptr = [number unsignedLongLongValue]; return valueptr; }
void *xamarin_nsnumber_to_nint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { NSInteger *valueptr = (NSInteger *) (ptr ? ptr : xamarin_calloc (sizeof (NSInteger))); *valueptr = [number integerValue]; return valueptr; }
void *xamarin_nsnumber_to_nuint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { NSUInteger *valueptr = (NSUInteger *) (ptr ? ptr : xamarin_calloc (sizeof (NSUInteger))); *valueptr = [number unsignedIntegerValue]; return valueptr; }
void *xamarin_nsnumber_to_float (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { float *valueptr = (float *) (ptr ? ptr : xamarin_calloc (sizeof (float))); *valueptr = [number floatValue]; return valueptr; }
void *xamarin_nsnumber_to_double (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { double *valueptr = (double *) (ptr ? ptr : xamarin_calloc (sizeof (double))); *valueptr = [number doubleValue]; return valueptr; }
void *xamarin_nsnumber_to_bool (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { BOOL *valueptr = (BOOL *) (ptr ? ptr : xamarin_calloc (sizeof (BOOL))); *valueptr = [number boolValue]; return valueptr; }
void *xamarin_nsnumber_to_sbyte (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { int8_t *valueptr = (int8_t *) (ptr ? ptr : xamarin_calloc (sizeof (int8_t))); *valueptr = [number charValue]; return valueptr; }
void *xamarin_nsnumber_to_byte (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { uint8_t *valueptr = (uint8_t *) (ptr ? ptr : xamarin_calloc (sizeof (uint8_t))); *valueptr = [number unsignedCharValue]; return valueptr; }
void *xamarin_nsnumber_to_short (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { int16_t *valueptr = (int16_t *) (ptr ? ptr : xamarin_calloc (sizeof (int16_t))); *valueptr = [number shortValue]; return valueptr; }
void *xamarin_nsnumber_to_ushort (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { uint16_t *valueptr = (uint16_t *) (ptr ? ptr : xamarin_calloc (sizeof (uint16_t))); *valueptr = [number unsignedShortValue]; return valueptr; }
void *xamarin_nsnumber_to_int (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { int32_t *valueptr = (int32_t *) (ptr ? ptr : xamarin_calloc (sizeof (int32_t))); *valueptr = [number intValue]; return valueptr; }
void *xamarin_nsnumber_to_uint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { uint32_t *valueptr = (uint32_t *) (ptr ? ptr : xamarin_calloc (sizeof (uint32_t))); *valueptr = [number unsignedIntValue]; return valueptr; }
void *xamarin_nsnumber_to_long (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { int64_t *valueptr = (int64_t *) (ptr ? ptr : xamarin_calloc (sizeof (int64_t))); *valueptr = [number longLongValue]; return valueptr; }
void *xamarin_nsnumber_to_ulong (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { uint64_t *valueptr = (uint64_t *) (ptr ? ptr : xamarin_calloc (sizeof (uint64_t))); *valueptr = [number unsignedLongLongValue]; return valueptr; }
void *xamarin_nsnumber_to_nint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { NSInteger *valueptr = (NSInteger *) (ptr ? ptr : xamarin_calloc (sizeof (NSInteger))); *valueptr = [number integerValue]; return valueptr; }
void *xamarin_nsnumber_to_nuint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { NSUInteger *valueptr = (NSUInteger *) (ptr ? ptr : xamarin_calloc (sizeof (NSUInteger))); *valueptr = [number unsignedIntegerValue]; return valueptr; }
void *xamarin_nsnumber_to_float (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { float *valueptr = (float *) (ptr ? ptr : xamarin_calloc (sizeof (float))); *valueptr = [number floatValue]; return valueptr; }
void *xamarin_nsnumber_to_double (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { double *valueptr = (double *) (ptr ? ptr : xamarin_calloc (sizeof (double))); *valueptr = [number doubleValue]; return valueptr; }
#if __POINTER_WIDTH__ == 32
void *xamarin_nsnumber_to_nfloat (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { float *valueptr = (float *) (ptr ? ptr : xamarin_calloc (sizeof (float))); *valueptr = [number floatValue]; return valueptr; }
void *xamarin_nsnumber_to_nfloat (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { float *valueptr = (float *) (ptr ? ptr : xamarin_calloc (sizeof (float))); *valueptr = [number floatValue]; return valueptr; }
#elif __POINTER_WIDTH__ == 64
void *xamarin_nsnumber_to_nfloat (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { double *valueptr = (double *) (ptr ? ptr : xamarin_calloc (sizeof (double))); *valueptr = [number doubleValue]; return valueptr; }
void *xamarin_nsnumber_to_nfloat (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { double *valueptr = (double *) (ptr ? ptr : xamarin_calloc (sizeof (double))); *valueptr = [number doubleValue]; return valueptr; }
#else
#error Invalid pointer size.
#endif
// Returns a pointer to the value type, which must be freed using xamarin_free.
// If called multiple times in succession, the returned pointer can be passed as the second ptr argument, and it need only be freed once done iterating.
void *xamarin_nsvalue_to_nsrange (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { NSRange *valueptr = (NSRange *) (ptr ? ptr : xamarin_calloc (sizeof (NSRange))); *valueptr = [value rangeValue]; return valueptr; }
void *xamarin_nsvalue_to_nsrange (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { NSRange *valueptr = (NSRange *) (ptr ? ptr : xamarin_calloc (sizeof (NSRange))); *valueptr = [value rangeValue]; return valueptr; }
#if HAVE_UIKIT // Yep, these CoreGraphics-looking category method is defined in UIKit.
void *xamarin_nsvalue_to_cgaffinetransform (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CGAffineTransform *valueptr = (CGAffineTransform *) (ptr ? ptr : xamarin_calloc (sizeof (CGAffineTransform))); *valueptr = [value CGAffineTransformValue]; return valueptr; }
void *xamarin_nsvalue_to_cgpoint (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CGPoint *valueptr = (CGPoint *) (ptr ? ptr : xamarin_calloc (sizeof (CGPoint))); *valueptr = [value CGPointValue]; return valueptr; }
void *xamarin_nsvalue_to_cgrect (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CGRect *valueptr = (CGRect *) (ptr ? ptr : xamarin_calloc (sizeof (CGRect))); *valueptr = [value CGRectValue]; return valueptr; }
void *xamarin_nsvalue_to_cgsize (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CGSize *valueptr = (CGSize *) (ptr ? ptr : xamarin_calloc (sizeof (CGSize))); *valueptr = [value CGSizeValue]; return valueptr; }
void *xamarin_nsvalue_to_cgvector (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CGVector *valueptr = (CGVector *) (ptr ? ptr : xamarin_calloc (sizeof (CGVector))); *valueptr = [value CGVectorValue]; return valueptr; }
void *xamarin_nsvalue_to_nsdirectionaledgeinsets(NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) {NSDirectionalEdgeInsets *valueptr =(NSDirectionalEdgeInsets *) (ptr ? ptr : xamarin_calloc (sizeof (NSDirectionalEdgeInsets)));*valueptr = [value directionalEdgeInsetsValue];return valueptr; }
void *xamarin_nsvalue_to_cgaffinetransform (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CGAffineTransform *valueptr = (CGAffineTransform *) (ptr ? ptr : xamarin_calloc (sizeof (CGAffineTransform))); *valueptr = [value CGAffineTransformValue]; return valueptr; }
void *xamarin_nsvalue_to_cgpoint (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CGPoint *valueptr = (CGPoint *) (ptr ? ptr : xamarin_calloc (sizeof (CGPoint))); *valueptr = [value CGPointValue]; return valueptr; }
void *xamarin_nsvalue_to_cgrect (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CGRect *valueptr = (CGRect *) (ptr ? ptr : xamarin_calloc (sizeof (CGRect))); *valueptr = [value CGRectValue]; return valueptr; }
void *xamarin_nsvalue_to_cgsize (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CGSize *valueptr = (CGSize *) (ptr ? ptr : xamarin_calloc (sizeof (CGSize))); *valueptr = [value CGSizeValue]; return valueptr; }
void *xamarin_nsvalue_to_cgvector (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CGVector *valueptr = (CGVector *) (ptr ? ptr : xamarin_calloc (sizeof (CGVector))); *valueptr = [value CGVectorValue]; return valueptr; }
void *xamarin_nsvalue_to_nsdirectionaledgeinsets(NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) {NSDirectionalEdgeInsets *valueptr =(NSDirectionalEdgeInsets *) (ptr ? ptr : xamarin_calloc (sizeof (NSDirectionalEdgeInsets)));*valueptr = [value directionalEdgeInsetsValue];return valueptr; }
#endif
#if HAVE_COREANIMATION
void *xamarin_nsvalue_to_catransform3d (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CATransform3D *valueptr = (CATransform3D *) (ptr ? ptr : xamarin_calloc (sizeof (CATransform3D))); *valueptr = [value CATransform3DValue]; return valueptr; }
void *xamarin_nsvalue_to_catransform3d (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CATransform3D *valueptr = (CATransform3D *) (ptr ? ptr : xamarin_calloc (sizeof (CATransform3D))); *valueptr = [value CATransform3DValue]; return valueptr; }
#endif
#if HAVE_MAPKIT // Yep, this is defined in MapKit.
void *xamarin_nsvalue_to_cllocationcoordinate2d (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CLLocationCoordinate2D *valueptr = (CLLocationCoordinate2D *) (ptr ? ptr : xamarin_calloc (sizeof (CLLocationCoordinate2D))); *valueptr = [value MKCoordinateValue]; return valueptr; }
void *xamarin_nsvalue_to_cllocationcoordinate2d (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CLLocationCoordinate2D *valueptr = (CLLocationCoordinate2D *) (ptr ? ptr : xamarin_calloc (sizeof (CLLocationCoordinate2D))); *valueptr = [value MKCoordinateValue]; return valueptr; }
#endif
#if HAVE_COREMEDIA
void *xamarin_nsvalue_to_cmtime (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CMTime *valueptr = (CMTime *) (ptr ? ptr : xamarin_calloc (sizeof (CMTime))); *valueptr = [value CMTimeValue]; return valueptr; }
void *xamarin_nsvalue_to_cmtimemapping (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CMTimeMapping *valueptr = (CMTimeMapping *) (ptr ? ptr : xamarin_calloc (sizeof (CMTimeMapping))); *valueptr = [value CMTimeMappingValue]; return valueptr; }
void *xamarin_nsvalue_to_cmtimerange (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { CMTimeRange *valueptr = (CMTimeRange *) (ptr ? ptr : xamarin_calloc (sizeof (CMTimeRange))); *valueptr = [value CMTimeRangeValue]; return valueptr; }
void *xamarin_nsvalue_to_cmtime (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CMTime *valueptr = (CMTime *) (ptr ? ptr : xamarin_calloc (sizeof (CMTime))); *valueptr = [value CMTimeValue]; return valueptr; }
void *xamarin_nsvalue_to_cmtimemapping (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CMTimeMapping *valueptr = (CMTimeMapping *) (ptr ? ptr : xamarin_calloc (sizeof (CMTimeMapping))); *valueptr = [value CMTimeMappingValue]; return valueptr; }
void *xamarin_nsvalue_to_cmtimerange (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { CMTimeRange *valueptr = (CMTimeRange *) (ptr ? ptr : xamarin_calloc (sizeof (CMTimeRange))); *valueptr = [value CMTimeRangeValue]; return valueptr; }
#endif
#if HAVE_MAPKIT
void *xamarin_nsvalue_to_mkcoordinatespan (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { MKCoordinateSpan *valueptr = (MKCoordinateSpan *) (ptr ? ptr : xamarin_calloc (sizeof (MKCoordinateSpan))); *valueptr = [value MKCoordinateSpanValue]; return valueptr; }
void *xamarin_nsvalue_to_mkcoordinatespan (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { MKCoordinateSpan *valueptr = (MKCoordinateSpan *) (ptr ? ptr : xamarin_calloc (sizeof (MKCoordinateSpan))); *valueptr = [value MKCoordinateSpanValue]; return valueptr; }
#endif
void *xamarin_nsvalue_to_scnmatrix4 (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { SCNMatrix4 *valueptr = (SCNMatrix4 *) (ptr ? ptr : xamarin_calloc (sizeof (SCNMatrix4))); *valueptr = [value SCNMatrix4Value]; return valueptr; }
void *xamarin_nsvalue_to_scnmatrix4 (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { SCNMatrix4 *valueptr = (SCNMatrix4 *) (ptr ? ptr : xamarin_calloc (sizeof (SCNMatrix4))); *valueptr = [value SCNMatrix4Value]; return valueptr; }
void *
xamarin_nsvalue_to_scnvector3 (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle)
xamarin_nsvalue_to_scnvector3 (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle)
{
#if TARGET_OS_IOS && defined (__arm__)
// In earlier versions of iOS [NSValue SCNVector3Value] would return 4
@ -1008,62 +1072,62 @@ xamarin_nsvalue_to_scnvector3 (NSValue *value, void *ptr, MonoClass *managedType
return valueptr;
}
void *xamarin_nsvalue_to_scnvector4 (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { SCNVector4 *valueptr = (SCNVector4 *) (ptr ? ptr : xamarin_calloc (sizeof (SCNVector4))); *valueptr = [value SCNVector4Value]; return valueptr; }
void *xamarin_nsvalue_to_scnvector4 (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { SCNVector4 *valueptr = (SCNVector4 *) (ptr ? ptr : xamarin_calloc (sizeof (SCNVector4))); *valueptr = [value SCNVector4Value]; return valueptr; }
#if HAVE_UIKIT
void *xamarin_nsvalue_to_uiedgeinsets (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { UIEdgeInsets *valueptr = (UIEdgeInsets *) (ptr ? ptr : xamarin_calloc (sizeof (UIEdgeInsets))); *valueptr = [value UIEdgeInsetsValue]; return valueptr; }
void *xamarin_nsvalue_to_uioffset (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle) { UIOffset *valueptr = (UIOffset *) (ptr ? ptr : xamarin_calloc (sizeof (UIOffset))); *valueptr = [value UIOffsetValue]; return valueptr; }
void *xamarin_nsvalue_to_uiedgeinsets (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { UIEdgeInsets *valueptr = (UIEdgeInsets *) (ptr ? ptr : xamarin_calloc (sizeof (UIEdgeInsets))); *valueptr = [value UIEdgeInsetsValue]; return valueptr; }
void *xamarin_nsvalue_to_uioffset (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle) { UIOffset *valueptr = (UIOffset *) (ptr ? ptr : xamarin_calloc (sizeof (UIOffset))); *valueptr = [value UIOffsetValue]; return valueptr; }
#endif
id xamarin_bool_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithBool: *(BOOL *) mono_object_unbox (value)]; }
id xamarin_sbyte_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithChar: *(int8_t *) mono_object_unbox (value)]; }
id xamarin_byte_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithUnsignedChar: *(uint8_t *) mono_object_unbox (value)]; }
id xamarin_short_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithShort: *(int16_t *) mono_object_unbox (value)]; }
id xamarin_ushort_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithUnsignedShort: *(uint16_t *) mono_object_unbox (value)]; }
id xamarin_int_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithInt: *(int32_t *) mono_object_unbox (value)]; }
id xamarin_uint_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithUnsignedInt: *(uint32_t *) mono_object_unbox (value)]; }
id xamarin_long_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithLongLong: *(int64_t *) mono_object_unbox (value)]; }
id xamarin_ulong_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithUnsignedLongLong: *(uint64_t *) mono_object_unbox (value)]; }
id xamarin_nint_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithInteger: *(NSInteger *) mono_object_unbox (value)]; }
id xamarin_nuint_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithUnsignedInteger: *(NSUInteger *) mono_object_unbox (value)]; }
id xamarin_float_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithFloat: *(float *) mono_object_unbox (value)]; }
id xamarin_double_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithDouble: *(double *) mono_object_unbox (value)]; }
id xamarin_bool_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithBool: *(BOOL *) mono_object_unbox (value)]; }
id xamarin_sbyte_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithChar: *(int8_t *) mono_object_unbox (value)]; }
id xamarin_byte_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithUnsignedChar: *(uint8_t *) mono_object_unbox (value)]; }
id xamarin_short_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithShort: *(int16_t *) mono_object_unbox (value)]; }
id xamarin_ushort_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithUnsignedShort: *(uint16_t *) mono_object_unbox (value)]; }
id xamarin_int_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithInt: *(int32_t *) mono_object_unbox (value)]; }
id xamarin_uint_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithUnsignedInt: *(uint32_t *) mono_object_unbox (value)]; }
id xamarin_long_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithLongLong: *(int64_t *) mono_object_unbox (value)]; }
id xamarin_ulong_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithUnsignedLongLong: *(uint64_t *) mono_object_unbox (value)]; }
id xamarin_nint_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithInteger: *(NSInteger *) mono_object_unbox (value)]; }
id xamarin_nuint_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithUnsignedInteger: *(NSUInteger *) mono_object_unbox (value)]; }
id xamarin_float_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithFloat: *(float *) mono_object_unbox (value)]; }
id xamarin_double_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithDouble: *(double *) mono_object_unbox (value)]; }
#if __POINTER_WIDTH__ == 32
id xamarin_nfloat_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithFloat: *(float *) mono_object_unbox (value)]; }
id xamarin_nfloat_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithFloat: *(float *) mono_object_unbox (value)]; }
#elif __POINTER_WIDTH__ == 64
id xamarin_nfloat_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSNumber numberWithDouble: *(double *) mono_object_unbox (value)]; }
id xamarin_nfloat_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSNumber numberWithDouble: *(double *) mono_object_unbox (value)]; }
#else
#error Invalid pointer size.
#endif
id xamarin_nsrange_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithRange: *(NSRange *) mono_object_unbox (value)]; }
id xamarin_nsrange_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithRange: *(NSRange *) mono_object_unbox (value)]; }
#if HAVE_UIKIT // yep, these CoreGraphics-looking category methods are defined in UIKit
id xamarin_cgaffinetransform_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCGAffineTransform: *(CGAffineTransform *) mono_object_unbox (value)]; }
id xamarin_cgpoint_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCGPoint: *(CGPoint *) mono_object_unbox (value)]; }
id xamarin_cgrect_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCGRect: *(CGRect *) mono_object_unbox (value)]; }
id xamarin_cgsize_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCGSize: *(CGSize *) mono_object_unbox (value)]; }
id xamarin_cgvector_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCGVector: *(CGVector *) mono_object_unbox (value)]; }
id xamarin_nsdirectionaledgeinsets_to_nsvalue(MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithDirectionalEdgeInsets:*(NSDirectionalEdgeInsets *)mono_object_unbox (value)]; }
id xamarin_cgaffinetransform_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCGAffineTransform: *(CGAffineTransform *) mono_object_unbox (value)]; }
id xamarin_cgpoint_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCGPoint: *(CGPoint *) mono_object_unbox (value)]; }
id xamarin_cgrect_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCGRect: *(CGRect *) mono_object_unbox (value)]; }
id xamarin_cgsize_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCGSize: *(CGSize *) mono_object_unbox (value)]; }
id xamarin_cgvector_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCGVector: *(CGVector *) mono_object_unbox (value)]; }
id xamarin_nsdirectionaledgeinsets_to_nsvalue(MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithDirectionalEdgeInsets:*(NSDirectionalEdgeInsets *)mono_object_unbox (value)]; }
#endif
#if HAVE_COREANIMATION
id xamarin_catransform3d_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCATransform3D: *(CATransform3D *) mono_object_unbox (value)]; }
id xamarin_catransform3d_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCATransform3D: *(CATransform3D *) mono_object_unbox (value)]; }
#endif
#if HAVE_MAPKIT // Yep, this is defined in MapKit.
id xamarin_cllocationcoordinate2d_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithMKCoordinate: *(CLLocationCoordinate2D *) mono_object_unbox (value)]; }
id xamarin_cllocationcoordinate2d_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithMKCoordinate: *(CLLocationCoordinate2D *) mono_object_unbox (value)]; }
#endif
#if HAVE_COREMEDIA
id xamarin_cmtime_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCMTime: *(CMTime *) mono_object_unbox (value)]; }
id xamarin_cmtimemapping_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCMTimeMapping: *(CMTimeMapping *) mono_object_unbox (value)]; }
id xamarin_cmtimerange_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithCMTimeRange: *(CMTimeRange *) mono_object_unbox (value)]; }
id xamarin_cmtime_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCMTime: *(CMTime *) mono_object_unbox (value)]; }
id xamarin_cmtimemapping_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCMTimeMapping: *(CMTimeMapping *) mono_object_unbox (value)]; }
id xamarin_cmtimerange_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithCMTimeRange: *(CMTimeRange *) mono_object_unbox (value)]; }
#endif
#if HAVE_MAPKIT
id xamarin_mkcoordinatespan_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithMKCoordinateSpan: *(MKCoordinateSpan *) mono_object_unbox (value)]; }
id xamarin_mkcoordinatespan_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithMKCoordinateSpan: *(MKCoordinateSpan *) mono_object_unbox (value)]; }
#endif
id xamarin_scnmatrix4_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithSCNMatrix4: *(SCNMatrix4 *) mono_object_unbox (value)]; }
id xamarin_scnvector3_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithSCNVector3: *(SCNVector3 *) mono_object_unbox (value)]; }
id xamarin_scnvector4_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithSCNVector4: *(SCNVector4 *) mono_object_unbox (value)]; }
id xamarin_scnmatrix4_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithSCNMatrix4: *(SCNMatrix4 *) mono_object_unbox (value)]; }
id xamarin_scnvector3_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithSCNVector3: *(SCNVector3 *) mono_object_unbox (value)]; }
id xamarin_scnvector4_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithSCNVector4: *(SCNVector4 *) mono_object_unbox (value)]; }
#if HAVE_UIKIT
id xamarin_uiedgeinsets_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithUIEdgeInsets: *(UIEdgeInsets *) mono_object_unbox (value)]; }
id xamarin_uioffset_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle) { return [NSValue valueWithUIOffset: *(UIOffset *) mono_object_unbox (value)]; }
id xamarin_uiedgeinsets_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithUIEdgeInsets: *(UIEdgeInsets *) mono_object_unbox (value)]; }
id xamarin_uioffset_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle) { return [NSValue valueWithUIOffset: *(UIOffset *) mono_object_unbox (value)]; }
#endif
#pragma clang diagnostic pop
@ -1078,70 +1142,70 @@ struct conversion_data {
};
id
xamarin_convert_string_to_nsstring (MonoObject *obj, void *context, guint32 *exception_gchandle)
xamarin_convert_string_to_nsstring (MonoObject *obj, void *context, GCHandle *exception_gchandle)
{
return xamarin_string_to_nsstring ((MonoString *) obj, false);
}
void *
xamarin_convert_nsstring_to_string (id value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle)
xamarin_convert_nsstring_to_string (id value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle)
{
return xamarin_nsstring_to_string (NULL, (NSString *) value);
}
id
xamarin_object_to_nsobject (MonoObject *object, void *context, guint32 *exception_gchandle)
xamarin_object_to_nsobject (MonoObject *object, void *context, GCHandle *exception_gchandle)
{
return xamarin_get_nsobject_handle (object);
}
id
xamarin_inativeobject_to_nsobject (MonoObject *object, void *context, guint32 *exception_gchandle)
xamarin_inativeobject_to_nsobject (MonoObject *object, void *context, GCHandle *exception_gchandle)
{
return xamarin_get_handle_for_inativeobject (object, exception_gchandle);
}
void *
xamarin_nsobject_to_object (id object, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle)
xamarin_nsobject_to_object (id object, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle)
{
struct conversion_data * data = (struct conversion_data *) context;
return xamarin_get_nsobject_with_type_for_ptr (object, false, data->element_type, exception_gchandle);
}
void *
xamarin_nsobject_to_inativeobject (id object, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle)
xamarin_nsobject_to_inativeobject (id object, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle)
{
struct conversion_data * data = (struct conversion_data *) context;
return xamarin_get_inative_object_dynamic (object, false, data->element_reflection_type, exception_gchandle);
}
void *
xamarin_nsobject_to_inativeobject_static (id object, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle)
xamarin_nsobject_to_inativeobject_static (id object, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle)
{
struct conversion_data * data = (struct conversion_data *) context;
return xamarin_get_inative_object_static (object, false, data->iface_token_ref, data->implementation_token_ref, exception_gchandle);
}
NSArray *
xamarin_managed_string_array_to_nsarray (MonoArray *array, guint32 *exception_gchandle)
xamarin_managed_string_array_to_nsarray (MonoArray *array, GCHandle *exception_gchandle)
{
return xamarin_convert_managed_to_nsarray_with_func (array, xamarin_convert_string_to_nsstring, 0, exception_gchandle);
}
NSArray *
xamarin_managed_nsobject_array_to_nsarray (MonoArray *array, guint32 *exception_gchandle)
xamarin_managed_nsobject_array_to_nsarray (MonoArray *array, GCHandle *exception_gchandle)
{
return xamarin_convert_managed_to_nsarray_with_func (array, xamarin_object_to_nsobject, 0, exception_gchandle);
}
NSArray *
xamarin_managed_inativeobject_array_to_nsarray (MonoArray *array, guint32 *exception_gchandle)
xamarin_managed_inativeobject_array_to_nsarray (MonoArray *array, GCHandle *exception_gchandle)
{
return xamarin_convert_managed_to_nsarray_with_func (array, xamarin_inativeobject_to_nsobject, 0, exception_gchandle);
}
NSArray *
xamarin_managed_array_to_nsarray (MonoArray *array, MonoType *managed_type, MonoClass *managed_class, guint32 *exception_gchandle)
xamarin_managed_array_to_nsarray (MonoArray *array, MonoType *managed_type, MonoClass *managed_class, GCHandle *exception_gchandle)
{
if (array == NULL)
return NULL;
@ -1161,7 +1225,7 @@ xamarin_managed_array_to_nsarray (MonoArray *array, MonoType *managed_type, Mono
// Don't know how to convert: show an exception.
char *element_name = xamarin_type_get_full_name (mono_class_get_type (e_klass), exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return NULL;
char *msg = xamarin_strdup_printf ("Unable to convert from a managed array of %s to an NSArray.", element_name);
*exception_gchandle = xamarin_create_product_exception_with_inner_exception (8032, *exception_gchandle, msg);
@ -1171,13 +1235,13 @@ xamarin_managed_array_to_nsarray (MonoArray *array, MonoType *managed_type, Mono
}
MonoArray *
xamarin_nsarray_to_managed_string_array (NSArray *array, guint32 *exception_gchandle)
xamarin_nsarray_to_managed_string_array (NSArray *array, GCHandle *exception_gchandle)
{
return xamarin_convert_nsarray_to_managed_with_func (array, mono_get_string_class (), xamarin_convert_nsstring_to_string, 0, exception_gchandle);
}
MonoArray *
xamarin_nsarray_to_managed_nsobject_array (NSArray *array, MonoType *array_type, MonoClass *element_class, guint32 *exception_gchandle)
xamarin_nsarray_to_managed_nsobject_array (NSArray *array, MonoType *array_type, MonoClass *element_class, GCHandle *exception_gchandle)
{
struct conversion_data data = { 0 };
data.domain = mono_domain_get ();
@ -1188,7 +1252,7 @@ xamarin_nsarray_to_managed_nsobject_array (NSArray *array, MonoType *array_type,
}
MonoArray *
xamarin_nsarray_to_managed_inativeobject_array (NSArray *array, MonoType *array_type, MonoClass *element_class, guint32 *exception_gchandle)
xamarin_nsarray_to_managed_inativeobject_array (NSArray *array, MonoType *array_type, MonoClass *element_class, GCHandle *exception_gchandle)
{
struct conversion_data data = { 0 };
data.domain = mono_domain_get ();
@ -1199,7 +1263,7 @@ xamarin_nsarray_to_managed_inativeobject_array (NSArray *array, MonoType *array_
}
MonoArray *
xamarin_nsarray_to_managed_inativeobject_array_static (NSArray *array, MonoType *array_type, MonoClass *element_class, uint32_t iface_token_ref, uint32_t implementation_token_ref, guint32 *exception_gchandle)
xamarin_nsarray_to_managed_inativeobject_array_static (NSArray *array, MonoType *array_type, MonoClass *element_class, uint32_t iface_token_ref, uint32_t implementation_token_ref, GCHandle *exception_gchandle)
{
struct conversion_data data = { 0 };
data.element_class = element_class == NULL ? mono_class_get_element_class (mono_class_from_mono_type (array_type)) : element_class;
@ -1210,7 +1274,7 @@ xamarin_nsarray_to_managed_inativeobject_array_static (NSArray *array, MonoType
}
MonoArray *
xamarin_nsarray_to_managed_array (NSArray *array, MonoType *managed_type, MonoClass *managed_class, guint32 *exception_gchandle)
xamarin_nsarray_to_managed_array (NSArray *array, MonoType *managed_type, MonoClass *managed_class, GCHandle *exception_gchandle)
{
if (array == NULL)
return NULL;
@ -1229,7 +1293,7 @@ xamarin_nsarray_to_managed_array (NSArray *array, MonoType *managed_type, MonoCl
// Don't know how to convert: show an exception.
char *element_name = xamarin_type_get_full_name (mono_class_get_type (e_klass), exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return NULL;
char *msg = xamarin_strdup_printf ("Unable to convert from an NSArray to a managed array of %s.", element_name);
*exception_gchandle = xamarin_create_product_exception_with_inner_exception (8031, *exception_gchandle, msg);
@ -1239,12 +1303,12 @@ xamarin_nsarray_to_managed_array (NSArray *array, MonoType *managed_type, MonoCl
}
static void *
xamarin_get_nsnumber_converter (MonoClass *managedType, MonoMethod *method, bool to_managed, guint32 *exception_gchandle)
xamarin_get_nsnumber_converter (MonoClass *managedType, MonoMethod *method, bool to_managed, GCHandle *exception_gchandle)
{
int type;
void * func = NULL;
char *fullname = xamarin_class_get_full_name (managedType, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
type = mono_type_get_type (mono_class_get_type (managedType));
@ -1305,11 +1369,11 @@ exception_handling:
}
static void *
xamarin_get_nsvalue_converter (MonoClass *managedType, MonoMethod *method, bool to_managed, guint32 *exception_gchandle)
xamarin_get_nsvalue_converter (MonoClass *managedType, MonoMethod *method, bool to_managed, GCHandle *exception_gchandle)
{
void * func = NULL;
char *fullname = xamarin_class_get_full_name (managedType, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
if (!strcmp (fullname, "Foundation.NSRange")) {
@ -1372,31 +1436,31 @@ exception_handling:
}
xamarin_id_to_managed_func
xamarin_get_nsnumber_to_managed_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle)
xamarin_get_nsnumber_to_managed_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle)
{
return (xamarin_id_to_managed_func) xamarin_get_nsnumber_converter (managedType, method, true, exception_gchandle);
}
xamarin_managed_to_id_func
xamarin_get_managed_to_nsnumber_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle)
xamarin_get_managed_to_nsnumber_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle)
{
return (xamarin_managed_to_id_func) xamarin_get_nsnumber_converter (managedType, method, false, exception_gchandle);
}
xamarin_id_to_managed_func
xamarin_get_nsvalue_to_managed_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle)
xamarin_get_nsvalue_to_managed_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle)
{
return (xamarin_id_to_managed_func) xamarin_get_nsvalue_converter (managedType, method, true, exception_gchandle);
}
xamarin_managed_to_id_func
xamarin_get_managed_to_nsvalue_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle)
xamarin_get_managed_to_nsvalue_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle)
{
return (xamarin_managed_to_id_func) xamarin_get_nsvalue_converter (managedType, method, false, exception_gchandle);
}
void *
xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */, guint32 *exception_gchandle)
xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */, GCHandle *exception_gchandle)
{
guint32 context_ref = GPOINTER_TO_UINT (context);
if (context_ref == INVALID_TOKEN_REF) {
@ -1412,14 +1476,14 @@ xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */
void *arg_ptrs [1];
managed_method = xamarin_get_managed_method_for_token (context_ref /* token ref */, exception_gchandle);
if (*exception_gchandle != 0) return NULL;
if (*exception_gchandle != INVALID_GCHANDLE) return NULL;
arg_ptrs [0] = mono_object_unbox (value);
retval = mono_runtime_invoke (managed_method, NULL, arg_ptrs, &exception);
if (exception) {
*exception_gchandle = mono_gchandle_new (exception, FALSE);
*exception_gchandle = xamarin_gchandle_new (exception, FALSE);
return NULL;
}
@ -1431,7 +1495,7 @@ xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */
}
void *
xamarin_nsstring_to_smart_enum (id value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle)
xamarin_nsstring_to_smart_enum (id value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle)
{
guint32 context_ref = GPOINTER_TO_UINT (context);
MonoObject *obj;
@ -1439,7 +1503,7 @@ xamarin_nsstring_to_smart_enum (id value, void *ptr, MonoClass *managedType, voi
if (context_ref == INVALID_TOKEN_REF) {
// This requires the dynamic registrar to invoke the correct conversion function
obj = xamarin_convert_nsstring_to_smart_enum (value, mono_type_get_object (mono_domain_get (), mono_class_get_type (managedType)), exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return ptr;
} else {
// The static registrar found the correct conversion function, and provided a token ref we can use
@ -1449,15 +1513,15 @@ xamarin_nsstring_to_smart_enum (id value, void *ptr, MonoClass *managedType, voi
MonoObject *exception = NULL;
managed_method = xamarin_get_managed_method_for_token (context_ref /* token ref */, exception_gchandle);
if (*exception_gchandle != 0) return NULL;
if (*exception_gchandle != INVALID_GCHANDLE) return NULL;
arg_ptrs [0] = xamarin_get_nsobject_with_type_for_ptr (value, false, xamarin_get_parameter_type (managed_method, 0), exception_gchandle);
if (*exception_gchandle != 0) return NULL;
if (*exception_gchandle != INVALID_GCHANDLE) return NULL;
obj = mono_runtime_invoke (managed_method, NULL, arg_ptrs, &exception);
if (exception) {
*exception_gchandle = mono_gchandle_new (exception, FALSE);
*exception_gchandle = xamarin_gchandle_new (exception, FALSE);
return NULL;
}
}
@ -1471,19 +1535,19 @@ xamarin_nsstring_to_smart_enum (id value, void *ptr, MonoClass *managedType, voi
}
xamarin_id_to_managed_func
xamarin_get_nsstring_to_smart_enum_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle)
xamarin_get_nsstring_to_smart_enum_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle)
{
return xamarin_nsstring_to_smart_enum;
}
xamarin_managed_to_id_func
xamarin_get_smart_enum_to_nsstring_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle)
xamarin_get_smart_enum_to_nsstring_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle)
{
return (xamarin_managed_to_id_func) xamarin_smart_enum_to_nsstring;
}
NSArray *
xamarin_convert_managed_to_nsarray_with_func (MonoArray *array, xamarin_managed_to_id_func convert, void *context, guint32 *exception_gchandle)
xamarin_convert_managed_to_nsarray_with_func (MonoArray *array, xamarin_managed_to_id_func convert, void *context, GCHandle *exception_gchandle)
{
id *buf = NULL;
NSArray *rv = NULL;
@ -1512,7 +1576,7 @@ xamarin_convert_managed_to_nsarray_with_func (MonoArray *array, xamarin_managed_
value = mono_array_get (array, MonoObject *, i);
}
buf [i] = convert (value, context, exception_gchandle);
if (*exception_gchandle != 0) {
if (*exception_gchandle != INVALID_GCHANDLE) {
*exception_gchandle = xamarin_get_exception_for_element_conversion_failure (*exception_gchandle, i);
goto exception_handling;
}
@ -1526,7 +1590,7 @@ exception_handling:
}
MonoArray *
xamarin_convert_nsarray_to_managed_with_func (NSArray *array, MonoClass *managedElementType, xamarin_id_to_managed_func convert, void *context, guint32 *exception_gchandle)
xamarin_convert_nsarray_to_managed_with_func (NSArray *array, MonoClass *managedElementType, xamarin_id_to_managed_func convert, void *context, GCHandle *exception_gchandle)
{
if (array == NULL)
return NULL;
@ -1556,7 +1620,7 @@ xamarin_convert_nsarray_to_managed_with_func (NSArray *array, MonoClass *managed
mobj = (MonoObject *) convert ([array objectAtIndex: i], NULL, managedElementType, context, exception_gchandle);
mono_array_setref (rv, i, mobj);
}
if (*exception_gchandle != 0) {
if (*exception_gchandle != INVALID_GCHANDLE) {
*exception_gchandle = xamarin_get_exception_for_element_conversion_failure (*exception_gchandle, i);
goto exception_handling;
}
@ -1569,45 +1633,45 @@ exception_handling:
}
NSNumber *
xamarin_convert_managed_to_nsnumber (MonoObject *value, MonoClass *managedType, MonoMethod *method, void *context, guint32 *exception_gchandle)
xamarin_convert_managed_to_nsnumber (MonoObject *value, MonoClass *managedType, MonoMethod *method, void *context, GCHandle *exception_gchandle)
{
xamarin_managed_to_id_func convert = xamarin_get_managed_to_nsnumber_func (managedType, method, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return NULL;
return convert (value, context, exception_gchandle);
}
NSValue *
xamarin_convert_managed_to_nsvalue (MonoObject *value, MonoClass *managedType, MonoMethod *method, void *context, guint32 *exception_gchandle)
xamarin_convert_managed_to_nsvalue (MonoObject *value, MonoClass *managedType, MonoMethod *method, void *context, GCHandle *exception_gchandle)
{
xamarin_managed_to_id_func convert = xamarin_get_managed_to_nsvalue_func (managedType, method, exception_gchandle);
if (*exception_gchandle != 0)
if (*exception_gchandle != INVALID_GCHANDLE)
return NULL;
return convert (value, context, exception_gchandle);
}
guint32
GCHandle
xamarin_create_bindas_exception (MonoType *inputType, MonoType *outputType, MonoMethod *method)
{
guint32 exception_gchandle;
GCHandle exception_gchandle;
char *to_name = NULL;
char *from_name = NULL;
char *method_full_name = NULL;
char *msg = NULL;
from_name = xamarin_type_get_full_name (inputType, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
to_name = xamarin_type_get_full_name (outputType, &exception_gchandle);
if (exception_gchandle != 0)
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
method_full_name = mono_method_full_name (method, TRUE);
msg = xamarin_strdup_printf ("Internal error: can't convert from '%s' to '%s' in %s. Please file a bug report with a test case (https://github.com/xamarin/xamarin-macios/issues/new).",
from_name, to_name, method_full_name);
exception_gchandle = mono_gchandle_new ((MonoObject *) xamarin_create_exception (msg), false);
exception_gchandle = xamarin_gchandle_new ((MonoObject *) xamarin_create_exception (msg), false);
exception_handling:
xamarin_free (to_name);

Просмотреть файл

@ -19,6 +19,7 @@
#include "main.h"
#include "mono-runtime.h"
#include "runtime-generated.h"
#include "trampolines.h"
#ifdef __cplusplus
extern "C" {
@ -166,8 +167,8 @@ void xamarin_assertion_message (const char *msg, ...) __attribute__((__noretur
const char * xamarin_get_bundle_path (); /* Public API */
// Sets the bundle path (where the managed executable is). By default APP/Contents/MonoBundle.
void xamarin_set_bundle_path (const char *path); /* Public API */
MonoObject * xamarin_get_managed_object_for_ptr_fast (id self, guint32 *exception_gchandle);
void xamarin_check_for_gced_object (MonoObject *obj, SEL sel, id self, MonoMethod *method, guint32 *exception_gchandle);
MonoObject * xamarin_get_managed_object_for_ptr_fast (id self, GCHandle *exception_gchandle);
void xamarin_check_for_gced_object (MonoObject *obj, SEL sel, id self, MonoMethod *method, GCHandle *exception_gchandle);
unsigned long xamarin_objc_type_size (const char *type);
bool xamarin_is_class_nsobject (MonoClass *cls);
bool xamarin_is_class_inativeobject (MonoClass *cls);
@ -175,32 +176,32 @@ bool xamarin_is_class_array (MonoClass *cls);
bool xamarin_is_class_nsnumber (MonoClass *cls);
bool xamarin_is_class_nsvalue (MonoClass *cls);
bool xamarin_is_class_nsstring (MonoClass *cls);
bool xamarin_is_class_nullable (MonoClass *cls, MonoClass **element_type, guint32 *exception_gchandle);
MonoClass * xamarin_get_nullable_type (MonoClass *cls, guint32 *exception_gchandle);
bool xamarin_is_class_nullable (MonoClass *cls, MonoClass **element_type, GCHandle *exception_gchandle);
MonoClass * xamarin_get_nullable_type (MonoClass *cls, GCHandle *exception_gchandle);
MonoType * xamarin_get_parameter_type (MonoMethod *managed_method, int index);
MonoObject * xamarin_get_nsobject_with_type_for_ptr (id self, bool owns, MonoType* type, guint32 *exception_gchandle);
MonoObject * xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *type, int32_t *created, guint32 *exception_gchandle);
MonoObject * xamarin_get_delegate_for_block_parameter (MonoMethod *method, guint32 token_ref, int par, void *nativeBlock, guint32 *exception_gchandle);
id xamarin_get_block_for_delegate (MonoMethod *method, MonoObject *delegate, const char *signature /* NULL allowed, but requires the dynamic registrar at runtime to compute */, guint32 token_ref /* INVALID_TOKEN_REF allowed, but requires the dynamic registrar at runtime */, guint32 *exception_gchandle);
MonoObject * xamarin_get_nsobject_with_type_for_ptr (id self, bool owns, MonoType* type, GCHandle *exception_gchandle);
MonoObject * xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *type, int32_t *created, GCHandle *exception_gchandle);
MonoObject * xamarin_get_delegate_for_block_parameter (MonoMethod *method, guint32 token_ref, int par, void *nativeBlock, GCHandle *exception_gchandle);
id xamarin_get_block_for_delegate (MonoMethod *method, MonoObject *delegate, const char *signature /* NULL allowed, but requires the dynamic registrar at runtime to compute */, guint32 token_ref /* INVALID_TOKEN_REF allowed, but requires the dynamic registrar at runtime */, GCHandle *exception_gchandle);
id xamarin_get_nsobject_handle (MonoObject *obj);
void xamarin_set_nsobject_handle (MonoObject *obj, id handle);
uint8_t xamarin_get_nsobject_flags (MonoObject *obj);
void xamarin_set_nsobject_flags (MonoObject *obj, uint8_t flags);
void xamarin_throw_nsexception (MonoException *exc);
void xamarin_rethrow_managed_exception (guint32 original_gchandle, guint32 *exception_gchandle);
void xamarin_rethrow_managed_exception (GCHandle original_gchandle, GCHandle *exception_gchandle);
MonoException * xamarin_create_exception (const char *msg);
id xamarin_get_handle (MonoObject *obj, guint32 *exception_gchandle);
id xamarin_get_handle (MonoObject *obj, GCHandle *exception_gchandle);
char * xamarin_strdup_printf (const char *msg, ...);
void * xamarin_calloc (size_t size);
void xamarin_free (void *ptr);
MonoMethod * xamarin_get_reflection_method_method (MonoReflectionMethod *method);
MonoMethod * xamarin_get_managed_method_for_token (guint32 token_ref, guint32 *exception_gchandle);
MonoMethod * xamarin_get_managed_method_for_token (guint32 token_ref, GCHandle *exception_gchandle);
void xamarin_framework_peer_lock ();
void xamarin_framework_peer_unlock ();
bool xamarin_file_exists (const char *path);
MonoAssembly * xamarin_open_and_register (const char *path, guint32 *exception_gchandle);
MonoAssembly * xamarin_open_and_register (const char *path, GCHandle *exception_gchandle);
void xamarin_unhandled_exception_handler (MonoObject *exc, gpointer user_data);
void xamarin_ftnptr_exception_handler (guint32 gchandle);
void xamarin_ftnptr_exception_handler (GCHandle gchandle);
void xamarin_create_classes ();
const char * xamarin_skip_encoding_flags (const char *encoding);
void xamarin_add_registration_map (struct MTRegistrationMap *map, bool partial);
@ -210,20 +211,20 @@ void xamarin_release_block_on_main_thread (void *obj);
bool xamarin_has_managed_ref (id self);
bool xamarin_has_managed_ref_safe (id self);
void xamarin_switch_gchandle (id self, bool to_weak);
uint32_t xamarin_get_gchandle (id self);
void xamarin_free_gchandle (id self, uint32_t gchandle);
GCHandle xamarin_get_gchandle (id self);
void xamarin_free_gchandle (id self, GCHandle gchandle);
void xamarin_clear_gchandle (id self);
uint32_t xamarin_get_gchandle_with_flags (id self);
void xamarin_set_gchandle (id self, uint32_t gchandle);
void xamarin_create_gchandle (id self, void *managed_object, uint32_t flags, bool force_weak);
GCHandle xamarin_get_gchandle_with_flags (id self, enum XamarinGCHandleFlags *flags);
void xamarin_set_gchandle_with_flags (id self, GCHandle gchandle, enum XamarinGCHandleFlags flags);
void xamarin_create_gchandle (id self, void *managed_object, enum XamarinGCHandleFlags flags, bool force_weak);
void xamarin_create_managed_ref (id self, void * managed_object, bool retain);
void xamarin_release_managed_ref (id self, MonoObject *managed_obj);
void xamarin_notify_dealloc (id self, uint32_t gchandle);
void xamarin_notify_dealloc (id self, GCHandle gchandle);
int xamarin_main (int argc, char *argv[], enum XamarinLaunchMode launch_mode);
char * xamarin_type_get_full_name (MonoType *type, guint32 *exception_gchandle); // return value must be freed with 'mono_free'
char * xamarin_class_get_full_name (MonoClass *klass, guint32 *exception_gchandle); // return value must be freed with 'mono_free'
char * xamarin_type_get_full_name (MonoType *type, GCHandle *exception_gchandle); // return value must be freed with 'mono_free'
char * xamarin_class_get_full_name (MonoClass *klass, GCHandle *exception_gchandle); // return value must be freed with 'mono_free'
#if DEBUG
void xamarin_verify_parameter (MonoObject *obj, SEL sel, id self, id arg, unsigned long index, MonoClass *expected, MonoMethod *method);
@ -237,10 +238,10 @@ void xamarin_install_unhandled_exception_hook (XamarinUnhandledExcepti
void xamarin_process_nsexception (NSException *exc);
void xamarin_process_nsexception_using_mode (NSException *ns_exception, bool throwManagedAsDefault);
void xamarin_process_managed_exception (MonoObject *exc);
void xamarin_process_managed_exception_gchandle (guint32 gchandle);
void xamarin_process_managed_exception_gchandle (GCHandle gchandle);
void xamarin_throw_product_exception (int code, const char *message);
guint32 xamarin_create_product_exception (int code, const char *message);
guint32 xamarin_create_product_exception_with_inner_exception (int code, guint32 inner_exception_gchandle /* will be freed */, const char *message);
GCHandle xamarin_create_product_exception (int code, const char *message);
GCHandle xamarin_create_product_exception_with_inner_exception (int code, GCHandle inner_exception_gchandle /* will be freed */, const char *message);
NSString * xamarin_print_all_exceptions (MonoObject *exc);
id xamarin_invoke_objc_method_implementation (id self, SEL sel, IMP xamarin_impl);
@ -292,7 +293,8 @@ extern xamarin_register_assemblies_callback xamarin_register_assemblies;
class XamarinObject {
public:
id native_object;
uint32_t gc_handle;
GCHandle gc_handle;
enum XamarinGCHandleFlags flags;
~XamarinObject ();
};
@ -302,13 +304,15 @@ public:
@interface XamarinAssociatedObject : NSObject {
@public
id native_object;
uint32_t gc_handle;
GCHandle gc_handle;
enum XamarinGCHandleFlags flags;
}
-(void) dealloc;
@end
@interface NSObject (NonXamarinObject)
-(uint32_t) xamarinGetGCHandle;
-(GCHandle) xamarinGetGCHandle;
-(enum XamarinGCHandleFlags) xamarinGetFlags;
@end
#endif

Просмотреть файл

@ -13,6 +13,12 @@
extern "C" {
#endif
enum XamarinGCHandleFlags : uint32_t {
XamarinGCHandleFlags_None = 0,
XamarinGCHandleFlags_WeakGCHandle = 1,
XamarinGCHandleFlags_HasManagedRef = 2,
};
void * xamarin_trampoline (id self, SEL sel, ...);
void xamarin_stret_trampoline (void *buffer, id self, SEL sel, ...);
float xamarin_fpret_single_trampoline (id self, SEL sel, ...);
@ -32,12 +38,14 @@ long long xamarin_longret_trampoline (id self, SEL sel, ...);
long long xamarin_static_longret_trampoline (id self, SEL sel, ...);
id xamarin_copyWithZone_trampoline1 (id self, SEL sel, NSZone *zone);
id xamarin_copyWithZone_trampoline2 (id self, SEL sel, NSZone *zone);
uint32_t xamarin_get_gchandle_trampoline (id self, SEL sel);
void xamarin_set_gchandle_trampoline (id self, SEL sel, uint32_t gc_handle);
GCHandle xamarin_get_gchandle_trampoline (id self, SEL sel);
void xamarin_set_gchandle_trampoline (id self, SEL sel, GCHandle gc_handle, enum XamarinGCHandleFlags flags);
enum XamarinGCHandleFlags xamarin_get_flags_trampoline (id self, SEL sel);
void xamarin_set_flags_trampoline (id self, SEL sel, enum XamarinGCHandleFlags flags);
int xamarin_get_frame_length (id self, SEL sel);
bool xamarin_collapse_struct_name (const char *type, char struct_name[], int max_char, guint32 *exception_gchandle);
guint32 xamarin_create_mt_exception (char *msg);
bool xamarin_collapse_struct_name (const char *type, char struct_name[], int max_char, GCHandle *exception_gchandle);
GCHandle xamarin_create_mt_exception (char *msg);
size_t xamarin_get_primitive_size (char type);
enum ArgumentSemantic /* Xcode 4.4 doesn't like this ': int' */ {
@ -83,109 +91,109 @@ enum ArgumentSemantic /* Xcode 4.4 doesn't like this ': int' */ {
// exception occurs, 'ptr' is returned (and no memory allocated).
// * xamarin_managed_to_id_func: the resulting Objective-C object.
typedef void * (*xamarin_id_to_managed_func) (id value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
typedef id (*xamarin_managed_to_id_func) (MonoObject *value, void *context, guint32 *exception_gchandle);
typedef void * (*xamarin_id_to_managed_func) (id value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
typedef id (*xamarin_managed_to_id_func) (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_generate_conversion_to_native (MonoObject *value, MonoType *inputType, MonoType *outputType, MonoMethod *method, void *context, guint32 *exception_gchandle);
void * xamarin_generate_conversion_to_managed (id value, MonoType *inputType, MonoType *outputType, MonoMethod *method, guint32 *exception_gchandle, void *context, /*SList*/ void **free_list);
NSNumber * xamarin_convert_managed_to_nsnumber (MonoObject *value, MonoClass *managedType, MonoMethod *method, void *context, guint32 *exception_gchandle);
NSValue * xamarin_convert_managed_to_nsvalue (MonoObject *value, MonoClass *managedType, MonoMethod *method, void *context, guint32 *exception_gchandle);
NSString * xamarin_convert_managed_to_nsstring (MonoObject *value, MonoType *managedType, MonoType *nativeType, MonoMethod *method, guint32 *exception_gchandle);
MonoObject * xamarin_convert_nsnumber_to_managed (NSNumber *value, MonoType *nativeType, MonoType *managedType, MonoMethod *method, guint32 *exception_gchandle);
MonoObject * xamarin_convert_nsvalue_to_managed (NSValue *value, MonoType *nativeType, MonoType *managedType, MonoMethod *method, guint32 *exception_gchandle);
MonoObject * xamarin_convert_nsstring_to_managed (NSString *value, MonoType *nativeType, MonoType *managedType, MonoMethod *method, guint32 *exception_gchandle);
guint32 xamarin_create_bindas_exception (MonoType *inputType, MonoType *outputType, MonoMethod *method);
guint32 xamarin_get_exception_for_parameter (int code, guint32 inner_exception_gchandle, const char *reason, SEL sel, MonoMethod *method, MonoType *p, int i, bool to_managed);
id xamarin_generate_conversion_to_native (MonoObject *value, MonoType *inputType, MonoType *outputType, MonoMethod *method, void *context, GCHandle *exception_gchandle);
void * xamarin_generate_conversion_to_managed (id value, MonoType *inputType, MonoType *outputType, MonoMethod *method, GCHandle *exception_gchandle, void *context, /*SList*/ void **free_list);
NSNumber * xamarin_convert_managed_to_nsnumber (MonoObject *value, MonoClass *managedType, MonoMethod *method, void *context, GCHandle *exception_gchandle);
NSValue * xamarin_convert_managed_to_nsvalue (MonoObject *value, MonoClass *managedType, MonoMethod *method, void *context, GCHandle *exception_gchandle);
NSString * xamarin_convert_managed_to_nsstring (MonoObject *value, MonoType *managedType, MonoType *nativeType, MonoMethod *method, GCHandle *exception_gchandle);
MonoObject * xamarin_convert_nsnumber_to_managed (NSNumber *value, MonoType *nativeType, MonoType *managedType, MonoMethod *method, GCHandle *exception_gchandle);
MonoObject * xamarin_convert_nsvalue_to_managed (NSValue *value, MonoType *nativeType, MonoType *managedType, MonoMethod *method, GCHandle *exception_gchandle);
MonoObject * xamarin_convert_nsstring_to_managed (NSString *value, MonoType *nativeType, MonoType *managedType, MonoMethod *method, GCHandle *exception_gchandle);
GCHandle xamarin_create_bindas_exception (MonoType *inputType, MonoType *outputType, MonoMethod *method);
GCHandle xamarin_get_exception_for_parameter (int code, GCHandle inner_exception_gchandle, const char *reason, SEL sel, MonoMethod *method, MonoType *p, int i, bool to_managed);
xamarin_id_to_managed_func xamarin_get_nsnumber_to_managed_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle);
xamarin_managed_to_id_func xamarin_get_managed_to_nsnumber_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle);
xamarin_id_to_managed_func xamarin_get_nsnumber_to_managed_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle);
xamarin_managed_to_id_func xamarin_get_managed_to_nsnumber_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle);
xamarin_id_to_managed_func xamarin_get_nsvalue_to_managed_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle);
xamarin_managed_to_id_func xamarin_get_managed_to_nsvalue_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle);
xamarin_id_to_managed_func xamarin_get_nsvalue_to_managed_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle);
xamarin_managed_to_id_func xamarin_get_managed_to_nsvalue_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle);
xamarin_id_to_managed_func xamarin_get_nsstring_to_smart_enum_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle);
xamarin_managed_to_id_func xamarin_get_smart_enum_to_nsstring_func (MonoClass *managedType, MonoMethod *method, guint32 *exception_gchandle);
xamarin_id_to_managed_func xamarin_get_nsstring_to_smart_enum_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle);
xamarin_managed_to_id_func xamarin_get_smart_enum_to_nsstring_func (MonoClass *managedType, MonoMethod *method, GCHandle *exception_gchandle);
NSArray * xamarin_convert_managed_to_nsarray_with_func (MonoArray *array, xamarin_managed_to_id_func convert, void *context, guint32 *exception_gchandle);
MonoArray * xamarin_convert_nsarray_to_managed_with_func (NSArray *array, MonoClass *managedElementType, xamarin_id_to_managed_func convert, void *context, guint32 *exception_gchandle);
NSArray * xamarin_convert_managed_to_nsarray_with_func (MonoArray *array, xamarin_managed_to_id_func convert, void *context, GCHandle *exception_gchandle);
MonoArray * xamarin_convert_nsarray_to_managed_with_func (NSArray *array, MonoClass *managedElementType, xamarin_id_to_managed_func convert, void *context, GCHandle *exception_gchandle);
void * xamarin_nsstring_to_smart_enum (id value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void * xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */, guint32 *exception_gchandle);
void * xamarin_nsstring_to_smart_enum (id value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void * xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */, GCHandle *exception_gchandle);
// Returns a pointer to the value type, which must be freed using xamarin_free.
void *xamarin_nsnumber_to_bool (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_sbyte (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_byte (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_short (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_ushort (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_int (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_uint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_long (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_ulong (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_nint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_nuint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_float (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_double (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_nfloat (NSNumber *number, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void *xamarin_nsnumber_to_bool (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_sbyte (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_byte (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_short (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_ushort (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_int (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_uint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_long (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_ulong (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_nint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_nuint (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_float (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_double (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsnumber_to_nfloat (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
// Returns a pointer to the value type, which must be freed using xamarin_free
void *xamarin_nsvalue_to_nsrange (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cgaffinetransform (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cgpoint (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cgrect (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cgsize (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cgvector (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_catransform3d (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cllocationcoordinate2d (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cmtime (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cmtimemapping (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_cmtimerange (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_mkcoordinatespan (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_scnmatrix4 (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_scnvector3 (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_scnvector4 (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_uiedgeinsets (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_uioffset (NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_nsdirectionaledgeinsets(NSValue *value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_ghandle);
void *xamarin_nsvalue_to_nsrange (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cgaffinetransform (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cgpoint (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cgrect (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cgsize (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cgvector (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_catransform3d (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cllocationcoordinate2d (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cmtime (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cmtimemapping (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_cmtimerange (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_mkcoordinatespan (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_scnmatrix4 (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_scnvector3 (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_scnvector4 (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_uiedgeinsets (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_uioffset (NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void *xamarin_nsvalue_to_nsdirectionaledgeinsets(NSValue *value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
id xamarin_bool_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_sbyte_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_byte_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_short_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_ushort_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_int_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_uint_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_long_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_ulong_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_nint_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_nuint_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_float_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_double_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_nfloat_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_nfloat_to_nsnumber (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_bool_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_sbyte_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_byte_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_short_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_ushort_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_int_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_uint_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_long_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_ulong_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_nint_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_nuint_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_float_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_double_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_nfloat_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_nfloat_to_nsnumber (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_nsrange_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cgaffinetransform_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cgpoint_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cgrect_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cgsize_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cgvector_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_catransform3d_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cllocationcoordinate2d_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cmtime_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cmtimemapping_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_cmtimerange_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_mkcoordinatespan_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_scnmatrix4_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_scnvector3_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_scnvector4_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_uiedgeinsets_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_uioffset_to_nsvalue (MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_nsdirectionaledgeinsets_to_nsvalue(MonoObject *value, void *context, guint32 *exception_gchandle);
id xamarin_nsrange_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cgaffinetransform_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cgpoint_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cgrect_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cgsize_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cgvector_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_catransform3d_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cllocationcoordinate2d_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cmtime_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cmtimemapping_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_cmtimerange_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_mkcoordinatespan_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_scnmatrix4_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_scnvector3_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_scnvector4_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_uiedgeinsets_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_uioffset_to_nsvalue (MonoObject *value, void *context, GCHandle *exception_gchandle);
id xamarin_nsdirectionaledgeinsets_to_nsvalue(MonoObject *value, void *context, GCHandle *exception_gchandle);
// These functions can be passed as xamarin_id_to_managed_func/xamarin_managed_to_id_func parameters
id xamarin_convert_string_to_nsstring (MonoObject *obj, void *context, guint32 *exception_gchandle);
void * xamarin_convert_nsstring_to_string (id value, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
id xamarin_convert_string_to_nsstring (MonoObject *obj, void *context, GCHandle *exception_gchandle);
void * xamarin_convert_nsstring_to_string (id value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
// These are simpler versions of the above string<->nsstring conversion functions.
NSString * xamarin_string_to_nsstring (MonoString *obj, bool retain);
@ -193,26 +201,26 @@ NSString * xamarin_string_to_nsstring (MonoString *obj, bool retain);
MonoString * xamarin_nsstring_to_string (MonoDomain *domain, NSString *obj);
// Either managed_type or managed_class has to be provided
NSArray * xamarin_managed_array_to_nsarray (MonoArray *array, MonoType *managed_type, MonoClass *managed_class, guint32 *exception_gchandle);
NSArray * xamarin_managed_array_to_nsarray (MonoArray *array, MonoType *managed_type, MonoClass *managed_class, GCHandle *exception_gchandle);
// Either managed_type or managed_class has to be provided
MonoArray * xamarin_nsarray_to_managed_array (NSArray *array, MonoType *managed_type, MonoClass *managed_class, guint32 *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_array (NSArray *array, MonoType *managed_type, MonoClass *managed_class, GCHandle *exception_gchandle);
NSArray * xamarin_managed_string_array_to_nsarray (MonoArray *array, guint32 *exception_gchandle);
NSArray * xamarin_managed_nsobject_array_to_nsarray (MonoArray *array, guint32 *exception_gchandle);
NSArray * xamarin_managed_inativeobject_array_to_nsarray (MonoArray *array, guint32 *exception_gchandle);
NSArray * xamarin_managed_string_array_to_nsarray (MonoArray *array, GCHandle *exception_gchandle);
NSArray * xamarin_managed_nsobject_array_to_nsarray (MonoArray *array, GCHandle *exception_gchandle);
NSArray * xamarin_managed_inativeobject_array_to_nsarray (MonoArray *array, GCHandle *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_string_array (NSArray *array, guint32 *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_nsobject_array (NSArray *array, MonoType *array_type, MonoClass *element_class, guint32 *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_inativeobject_array (NSArray *array, MonoType *array_type, MonoClass *element_class, guint32 *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_inativeobject_array_static (NSArray *array, MonoType *array_type, MonoClass *element_class, uint32_t iface_token_ref, uint32_t implementation_token_ref, guint32 *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_string_array (NSArray *array, GCHandle *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_nsobject_array (NSArray *array, MonoType *array_type, MonoClass *element_class, GCHandle *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_inativeobject_array (NSArray *array, MonoType *array_type, MonoClass *element_class, GCHandle *exception_gchandle);
MonoArray * xamarin_nsarray_to_managed_inativeobject_array_static (NSArray *array, MonoType *array_type, MonoClass *element_class, uint32_t iface_token_ref, uint32_t implementation_token_ref, GCHandle *exception_gchandle);
void * xamarin_nsobject_to_object (id object, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
id xamarin_object_to_nsobject (MonoObject *object, void *context, guint32 *exception_gchandle);
void * xamarin_nsobject_to_object (id object, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
id xamarin_object_to_nsobject (MonoObject *object, void *context, GCHandle *exception_gchandle);
id xamarin_inativeobject_to_nsobject (MonoObject *object, void *context, guint32 *exception_gchandle);
id xamarin_inativeobject_to_nsobject (MonoObject *object, void *context, GCHandle *exception_gchandle);
void * xamarin_nsobject_to_inativeobject (id object, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void * xamarin_nsobject_to_inativeobject_static (id object, void *ptr, MonoClass *managedType, void *context, guint32 *exception_gchandle);
void * xamarin_nsobject_to_inativeobject (id object, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
void * xamarin_nsobject_to_inativeobject_static (id object, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
/* Copied from SGen */

Просмотреть файл

@ -1006,6 +1006,12 @@ namespace Registrar {
case Trampoline.SetGCHandle:
tramp = Method.SetGCHandleTrampoline;
break;
case Trampoline.GetFlags:
tramp = Method.GetFlagsTrampoline;
break;
case Trampoline.SetFlags:
tramp = Method.SetFlagsTrampoline;
break;
default:
throw ErrorHelper.CreateError (4144, "Cannot register the method '{0}.{1}' since it does not have an associated trampoline. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new", method.DeclaringType.Type.FullName, method.Name);
}

Просмотреть файл

@ -112,6 +112,14 @@ namespace ObjCRuntime {
internal unsafe static IntPtr SetGCHandleTrampoline {
get { return Runtime.options->Trampolines->set_gchandle_tramp; }
}
internal unsafe static IntPtr GetFlagsTrampoline {
get { return Runtime.options->Trampolines->get_flags_tramp; }
}
internal unsafe static IntPtr SetFlagsTrampoline {
get { return Runtime.options->Trampolines->set_flags_tramp; }
}
#endif // !COREBUILD
}
}

Просмотреть файл

@ -567,6 +567,8 @@ namespace Registrar {
case Trampoline.Retain:
case Trampoline.GetGCHandle:
case Trampoline.SetGCHandle:
case Trampoline.GetFlags:
case Trampoline.SetFlags:
return true;
default:
return false;
@ -2048,8 +2050,22 @@ namespace Registrar {
}, ref exceptions);
objcType.Add (new ObjCMethod (this, objcType, null) {
Selector = "xamarinSetGCHandle:",
Selector = "xamarinSetGCHandle:flags:",
Trampoline = Trampoline.SetGCHandle,
Signature = "v@:^vi",
IsStatic = false,
}, ref exceptions);
objcType.Add (new ObjCMethod (this, objcType, null) {
Selector = "xamarinGetFlags",
Trampoline = Trampoline.GetFlags,
Signature = "i@:",
IsStatic = false,
}, ref exceptions);
objcType.Add (new ObjCMethod (this, objcType, null) {
Selector = "xamarinSetFlags:",
Trampoline = Trampoline.SetFlags,
Signature = "v@:i",
IsStatic = false,
}, ref exceptions);
@ -2775,6 +2791,8 @@ namespace Registrar {
CopyWithZone2,
GetGCHandle,
SetGCHandle,
GetFlags,
SetFlags,
}
}

Просмотреть файл

@ -116,6 +116,8 @@ namespace ObjCRuntime {
#endif
public IntPtr get_gchandle_tramp;
public IntPtr set_gchandle_tramp;
public IntPtr get_flags_tramp;
public IntPtr set_flags_tramp;
}
[Flags]
@ -332,10 +334,10 @@ namespace ObjCRuntime {
return objc_exception_mode;
}
static MarshalManagedExceptionMode OnMarshalManagedException (int exception_handle)
static MarshalManagedExceptionMode OnMarshalManagedException (IntPtr exception_handle)
{
if (MarshalManagedException != null) {
var exception = GCHandle.FromIntPtr (new IntPtr (exception_handle)).Target as Exception;
var exception = GCHandle.FromIntPtr (exception_handle).Target as Exception;
var args = new MarshalManagedExceptionEventArgs ()
{
Exception = exception,
@ -408,13 +410,13 @@ namespace ObjCRuntime {
#endif
}
static void RethrowManagedException (uint exception_gchandle)
static void RethrowManagedException (IntPtr exception_gchandle)
{
var e = (Exception) GCHandle.FromIntPtr ((IntPtr) exception_gchandle).Target;
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture (e).Throw ();
}
static int CreateNSException (IntPtr ns_exception)
static IntPtr CreateNSException (IntPtr ns_exception)
{
Exception ex;
#if MONOMAC
@ -422,18 +424,18 @@ namespace ObjCRuntime {
#else
ex = new MonoTouchException (Runtime.GetNSObject<NSException> (ns_exception));
#endif
return GCHandle.ToIntPtr (GCHandle.Alloc (ex)).ToInt32 ();
return GCHandle.ToIntPtr (GCHandle.Alloc (ex));
}
static int CreateRuntimeException (int code, IntPtr message)
static IntPtr CreateRuntimeException (int code, IntPtr message)
{
var ex = ErrorHelper.CreateError (code, Marshal.PtrToStringAuto (message));
return GCHandle.ToIntPtr (GCHandle.Alloc (ex)).ToInt32 ();
return GCHandle.ToIntPtr (GCHandle.Alloc (ex));
}
static IntPtr UnwrapNSException (uint exc_handle)
static IntPtr UnwrapNSException (IntPtr exc_handle)
{
var obj = GCHandle.FromIntPtr (new IntPtr (exc_handle)).Target;
var obj = GCHandle.FromIntPtr (exc_handle).Target;
#if MONOMAC
var exc = obj as ObjCException;
#else
@ -739,11 +741,11 @@ namespace ObjCRuntime {
}
// If inner_exception_gchandle is provided, it will be freed.
static int CreateProductException (int code, uint inner_exception_gchandle, string msg)
static IntPtr CreateProductException (int code, IntPtr inner_exception_gchandle, string msg)
{
Exception inner_exception = null;
if (inner_exception_gchandle != 0) {
GCHandle gchandle = GCHandle.FromIntPtr (new IntPtr (inner_exception_gchandle));
if (inner_exception_gchandle != IntPtr.Zero) {
GCHandle gchandle = GCHandle.FromIntPtr (inner_exception_gchandle);
inner_exception = (Exception) gchandle.Target;
gchandle.Free ();
}
@ -753,7 +755,7 @@ namespace ObjCRuntime {
} else {
ex = ErrorHelper.CreateError (code, msg);
}
return GCHandle.ToIntPtr (GCHandle.Alloc (ex, GCHandleType.Normal)).ToInt32 ();
return GCHandle.ToIntPtr (GCHandle.Alloc (ex, GCHandleType.Normal));
}
static IntPtr TypeGetFullName (IntPtr type)

Просмотреть файл

@ -2506,9 +2506,13 @@ namespace Registrar {
else if (method.CurrentTrampoline == Trampoline.Release)
return "-(void) release";
else if (method.CurrentTrampoline == Trampoline.GetGCHandle)
return "-(uint32_t) xamarinGetGCHandle";
return "-(GCHandle) xamarinGetGCHandle";
else if (method.CurrentTrampoline == Trampoline.GetFlags)
return "-(enum XamarinGCHandleFlags) xamarinGetFlags";
else if (method.CurrentTrampoline == Trampoline.SetFlags)
return "-(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags";
else if (method.CurrentTrampoline == Trampoline.SetGCHandle)
return "-(void) xamarinSetGCHandle: (uint32_t) gchandle";
return "-(void) xamarinSetGCHandle: (GCHandle) gchandle flags: (enum XamarinGCHandleFlags) flags";
else if (method.CurrentTrampoline == Trampoline.CopyWithZone1 || method.CurrentTrampoline == Trampoline.CopyWithZone2)
return "-(id) copyWithZone: (NSZone *)zone";
@ -3131,20 +3135,35 @@ namespace Registrar {
sb.WriteLine ();
return;
case Trampoline.GetGCHandle:
sb.WriteLine ("-(uint32_t) xamarinGetGCHandle");
sb.WriteLine ("-(GCHandle) xamarinGetGCHandle");
sb.WriteLine ("{");
sb.WriteLine ("return __monoObjectGCHandle.gc_handle;");
sb.WriteLine ("}");
sb.WriteLine ();
return;
case Trampoline.SetGCHandle:
sb.WriteLine ("-(void) xamarinSetGCHandle: (uint32_t) gc_handle");
sb.WriteLine ("-(void) xamarinSetGCHandle: (GCHandle) gc_handle flags: (enum XamarinGCHandleFlags) flags");
sb.WriteLine ("{");
sb.WriteLine ("__monoObjectGCHandle.gc_handle = gc_handle;");
sb.WriteLine ("__monoObjectGCHandle.flags = flags;");
sb.WriteLine ("__monoObjectGCHandle.native_object = self;");
sb.WriteLine ("}");
sb.WriteLine ();
return;
case Trampoline.GetFlags:
sb.WriteLine ("-(enum XamarinGCHandleFlags) xamarinGetFlags");
sb.WriteLine ("{");
sb.WriteLine ("return __monoObjectGCHandle.flags;");
sb.WriteLine ("}");
sb.WriteLine ();
return;
case Trampoline.SetFlags:
sb.WriteLine ("-(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags");
sb.WriteLine ("{");
sb.WriteLine ("__monoObjectGCHandle.flags = flags;");
sb.WriteLine ("}");
sb.WriteLine ();
return;
case Trampoline.Constructor:
if (isGeneric) {
sb.WriteLine (GetObjCSignature (method, exceptions));
@ -3159,16 +3178,17 @@ namespace Registrar {
sb.AppendLine ("-(id) copyWithZone: (NSZone *) zone");
sb.AppendLine ("{");
sb.AppendLine ("id rv;");
sb.AppendLine ("int gchandle;");
sb.AppendLine ("GCHandle gchandle;");
sb.AppendLine ("enum XamarinGCHandleFlags flags = XamarinGCHandleFlags_None;");
sb.AppendLine ();
sb.AppendLine ("gchandle = xamarin_get_gchandle_with_flags (self);");
sb.AppendLine ("if (gchandle != 0)");
sb.Indent ().AppendLine ("xamarin_set_gchandle (self, 0);").Unindent ();
sb.AppendLine ("gchandle = xamarin_get_gchandle_with_flags (self, &flags);");
sb.AppendLine ("if (gchandle != INVALID_GCHANDLE)");
sb.Indent ().AppendLine ("xamarin_set_gchandle_with_flags (self, INVALID_GCHANDLE, XamarinGCHandleFlags_None);").Unindent ();
// Call the base class implementation
sb.AppendLine ("rv = [super copyWithZone: zone];");
sb.AppendLine ();
sb.AppendLine ("if (gchandle != 0)");
sb.Indent ().AppendLine ("xamarin_set_gchandle (self, gchandle);").Unindent ();
sb.AppendLine ("if (gchandle != INVALID_GCHANDLE)");
sb.Indent ().AppendLine ("xamarin_set_gchandle_with_flags (self, gchandle, flags);").Unindent ();
sb.AppendLine ();
sb.AppendLine ("return rv;");
sb.AppendLine ("}");
@ -3445,14 +3465,14 @@ namespace Registrar {
body_setup.AppendLine ("MonoObject *a{0} = NULL;", i);
if (!isOut) {
setup_call_stack.AppendLine ("a{0} = *p{0} ? xamarin_get_selector (*p{0}, &exception_gchandle) : NULL;", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
}
setup_call_stack.AppendLine ("arg_ptrs [{0}] = &a{0};", i);
copyback.AppendLine ("*p{0} = a{0} ? (SEL) xamarin_get_handle_for_inativeobject (a{0}, &exception_gchandle) : NULL;", i);
copyback.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
copyback.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else {
setup_call_stack.AppendLine ("arg_ptrs [{0}] = p{0} ? xamarin_get_selector (p{0}, &exception_gchandle) : NULL;", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
}
break;
case "ObjCRuntime.Class":
@ -3460,14 +3480,14 @@ namespace Registrar {
body_setup.AppendLine ("MonoObject *a{0} = NULL;", i);
if (!isOut) {
setup_call_stack.AppendLine ("a{0} = *p{0} ? xamarin_get_class (*p{0}, &exception_gchandle) : NULL;", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
}
setup_call_stack.AppendLine ("arg_ptrs [{0}] = &a{0};", i);
copyback.AppendLine ("*p{0} = a{0} ? (Class) xamarin_get_handle_for_inativeobject (a{0}, &exception_gchandle) : NULL;", i);
copyback.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
copyback.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else {
setup_call_stack.AppendLine ("arg_ptrs [{0}] = p{0} ? xamarin_get_class (p{0}, &exception_gchandle) : NULL;", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
}
break;
case "System.String":
@ -3508,10 +3528,10 @@ namespace Registrar {
if (isString) {
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_string_array (arr{0}, &exception_gchandle);", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else if (isNSObject) {
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_nsobject_array (arr{0}, xamarin_get_parameter_type (managed_method, {0}), NULL, &exception_gchandle);", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else if (isINativeObject) {
TypeDefinition nativeObjType = elementType.Resolve ();
var isNativeObjectInterface = nativeObjType.IsInterface;
@ -3536,7 +3556,7 @@ namespace Registrar {
} else {
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_inativeobject_array (arr{0}, xamarin_get_parameter_type (managed_method, {0}), NULL, &exception_gchandle);", i);
}
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else {
throw ErrorHelper.CreateError (App, 4111, method.Method, Errors.MT4111, type.FullName, descriptiveMethodName);
}
@ -3572,7 +3592,7 @@ namespace Registrar {
body_setup.AppendLine ("MonoType *paramtype{0} = NULL;", i);
setup_call_stack.AppendLine ("paramtype{0} = xamarin_get_parameter_type (managed_method, {0});", i);
setup_call_stack.AppendLine ("mobj{0} = xamarin_get_nsobject_with_type_for_ptr (nsobj{0}, false, paramtype{0}, &exception_gchandle);", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) {");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) {");
setup_call_stack.AppendLine ("exception_gchandle = xamarin_get_exception_for_parameter (8029, exception_gchandle, \"Unable to marshal the byref parameter\", _cmd, managed_method, paramtype{0}, {0}, true);", i);
setup_call_stack.AppendLine ("goto exception_handling;");
setup_call_stack.AppendLine ("}");
@ -3602,7 +3622,7 @@ namespace Registrar {
body_setup.AppendLine ("MonoType *paramtype{0} = NULL;", i);
setup_call_stack.AppendLine ("paramtype{0} = xamarin_get_parameter_type (managed_method, {0});", i);
setup_call_stack.AppendLine ("mobj{0} = xamarin_get_nsobject_with_type_for_ptr_created (nsobj{0}, false, paramtype{0}, &created{0}, &exception_gchandle);", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) {");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) {");
setup_call_stack.AppendLine ("exception_gchandle = xamarin_get_exception_for_parameter (8029, exception_gchandle, \"Unable to marshal the parameter\", _cmd, managed_method, paramtype{0}, {0}, true);", i);
setup_call_stack.AppendLine ("goto exception_handling;");
setup_call_stack.AppendLine ("}");
@ -3615,7 +3635,7 @@ namespace Registrar {
if (HasAttribute (paramBase, ObjCRuntime, StringConstants.TransientAttribute)) {
copyback.AppendLine ("if (created{0}) {{", i);
copyback.AppendLine ("xamarin_dispose (mobj{0}, &exception_gchandle);", i);
copyback.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
copyback.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
copyback.AppendLine ("}");
}
}
@ -3645,16 +3665,16 @@ namespace Registrar {
setup_call_stack.AppendLine ("inobj{0} = NULL;", i);
} else if (td.IsInterface) {
setup_call_stack.AppendLine ("inobj{0} = xamarin_get_inative_object_static (*p{0}, false, 0x{1:X} /* {2} */, 0x{3:X} /* {4} */, &exception_gchandle);", i, CreateTokenReference (td, TokenType.TypeDef), td.FullName, CreateTokenReference (nativeObjType, TokenType.TypeDef), nativeObjType.FullName);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else {
setup_call_stack.AppendLine ("inobj{0} = xamarin_get_inative_object_dynamic (*p{0}, false, mono_type_get_object (mono_domain_get (), type{0}), &exception_gchandle);", i);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
}
setup_call_stack.AppendLine ("arg_ptrs [{0}] = &inobj{0};", i);
body_setup.AppendLine ("id handle{0} = nil;", i);
copyback.AppendLine ("if (inobj{0} != NULL)", i);
copyback.AppendLine ("handle{0} = xamarin_get_handle_for_inativeobject (inobj{0}, &exception_gchandle);", i);
copyback.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
copyback.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
copyback.AppendLine ("*p{0} = (id) handle{0};", i);
} else {
if (td.IsInterface) {
@ -3662,7 +3682,7 @@ namespace Registrar {
} else {
setup_call_stack.AppendLine ("arg_ptrs [{0}] = xamarin_get_inative_object_dynamic (p{0}, false, mono_type_get_object (mono_domain_get (), type{0}), &exception_gchandle);", i);
}
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
}
} else if (type.IsValueType) {
if (isRef || isOut) {
@ -3689,7 +3709,7 @@ namespace Registrar {
}
setup_call_stack.AppendLine ("if (p{0}) {{", i);
setup_call_stack.AppendLine ("arg_ptrs [{0}] = (void *) xamarin_get_delegate_for_block_parameter (managed_method, {1}, {0}, p{0}, &exception_gchandle);", i, token);
setup_call_stack.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
setup_call_stack.AppendLine ("} else {");
setup_call_stack.AppendLine ("arg_ptrs [{0}] = NULL;", i);
setup_call_stack.AppendLine ("}");
@ -3730,7 +3750,7 @@ namespace Registrar {
if (isCtor)
invoke.AppendLine ("xamarin_create_managed_ref (self, mthis, true);");
body_setup.AppendLine ("guint32 exception_gchandle = 0;");
body_setup.AppendLine ("GCHandle exception_gchandle = INVALID_GCHANDLE;");
// prepare the return value
if (!isVoid) {
switch (rettype) {
@ -3764,7 +3784,7 @@ namespace Registrar {
setup_return.AppendLine ("res = {0} ((MonoArray *) retval, &exception_gchandle);", conversion_func);
if (retain)
setup_return.AppendLine ("[res retain];");
setup_return.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_return.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
setup_return.AppendLine ("xamarin_framework_peer_lock ();");
setup_return.AppendLine ("mt_dummy_use (retval);");
setup_return.AppendLine ("xamarin_framework_peer_unlock ();");
@ -3785,14 +3805,14 @@ namespace Registrar {
setup_return.AppendLine ("res = retobj;");
} else if (IsPlatformType (type, "ObjCRuntime", "Selector")) {
setup_return.AppendLine ("res = (SEL) xamarin_get_handle_for_inativeobject (retval, &exception_gchandle);");
setup_return.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_return.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else if (IsPlatformType (type, "ObjCRuntime", "Class")) {
setup_return.AppendLine ("res = (Class) xamarin_get_handle_for_inativeobject (retval, &exception_gchandle);");
setup_return.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_return.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else if (IsNativeObject (type)) {
setup_return.AppendLine ("{0} retobj;", rettype);
setup_return.AppendLine ("retobj = xamarin_get_handle_for_inativeobject ((MonoObject *) retval, &exception_gchandle);");
setup_return.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_return.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
setup_return.AppendLine ("xamarin_framework_peer_lock ();");
setup_return.AppendLine ("[retobj retain];");
setup_return.AppendLine ("xamarin_framework_peer_unlock ();");
@ -3825,7 +3845,7 @@ namespace Registrar {
}
}
setup_return.AppendLine ("res = xamarin_get_block_for_delegate (managed_method, retval, {0}, {1}, &exception_gchandle);", signature, token);
setup_return.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
setup_return.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else {
throw ErrorHelper.CreateError (4104, Errors.MT4104, returntype.FullName, descriptiveMethodName);
}
@ -3860,7 +3880,7 @@ namespace Registrar {
if (isCtor) {
body.WriteLine ("bool has_nsobject = xamarin_has_nsobject (self, &exception_gchandle);");
body.WriteLine ("if (exception_gchandle != 0) goto exception_handling;");
body.WriteLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
body.WriteLine ("if (has_nsobject) {");
body.WriteLine ("*call_super = true;");
body.WriteLine ("goto exception_handling;");
@ -3870,7 +3890,7 @@ namespace Registrar {
if ((!isStatic || isInstanceCategory) && !isCtor) {
body.WriteLine ("if (self) {");
body.WriteLine ("mthis = xamarin_get_managed_object_for_ptr_fast (self, &exception_gchandle);");
body.WriteLine ("if (exception_gchandle != 0) goto exception_handling;");
body.WriteLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
body.WriteLine ("}");
}
@ -3889,7 +3909,7 @@ namespace Registrar {
}
body.Write ("MonoReflectionMethod *reflection_method = (MonoReflectionMethod *) xamarin_gchandle_unwrap (reflection_method_handle);");
body.WriteLine ("if (exception_gchandle != 0) goto exception_handling;");
body.WriteLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
body.WriteLine ("managed_method = xamarin_get_reflection_method_method (reflection_method);");
if (merge_bodies)
body.WriteLine ("*managed_method_ptr = managed_method;");
@ -3898,7 +3918,7 @@ namespace Registrar {
if (!isStatic && !isInstanceCategory && !isCtor) {
body.WriteLine ("xamarin_check_for_gced_object (mthis, _cmd, self, managed_method, &exception_gchandle);");
body.WriteLine ("if (exception_gchandle != 0) goto exception_handling;");
body.WriteLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
}
if (trace)
@ -3916,7 +3936,7 @@ namespace Registrar {
body.WriteLine ("MONO_THREAD_DETACH;"); // COOP: this will switch to GC_SAFE
body.AppendLine ("if (exception_gchandle != 0)");
body.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE)");
body.Indent ().WriteLine ("xamarin_process_managed_exception_gchandle (exception_gchandle);").Unindent ();
if (App.MarshalManagedExceptions != MarshalManagedExceptionMode.Disable)
@ -4390,7 +4410,7 @@ namespace Registrar {
} else if (isManagedNullable) {
underlyingManagedType = GetNullableType (managedType);
sb.AppendLine ($"{classVariableName} = xamarin_get_nullable_type ({managedClassExpression}, &exception_gchandle);");
sb.AppendLine ($"if (exception_gchandle != 0) goto exception_handling;");
sb.AppendLine ($"if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else {
sb.AppendLine ($"{classVariableName} = {managedClassExpression};");
}
@ -4423,9 +4443,9 @@ namespace Registrar {
}
if (isManagedArray) {
sb.AppendLine ($"xamarin_id_to_managed_func {inputName}_conv_func = (xamarin_id_to_managed_func) {func};");
sb.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
sb.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
sb.AppendLine ($"{outputName} = xamarin_convert_nsarray_to_managed_with_func ({inputName}, {classVariableName}, {inputName}_conv_func, GINT_TO_POINTER ({token}), &exception_gchandle);");
sb.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
sb.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else {
var tmpName = $"{inputName}_conv_tmp";
body_setup.AppendLine ($"{nativeTypeName} {tmpName};");
@ -4433,11 +4453,11 @@ namespace Registrar {
var tmpName2 = $"{inputName}_conv_ptr";
body_setup.AppendLine ($"void *{tmpName2} = NULL;");
sb.AppendLine ($"{tmpName2} = {func} ({inputName}, &{tmpName}, {classVariableName}, GINT_TO_POINTER ({token}), &exception_gchandle);");
sb.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
sb.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
sb.AppendLine ($"{outputName} = mono_value_box (mono_domain_get (), {classVariableName}, {tmpName2});");
} else {
sb.AppendLine ($"{outputName} = {func} ({inputName}, &{tmpName}, {classVariableName}, GINT_TO_POINTER ({token}), &exception_gchandle);");
sb.AppendLine ("if (exception_gchandle != 0) goto exception_handling;");
sb.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
}
}
@ -4477,7 +4497,7 @@ namespace Registrar {
} else if (isManagedNullable) {
underlyingManagedType = GetNullableType (managedType);
sb.AppendLine ($"{classVariableName} = xamarin_get_nullable_type ({managedClassExpression}, &exception_gchandle);");
sb.AppendLine ($"if (exception_gchandle != 0) goto exception_handling;");
sb.AppendLine ($"if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
} else {
sb.AppendLine ($"{classVariableName} = {managedClassExpression};");
}
@ -4513,7 +4533,7 @@ namespace Registrar {
} else {
sb.AppendLine ($"{outputName} = {func} ({inputName}, GINT_TO_POINTER ({token}), &exception_gchandle);");
}
sb.AppendLine ($"if (exception_gchandle != 0) goto exception_handling;");
sb.AppendLine ($"if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
if (isManagedNullable || isManagedArray) {
sb.AppendLine ($"}} else {{");

Просмотреть файл

@ -648,7 +648,7 @@ namespace Xamarin.Bundler {
var assembly_location_count = 0;
var enable_llvm = (abi & Abi.LLVM) != 0;
register_assemblies.AppendLine ("\tguint32 exception_gchandle = 0;");
register_assemblies.AppendLine ("\tGCHandle exception_gchandle = INVALID_GCHANDLE;");
foreach (var s in assemblies) {
if (!s.IsAOTCompiled)
continue;