From 97faed65caf145e6cfb4861ee2e6a76e268e3374 Mon Sep 17 00:00:00 2001 From: Victor Nova Date: Thu, 21 Oct 2021 17:20:56 -0700 Subject: [PATCH] remove unused PythonMethodAttribute fixes https://github.com/pythonnet/pythonnet/issues/1604 --- src/runtime/interop.cs | 10 --------- src/runtime/typemanager.cs | 39 --------------------------------- src/runtime/typemethod.cs | 45 -------------------------------------- 3 files changed, 94 deletions(-) delete mode 100644 src/runtime/typemethod.cs diff --git a/src/runtime/interop.cs b/src/runtime/interop.cs index e10348e39..641a188eb 100644 --- a/src/runtime/interop.cs +++ b/src/runtime/interop.cs @@ -4,7 +4,6 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Reflection; -using System.Text; namespace Python.Runtime { @@ -31,15 +30,6 @@ public string DocString private string docStr; } - [Serializable] - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate)] - internal class PythonMethodAttribute : Attribute - { - public PythonMethodAttribute() - { - } - } - [Serializable] [AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate)] internal class ModuleFunctionAttribute : Attribute diff --git a/src/runtime/typemanager.cs b/src/runtime/typemanager.cs index 7a836bf05..cd4faae73 100644 --- a/src/runtime/typemanager.cs +++ b/src/runtime/typemanager.cs @@ -208,8 +208,6 @@ internal static unsafe PyType CreateType(Type impl) Runtime.PyDict_SetItem(dict, PyIdentifier.__module__, mod); mod.Dispose(); - InitMethods(dict, impl); - dict.Dispose(); // The type has been modified after PyType_Ready has been called @@ -806,43 +804,6 @@ static void InitializeSlot(IntPtr type, int slotOffset, ThunkInfo thunk, SlotsHo } } - /// - /// Given a dict of a newly allocated Python type object and a managed Type that - /// implements it, initialize any methods defined by the Type that need - /// to appear in the Python type __dict__ (based on custom attribute). - /// - private static void InitMethods(BorrowedReference typeDict, Type type) - { - Type marker = typeof(PythonMethodAttribute); - - BindingFlags flags = BindingFlags.Public | BindingFlags.Static; - var addedMethods = new HashSet(); - - while (type != null) - { - MethodInfo[] methods = type.GetMethods(flags); - foreach (MethodInfo method in methods) - { - if (!addedMethods.Contains(method.Name)) - { - object[] attrs = method.GetCustomAttributes(marker, false); - if (attrs.Length > 0) - { - string method_name = method.Name; - var mi = new MethodInfo[1]; - mi[0] = method; - MethodObject m = new TypeMethod(type, method_name, mi); - Runtime.PyDict_SetItemString(typeDict, method_name, m.ObjectReference); - m.DecrRefCount(); - addedMethods.Add(method_name); - } - } - } - type = type.BaseType; - } - } - - /// /// Utility method to copy slots from a given type to another type. /// diff --git a/src/runtime/typemethod.cs b/src/runtime/typemethod.cs deleted file mode 100644 index 4da92613c..000000000 --- a/src/runtime/typemethod.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Reflection; - -namespace Python.Runtime -{ - /// - /// Implements a Python type that provides access to CLR object methods. - /// - internal class TypeMethod : MethodObject - { - public TypeMethod(Type type, string name, MethodInfo[] info) : - base(type, name, info) - { - } - - public TypeMethod(Type type, string name, MethodInfo[] info, bool allow_threads) : - base(type, name, info, allow_threads) - { - } - - public override IntPtr Invoke(IntPtr ob, IntPtr args, IntPtr kw) - { - MethodInfo mi = info[0]; - var arglist = new object[3]; - arglist[0] = ob; - arglist[1] = args; - arglist[2] = kw; - - try - { - object inst = null; - if (ob != IntPtr.Zero) - { - inst = GetManagedObject(ob); - } - return (IntPtr)mi.Invoke(inst, BindingFlags.Default, null, arglist, null); - } - catch (Exception e) - { - Exceptions.SetError(e); - return IntPtr.Zero; - } - } - } -} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy