This repository was archived by the owner on Jul 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,7 @@ public static void LoadDefaultArgs()
2525 {
2626 using ( new PythonEngine ( ) )
2727 {
28- var argvref = new BorrowedReference ( Runtime . Runtime . PySys_GetObject ( "argv" ) ) ;
29- using ( var argv = new PyList ( argvref . DangerousGetAddress ( ) ) )
28+ using ( var argv = new PyList ( new BorrowedReference ( Runtime . Runtime . PySys_GetObject ( "argv" ) ) ) )
3029 {
3130 Assert . AreNotEqual ( 0 , argv . Length ( ) ) ;
3231 }
@@ -39,8 +38,7 @@ public static void LoadSpecificArgs()
3938 var args = new [ ] { "test1" , "test2" } ;
4039 using ( new PythonEngine ( args ) )
4140 {
42- var argvref = new BorrowedReference ( Runtime . Runtime . PySys_GetObject ( "argv" ) ) ;
43- using ( var argv = new PyList ( argvref . DangerousGetAddress ( ) ) )
41+ using ( var argv = new PyList ( new BorrowedReference ( Runtime . Runtime . PySys_GetObject ( "argv" ) ) ) )
4442 {
4543 Assert . AreEqual ( args [ 0 ] , argv [ 0 ] . ToString ( ) ) ;
4644 Assert . AreEqual ( args [ 1 ] , argv [ 1 ] . ToString ( ) ) ;
Original file line number Diff line number Diff line change @@ -80,6 +80,25 @@ public PyList(PyObject[] items)
8080 }
8181 }
8282
83+ /// <summary>
84+ /// Constructor to make a PyList from a BorrowedReference.
85+ /// The list assumes ownership of the reference.
86+ /// </summary>
87+ /// <param name="r">The borrowed reference</param>
88+ internal PyList ( BorrowedReference r )
89+ {
90+ IntPtr addr = r . DangerousGetAddress ( ) ;
91+ if ( ! Runtime . PyList_Check ( addr ) )
92+ {
93+ throw new ArgumentException ( "object is not a list" ) ;
94+ }
95+
96+ obj = addr ;
97+ // Take ownership.
98+ Runtime . XIncref ( addr ) ;
99+
100+ }
101+
83102
84103 /// <summary>
85104 /// IsListType Method
You can’t perform that action at this time.
0 commit comments