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

Commit3785c40

Browse files
filmorvmuriart
authored andcommitted
Use Py.Throw in a few more places.
In particular in Py.Import.
1 parent4f67c5d commit3785c40

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

‎src/runtime/pythonengine.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ public static void Initialize(IEnumerable<string> args)
154154
Exceptions.Clear();
155155

156156
Py.SetArgv(args);
157-
Py.Throw();
158157

159158
// register the atexit callback (this doesn't use Py_AtExit as the C atexit
160159
// callbacks are called after python is fully finalized but the python ones
@@ -382,10 +381,7 @@ public static void EndAllowThreads(IntPtr ts)
382381
publicstaticPyObjectImportModule(stringname)
383382
{
384383
IntPtrop=Runtime.PyImport_ImportModule(name);
385-
if(op==IntPtr.Zero)
386-
{
387-
returnnull;
388-
}
384+
Py.Throw();
389385
returnnewPyObject(op);
390386
}
391387

@@ -401,10 +397,7 @@ public static PyObject ImportModule(string name)
401397
publicstaticPyObjectReloadModule(PyObjectmodule)
402398
{
403399
IntPtrop=Runtime.PyImport_ReloadModule(module.Handle);
404-
if(op==IntPtr.Zero)
405-
{
406-
thrownewPythonException();
407-
}
400+
Py.Throw();
408401
returnnewPyObject(op);
409402
}
410403

@@ -420,15 +413,9 @@ public static PyObject ReloadModule(PyObject module)
420413
publicstaticPyObjectModuleFromString(stringname,stringcode)
421414
{
422415
IntPtrc=Runtime.Py_CompileString(code,"none",(IntPtr)257);
423-
if(c==IntPtr.Zero)
424-
{
425-
thrownewPythonException();
426-
}
416+
Py.Throw();
427417
IntPtrm=Runtime.PyImport_ExecCodeModule(name,c);
428-
if(m==IntPtr.Zero)
429-
{
430-
thrownewPythonException();
431-
}
418+
Py.Throw();
432419
returnnewPyObject(m);
433420
}
434421

@@ -476,10 +463,7 @@ public static PyObject RunString(
476463
code,flag,globals.Value,locals.Value
477464
);
478465

479-
if(Runtime.PyErr_Occurred()!=0)
480-
{
481-
thrownewPythonException();
482-
}
466+
Py.Throw();
483467

484468
returnnewPyObject(result);
485469
}
@@ -583,6 +567,7 @@ public static void SetArgv(IEnumerable<string> argv)
583567
{
584568
vararr=argv.ToArray();
585569
Runtime.PySys_SetArgvEx(arr.Length,arr,0);
570+
Py.Throw();
586571
}
587572
}
588573

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp