PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/DICK.B1/IronPython.Modules/gc.cs

https://bitbucket.org/williamybs/uidipythontool
C# | 110 lines | 72 code | 24 blank | 14 comment | 0 complexity | 0fc831bca7d95d3beb824bd6aaffaa9a MD5 | raw file
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Microsoft Public License. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Microsoft Public License, please send an email to
  8. * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Microsoft Public License.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System;
  16. using Microsoft.Scripting;
  17. using Microsoft.Scripting.Runtime;
  18. using IronPython.Runtime;
  19. using IronPython.Runtime.Exceptions;
  20. using IronPython.Runtime.Operations;
  21. using IronPython.Runtime.Types;
  22. using SpecialName = System.Runtime.CompilerServices.SpecialNameAttribute;
  23. [assembly: PythonModule("gc", typeof(IronPython.Modules.PythonGC))]
  24. namespace IronPython.Modules {
  25. public static class PythonGC {
  26. public const string __doc__ = "Provides functions for inspecting, configuring, and forcing garbage collection.";
  27. public const int DEBUG_STATS = 1;
  28. public const int DEBUG_COLLECTABLE = 2;
  29. public const int DEBUG_UNCOLLECTABLE = 4;
  30. public const int DEBUG_INSTANCES = 8;
  31. public const int DEBUG_OBJECTS = 16;
  32. public const int DEBUG_SAVEALL = 32;
  33. public const int DEBUG_LEAK = (DEBUG_COLLECTABLE | DEBUG_UNCOLLECTABLE | DEBUG_INSTANCES | DEBUG_OBJECTS | DEBUG_SAVEALL);
  34. private static readonly object _threadholdKey = new object();
  35. [SpecialName]
  36. public static void PerformModuleReload(PythonContext/*!*/ context, PythonDictionary/*!*/ dict) {
  37. context.SetModuleState(_threadholdKey, PythonTuple.MakeTuple(64 * 1024, 256 * 1024, 1024 * 1024));
  38. }
  39. public static void enable() {
  40. }
  41. public static void disable(CodeContext/*!*/ context) {
  42. PythonOps.Warn(context, PythonExceptions.RuntimeWarning, "IronPython has no support for disabling the GC");
  43. }
  44. public static object isenabled() {
  45. return ScriptingRuntimeHelpers.True;
  46. }
  47. public static int collect(CodeContext context, int generation) {
  48. return PythonContext.GetContext(context).Collect(generation);
  49. }
  50. public static int collect(CodeContext context) {
  51. return collect(context, GC.MaxGeneration);
  52. }
  53. public static void set_debug(object o) {
  54. throw PythonOps.NotImplementedError("gc.set_debug isn't implemented");
  55. }
  56. public static object get_debug() {
  57. return null;
  58. }
  59. public static object[] get_objects() {
  60. throw PythonOps.NotImplementedError("gc.get_objects isn't implemented");
  61. }
  62. public static void set_threshold(CodeContext/*!*/ context, params object[] args) {
  63. SetThresholds(context, PythonTuple.MakeTuple(args));
  64. }
  65. public static PythonTuple get_threshold(CodeContext/*!*/ context) {
  66. return GetThresholds(context);
  67. }
  68. public static object[] get_referrers(params object[] objs) {
  69. throw PythonOps.NotImplementedError("gc.get_referrers isn't implemented");
  70. }
  71. public static object[] get_referents(params object[] objs) {
  72. throw PythonOps.NotImplementedError("gc.get_referents isn't implemented");
  73. }
  74. public static List garbage {
  75. get {
  76. return new List();
  77. }
  78. }
  79. private static PythonTuple GetThresholds(CodeContext/*!*/ context) {
  80. return (PythonTuple)PythonContext.GetContext(context).GetModuleState(_threadholdKey);
  81. }
  82. private static void SetThresholds(CodeContext/*!*/ context, PythonTuple thresholds) {
  83. PythonContext.GetContext(context).SetModuleState(_threadholdKey, thresholds);
  84. }
  85. }
  86. }