Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BGen] Remove support for the System.Drawing objects. #22247

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 17 additions & 39 deletions src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,11 @@ string GetToBindAsWrapper (MethodInfo mi, MemberInformation minfo = null, Parame
temp = string.Format ("{3}new NSNumber ({2}{1}{0});", denullify, parameterName, enumCast, nullCheck);
} else if (originalType == TypeCache.NSValue) {
var typeStr = string.Empty;
if (!TypeCache.NSValueCreateMap.TryGetValue (retType, out typeStr)) {
// HACK: These are problematic for X.M due to we do not ship System.Drawing for Full profile
if (retType.Name == "RectangleF" || retType.Name == "SizeF" || retType.Name == "PointF")
typeStr = retType.Name;
else
throw GetBindAsException ("box", retType.Name, originalType.Name, "container", minfo?.mi, pi);
if (TypeCache.NSValueCreateMap.TryGetValue (retType, out typeStr)) {
temp = string.Format ("{3}NSValue.From{0} ({2}{1});", typeStr, denullify, parameterName, nullCheck);
} else {
throw GetBindAsException ("box", retType.Name, originalType.Name, "container", minfo?.mi, pi);
}
temp = string.Format ("{3}NSValue.From{0} ({2}{1});", typeStr, denullify, parameterName, nullCheck);
} else if (originalType == TypeCache.NSString && IsSmartEnum (retType)) {
temp = isNullable ? $"{parameterName} is null ? null : " : string.Empty;
temp += $"{TypeManager.FormatType (retType.DeclaringType, retType)}Extensions.GetConstant ({parameterName}{denullify});";
Expand All @@ -452,13 +449,11 @@ string GetToBindAsWrapper (MethodInfo mi, MemberInformation minfo = null, Parame
valueConverter = $"new NSNumber ({cast}o{denullify}), {parameterName});";
} else if (arrType == TypeCache.NSValue && !isNullable) {
var typeStr = string.Empty;
if (!TypeCache.NSValueCreateMap.TryGetValue (arrRetType, out typeStr)) {
if (arrRetType.Name == "RectangleF" || arrRetType.Name == "SizeF" || arrRetType.Name == "PointF")
typeStr = retType.Name;
else
throw GetBindAsException ("box", arrRetType.Name, originalType.Name, "array", minfo?.mi, pi);
if (TypeCache.NSValueCreateMap.TryGetValue (arrRetType, out typeStr)) {
valueConverter = $"NSValue.From{typeStr} (o{denullify}), {parameterName});";
} else {
throw GetBindAsException ("box", arrRetType.Name, originalType.Name, "array", minfo?.mi, pi);
}
valueConverter = $"NSValue.From{typeStr} (o{denullify}), {parameterName});";
} else
throw new BindingException (1048, true, isNullable ? arrRetType.Name + "?[]" : retType.Name);
temp = $"NSArray.FromNSObjects (o => {valueConverter}";
Expand Down Expand Up @@ -498,15 +493,12 @@ string GetFromBindAsWrapper (MemberInformation minfo, out string suffix)
if (isNullable)
append = $"?{append}";
} else if (originalReturnType == TypeCache.NSValue) {
if (!TypeManager.NSValueReturnMap.TryGetValue (retType, out append)) {
// HACK: These are problematic for X.M due to we do not ship System.Drawing for Full profile
if (retType.Name == "RectangleF" || retType.Name == "SizeF" || retType.Name == "PointF")
append = $".{retType.Name}Value";
else
throw GetBindAsException ("unbox", retType.Name, originalReturnType.Name, "container", minfo.mi);
if (TypeManager.NSValueReturnMap.TryGetValue (retType, out append)) {
if (isNullable)
append = $"?{append}";
} else {
throw GetBindAsException ("unbox", retType.Name, originalReturnType.Name, "container", minfo.mi);
}
if (isNullable)
append = $"?{append}";
} else if (originalReturnType == TypeCache.NSString && IsSmartEnum (retType)) {
append = $"{TypeManager.FormatType (retType.DeclaringType, retType)}Extensions.GetValue (";
suffix = ")";
Expand All @@ -532,12 +524,11 @@ string GetFromBindAsWrapper (MemberInformation minfo, out string suffix)
} else
throw GetBindAsException ("unbox", retType.Name, arrType.Name, "array", minfo.mi);
} else if (arrType == TypeCache.NSValue && !arrIsNullable) {
if (arrRetType.Name == "RectangleF" || arrRetType.Name == "SizeF" || arrRetType.Name == "PointF")
valueFetcher = $"{(arrIsNullable ? "?" : string.Empty)}.{arrRetType.Name}Value";
else if (!TypeManager.NSValueReturnMap.TryGetValue (arrRetType, out valueFetcher))
if (TypeManager.NSValueReturnMap.TryGetValue (arrRetType, out valueFetcher)) {
append = string.Format ("ptr => {{\n\tusing (var val = Runtime.GetNSObject<NSValue> (ptr)!) {{\n\t\treturn val{0};\n\t}}\n}}", valueFetcher);
} else {
throw GetBindAsException ("unbox", retType.Name, arrType.Name, "array", minfo.mi);

append = string.Format ("ptr => {{\n\tusing (var val = Runtime.GetNSObject<NSValue> (ptr)!) {{\n\t\treturn val{0};\n\t}}\n}}", valueFetcher);
}
} else
throw new BindingException (1048, true, arrIsNullable ? arrRetType.Name + "?[]" : retType.Name);
} else
Expand Down Expand Up @@ -2137,12 +2128,6 @@ void GenerateEventArgsFile ()
print (GenerateNSNumber ("", "DoubleValue"));
else if (propertyType == TypeCache.System_Float)
print (GenerateNSNumber ("", "FloatValue"));
else if (fullname == "System.Drawing.PointF")
print (GenerateNSValue ("PointFValue"));
else if (fullname == "System.Drawing.SizeF")
print (GenerateNSValue ("SizeFValue"));
else if (fullname == "System.Drawing.RectangleF")
print (GenerateNSValue ("RectangleFValue"));
else if (fullname == "CoreGraphics.CGPoint")
print (GenerateNSValue ("CGPointValue"));
else if (fullname == "CoreGraphics.CGSize")
Expand Down Expand Up @@ -6341,8 +6326,6 @@ public void Generate (Type type)
print ("return Dlfcn.GetIntPtr (Libraries.{2}.Handle, \"{1}\");", field_pi.Name, fieldAttr.SymbolName, library_name);
} else if (field_pi.PropertyType == TypeCache.System_UIntPtr) {
print ("return Dlfcn.GetUIntPtr (Libraries.{2}.Handle, \"{1}\");", field_pi.Name, fieldAttr.SymbolName, library_name);
} else if (field_pi.PropertyType.FullName == "System.Drawing.SizeF") {
print ("return Dlfcn.GetSizeF (Libraries.{2}.Handle, \"{1}\");", field_pi.Name, fieldAttr.SymbolName, library_name);
} else if (field_pi.PropertyType == TypeCache.System_Int64) {
print ("return Dlfcn.GetInt64 (Libraries.{2}.Handle, \"{1}\");", field_pi.Name, fieldAttr.SymbolName, library_name);
} else if (field_pi.PropertyType == TypeCache.System_UInt64) {
Expand Down Expand Up @@ -6427,8 +6410,6 @@ public void Generate (Type type)
print ("Dlfcn.SetIntPtr (Libraries.{2}.Handle, \"{1}\", value);", field_pi.Name, fieldAttr.SymbolName, library_name);
} else if (field_pi.PropertyType == TypeCache.System_UIntPtr) {
print ("Dlfcn.SetUIntPtr (Libraries.{2}.Handle, \"{1}\", value);", field_pi.Name, fieldAttr.SymbolName, library_name);
} else if (field_pi.PropertyType.FullName == "System.Drawing.SizeF") {
print ("Dlfcn.SetSizeF (Libraries.{2}.Handle, \"{1}\", value);", field_pi.Name, fieldAttr.SymbolName, library_name);
} else if (field_pi.PropertyType == TypeCache.System_Int64) {
print ("Dlfcn.SetInt64 (Libraries.{2}.Handle, \"{1}\", value);", field_pi.Name, fieldAttr.SymbolName, library_name);
} else if (field_pi.PropertyType == TypeCache.System_UInt64) {
Expand Down Expand Up @@ -7501,9 +7482,6 @@ object GetDefaultValue (MethodInfo mi)

var type = def as Type;
if (type is not null && (
type.FullName == "System.Drawing.PointF" ||
type.FullName == "System.Drawing.SizeF" ||
type.FullName == "System.Drawing.RectangleF" ||
type.FullName == "CoreGraphics.CGPoint" ||
type.FullName == "CoreGraphics.CGSize" ||
type.FullName == "CoreGraphics.CGRect"))
Expand Down
11 changes: 6 additions & 5 deletions tests/generator/bindastests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Foundation;
using CoreMedia;
using CoreAnimation;
using CoreGraphics;
using ObjCRuntime;

namespace BindAsTests {
Expand All @@ -12,10 +13,10 @@ interface MyFooClass {

[return: BindAs (typeof (bool?))]
[Export ("boolMethod:a:b:c:d:")]
NSNumber BoolMethod (int arg0, string arg1, [BindAs (typeof (RectangleF))] NSValue arg2, [BindAs (typeof (bool?))] NSNumber arg3, int arg4);
NSNumber BoolMethod (int arg0, string arg1, [BindAs (typeof (CGRect))] NSValue arg2, [BindAs (typeof (bool?))] NSNumber arg3, int arg4);

[Export ("stringMethod:a:b:c:d:")]
string stringMethod (int arg0, string arg1, [BindAs (typeof (RectangleF))] NSValue arg2, [BindAs (typeof (bool?))] NSNumber arg3, int arg4);
string stringMethod (int arg0, string arg1, [BindAs (typeof (CGRect))] NSValue arg2, [BindAs (typeof (bool?))] NSNumber arg3, int arg4);

[return: BindAs (typeof (bool?))]
[Export ("boolMethod:")]
Expand Down Expand Up @@ -45,7 +46,7 @@ interface MyFooClass {
[Export ("cmtimeMethod")]
NSValue CMTimeMethod ();

[return: BindAs (typeof (PointF))]
[return: BindAs (typeof (CGPoint))]
[Static, Export ("pointMethodS:")]
NSValue PointFMethodS (sbyte arg1);

Expand All @@ -57,11 +58,11 @@ interface MyFooClass {
[Export ("doubleProperty")]
NSNumber DoubleProperty { get; set; }

[BindAs (typeof (RectangleF?))]
[BindAs (typeof (CGRect?))]
[Static, Export ("rectangleFPropertyS")]
NSValue RectangleFPropertyS { get; set; }

[BindAs (typeof (SizeF))]
[BindAs (typeof (CGSize))]
[Export ("sizeFFProperty")]
NSValue SizeFProperty { get; set; }

Expand Down
Loading