1- using System . Linq ;
21using System ;
2+ using System . Linq ;
33using System . Reflection ;
44
55namespace Python . Runtime
@@ -43,16 +43,15 @@ internal NewReference GetDocString()
4343 }
4444 str += t . ToString ( ) ;
4545 }
46- return NewReference . DangerousFromPointer ( Runtime . PyString_FromString ( str ) ) ;
46+ return Runtime . PyString_FromString ( str ) ;
4747 }
4848
4949
5050 /// <summary>
5151 /// Implements __new__ for reflected classes and value types.
5252 /// </summary>
53- public static IntPtr tp_new ( IntPtr tpRaw , IntPtr args , IntPtr kw )
53+ public static NewReference tp_new ( BorrowedReference tp , BorrowedReference args , BorrowedReference kw )
5454 {
55- var tp = new BorrowedReference ( tpRaw ) ;
5655 var self = GetManagedObject ( tp ) as ClassObject ;
5756
5857 // Sanity check: this ensures a graceful error if someone does
@@ -77,32 +76,32 @@ public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw)
7776 if ( Runtime . PyTuple_Size ( args ) != 1 )
7877 {
7978 Exceptions . SetError ( Exceptions . TypeError , "no constructors match given arguments" ) ;
80- return IntPtr . Zero ;
79+ return default ;
8180 }
8281
83- IntPtr op = Runtime . PyTuple_GetItem ( args , 0 ) ;
82+ BorrowedReference op = Runtime . PyTuple_GetItem ( args , 0 ) ;
8483 object result ;
8584
8685 if ( ! Converter . ToManaged ( op , type , out result , true ) )
8786 {
88- return IntPtr . Zero ;
87+ return default ;
8988 }
9089
91- return CLRObject . GetReference ( result , tp ) . DangerousMoveToPointerOrNull ( ) ;
90+ return CLRObject . GetReference ( result , tp ) ;
9291 }
9392
9493 if ( type . IsAbstract )
9594 {
9695 Exceptions . SetError ( Exceptions . TypeError , "cannot instantiate abstract class" ) ;
97- return IntPtr . Zero ;
96+ return default ;
9897 }
9998
10099 if ( type . IsEnum )
101100 {
102- return NewEnum ( type , new BorrowedReference ( args ) , tp ) . DangerousMoveToPointerOrNull ( ) ;
101+ return NewEnum ( type , args , tp ) ;
103102 }
104103
105- object obj = self . binder . InvokeRaw ( IntPtr . Zero , args , kw ) ;
104+ object obj = self . binder . InvokeRaw ( null , args , kw ) ;
106105 if ( obj == null )
107106 {
108107 return IntPtr . Zero ;
@@ -154,7 +153,7 @@ private static NewReference NewEnum(Type type, BorrowedReference args, BorrowedR
154153 /// both to implement the Array[int] syntax for creating arrays and
155154 /// to support generic name overload resolution using [].
156155 /// </summary>
157- public override IntPtr type_subscript ( IntPtr idx )
156+ public override NewReference type_subscript ( BorrowedReference idx )
158157 {
159158 if ( ! type . Valid )
160159 {
0 commit comments