diff --git a/src/runtime/arrayobject.cs b/src/runtime/arrayobject.cs index eaff49214..6096706dd 100644 --- a/src/runtime/arrayobject.cs +++ b/src/runtime/arrayobject.cs @@ -38,10 +38,9 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) } - //==================================================================== - // Implements __getitem__ for array types. - //==================================================================== - + /// + /// Implements __getitem__ for array types. + /// public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) { CLRObject obj = (CLRObject)ManagedType.GetManagedObject(ob); @@ -131,10 +130,9 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) } - //==================================================================== - // Implements __setitem__ for array types. - //==================================================================== - + /// + /// Implements __setitem__ for array types. + /// public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) { CLRObject obj = (CLRObject)ManagedType.GetManagedObject(ob); @@ -226,10 +224,9 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) } - //==================================================================== - // Implements __contains__ for array types. - //==================================================================== - + /// + /// Implements __contains__ for array types. + /// public static int sq_contains(IntPtr ob, IntPtr v) { CLRObject obj = (CLRObject)ManagedType.GetManagedObject(ob); @@ -251,10 +248,9 @@ public static int sq_contains(IntPtr ob, IntPtr v) } - //==================================================================== - // Implements __len__ for array types. - //==================================================================== - + /// + /// Implements __len__ for array types. + /// public static int mp_length(IntPtr ob) { CLRObject self = (CLRObject)ManagedType.GetManagedObject(ob); diff --git a/src/runtime/assemblymanager.cs b/src/runtime/assemblymanager.cs index f263728bb..b98455ec3 100644 --- a/src/runtime/assemblymanager.cs +++ b/src/runtime/assemblymanager.cs @@ -31,12 +31,11 @@ private AssemblyManager() { } - //=================================================================== - // Initialization performed on startup of the Python runtime. Here we - // scan all of the currently loaded assemblies to determine exported - // names, and register to be notified of new assembly loads. - //=================================================================== - + /// + /// Initialization performed on startup of the Python runtime. Here we + /// scan all of the currently loaded assemblies to determine exported + /// names, and register to be notified of new assembly loads. + /// internal static void Initialize() { namespaces = new ConcurrentDictionary>(); @@ -69,10 +68,9 @@ internal static void Initialize() } - //=================================================================== - // Cleanup resources upon shutdown of the Python runtime. - //=================================================================== - + /// + /// Cleanup resources upon shutdown of the Python runtime. + /// internal static void Shutdown() { AppDomain domain = AppDomain.CurrentDomain; @@ -81,14 +79,13 @@ internal static void Shutdown() } - //=================================================================== - // Event handler for assembly load events. At the time the Python - // runtime loads, we scan the app domain to map the assemblies that - // are loaded at the time. We also have to register this event handler - // so that we can know about assemblies that get loaded after the - // Python runtime is initialized. - //=================================================================== - + /// + /// Event handler for assembly load events. At the time the Python + /// runtime loads, we scan the app domain to map the assemblies that + /// are loaded at the time. We also have to register this event handler + /// so that we can know about assemblies that get loaded after the + /// Python runtime is initialized. + /// static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args) { Assembly assembly = args.LoadedAssembly; @@ -97,14 +94,13 @@ static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args) } - //=================================================================== - // Event handler for assembly resolve events. This is needed because - // we augment the assembly search path with the PYTHONPATH when we - // load an assembly from Python. Because of that, we need to listen - // for failed loads, because they might be dependencies of something - // we loaded from Python which also needs to be found on PYTHONPATH. - //=================================================================== - + /// + /// Event handler for assembly resolve events. This is needed because + /// we augment the assembly search path with the PYTHONPATH when we + /// load an assembly from Python. Because of that, we need to listen + /// for failed loads, because they might be dependencies of something + /// we loaded from Python which also needs to be found on PYTHONPATH. + /// static Assembly ResolveHandler(Object ob, ResolveEventArgs args) { string name = args.Name.ToLower(); @@ -120,19 +116,17 @@ static Assembly ResolveHandler(Object ob, ResolveEventArgs args) } - //=================================================================== - // We __really__ want to avoid using Python objects or APIs when - // probing for assemblies to load, since our ResolveHandler may be - // called in contexts where we don't have the Python GIL and can't - // even safely try to get it without risking a deadlock ;( - // - // To work around that, we update a managed copy of sys.path (which - // is the main thing we care about) when UpdatePath is called. The - // import hook calls this whenever it knows its about to use the - // assembly manager, which lets us keep up with changes to sys.path - // in a relatively lightweight and low-overhead way. - //=================================================================== - + /// + /// We __really__ want to avoid using Python objects or APIs when + /// probing for assemblies to load, since our ResolveHandler may be + /// called in contexts where we don't have the Python GIL and can't + /// even safely try to get it without risking a deadlock ;( + /// To work around that, we update a managed copy of sys.path (which + /// is the main thing we care about) when UpdatePath is called. The + /// import hook calls this whenever it knows its about to use the + /// assembly manager, which lets us keep up with changes to sys.path + /// in a relatively lightweight and low-overhead way. + /// internal static void UpdatePath() { IntPtr list = Runtime.PySys_GetObject("path"); @@ -154,12 +148,11 @@ internal static void UpdatePath() } - //=================================================================== - // Given an assembly name, try to find this assembly file using the - // PYTHONPATH. If not found, return null to indicate implicit load - // using standard load semantics (app base directory then GAC, etc.) - //=================================================================== - + /// + /// Given an assembly name, try to find this assembly file using the + /// PYTHONPATH. If not found, return null to indicate implicit load + /// using standard load semantics (app base directory then GAC, etc.) + /// public static string FindAssembly(string name) { char sep = Path.DirectorySeparatorChar; @@ -193,11 +186,10 @@ public static string FindAssembly(string name) } - //=================================================================== - // Loads an assembly from the application directory or the GAC - // given a simple assembly name. Returns the assembly if loaded. - //=================================================================== - + /// + /// Loads an assembly from the application directory or the GAC + /// given a simple assembly name. Returns the assembly if loaded. + /// public static Assembly LoadAssembly(string name) { Assembly assembly = null; @@ -216,10 +208,9 @@ public static Assembly LoadAssembly(string name) } - //=================================================================== - // Loads an assembly using an augmented search path (the python path). - //=================================================================== - + /// + /// Loads an assembly using an augmented search path (the python path). + /// public static Assembly LoadAssemblyPath(string name) { string path = FindAssembly(name); @@ -240,8 +231,10 @@ public static Assembly LoadAssemblyPath(string name) /// /// Loads an assembly using full path. /// - /// - /// + /// + /// + /// + /// public static Assembly LoadAssemblyFullPath(string name) { Assembly assembly = null; @@ -263,10 +256,9 @@ public static Assembly LoadAssemblyFullPath(string name) return assembly; } - //=================================================================== - // Returns an assembly that's already been loaded - //=================================================================== - + /// + /// Returns an assembly that's already been loaded + /// public static Assembly FindLoadedAssembly(string name) { foreach (Assembly a in assemblies) @@ -279,18 +271,19 @@ public static Assembly FindLoadedAssembly(string name) return null; } - //=================================================================== - // Given a qualified name of the form A.B.C.D, attempt to load - // an assembly named after each of A.B.C.D, A.B.C, A.B, A. This - // will only actually probe for the assembly once for each unique - // namespace. Returns true if any assemblies were loaded. - // TODO item 3 "* Deprecate implicit loading of assemblies": - // Set the fromFile flag if the name of the loaded assembly matches - // the fully qualified name that was requested if the framework - // actually loads an assembly. - // Call ONLY for namespaces that HAVE NOT been cached yet. - //=================================================================== - + /// + /// Given a qualified name of the form A.B.C.D, attempt to load + /// an assembly named after each of A.B.C.D, A.B.C, A.B, A. This + /// will only actually probe for the assembly once for each unique + /// namespace. Returns true if any assemblies were loaded. + /// + /// + /// TODO item 3 "* Deprecate implicit loading of assemblies": + /// Set the fromFile flag if the name of the loaded assembly matches + /// the fully qualified name that was requested if the framework + /// actually loads an assembly. + /// Call ONLY for namespaces that HAVE NOT been cached yet. + /// public static bool LoadImplicit(string name, bool warn = true) { string[] names = name.Split('.'); @@ -339,13 +332,12 @@ public static bool LoadImplicit(string name, bool warn = true) } - //=================================================================== - // Scans an assembly for exported namespaces, adding them to the - // mapping of valid namespaces. Note that for a given namespace - // a.b.c.d, each of a, a.b, a.b.c and a.b.c.d are considered to - // be valid namespaces (to better match Python import semantics). - //=================================================================== - + /// + /// Scans an assembly for exported namespaces, adding them to the + /// mapping of valid namespaces. Note that for a given namespace + /// a.b.c.d, each of a, a.b, a.b.c and a.b.c.d are considered to + /// be valid namespaces (to better match Python import semantics). + /// internal static void ScanAssembly(Assembly assembly) { // A couple of things we want to do here: first, we want to @@ -390,20 +382,18 @@ public static AssemblyName[] ListAssemblies() return names.ToArray(); } - //=================================================================== - // Returns true if the given qualified name matches a namespace - // exported by an assembly loaded in the current app domain. - //=================================================================== - + /// + /// Returns true if the given qualified name matches a namespace + /// exported by an assembly loaded in the current app domain. + /// public static bool IsValidNamespace(string name) { return !String.IsNullOrEmpty(name) && namespaces.ContainsKey(name); } - //=================================================================== - // Returns list of assemblies that declare types in a given namespace - //=================================================================== - + /// + /// Returns list of assemblies that declare types in a given namespace + /// public static IEnumerable GetAssemblies(string nsname) { if (!namespaces.ContainsKey(nsname)) @@ -412,10 +402,9 @@ public static IEnumerable GetAssemblies(string nsname) return namespaces[nsname].Keys; } - //=================================================================== - // Returns the current list of valid names for the input namespace. - //=================================================================== - + /// + /// Returns the current list of valid names for the input namespace. + /// public static List GetNames(string nsname) { //Dictionary seen = new Dictionary(); @@ -460,12 +449,11 @@ public static List GetNames(string nsname) return names; } - //=================================================================== - // 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. - //=================================================================== - + /// + /// 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. + /// public static Type LookupType(string qname) { foreach (Assembly assembly in assemblies) @@ -528,8 +516,8 @@ public IEnumerator GetEnumerator() } /// - /// Enumerator wrapping around 's enumerator. - /// Acquires and releases a read lock on during enumeration + /// Enumerator wrapping around 's enumerator. + /// Acquires and releases a read lock on during enumeration /// private class Enumerator : IEnumerator { diff --git a/src/runtime/classbase.cs b/src/runtime/classbase.cs index 7c7bb0509..6ed43689b 100644 --- a/src/runtime/classbase.cs +++ b/src/runtime/classbase.cs @@ -30,19 +30,17 @@ internal virtual bool CanSubclass() return (!this.type.IsEnum); } - //==================================================================== - // Implements __init__ for reflected classes and value types. - //==================================================================== - + /// + /// Implements __init__ for reflected classes and value types. + /// public static int tp_init(IntPtr ob, IntPtr args, IntPtr kw) { return 0; } - //==================================================================== - // Default implementation of [] semantics for reflected types. - //==================================================================== - + /// + /// Default implementation of [] semantics for reflected types. + /// public virtual IntPtr type_subscript(IntPtr idx) { Type[] types = Runtime.PythonArgsToTypeArray(idx); @@ -64,10 +62,9 @@ public virtual IntPtr type_subscript(IntPtr idx) return Exceptions.RaiseTypeError("no type matches params"); } - //==================================================================== - // Standard comparison implementation for instances of reflected types. - //==================================================================== - + /// + /// Standard comparison implementation for instances of reflected types. + /// public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) { CLRObject co1; @@ -173,12 +170,11 @@ public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) } } - //==================================================================== - // Standard iteration support for instances of reflected types. This - // allows natural iteration over objects that either are IEnumerable - // or themselves support IEnumerator directly. - //==================================================================== - + /// + /// Standard iteration support for instances of reflected types. This + /// allows natural iteration over objects that either are IEnumerable + /// or themselves support IEnumerator directly. + /// public static IntPtr tp_iter(IntPtr ob) { CLRObject co = GetManagedObject(ob) as CLRObject; @@ -209,10 +205,9 @@ public static IntPtr tp_iter(IntPtr ob) } - //==================================================================== - // Standard __hash__ implementation for instances of reflected types. - //==================================================================== - + /// + /// Standard __hash__ implementation for instances of reflected types. + /// public static IntPtr tp_hash(IntPtr ob) { CLRObject co = GetManagedObject(ob) as CLRObject; @@ -224,10 +219,9 @@ public static IntPtr tp_hash(IntPtr ob) } - //==================================================================== - // Standard __str__ implementation for instances of reflected types. - //==================================================================== - + /// + /// Standard __str__ implementation for instances of reflected types. + /// public static IntPtr tp_str(IntPtr ob) { CLRObject co = GetManagedObject(ob) as CLRObject; @@ -251,10 +245,9 @@ public static IntPtr tp_str(IntPtr ob) } - //==================================================================== - // Default implementations for required Python GC support. - //==================================================================== - + /// + /// Default implementations for required Python GC support. + /// public static int tp_traverse(IntPtr ob, IntPtr func, IntPtr args) { return 0; @@ -270,10 +263,9 @@ public static int tp_is_gc(IntPtr type) return 1; } - //==================================================================== - // Standard dealloc implementation for instances of reflected types. - //==================================================================== - + /// + /// Standard dealloc implementation for instances of reflected types. + /// public static void tp_dealloc(IntPtr ob) { ManagedType self = GetManagedObject(ob); diff --git a/src/runtime/classderived.cs b/src/runtime/classderived.cs index ea0cbb7e9..c7f60e7af 100644 --- a/src/runtime/classderived.cs +++ b/src/runtime/classderived.cs @@ -16,7 +16,6 @@ namespace Python.Runtime /// Python type objects. Each of those type objects is associated with /// an instance of ClassObject, which provides its implementation. /// - // interface used to idenfity which C# types were dynamically created as python subclasses public interface IPythonDerivedType { @@ -569,13 +568,13 @@ private static ModuleBuilder GetModuleBuilder(string assemblyName, string module // public class PythonDerivedType { - //==================================================================== - // This is the implementaion of the overriden methods in the derived - // type. It looks for a python method with the same name as the method - // on the managed base class and if it exists and isn't the managed - // method binding (ie it has been overriden in the derived python - // class) it calls it, otherwise it calls the base method. - //==================================================================== + /// + /// This is the implementaion of the overriden methods in the derived + /// type. It looks for a python method with the same name as the method + /// on the managed base class and if it exists and isn't the managed + /// method binding (ie it has been overriden in the derived python + /// class) it calls it, otherwise it calls the base method. + /// public static T InvokeMethod(IPythonDerivedType obj, string methodName, string origMethodName, Object[] args) { FieldInfo fi = obj.GetType().GetField("__pyobj__"); diff --git a/src/runtime/classmanager.cs b/src/runtime/classmanager.cs index 2588adf7e..2af783f12 100644 --- a/src/runtime/classmanager.cs +++ b/src/runtime/classmanager.cs @@ -35,11 +35,10 @@ static ClassManager() dtype = typeof(System.MulticastDelegate); } - //==================================================================== - // Return the ClassBase-derived instance that implements a particular - // reflected managed type, creating it if it doesn't yet exist. - //==================================================================== - + /// + /// Return the ClassBase-derived instance that implements a particular + /// reflected managed type, creating it if it doesn't yet exist. + /// internal static ClassBase GetClass(Type type) { ClassBase cb = null; @@ -56,12 +55,11 @@ internal static ClassBase GetClass(Type type) } - //==================================================================== - // Create a new ClassBase-derived instance that implements a reflected - // managed type. The new object will be associated with a generated - // Python type object. - //==================================================================== - + /// + /// Create a new ClassBase-derived instance that implements a reflected + /// managed type. The new object will be associated with a generated + /// Python type object. + /// private static ClassBase CreateClass(Type type) { // Next, select the appropriate managed implementation class. diff --git a/src/runtime/classobject.cs b/src/runtime/classobject.cs index 671f0c8e6..13eab44b0 100644 --- a/src/runtime/classobject.cs +++ b/src/runtime/classobject.cs @@ -26,10 +26,9 @@ internal ClassObject(Type tp) : base(tp) } - //==================================================================== - // Helper to get docstring from reflected constructor info. - //==================================================================== - + /// + /// Helper to get docstring from reflected constructor info. + /// internal IntPtr GetDocString() { MethodBase[] methods = binder.GetMethods(); @@ -44,10 +43,9 @@ internal IntPtr GetDocString() } - //==================================================================== - // Implements __new__ for reflected classes and value types. - //==================================================================== - + /// + /// Implements __new__ for reflected classes and value types. + /// public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { ClassObject self = GetManagedObject(tp) as ClassObject; @@ -108,12 +106,11 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) } - //==================================================================== - // Implementation of [] semantics for reflected types. This exists - // both to implement the Array[int] syntax for creating arrays and - // to support generic name overload resolution using []. - //==================================================================== - + /// + /// Implementation of [] semantics for reflected types. This exists + /// both to implement the Array[int] syntax for creating arrays and + /// to support generic name overload resolution using []. + /// public override IntPtr type_subscript(IntPtr idx) { // If this type is the Array type, the [] means we need to @@ -160,10 +157,9 @@ public override IntPtr type_subscript(IntPtr idx) } - //==================================================================== - // Implements __getitem__ for reflected classes and value types. - //==================================================================== - + /// + /// Implements __getitem__ for reflected classes and value types. + /// public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) { //ManagedType self = GetManagedObject(ob); @@ -208,10 +204,9 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) } - //==================================================================== - // Implements __setitem__ for reflected classes and value types. - //==================================================================== - + /// + /// Implements __setitem__ for reflected classes and value types. + /// public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) { //ManagedType self = GetManagedObject(ob); @@ -289,13 +284,12 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) } - //==================================================================== - // This is a hack. Generally, no managed class is considered callable - // from Python - with the exception of System.Delegate. It is useful - // to be able to call a System.Delegate instance directly, especially - // when working with multicast delegates. - //==================================================================== - + /// + /// This is a hack. Generally, no managed class is considered callable + /// from Python - with the exception of System.Delegate. It is useful + /// to be able to call a System.Delegate instance directly, especially + /// when working with multicast delegates. + /// public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) { //ManagedType self = GetManagedObject(ob); diff --git a/src/runtime/codegenerator.cs b/src/runtime/codegenerator.cs index 527ef418a..d592843cb 100644 --- a/src/runtime/codegenerator.cs +++ b/src/runtime/codegenerator.cs @@ -29,20 +29,18 @@ internal CodeGenerator() mBuilder = aBuilder.DefineDynamicModule("__CodeGenerator_Module"); } - //==================================================================== - // DefineType is a shortcut utility to get a new TypeBuilder. - //==================================================================== - + /// + /// DefineType is a shortcut utility to get a new TypeBuilder. + /// internal TypeBuilder DefineType(string name) { TypeAttributes attrs = TypeAttributes.Public; return mBuilder.DefineType(name, attrs); } - //==================================================================== - // DefineType is a shortcut utility to get a new TypeBuilder. - //==================================================================== - + /// + /// DefineType is a shortcut utility to get a new TypeBuilder. + /// internal TypeBuilder DefineType(string name, Type basetype) { TypeAttributes attrs = TypeAttributes.Public; diff --git a/src/runtime/constructorbinder.cs b/src/runtime/constructorbinder.cs index 837c7ff2e..400a0dd54 100644 --- a/src/runtime/constructorbinder.cs +++ b/src/runtime/constructorbinder.cs @@ -3,14 +3,13 @@ namespace Python.Runtime { - //======================================================================== - // A ConstructorBinder encapsulates information about one or more managed - // constructors, and is responsible for selecting the right constructor - // given a set of Python arguments. This is slightly different than the - // standard MethodBinder because of a difference in invoking constructors - // using reflection (which is seems to be a CLR bug). - //======================================================================== - + /// + /// A ConstructorBinder encapsulates information about one or more managed + /// constructors, and is responsible for selecting the right constructor + /// given a set of Python arguments. This is slightly different than the + /// standard MethodBinder because of a difference in invoking constructors + /// using reflection (which is seems to be a CLR bug). + /// internal class ConstructorBinder : MethodBinder { private Type _containingType = null; @@ -20,15 +19,14 @@ internal ConstructorBinder(Type containingType) : base() _containingType = containingType; } - //==================================================================== - // Constructors get invoked when an instance of a wrapped managed - // class or a subclass of a managed class is created. This differs - // from the MethodBinder implementation in that we return the raw - // result of the constructor rather than wrapping it as a Python - // object - the reason is that only the caller knows the correct - // Python type to use when wrapping the result (may be a subclass). - //==================================================================== - + /// + /// Constructors get invoked when an instance of a wrapped managed + /// class or a subclass of a managed class is created. This differs + /// from the MethodBinder implementation in that we return the raw + /// result of the constructor rather than wrapping it as a Python + /// object - the reason is that only the caller knows the correct + /// Python type to use when wrapping the result (may be a subclass). + /// internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw) { return this.InvokeRaw(inst, args, kw, null); diff --git a/src/runtime/constructorbinding.cs b/src/runtime/constructorbinding.cs index 940650186..6a929eff7 100644 --- a/src/runtime/constructorbinding.cs +++ b/src/runtime/constructorbinding.cs @@ -77,9 +77,9 @@ public static IntPtr tp_descr_get(IntPtr op, IntPtr instance, IntPtr owner) return self.pyHandle; } - //==================================================================== - // Implement explicit overload selection using subscript syntax ([]). - //==================================================================== + /// + /// Implement explicit overload selection using subscript syntax ([]). + /// /// /// ConstructorBinding.GetItem(PyObject *o, PyObject *key) /// Return element of o corresponding to the object key or NULL on failure. @@ -112,10 +112,9 @@ public static IntPtr mp_subscript(IntPtr op, IntPtr key) return boundCtor.pyHandle; } - //==================================================================== - // ConstructorBinding __repr__ implementation [borrowed from MethodObject]. - //==================================================================== - + /// + /// ConstructorBinding __repr__ implementation [borrowed from MethodObject]. + /// public static IntPtr tp_repr(IntPtr ob) { ConstructorBinding self = (ConstructorBinding)GetManagedObject(ob); @@ -140,10 +139,9 @@ public static IntPtr tp_repr(IntPtr ob) return self.repr; } - //==================================================================== - // ConstructorBinding dealloc implementation. - //==================================================================== - + /// + /// ConstructorBinding dealloc implementation. + /// public static new void tp_dealloc(IntPtr ob) { ConstructorBinding self = (ConstructorBinding)GetManagedObject(ob); @@ -207,10 +205,9 @@ public static IntPtr tp_call(IntPtr op, IntPtr args, IntPtr kw) return CLRObject.GetInstHandle(obj, self.pyTypeHndl); } - //==================================================================== - // BoundContructor __repr__ implementation [borrowed from MethodObject]. - //==================================================================== - + /// + /// BoundContructor __repr__ implementation [borrowed from MethodObject]. + /// public static IntPtr tp_repr(IntPtr ob) { BoundContructor self = (BoundContructor)GetManagedObject(ob); @@ -228,10 +225,9 @@ public static IntPtr tp_repr(IntPtr ob) return self.repr; } - //==================================================================== - // ConstructorBinding dealloc implementation. - //==================================================================== - + /// + /// ConstructorBinding dealloc implementation. + /// public static new void tp_dealloc(IntPtr ob) { BoundContructor self = (BoundContructor)GetManagedObject(ob); diff --git a/src/runtime/converter.cs b/src/runtime/converter.cs index 320d6eb58..697d84858 100644 --- a/src/runtime/converter.cs +++ b/src/runtime/converter.cs @@ -7,10 +7,9 @@ namespace Python.Runtime { - //======================================================================== - // Performs data conversions between managed types and Python types. - //======================================================================== - + /// + /// Performs data conversions between managed types and Python types. + /// [SuppressUnmanagedCodeSecurityAttribute()] internal class Converter { @@ -48,10 +47,9 @@ static Converter() } - //==================================================================== - // Given a builtin Python type, return the corresponding CLR type. - //==================================================================== - + /// + /// Given a builtin Python type, return the corresponding CLR type. + /// internal static Type GetTypeByAlias(IntPtr op) { if ((op == Runtime.PyStringType) || @@ -113,12 +111,12 @@ internal static IntPtr GetPythonTypeByAlias(Type op) } - //==================================================================== - // Return a Python object for the given native object, converting - // basic types (string, int, etc.) into equivalent Python objects. - // This always returns a new reference. Note that the System.Decimal - // type has no Python equivalent and converts to a managed instance. - //==================================================================== + /// + /// Return a Python object for the given native object, converting + /// basic types (string, int, etc.) into equivalent Python objects. + /// This always returns a new reference. Note that the System.Decimal + /// type has no Python equivalent and converts to a managed instance. + /// internal static IntPtr ToPython(T value) { return ToPython(value, typeof(T)); @@ -234,11 +232,10 @@ internal static IntPtr ToPython(Object value, Type type) } - //==================================================================== - // In a few situations, we don't have any advisory type information - // when we want to convert an object to Python. - //==================================================================== - + /// + /// In a few situations, we don't have any advisory type information + /// when we want to convert an object to Python. + /// internal static IntPtr ToPythonImplicit(Object value) { if (value == null) @@ -252,11 +249,10 @@ internal static IntPtr ToPythonImplicit(Object value) } - //==================================================================== - // Return a managed object for the given Python object, taking funny - // byref types into account. - //==================================================================== - + /// + /// Return a managed object for the given Python object, taking funny + /// byref types into account. + /// internal static bool ToManaged(IntPtr value, Type type, out object result, bool setError) { @@ -415,10 +411,9 @@ internal static bool ToManagedValue(IntPtr value, Type obType, return ToPrimitive(value, obType, out result, setError); } - //==================================================================== - // Convert a Python value to an instance of a primitive managed type. - //==================================================================== - + /// + /// Convert a Python value to an instance of a primitive managed type. + /// static bool ToPrimitive(IntPtr value, Type obType, out Object result, bool setError) { IntPtr overflow = Exceptions.OverflowError; @@ -826,12 +821,11 @@ static void SetConversionError(IntPtr value, Type target) } - //==================================================================== - // Convert a Python value to a correctly typed managed array instance. - // The Python value must support the Python sequence protocol and the - // items in the sequence must be convertible to the target array type. - //==================================================================== - + /// + /// Convert a Python value to a correctly typed managed array instance. + /// The Python value must support the Python sequence protocol and the + /// items in the sequence must be convertible to the target array type. + /// static bool ToArray(IntPtr value, Type obType, out Object result, bool setError) { Type elementType = obType.GetElementType(); @@ -878,10 +872,9 @@ static bool ToArray(IntPtr value, Type obType, out Object result, bool setError) } - //==================================================================== - // Convert a Python value to a correctly typed managed enum instance. - //==================================================================== - + /// + /// Convert a Python value to a correctly typed managed enum instance. + /// static bool ToEnum(IntPtr value, Type obType, out Object result, bool setError) { Type etype = Enum.GetUnderlyingType(obType); diff --git a/src/runtime/delegatemanager.cs b/src/runtime/delegatemanager.cs index a9e26fb01..0a29b8e13 100644 --- a/src/runtime/delegatemanager.cs +++ b/src/runtime/delegatemanager.cs @@ -33,12 +33,11 @@ public DelegateManager() codeGenerator = new CodeGenerator(); } - //==================================================================== - // Given a true delegate instance, return the PyObject handle of the - // Python object implementing the delegate (or IntPtr.Zero if the - // delegate is not implemented in Python code. - //==================================================================== - + /// + /// Given a true delegate instance, return the PyObject handle of the + /// Python object implementing the delegate (or IntPtr.Zero if the + /// delegate is not implemented in Python code. + /// public IntPtr GetPythonHandle(Delegate d) { if ((d != null) && (d.Target is Dispatcher)) @@ -49,11 +48,10 @@ public IntPtr GetPythonHandle(Delegate d) return IntPtr.Zero; } - //==================================================================== - // GetDispatcher is responsible for creating a class that provides - // an appropriate managed callback method for a given delegate type. - //==================================================================== - + /// + /// GetDispatcher is responsible for creating a class that provides + /// an appropriate managed callback method for a given delegate type. + /// private Type GetDispatcher(Type dtype) { // If a dispatcher type for the given delegate type has already @@ -154,12 +152,11 @@ private Type GetDispatcher(Type dtype) return disp; } - //==================================================================== - // Given a delegate type and a callable Python object, GetDelegate - // returns an instance of the delegate type. The delegate instance - // returned will dispatch calls to the given Python object. - //==================================================================== - + /// + /// Given a delegate type and a callable Python object, GetDelegate + /// returns an instance of the delegate type. The delegate instance + /// returned will dispatch calls to the given Python object. + /// internal Delegate GetDelegate(Type dtype, IntPtr callable) { Type dispatcher = GetDispatcher(dtype); diff --git a/src/runtime/delegateobject.cs b/src/runtime/delegateobject.cs index 2186e98ad..2d305e5f2 100644 --- a/src/runtime/delegateobject.cs +++ b/src/runtime/delegateobject.cs @@ -20,11 +20,10 @@ internal DelegateObject(Type tp) : base(tp) } - //==================================================================== - // Given a PyObject pointer to an instance of a delegate type, return - // the true managed delegate the Python object represents (or null). - //==================================================================== - + /// + /// Given a PyObject pointer to an instance of a delegate type, return + /// the true managed delegate the Python object represents (or null). + /// private static Delegate GetTrueDelegate(IntPtr op) { CLRObject o = GetManagedObject(op) as CLRObject; @@ -43,14 +42,13 @@ internal override bool CanSubclass() } - //==================================================================== - // DelegateObject __new__ implementation. The result of this is a new - // PyObject whose type is DelegateObject and whose ob_data is a handle - // to an actual delegate instance. The method wrapped by the actual - // delegate instance belongs to an object generated to relay the call - // to the Python callable passed in. - //==================================================================== - + /// + /// DelegateObject __new__ implementation. The result of this is a new + /// PyObject whose type is DelegateObject and whose ob_data is a handle + /// to an actual delegate instance. The method wrapped by the actual + /// delegate instance belongs to an object generated to relay the call + /// to the Python callable passed in. + /// public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { DelegateObject self = (DelegateObject)GetManagedObject(tp); @@ -73,10 +71,9 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) } - //==================================================================== - // Implements __call__ for reflected delegate types. - //==================================================================== - + /// + /// Implements __call__ for reflected delegate types. + /// public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) { // todo: add fast type check! @@ -99,9 +96,9 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) } - //==================================================================== - // Implements __cmp__ for reflected delegate types. - //==================================================================== + /// + /// Implements __cmp__ for reflected delegate types. + /// #if PYTHON3 public static new IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) { diff --git a/src/runtime/eventbinding.cs b/src/runtime/eventbinding.cs index 090d812ca..b31286b4c 100644 --- a/src/runtime/eventbinding.cs +++ b/src/runtime/eventbinding.cs @@ -2,10 +2,9 @@ namespace Python.Runtime { - //======================================================================== - // Implements a Python event binding type, similar to a method binding. - //======================================================================== - + /// + /// Implements a Python event binding type, similar to a method binding. + /// internal class EventBinding : ExtensionType { EventObject e; @@ -19,10 +18,9 @@ public EventBinding(EventObject e, IntPtr target) : base() } - //==================================================================== - // EventBinding += operator implementation. - //==================================================================== - + /// + /// EventBinding += operator implementation. + /// public static IntPtr nb_inplace_add(IntPtr ob, IntPtr arg) { EventBinding self = (EventBinding)GetManagedObject(ob); @@ -43,10 +41,9 @@ public static IntPtr nb_inplace_add(IntPtr ob, IntPtr arg) } - //==================================================================== - // EventBinding -= operator implementation. - //==================================================================== - + /// + /// EventBinding -= operator implementation. + /// public static IntPtr nb_inplace_subtract(IntPtr ob, IntPtr arg) { EventBinding self = (EventBinding)GetManagedObject(ob); @@ -67,10 +64,9 @@ public static IntPtr nb_inplace_subtract(IntPtr ob, IntPtr arg) } - //==================================================================== - // EventBinding __hash__ implementation. - //==================================================================== - + /// + /// EventBinding __hash__ implementation. + /// public static IntPtr tp_hash(IntPtr ob) { EventBinding self = (EventBinding)GetManagedObject(ob); @@ -103,10 +99,9 @@ public static IntPtr tp_hash(IntPtr ob) } - //==================================================================== - // EventBinding __repr__ implementation. - //==================================================================== - + /// + /// EventBinding __repr__ implementation. + /// public static IntPtr tp_repr(IntPtr ob) { EventBinding self = (EventBinding)GetManagedObject(ob); @@ -116,10 +111,9 @@ public static IntPtr tp_repr(IntPtr ob) } - //==================================================================== - // EventBinding dealloc implementation. - //==================================================================== - + /// + /// EventBinding dealloc implementation. + /// public static new void tp_dealloc(IntPtr ob) { EventBinding self = (EventBinding)GetManagedObject(ob); diff --git a/src/runtime/eventobject.cs b/src/runtime/eventobject.cs index 191a95546..8ac0ed3ac 100644 --- a/src/runtime/eventobject.cs +++ b/src/runtime/eventobject.cs @@ -4,10 +4,9 @@ namespace Python.Runtime { - //======================================================================== - // Implements a Python descriptor type that provides access to CLR events. - //======================================================================== - + /// + /// Implements a Python descriptor type that provides access to CLR events. + /// internal class EventObject : ExtensionType { internal string name; @@ -22,10 +21,9 @@ public EventObject(EventInfo info) : base() } - //==================================================================== - // Register a new Python object event handler with the event. - //==================================================================== - + /// + /// Register a new Python object event handler with the event. + /// internal bool AddEventHandler(IntPtr target, IntPtr handler) { Object obj = null; @@ -71,10 +69,9 @@ internal bool AddEventHandler(IntPtr target, IntPtr handler) } - //==================================================================== - // Remove the given Python object event handler. - //==================================================================== - + /// + /// Remove the given Python object event handler. + /// internal bool RemoveEventHandler(IntPtr target, IntPtr handler) { Object obj = null; @@ -128,11 +125,10 @@ internal bool RemoveEventHandler(IntPtr target, IntPtr handler) } - //==================================================================== - // Descriptor __get__ implementation. A getattr on an event returns - // a "bound" event that keeps a reference to the object instance. - //==================================================================== - + /// + /// Descriptor __get__ implementation. A getattr on an event returns + /// a "bound" event that keeps a reference to the object instance. + /// public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) { EventObject self = GetManagedObject(ds) as EventObject; @@ -168,14 +164,13 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) } - //==================================================================== - // Descriptor __set__ implementation. This actually never allows you - // to set anything; it exists solely to support the '+=' spelling of - // event handler registration. The reason is that given code like: - // 'ob.SomeEvent += method', Python will attempt to set the attribute - // SomeEvent on ob to the result of the '+=' operation. - //==================================================================== - + /// + /// Descriptor __set__ implementation. This actually never allows you + /// to set anything; it exists solely to support the '+=' spelling of + /// event handler registration. The reason is that given code like: + /// 'ob.SomeEvent += method', Python will attempt to set the attribute + /// SomeEvent on ob to the result of the '+=' operation. + /// public static new int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val) { EventBinding e = GetManagedObject(val) as EventBinding; @@ -191,10 +186,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) } - //==================================================================== - // Descriptor __repr__ implementation. - //==================================================================== - + /// + /// Descriptor __repr__ implementation. + /// public static IntPtr tp_repr(IntPtr ob) { EventObject self = (EventObject)GetManagedObject(ob); @@ -203,10 +197,9 @@ public static IntPtr tp_repr(IntPtr ob) } - //==================================================================== - // Descriptor dealloc implementation. - //==================================================================== - + /// + /// Descriptor dealloc implementation. + /// public static new void tp_dealloc(IntPtr ob) { EventObject self = (EventObject)GetManagedObject(ob); diff --git a/src/runtime/exceptions.cs b/src/runtime/exceptions.cs index 429c09212..448655213 100644 --- a/src/runtime/exceptions.cs +++ b/src/runtime/exceptions.cs @@ -38,10 +38,9 @@ internal static Exception ToException(IntPtr ob) return e; } - //==================================================================== - // Exception __str__ implementation - //==================================================================== - + /// + /// Exception __str__ implementation + /// public new static IntPtr tp_str(IntPtr ob) { Exception e = ToException(ob); @@ -78,10 +77,9 @@ private Exceptions() { } - //=================================================================== - // Initialization performed on startup of the Python runtime. - //=================================================================== - + /// + /// Initialization performed on startup of the Python runtime. + /// internal static void Initialize() { #if PYTHON3 @@ -111,10 +109,9 @@ internal static void Initialize() } - //=================================================================== - // Cleanup resources upon shutdown of the Python runtime. - //=================================================================== - + /// + /// Cleanup resources upon shutdown of the Python runtime. + /// internal static void Shutdown() { if (0 != Runtime.Py_IsInitialized()) diff --git a/src/runtime/extensiontype.cs b/src/runtime/extensiontype.cs index 769904444..a09f57696 100644 --- a/src/runtime/extensiontype.cs +++ b/src/runtime/extensiontype.cs @@ -46,10 +46,9 @@ public ExtensionType() : base() } - //==================================================================== - // Common finalization code to support custom tp_deallocs. - //==================================================================== - + /// + /// Common finalization code to support custom tp_deallocs. + /// public static void FinalizeObject(ManagedType self) { Runtime.PyObject_GC_Del(self.pyHandle); @@ -58,10 +57,9 @@ public static void FinalizeObject(ManagedType self) } - //==================================================================== - // Type __setattr__ implementation. - //==================================================================== - + /// + /// Type __setattr__ implementation. + /// public static int tp_setattro(IntPtr ob, IntPtr key, IntPtr val) { string message = "type does not support setting attributes"; @@ -74,11 +72,10 @@ public static int tp_setattro(IntPtr ob, IntPtr key, IntPtr val) } - //==================================================================== - // Default __set__ implementation - this prevents descriptor instances - // being silently replaced in a type __dict__ by default __setattr__. - //==================================================================== - + /// + /// Default __set__ implementation - this prevents descriptor instances + /// being silently replaced in a type __dict__ by default __setattr__. + /// public static int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val) { string message = "attribute is read-only"; @@ -87,10 +84,9 @@ public static int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val) } - //==================================================================== - // Required Python GC support. - //==================================================================== - + /// + /// Required Python GC support. + /// public static int tp_traverse(IntPtr ob, IntPtr func, IntPtr args) { return 0; @@ -109,10 +105,9 @@ public static int tp_is_gc(IntPtr type) } - //==================================================================== - // Default dealloc implementation. - //==================================================================== - + /// + /// Default dealloc implementation. + /// public static void tp_dealloc(IntPtr ob) { // Clean up a Python instance of this extension type. This diff --git a/src/runtime/fieldobject.cs b/src/runtime/fieldobject.cs index 53597aee7..3d65f5fd3 100644 --- a/src/runtime/fieldobject.cs +++ b/src/runtime/fieldobject.cs @@ -5,10 +5,9 @@ namespace Python.Runtime { - //======================================================================== - // Implements a Python descriptor type that provides access to CLR fields. - //======================================================================== - + /// + /// Implements a Python descriptor type that provides access to CLR fields. + /// internal class FieldObject : ExtensionType { FieldInfo info; @@ -18,12 +17,11 @@ public FieldObject(FieldInfo info) : base() this.info = info; } - //==================================================================== - // Descriptor __get__ implementation. This method returns the - // value of the field on the given object. The returned value - // is converted to an appropriately typed Python object. - //==================================================================== - + /// + /// Descriptor __get__ implementation. This method returns the + /// value of the field on the given object. The returned value + /// is converted to an appropriately typed Python object. + /// public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) { FieldObject self = (FieldObject)GetManagedObject(ds); @@ -69,12 +67,11 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) } } - //==================================================================== - // Descriptor __set__ implementation. This method sets the value of - // a field based on the given Python value. The Python value must be - // convertible to the type of the field. - //==================================================================== - + /// + /// Descriptor __set__ implementation. This method sets the value of + /// a field based on the given Python value. The Python value must be + /// convertible to the type of the field. + /// public static new int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val) { FieldObject self = (FieldObject)GetManagedObject(ds); @@ -136,10 +133,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) } } - //==================================================================== - // Descriptor __repr__ implementation. - //==================================================================== - + /// + /// Descriptor __repr__ implementation. + /// public static IntPtr tp_repr(IntPtr ob) { FieldObject self = (FieldObject)GetManagedObject(ob); diff --git a/src/runtime/generictype.cs b/src/runtime/generictype.cs index 19cde37bf..761efc045 100644 --- a/src/runtime/generictype.cs +++ b/src/runtime/generictype.cs @@ -15,10 +15,9 @@ internal GenericType(Type tp) : base(tp) { } - //==================================================================== - // Implements __new__ for reflected generic types. - //==================================================================== - + /// + /// Implements __new__ for reflected generic types. + /// public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { Exceptions.SetError(Exceptions.TypeError, "cannot instantiate an open generic type"); @@ -26,10 +25,9 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) } - //==================================================================== - // Implements __call__ for reflected generic types. - //==================================================================== - + /// + /// Implements __call__ for reflected generic types. + /// public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) { Exceptions.SetError(Exceptions.TypeError, "object is not callable"); diff --git a/src/runtime/genericutil.cs b/src/runtime/genericutil.cs index 9870b2a5b..6568ac438 100644 --- a/src/runtime/genericutil.cs +++ b/src/runtime/genericutil.cs @@ -24,10 +24,9 @@ static GenericUtil() mapping = new Dictionary>>(); } - //==================================================================== - // Register a generic type that appears in a given namespace. - //==================================================================== - + /// + /// Register a generic type that appears in a given namespace. + /// internal static void Register(Type t) { if (null == t.Namespace || null == t.Name) @@ -56,10 +55,9 @@ internal static void Register(Type t) gnames.Add(t.Name); } - //==================================================================== - // xxx - //==================================================================== - + /// + /// xxx + /// public static List GetGenericBaseNames(string ns) { Dictionary> nsmap = null; @@ -76,10 +74,9 @@ public static List GetGenericBaseNames(string ns) return names; } - //==================================================================== - // xxx - //==================================================================== - + /// + /// xxx + /// public static Type GenericForType(Type t, int paramCount) { return GenericByName(t.Namespace, t.Name, paramCount); @@ -136,10 +133,9 @@ public static List GenericsByName(string ns, string basename) return result; } - //==================================================================== - // xxx - //==================================================================== - + /// + /// xxx + /// public static string GenericNameForBaseName(string ns, string name) { Dictionary> nsmap = null; diff --git a/src/runtime/importhook.cs b/src/runtime/importhook.cs index 851bf49d7..68d81ac14 100644 --- a/src/runtime/importhook.cs +++ b/src/runtime/importhook.cs @@ -4,10 +4,9 @@ namespace Python.Runtime { - //======================================================================== - // Implements the "import hook" used to integrate Python with the CLR. - //======================================================================== - + /// + /// Implements the "import hook" used to integrate Python with the CLR. + /// internal class ImportHook { static IntPtr py_import; @@ -25,10 +24,9 @@ internal static void InitializeModuleDef() } #endif - //=================================================================== - // Initialization performed on startup of the Python runtime. - //=================================================================== - + /// + /// Initialization performed on startup of the Python runtime. + /// internal static void Initialize() { // Initialize the Python <--> CLR module hook. We replace the @@ -70,10 +68,9 @@ internal static void Initialize() } - //=================================================================== - // Cleanup resources upon shutdown of the Python runtime. - //=================================================================== - + /// + /// Cleanup resources upon shutdown of the Python runtime. + /// internal static void Shutdown() { if (0 != Runtime.Py_IsInitialized()) @@ -88,9 +85,9 @@ internal static void Shutdown() } } - //=================================================================== - // Return the clr python module (new reference) - //=================================================================== + /// + /// Return the clr python module (new reference) + /// public static IntPtr GetCLRModule(IntPtr? fromList = null) { root.InitializePreload(); @@ -146,10 +143,9 @@ public static IntPtr GetCLRModule(IntPtr? fromList = null) #endif } - //=================================================================== - // The actual import hook that ties Python to the managed world. - //=================================================================== - + /// + /// The actual import hook that ties Python to the managed world. + /// public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { // Replacement for the builtin __import__. The original import diff --git a/src/runtime/indexer.cs b/src/runtime/indexer.cs index 06355c9f7..7f0b6fe10 100644 --- a/src/runtime/indexer.cs +++ b/src/runtime/indexer.cs @@ -5,10 +5,9 @@ namespace Python.Runtime { - //======================================================================== - // Bundles the information required to support an indexer property. - //======================================================================== - + /// + /// Bundles the information required to support an indexer property. + /// internal class Indexer { public MethodBinder GetterBinder; @@ -81,7 +80,7 @@ internal bool NeedsDefaultArgs(IntPtr args) /// /// This will return default arguments a new instance of a tuple. The size - /// of the tuple will indicate the number of default arguments. + /// of the tuple will indicate the number of default arguments. /// /// This is pointing to the tuple args passed in /// a new instance of the tuple containing the default args diff --git a/src/runtime/interfaceobject.cs b/src/runtime/interfaceobject.cs index 076ecc727..8e64c24d7 100644 --- a/src/runtime/interfaceobject.cs +++ b/src/runtime/interfaceobject.cs @@ -30,10 +30,9 @@ static InterfaceObject() cc_attr = typeof(CoClassAttribute); } - //==================================================================== - // Implements __new__ for reflected interface types. - //==================================================================== - + /// + /// Implements __new__ for reflected interface types. + /// public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { InterfaceObject self = (InterfaceObject)GetManagedObject(tp); diff --git a/src/runtime/interop.cs b/src/runtime/interop.cs index 9be8169d2..148ca2d2c 100644 --- a/src/runtime/interop.cs +++ b/src/runtime/interop.cs @@ -7,12 +7,11 @@ namespace Python.Runtime { - //======================================================================= - // This file defines objects to support binary interop with the Python - // runtime. Generally, the definitions here need to be kept up to date - // when moving to new Python versions. - //======================================================================= - + /// + /// This file defines objects to support binary interop with the Python + /// runtime. Generally, the definitions here need to be kept up to date + /// when moving to new Python versions. + /// [Serializable()] [AttributeUsage(AttributeTargets.All)] public class DocStringAttribute : Attribute diff --git a/src/runtime/iterator.cs b/src/runtime/iterator.cs index dcab722f1..f2a32deb4 100644 --- a/src/runtime/iterator.cs +++ b/src/runtime/iterator.cs @@ -4,11 +4,10 @@ namespace Python.Runtime { - //======================================================================== - // Implements a generic Python iterator for IEnumerable objects and - // managed array objects. This supports 'for i in object:' in Python. - //======================================================================== - + /// + /// Implements a generic Python iterator for IEnumerable objects and + /// managed array objects. This supports 'for i in object:' in Python. + /// internal class Iterator : ExtensionType { IEnumerator iter; @@ -19,10 +18,9 @@ public Iterator(IEnumerator e) : base() } - //==================================================================== - // Implements support for the Python iteration protocol. - //==================================================================== - + /// + /// Implements support for the Python iteration protocol. + /// public static IntPtr tp_iternext(IntPtr ob) { Iterator self = GetManagedObject(ob) as Iterator; diff --git a/src/runtime/managedtype.cs b/src/runtime/managedtype.cs index ebb2057b9..0d46f2366 100644 --- a/src/runtime/managedtype.cs +++ b/src/runtime/managedtype.cs @@ -5,12 +5,11 @@ namespace Python.Runtime { - //======================================================================== - // Common base class for all objects that are implemented in managed - // code. It defines the common fields that associate CLR and Python - // objects and common utilities to convert between those identities. - //======================================================================== - + /// + /// Common base class for all objects that are implemented in managed + /// code. It defines the common fields that associate CLR and Python + /// objects and common utilities to convert between those identities. + /// internal abstract class ManagedType { internal GCHandle gcHandle; // Native handle @@ -18,10 +17,9 @@ internal abstract class ManagedType internal IntPtr tpHandle; // PyType * - //==================================================================== - // Given a Python object, return the associated managed object or null. - //==================================================================== - + /// + /// Given a Python object, return the associated managed object or null. + /// internal static ManagedType GetManagedObject(IntPtr ob) { if (ob != IntPtr.Zero) diff --git a/src/runtime/metatype.cs b/src/runtime/metatype.cs index b1761c2d7..6701a2a07 100644 --- a/src/runtime/metatype.cs +++ b/src/runtime/metatype.cs @@ -5,21 +5,19 @@ namespace Python.Runtime { - //======================================================================== - // The managed metatype. This object implements the type of all reflected - // types. It also provides support for single-inheritance from reflected - // managed types. - //======================================================================== - + /// + /// The managed metatype. This object implements the type of all reflected + /// types. It also provides support for single-inheritance from reflected + /// managed types. + /// internal class MetaType : ManagedType { static IntPtr PyCLRMetaType; - //==================================================================== - // Metatype initialization. This bootstraps the CLR metatype to life. - //==================================================================== - + /// + /// Metatype initialization. This bootstraps the CLR metatype to life. + /// public static IntPtr Initialize() { PyCLRMetaType = TypeManager.CreateMetaType(typeof(MetaType)); @@ -27,11 +25,10 @@ public static IntPtr Initialize() } - //==================================================================== - // Metatype __new__ implementation. This is called to create a new - // class / type when a reflected class is subclassed. - //==================================================================== - + /// + /// Metatype __new__ implementation. This is called to create a new + /// class / type when a reflected class is subclassed. + /// public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { int len = Runtime.PyTuple_Size(args); @@ -141,12 +138,11 @@ public static void tp_free(IntPtr tp) } - //==================================================================== - // Metatype __call__ implementation. This is needed to ensure correct - // initialization (__init__ support), because the tp_call we inherit - // from PyType_Type won't call __init__ for metatypes it doesnt know. - //==================================================================== - + /// + /// Metatype __call__ implementation. This is needed to ensure correct + /// initialization (__init__ support), because the tp_call we inherit + /// from PyType_Type won't call __init__ for metatypes it doesnt know. + /// public static IntPtr tp_call(IntPtr tp, IntPtr args, IntPtr kw) { IntPtr func = Marshal.ReadIntPtr(tp, TypeOffset.tp_new); @@ -192,14 +188,13 @@ public static IntPtr tp_call(IntPtr tp, IntPtr args, IntPtr kw) } - //==================================================================== - // Type __setattr__ implementation for reflected types. Note that this - // is slightly different than the standard setattr implementation for - // the normal Python metatype (PyTypeType). We need to look first in - // the type object of a reflected type for a descriptor in order to - // support the right setattr behavior for static fields and properties. - //==================================================================== - + /// + /// Type __setattr__ implementation for reflected types. Note that this + /// is slightly different than the standard setattr implementation for + /// the normal Python metatype (PyTypeType). We need to look first in + /// the type object of a reflected type for a descriptor in order to + /// support the right setattr behavior for static fields and properties. + /// public static int tp_setattro(IntPtr tp, IntPtr name, IntPtr value) { IntPtr descr = Runtime._PyType_Lookup(tp, name); @@ -232,11 +227,11 @@ public static int tp_setattro(IntPtr tp, IntPtr name, IntPtr value) return res; } - //==================================================================== - // The metatype has to implement [] semantics for generic types, so - // here we just delegate to the generic type def implementation. Its - // own mp_subscript - //==================================================================== + /// + /// The metatype has to implement [] semantics for generic types, so + /// here we just delegate to the generic type def implementation. Its + /// own mp_subscript + /// public static IntPtr mp_subscript(IntPtr tp, IntPtr idx) { ClassBase cb = GetManagedObject(tp) as ClassBase; @@ -247,11 +242,10 @@ public static IntPtr mp_subscript(IntPtr tp, IntPtr idx) return Exceptions.RaiseTypeError("unsubscriptable object"); } - //==================================================================== - // Dealloc implementation. This is called when a Python type generated - // by this metatype is no longer referenced from the Python runtime. - //==================================================================== - + /// + /// Dealloc implementation. This is called when a Python type generated + /// by this metatype is no longer referenced from the Python runtime. + /// public static void tp_dealloc(IntPtr tp) { // Fix this when we dont cheat on the handle for subclasses! diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index c4d41d156..651791599 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -4,13 +4,12 @@ namespace Python.Runtime { - //======================================================================== - // A MethodBinder encapsulates information about a (possibly overloaded) - // managed method, and is responsible for selecting the right method given - // a set of Python arguments. This is also used as a base class for the - // ConstructorBinder, a minor variation used to invoke constructors. - //======================================================================== - + /// + /// A MethodBinder encapsulates information about a (possibly overloaded) + /// managed method, and is responsible for selecting the right method given + /// a set of Python arguments. This is also used as a base class for the + /// ConstructorBinder, a minor variation used to invoke constructors. + /// internal class MethodBinder { public ArrayList list; @@ -39,11 +38,10 @@ internal void AddMethod(MethodBase m) this.list.Add(m); } - //==================================================================== - // Given a sequence of MethodInfo and a sequence of types, return the - // MethodInfo that matches the signature represented by those types. - //==================================================================== - + /// + /// Given a sequence of MethodInfo and a sequence of types, return the + /// MethodInfo that matches the signature represented by those types. + /// internal static MethodInfo MatchSignature(MethodInfo[] mi, Type[] tp) { if (tp == null) @@ -73,11 +71,10 @@ internal static MethodInfo MatchSignature(MethodInfo[] mi, Type[] tp) return null; } - //==================================================================== - // Given a sequence of MethodInfo and a sequence of type parameters, - // return the MethodInfo that represents the matching closed generic. - //==================================================================== - + /// + /// Given a sequence of MethodInfo and a sequence of type parameters, + /// return the MethodInfo that represents the matching closed generic. + /// internal static MethodInfo MatchParameters(MethodInfo[] mi, Type[] tp) { if (tp == null) @@ -102,11 +99,10 @@ internal static MethodInfo MatchParameters(MethodInfo[] mi, Type[] tp) } - //==================================================================== - // Given a sequence of MethodInfo and two sequences of type parameters, - // return the MethodInfo that matches the signature and the closed generic. - //==================================================================== - + /// + /// Given a sequence of MethodInfo and two sequences of type parameters, + /// return the MethodInfo that matches the signature and the closed generic. + /// internal static MethodInfo MatchSignatureAndParameters(MethodInfo[] mi, Type[] genericTp, Type[] sigTp) { if ((genericTp == null) || (sigTp == null)) @@ -153,12 +149,11 @@ internal static MethodInfo MatchSignatureAndParameters(MethodInfo[] mi, Type[] g } - //==================================================================== - // Return the array of MethodInfo for this method. The result array - // is arranged in order of precendence (done lazily to avoid doing it - // at all for methods that are never called). - //==================================================================== - + /// + /// Return the array of MethodInfo for this method. The result array + /// is arranged in order of precendence (done lazily to avoid doing it + /// at all for methods that are never called). + /// internal MethodBase[] GetMethods() { if (!init) @@ -171,11 +166,10 @@ internal MethodBase[] GetMethods() return methods; } - //==================================================================== - // Precedence algorithm largely lifted from jython - the concerns are - // generally the same so we'll start w/this and tweak as necessary. - //==================================================================== - + /// + /// Precedence algorithm largely lifted from jython - the concerns are + /// generally the same so we'll start w/this and tweak as necessary. + /// internal static int GetPrecedence(MethodBase mi) { ParameterInfo[] pi = mi.GetParameters(); @@ -191,10 +185,9 @@ internal static int GetPrecedence(MethodBase mi) return val; } - //==================================================================== - // Return a precedence value for a particular Type object. - //==================================================================== - + /// + /// Return a precedence value for a particular Type object. + /// internal static int ArgPrecedence(Type t) { Type objectType = typeof(Object); @@ -242,12 +235,11 @@ internal static int ArgPrecedence(Type t) return 2000; } - //==================================================================== - // Bind the given Python instance and arguments to a particular method - // overload and return a structure that contains the converted Python - // instance, converted arguments and the correct method to call. - //==================================================================== - + /// + /// Bind the given Python instance and arguments to a particular method + /// overload and return a structure that contains the converted Python + /// instance, converted arguments and the correct method to call. + /// internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw) { return this.Bind(inst, args, kw, null, null); @@ -567,10 +559,9 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i } - //======================================================================== - // Utility class to sort method info by parameter type precedence. - //======================================================================== - + /// + /// Utility class to sort method info by parameter type precedence. + /// internal class MethodSorter : IComparer { int IComparer.Compare(Object m1, Object m2) @@ -586,12 +577,11 @@ int IComparer.Compare(Object m1, Object m2) } - //======================================================================== - // A Binding is a utility instance that bundles together a MethodInfo - // representing a method to call, a (possibly null) target instance for - // the call, and the arguments for the call (all as managed values). - //======================================================================== - + /// + /// A Binding is a utility instance that bundles together a MethodInfo + /// representing a method to call, a (possibly null) target instance for + /// the call, and the arguments for the call (all as managed values). + /// internal class Binding { public MethodBase info; diff --git a/src/runtime/methodbinding.cs b/src/runtime/methodbinding.cs index 9d328381f..878779989 100644 --- a/src/runtime/methodbinding.cs +++ b/src/runtime/methodbinding.cs @@ -4,12 +4,11 @@ namespace Python.Runtime { - //======================================================================== - // Implements a Python binding type for CLR methods. These work much like - // standard Python method bindings, but the same type is used to bind - // both static and instance methods. - //======================================================================== - + /// + /// Implements a Python binding type for CLR methods. These work much like + /// standard Python method bindings, but the same type is used to bind + /// both static and instance methods. + /// internal class MethodBinding : ExtensionType { internal MethodInfo info; @@ -35,10 +34,9 @@ public MethodBinding(MethodObject m, IntPtr target) : this(m, target, IntPtr.Zer { } - //==================================================================== - // Implement binding of generic methods using the subscript syntax []. - //==================================================================== - + /// + /// Implement binding of generic methods using the subscript syntax []. + /// public static IntPtr mp_subscript(IntPtr tp, IntPtr idx) { MethodBinding self = (MethodBinding)GetManagedObject(tp); @@ -63,10 +61,9 @@ public static IntPtr mp_subscript(IntPtr tp, IntPtr idx) } - //==================================================================== - // MethodBinding __getattribute__ implementation. - //==================================================================== - + /// + /// MethodBinding __getattribute__ implementation. + /// public static IntPtr tp_getattro(IntPtr ob, IntPtr key) { MethodBinding self = (MethodBinding)GetManagedObject(ob); @@ -97,10 +94,9 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) } - //==================================================================== - // MethodBinding __call__ implementation. - //==================================================================== - + /// + /// MethodBinding __call__ implementation. + /// public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) { MethodBinding self = (MethodBinding)GetManagedObject(ob); @@ -187,10 +183,9 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) } - //==================================================================== - // MethodBinding __hash__ implementation. - //==================================================================== - + /// + /// MethodBinding __hash__ implementation. + /// public static IntPtr tp_hash(IntPtr ob) { MethodBinding self = (MethodBinding)GetManagedObject(ob); @@ -222,10 +217,9 @@ public static IntPtr tp_hash(IntPtr ob) return new IntPtr(x); } - //==================================================================== - // MethodBinding __repr__ implementation. - //==================================================================== - + /// + /// MethodBinding __repr__ implementation. + /// public static IntPtr tp_repr(IntPtr ob) { MethodBinding self = (MethodBinding)GetManagedObject(ob); @@ -234,10 +228,9 @@ public static IntPtr tp_repr(IntPtr ob) return Runtime.PyString_FromStringAndSize(s, s.Length); } - //==================================================================== - // MethodBinding dealloc implementation. - //==================================================================== - + /// + /// MethodBinding dealloc implementation. + /// public static new void tp_dealloc(IntPtr ob) { MethodBinding self = (MethodBinding)GetManagedObject(ob); diff --git a/src/runtime/methodobject.cs b/src/runtime/methodobject.cs index b3e1a66c5..d30188d44 100644 --- a/src/runtime/methodobject.cs +++ b/src/runtime/methodobject.cs @@ -4,12 +4,13 @@ namespace Python.Runtime { - //======================================================================== - // Implements a Python type that represents a CLR method. Method objects - // support a subscript syntax [] to allow explicit overload selection. - //======================================================================== - // TODO: ForbidPythonThreadsAttribute per method info - + /// + /// Implements a Python type that represents a CLR method. Method objects + /// support a subscript syntax [] to allow explicit overload selection. + /// + /// + /// TODO: ForbidPythonThreadsAttribute per method info + /// internal class MethodObject : ExtensionType { internal MethodInfo[] info; @@ -58,10 +59,9 @@ public virtual IntPtr Invoke(IntPtr target, IntPtr args, IntPtr kw, MethodBase i return binder.Invoke(target, args, kw, info, this.info); } - //==================================================================== - // Helper to get docstrings from reflected method / param info. - //==================================================================== - + /// + /// Helper to get docstrings from reflected method / param info. + /// internal IntPtr GetDocString() { if (doc != IntPtr.Zero) @@ -91,28 +91,27 @@ internal IntPtr GetDocString() } - //==================================================================== - // This is a little tricky: a class can actually have a static method - // and instance methods all with the same name. That makes it tough - // to support calling a method 'unbound' (passing the instance as the - // first argument), because in this case we can't know whether to call - // the instance method unbound or call the static method. - // - // The rule we is that if there are both instance and static methods - // with the same name, then we always call the static method. So this - // method returns true if any of the methods that are represented by - // the descriptor are static methods (called by MethodBinding). - //==================================================================== - + /// + /// This is a little tricky: a class can actually have a static method + /// and instance methods all with the same name. That makes it tough + /// to support calling a method 'unbound' (passing the instance as the + /// first argument), because in this case we can't know whether to call + /// the instance method unbound or call the static method. + /// + /// + /// The rule we is that if there are both instance and static methods + /// with the same name, then we always call the static method. So this + /// method returns true if any of the methods that are represented by + /// the descriptor are static methods (called by MethodBinding). + /// internal bool IsStatic() { return this.is_static; } - //==================================================================== - // Descriptor __getattribute__ implementation. - //==================================================================== - + /// + /// Descriptor __getattribute__ implementation. + /// public static IntPtr tp_getattro(IntPtr ob, IntPtr key) { MethodObject self = (MethodObject)GetManagedObject(ob); @@ -133,11 +132,10 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) return Runtime.PyObject_GenericGetAttr(ob, key); } - //==================================================================== - // Descriptor __get__ implementation. Accessing a CLR method returns - // a "bound" method similar to a Python bound method. - //==================================================================== - + /// + /// Descriptor __get__ implementation. Accessing a CLR method returns + /// a "bound" method similar to a Python bound method. + /// public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) { MethodObject self = (MethodObject)GetManagedObject(ds); @@ -183,10 +181,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) return binding.pyHandle; } - //==================================================================== - // Descriptor __repr__ implementation. - //==================================================================== - + /// + /// Descriptor __repr__ implementation. + /// public static IntPtr tp_repr(IntPtr ob) { MethodObject self = (MethodObject)GetManagedObject(ob); @@ -194,10 +191,9 @@ public static IntPtr tp_repr(IntPtr ob) return Runtime.PyString_FromStringAndSize(s, s.Length); } - //==================================================================== - // Descriptor dealloc implementation. - //==================================================================== - + /// + /// Descriptor dealloc implementation. + /// public static new void tp_dealloc(IntPtr ob) { MethodObject self = (MethodObject)GetManagedObject(ob); diff --git a/src/runtime/modulefunctionobject.cs b/src/runtime/modulefunctionobject.cs index 667b37fe9..b6f2899d8 100644 --- a/src/runtime/modulefunctionobject.cs +++ b/src/runtime/modulefunctionobject.cs @@ -22,20 +22,18 @@ public ModuleFunctionObject(Type type, string name, MethodInfo[] info, bool allo } } - //==================================================================== - // __call__ implementation. - //==================================================================== - + /// + /// __call__ implementation. + /// public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) { ModuleFunctionObject self = (ModuleFunctionObject)GetManagedObject(ob); return self.Invoke(ob, args, kw); } - //==================================================================== - // __repr__ implementation. - //==================================================================== - + /// + /// __repr__ implementation. + /// public static new IntPtr tp_repr(IntPtr ob) { ModuleFunctionObject self = (ModuleFunctionObject)GetManagedObject(ob); diff --git a/src/runtime/moduleobject.cs b/src/runtime/moduleobject.cs index c4fec976b..3b9ad94a9 100644 --- a/src/runtime/moduleobject.cs +++ b/src/runtime/moduleobject.cs @@ -7,11 +7,10 @@ namespace Python.Runtime { - //======================================================================== - // Implements a Python type that provides access to CLR namespaces. The - // type behaves like a Python module, and can contain other sub-modules. - //======================================================================== - + /// + /// Implements a Python type that provides access to CLR namespaces. The + /// type behaves like a Python module, and can contain other sub-modules. + /// internal class ModuleObject : ExtensionType { Dictionary cache; @@ -61,13 +60,12 @@ public ModuleObject(string name) : base() } - //=================================================================== - // Returns a ClassBase object representing a type that appears in - // this module's namespace or a ModuleObject representing a child - // namespace (or null if the name is not found). This method does - // not increment the Python refcount of the returned object. - //=================================================================== - + /// + /// Returns a ClassBase object representing a type that appears in + /// this module's namespace or a ModuleObject representing a child + /// namespace (or null if the name is not found). This method does + /// not increment the Python refcount of the returned object. + /// public ManagedType GetAttribute(string name, bool guess) { ManagedType cached = null; @@ -175,10 +173,9 @@ public ManagedType GetAttribute(string name, bool guess) } - //=================================================================== - // Stores an attribute in the instance dict for future lookups. - //=================================================================== - + /// + /// Stores an attribute in the instance dict for future lookups. + /// private void StoreAttribute(string name, ManagedType ob) { Runtime.PyDict_SetItemString(dict, name, ob.pyHandle); @@ -186,12 +183,11 @@ private void StoreAttribute(string name, ManagedType ob) } - //=================================================================== - // Preloads all currently-known names for the module namespace. This - // can be called multiple times, to add names from assemblies that - // may have been loaded since the last call to the method. - //=================================================================== - + /// + /// Preloads all currently-known names for the module namespace. This + /// can be called multiple times, to add names from assemblies that + /// may have been loaded since the last call to the method. + /// public void LoadNames() { ManagedType m = null; @@ -253,13 +249,12 @@ internal void InitializeModuleMembers() } - //==================================================================== - // ModuleObject __getattribute__ implementation. Module attributes - // are always either classes or sub-modules representing subordinate - // namespaces. CLR modules implement a lazy pattern - the sub-modules - // and classes are created when accessed and cached for future use. - //==================================================================== - + /// + /// ModuleObject __getattribute__ implementation. Module attributes + /// are always either classes or sub-modules representing subordinate + /// namespaces. CLR modules implement a lazy pattern - the sub-modules + /// and classes are created when accessed and cached for future use. + /// public static IntPtr tp_getattro(IntPtr ob, IntPtr key) { ModuleObject self = (ModuleObject)GetManagedObject(ob); @@ -296,10 +291,9 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) return attr.pyHandle; } - //==================================================================== - // ModuleObject __repr__ implementation. - //==================================================================== - + /// + /// ModuleObject __repr__ implementation. + /// public static IntPtr tp_repr(IntPtr ob) { ModuleObject self = (ModuleObject)GetManagedObject(ob); diff --git a/src/runtime/overload.cs b/src/runtime/overload.cs index e7d548a23..a183863d6 100644 --- a/src/runtime/overload.cs +++ b/src/runtime/overload.cs @@ -3,11 +3,10 @@ namespace Python.Runtime { - //======================================================================== - // Implements the __overloads__ attribute of method objects. This object - // supports the [] syntax to explicitly select an overload by signature. - //======================================================================== - + /// + /// Implements the __overloads__ attribute of method objects. This object + /// supports the [] syntax to explicitly select an overload by signature. + /// internal class OverloadMapper : ExtensionType { MethodObject m; @@ -20,10 +19,9 @@ public OverloadMapper(MethodObject m, IntPtr target) : base() this.m = m; } - //==================================================================== - // Implement explicit overload selection using subscript syntax ([]). - //==================================================================== - + /// + /// Implement explicit overload selection using subscript syntax ([]). + /// public static IntPtr mp_subscript(IntPtr tp, IntPtr idx) { OverloadMapper self = (OverloadMapper)GetManagedObject(tp); @@ -51,10 +49,9 @@ public static IntPtr mp_subscript(IntPtr tp, IntPtr idx) return mb.pyHandle; } - //==================================================================== - // OverloadMapper __repr__ implementation. - //==================================================================== - + /// + /// OverloadMapper __repr__ implementation. + /// public static IntPtr tp_repr(IntPtr op) { OverloadMapper self = (OverloadMapper)GetManagedObject(op); @@ -63,10 +60,9 @@ public static IntPtr tp_repr(IntPtr op) return doc; } - //==================================================================== - // OverloadMapper dealloc implementation. - //==================================================================== - + /// + /// OverloadMapper dealloc implementation. + /// public static new void tp_dealloc(IntPtr ob) { OverloadMapper self = (OverloadMapper)GetManagedObject(ob); diff --git a/src/runtime/propertyobject.cs b/src/runtime/propertyobject.cs index bfb70899f..ea029cc91 100644 --- a/src/runtime/propertyobject.cs +++ b/src/runtime/propertyobject.cs @@ -5,10 +5,9 @@ namespace Python.Runtime { - //======================================================================== - // Implements a Python descriptor type that manages CLR properties. - //======================================================================== - + /// + /// Implements a Python descriptor type that manages CLR properties. + /// internal class PropertyObject : ExtensionType { PropertyInfo info; @@ -24,12 +23,11 @@ public PropertyObject(PropertyInfo md) : base() } - //==================================================================== - // Descriptor __get__ implementation. This method returns the - // value of the property on the given object. The returned value - // is converted to an appropriately typed Python object. - //==================================================================== - + /// + /// Descriptor __get__ implementation. This method returns the + /// value of the property on the given object. The returned value + /// is converted to an appropriately typed Python object. + /// public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) { PropertyObject self = (PropertyObject)GetManagedObject(ds); @@ -85,12 +83,11 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) } - //==================================================================== - // Descriptor __set__ implementation. This method sets the value of - // a property based on the given Python value. The Python value must - // be convertible to the type of the property. - //==================================================================== - + /// + /// Descriptor __set__ implementation. This method sets the value of + /// a property based on the given Python value. The Python value must + /// be convertible to the type of the property. + /// public static new int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val) { PropertyObject self = (PropertyObject)GetManagedObject(ds); @@ -156,10 +153,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) } - //==================================================================== - // Descriptor __repr__ implementation. - //==================================================================== - + /// + /// Descriptor __repr__ implementation. + /// public static IntPtr tp_repr(IntPtr ob) { PropertyObject self = (PropertyObject)GetManagedObject(ob); diff --git a/src/runtime/pyansistring.cs b/src/runtime/pyansistring.cs index 71dec3362..d15961ee3 100644 --- a/src/runtime/pyansistring.cs +++ b/src/runtime/pyansistring.cs @@ -7,7 +7,6 @@ public class PyAnsiString : PySequence /// /// PyAnsiString Constructor /// - /// /// /// Creates a new PyAnsiString from an existing object reference. Note /// that the instance assumes ownership of the object reference. @@ -21,7 +20,6 @@ public PyAnsiString(IntPtr ptr) : base(ptr) /// /// PyString Constructor /// - /// /// /// Copy constructor - obtain a PyAnsiString from a generic PyObject. /// An ArgumentException will be thrown if the given object is not @@ -41,7 +39,6 @@ public PyAnsiString(PyObject o) : base() /// /// PyAnsiString Constructor /// - /// /// /// Creates a Python string from a managed string. /// @@ -58,7 +55,6 @@ public PyAnsiString(string s) : base() /// /// IsStringType Method /// - /// /// /// Returns true if the given object is a Python string. /// diff --git a/src/runtime/pydict.cs b/src/runtime/pydict.cs index 0d1449862..1672df4fe 100644 --- a/src/runtime/pydict.cs +++ b/src/runtime/pydict.cs @@ -12,7 +12,6 @@ public class PyDict : PyObject /// /// PyDict Constructor /// - /// /// /// Creates a new PyDict from an existing object reference. Note /// that the instance assumes ownership of the object reference. @@ -26,7 +25,6 @@ public PyDict(IntPtr ptr) : base(ptr) /// /// PyDict Constructor /// - /// /// /// Creates a new Python dictionary object. /// @@ -43,7 +41,6 @@ public PyDict() : base() /// /// PyDict Constructor /// - /// /// /// Copy constructor - obtain a PyDict from a generic PyObject. An /// ArgumentException will be thrown if the given object is not a @@ -63,7 +60,6 @@ public PyDict(PyObject o) : base() /// /// IsDictType Method /// - /// /// /// Returns true if the given object is a Python dictionary. /// @@ -76,7 +72,6 @@ public static bool IsDictType(PyObject value) /// /// HasKey Method /// - /// /// /// Returns true if the object key appears in the dictionary. /// @@ -89,7 +84,6 @@ public bool HasKey(PyObject key) /// /// HasKey Method /// - /// /// /// Returns true if the string key appears in the dictionary. /// @@ -103,7 +97,6 @@ public bool HasKey(string key) /// /// Keys Method /// - /// /// /// Returns a sequence containing the keys of the dictionary. /// @@ -121,7 +114,6 @@ public PyObject Keys() /// /// Values Method /// - /// /// /// Returns a sequence containing the values of the dictionary. /// @@ -139,7 +131,6 @@ public PyObject Values() /// /// Items Method /// - /// /// /// Returns a sequence containing the items of the dictionary. /// @@ -157,7 +148,6 @@ public PyObject Items() /// /// Copy Method /// - /// /// /// Returns a copy of the dictionary. /// @@ -175,7 +165,6 @@ public PyDict Copy() /// /// Update Method /// - /// /// /// Update the dictionary from another dictionary. /// @@ -192,7 +181,6 @@ public void Update(PyObject other) /// /// Clear Method /// - /// /// /// Clears the dictionary. /// diff --git a/src/runtime/pyfloat.cs b/src/runtime/pyfloat.cs index c8a363ea8..bcd5ad23d 100644 --- a/src/runtime/pyfloat.cs +++ b/src/runtime/pyfloat.cs @@ -12,7 +12,6 @@ public class PyFloat : PyNumber /// /// PyFloat Constructor /// - /// /// /// Creates a new PyFloat from an existing object reference. Note /// that the instance assumes ownership of the object reference. @@ -26,7 +25,6 @@ public PyFloat(IntPtr ptr) : base(ptr) /// /// PyFloat Constructor /// - /// /// /// Copy constructor - obtain a PyFloat from a generic PyObject. An /// ArgumentException will be thrown if the given object is not a @@ -46,7 +44,6 @@ public PyFloat(PyObject o) : base() /// /// PyFloat Constructor /// - /// /// /// Creates a new Python float from a double value. /// @@ -63,7 +60,6 @@ public PyFloat(double value) : base() /// /// PyFloat Constructor /// - /// /// /// Creates a new Python float from a string value. /// @@ -83,7 +79,6 @@ public PyFloat(string value) : base() /// /// IsFloatType Method /// - /// /// /// Returns true if the given object is a Python float. /// @@ -96,8 +91,6 @@ public static bool IsFloatType(PyObject value) /// /// AsFloat Method /// - /// - /// /// /// Convert a Python object to a Python float if possible, raising /// a PythonException if the conversion is not possible. This is diff --git a/src/runtime/pyint.cs b/src/runtime/pyint.cs index 847ad2ebf..43f9d02aa 100644 --- a/src/runtime/pyint.cs +++ b/src/runtime/pyint.cs @@ -12,7 +12,6 @@ public class PyInt : PyNumber /// /// PyInt Constructor /// - /// /// /// Creates a new PyInt from an existing object reference. Note /// that the instance assumes ownership of the object reference. @@ -26,7 +25,6 @@ public PyInt(IntPtr ptr) : base(ptr) /// /// PyInt Constructor /// - /// /// /// Copy constructor - obtain a PyInt from a generic PyObject. An /// ArgumentException will be thrown if the given object is not a @@ -46,7 +44,6 @@ public PyInt(PyObject o) : base() /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from an int32 value. /// @@ -63,7 +60,6 @@ public PyInt(int value) : base() /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from a uint32 value. /// @@ -81,7 +77,6 @@ public PyInt(uint value) : base(IntPtr.Zero) /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from an int64 value. /// @@ -98,7 +93,6 @@ public PyInt(long value) : base(IntPtr.Zero) /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from a uint64 value. /// @@ -116,7 +110,6 @@ public PyInt(ulong value) : base(IntPtr.Zero) /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from an int16 value. /// @@ -128,7 +121,6 @@ public PyInt(short value) : this((int)value) /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from a uint16 value. /// @@ -141,7 +133,6 @@ public PyInt(ushort value) : this((int)value) /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from a byte value. /// @@ -153,7 +144,6 @@ public PyInt(byte value) : this((int)value) /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from an sbyte value. /// @@ -166,7 +156,6 @@ public PyInt(sbyte value) : this((int)value) /// /// PyInt Constructor /// - /// /// /// Creates a new Python int from a string value. /// @@ -183,7 +172,6 @@ public PyInt(string value) : base() /// /// IsIntType Method /// - /// /// /// Returns true if the given object is a Python int. /// @@ -196,8 +184,6 @@ public static bool IsIntType(PyObject value) /// /// AsInt Method /// - /// - /// /// /// Convert a Python object to a Python int if possible, raising /// a PythonException if the conversion is not possible. This is @@ -217,7 +203,6 @@ public static PyInt AsInt(PyObject value) /// /// ToInt16 Method /// - /// /// /// Return the value of the Python int object as an int16. /// @@ -230,7 +215,6 @@ public short ToInt16() /// /// ToInt32 Method /// - /// /// /// Return the value of the Python int object as an int32. /// @@ -243,7 +227,6 @@ public int ToInt32() /// /// ToInt64 Method /// - /// /// /// Return the value of the Python int object as an int64. /// diff --git a/src/runtime/pyiter.cs b/src/runtime/pyiter.cs index 5310c4d8b..a2f239ccf 100644 --- a/src/runtime/pyiter.cs +++ b/src/runtime/pyiter.cs @@ -14,7 +14,6 @@ public class PyIter : PyObject, IEnumerator /// /// PyIter Constructor /// - /// /// /// Creates a new PyIter from an existing iterator reference. Note /// that the instance assumes ownership of the object reference. @@ -27,7 +26,6 @@ public PyIter(IntPtr ptr) : base(ptr) /// /// PyIter Constructor /// - /// /// /// Creates a Python iterator from an iterable. Like doing "iter(iterable)" in python. /// diff --git a/src/runtime/pylist.cs b/src/runtime/pylist.cs index 681e864a4..235f39c77 100644 --- a/src/runtime/pylist.cs +++ b/src/runtime/pylist.cs @@ -11,7 +11,6 @@ public class PyList : PySequence /// /// PyList Constructor /// - /// /// /// Creates a new PyList from an existing object reference. Note /// that the instance assumes ownership of the object reference. @@ -25,7 +24,6 @@ public PyList(IntPtr ptr) : base(ptr) /// /// PyList Constructor /// - /// /// /// Copy constructor - obtain a PyList from a generic PyObject. An /// ArgumentException will be thrown if the given object is not a @@ -45,7 +43,6 @@ public PyList(PyObject o) : base() /// /// PyList Constructor /// - /// /// /// Creates a new empty Python list object. /// @@ -62,7 +59,6 @@ public PyList() : base() /// /// PyList Constructor /// - /// /// /// Creates a new Python list object from an array of PyObjects. /// @@ -86,7 +82,6 @@ public PyList(PyObject[] items) : base() /// /// IsListType Method /// - /// /// /// Returns true if the given object is a Python list. /// @@ -99,7 +94,6 @@ public static bool IsListType(PyObject value) /// /// AsList Method /// - /// /// /// Converts a Python object to a Python list if possible, raising /// a PythonException if the conversion is not possible. This is @@ -119,7 +113,6 @@ public static PyList AsList(PyObject value) /// /// Append Method /// - /// /// /// Append an item to the list object. /// @@ -135,7 +128,6 @@ public void Append(PyObject item) /// /// Insert Method /// - /// /// /// Insert an item in the list object at the given index. /// @@ -152,7 +144,6 @@ public void Insert(int index, PyObject item) /// /// Reverse Method /// - /// /// /// Reverse the order of the list object in place. /// @@ -169,7 +160,6 @@ public void Reverse() /// /// Sort Method /// - /// /// /// Sort the list in place. /// diff --git a/src/runtime/pylong.cs b/src/runtime/pylong.cs index 8e17d2a59..a4ce60279 100644 --- a/src/runtime/pylong.cs +++ b/src/runtime/pylong.cs @@ -11,7 +11,6 @@ public class PyLong : PyNumber /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from an existing object reference. Note /// that the instance assumes ownership of the object reference. @@ -25,7 +24,6 @@ public PyLong(IntPtr ptr) : base(ptr) /// /// PyLong Constructor /// - /// /// /// Copy constructor - obtain a PyLong from a generic PyObject. An /// ArgumentException will be thrown if the given object is not a @@ -45,7 +43,6 @@ public PyLong(PyObject o) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from an int32 value. /// @@ -62,7 +59,6 @@ public PyLong(int value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from a uint32 value. /// @@ -80,7 +76,6 @@ public PyLong(uint value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from an int64 value. /// @@ -97,7 +92,6 @@ public PyLong(long value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from a uint64 value. /// @@ -115,7 +109,6 @@ public PyLong(ulong value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from an int16 value. /// @@ -132,7 +125,6 @@ public PyLong(short value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from an uint16 value. /// @@ -150,7 +142,6 @@ public PyLong(ushort value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from a byte value. /// @@ -167,7 +158,6 @@ public PyLong(byte value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from an sbyte value. /// @@ -185,7 +175,6 @@ public PyLong(sbyte value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from an double value. /// @@ -202,7 +191,6 @@ public PyLong(double value) : base() /// /// PyLong Constructor /// - /// /// /// Creates a new PyLong from a string value. /// @@ -219,7 +207,6 @@ public PyLong(string value) : base() /// /// IsLongType Method /// - /// /// /// Returns true if the given object is a Python long. /// @@ -232,8 +219,6 @@ public static bool IsLongType(PyObject value) /// /// AsLong Method /// - /// - /// /// /// Convert a Python object to a Python long if possible, raising /// a PythonException if the conversion is not possible. This is @@ -252,7 +237,6 @@ public static PyLong AsLong(PyObject value) /// /// ToInt16 Method /// - /// /// /// Return the value of the Python long object as an int16. /// @@ -265,7 +249,6 @@ public short ToInt16() /// /// ToInt32 Method /// - /// /// /// Return the value of the Python long object as an int32. /// @@ -278,7 +261,6 @@ public int ToInt32() /// /// ToInt64 Method /// - /// /// /// Return the value of the Python long object as an int64. /// diff --git a/src/runtime/pynumber.cs b/src/runtime/pynumber.cs index e6805d708..14b32b593 100644 --- a/src/runtime/pynumber.cs +++ b/src/runtime/pynumber.cs @@ -21,7 +21,6 @@ protected PyNumber() : base() /// /// IsNumberType Method /// - /// /// /// Returns true if the given object is a Python numeric type. /// diff --git a/src/runtime/pysequence.cs b/src/runtime/pysequence.cs index a5f6f3dad..85101128b 100644 --- a/src/runtime/pysequence.cs +++ b/src/runtime/pysequence.cs @@ -22,7 +22,6 @@ protected PySequence() : base() /// /// IsSequenceType Method /// - /// /// /// Returns true if the given object implements the sequence protocol. /// @@ -35,7 +34,6 @@ public static bool IsSequenceType(PyObject value) /// /// GetSlice Method /// - /// /// /// Return the slice of the sequence with the given indices. /// @@ -53,7 +51,6 @@ public PyObject GetSlice(int i1, int i2) /// /// SetSlice Method /// - /// /// /// Sets the slice of the sequence with the given indices. /// @@ -70,7 +67,6 @@ public void SetSlice(int i1, int i2, PyObject v) /// /// DelSlice Method /// - /// /// /// Deletes the slice of the sequence with the given indices. /// @@ -87,7 +83,6 @@ public void DelSlice(int i1, int i2) /// /// Index Method /// - /// /// /// Return the index of the given item in the sequence, or -1 if /// the item does not appear in the sequence. @@ -107,7 +102,6 @@ public int Index(PyObject item) /// /// Contains Method /// - /// /// /// Return true if the sequence contains the given item. This method /// throws a PythonException if an error occurs during the check. @@ -126,7 +120,6 @@ public bool Contains(PyObject item) /// /// Concat Method /// - /// /// /// Return the concatenation of the sequence object with the passed in /// sequence object. @@ -145,7 +138,6 @@ public PyObject Concat(PyObject other) /// /// Repeat Method /// - /// /// /// Return the sequence object repeated N times. This is equivalent /// to the Python expression "object * count". diff --git a/src/runtime/pystring.cs b/src/runtime/pystring.cs index a3d198a2c..1fe3a6d7e 100644 --- a/src/runtime/pystring.cs +++ b/src/runtime/pystring.cs @@ -12,7 +12,6 @@ public class PyString : PySequence /// /// PyString Constructor /// - /// /// /// Creates a new PyString from an existing object reference. Note /// that the instance assumes ownership of the object reference. @@ -26,7 +25,6 @@ public PyString(IntPtr ptr) : base(ptr) /// /// PyString Constructor /// - /// /// /// Copy constructor - obtain a PyString from a generic PyObject. /// An ArgumentException will be thrown if the given object is not @@ -46,7 +44,6 @@ public PyString(PyObject o) : base() /// /// PyString Constructor /// - /// /// /// Creates a Python string from a managed string. /// @@ -63,7 +60,6 @@ public PyString(string s) : base() /// /// IsStringType Method /// - /// /// /// Returns true if the given object is a Python string. /// diff --git a/src/runtime/pythonengine.cs b/src/runtime/pythonengine.cs index 3f0022467..a2eccff0d 100644 --- a/src/runtime/pythonengine.cs +++ b/src/runtime/pythonengine.cs @@ -210,11 +210,11 @@ public static void Initialize(IEnumerable args) } } - //==================================================================== - // A helper to perform initialization from the context of an active - // CPython interpreter process - this bootstraps the managed runtime - // when it is imported by the CLR extension module. - //==================================================================== + /// + /// A helper to perform initialization from the context of an active + /// CPython interpreter process - this bootstraps the managed runtime + /// when it is imported by the CLR extension module. + /// #if PYTHON3 public static IntPtr InitExt() #elif PYTHON2 diff --git a/src/runtime/pythonexception.cs b/src/runtime/pythonexception.cs index 124636457..d2475664c 100644 --- a/src/runtime/pythonexception.cs +++ b/src/runtime/pythonexception.cs @@ -76,7 +76,6 @@ public void Restore() /// /// PyType Property /// - /// /// /// Returns the exception type as a Python object. /// @@ -88,7 +87,6 @@ public IntPtr PyType /// /// PyValue Property /// - /// /// /// Returns the exception value as a Python object. /// @@ -100,7 +98,6 @@ public IntPtr PyValue /// /// PyTB Property /// - /// /// /// Returns the TraceBack as a Python object. /// @@ -112,7 +109,6 @@ public IntPtr PyTB /// /// Message Property /// - /// /// /// A string representing the python exception message. /// @@ -124,7 +120,6 @@ public override string Message /// /// StackTrace Property /// - /// /// /// A string representing the python exception stack trace. /// @@ -137,7 +132,6 @@ public override string StackTrace /// /// Dispose Method /// - /// /// /// The Dispose method provides a way to explicitly release the /// Python objects represented by a PythonException. @@ -166,7 +160,6 @@ public void Dispose() /// /// Matches Method /// - /// /// /// Returns true if the Python exception type represented by the /// PythonException instance matches the given exception type. diff --git a/src/runtime/pytuple.cs b/src/runtime/pytuple.cs index 97f4c5bbc..682ed3f50 100644 --- a/src/runtime/pytuple.cs +++ b/src/runtime/pytuple.cs @@ -11,7 +11,6 @@ public class PyTuple : PySequence /// /// PyTuple Constructor /// - /// /// /// Creates a new PyTuple from an existing object reference. Note /// that the instance assumes ownership of the object reference. @@ -25,7 +24,6 @@ public PyTuple(IntPtr ptr) : base(ptr) /// /// PyTuple Constructor /// - /// /// /// Copy constructor - obtain a PyTuple from a generic PyObject. An /// ArgumentException will be thrown if the given object is not a @@ -45,7 +43,6 @@ public PyTuple(PyObject o) : base() /// /// PyTuple Constructor /// - /// /// /// Creates a new empty PyTuple. /// @@ -62,7 +59,6 @@ public PyTuple() : base() /// /// PyTuple Constructor /// - /// /// /// Creates a new PyTuple from an array of PyObject instances. /// @@ -86,7 +82,6 @@ public PyTuple(PyObject[] items) : base() /// /// IsTupleType Method /// - /// /// /// Returns true if the given object is a Python tuple. /// @@ -99,7 +94,6 @@ public static bool IsTupleType(PyObject value) /// /// AsTuple Method /// - /// /// /// Convert a Python object to a Python tuple if possible, raising /// a PythonException if the conversion is not possible. This is diff --git a/src/runtime/runtime.cs b/src/runtime/runtime.cs index f79daa970..2c1ab87ab 100644 --- a/src/runtime/runtime.cs +++ b/src/runtime/runtime.cs @@ -184,7 +184,7 @@ public class Runtime internal static bool is32bit; /// - /// Intitialize the runtime... + /// Initialize the runtime... /// internal static void Initialize() { @@ -333,7 +333,7 @@ internal static void Shutdown() Py_Finalize(); } - // called *without* the GIL aquired by clr._AtExit + // called *without* the GIL acquired by clr._AtExit internal static int AtExit() { lock (IsFinalizingLock) @@ -497,12 +497,11 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects) return types; } - //=================================================================== - // Managed exports of the Python C API. Where appropriate, we do - // some optimization to avoid managed <--> unmanaged transitions - // (mostly for heavily used methods). - //=================================================================== - + /// + /// Managed exports of the Python C API. Where appropriate, we do + /// some optimization to avoid managed <--> unmanaged transitions + /// (mostly for heavily used methods). + /// internal unsafe static void XIncref(IntPtr op) { #if Py_DEBUG @@ -877,14 +876,14 @@ internal unsafe static extern IntPtr PyMethod_New(IntPtr func, IntPtr self, IntPtr cls); - //==================================================================== - // Python abstract object API - //==================================================================== - - // A macro-like method to get the type of a Python object. This is - // designed to be lean and mean in IL & avoid managed <-> unmanaged - // transitions. Note that this does not incref the type object. - + /// + /// Python abstract object API + /// + /// + /// A macro-like method to get the type of a Python object. This is + /// designed to be lean and mean in IL & avoid managed <-> unmanaged + /// transitions. Note that this does not incref the type object. + /// internal unsafe static IntPtr PyObject_TYPE(IntPtr op) { @@ -908,10 +907,11 @@ internal unsafe static IntPtr } } - // Managed version of the standard Python C API PyObject_Type call. - // This version avoids a managed <-> unmanaged transition. This one - // does incref the returned type object. - + /// + /// Managed version of the standard Python C API PyObject_Type call. + /// This version avoids a managed <-> unmanaged transition. This one + /// does incref the returned type object. + /// internal unsafe static IntPtr PyObject_Type(IntPtr op) { @@ -1089,10 +1089,9 @@ internal unsafe static extern IntPtr PyObject_Dir(IntPtr pointer); - //==================================================================== - // Python number API - //==================================================================== - + /// + /// Python number API + /// #if PYTHON3 [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyNumber_Long", @@ -1394,10 +1393,9 @@ internal unsafe static extern IntPtr internal unsafe static extern IntPtr PyNumber_Invert(IntPtr o1); - //==================================================================== - // Python sequence API - //==================================================================== - + /// + /// Python sequence API + /// [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] internal unsafe static extern bool @@ -1474,10 +1472,9 @@ internal unsafe static extern IntPtr PySequence_List(IntPtr pointer); - //==================================================================== - // Python string API - //==================================================================== - + /// + /// Python string API + /// internal static bool IsStringType(IntPtr op) { IntPtr t = PyObject_TYPE(op); @@ -1769,10 +1766,9 @@ internal unsafe static string GetManagedString(IntPtr op) return null; } - //==================================================================== - // Python dictionary API - //==================================================================== - + /// + /// Python dictionary API + /// internal static bool PyDict_Check(IntPtr ob) { return PyObject_TYPE(ob) == Runtime.PyDictType; @@ -1859,10 +1855,9 @@ internal unsafe static extern int PyDict_Size(IntPtr pointer); - //==================================================================== - // Python list API - //==================================================================== - + /// + /// Python list API + /// internal static bool PyList_Check(IntPtr ob) { return PyObject_TYPE(ob) == Runtime.PyListType; @@ -1924,10 +1919,9 @@ internal unsafe static extern int PyList_Size(IntPtr pointer); - //==================================================================== - // Python tuple API - //==================================================================== - + /// + /// Python tuple API + /// internal static bool PyTuple_Check(IntPtr ob) { return PyObject_TYPE(ob) == Runtime.PyTupleType; @@ -1959,10 +1953,9 @@ internal unsafe static extern int PyTuple_Size(IntPtr pointer); - //==================================================================== - // Python iterator API - //==================================================================== - + /// + /// Python iterator API + /// #if PYTHON2 [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] @@ -1983,10 +1976,9 @@ internal static bool internal unsafe static extern IntPtr PyIter_Next(IntPtr pointer); - //==================================================================== - // Python module API - //==================================================================== - + /// + /// Python module API + /// [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] internal unsafe static extern IntPtr @@ -2070,10 +2062,9 @@ internal unsafe static extern int PySys_SetObject(string name, IntPtr ob); - //==================================================================== - // Python type object API - //==================================================================== - + /// + /// Python type object API + /// internal static bool PyType_Check(IntPtr ob) { return PyObject_TypeCheck(ob, Runtime.PyTypeType); @@ -2151,10 +2142,9 @@ internal unsafe static extern void PyObject_GC_UnTrack(IntPtr tp); - //==================================================================== - // Python memory API - //==================================================================== - + /// + /// Python memory API + /// [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] internal unsafe static extern IntPtr @@ -2171,10 +2161,9 @@ internal unsafe static extern void PyMem_Free(IntPtr ptr); - //==================================================================== - // Python exception API - //==================================================================== - + /// + /// Python exception API + /// [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] internal unsafe static extern void @@ -2236,10 +2225,9 @@ internal unsafe static extern void PyErr_Print(); - //==================================================================== - // Miscellaneous - //==================================================================== - + /// + /// Miscellaneous + /// [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] internal unsafe static extern IntPtr diff --git a/src/runtime/typemanager.cs b/src/runtime/typemanager.cs index d6c474f8d..d85bdf9bb 100644 --- a/src/runtime/typemanager.cs +++ b/src/runtime/typemanager.cs @@ -8,11 +8,10 @@ namespace Python.Runtime { - //======================================================================= - // The TypeManager class is responsible for building binary-compatible - // Python type objects that are implemented in managed code. - //======================================================================= - + /// + /// The TypeManager class is responsible for building binary-compatible + /// Python type objects that are implemented in managed code. + /// internal class TypeManager { static BindingFlags tbFlags; @@ -25,13 +24,12 @@ static TypeManager() } - //==================================================================== - // Given a managed Type derived from ExtensionType, get the handle to - // a Python type object that delegates its implementation to the Type - // object. These Python type instances are used to implement internal - // descriptor and utility types like ModuleObject, PropertyObject, etc. - //==================================================================== - + /// + /// Given a managed Type derived from ExtensionType, get the handle to + /// a Python type object that delegates its implementation to the Type + /// object. These Python type instances are used to implement internal + /// descriptor and utility types like ModuleObject, PropertyObject, etc. + /// internal static IntPtr GetTypeHandle(Type type) { // Note that these types are cached with a refcount of 1, so they @@ -48,12 +46,11 @@ internal static IntPtr GetTypeHandle(Type type) } - //==================================================================== - // Get the handle of a Python type that reflects the given CLR type. - // The given ManagedType instance is a managed object that implements - // the appropriate semantics in Python for the reflected managed type. - //==================================================================== - + /// + /// Get the handle of a Python type that reflects the given CLR type. + /// The given ManagedType instance is a managed object that implements + /// the appropriate semantics in Python for the reflected managed type. + /// internal static IntPtr GetTypeHandle(ManagedType obj, Type type) { IntPtr handle = IntPtr.Zero; @@ -68,15 +65,14 @@ internal static IntPtr GetTypeHandle(ManagedType obj, Type type) } - //==================================================================== - // The following CreateType implementations do the necessary work to - // create Python types to represent managed extension types, reflected - // types, subclasses of reflected types and the managed metatype. The - // dance is slightly different for each kind of type due to different - // behavior needed and the desire to have the existing Python runtime - // do as much of the allocation and initialization work as possible. - //==================================================================== - + /// + /// The following CreateType implementations do the necessary work to + /// create Python types to represent managed extension types, reflected + /// types, subclasses of reflected types and the managed metatype. The + /// dance is slightly different for each kind of type due to different + /// behavior needed and the desire to have the existing Python runtime + /// do as much of the allocation and initialization work as possible. + /// internal static IntPtr CreateType(Type impl) { IntPtr type = AllocateTypeObject(impl.Name); @@ -395,10 +391,9 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl) } - //==================================================================== - // Utility method to allocate a type object & do basic initialization. - //==================================================================== - + /// + /// Utility method to allocate a type object & do basic initialization. + /// internal static IntPtr AllocateTypeObject(string name) { IntPtr type = Runtime.PyType_GenericAlloc(Runtime.PyTypeType, 0); @@ -445,12 +440,11 @@ internal static IntPtr AllocateTypeObject(string name) } - //==================================================================== - // Given a newly allocated Python type object and a managed Type that - // provides the implementation for the type, connect the type slots of - // the Python object to the managed methods of the implementing Type. - //==================================================================== - + /// + /// Given a newly allocated Python type object and a managed Type that + /// provides the implementation for the type, connect the type slots of + /// the Python object to the managed methods of the implementing Type. + /// internal static void InitializeSlots(IntPtr type, Type impl) { Hashtable seen = new Hashtable(8); @@ -492,12 +486,11 @@ internal static void InitializeSlots(IntPtr type, Type impl) } - //==================================================================== - // Given 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). - //==================================================================== - + /// + /// Given 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(IntPtr pytype, Type type) { IntPtr dict = Marshal.ReadIntPtr(pytype, TypeOffset.tp_dict); @@ -531,10 +524,9 @@ private static void InitMethods(IntPtr pytype, Type type) } - //==================================================================== - // Utility method to copy slots from a given type to another type. - //==================================================================== - + /// + /// Utility method to copy slots from a given type to another type. + /// internal static void CopySlot(IntPtr from, IntPtr to, int offset) { IntPtr fp = Marshal.ReadIntPtr(from, offset); diff --git a/src/runtime/typemethod.cs b/src/runtime/typemethod.cs index 0c60301a0..50577f93d 100644 --- a/src/runtime/typemethod.cs +++ b/src/runtime/typemethod.cs @@ -4,10 +4,9 @@ namespace Python.Runtime { - //======================================================================== - // Implements a Python type that provides access to CLR object methods. - //======================================================================== - + /// + /// Implements a Python type that provides access to CLR object methods. + /// internal class TypeMethod : MethodObject { public TypeMethod(Type type, string name, MethodInfo[] info) :