Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Runtime/Shutdown loop stores old caches and static variables. It's pr…
…oduces bugs when CPython freeing up enough objects.
  • Loading branch information
dse committed Aug 31, 2017
commit 9de6f7bd071f60c67b42847f33453c0d5bd61c7a
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].

### Fixed

- Fixed secondary PythonEngine.Initialize call, all sensitive static variables now reseted.
This is a hidden bug. Once python cleaning up enough memory, objects from previous engine run becomes corrupted.
- Fixed Visual Studio 2017 compat (#434) for setup.py
- Fixed crash on exit of the Python interpreter if a python class
derived from a .NET class has a `__namespace__` or `__assembly__`
Expand Down
8 changes: 3 additions & 5 deletions src/runtime/assemblymanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ internal class AssemblyManager
{
// modified from event handlers below, potentially triggered from different .NET threads
// therefore this should be a ConcurrentDictionary
private static ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces;
private static ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces =
new ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>>();
//private static Dictionary<string, Dictionary<string, string>> generics;
private static AssemblyLoadEventHandler lhandler;
private static ResolveEventHandler rhandler;

// updated only under GIL?
private static Dictionary<string, int> probed;
private static Dictionary<string, int> probed = new Dictionary<string, int>(32);

// modified from event handlers below, potentially triggered from different .NET threads
private static AssemblyList assemblies;
Expand All @@ -40,9 +41,6 @@ private AssemblyManager()
/// </summary>
internal static void Initialize()
{
namespaces = new ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>>();
probed = new Dictionary<string, int>(32);
//generics = new Dictionary<string, Dictionary<string, string>>();
assemblies = new AssemblyList(16);
pypath = new List<string>(16);

Expand Down
9 changes: 8 additions & 1 deletion src/runtime/classderived.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

Expand Down Expand Up @@ -32,6 +33,12 @@ static ClassDerivedObject()
moduleBuilders = new Dictionary<Tuple<string, string>, ModuleBuilder>();
}

public static void Reset()
{
assemblyBuilders = new Dictionary<string, AssemblyBuilder>();
moduleBuilders = new Dictionary<Tuple<string, string>, ModuleBuilder>();
}

internal ClassDerivedObject(Type tp) : base(tp)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/classmanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ static ClassManager()
dtype = typeof(MulticastDelegate);
}

public static void Reset()
{
cache = new Dictionary<Type, ClassBase>(128);
}

/// <summary>
/// Return the ClassBase-derived instance that implements a particular
/// reflected managed type, creating it if it doesn't yet exist.
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/genericutil.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Resources;

namespace Python.Runtime
{
Expand All @@ -20,6 +21,11 @@ static GenericUtil()
mapping = new Dictionary<string, Dictionary<string, List<string>>>();
}

public static void Reset()
{
mapping = new Dictionary<string, Dictionary<string, List<string>>>();
}

/// <summary>
/// Register a generic type that appears in a given namespace.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/moduleobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ public CLRModule() : base("clr")
}
}

public static void Reset()
{
hacked = false;
interactive_preload = true;
preload = false;

// XXX Test performance of new features //
_SuppressDocs = false;
_SuppressOverloads = false;
}

/// <summary>
/// The initializing of the preload hook has to happen as late as
/// possible since sys.ps1 is created after the CLR module is
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/pyscope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,15 @@ public void Dispose()

public class PyScopeManager
{
public readonly static PyScopeManager Global = new PyScopeManager();
public static PyScopeManager Global;

private Dictionary<string, PyScope> NamedScopes = new Dictionary<string, PyScope>();

internal static void Reset()
{
Global = new PyScopeManager();
}

internal PyScope NewScope(string name)
{
if (name == null)
Expand Down
7 changes: 7 additions & 0 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ internal static void Initialize()
PyEval_InitThreads();
}

CLRModule.Reset();
GenericUtil.Reset();
PyScopeManager.Reset();
ClassManager.Reset();
ClassDerivedObject.Reset();
TypeManager.Reset();

IntPtr op;
IntPtr dict;
if (IsPython3)
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/typemanager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
Expand All @@ -21,6 +21,10 @@ static TypeManager()
cache = new Dictionary<Type, IntPtr>(128);
}

public static void Reset()
{
cache = new Dictionary<Type, IntPtr>(128);
}

/// <summary>
/// Given a managed Type derived from ExtensionType, get the handle to
Expand Down