Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa2d9fd

Browse files
author
dse
committed
Runtime/Shutdown loop stores old caches and static variables. It's produces bugs when CPython freeing up enough objects.
1 parentdf1c224 commitfa2d9fd

File tree

9 files changed

+53
-8
lines changed

9 files changed

+53
-8
lines changed

‎CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2121

2222
###Fixed
2323

24+
- Fixed secondary PythonEngine.Initialize call, all sensitive static variables now reseted.
25+
This is a hidden bug. Once python cleaning up enough memory, objects from previous engine run becomes corrupted.
2426
- Fixed Visual Studio 2017 compat (#434) for setup.py
2527
- Fixed crash on exit of the Python interpreter if a python class
2628
derived from a .NET class has a`__namespace__` or`__assembly__`

‎src/runtime/assemblymanager.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ internal class AssemblyManager
1717
{
1818
// modified from event handlers below, potentially triggered from different .NET threads
1919
// therefore this should be a ConcurrentDictionary
20-
privatestaticConcurrentDictionary<string,ConcurrentDictionary<Assembly,string>>namespaces;
20+
privatestaticConcurrentDictionary<string,ConcurrentDictionary<Assembly,string>>namespaces=
21+
newConcurrentDictionary<string,ConcurrentDictionary<Assembly,string>>();
2122
//private static Dictionary<string, Dictionary<string, string>> generics;
2223
privatestaticAssemblyLoadEventHandlerlhandler;
2324
privatestaticResolveEventHandlerrhandler;
2425

2526
// updated only under GIL?
26-
privatestaticDictionary<string,int>probed;
27+
privatestaticDictionary<string,int>probed=newDictionary<string,int>(32);
2728

2829
// modified from event handlers below, potentially triggered from different .NET threads
2930
privatestaticAssemblyListassemblies;
@@ -40,9 +41,6 @@ private AssemblyManager()
4041
/// </summary>
4142
internalstaticvoidInitialize()
4243
{
43-
namespaces=newConcurrentDictionary<string,ConcurrentDictionary<Assembly,string>>();
44-
probed=newDictionary<string,int>(32);
45-
//generics = new Dictionary<string, Dictionary<string, string>>();
4644
assemblies=newAssemblyList(16);
4745
pypath=newList<string>(16);
4846

‎src/runtime/classderived.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
usingSystem;
1+
usingSystem;
22
usingSystem.Collections.Generic;
33
usingSystem.Linq;
44
usingSystem.Reflection;
55
usingSystem.Reflection.Emit;
6+
usingSystem.Resources;
67
usingSystem.Runtime.InteropServices;
78
usingSystem.Threading.Tasks;
89

@@ -32,6 +33,12 @@ static ClassDerivedObject()
3233
moduleBuilders=newDictionary<Tuple<string,string>,ModuleBuilder>();
3334
}
3435

36+
publicstaticvoidReset()
37+
{
38+
assemblyBuilders=newDictionary<string,AssemblyBuilder>();
39+
moduleBuilders=newDictionary<Tuple<string,string>,ModuleBuilder>();
40+
}
41+
3542
internalClassDerivedObject(Typetp):base(tp)
3643
{
3744
}

‎src/runtime/classmanager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ static ClassManager()
3434
dtype=typeof(MulticastDelegate);
3535
}
3636

37+
publicstaticvoidReset()
38+
{
39+
cache=newDictionary<Type,ClassBase>(128);
40+
}
41+
3742
/// <summary>
3843
/// Return the ClassBase-derived instance that implements a particular
3944
/// reflected managed type, creating it if it doesn't yet exist.

‎src/runtime/genericutil.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
usingSystem;
22
usingSystem.Collections.Generic;
3+
usingSystem.Resources;
34

45
namespacePython.Runtime
56
{
@@ -20,6 +21,11 @@ static GenericUtil()
2021
mapping=newDictionary<string,Dictionary<string,List<string>>>();
2122
}
2223

24+
publicstaticvoidReset()
25+
{
26+
mapping=newDictionary<string,Dictionary<string,List<string>>>();
27+
}
28+
2329
/// <summary>
2430
/// Register a generic type that appears in a given namespace.
2531
/// </summary>

‎src/runtime/moduleobject.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ public CLRModule() : base("clr")
328328
}
329329
}
330330

331+
publicstaticvoidReset()
332+
{
333+
hacked=false;
334+
interactive_preload=true;
335+
preload=false;
336+
337+
// XXX Test performance of new features //
338+
_SuppressDocs=false;
339+
_SuppressOverloads=false;
340+
}
341+
331342
/// <summary>
332343
/// The initializing of the preload hook has to happen as late as
333344
/// possible since sys.ps1 is created after the CLR module is

‎src/runtime/pyscope.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,15 @@ public void Dispose()
537537

538538
publicclassPyScopeManager
539539
{
540-
publicreadonlystaticPyScopeManagerGlobal=newPyScopeManager();
540+
publicstaticPyScopeManagerGlobal;
541541

542542
privateDictionary<string,PyScope>NamedScopes=newDictionary<string,PyScope>();
543543

544+
internalstaticvoidReset()
545+
{
546+
Global=newPyScopeManager();
547+
}
548+
544549
internalPyScopeNewScope(stringname)
545550
{
546551
if(name==null)

‎src/runtime/runtime.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ internal static void Initialize()
221221
PyEval_InitThreads();
222222
}
223223

224+
CLRModule.Reset();
225+
GenericUtil.Reset();
226+
PyScopeManager.Reset();
227+
ClassManager.Reset();
228+
ClassDerivedObject.Reset();
229+
TypeManager.Reset();
230+
224231
IntPtrop;
225232
IntPtrdict;
226233
if(IsPython3)

‎src/runtime/typemanager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usingSystem;
1+
usingSystem;
22
usingSystem.Collections;
33
usingSystem.Collections.Generic;
44
usingSystem.Reflection;
@@ -21,6 +21,10 @@ static TypeManager()
2121
cache=newDictionary<Type,IntPtr>(128);
2222
}
2323

24+
publicstaticvoidReset()
25+
{
26+
cache=newDictionary<Type,IntPtr>(128);
27+
}
2428

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp