Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 46adc46

Browse files
committed
added checks to PyCheck_Iter_PyObject_IsIterable_ThreadingLock_Test in attempt to replace segfault with a more meaningful exception
related to #1060
1 parent 22735f8 commit 46adc46

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/embed_tests/TestRuntime.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using NUnit.Framework;
34
using Python.Runtime;
45
using Python.Runtime.Platform;
@@ -110,9 +111,15 @@ public static void PyCheck_Iter_PyObject_IsIterable_ThreadingLock_Test()
110111
// Create an instance of threading.Lock, which is one of the very few types that does not have the
111112
// TypeFlags.HaveIter set in Python 2. This tests a different code path in PyObject_IsIterable and PyIter_Check.
112113
var threading = Runtime.Runtime.PyImport_ImportModule("threading");
114+
Exceptions.ErrorCheck(threading);
113115
var threadingDict = Runtime.Runtime.PyModule_GetDict(threading);
116+
Exceptions.ErrorCheck(threadingDict);
114117
var lockType = Runtime.Runtime.PyDict_GetItemString(threadingDict, "Lock");
118+
if (lockType == IntPtr.Zero)
119+
throw new KeyNotFoundException("class 'Lock' was not found in 'threading'");
120+
115121
var lockInstance = Runtime.Runtime.PyObject_CallObject(lockType, Runtime.Runtime.PyTuple_New(0));
122+
Exceptions.ErrorCheck(lockInstance);
116123

117124
Assert.IsFalse(Runtime.Runtime.PyObject_IsIterable(lockInstance));
118125
Assert.IsFalse(Runtime.Runtime.PyIter_Check(lockInstance));

0 commit comments

Comments
 (0)