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

Commitec65efe

Browse files
authored
fixed dynamic unary and binary operations not raising Python exception on failure (#1508)
Instead, they crashed with ArgumentNullException due to null pointer passed to PyObject constructor. Fixed by adding a check for None.
1 parent4529fde commitec65efe

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

‎src/embed_tests/TestPyObject.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ public void AsManagedObjectInvalidCast()
7171
varlist=PythonEngine.Eval("list");
7272
Assert.Throws<InvalidCastException>(()=>list.AsManagedObject(typeof(int)));
7373
}
74+
75+
[Test]
76+
publicvoidUnaryMinus_ThrowsOnBadType()
77+
{
78+
dynamiclist=newPyList();
79+
varerror=Assert.Throws<PythonException>(()=>list=-list);
80+
Assert.AreEqual("TypeError",error.Type.Name);
81+
}
7482
}
7583
}

‎src/runtime/pyobject.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg
13981398
result=null;
13991399
returnfalse;
14001400
}
1401+
Exceptions.ErrorCheck(res);
14011402
result=CheckNone(newPyObject(res));
14021403
returntrue;
14031404
}
@@ -1450,6 +1451,7 @@ public override bool TryUnaryOperation(UnaryOperationBinder binder, out object r
14501451
result=null;
14511452
returnfalse;
14521453
}
1454+
Exceptions.ErrorCheck(res);
14531455
result=CheckNone(newPyObject(res));
14541456
returntrue;
14551457
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp