Skip to content

Commit

Permalink
better method of getting clr object
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed May 29, 2024
1 parent 6e5dfbb commit 69ec514
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/runtime/McNeel.PythonEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,11 @@ public void SetStdIO(Stream stdout)
using var sys = Runtime.PyImport_ImportModule("sys");
using (PyObject sysObj = sys.MoveToPyObject())
{
if (sysObj.GetAttr("stdout")
.AsManagedObject(typeof(RhinoCodePythonEngineIO)) is RhinoCodePythonEngineIO currentStdout)
if (sysObj.GetAttr("stdout") is PyObject stdoutObj
&& ManagedType.GetManagedObject(stdoutObj) is CLRObject clrObj
&& clrObj.inst is RhinoCodePythonEngineIO exstStdout)
{
currentStdout.Dispose();
exstStdout.Dispose();
}

using var stdio = PyObject.FromManagedObject(new RhinoCodePythonEngineIO(stdout));
Expand Down

0 comments on commit 69ec514

Please sign in to comment.