From 46adc4631e2c1cb267e7d7c4bf68d537907d228e Mon Sep 17 00:00:00 2001 From: Victor Milovanov Date: Tue, 25 Feb 2020 14:12:14 -0800 Subject: [PATCH] added checks to PyCheck_Iter_PyObject_IsIterable_ThreadingLock_Test in attempt to replace segfault with a more meaningful exception related to https://github.com/pythonnet/pythonnet/issues/1060 --- src/embed_tests/TestRuntime.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/embed_tests/TestRuntime.cs b/src/embed_tests/TestRuntime.cs index 25b70fac5..157fe4cb7 100644 --- a/src/embed_tests/TestRuntime.cs +++ b/src/embed_tests/TestRuntime.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using NUnit.Framework; using Python.Runtime; using Python.Runtime.Platform; @@ -110,9 +111,15 @@ public static void PyCheck_Iter_PyObject_IsIterable_ThreadingLock_Test() // Create an instance of threading.Lock, which is one of the very few types that does not have the // TypeFlags.HaveIter set in Python 2. This tests a different code path in PyObject_IsIterable and PyIter_Check. var threading = Runtime.Runtime.PyImport_ImportModule("threading"); + Exceptions.ErrorCheck(threading); var threadingDict = Runtime.Runtime.PyModule_GetDict(threading); + Exceptions.ErrorCheck(threadingDict); var lockType = Runtime.Runtime.PyDict_GetItemString(threadingDict, "Lock"); + if (lockType == IntPtr.Zero) + throw new KeyNotFoundException("class 'Lock' was not found in 'threading'"); + var lockInstance = Runtime.Runtime.PyObject_CallObject(lockType, Runtime.Runtime.PyTuple_New(0)); + Exceptions.ErrorCheck(lockInstance); Assert.IsFalse(Runtime.Runtime.PyObject_IsIterable(lockInstance)); Assert.IsFalse(Runtime.Runtime.PyIter_Check(lockInstance));