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

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! add a Variables method
  • Loading branch information
yagweb committed Apr 7, 2017
commit 5484451819e74bde7d7109523a8d88f09f2ca6a0
16 changes: 16 additions & 0 deletions src/runtime/pyscope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ internal PyScope(string name)
variables, "__builtins__",
Runtime.PyEval_GetBuiltins()
);
InitVariables();
}

//To compitable with the python module
private void InitVariables()
{
SetVariable("locals", (Func<PyDict>)Variables);
SetVariable("globals", (Func<PyDict>)Variables);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said before, I'm strongly against this. I don't see any advantage in this over separating globals and locals as done in the Python API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the responses below.

}
Expand All @@ -50,10 +56,19 @@ internal PyScope(string name)
/// </summary>
internal IntPtr variables { get; private set; }

public long Refcount
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this one for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used for debug, now there are 2 IntPtr in the PyScope and the code seems stable, so it was removed.

{
get
{
return Runtime.Refcount(variables);
}
}

public event Action<PyScope> OnDispose;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use-case for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyScopes are managed by Py class, when it was disposed, Py class can do some cleaning work through registering this event.

In the future, methods in Py class maybe put in an independent ScopeManager class, see the responses below.


public PyDict Variables()
{
Runtime.XIncref(variables);
return new PyDict(variables);
}

Expand All @@ -77,6 +92,7 @@ public void ImportScope(PyScope scope)
{
throw new PythonException();
}
InitVariables();
}

/// <summary>
Expand Down