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

Skip to content

Commit 4616921

Browse files
committed
Replace Py.Throw with Runtime.CheckExceptionOccurred
1 parent 46660fa commit 4616921

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/runtime/pythonengine.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public static void EndAllowThreads(IntPtr ts)
362362
public static PyObject ImportModule(string name)
363363
{
364364
IntPtr op = Runtime.PyImport_ImportModule(name);
365-
Py.Throw();
365+
Runtime.CheckExceptionOccurred();
366366
return new PyObject(op);
367367
}
368368

@@ -377,7 +377,7 @@ public static PyObject ImportModule(string name)
377377
public static PyObject ReloadModule(PyObject module)
378378
{
379379
IntPtr op = Runtime.PyImport_ReloadModule(module.Handle);
380-
Py.Throw();
380+
Runtime.CheckExceptionOccurred();
381381
return new PyObject(op);
382382
}
383383

@@ -392,9 +392,9 @@ public static PyObject ReloadModule(PyObject module)
392392
public static PyObject ModuleFromString(string name, string code)
393393
{
394394
IntPtr c = Runtime.Py_CompileString(code, "none", (IntPtr)257);
395-
Py.Throw();
395+
Runtime.CheckExceptionOccurred();
396396
IntPtr m = Runtime.PyImport_ExecCodeModule(name, c);
397-
Py.Throw();
397+
Runtime.CheckExceptionOccurred();
398398
return new PyObject(m);
399399
}
400400

@@ -473,7 +473,7 @@ public static PyObject RunString(
473473
code, flag, globals.Value, locals.Value
474474
);
475475

476-
Py.Throw();
476+
Runtime.CheckExceptionOccurred();
477477

478478
return new PyObject(result);
479479
}
@@ -600,18 +600,7 @@ public static void SetArgv(IEnumerable<string> argv)
600600
{
601601
string[] arr = argv.ToArray();
602602
Runtime.PySys_SetArgvEx(arr.Length, arr, 0);
603-
Py.Throw();
604-
}
605-
}
606-
607-
internal static void Throw()
608-
{
609-
using (GIL())
610-
{
611-
if (Runtime.PyErr_Occurred() != 0)
612-
{
613-
throw new PythonException();
614-
}
603+
Runtime.CheckExceptionOccurred();
615604
}
616605
}
617606
}

0 commit comments

Comments
 (0)