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

Skip to content

Commit 5484451

Browse files
committed
fixup! add a Variables method
1 parent 904d9ed commit 5484451

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/runtime/pyscope.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ internal PyScope(string name)
4141
variables, "__builtins__",
4242
Runtime.PyEval_GetBuiltins()
4343
);
44+
InitVariables();
45+
}
46+
47+
//To compitable with the python module
48+
private void InitVariables()
49+
{
4450
SetVariable("locals", (Func<PyDict>)Variables);
4551
SetVariable("globals", (Func<PyDict>)Variables);
4652
}
@@ -50,10 +56,19 @@ internal PyScope(string name)
5056
/// </summary>
5157
internal IntPtr variables { get; private set; }
5258

59+
public long Refcount
60+
{
61+
get
62+
{
63+
return Runtime.Refcount(variables);
64+
}
65+
}
66+
5367
public event Action<PyScope> OnDispose;
5468

5569
public PyDict Variables()
5670
{
71+
Runtime.XIncref(variables);
5772
return new PyDict(variables);
5873
}
5974

@@ -77,6 +92,7 @@ public void ImportScope(PyScope scope)
7792
{
7893
throw new PythonException();
7994
}
95+
InitVariables();
8096
}
8197

8298
/// <summary>

0 commit comments

Comments
 (0)