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

Skip to content

Commit 802a43a

Browse files
committed
BorrowReference instead of increasing the refcount
Addresses comments: #958 #958
1 parent 7ec9a6c commit 802a43a

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/embed_tests/pyinitialize.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ public static void StartAndStopTwice()
2424
public static void LoadDefaultArgs()
2525
{
2626
using (new PythonEngine())
27-
using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv")))
2827
{
29-
Runtime.Runtime.XIncref(argv.Handle);
30-
Assert.AreNotEqual(0, argv.Length());
28+
var argvref = new BorrowedReference(Runtime.Runtime.PySys_GetObject("argv"));
29+
using(var argv = new PyList(argvref.DangerousGetAddress()))
30+
{
31+
Assert.AreNotEqual(0, argv.Length());
32+
}
3133
}
3234
}
3335

@@ -36,11 +38,13 @@ public static void LoadSpecificArgs()
3638
{
3739
var args = new[] { "test1", "test2" };
3840
using (new PythonEngine(args))
39-
using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv")))
4041
{
41-
Runtime.Runtime.XIncref(argv.Handle);
42-
Assert.AreEqual(args[0], argv[0].ToString());
43-
Assert.AreEqual(args[1], argv[1].ToString());
42+
var argvref = new BorrowedReference(Runtime.Runtime.PySys_GetObject("argv"));
43+
using(var argv = new PyList(argvref.DangerousGetAddress()))
44+
{
45+
Assert.AreEqual(args[0], argv[0].ToString());
46+
Assert.AreEqual(args[1], argv[1].ToString());
47+
}
4448
}
4549
}
4650

0 commit comments

Comments
 (0)