Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Support converting block literal wrapped delegates back
Browse files Browse the repository at this point in the history
This currently will only support converting block literals that
are backed by delegates we have created, a pure objc delegate
will not be supported thru this mechanism, but this could be
extended to do so in the future.
  • Loading branch information
Geoff Norton committed Jan 4, 2011
1 parent 760aeef commit 20b605b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/generator.cs
Expand Up @@ -1372,6 +1372,9 @@ void GenerateInvoke (bool stret, bool supercall, MethodInfo mi, string selector,
} else if (mai.Type == typeof (string) && !mai.PlainString){
cast_a = "NSString.FromHandle (";
cast_b = ")";
} else if (mi.ReturnType.IsSubclassOf (typeof (Delegate))){
cast_a = "(BlockLiteral *)";
cast_b = "";
} else if (LookupMarshal (mai.Type, out mt)){
cast_a = mt.CreateFromRet;
cast_b = ")";
Expand Down Expand Up @@ -1559,11 +1562,16 @@ public void GenerateMethodBody (Type type, MethodInfo mi, bool virtual_method, b
(mi.Name != "Constructor" && (NeedStret (mi) || disposes.Length > 0 || has_postget) && mi.ReturnType != typeof (void)) ||
(HasAttribute (mi, typeof (FactoryAttribute))) ||
(assign != null && (IsWrappedType (mi.ReturnType) || (mi.ReturnType.IsArray && IsWrappedType (mi.ReturnType.GetElementType ())))) ||
(mi.ReturnType.IsSubclassOf (typeof (Delegate))) ||
(mi.Name != "Constructor" && byRefPostProcessing.Length > 0 && mi.ReturnType != typeof (void));


if (use_temp_return)
print ("{0} ret;", FormatType (mi.DeclaringType, mi.ReturnType)); // = new {0} ();"
if (use_temp_return) {
if (mi.ReturnType.IsSubclassOf (typeof (Delegate)))
print ("BlockLiteral *ret;");
else
print ("{0} ret;", FormatType (mi.DeclaringType, mi.ReturnType)); // = new {0} ();"
}

bool needs_temp = use_temp_return || disposes.Length > 0;
if (virtual_method || mi.Name == "Constructor"){
Expand Down Expand Up @@ -1603,8 +1611,13 @@ public void GenerateMethodBody (Type type, MethodInfo mi, bool virtual_method, b
print ("ret.Release (); // Release implicit ref taken by GetNSObject");
if (byRefPostProcessing.Length > 0)
print (byRefPostProcessing.ToString ());
if (use_temp_return)
print ("return ret;");
if (use_temp_return) {
if (mi.ReturnType.IsSubclassOf (typeof (Delegate))) {
print ("return ({0}) (ret->global_handle != IntPtr.Zero ? GCHandle.FromIntPtr (ret->global_handle).Target : GCHandle.FromIntPtr (ret->local_handle).Target);", FormatType (mi.DeclaringType, mi.ReturnType));
} else {
print ("return ret;");
}
}

indent--;
}
Expand Down

0 comments on commit 20b605b

Please sign in to comment.