-
Notifications
You must be signed in to change notification settings - Fork 555
[generator] Fix bug 17232 - Invalid class name generated in the Libraries.g.cs file. #33
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1485,7 +1485,7 @@ public partial class Generator : IMemberGatherer { | |
| Dictionary<Type,TrampolineInfo> trampolines = new Dictionary<Type,TrampolineInfo> (); | ||
| Dictionary<Type,int> trampolines_generic_versions = new Dictionary<Type,int> (); | ||
| Dictionary<Type,Type> notification_event_arg_types = new Dictionary<Type,Type> (); | ||
| List <string> libraries = new List <string> (); | ||
| Dictionary<string, string> libraries = new Dictionary<string, string> (); // <LibraryName, libraryPath> | ||
|
|
||
| List<Tuple<string, ParameterInfo[]>> async_result_types = new List<Tuple <string, ParameterInfo[]>> (); | ||
| HashSet<string> async_result_types_emitted = new HashSet<string> (); | ||
|
|
@@ -3004,7 +3004,30 @@ void GenerateTrampolinesForQueue (TrampolineInfo [] queue) | |
| print ("}} /* class {0} */", ti.NativeInvokerName); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // We need to check against the user using just UIKit (and friends) in the FieldAttribute | ||
| // so we need to reflect the libraries contained in our Constants class and do the mapping | ||
| // we will return the system library path if found | ||
| bool IsNotSystemLibrary (string library_name) | ||
| { | ||
| string library_path = null; | ||
| return TryGetLibraryPath (library_name, ref library_path); | ||
| } | ||
|
|
||
| bool TryGetLibraryPath (string library_name, ref string library_path) | ||
| { | ||
| var libSuffixedName = $"{library_name}Library"; | ||
| var constType = typeof ( | ||
| #if XAMCORE_2_0 | ||
| XamCore.ObjCRuntime.Constants); | ||
| #else | ||
| XamCore.Constants); | ||
| #endif | ||
| var field = constType.GetFields (BindingFlags.Public | BindingFlags.Static).FirstOrDefault (f => f.Name == libSuffixedName); | ||
| library_path = (string) field?.GetValue (null); | ||
| return library_path == null; | ||
| } | ||
|
|
||
| void GenerateLibraryHandles () | ||
| { | ||
| sw = GetOutputStream ("ObjCRuntime", "Libraries"); | ||
|
|
@@ -3013,10 +3036,14 @@ void GenerateLibraryHandles () | |
| print ("namespace {0} {{", ns.CoreObjCRuntime); indent++; | ||
| print ("[CompilerGenerated]"); | ||
| print ("static partial class Libraries {"); indent++; | ||
| foreach (string library_name in libraries.OrderBy (v => v)) { | ||
| print ("static public class {0} {{", library_name); indent++; | ||
| foreach (var library_info in libraries.OrderBy (v => v.Key)) { | ||
| var library_name = library_info.Key; | ||
| var library_path = library_info.Value; | ||
| print ("static public class {0} {{", library_name.Replace (".", string.Empty)); indent++; | ||
| if (BindThirdPartyLibrary && library_name == "__Internal") { | ||
| print ("static public readonly IntPtr Handle = Dlfcn.dlopen (null, 0);"); | ||
| } else if (BindThirdPartyLibrary && library_path != null && IsNotSystemLibrary (library_name)) { | ||
| print ($"static public readonly IntPtr Handle = Dlfcn.dlopen (\"{library_path}\", 0);"); | ||
| } else { | ||
| print ("static public readonly IntPtr Handle = Dlfcn.dlopen (Constants.{0}Library, 0);", library_name); | ||
| } | ||
|
|
@@ -6228,6 +6255,7 @@ public void Generate (Type type) | |
| foreach (var field_pi in field_exports.OrderBy (f => f.Name)) { | ||
| var fieldAttr = (FieldAttribute) field_pi.GetCustomAttributes (typeof (FieldAttribute), true) [0]; | ||
| string library_name; | ||
| string library_path = null; | ||
|
|
||
| if (fieldAttr.LibraryName != null){ | ||
| // Remapped | ||
|
|
@@ -6241,19 +6269,31 @@ public void Generate (Type type) | |
| library_name = CoreServicesMap; | ||
| break; | ||
| } | ||
| } | ||
| } else { | ||
| // we get something in LibraryName from FieldAttribute so we asume | ||
| // it is a path to a library, so we save the path and change library name | ||
| // to a valid identifier if needed | ||
| library_path = library_name; | ||
| library_name = Path.GetFileName (library_name); | ||
| if (library_name.Contains (".")) | ||
| library_name = library_name.Replace (".", string.Empty); | ||
| } | ||
| } else if (BindThirdPartyLibrary) { | ||
| // User should provide a LibraryName | ||
| throw new BindingException (1042, true, $"Missing '[Field (LibraryName=value)]' for {field_pi.Name} (e.g.\"__Internal\")"); | ||
| } else { | ||
| library_name = type.Namespace; | ||
| // note: not every binding namespace will start with ns.Prefix (e.g. MonoTouch.) | ||
| if (!String.IsNullOrEmpty (ns.Prefix) && library_name.StartsWith (ns.Prefix)) | ||
| if (!String.IsNullOrEmpty (ns.Prefix) && library_name.StartsWith (ns.Prefix)) { | ||
| library_name = library_name.Substring (ns.Prefix.Length + 1); | ||
| library_name = library_name.Replace (".", string.Empty); // Remove dots from namespaces | ||
| } | ||
| } | ||
|
|
||
| if (!libraries.Contains (library_name)) { | ||
| libraries.Add (library_name); | ||
| } | ||
| if (!libraries.ContainsKey (library_name)) | ||
| libraries.Add (library_name, library_path); | ||
|
|
||
| bool is_unified_internal = field_pi.IsUnifiedInternal (); | ||
|
|
||
| string fieldTypeName = FormatType (field_pi.DeclaringType, field_pi.PropertyType); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra lines to reduce diff. |
||
| // Value types we dont cache for now, to avoid Nullable<T> | ||
| if (!field_pi.PropertyType.IsValueType) { | ||
|
|
@@ -6263,7 +6303,7 @@ public void Generate (Type type) | |
| } | ||
|
|
||
| PrintPreserveAttribute (field_pi); | ||
| print ("[Field (\"{0}\", \"{1}\")]", fieldAttr.SymbolName, library_name); | ||
| print ("[Field (\"{0}\", \"{1}\")]", fieldAttr.SymbolName, library_path ?? library_name); | ||
| PrintPlatformAttributes (field_pi); | ||
| if (Generator.HasAttribute (field_pi, typeof (AdvancedAttribute))){ | ||
| print ("[EditorBrowsable (EditorBrowsableState.Advanced)]"); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got a small question about this. You are using a Tuple that contains the lib name and the lib path. Later in the code we have to use things such as:
I'm wondering how many times (if ever) we have a LibraryName that is not unique. If that is guaranteed, that is, no library will have the same name as other, using a dictionary (the StringDictionary specialised collection) over a
List <Tuple <string, string>>makes sense. Searching will be faster, we will have less linq operations (and we all know that is good ;) ) and makes things such as accessing the data cleaner removing things like: