Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

Commit 39f47c8

Browse files
committed
* Classify runtime data
* External interface for custom storing wrapper objects
1 parent 97c8c2a commit 39f47c8

File tree

7 files changed

+336
-68
lines changed

7 files changed

+336
-68
lines changed

src/runtime/classmanager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ private static int OnVisit(IntPtr ob, IntPtr arg)
8282
}
8383

8484

85-
internal static void StashPush(Stack stack)
85+
internal static void StashPush(RuntimeDataStorage storage)
8686
{
87-
stack.Push(cache);
87+
storage.PushValue(cache);
8888
}
8989

90-
internal static void StashPop(Stack stack)
90+
internal static void StashPop(RuntimeDataStorage storage)
9191
{
92-
cache = (Dictionary<Type, ClassBase>)stack.Pop();
92+
cache = storage.PopValue<Dictionary<Type, ClassBase>>();
9393
}
9494

9595
/// <summary>

src/runtime/clrobject.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ internal CLRObject(object ob, IntPtr tp)
3535
Exceptions.SetArgsAndCause(py);
3636
}
3737

38+
protected CLRObject()
39+
{
40+
}
41+
3842

3943
internal static CLRObject GetInstance(object ob, IntPtr pyType)
4044
{
@@ -70,6 +74,18 @@ internal static IntPtr GetInstHandle(object ob)
7074
return co.pyHandle;
7175
}
7276

77+
internal static CLRObject Restore(object ob, IntPtr pyHandle)
78+
{
79+
CLRObject co = new CLRObject()
80+
{
81+
inst = ob,
82+
pyHandle = pyHandle,
83+
tpHandle = Runtime.PyObject_TYPE(pyHandle)
84+
};
85+
co.Load();
86+
return co;
87+
}
88+
7389
protected override void OnSave()
7490
{
7591
base.OnSave();

src/runtime/interop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,15 +564,15 @@ public ThunkInfo(Delegate target)
564564
}
565565
}
566566

567-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
567+
[StructLayout(LayoutKind.Sequential)]
568568
struct PyGC_Node
569569
{
570570
public IntPtr gc_next;
571571
public IntPtr gc_prev;
572572
public IntPtr gc_refs;
573573
}
574574

575-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
575+
[StructLayout(LayoutKind.Sequential)]
576576
struct PyGC_Head
577577
{
578578
public PyGC_Node gc;

src/runtime/metatype.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public static void Release()
4040
_metaSlotsHodler = null;
4141
}
4242

43-
internal static void StashPush(Stack stack)
43+
internal static void StashPush(RuntimeDataStorage storage)
4444
{
4545
Runtime.XIncref(PyCLRMetaType);
46-
stack.Push(PyCLRMetaType);
46+
storage.PushValue(PyCLRMetaType);
4747
}
4848

49-
internal static IntPtr StashPop(Stack stack)
49+
internal static IntPtr StashPop(RuntimeDataStorage storage)
5050
{
51-
PyCLRMetaType = (IntPtr)stack.Pop();
51+
PyCLRMetaType = storage.PopValue<IntPtr>();
5252
_metaSlotsHodler = new SlotsHolder(PyCLRMetaType);
5353
TypeManager.InitializeSlots(PyCLRMetaType, typeof(MetaType), _metaSlotsHodler);
5454

src/runtime/runtime.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd
206206
string rtdir = RuntimeEnvironment.GetRuntimeDirectory();
207207
IntPtr path = PySys_GetObject("path");
208208
IntPtr item = PyString_FromString(rtdir);
209-
PyList_Append(path, item);
209+
if (PySequence_Contains(path, item) == 0)
210+
{
211+
PyList_Append(path, item);
212+
}
210213
XDecref(item);
211214
AssemblyManager.UpdatePath();
212215
}
@@ -364,12 +367,7 @@ internal static void Shutdown()
364367
AssemblyManager.Shutdown();
365368
ImportHook.Shutdown();
366369

367-
#if !NETSTANDARD
368-
if (mode != ShutdownMode.Reload)
369-
{
370-
ClearClrModules();
371-
}
372-
#endif
370+
ClearClrModules();
373371
RemoveClrRootModule();
374372

375373
MoveClrInstancesOnwershipToPython();
@@ -454,8 +452,7 @@ private static void ClearClrModules()
454452
var item = PyList_GetItem(items, i);
455453
var name = PyTuple_GetItem(item, 0);
456454
var module = PyTuple_GetItem(item, 1);
457-
var clrModule = ManagedType.GetManagedObject(module);
458-
if (clrModule != null)
455+
if (ManagedType.IsManagedType(module))
459456
{
460457
PyDict_DelItem(modules, name);
461458
}
@@ -486,8 +483,8 @@ private static void PyDictTryDelItem(IntPtr dict, string key)
486483

487484
private static void MoveClrInstancesOnwershipToPython()
488485
{
489-
var copyObjs = ManagedType.GetManagedObjects().ToArray();
490486
var objs = ManagedType.GetManagedObjects();
487+
var copyObjs = objs.ToArray();
491488
foreach (var entry in copyObjs)
492489
{
493490
ManagedType obj = entry.Key;

0 commit comments

Comments
 (0)