fixed Python derived types crashing on shutdown of Python process

clearing GCHandle from an instance of Python derived type would drop the last reference to it, so it was destroyed without being removed from reflectedObjects collection
This commit is contained in:
Victor Nova 2021-12-20 12:27:56 -08:00 коммит произвёл Victor
Родитель e9c3a3d523
Коммит 2596cdf61c
2 изменённых файлов: 6 добавлений и 4 удалений

Просмотреть файл

@ -80,16 +80,17 @@ namespace Python.Runtime
tp_clear(lastRef.Borrow());
bool deleted = loadedExtensions.Remove(lastRef.DangerousGetAddress());
Debug.Assert(deleted);
// we must decref our type: https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc
DecrefTypeAndFree(lastRef.Steal());
}
public static int tp_clear(BorrowedReference ob)
{
TryFreeGCHandle(ob);
if (TryFreeGCHandle(ob))
{
bool deleted = loadedExtensions.Remove(ob.DangerousGetAddress());
Debug.Assert(deleted);
}
int res = ClassBase.BaseUnmanagedClear(ob);
return res;

Просмотреть файл

@ -339,6 +339,7 @@ namespace Python.Runtime
else if (forceBreakLoops)
{
NullGCHandles(CLRObject.reflectedObjects);
CLRObject.reflectedObjects.Clear();
}
}
return false;