8000 fixed bug of Exec method #591 by yagweb · Pull Request #594 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

fixed bug of Exec method #591 #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/embed_tests/pyrunstring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,20 @@ public void TestExec()
object c = locals.GetItem("c").AsManagedObject(typeof(int));
Assert.AreEqual(111, c);
}

[Test]
public void TestExec2()
{
string code = @"
class Test1():
pass

class Test2():
def __init__(self):
Test1()

Test2()";
PythonEngine.Exec(code);
}
}
}
8000 10 changes: 2 additions & 8 deletions src/runtime/pythonengine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,10 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals,
borrowedGlobals = false;
}
}

var borrowedLocals = true;

if (locals == null)
{
locals = Runtime.PyDict_New();
borrowedLocals = false;
locals = globals;
}

try
Expand All @@ -516,10 +514,6 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals,
}
finally
{
if (!borrowedLocals)
{
Runtime.XDecref(locals.Value);
}
if (!borrowedGlobals)
{
Runtime.XDecref(globals.Value);
Expand Down
0