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

Commit1a2499b

Browse files
authored
Merge pull requestpythonnet#273 from ArvidJB/isinstance_refcount_leak
Calling isinstance(x,t) repeatedly when x or t is not actually a CLR …
2 parents85db427 +b68e7a1 commit1a2499b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

‎src/runtime/metatype.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ static IntPtr DoInstanceCheck(IntPtr tp, IntPtr args, bool checkType)
281281
{
282282
ClassBasecb=GetManagedObject(tp)asClassBase;
283283

284-
if(cb==null)
284+
if(cb==null){
285+
Runtime.Incref(Runtime.PyFalse);
285286
returnRuntime.PyFalse;
287+
}
286288

287289
using(PyListargsObj=newPyList(args))
288290
{
@@ -296,12 +298,16 @@ static IntPtr DoInstanceCheck(IntPtr tp, IntPtr args, bool checkType)
296298
else
297299
otherType=arg.GetPythonType();
298300

299-
if(Runtime.PyObject_TYPE(otherType.Handle)!=PyCLRMetaType)
301+
if(Runtime.PyObject_TYPE(otherType.Handle)!=PyCLRMetaType){
302+
Runtime.Incref(Runtime.PyFalse);
300303
returnRuntime.PyFalse;
304+
}
301305

302306
ClassBaseotherCb=GetManagedObject(otherType.Handle)asClassBase;
303-
if(otherCb==null)
307+
if(otherCb==null){
308+
Runtime.Incref(Runtime.PyFalse);
304309
returnRuntime.PyFalse;
310+
}
305311

306312
returnConverter.ToPython(cb.type.IsAssignableFrom(otherCb.type));
307313
}

‎src/tests/test_subclass.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ def handler(self, x, args):
147147
self.assertEqual(event_handler.value,3)
148148
self.assertEqual(len(d.event_handlers),1)
149149

150+
deftest_isinstance(self):
151+
fromSystemimportObject
152+
fromSystemimportString
153+
154+
a= [str(x)forxinrange(0,1000)]
155+
b= [String(x)forxina]
156+
157+
forxina:
158+
self.assertFalse(isinstance(x,Object))
159+
self.assertFalse(isinstance(x,String))
160+
161+
forxinb:
162+
self.assertTrue(isinstance(x,Object))
163+
self.assertTrue(isinstance(x,String))
164+
150165

151166
deftest_suite():
152167
returnunittest.makeSuite(SubClassTests)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp