8000 Fix or disable warnings in Python.Runtime by filmor · Pull Request #1318 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Fix or disable warnings in Python.Runtime #1318

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 1 commit into from
Dec 12, 2020
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
Fix or disable warnings in Python.Runtime
The only tricky one here is the `LookupType` obsoletion, since we are
still not handling name conflicts.
  • Loading branch information
filmor committed Dec 12, 2020
commit f70a73a91108904b3f577cec466a679712d6770c
9 changes: 9 additions & 0 deletions src/runtime/BorrowedReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,14 @@ public BorrowedReference(IntPtr pointer)
=> a.pointer == b.pointer;
public static bool operator !=(BorrowedReference a, BorrowedReference b)
=> a.pointer != b.pointer;

public override bool Equals(object obj) {
if (obj is IntPtr ptr)
return ptr == pointer;

return false;
}

public override int GetHashCode() => pointer.GetHashCode();
}
}
25 changes: 3 additions & 22 deletions src/runtime/assemblymanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ internal class AssemblyManager
// therefore this should be a ConcurrentDictionary
//
// WARNING: Dangerous if cross-app domain usage is ever supported
// Reusing the dictionary with assemblies accross multiple initializations is problematic.
// Loading happens from CurrentDomain (see line 53). And if the first call is from AppDomain that is later unloaded,
// than it can end up referring to assemblies that are already unloaded (default behavior after unload appDomain -
// Reusing the dictionary with assemblies accross multiple initializations is problematic.
// Loading happens from CurrentDomain (see line 53). And if the first call is from AppDomain that is later unloaded,
// than it can end up referring to assemblies that are already unloaded (default behavior after unload appDomain -
// unless LoaderOptimization.MultiDomain is used);
// So for multidomain support it is better to have the dict. recreated for each app-domain initialization
private static ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces =
10000 Expand Down Expand Up @@ -365,25 +365,6 @@ public static List<string> GetNames(string nsname)
return names;
}

/// <summary>
/// Returns the System.Type object for a given qualified name,
/// looking in the currently loaded assemblies for the named
/// type. Returns null if the named type cannot be found.
/// </summary>
[Obsolete("Use LookupTypes and handle name conflicts")]
public static Type LookupType(string qname)
{
foreach (Assembly assembly in assemblies)
{
Type type = assembly.GetType(qname);
if (type != null && IsExported(type))
{
return type;
}
}
return null;
}

/// <summary>
/// Returns the <see cref="Type"/> objects for the given qualified name,
/// looking in the currently loaded assemblies for the named
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/classobject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System;
using System.Reflection;

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

Type gtype = AssemblyManager.LookupType($"{type.FullName}`{types.Length}");
Type gtype = AssemblyManager.LookupTypes($"{type.FullName}`{types.Length}").FirstOrDefault();
if (gtype != null)
{
var g = ClassManager.GetClass(gtype) as GenericType;
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/finalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public IncorrectRefCountException(IntPtr ptr)
}

public delegate bool IncorrectRefCntHandler(object sender, IncorrectFinalizeArgs e);
public event IncorrectRefCntHandler IncorrectRefCntResolver;
#pragma warning disable 414
public event IncorrectRefCntHandler IncorrectRefCntResolver = null;
#pragma warning restore 414
public bool ThrowIfUnhandleIncorrectRefCount { get; set; } = true;

#endregion
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/genericutil.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System.Resources;
Expand Down Expand Up @@ -124,7 +125,7 @@ public static List<Type> GenericsByName(string ns, string basename)
foreach (string name in names)
{
string qname = ns + "." + name;
Type o = AssemblyManager.LookupType(qname);
Type o = AssemblyManager.LookupTypes(qname).FirstOrDefault();
if (o != null)
{
result.Add(o);
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ internal static class ManagedDataOffsets

static class DataOffsets
{
public static readonly int ob_data;
public static readonly int ob_dict;
public static readonly int ob_data = 0;
public static readonly int ob_dict = 0;

static DataOffsets()
{
Expand Down
2 changes: 2 additions & 0 deletions src/testing/eventtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Python.Test
public delegate void EventHandlerTest(object sender, EventArgsTest e);


#pragma warning disable 67 // Unused events, these are only accessed from Python
public class EventTest
{
public static event EventHandlerTest PublicStaticEvent;
Expand Down Expand Up @@ -100,6 +101,7 @@ public static void ShutUpCompiler()
e.PrivateEvent += f;
}
}
#pragma warning restore 67


public class EventArgsTest : EventArgs
Expand Down
0