From ac5ff5e32134f5e56e49389ae0a2e82ce2e07b9d Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 17 Feb 2016 12:02:41 +0100 Subject: [PATCH] [runtime] Replace xamarin_try_get_nsobject with xamarin_has_nsobject. Removes one usage of ObjectWrapper, since we don't actually need the return value, we just need to know if an object exists. --- runtime/delegates.t4 | 8 ++++---- runtime/trampolines-invoke.m | 3 +-- runtime/xamarin/runtime.h | 2 +- src/ObjCRuntime/Runtime.cs | 10 +++++----- tools/common/StaticRegistrar.cs | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/runtime/delegates.t4 b/runtime/delegates.t4 index 4c90714aea..0f97267017 100644 --- a/runtime/delegates.t4 +++ b/runtime/delegates.t4 @@ -67,14 +67,14 @@ "SEL", "IntPtr", "sel" ) { WrappedManagedFunction = "GetMethodForSelector" }, - new XDelegate ("MonoObject *", "IntPtr", "xamarin_try_get_nsobject", - "id", "IntPtr", "obj" - ) { WrappedManagedFunction = "TryGetNSObjectWrapped" }, - new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_nsobject", "id", "IntPtr", "obj" ) { WrappedManagedFunction = "GetNSObjectWrapped" }, + new XDelegate ("bool", "bool", "xamarin_has_nsobject", + "id", "IntPtr", "obj" + ) { WrappedManagedFunction = "HasNSObject" }, + new XDelegate ("id", "IntPtr", "xamarin_get_handle_for_inativeobject", "MonoObject *", "IntPtr", "obj" ) { WrappedManagedFunction = "GetHandleForINativeObject" }, diff --git a/runtime/trampolines-invoke.m b/runtime/trampolines-invoke.m index ac97803a54..a59199fd78 100644 --- a/runtime/trampolines-invoke.m +++ b/runtime/trampolines-invoke.m @@ -27,8 +27,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_ bool is_ctor = type == Tramp_Ctor; if (is_ctor) { - void *obj = xamarin_try_get_nsobject (self); - if (obj != NULL) { + if (xamarin_has_nsobject (self)) { self = xamarin_invoke_objc_method_implementation (self, sel, (IMP) xamarin_ctor_trampoline); marshal_return_value (context, "|", sizeof (id), self, NULL, false, NULL); return; diff --git a/runtime/xamarin/runtime.h b/runtime/xamarin/runtime.h index 208d2de5f7..a68ec5f5ac 100644 --- a/runtime/xamarin/runtime.h +++ b/runtime/xamarin/runtime.h @@ -172,7 +172,7 @@ MonoObject* xamarin_get_selector (SEL ptr); Class xamarin_get_class_handle (MonoObject *obj); SEL xamarin_get_selector_handle (MonoObject *obj); MethodDescription xamarin_get_method_for_selector (Class cls, SEL sel); -MonoObject* xamarin_try_get_nsobject (id obj); +bool xamarin_has_nsobject (id obj); MonoObject* xamarin_get_nsobject (id obj); id xamarin_get_handle_for_inativeobject (MonoObject *obj); void xamarin_unregister_nsobject (id native_obj, MonoObject *managed_obj); diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index a35408cc09..5e95233200 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -517,16 +517,16 @@ namespace XamCore.ObjCRuntime { return Registrar.GetMethodDescription (Class.Lookup (cls), sel); } - static IntPtr TryGetNSObjectWrapped (IntPtr ptr) - { - return ObjectWrapper.Convert (TryGetNSObject (ptr)); - } - static IntPtr GetNSObjectWrapped (IntPtr ptr) { return ObjectWrapper.Convert (TryGetNSObject (ptr, true)); } + static bool HasNSObject (IntPtr ptr) + { + return TryGetNSObject (ptr) != null; + } + static IntPtr GetHandleForINativeObject (IntPtr ptr) { return ((INativeObject) ObjectWrapper.Convert (ptr)).Handle; diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index e74ac58f2f..80a1b6e7d7 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -3186,7 +3186,7 @@ namespace XamCore.Registrar { body.Unindent (); if (isCtor) { - body.WriteLine ("if (xamarin_try_get_nsobject (self)) {"); + body.WriteLine ("if (xamarin_has_nsobject (self)) {"); body.WriteLine ("*call_super = true;"); body.WriteLine ("return self;"); body.WriteLine ("}");