Skip to content

Commit bd264cf

Browse files
authored
Fix or disable warnings in Python.Runtime (#1318)
The only tricky one here is the `LookupType` obsoletion, since we are still not handling name conflicts.
1 parent d2685a1 commit bd264cf

File tree

7 files changed

+23
-27
lines changed

7 files changed

+23
-27
lines changed

src/runtime/BorrowedReference.cs

+9
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,14 @@ public BorrowedReference(IntPtr pointer)
2727
=> a.pointer == b.pointer;
2828
public static bool operator !=(BorrowedReference a, BorrowedReference b)
2929
=> a.pointer != b.pointer;
30+
31+
public override bool Equals(object obj) {
32+
if (obj is IntPtr ptr)
33+
return ptr == pointer;
34+
35+
return false;
36+
}
37+
38+
public override int GetHashCode() => pointer.GetHashCode();
3039
}
3140
}

src/runtime/assemblymanager.cs

+3-22
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ internal class AssemblyManager
2020
// therefore this should be a ConcurrentDictionary
2121
//
2222
// WARNING: Dangerous if cross-app domain usage is ever supported
23-
// Reusing the dictionary with assemblies accross multiple initializations is problematic.
24-
// Loading happens from CurrentDomain (see line 53). And if the first call is from AppDomain that is later unloaded,
25-
// than it can end up referring to assemblies that are already unloaded (default behavior after unload appDomain -
23+
// Reusing the dictionary with assemblies accross multiple initializations is problematic.
24+
// Loading happens from CurrentDomain (see line 53). And if the first call is from AppDomain that is later unloaded,
25+
// than it can end up referring to assemblies that are already unloaded (default behavior after unload appDomain -
2626
// unless LoaderOptimization.MultiDomain is used);
2727
// So for multidomain support it is better to have the dict. recreated for each app-domain initialization
2828
private static ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces =
@@ -365,25 +365,6 @@ public static List<string> GetNames(string nsname)
365365
return names;
366366
}
367367

368-
/// <summary>
369-
/// Returns the System.Type object for a given qualified name,
370-
/// looking in the currently loaded assemblies for the named
371-
/// type. Returns null if the named type cannot be found.
372-
/// </summary>
373-
[Obsolete("Use LookupTypes and handle name conflicts")]
374-
public static Type LookupType(string qname)
375-
{
376-
foreach (Assembly assembly in assemblies)
377-
{
378-
Type type = assembly.GetType(qname);
379-
if (type != null && IsExported(type))
380-
{
381-
return type;
382-
}
383-
}
384-
return null;
385-
}
386-
387368
/// <summary>
388369
/// Returns the <see cref="Type"/> objects for the given qualified name,
389370
/// looking in the currently loaded assemblies for the named

src/runtime/classobject.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Linq;
12
using System;
23
using System.Reflection;
34

@@ -143,7 +144,7 @@ public override IntPtr type_subscript(IntPtr idx)
143144
return Exceptions.RaiseTypeError("type(s) expected");
144145
}
145146

146-
Type gtype = AssemblyManager.LookupType($"{type.FullName}`{types.Length}");
147+
Type gtype = AssemblyManager.LookupTypes($"{type.FullName}`{types.Length}").FirstOrDefault();
147148
if (gtype != null)
148149
{
149150
var g = ClassManager.GetClass(gtype) as GenericType;

src/runtime/finalizer.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public IncorrectRefCountException(IntPtr ptr)
6262
}
6363

6464
public delegate bool IncorrectRefCntHandler(object sender, IncorrectFinalizeArgs e);
65-
public event IncorrectRefCntHandler IncorrectRefCntResolver;
65+
#pragma warning disable 414
66+
public event IncorrectRefCntHandler IncorrectRefCntResolver = null;
67+
#pragma warning restore 414
6668
public bool ThrowIfUnhandleIncorrectRefCount { get; set; } = true;
6769

6870
#endregion

src/runtime/genericutil.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Linq;
12
using System;
23
using System.Collections.Generic;
34
using System.Resources;
@@ -124,7 +125,7 @@ public static List<Type> GenericsByName(string ns, string basename)
124125
foreach (string name in names)
125126
{
126127
string qname = ns + "." + name;
127-
Type o = AssemblyManager.LookupType(qname);
128+
Type o = AssemblyManager.LookupTypes(qname).FirstOrDefault();
128129
if (o != null)
129130
{
130131
result.Add(o);

src/runtime/interop.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ internal static class ManagedDataOffsets
8080

8181
static class DataOffsets
8282
{
83-
public static readonly int ob_data;
84-
public static readonly int ob_dict;
83+
public static readonly int ob_data = 0;
84+
public static readonly int ob_dict = 0;
8585

8686
static DataOffsets()
8787
{

src/testing/eventtest.cs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Python.Test
88
public delegate void EventHandlerTest(object sender, EventArgsTest e);
99

1010

11+
#pragma warning disable 67 // Unused events, these are only accessed from Python
1112
public class EventTest
1213
{
1314
public static event EventHandlerTest PublicStaticEvent;
@@ -100,6 +101,7 @@ public static void ShutUpCompiler()
100101
e.PrivateEvent += f;
101102
}
102103
}
104+
#pragma warning restore 67
103105

104106

105107
public class EventArgsTest : EventArgs

0 commit comments

Comments
 (0)